27 #include "../shared/ufotypes.h"
28 #include "../game/g_local.h"
29 #include "../game/g_actor.h"
30 #include "../game/g_client.h"
31 #include "../game/g_edicts.h"
32 #include "../game/g_inventory.h"
33 #include "../game/g_move.h"
34 #include "../server/server.h"
35 #include "../client/renderer/r_state.h"
82 const char*
name =
"name";
90 ASSERT_NE(size, -1) <<
"could not load game/entity.txt.";
91 ASSERT_TRUE(size > 0) <<
"game/entity.txt is empty.";
98 svs.
ge->SpawnEntities(name, day, (
const char*)buf);
99 ASSERT_TRUE(
svs.
ge->ClientConnect(player, userinfo,
sizeof(userinfo))) <<
"Failed to connect the client";
100 ASSERT_FALSE(
svs.
ge->RunFrame()) <<
"Failed to run the server logic frame tick";
122 }
else if (
Q_streq(aircraft,
"craft_drop_firebird")) {
124 }
else if (
Q_streq(aircraft,
"craft_drop_raptor")) {
126 }
else if (
Q_streq(aircraft,
"craft_drop_herakles")) {
129 ADD_FAILURE() <<
"Error: Mapdef defines unknown aircraft: " << aircraft;
140 }
else if (
Q_streq(aircraft,
"craft_drop_firebird")) {
142 }
else if (
Q_streq(aircraft,
"craft_drop_raptor")) {
144 }
else if (
Q_streq(aircraft,
"craft_drop_herakles")) {
147 ADD_FAILURE() <<
"Error: Mapdef defines unknown aircraft: " << aircraft;
158 }
else if (
Q_streq(ufo,
"craft_ufo_scout") ||
Q_streq(ufo,
"craft_crash_scout")) {
160 }
else if (
Q_streq(ufo,
"craft_ufo_fighter") ||
Q_streq(ufo,
"craft_crash_fighter")) {
162 }
else if (
Q_streq(ufo,
"craft_ufo_harvester") ||
Q_streq(ufo,
"craft_crash_harvester")) {
164 }
else if (
Q_streq(ufo,
"craft_ufo_corrupter") ||
Q_streq(ufo,
"craft_crash_corrupter")) {
166 }
else if (
Q_streq(ufo,
"craft_ufo_supply") ||
Q_streq(ufo,
"craft_crash_supply")) {
168 }
else if (
Q_streq(ufo,
"craft_ufo_gunboat") ||
Q_streq(ufo,
"craft_crash_gunboat")) {
170 }
else if (
Q_streq(ufo,
"craft_ufo_bomber") ||
Q_streq(ufo,
"craft_crash_bomber")) {
172 }
else if (
Q_streq(ufo,
"craft_ufo_ripper") ||
Q_streq(ufo,
"craft_crash_ripper")) {
175 ADD_FAILURE() <<
"Error: Mapdef defines unknown UFO: " << ufo;
183 std::cout <<
"[ ] adding test parameter: gamemode multiplayer" << std::endl;
184 Com_Printf(
"CountSpawnpoints - adding test parameter: gamemode multiplayer\n");
188 ADD_FAILURE() <<
"Error: Multiplayer enabled, but no gametypes defined in mapdef " << md->
id;
189 Com_Printf(
"CountSpawnpoints - error: Multiplayer enabled, but no gametypes defined in mapdef.\n");
194 ADD_FAILURE() <<
"Error: Multiplayer enabled, but number of teams is " << md->
teams;
195 Com_Printf(
"CountSpawnpoints - error: Multiplayer enabled, but number of teams is %i.\n", md->
teams);
203 Cvar_Set(
"sv_maxsoldiersperteam",
"12");
204 Cvar_Set(
"ai_multiplayeraliens",
"64");
207 Com_Printf(
"CountSpawnpoints - loading map: mode multiplayer mapdef %s map %s assembly %s dropship %s ufo %s\n", md->
id, md->
mapTheme, asmName, aircraft, ufo);
213 ADD_FAILURE() <<
"Error: Failed to load assembly " << asmName <<
" from mapdef " << md->
id <<
", map "
214 << md->
mapTheme <<
" aircraft: " << aircraft <<
", ufo: " << ufo <<
" => multiplayer mode.";
215 Com_Printf(
"CountSpawnpoints - error: Multiplayer enabled, but no gametypes defined in mapdef.\n");
216 Com_Printf(
"CountSpawnpoints - error: Failed to load map.\n");
222 Com_Printf(
"CountSpawnpoints - result: %li ms\n", time);
227 Com_Printf(
"CountSpawnpoints - map: mode multiplayer\n");
228 Com_Printf(
"CountSpawnpoints - map: mapdef %s\n", md->
id);
230 Com_Printf(
"CountSpawnpoints - map: assembly %s\n", asmName);
231 Com_Printf(
"CountSpawnpoints - map: aircraft %s \n", aircraft);
232 Com_Printf(
"CountSpawnpoints - map: ufo %s\n", ufo);
246 Com_Printf(
"CountSpawnpoints - count spawnpoints: civilian %i\n", spawnCivs);
255 for (
int j = 0; j < gt->
num_cvars; j++, list++) {
257 coop = std::max(coop, atoi(list->
value));
258 }
else if (
Q_streq(list->
name,
"sv_maxsoldiersperteam")) {
259 minMP = std::max(minMP, atoi(list->
value));
271 for (
int currTeamNum = startTeam; currTeamNum < startTeam + md->
teams; ++currTeamNum) {
273 ADD_FAILURE() <<
"Error: Mapdef " << md->
id <<
" has too many teams set.";
274 Com_Printf(
"CountSpawnpoints - error: Too many teams set.\n");
279 EXPECT_GE(spawnTeam, minMP) <<
"Error: Assembly " << asmName <<
" from mapdef " << md->
id <<
", map " << md->
mapTheme
280 <<
"(aircraft: " << aircraft <<
", ufo: " << ufo <<
") in multiplayer mode: Only " << spawnTeam
281 <<
" spawnpoints for team " << currTeamNum <<
" but " << minMP <<
" expected.";
283 Com_Printf(
"CountSpawnpoints - count spawnpoints: player team/needs/found %i/%i/%i\n", currTeamNum, minMP, spawnTeam);
284 if (spawnTeam < minMP)
285 Com_Printf(
"CountSpawnpoints - error: missing spawnpoints - player team/needs/found %i/%i/%i\n", currTeamNum, minMP, spawnTeam);
291 EXPECT_GE(spawnAliens, minAliens) <<
"Assembly " << asmName <<
" from mapdef " << md->
id <<
", map " << md->
mapTheme
292 <<
"(aircraft: " << aircraft <<
", ufo: " << ufo <<
") in multiplayer mode defines at least one coop game mode,"
293 <<
" but does not have enough alien spawn positions for that. We expect at least " << minAliens
294 <<
" spawn positions for aliens, the map provides " << spawnAliens <<
".";
296 Com_Printf(
"CountSpawnpoints - count spawnpoints: alien needs/found %i/%i\n", minAliens, spawnAliens);
297 if (spawnAliens < minAliens)
298 Com_Printf(
"CountSpawnpoints - error: missing spawnpoints - alien needs/found %i/%i\n", minAliens, spawnAliens);
307 std::cout <<
"[ ] adding test parameter: gamemode singleplayer" << std::endl;
308 Com_Printf(
"CountSpawnpoints - adding test parameter: gamemode singleplayer\n");
315 Cvar_Set(
"sv_maxsoldiersperteam",
"12");
316 Cvar_Set(
"ai_singleplayeraliens",
"64");
319 Com_Printf(
"CountSpawnpoints - loading map: mode singleplayer mapdef %s map %s assembly %s dropship %s ufo %s\n", md->
id, md->
mapTheme, asmName, aircraft, ufo);
325 ADD_FAILURE() <<
"Error: Failed to load assembly " << asmName <<
" from mapdef " << md->
id <<
", map "
326 << md->
mapTheme <<
" aircraft: " << aircraft <<
", ufo: " << ufo <<
" => singleplayer mode.";
327 Com_Printf(
"CountSpawnpoints - error: Failed to load map.\n");
332 Com_Printf(
"CountSpawnpoints - result: %li ms\n", time);
350 const int minAliens = std::min(md->
maxAliens, numteamUFO);
359 EXPECT_GE(spawnHumans, minHumans) <<
"Error: Assembly " << asmName <<
" in mapdef " << md->
id
360 <<
" from map " << md->
mapTheme <<
" in singleplayer mode (aircraft: " << aircraft
361 <<
" ufo: " << ufo <<
"): Only " << spawnHumans <<
" human spawnpoints but " << minHumans
364 EXPECT_GE(spawnAliens, minAliens) <<
"Error: Assembly " << asmName <<
" in mapdef " << md->
id
365 <<
" from map " << md->
mapTheme <<
" in singleplayer mode (aircraft: " << aircraft
366 <<
" ufo: " << ufo <<
"): Only " << spawnAliens <<
" alien spawnpoints but " << minAliens
369 EXPECT_GE(spawnHuman2x2, minHuman2x2) <<
"Error: Assembly " << asmName <<
" in mapdef " << md->
id
370 <<
" from map " << md->
mapTheme <<
" in singleplayer mode (aircraft: " << aircraft
371 <<
" ufo: " << ufo <<
"): Only " << spawnHuman2x2 <<
" human 2x2 spawnpoints but " << minHuman2x2
375 EXPECT_GE(md->
maxAliens, numteamUFO) <<
"Error: Assembly " << asmName <<
" in mapdef " << md->
id
376 <<
" from map " << md->
mapTheme <<
" in singleplayer mode (aircraft: " << aircraft
377 <<
" ufo: " << ufo <<
"): The number of aliens allowed on the map is smaller than expected.";
381 Com_Printf(
"CountSpawnpoints - map: mode singleplayer\n");
382 Com_Printf(
"CountSpawnpoints - map: mapdef %s\n", md->
id);
384 Com_Printf(
"CountSpawnpoints - map: assembly %s\n", asmName);
385 Com_Printf(
"CountSpawnpoints - map: aircraft %s \n", aircraft);
386 Com_Printf(
"CountSpawnpoints - map: ufo %s\n", ufo);
387 Com_Printf(
"CountSpawnpoints - count spawnpoints: civilian %i\n", spawnCivs);
388 Com_Printf(
"CountSpawnpoints - count spawnpoints: singleplayer needs/found %i/%i\n", minHumans, spawnHumans);
389 Com_Printf(
"CountSpawnpoints - count spawnpoints: singleplayer_2x2 needs/found %i/%i\n", minHuman2x2, spawnHuman2x2);
390 Com_Printf(
"CountSpawnpoints - count spawnpoints: alien needs/found %i/%i\n", minAliens, spawnAliens);
391 if (spawnHumans < minHumans)
392 Com_Printf(
"CountSpawnpoints - error: missing spawnpoints - singleplayer needs/found %i/%i\n", minHumans, spawnHumans);
393 if (spawnHuman2x2 < minHuman2x2)
394 Com_Printf(
"CountSpawnpoints - error: missing spawnpoints - singleplayer_2x2 needs/found %i/%i\n", minHuman2x2, spawnHuman2x2);
395 if (spawnAliens < minAliens)
396 Com_Printf(
"CountSpawnpoints - error: missing spawnpoints - alien needs/found %i/%i\n", minAliens, spawnAliens);
399 Com_Printf(
"CountSpawnpoints - error: mapdef parameter - maxaliens needs/found %i/%i\n", numteamUFO, md->
maxAliens);
408 if (verbose && ufo) {
409 std::cout <<
"[ ] adding test parameter: ufo " << ufo << std::endl;
410 Com_Printf(
"CountSpawnpoints - adding test parameter: ufo %s\n", ufo);
428 Com_Printf(
"CountSpawnpoints - error: Gamemode not defined in mapdef: %s\n", mode);
429 ADD_FAILURE() <<
"Error: Gamemode not defined in mapdef: " <<
mode;
431 }
else if (
Q_streq(mode,
"mp")) {
435 Com_Printf(
"CountSpawnpoints - error: Gamemode not defined in mapdef: %s\n", mode);
436 ADD_FAILURE() <<
"Error: Gamemode not defined in mapdef: " <<
mode;
439 Com_Printf(
"CountSpawnpoints - error: Not a valid gamemode: %s\n", mode);
440 ADD_FAILURE() <<
"Error: Not a valid gamemode: " <<
mode;
455 if (verbose && aircraft) {
456 std::cout <<
"[ ] adding test parameter: aircraft " << aircraft << std::endl;
457 Com_Printf(
"CountSpawnpoints - adding test parameter: aircraft %s\n", aircraft);
472 Com_Printf(
"CountSpawnpoints - error: Not a valid UFO id: %s\n", ufo);
473 ADD_FAILURE() <<
"Error: Not a valid ufo id: " << ufo;
491 std::cout <<
"[ ] testing mapdef: " << md->
id <<
" assembly: " << asmName << std::endl;
492 Com_Printf(
"CountSpawnpoints - adding test parameter: assembly %s\n", asmName);
494 std::cout <<
"[ ] testing mapdef: " << md->
id << std::endl;
509 Com_Printf(
"CountSpawnpoints - error: Not a valid aircraft id: %s\n", aircraft);
510 ADD_FAILURE() <<
"Error: Not a valid aircraft id: " << aircraft;
527 Com_Printf(
"CountSpawnpoints - test start: mapdef %s\n", md->
id);
540 Com_Printf(
"CountSpawnpoints - error: Not a valid assembly: %s\n", asmName);
541 ADD_FAILURE() <<
"Error: Not a valid assembly: " << asmName;
545 std::cout <<
"[ ] testing mapdef: " << md->
id << std::endl;
557 bool verbose =
false;
570 testCountSpawnpointsForMap(verbose, md);
572 std::cout <<
"[ ] Static maps tested: " <<
mapCount << std::endl;
578 bool verbose =
false;
591 testCountSpawnpointsForMap(verbose, md);
596 Com_Printf(
"CountSpawnpoints - error: Not a valid mapdef: %s\n", mapdefId);
597 ADD_FAILURE() <<
"Error: Not a valid mapdef: " << mapdefId;
608 testCountSpawnpointsForMap(verbose, md);
612 std::cout <<
"[ ] RMA combinations tested: " <<
mapCount << std::endl;
618 const char*
mapName =
"test_game";
619 ASSERT_NE(-1,
FS_CheckFile(
"maps/%s.bsp", mapName)) <<
"Map resource '" << mapName <<
".bsp' for test is missing.";
624 SV_Map(
true, mapName,
nullptr);
630 ASSERT_TRUE(e->
doorState) <<
"this one is triggered by an actor standing inside of a trigger_touch";
632 ASSERT_FALSE(e->
doorState) <<
"this one has a trigger_touch, too - but nobody is touching that trigger yet";
634 ASSERT_TRUE(
false) <<
"both of the used doors have a targetname set";
639 ASSERT_TRUE(cnt > 0);
640 ASSERT_TRUE(doors == 2);
645 const char*
mapName =
"test_game";
646 ASSERT_NE(-1,
FS_CheckFile(
"maps/%s.bsp", mapName)) <<
"Map resource '" << mapName <<
".bsp' for test is missing.";
647 SV_Map(
true, mapName,
nullptr);
658 while (invlist !=
nullptr) {
668 const char*
mapName =
"test_game";
669 ASSERT_NE(-1,
FS_CheckFile(
"maps/%s.bsp", mapName)) <<
"Map resource '" << mapName <<
".bsp' for test is missing.";
672 SV_Map(
true, mapName,
nullptr);
675 Actor* actor =
nullptr;
678 const bool visible = actor->
visflags & teamMask;
682 ASSERT_TRUE(visible) <<
"visflags: " << visFlagsBuf <<
", teamMask: " << teamMaskBuf;
688 ASSERT_TRUE(num > 0) <<
"No alien actors found";
693 const char*
mapName =
"test_game";
694 ASSERT_NE(-1,
FS_CheckFile(
"maps/%s.bsp", mapName)) <<
"Map resource '" << mapName <<
".bsp' for test is missing.";
700 SV_Map(
true, mapName,
nullptr);
705 ASSERT_TRUE(
nullptr != diedEnt);
708 ASSERT_TRUE(diedEnt->
isDead());
712 ASSERT_TRUE(
nullptr != actor);
715 Player& player = actor->getPlayer();
721 ASSERT_TRUE(
nullptr != floorItems);
722 ASSERT_EQ(floorItems->
getFloor(), actor->getFloor());
729 ASSERT_TRUE(
nullptr == invlist);
732 Item* entryToMove = actor->getFloor();
737 Com_Printf(
"trying to move item %s from floor into backpack to pos %i:%i\n", entryToMove->
def()->
name, tx, ty);
742 Com_Printf(
"item %s was moved successfully into the backpack\n", entryToMove->
def()->
name);
744 ASSERT_TRUE(
nullptr != invlist);
750 const char*
mapName =
"test_game";
751 ASSERT_NE(-1,
FS_CheckFile(
"maps/%s.bsp", mapName)) <<
"Map resource '" << mapName <<
".bsp' for test is missing.";
758 SV_Map(
true, mapName,
nullptr);
763 ASSERT_TRUE(
nullptr != diedEnt) <<
"No living actor in the alien team";
766 ASSERT_TRUE(diedEnt->
isDead()) <<
"Actor is not dead";
770 ASSERT_TRUE(
nullptr != diedEnt2) <<
"No living actor in the alien team";
773 Player& player = diedEnt2->getPlayer();
780 ASSERT_TRUE(diedEnt2->isDead()) <<
"Actor is not dead";
784 ASSERT_TRUE(
nullptr != actor) <<
"No living actor in the alien team";
786 player = actor->getPlayer();
787 ASSERT_TRUE(
G_IsAIPlayer(&player)) <<
"Player is not ai controlled";
790 ASSERT_TRUE(
VectorCompare(actor->pos, diedEnt->
pos)) <<
"Actor is not at the same position as the died entity";
793 ASSERT_TRUE(
nullptr != floorItems);
794 ASSERT_EQ(floorItems->
getFloor(), actor->getFloor());
801 ASSERT_TRUE(
nullptr == invlist);
805 Item* entryToMove = actor->getFloor();
810 Com_Printf(
"trying to move item %s from floor into backpack to pos %i:%i\n", entryToMove->
def()->
name, tx, ty);
815 Com_Printf(
"item %s was moved successfully into the backpack\n", entryToMove->
def()->
name);
817 ASSERT_TRUE(
nullptr != invlist);
823 const char*
mapName =
"test_game";
824 ASSERT_NE(-1,
FS_CheckFile(
"maps/%s.bsp", mapName)) <<
"Map resource '" << mapName <<
".bsp' for test is missing.";
825 SV_Map(
true, mapName,
nullptr);
837 ASSERT_TRUE(nr > 0) <<
"Could not find any items in the inventory of the actor";
839 ASSERT_TRUE(
nullptr == actor->
getFloor());
841 ASSERT_TRUE(
nullptr != actor->
getFloor());
bool Q_strnull(const char *string)
Edict * G_EdictsGetNextInUse(Edict *lastEnt)
Iterate through the entities that are in use.
int testCountSpawnpointsGetNum2x2ValueForAircraft(const char *aircraft)
int FS_CheckFile(const char *fmt,...)
Just returns the filelength and -1 if the file wasn't found.
static void TearDownTestCase()
static int GAMETEST_GetItemCount(const Edict *ent, containerIndex_t container)
static void SetUpTestCase()
void G_ClientMove(const Player &player, int visTeam, Actor *actor, const pos3_t to)
Generates the client events that are send over the netchannel to move an actor.
memPool_t * sv_genericPool
void SV_Map(bool day, const char *levelstring, const char *assembly, bool verbose=true)
Change the server to a new map, taking all connected clients along with it.
const objDef_t * def(void) const
void Com_ParseScripts(bool onlyServer)
int FS_LoadFile(const char *path, byte **buffer)
Filenames are relative to the quake search path.
void Com_Printf(const char *const fmt,...)
gltexunit_t texunits[MAX_GL_TEXUNITS]
void testCountSpawnpointsForMapInSingleplayerMode(bool verbose, const mapDef_t *md, const char *asmName, const char *aircraft, const char *ufo)
cvar_t * masterserver_url
cvarlist_t cvars[MAX_CVARLISTINGAMETYPE]
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...
Item * getContainer(const containerIndex_t idx) const
item instance data, with linked list capability
serverInstanceGame_t * sv
int testCountSpawnpointsGetNumteamValueForAircraft(const char *aircraft)
void G_InventoryToFloor(Edict *ent)
Move items to adjacent locations if the containers on the current floor edict are full...
void testCountSpawnpointsForMapWithAssembly(bool verbose, const mapDef_t *md, const char *asmName)
gltexunit_t * active_texunit
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
byte num_spawnpoints[MAX_TEAMS]
void testCountSpawnpointsForMapWithAssemblyAndAircraftAndUfo(bool verbose, const mapDef_t *md, const char *asmName, const char *aircraft, const char *ufo)
TEST_F(GameTest, SpawnAndConnect)
gametype_t gts[MAX_GAMETYPES]
void testCountSpawnpointsForMapInMultiplayerMode(bool verbose, const mapDef_t *md, const char *asmName, const char *aircraft, const char *ufo)
void testCountSpawnpointsForMapWithAssemblyAndAircraft(bool verbose, const mapDef_t *md, const char *asmName, const char *aircraft)
#define Mem_CreatePool(name)
Edict * G_GetFloorItemFromPos(const pos3_t pos)
Callback to G_GetEdictFromPos() for given position, used to get items from position.
#define INVDEF(containerID)
int countItems() const
Count the number of items in the Container.
void testCountSpawnpointsForMap(bool verbose, const mapDef_t *md)
bool G_ActorInvMove(Actor *actor, const invDef_t *fromContType, Item *fItem, const invDef_t *toContType, int tx, int ty, bool checkaction)
Moves an item inside an inventory. Floors are handled special.
#define VectorCompare(a, b)
#define G_TeamToVisMask(team)
const char * Com_UnsignedIntToBinary(uint32_t x)
void SV_ClearWorld(void)
Clear physics interaction links.
bool TEST_ExistsProperty(const char *name)
memPool_t * com_networkPool
Actor * G_EdictsGetNextLivingActorOfTeam(Actor *lastEnt, const int team)
Iterate through the living actor entities of the given team.
const char * TEST_GetStringProperty(const char *name)
const Container * getNextCont(const Container *prev, bool inclTemp=false) const
void SV_InitGameProgs(void)
Init the game subsystem for a new map.
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
#define LIST_Foreach(list, type, var)
Iterates over a linked list, it's safe to delete the returned entry from the list while looping over ...
bool G_ActorDieOrStun(Actor *actor, Edict *attacker)
Reports and handles death or stun of an actor. If the HP of an actor is zero the actor will die...
byte num_2x2spawnpoints[MAX_TEAMS]
#define MapDef_Foreach(var)
Edict * G_GetFloorItems(Edict *ent)
Prepares a list of items on the floor at given entity position.
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
bool LIST_IsEmpty(const linkedList_t *list)
Checks whether the given list is empty.
Player * G_PlayerGetNextHuman(Player *lastPlayer)
Iterate through the list of players.
void SV_ShutdownGameProgs(void)
Called when either the entire server is being killed, or it is changing to a different game directory...
#define G_IsAIPlayer(player)
serverInstanceStatic_t svs
static const char * mapName
void FS_FreeFile(void *buffer)
int Sys_Milliseconds(void)
int testCountSpawnpointsGetNumteamValueForUFO(const char *ufo)