26 #include "../client/client.h"
27 #include "../client/cl_lua.h"
28 #include "../client/cgame/cl_game.h"
29 #include "../client/renderer/r_state.h"
30 #include "../client/ui/ui_main.h"
31 #include "../client/cgame/campaign/cp_campaign.h"
32 #include "../client/cgame/campaign/cp_geoscape.h"
33 #include "../client/cgame/campaign/cp_hospital.h"
34 #include "../client/cgame/campaign/cp_missions.h"
35 #include "../client/cgame/campaign/cp_nation.h"
36 #include "../client/cgame/campaign/cp_overlay.h"
37 #include "../client/cgame/campaign/cp_ufo.h"
38 #include "../client/cgame/campaign/cp_time.h"
39 #include "../client/cgame/campaign/cp_alien_interest.h"
40 #include "../client/cgame/campaign/cp_auto_mission.h"
41 #include "../client/cgame/campaign/itemcargo.h"
42 #include "../client/cgame/campaign/missions/cp_mission_intercept.h"
43 #include "../shared/parse.h"
44 #include "../shared/images.h"
159 const vec2_t destination = { 10, 10 };
169 base =
CreateBase(
"unittestaircraft", destination);
170 ASSERT_TRUE(
nullptr != base);
174 ASSERT_TRUE(
nullptr != aircraft);
177 aircraftTemplate = aircraft->
tpl;
178 ASSERT_TRUE(
nullptr != aircraftTemplate);
180 firstIdx = aircraft->
idx;
186 ASSERT_EQ(count, initialCount - 1);
190 ASSERT_TRUE(
nullptr != newAircraft);
192 ASSERT_EQ(count, initialCount);
195 ASSERT_EQ(newAircraft->
homebase, base);
200 ASSERT_NE(firstIdx, a->idx);
202 if (a->idx == newAircraft->
idx)
206 ASSERT_EQ(newFound, 1);
213 ASSERT_TRUE(
nullptr == aircraft);
232 ASSERT_TRUE(
nullptr != e);
245 const int amount = 3;
246 for (i = 0; i < amount; i++) {
248 ASSERT_TRUE(
nullptr != e);
257 ASSERT_EQ(cnt, amount);
271 ASSERT_TRUE(
nullptr != e);
277 for (i = 0; i < 512; i++) {
279 ASSERT_TRUE(
nullptr != e);
282 ASSERT_EQ(cnt, i + 1);
315 const vec2_t pos = {-73.2, 18.5};
324 ASSERT_TRUE(campaign !=
nullptr);
332 base =
CreateBase(
"unittestautomission", pos);
333 ASSERT_TRUE(
nullptr != base);
342 ASSERT_TRUE(
nullptr != aircraft);
349 ASSERT_TRUE(
nullptr != mission);
352 AM_Go(mission, aircraft, campaign, &battleParameters, &result);
360 const vec2_t pos = {0, 0};
361 const vec2_t posTarget = {51, 0};
365 ASSERT_TRUE(
nullptr != base);
366 base_t* targetBase =
CreateBase(
"unittesttransferitemtargetbase", posTarget,
true);
367 ASSERT_TRUE(
nullptr != targetBase);
371 ASSERT_TRUE(
nullptr != od);
380 ASSERT_TRUE(
nullptr != transfer);
404 ASSERT_TRUE(
nullptr != transfer);
417 ASSERT_TRUE(
nullptr != transfer);
440 const vec2_t pos = {0, 0};
447 ASSERT_TRUE(
nullptr != ufo);
454 storedUFO =
US_StoreUFO(ufo, installation, date, 1.0);
455 ASSERT_TRUE(
nullptr != storedUFO);
486 ASSERT_TRUE(
nullptr != laserTech);
488 ASSERT_TRUE(
nullptr != otherLaserTech);
490 const vec2_t pos = {0, 0};
497 ASSERT_EQ(laserTech->
base, base);
504 for (
int i = 0;
i < n;
i++) {
506 ASSERT_EQ(finished, 0) <<
"Did not expect to finish a research (#" << finished <<
", i:" <<
i <<
")";
523 const vec2_t pos = {0, 0};
540 ASSERT_TRUE(
nullptr != od);
545 ASSERT_TRUE(
nullptr != prod);
550 for (i = 0; i < n; i++) {
566 const vec2_t pos = {0, 0};
583 ASSERT_TRUE(
nullptr != aircraft);
586 ASSERT_TRUE(
nullptr ==
PR_QueueNew(base, &data, 1));
590 ASSERT_TRUE(
nullptr != aircraft);
593 ASSERT_TRUE(
nullptr != prod);
598 for (i = 0; i < n; i++) {
614 const vec2_t pos = {0, 0};
632 ASSERT_TRUE(
nullptr != ufo);
637 ASSERT_TRUE(
nullptr != storedUFO);
641 ASSERT_TRUE(
nullptr != prod);
647 for (i = 0; i < n; i++) {
682 const vec2_t destination = { 10, 10 };
685 const int deltaTime = 1000;
690 ASSERT_TRUE(
nullptr != base);
699 ASSERT_TRUE(
nullptr != aircraft);
707 ASSERT_TRUE(
nullptr != ufoTemplate);
712 ASSERT_TRUE(
nullptr != mission);
719 ASSERT_TRUE(
nullptr != ufo);
762 const vec2_t destination = { 10, 10 };
789 ASSERT_TRUE(
nullptr != nation);
813 const vec2_t pos = {0, 0};
851 ASSERT_STREQ(base->
name,
"unittestbase");
871 const vec2_t pos = {0, 0};
875 ASSERT_TRUE(
nullptr != nation);
877 const int employees = 10000;
878 for (
int i = 0;
i < employees;
i++) {
903 const vec2_t destination = { 10, 10 };
916 for (
int i = 0;
i < seconds;
i++) {
990 const vec2_t destination = { 10, 10 };
992 base =
CreateBase(
"unittestcampaigntime", destination);
1020 const vec2_t destination = { 10, 10 };
1023 base =
CreateBase(
"unittesthospital", destination);
1030 if (!employee->isHired())
1032 employee->chr.HP = employee->chr.maxHP - 10;
1043 if (!employee->isHired())
1045 ASSERT_NE(employee->chr.HP, employee->chr.maxHP - 10) << employee->chr.HP <<
"/" << employee->chr.maxHP;
1057 const vec2_t pos = {0, 0};
1061 building_t* entrance, *building1, *building2;
1066 base =
CreateBase(
"unittestbuildingconstruction1", pos);
1067 ASSERT_TRUE(
nullptr != base);
1068 base =
CreateBase(
"unittestbuildingconstruction2", pos);
1069 ASSERT_TRUE(
nullptr != base);
1077 ASSERT_TRUE(
nullptr != buildingTemplate);
1080 x = entrance->
pos[0];
1081 y = entrance->
pos[1];
1091 ASSERT_TRUE(
nullptr == building1);
1094 x = (x + entrance->
pos[0]) /2;
1097 ASSERT_TRUE(
nullptr != building1);
1100 if (x < entrance->pos[0])
1105 ASSERT_TRUE(
nullptr == building2);
1119 ASSERT_TRUE(
nullptr != building2);
1125 ASSERT_TRUE(
nullptr != building2);
1148 const char* error =
nullptr;
1152 ASSERT_TRUE(success) << error;
1157 const char* map = md->
id;
1170 for (i = 0; i < ufoIdsNum; i++) {
1184 ASSERT_TRUE(
CP_ChooseMap(&mission, city->
pos)) <<
"could not find a map for city " << city->id;
1189 ASSERT_NE(0, numUfoTypes);
1190 for (i = 0; i < numUfoTypes; i++) {
1197 ASSERT_TRUE(
nullptr != ufo);
1201 mission.
mapDef =
nullptr;
1203 ASSERT_TRUE(
CP_ChooseMap(&mission, city->
pos)) <<
"could not find map for city " << city->
id <<
" with ufo: " << ufo->
id;
1222 for (i = 0; i < numUfoTypes; i++) {
1237 ASSERT_TRUE(
va(
"%s wasn't used", md->
id));
1251 ASSERT_TRUE(result) <<
"could not find a mission for mapdef " << md->
id;
1265 for (
int i = 0;
i < 60;
i++) {
1272 event->active =
true;
1275 event->command =
Mem_StrDup(
"test_eventtrigger");
1276 event->require =
Mem_StrDup(
"ufo[craft_ufo_harvester]");
1294 const int expected = 22;
1296 ASSERT_TRUE(maxSize >= expected);
1298 const vec2_t destination = { 10, 10 };
1300 ASSERT_TRUE(
nullptr != base);
1304 ASSERT_TRUE(
B_AssembleMap(maps,
sizeof(maps), coords,
sizeof(coords), base));
1305 const char* str = coords;
1306 int coordsAmount = 0;
1311 }
while (str !=
nullptr);
1319 }
while (str !=
nullptr);
1322 ASSERT_EQ(coordsAmount / 3, expected) <<
"coords have " << coordsAmount <<
" entries: '" << coords <<
"'";
1323 ASSERT_EQ(mapsAmount, expected) <<
"maps have " << mapsAmount <<
" entries: '"<< maps <<
"'";
1328 const char* types[] = {
"terrain",
"culture",
"population",
"nations",
nullptr};
1334 for (
const char **t = types; *t; ++t) {
1335 const char *image =
va(
"pics/geoscape/%s_%s", c.
map, *t);
1337 ASSERT_TRUE(surf !=
nullptr);
1338 const int w = surf->w;
1339 const int h = surf->h;
1344 SDL_FreeSurface(surf);
bool CP_IsTimeStopped(void)
Check if time is stopped.
void SAV_Init(void)
Register all save-subsystems and init some cvars and commands.
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
production_t * PR_QueueNew(base_t *base, const productionData_t *data, signed int amount)
Add a new item to the bottom of the production queue.
nation_t * NAT_GetNationByID(const char *nationID)
Return a nation-pointer by the nations id.
bool Date_IsDue(const date_t *date)
Checks whether a given date is equal or earlier than the current campaign date.
int numCampaignTriggerEvents
virtual bool add(const objDef_t *od, int amount, int looseAmount)
Add items to the cargo.
A building with all it's data.
storedUFO_t * US_StoreUFO(const aircraft_t *ufoTemplate, installation_t *installation, date_t date, float condition)
Adds an UFO to the storage.
const installationTemplate_t * INS_GetInstallationTemplateByType(installationType_t type)
Returns the installation Template for a given installation type.
void Cmd_RemoveCommand(const char *cmdName)
Removes a command from script interface.
void B_UpdateBuildingConstructions(void)
Updates base data.
const objDef_t * INVSH_GetItemByID(const char *id)
Returns the item that belongs to the given id or nullptr if it wasn't found.
A installation with all it's data.
QGL_EXTERN GLint GLenum type
bool B_GetBuildingStatus(const base_t *const base, const buildingType_t buildingType)
Get the status associated to a building.
bool CP_ChooseMap(mission_t *mission, const vec2_t pos)
Choose a map for given mission.
aircraft_t * AIR_NewAircraft(base_t *base, const aircraft_t *aircraftTemplate)
Places a new aircraft in the given base.
static base_t * CreateBase(const char *name, const vec2_t pos, bool fillBase=false)
void GEO_Init(const char *map)
void CP_InterceptNextStage(mission_t *mission)
Determine what action should be performed when a Intercept mission stage ends.
void RS_MarkOneResearchable(technology_t *tech)
Marks one tech as researchable.
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...
void INT_ResetAlienInterest(void)
Initialize alien interest values and mission cycle.
float ufoDetectionProbability
#define E_Foreach(employeeType, var)
static void FreeAllInventory(void)
researchStatus_t statusResearch
void INS_UpdateInstallationData(void)
Check if some installation are build.
void UFO_CampaignRunUFOs(const campaign_t *campaign, int deltaTime)
Make the UFOs run.
Defines a type of UGV/Robot.
linkedList_t * populations
#define Mem_PoolAlloc(size, pool, tagNum)
static const inventoryImport_t inventoryImport
void RS_MarkResearchable(const base_t *base, bool init)
Marks all the techs that can be researched. Automatically researches 'free' techs such as ammo for a ...
#define B_AtLeastOneExists()
void Com_ParseScripts(bool onlyServer)
aircraft_t * UFO_AddToGeoscape(ufoType_t ufoType, const vec2_t destination, mission_t *mission)
Add a UFO to geoscape.
void CP_ResetCampaignData(void)
Will clear most of the parsed singleplayer data.
const aircraft_t * AIR_GetAircraft(const char *name)
Searches the global array of aircraft types for a given aircraft.
const byte * GEO_GetColor(const vec2_t pos, mapType_t type, bool *coast)
Returns the color value from geoscape of a certain mask (terrain, culture or population) at a given p...
void BS_InitMarket(const campaign_t *campaign)
sets market prices at start of the game
aircraft_t * UFO_GetNextOnGeoscape(aircraft_t *lastUFO)
#define PR_SetData(dataPtr, typeVal, ptr)
Defines all attributes of objects used in the inventory.
gltexunit_t texunits[MAX_GL_TEXUNITS]
building_t * B_GetBuildingTemplate(const char *buildingName)
Returns the building in the global building-types list that has the unique name buildingID.
bool Date_LaterThan(const date_t *now, const date_t *compare)
Check whether the given date and time is later than current date.
struct mission_s * mission
memPool_t * cp_campaignPool
#define CAP_GetCurrent(base, capacity)
int E_CountHired(const base_t *const base, employeeType_t type)
Counts hired employees of a given type in a given base.
building_t * B_BuildBuilding(base_t *base, const building_t *buildingTemplate, int col, int row)
Build a new building to the base.
A base with all it's data.
int LIST_Count(const linkedList_t *list)
memPool_t * cl_genericPool
void CP_ReadCampaignData(const campaign_t *campaign)
int CAP_GetFreeCapacity(const base_t *base, baseCapacities_t capacityType)
Returns the free capacity of a type.
bool E_HireEmployee(base_t *base, Employee *employee)
Hires the employee in a base.
static void SetUpTestCase()
void Cmd_ExecuteString(const char *text,...)
A complete command line has been parsed, so try to execute it.
struct technology_s * tech
bool E_DeleteEmployee(Employee *employee)
Removes the employee completely from the game (buildings + global list).
int PR_WorkersAvailable(const base_t *base)
Returns the numer of workers available to produce an item.
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.
int UFO_GetAvailableUFOsForMission(const interestCategory_t missionType, ufoType_t *ufoTypes, bool checkInterest)
Fill an array with available UFOs for the mission type.
void CP_UpdateTime(void)
Updates date/time and timescale (=timelapse) on the geoscape menu.
int PR_GetRemainingHours(const production_t *prod)
Calculates the remaining hours for a technology.
const aircraft_t * UFO_GetByType(const ufoType_t type)
Get the aircraft template for a given UFO type.
aircraft_t * AIR_GetFirstFromBase(const base_t *b)
Iterates through the aircraft of a base.
#define Vector2Set(v, x, y)
TEST_F(CampaignTest, testAircraftHandling)
void CL_InitLua(void)
Initializes the ui-lua interfacing environment.
void CP_CampaignRun(campaign_t *campaign, float secondsSinceLastFrame)
Called every frame when we are in geoscape view.
void UR_ProcessActive(void)
Function to process active recoveries.
void initInventory(const char *name, const csi_t *csi, const inventoryImport_t *import)
Initializes the inventory definition by linking the ->next pointers properly.
short Com_GetUfoIdsNum(void)
Employee * E_CreateEmployee(employeeType_t type, const nation_t *nation, const ugv_t *ugvType)
Creates an entry of a new employee in the global list and assignes it to no building/base.
void CP_ParseCampaignData(void)
Read the data for campaigns.
memPool_t * com_genericPool
static bool skipTest(const mapDef_t *md)
class ItemCargo * itemCargo
Structure for stored UFOs.
void B_SetUpFirstBase(const campaign_t *campaign, base_t *base)
Setup aircraft and equipment for first base. Uses the campaign scriptable equipmentlist.
static void testEventTrigger_f(void)
employeeType_t
The types of employees.
static void FreeInventory(void *data)
void CP_UpdateCredits(int credits)
Sets credits and update mn_credits cvar.
struct aircraft_s * aircraftTarget
This is the technology parsed from research.ufo.
campaign_t * CP_GetCampaign(const char *name)
Returns the campaign pointer from global campaign array.
SDL_Surface * Img_LoadImage(char const *name)
Loads the specified image from the game filesystem and populates the provided SDL_Surface.
#define Mem_CreatePool(name)
int ufoInterestOnGeoscape
Engine-side time information in the game.
void CP_TriggerEvent(campaignTriggerEventType_t type, const void *userdata)
Triggers a campaign event with a special type.
void CP_CreateBattleParameters(mission_t *mission, battleParam_t *param, const aircraft_t *aircraft)
Create parameters needed for battle. This is the data that is used for starting the tactical part of ...
baseBuildingTile_t map[BASE_SIZE][BASE_SIZE]
const linkedList_t * LIST_ContainsString(const linkedList_t *list, const char *string)
Searches for the first occurrence of a given string.
int AIR_BaseCountAircraft(const base_t *base)
Returns the number of aircraft on the given base.
#define MapDef_ForeachSingleplayerCampaign(var)
aircraftSlot_t weapons[MAX_AIRCRAFTSLOT]
#define MAX_INSTALLATIONS_PER_BASE
mapDef_t * Com_GetMapDefinitionByID(const char *mapDefID)
void AM_Go(mission_t *mission, aircraft_t *aircraft, const campaign_t *campaign, const battleParam_t *battleParameters, missionResults_t *results)
Handles the auto mission.
bool CP_GetRandomPosOnGeoscapeWithParameters(vec2_t pos, const linkedList_t *terrainTypes, const linkedList_t *cultureTypes, const linkedList_t *populationTypes, const linkedList_t *nations)
Determines a random position on geoscape that fulfills certain criteria given via parameters...
const installationTemplate_t * installationTemplate
technology_t * RS_GetTechByID(const char *id)
return a pointer to the technology identified by given id string
void B_Destroy(base_t *base)
Destroy a base.
installation_t * INS_Build(const installationTemplate_t *installationTemplate, const vec2_t pos, const char *name)
Build a new installation.
const GLuint *typedef void(APIENTRY *GenRenderbuffersEXT_t)(GLsizei
bool AIR_IsAircraftOnGeoscape(const aircraft_t *aircraft)
Checks whether given aircraft is on geoscape.
static const int TAG_INVENTORY
int numBuildings[MAX_BASES]
#define AIR_ForeachFromBase(var, base)
iterates trough all aircraft from a specific homebase
bool PR_ProductionAllowed(const base_t *base)
Returns true if the current base is able to produce items.
static bool testEventTriggerCalled
int E_CountUnhired(employeeType_t type)
Counts unhired employees of a given type in a given base.
static void ResetInventoryList(void)
const char * Com_Parse(const char *data_p[], char *target, size_t size, bool replaceWhitespaces)
Parse a token out of a string.
transfer_t * TR_TransferStart(base_t *srcBase, transfer_t &transData)
Starts a transfer.
int PR_GetRemainingMinutes(const production_t *prod)
Calculates the remaining time for a technology in minutes.
int B_GetInstallationLimit(void)
Counts the actual installation count limit.
#define Mem_FreeTag(pool, tagNum)
void RS_InitTree(const campaign_t *campaign, bool load)
Gets all needed names/file-paths/etc... for each technology entry. Should be executed after the parsi...
void CL_SetClientState(connstate_t state)
Sets the client state.
int AIR_GetTeamSize(const aircraft_t *aircraft)
Counts the number of soldiers in given aircraft.
int numItems[MAX_OBJDEFS]
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
campaignTriggerEvent_t campaignTriggerEvents[MAX_CAMPAIGN_TRIGGER_EVENTS]
bool RADAR_CheckUFOSensored(radar_t *radar, const vec2_t posRadar, const aircraft_t *ufo, bool detected)
Check if the specified UFO is inside the sensor range of the given radar.
#define MapIsWater(color)
Transfer information (they are being stored in ccs.transfers).
#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 ...
void E_InitialEmployees(const campaign_t *campaign)
Create initial hireable employees.
#define Vector2Copy(src, dest)
memPool_t * vid_imagePool
void UFO_SendToDestination(aircraft_t *ufo, const vec2_t dest)
Make the specified UFO go to destination.
void E_DeleteAllEmployees(base_t *base)
Removes all employees completely from the game (buildings + global list) from a given base...
bool B_AssembleMap(char *maps, size_t mapsLength, char *coords, size_t coordsLength, const base_t *base)
Perform the base assembling in case of an alien attack.
static campaign_t * GetCampaign(void)
void GAME_InitStartup(void)
void HOS_HospitalRun(void)
Checks health status of all employees in all bases.
GLsizei const GLvoid * data
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
building_t buildings[MAX_BASES][MAX_BUILDINGS]
#define AIR_Foreach(var)
iterates trough all aircraft
static installation_t * CreateInstallation(const char *name, const vec2_t pos)
bool LIST_IsEmpty(const linkedList_t *list)
Checks whether the given list is empty.
void Cmd_Dummy_f(void)
Dummy binding if you don't want unknown commands forwarded to the server.
int RS_ResearchRun(void)
Checks the research status.
An aircraft with all it's data.
bool B_BuildingDestroy(building_t *building)
Removes a building from the given base.
technology_t * RS_GetTechForItem(const objDef_t *item)
Returns technology entry for an item.
void RS_AssignScientist(technology_t *tech, base_t *base, Employee *employee)
Assigns scientist to the selected research-project.
static void * AllocInventoryMemory(size_t size)
void destroyInventoryInterface(void)
buildingStatus_t buildingStatus
void UFO_RemoveFromGeoscape(aircraft_t *ufo)
Remove the specified ufo from geoscape.
void TR_TransferRun(void)
Checks whether given transfer should be processed.
#define VectorEqual(a, b)
void CP_CampaignRunMarket(campaign_t *campaign)
make number of items change every day.
int skills[SKILL_NUM_TYPES]
Holds all information for the production of one item-type.
base_t * B_Build(const campaign_t *campaign, const vec2_t pos, const char *name, bool fillBase)
Build new base, uses template for the first base.
Structure with mission info needed to create results summary at menu won.
campaign_t campaigns[MAX_CAMPAIGNS]
void AIRFIGHT_CampaignRunProjectiles(const campaign_t *campaign, int dt)
Update values of projectiles.
void PR_ProductionRun(void)
Checks whether an item is finished.
void NAT_HandleBudget(const campaign_t *campaign)
Update the nation data from all parsed nation each month.
struct components_s * comp
void B_SetName(base_t *base, const char *name)
Set the base name.
bool SAV_GameLoad(const char *file, const char **error)
Loads the given savegame from an xml File.
mission_t * CP_CreateNewMission(interestCategory_t category, bool beginNow)
Create a new mission of given category.
const ugv_t * Com_GetUGVByID(const char *ugvID)
Searches an UGV definition by a given script id and returns the pointer to the global data...
void UFO_CheckShootBack(const campaign_t *campaign, aircraft_t *ufo, aircraft_t *phalanxAircraft)
Check if the ufo can shoot back at phalanx aircraft.
int Sys_Milliseconds(void)
void AIR_DeleteAircraft(aircraft_t *aircraft)
Removes an aircraft from its base and the game.
static void TearDownTestCase()