UFO: Alien Invasion
Loading...
Searching...
No Matches
cl_radar.cpp
Go to the documentation of this file.
1
5
6/*
7Copyright (C) 2002-2025 UFO: Alien Invasion.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, 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
38
39static void CL_BattlescapeRadarOpen_f (void)
40{
41 UI_PushWindow("radarwindow");
42}
43
45{
46 UI_CloseWindow("radarwindow");
47}
48
57static 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;
136}
137
142{
144 UI_ExecuteConfunc("mn_radarhud_reinit");
145}
146
clientBattleScape_t cl
static void CL_BattlescapeRadarClose_f(void)
Definition cl_radar.cpp:44
static void CL_BattlescapeRadarGenerateAll(uiNode_t *node, uiTimer_t *timer)
Definition cl_radar.cpp:111
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
static void CL_BattlescapeRadarGenerate_f(void)
Take a screen shot of the map with the position of the radar.
Definition cl_radar.cpp:96
void CL_BattlescapeRadarInit(void)
Definition cl_radar.cpp:147
static void CL_BattlescapeRadarGenerateAllRelease_f(void)
Definition cl_radar.cpp:141
static void CL_BattlescapeRadarMapInFrameBuffer(int *x, int *y, int *width, int *height)
Definition cl_radar.cpp:57
static void CL_BattlescapeRadarOpen_f(void)
Definition cl_radar.cpp:39
static void CL_BattlescapeRadarGenPreview_f(void)
Definition cl_radar.cpp:74
Battlescape radar header.
viddef_t viddef
Definition cl_video.cpp:34
Video driver defs.
Primary header for client.
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
Definition cmd.cpp:1007
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
Definition cmd.cpp:744
void Cbuf_AddText(const char *format,...)
Adds command text at the end of the buffer.
Definition cmd.cpp:126
void Cvar_SetValue(const char *varName, float value)
Expands value to a string and calls Cvar_Set.
Definition cvar.cpp:671
int Cvar_GetInteger(const char *varName)
Returns the int value of a cvar.
Definition cvar.cpp:194
const char * Cvar_GetString(const char *varName)
Returns the value of cvar as string.
Definition cvar.cpp:210
level_locals_t level
Definition g_main.cpp:38
const char * filename
Definition ioapi.h:41
const char int mode
Definition ioapi.h:41
void R_ScreenShot(int x, int y, int width, int height, const char *filename, const char *ext)
Definition r_misc.cpp:101
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
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
static const char * mapName
void UI_ExecuteConfunc(const char *fmt,...)
Executes confunc - just to identify those confuncs in the code - in this frame.
Definition ui_main.cpp:110
uiTimer_t * UI_AllocTimer(uiNode_t *node, int firstDelay, timerCallback_t callback)
Allocate a new time for a node.
Definition ui_timer.cpp:123
void UI_TimerStart(uiTimer_t *timer)
Restart a timer.
Definition ui_timer.cpp:150
void UI_TimerRelease(uiTimer_t *timer)
Release the timer. It no more exists.
Definition ui_timer.cpp:176
uiNode_t * UI_PushWindow(const char *name, const char *parentName, linkedList_t *params)
Push a window onto the window stack.
void UI_CloseWindow(const char *name)