UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cl_radar.cpp
Go to the documentation of this file.
1 
6 /*
7 Copyright (C) 2002-2020 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24 */
25 
26 #include "../client.h"
27 #include "cl_radar.h"
28 #include "../renderer/r_draw.h"
29 #include "../renderer/r_misc.h"
30 #include "../cl_video.h"
31 #include "../ui/ui_main.h"
32 #include "../ui/ui_timer.h"
33 #include "cl_localentity.h"
34 #include "cl_camera.h"
35 #include "cl_battlescape.h"
36 
37 static uiTimer_t* timer;
38 
39 static void CL_BattlescapeRadarOpen_f (void)
40 {
41  UI_PushWindow("radarwindow");
42 }
43 
44 static void CL_BattlescapeRadarClose_f (void)
45 {
46  UI_CloseWindow("radarwindow");
47 }
48 
57 static void CL_BattlescapeRadarMapInFrameBuffer (int* x, int* y, int* width, int* height)
58 {
59  /* Coefficient come from metric (Bunker map, and game with resolution 1024x1024) == 0.350792947 */
60  static const float magicCoef = 0.351f;
61  const float mapWidth = cl.mapData->mapBox.getWidthX();
62  const float mapHeight = cl.mapData->mapBox.getWidthY();
63 
64  /* compute width and height with the same round error on both sides */
66  const int x2 = (viddef.context.width / 2) + (mapWidth * magicCoef * 0.5);
67  const int y2 = (viddef.context.height / 2) + (mapHeight * magicCoef * 0.5) + 1;
68  *x = (viddef.context.width / 2) - (mapWidth * magicCoef * 0.5);
69  *y = (viddef.context.height / 2) - (mapHeight * magicCoef * 0.5);
70  *width = (x2 - *x);
71  *height = (y2 - *y);
72 }
73 
75 {
76  int x, y, width, height;
77  /* map to screen */
78  CL_BattlescapeRadarMapInFrameBuffer(&x, &y, &width, &height);
79 
80  /* from screen to virtual screen */
81  x /= viddef.rx;
82  width /= viddef.rx;
83  y /= viddef.ry;
84  height /= viddef.ry;
85  y = viddef.virtualHeight - y - height;
86 
87  UI_ExecuteConfunc("mn_radarhud_setmapborder %d %d %d %d", x, y, width, height);
88 }
89 
97 {
98  const int border = 0;
99  const char* mapName = Cvar_GetString("sv_mapname");
100 
101  const int level = Cvar_GetInteger("cl_worldlevel");
102  const char* filename = nullptr;
103  int x, y, width, height;
104 
105  CL_BattlescapeRadarMapInFrameBuffer(&x, &y, &width, &height);
106  if (mapName)
107  filename = va("%s_%i", mapName, level + 1);
108  R_ScreenShot(x - border, y - border, width + border * 2, height + border * 2, filename, nullptr);
109 }
110 
112 {
113  const int level = (timer->calledTime - 1) / 2;
114  const int mode = (timer->calledTime - 1) % 2;
115 
116  if (level >= cl.mapMaxLevel) {
117  Cbuf_AddText("ui_genallradarmaprelease");
118  return;
119  }
120 
121  if (mode == 0)
122  Cvar_SetValue("cl_worldlevel", level);
123  else
124  Cmd_ExecuteString("ui_genradarmap");
125 }
126 
132 {
133  const int delay = 1000;
134  timer = UI_AllocTimer(nullptr, delay, CL_BattlescapeRadarGenerateAll);
135  UI_TimerStart(timer);
136 }
137 
142 {
143  UI_TimerRelease(timer);
144  UI_ExecuteConfunc("mn_radarhud_reinit");
145 }
146 
148 {
151 
152  Cmd_AddCommand("ui_genpreviewradarmap", CL_BattlescapeRadarGenPreview_f);
154  Cmd_AddCommand("ui_genallradarmap", CL_BattlescapeRadarGenerateAll_f);
155  Cmd_AddCommand("ui_genallradarmaprelease", CL_BattlescapeRadarGenerateAllRelease_f);
156 }
static void CL_BattlescapeRadarClose_f(void)
Definition: cl_radar.cpp:44
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
Definition: cmd.cpp:744
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
Definition: shared.cpp:410
static void CL_BattlescapeRadarOpen_f(void)
Definition: cl_radar.cpp:39
const char * filename
Definition: ioapi.h:41
void Cbuf_AddText(const char *format,...)
Adds command text at the end of the buffer.
Definition: cmd.cpp:126
float rx
Definition: cl_video.h:71
viddef_t viddef
Definition: cl_video.cpp:34
unsigned width
Definition: cl_video.h:44
uiTimer_t * UI_AllocTimer(uiNode_t *node, int firstDelay, timerCallback_t callback)
Allocate a new time for a node.
Definition: ui_timer.cpp:123
static void CL_BattlescapeRadarGenPreview_f(void)
Definition: cl_radar.cpp:74
int virtualHeight
Definition: cl_video.h:74
static void CL_BattlescapeRadarGenerateAll(uiNode_t *node, uiTimer_t *timer)
Definition: cl_radar.cpp:111
int Cvar_GetInteger(const char *varName)
Returns the int value of a cvar.
Definition: cvar.cpp:194
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
Definition: cmd.cpp:1007
uiNode_t * UI_PushWindow(const char *name, const char *parentName, linkedList_t *params)
Push a window onto the window stack.
Definition: ui_windows.cpp:170
float getWidthY() const
Definition: aabb.h:144
void UI_CloseWindow(const char *name)
Definition: ui_windows.cpp:435
void UI_TimerRelease(uiTimer_t *timer)
Release the timer. It no more exists.
Definition: ui_timer.cpp:176
clientBattleScape_t cl
Battlescape radar header.
viddefContext_t context
Definition: cl_video.h:67
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
void R_ScreenShot(int x, int y, int width, int height, const char *filename, const char *ext)
Definition: r_misc.cpp:101
void CL_BattlescapeRadarInit(void)
Definition: cl_radar.cpp:147
float getWidthX() const
Definition: aabb.h:141
static void CL_BattlescapeRadarGenerate_f(void)
Take a screen shot of the map with the position of the radar.
Definition: cl_radar.cpp:96
static void CL_BattlescapeRadarGenerateAllRelease_f(void)
Definition: cl_radar.cpp:141
const char int mode
Definition: ioapi.h:41
AABB mapBox
Definition: typedefs.h:351
const char * Cvar_GetString(const char *varName)
Returns the value of cvar as string.
Definition: cvar.cpp:210
unsigned height
Definition: cl_video.h:45
float ry
Definition: cl_video.h:72
static void CL_BattlescapeRadarMapInFrameBuffer(int *x, int *y, int *width, int *height)
Definition: cl_radar.cpp:57
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
Definition: cvar.cpp:671
static void CL_BattlescapeRadarGenerateAll_f(void)
Take all screenshots from lower to upper map level. Use a timer to delay each capture.
Definition: cl_radar.cpp:131
int calledTime
Definition: ui_timer.h:43
void UI_TimerStart(uiTimer_t *timer)
Restart a timer.
Definition: ui_timer.cpp:150
static const char * mapName
level_locals_t level
Definition: g_main.cpp:38
static uiTimer_t * timer
Definition: cl_radar.cpp:37
void UI_ExecuteConfunc(const char *fmt,...)
Executes confunc - just to identify those confuncs in the code - in this frame.
Definition: ui_main.cpp:110