UFO: Alien Invasion
Loading...
Searching...
No Matches
test_mapdefmassrma.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 "test_shared.h"
27#include "../client/client.h"
28#include "../client/cl_shared.h"
29#include "../client/cl_lua.h"
32#include "../common/routing.h"
33#include "../server/server.h"
34#include "../server/sv_rma.h"
35
36#define RMA_HIGHEST_SUPPORTED_SEED 50
37
38class MapDefMassRMATest: public ::testing::Test {
39protected:
40 static void SetUpTestCase() {
41 TEST_Init();
42
43 sv_genericPool = Mem_CreatePool("mapdef-test");
45 vid_imagePool = Mem_CreatePool("Vid: Image system");
46 sv_dumpmapassembly = Cvar_Get("sv_dumpassembly", "0");
47 sv_public = Cvar_Get("sv_public", "0");
48 port = Cvar_Get("testport", "27909");
49 masterserver_url = Cvar_Get("masterserver_test", "http://localhost");
50
51 cl_genericPool = Mem_CreatePool("Client: Generic");
52
53 r_state.active_texunit = &r_state.texunits[0];
54 R_FontInit();
55 CL_InitLua();
56 UI_Init();
57
58 OBJZERO(cls);
59 Com_ParseScripts(false);
60 }
61
62 static void TearDownTestCase() {
65 }
66};
67
70
77TEST_F(MapDefMassRMATest, DISABLED_MapDefsMassRMA)
78{
80 const char* filterId = TEST_GetStringProperty("mapdef-id");
81 const mapDef_t* md;
82 int mapCount = 0;
83
84 ASSERT_TRUE(csi.numMDs > 0);
85
86 MapDef_Foreach(md) {
87 if (md->mapTheme[0] == '.')
88 continue;
89 if (filterId && !Q_streq(filterId, md->id))
90 continue;
91 if (++mapCount <= 0) /* change 0 to n to skip the first n assemblies */
92 continue;
93
94 {
95 char* p = md->mapTheme;
96
97 if (*p == '+')
98 p++;
99 else
100 continue;
101
102 const char* asmName = (const char*)LIST_GetByIdx(md->params, 0);
103 Com_Printf("\nMap: %s Assembly: %s AssNr: %i\n", p, asmName, mapCount);
104
105 sv_threads->integer = 0;
106
107 /* This is tricky. Some maps don't have any ufo on them and thus in the mapdef.
108 * That would cause a LIST_Foreach macro to never run it's body. That's why these
109 * for-loops seem to have two termination conditions. In fact, we have to manually
110 * exit the for-loops if we ran it just once (without ufos nor dropships).
111 */
112 bool didItOnce = false;
113 linkedList_t* iterDrop;
114 for (iterDrop = md->aircraft; iterDrop || !didItOnce; iterDrop = iterDrop->next) {
115 const char* craft = nullptr;
116 if (iterDrop)
117 craft = (const char*) (iterDrop->data);
118
119 if (craft)
120 Cvar_Set("rm_drop", "%s", Com_GetRandomMapAssemblyNameForCraft(craft));
121 else
122 Cvar_Set("rm_drop", "+craft_drop_firebird");
123
124 linkedList_t* iterUfo;
125 for (iterUfo = md->ufos; iterUfo || !didItOnce; iterUfo = iterUfo->next) {
126 const char* ufo = nullptr;
127 if (iterUfo)
128 ufo = (const char*) (iterUfo->data);
129 if (ufo)
131 else
132 Cvar_Set("rm_ufo", "+craft_ufo_scout");
133
134 Com_Printf("\nDrop: %s Ufo: %s", craft, ufo);
135 Com_Printf("\nSeed:");
136 for (int i = 0; i < RMA_HIGHEST_SUPPORTED_SEED; i++) {
137 asmName = nullptr;
138 srand(i);
139 long time = Sys_Milliseconds();
140 Com_Printf(" %i", i);
141#if 0
142
143 typedef struct skip_info {
144 int seed;
145 char const* map;
146 char const* params;
147 char const* craft;
148 char const* ufo;
149 } skip_info;
150 /* if we have known problems with some combinations, we can skip them */
151 skip_info const skip_list[] = {
152 /* examples: */
153 // { 20, "forest", "large", "craft_drop_raptor", 0 },
154 // { 12, "forest", "large" "craft_drop_herakles", "craft_ufo_harvester" },
155 { -1, "frozen", "nature_medium",0, 0 },
156 { 11, "village", "medium", 0, 0 },
157 { 19, "village", "medium", 0, 0 },
158 { -1, "village", "medium_noufo", 0, 0 },
159 { -1, "village", "small", 0, 0 },
160 };
161
162 bool skip = false;
163 for (skip_info const* e = skip_list; e != endof(skip_list); ++e) {
164 if (e->seed >= 0 && i != e->seed)
165 continue;
166 if (e->map && !Q_streq(p, e->map))
167 continue;
168 if (e->params && !Q_streq(md->params, e->params))
169 continue;
170 if (e->craft && !Q_streq(craft, e->craft))
171 continue;
172 if (e->ufo && !Q_streq(ufo, e->ufo))
173 continue;
174 skip = true;
175 break;
176 }
177 if (skip)
178 continue;
179#endif
180 /* for ufocrash map, the ufoname is the assemblyame */
181 if (Q_streq(p, "ufocrash"))
182 asmName = Com_GetRandomMapAssemblyNameForCraft(ufo) + 1; /* +1 = get rid of the '+' */
183 else
184 asmName = (const char*)LIST_GetByIdx(md->params, 0);
185
186 char* entityString = SV_GetConfigString(CS_ENTITYSTRING);
187 const int numPlaced = SV_AssembleMap(p, asmName, mapStr, posStr, entityString, i, false);
188 ASSERT_TRUE(numPlaced != 0);
189 time = (Sys_Milliseconds() - time);
190 ASSERT_TRUE(time < 30000);
191 if (time > 10000)
192 Com_Printf("\nMap: %s Assembly: %s Seed: %i tiles: %i ms: %li\n", p, asmName, i, numPlaced, time);
193 }
194 didItOnce = true;
195 if (!iterUfo)
196 break;
197 }
198 if (!iterDrop)
199 break;
200 }
201 }
202 }
203}
void CL_InitLua(void)
Initializes the ui-lua interfacing environment.
Definition cl_lua.cpp:130
memPool_t * vid_imagePool
Definition cl_main.cpp:88
client_static_t cls
Definition cl_main.cpp:83
memPool_t * cl_genericPool
Definition cl_main.cpp:86
void R_FontInit(void)
Definition r_font.cpp:716
Share stuff between the different cgame implementations.
static void SetUpTestCase()
static void TearDownTestCase()
Primary header for client.
csi_t csi
Definition common.cpp:39
cvar_t * port
Definition common.cpp:58
void Com_Printf(const char *const fmt,...)
Definition common.cpp:428
memPool_t * com_networkPool
Definition common.cpp:73
cvar_t * masterserver_url
Definition common.cpp:57
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
Definition cvar.cpp:615
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
Definition cvar.cpp:342
#define MAX_TOKEN_CHARS
Definition defines.h:372
void * LIST_GetByIdx(linkedList_t *list, int index)
Get an entry of a linked list by its index in the list.
Definition list.cpp:362
#define Mem_CreatePool(name)
Definition mem.h:32
void NET_Shutdown(void)
Definition net.cpp:337
#define CS_ENTITYSTRING
Definition q_shared.h:324
#define MAX_TILESTRINGS
Definition q_shared.h:298
#define MapDef_Foreach(var)
Definition q_shared.h:505
QGL_EXTERN GLint i
Definition r_gl.h:113
rstate_t r_state
Definition r_main.cpp:48
grid pathfinding and routing
void Com_ParseScripts(bool onlyServer)
Definition scripts.cpp:3619
const char * Com_GetRandomMapAssemblyNameForCraft(const char *craftID)
Returns the name of an aircraft or an ufo that is used in the ump files for the random map assembly.
Definition scripts.cpp:3277
Main server include file.
memPool_t * sv_genericPool
Definition sv_main.cpp:55
char * SV_GetConfigString(int index)
Definition sv_main.cpp:77
cvar_t * sv_threads
Definition sv_main.cpp:48
cvar_t * sv_public
Definition sv_main.cpp:52
cvar_t * sv_dumpmapassembly
Definition sv_main.cpp:47
#define endof(x)
Definition shared.h:106
#define Q_streq(a, b)
Definition shared.h:136
#define OBJZERO(obj)
Definition shared.h:178
void * data
Definition list.h:31
linkedList_t * next
Definition list.h:32
linkedList_t * aircraft
Definition q_shared.h:492
char * mapTheme
Definition q_shared.h:464
linkedList_t * ufos
Definition q_shared.h:491
char * id
Definition q_shared.h:463
linkedList_t * params
Definition q_shared.h:465
int SV_AssembleMap(const char *mapTheme, const char *assembly, char *asmTiles, char *asmPos, char *entityString, const unsigned int seed, bool print)
Definition sv_rma.cpp:2212
#define RMA_HIGHEST_SUPPORTED_SEED
Definition sv_rma.h:31
int Sys_Milliseconds(void)
static int mapCount
Definition test_game.cpp:37
char posStr[MAX_TOKEN_CHARS *MAX_TILESTRINGS]
char mapStr[MAX_TOKEN_CHARS *MAX_TILESTRINGS]
TEST_F(MapDefMassRMATest, DISABLED_MapDefsMassRMA)
This test cycles through the list of map definitions found in the maps.ufo script and builds each map...
void TEST_Shutdown(void)
const char * TEST_GetStringProperty(const char *name)
void TEST_Init(void)
void UI_Init(void)
Definition ui_main.cpp:278