UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
cp_campaign.cpp File Reference

Single player campaign control. More...

#include "../../cl_shared.h"
#include "../../ui/ui_main.h"
#include "../cgame.h"
#include "cp_campaign.h"
#include "cp_capacity.h"
#include "cp_character.h"
#include "cp_overlay.h"
#include "cp_mapfightequip.h"
#include "cp_hospital.h"
#include "cp_hospital_callbacks.h"
#include "cp_base_callbacks.h"
#include "cp_basedefence_callbacks.h"
#include "cp_team.h"
#include "cp_team_callbacks.h"
#include "cp_popup.h"
#include "cp_geoscape.h"
#include "cp_ufo.h"
#include "cp_installation_callbacks.h"
#include "cp_alien_interest.h"
#include "cp_missions.h"
#include "cp_mission_triggers.h"
#include "cp_nation.h"
#include "cp_statistics.h"
#include "cp_time.h"
#include "cp_xvi.h"
#include "cp_fightequip_callbacks.h"
#include "cp_produce_callbacks.h"
#include "cp_transfer.h"
#include "cp_market_callbacks.h"
#include "cp_research_callbacks.h"
#include "cp_uforecovery.h"
#include "save/save_campaign.h"
#include "cp_auto_mission.h"
#include "missions/cp_mission_baseattack.h"
#include "missions/cp_mission_ufocarrier.h"

Go to the source code of this file.

Macros

#define NATIONBELOWLIMITPERCENTAGE   0.5f
 

Functions

bool CP_IsRunning (void)
 Checks whether a campaign mode game is running. More...
 
void CP_EndCampaign (bool won)
 Function to handle the campaign end. More...
 
void CP_CheckLostCondition (const campaign_t *campaign)
 Checks whether the player has lost the campaign. More...
 
static void CP_CheckMissionEnd (const campaign_t *campaign)
 Check for missions that have a timeout defined. More...
 
static void CP_CampaignFunctionPeriodicCall (campaign_t *campaign, int dt, bool updateRadarOverlay)
 Functions that should be called with a minimum time lapse (will be called at least every DETECTION_INTERVAL) More...
 
bool CP_OnGeoscape (void)
 Returns if we are currently on the Geoscape. More...
 
static void CP_AdvanceTimeBySeconds (int seconds)
 Ensure that the day always matches the seconds. If the seconds per day limit is reached, the seconds are reset and the day is increased. More...
 
static bool CP_IsBudgetDue (const dateLong_t *oldDate, const dateLong_t *date)
 
void CP_CampaignRun (campaign_t *campaign, float secondsSinceLastFrame)
 Called every frame when we are in geoscape view. More...
 
bool CP_CheckCredits (int costs)
 Checks whether you have enough credits for something. More...
 
void CP_UpdateCredits (int credits)
 Sets credits and update mn_credits cvar. More...
 
static bool CP_LoadMapDefStatXML (xmlNode_t *parent)
 Load mapDef statistics. More...
 
bool CP_LoadXML (xmlNode_t *parent)
 Load callback for savegames in XML Format. More...
 
static bool CP_SaveMapDefStatXML (xmlNode_t *parent)
 Save mapDef statistics. More...
 
bool CP_SaveXML (xmlNode_t *parent)
 Save callback for savegames in XML Format. More...
 
void CP_StartSelectedMission (void)
 Starts a selected mission. More...
 
static void CP_AddCampaignCallbackCommands (void)
 registers callback commands that are used by campaign More...
 
static void CP_AddCampaignCommands (void)
 
static void CP_RemoveCampaignCallbackCommands (void)
 registers callback commands that are used by campaign More...
 
static void CP_RemoveCampaignCommands (void)
 
void CP_CampaignInit (campaign_t *campaign, bool load)
 Called at new game and load game. More...
 
void CP_Shutdown (void)
 Campaign closing actions. More...
 
campaign_tCP_GetCampaign (const char *name)
 Returns the campaign pointer from global campaign array. More...
 
void CP_ResetCampaignData (void)
 Will clear most of the parsed singleplayer data. More...
 
int CP_GetSalaryUpKeepBase (const salary_t *salary, const base_t *base)
 
void CP_InitStartup (void)
 

Variables

memPool_tcp_campaignPool
 
ccs_t ccs
 
cvar_tcp_missiontest
 
const int DETECTION_INTERVAL = (SECONDS_PER_HOUR / 2)
 delay between actions that must be executed independently of time scale More...
 
static const cmdList_t game_commands []
 

Detailed Description

Single player campaign control.

Definition in file cp_campaign.cpp.

Macro Definition Documentation

#define NATIONBELOWLIMITPERCENTAGE   0.5f

Definition at line 66 of file cp_campaign.cpp.

Referenced by CP_CheckLostCondition().

Function Documentation

static void CP_AddCampaignCallbackCommands ( void  )
static

registers callback commands that are used by campaign

Todo:
callbacks should be registered on menu push (what about sideeffects for commands that are called from different menus?)
See also
CP_AddCampaignCommands
CP_RemoveCampaignCallbackCommands

Definition at line 712 of file cp_campaign.cpp.

References AIM_InitCallbacks(), B_InitCallbacks(), BDEF_InitCallbacks(), BS_InitCallbacks(), CP_TEAM_InitCallbacks(), HOS_InitCallbacks(), INS_InitCallbacks(), PR_InitCallbacks(), and RS_InitCallbacks().

Referenced by CP_AddCampaignCommands().

static void CP_AddCampaignCommands ( void  )
static

Definition at line 725 of file cp_campaign.cpp.

References cgi, and CP_AddCampaignCallbackCommands().

Referenced by CP_CampaignInit().

static void CP_AdvanceTimeBySeconds ( int  seconds)
inlinestatic

Ensure that the day always matches the seconds. If the seconds per day limit is reached, the seconds are reset and the day is increased.

Parameters
secondsThe seconds to add to the campaign date

Definition at line 208 of file cp_campaign.cpp.

References ccs_s::date, date_s::day, date_s::sec, and SECONDS_PER_DAY.

Referenced by CP_CampaignRun().

static void CP_CampaignFunctionPeriodicCall ( campaign_t campaign,
int  dt,
bool  updateRadarOverlay 
)
static

Functions that should be called with a minimum time lapse (will be called at least every DETECTION_INTERVAL)

Parameters
[in]campaignThe campaign data structure
[in]dtElapsed game seconds since last call.
[in]updateRadarOverlaytrue if radar overlay should be updated (only for drawing purpose)
See also
CP_CampaignRun

Definition at line 176 of file cp_campaign.cpp.

References AB_UpdateStealthForAllBase(), AIR_CampaignRun(), AIRFIGHT_CampaignRunBaseDefence(), AIRFIGHT_CampaignRunProjectiles(), CP_CheckNewMissionDetectedOnGeoscape(), UFO_CampaignCheckEvents(), UFO_CampaignRunUFOs(), and UFO_UpdateAlienInterestForAllBasesAndInstallations().

Referenced by CP_CampaignRun().

void CP_CampaignInit ( campaign_t campaign,
bool  load 
)

Called at new game and load game.

Parameters
[in]loadtrue if we are loading game, false otherwise
[in]campaignPointer to campaign - it will be set to ccs.curCampaign here.

< Initialise all data in the research tree.

Definition at line 765 of file cp_campaign.cpp.

References B_SelectBase(), BS_InitMarket(), cgi, CL_EventAddMail(), CL_PopupInit(), CP_AddCampaignCommands(), CP_GameTimeStop(), CP_InitializeSpawningDelay(), CP_InitializeXVIOverlay(), CP_ReadCampaignData(), CP_ScriptSanityCheck(), CP_UpdateCredits(), CP_UpdateTime(), CP_UpdateXVIMapButton(), CP_XVIInit(), campaign_s::credits, ccs_s::curCampaign, E_InitialEmployees(), GEO_Reset(), INT_ResetAlienInterest(), campaign_s::map, RS_InitTree(), and RS_MarkResearchable().

Referenced by CP_LoadXML(), and GAME_CP_Start_f().

bool CP_CheckCredits ( int  costs)

Checks whether you have enough credits for something.

Parameters
[in]costscosts to check

Definition at line 356 of file cp_campaign.cpp.

References ccs_s::credits.

Referenced by B_BuildBuilding(), and B_BuildBuilding_f().

void CP_CheckLostCondition ( const campaign_t campaign)

Checks whether the player has lost the campaign.

Todo:
Should we make the campaign lost when a player loses all his bases? until he has set up a base again, the aliens might have invaded the whole world ;) - i mean, removing the credits check here.

Definition at line 100 of file cp_campaign.cpp.

References _, B_AtLeastOneExists, campaign_s::basecost, cgi, CP_EndCampaign(), CP_GetAverageXVIRate(), ccs_s::credits, nationInfo_s::happiness, cvar_s::integer, campaign_s::maxAllowedXVIRateUntilLost, campaign_s::minhappiness, NAT_Foreach, NAT_GetCurrentMonthInfo(), NATIONBELOWLIMITPERCENTAGE, campaign_s::negativeCreditsUntilLost, ccs_s::numNations, and TEXT_STANDARD.

Referenced by CP_CampaignRun(), and CP_MissionEnd().

static void CP_CheckMissionEnd ( const campaign_t campaign)
static

Check for missions that have a timeout defined.

Definition at line 159 of file cp_campaign.cpp.

References CP_CheckMissionLimitedInTime(), CP_MissionStageEnd(), ccs_s::date, Date_LaterThan(), and MIS_Foreach.

Referenced by CP_CampaignRun().

void CP_EndCampaign ( bool  won)

Function to handle the campaign end.

Parameters
[in]wonIf the player won the game

Definition at line 88 of file cp_campaign.cpp.

References cgi, and va().

Referenced by CP_AttackUFOCarrier_f(), CP_CheckLostCondition(), and CP_EndGame_f().

campaign_t* CP_GetCampaign ( const char *  name)

Returns the campaign pointer from global campaign array.

Parameters
nameName of the campaign
Returns
campaign_t pointer to campaign with name or nullptr if not found

Definition at line 860 of file cp_campaign.cpp.

References ccs_s::campaigns, cgi, i, campaign_s::id, ccs_s::numCampaigns, and Q_streq.

Referenced by CP_LoadXML(), CP_ParseCampaign(), GAME_CP_CampaignDescription_f(), GAME_CP_Start_f(), and GetCampaign().

int CP_GetSalaryUpKeepBase ( const salary_t salary,
const base_t base 
)
static bool CP_IsBudgetDue ( const dateLong_t oldDate,
const dateLong_t date 
)
inlinestatic
Returns
true if a month has passed

Definition at line 220 of file cp_campaign.cpp.

References dateLong_s::month, and dateLong_s::year.

Referenced by CP_CampaignRun().

bool CP_IsRunning ( void  )

Checks whether a campaign mode game is running.

Definition at line 79 of file cp_campaign.cpp.

References ccs_s::curCampaign.

Referenced by CP_Shutdown(), GAME_CP_Frame(), GAME_CP_Start_f(), GEO_Draw(), SAV_GameContinue_f(), SAV_GameQuickSave_f(), and SAV_GameSaveAllowed().

static bool CP_LoadMapDefStatXML ( xmlNode_t parent)
static
bool CP_OnGeoscape ( void  )

Returns if we are currently on the Geoscape.

Todo:
This relies on scripted content. Should work other way!

Definition at line 198 of file cp_campaign.cpp.

References cgi, Q_streq, and cgame_import_s::UI_GetActiveWindowName().

Referenced by CP_AllowTimeScale(), CP_GameTimeStop(), and GAME_CP_Frame().

static void CP_RemoveCampaignCallbackCommands ( void  )
static

registers callback commands that are used by campaign

Todo:
callbacks should be removed on menu pop (what about sideeffects for commands that are called from different menus?)
See also
CP_AddCampaignCommands
CP_RemoveCampaignCallbackCommands

Definition at line 738 of file cp_campaign.cpp.

References AIM_ShutdownCallbacks(), B_ShutdownCallbacks(), BDEF_ShutdownCallbacks(), BS_ShutdownCallbacks(), CP_TEAM_ShutdownCallbacks(), HOS_ShutdownCallbacks(), INS_ShutdownCallbacks(), MSO_Shutdown(), PR_ShutdownCallbacks(), RS_ShutdownCallbacks(), and UP_Shutdown().

Referenced by CP_RemoveCampaignCommands().

static void CP_RemoveCampaignCommands ( void  )
static

Definition at line 753 of file cp_campaign.cpp.

References cgi, and CP_RemoveCampaignCallbackCommands().

Referenced by CP_Shutdown().

static bool CP_SaveMapDefStatXML ( xmlNode_t parent)
static

Save mapDef statistics.

Parameters
[out]parentXML Node structure, where we write the information to

Definition at line 483 of file cp_campaign.cpp.

References cgi, mapDef_s::id, MapDef_ForeachSingleplayerCampaign, SAVE_CAMPAIGN_MAPDEF, SAVE_CAMPAIGN_MAPDEF_COUNT, SAVE_CAMPAIGN_MAPDEF_ID, mapDef_s::timesAlreadyUsed, cgame_import_s::XML_AddNode(), and xmlNode_t.

Referenced by CP_SaveXML().

void CP_UpdateCredits ( int  credits)

Variable Documentation

ccs_t ccs

Definition at line 62 of file cp_campaign.cpp.

Referenced by AB_BaseSearchedByNations(), AB_BuildBase(), AB_DestroyBase(), AB_GetAlienBaseNumber(), AB_LoadXML(), AB_Shutdown(), AII_CarriedItems(), AIR_Add(), AIR_Delete(), AIR_GetAircraftSilent(), AIR_LoadAircraftXML(), AIR_LoadXML(), AIR_NewAircraft(), AIR_ParseAircraft(), AIR_ScriptSanityCheck(), AIR_Shutdown(), AIRFIGHT_AddProjectile(), AIRFIGHT_BaseShoot(), AIRFIGHT_CampaignRunProjectiles(), AIRFIGHT_ExecuteActions(), AIRFIGHT_InstallationShoot(), AIRFIGHT_LoadXML(), AIRFIGHT_RemoveProjectile(), AIRFIGHT_RemoveProjectileAimingAircraft(), AIRFIGHT_SaveXML(), AIRFIGHT_UpdateProjectileForDestroyedAircraft(), AL_AddAliens(), AM_Go(), AM_Go_f(), B_BaseInit_f(), B_Build(), B_BuildBase_f(), B_BuildBuilding(), B_BuildFromTemplate(), B_BuildingDestroy(), B_BuildingScriptSanityCheck(), B_Destroy(), B_GetBaseByIDX(), B_GetBaseTemplate(), B_GetBuildingTemplateByType(), B_GetBuildingTemplateSilent(), B_GetConstructionTimeRemain(), B_GetCount(), B_GetNext(), B_GetNextBuilding(), B_InitCallbacks(), B_IsBuildingDestroyable(), B_ListBuildings_f(), B_LoadXML(), B_ParseBaseTemplate(), B_ParseBuildings(), B_SelectBase(), B_SellOrAddItems(), B_SetBaseTitle_f(), B_SetUpFirstBase(), B_UpdateBaseCapacities(), BATTLE_Start(), BS_Buy_f(), BS_BuyAircraft(), BS_BuyItem(), BS_BuyUGV(), BS_FillMarket_f(), BS_ProcessCraftItemSale(), BS_SellAircraft(), BS_SellItem(), BS_SellUGV(), BS_SetAutosell_f(), CHAR_UpdateStats(), CITY_GetById(), CITY_GetByPos(), CITY_Parse(), CL_EventAddMail(), CL_GetEventMail(), CL_GetRankByIdx(), CL_GetRankIdx(), CL_ParseCampaignEvents(), CL_ParseEventMails(), CL_ParseNations(), CL_ParseRanks(), COMP_GetComponentsByID(), COMP_ParseComponents(), CP_AllowTimeScale(), CP_AttackUFOCarrier_f(), CP_BaseAttackGoToBase(), CP_BaseAttackMissionLeave(), CP_BaseAttackStartMission(), CP_BasemissionIsSubvertingGovernmentMission(), CP_BeginRescueMission(), CP_BuildBaseSetUpBase(), CP_BuildBaseSubvertGovernment(), CP_CampaignRunMarket(), CP_ChangeNationHappiness_f(), CP_CheckCampaignEvents(), CP_CheckTriggerEvent(), CP_ChooseCity(), CP_CreateNewMission(), CP_EndRescueMission(), CP_GameTimeFast(), CP_GameTimeSlow(), CP_GameTimeStop(), CP_GetAverageXVIRate(), CP_GetEventsByID(), CP_HarvestMissionGo(), CP_HarvestMissionStart(), CP_InitializeSpawningDelay(), CP_InterceptAircraftMissionSet(), CP_InterceptAttackInstallation(), CP_InterceptNextStage(), CP_IsTimeStopped(), CP_LeaveRescueMission(), CP_MissionBegin(), CP_MissionEnd(), CP_MissionRemove(), CP_MissionStageEnd(), CP_ParseAlienTeam(), CP_ParseCampaign(), CP_ParseCampaignData(), CP_ParseEventTrigger(), CP_ParseResearchableCampaignStates(), CP_ParseResearchedCampaignItems(), CP_ReadCampaignData(), CP_ReconMissionAerial(), CP_ReconMissionGround(), CP_ReconMissionGroundGo(), CP_ReconMissionLeave(), CP_ReduceXVIEverywhere(), CP_SelectNewMissionType(), CP_SetAlienTeamByInterest(), CP_SetGameTime(), CP_SetMissionName(), CP_SpawnCrashSiteMission(), CP_SpawnNewMissions(), CP_StartXVISpreading_f(), CP_SupplySetStayAtBase(), CP_TerrorMissionGo(), CP_TerrorMissionStart(), CP_TriggerEvent(), CP_TriggerEventLoadXML(), CP_TriggerEventSaveXML(), CP_UFOCarrierMissionStart(), CP_UFOCarrierMissionUpdate(), CP_UpdateNationXVIInfection(), CP_UpdateTime(), CP_XVIMissionStart(), CreateBase(), CreateInstallation(), Date_IsDue(), E_CountByType(), E_CreateEmployee(), E_DeleteEmployee(), E_LoadXML(), E_Shutdown(), GAME_CP_CampaignDescription_f(), GAME_CP_Frame(), GAME_CP_GetCampaigns_f(), GAME_CP_GetEquipmentDefinition(), GAME_CP_GetTeamDef(), GAME_CP_InitMissionBriefing(), GAME_CP_Results(), GAME_CP_Results_f(), GAME_CP_TeamIsKnown(), GEO_Click(), GEO_Draw(), GEO_DrawMarkers(), GEO_IsNight(), GEO_NotifyUFORemoved(), GEO_ResetAction(), HOS_HealCharacter(), INS_Build(), INS_BuildInstallation_f(), INS_DestroyInstallation(), INS_FillTypes_f(), INS_FillUFOYardData_f(), INS_GetCount(), INS_GetInstallationTemplateByID(), INS_GetInstallationTemplateByType(), INS_LinkTechnologies(), INS_LoadXML(), INS_ParseInstallations(), INS_SelectInstallation(), INS_SelectType_f(), INS_SetInstallationTitle(), INS_Shutdown(), INS_UpdateInstallationData(), INT_ChangeIndividualInterest(), INT_IncreaseAlienInterest(), INT_LoadXML(), INT_ResetAlienInterest(), INT_SaveXML(), MIS_CreateAlienTeam(), MIS_LoadXML(), MIS_Shutdown(), MS_AddNewMessage(), MSO_InitList(), MSO_ParseCategory(), MSO_Toggle_f(), MSO_UpdateVisibleButtons(), NAT_GetRandom(), NAT_HandleBudget(), NAT_ScriptSanityCheck(), NAT_Shutdown(), PR_CalculateTotalFrames(), PR_CheckFrame(), PR_FinishProduction(), PR_GetPrice(), PR_UpdateProductionList(), RS_CheckRequirements(), RS_CountScientistsInBase(), RS_FillTechnologyList_f(), RS_GetTechByIDX(), RS_GetTechForItem(), RS_GetTechForTeam(), RS_GetTechWithMostScientists(), RS_InitTree(), RS_IsResearched_idx(), RS_IsValidTechIndex(), RS_MarkCollected(), RS_MarkOneResearchable(), RS_MarkResearchable(), RS_ParseTechnologies(), RS_RequiredLinksAssign(), RS_ResearchFinish(), RS_ResearchRun(), RS_SaveXML(), RS_ScriptSanityCheck(), RS_ShowActiveResearch_f(), Employee::salary(), SAV_GameSave(), CampaignTest::SetUp(), STAT_GetExpenses_f(), STATS_LoadXML(), STATS_SaveXML(), STATS_Update_f(), TEST_F(), TR_DestinationCapacityList_f(), TR_List_f(), TR_LoadXML(), TR_Shutdown(), TR_TransferEnd(), TR_TransferStart(), UFO_CampaignRunUFOs(), UFO_CreateFromTemplate(), UFO_DetectNewUFO(), UFO_GeoSelectUFO_f(), UFO_GetByIDX(), UFO_GetByType(), UFO_GetNext(), UFO_GetTemplate(), UFO_GetTemplateForGeoscape(), UFO_NotifyPhalanxAircraftRemoved(), UFO_RemoveFromGeoscape(), UFO_ShouldAppearOnGeoscape(), UP_Click_f(), UP_GenerateSummary(), UP_GetUnreadMails(), UP_MailClientClick_f(), UP_ParseChapter(), UP_SetAllMailsRead_f(), UP_SetMailHeader(), UR_DialogStartSell_f(), UR_DialogStartStore_f(), UR_ProcessActive(), UR_Shutdown(), US_LoadXML(), US_RemoveStoredUFO(), US_SelectStoredUfo_f(), US_StoredUFOCount(), US_StoreUFO(), and US_TransferUFO().

cvar_t* cp_missiontest

Definition at line 63 of file cp_campaign.cpp.

Referenced by CP_ChooseMap(), CP_GameTimeStop(), and CampaignTest::SetUpTestCase().

const cmdList_t game_commands[]
static
Initial value:
= {
{"update_base_radar_coverage", RADAR_UpdateBaseRadarCoverage_f, "Update base radar coverage"},
{"addeventmail", CL_EventAddMail_f, "Add a new mail (event trigger) - e.g. after a mission"},
{"game_go", CP_StartSelectedMission, nullptr},
{"game_timestop", CP_GameTimeStop, nullptr},
{"game_timeslow", CP_GameTimeSlow, nullptr},
{"game_timefast", CP_GameTimeFast, nullptr},
{"game_settimeid", CP_SetGameTime_f, nullptr},
{"map_center", GEO_CenterOnPoint_f, "Centers the geoscape view on items on the geoscape - and cycle through them"},
{"cp_start_xvi_spreading", CP_StartXVISpreading_f, "Start XVI spreading"},
{"cp_spawn_ufocarrier", CP_SpawnUFOCarrier_f, "Spawns a UFO-Carrier on the geoscape"},
{"cp_attack_ufocarrier", CP_AttackUFOCarrier_f, "Attack the UFO-Carrier"},
{nullptr, nullptr, nullptr}
}
void CP_SetGameTime_f(void)
Set a new time game from id.
Definition: cp_time.cpp:214
void CP_GameTimeSlow(void)
Decrease game time speed.
Definition: cp_time.cpp:160
void CP_GameTimeStop(void)
Stop game time speed.
Definition: cp_time.cpp:126
void CP_StartSelectedMission(void)
Starts a selected mission.
void CP_AttackUFOCarrier_f(void)
Decide whether you hit and destroyed the carrier and spawns a new carrier crash site mission...
void CL_EventAddMail_f(void)
Definition: cp_event.cpp:554
void RADAR_UpdateBaseRadarCoverage_f(void)
Update radar coverage when building/destroying new radar.
Definition: cp_radar.cpp:277
void CP_StartXVISpreading_f(void)
Start XVI spreading in campaign.
Definition: cp_xvi.cpp:276
void GEO_CenterOnPoint_f(void)
Switch to next model on 2D and 3D geoscape.
void CP_GameTimeFast(void)
Increase game time speed.
Definition: cp_time.cpp:174
void CP_SpawnUFOCarrier_f(void)
Spawns a UFO-Carrier mission.

Definition at line 684 of file cp_campaign.cpp.