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

Campaign missions headers. More...

#include "cp_campaign.h"

Go to the source code of this file.

Data Structures

struct  missionResults_s
 Structure with mission info needed to create results summary at menu won. More...
 
struct  mission_s
 mission definition More...
 
union  mission_s::missionData_t
 

Macros

#define MIS_Foreach(var)   LIST_Foreach(ccs.missions, mission_t, var)
 iterates through missions More...
 

Typedefs

typedef enum missionStage_s missionStage_t
 
typedef struct missionResults_s missionResults_t
 Structure with mission info needed to create results summary at menu won. More...
 
typedef struct mission_s mission_t
 mission definition More...
 

Enumerations

enum  missionStage_s {
  STAGE_NOT_ACTIVE, STAGE_COME_FROM_ORBIT, STAGE_RECON_AIR, STAGE_MISSION_GOTO,
  STAGE_RECON_GROUND, STAGE_TERROR_MISSION, STAGE_BUILD_BASE, STAGE_BASE_ATTACK,
  STAGE_SUBVERT_GOV, STAGE_SUPPLY, STAGE_SPREAD_XVI, STAGE_INTERCEPT,
  STAGE_BASE_DISCOVERED, STAGE_HARVEST, STAGE_RETURN_TO_ORBIT, STAGE_OVER
}
 
enum  missionState_t { WON, DRAW, LOST }
 

Functions

const char * MIS_GetName (const mission_t *mission)
 Returns a short translated name for a mission. More...
 
void BATTLE_SetVars (const battleParam_t *battleParameters)
 Set some needed cvars from a battle definition. More...
 
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 the mission. More...
 
void BATTLE_Start (mission_t *mission, const battleParam_t *battleParameters)
 Select the mission type and start the map from mission definition. More...
 
mission_tCP_GetMissionByIDSilent (const char *missionId)
 Get a mission in ccs.missions by Id without error messages. More...
 
mission_tCP_GetMissionByID (const char *missionId)
 Get a mission in ccs.missions by Id. More...
 
int MIS_GetIdx (const mission_t *mis)
 Find idx corresponding to mission. More...
 
mission_tMIS_GetByIdx (int id)
 Find mission corresponding to idx. More...
 
mission_tCP_CreateNewMission (interestCategory_t category, bool beginNow)
 Create a new mission of given category. More...
 
void CP_UFOProceedMission (const struct campaign_s *campaign, struct aircraft_s *ufocraft)
 
void CP_MissionRemove (mission_t *mission)
 Removes a mission from mission global array. More...
 
bool CP_MissionBegin (mission_t *mission)
 mission begins: UFO arrive on earth. More...
 
bool CP_CheckNewMissionDetectedOnGeoscape (void)
 Check if mission has been detected by radar. More...
 
bool CP_CheckMissionLimitedInTime (const mission_t *mission)
 Check if mission should end because of limited time. More...
 
void CP_MissionDisableTimeLimit (mission_t *mission)
 Disable time limit for given mission. More...
 
void CP_MissionNotifyBaseDestroyed (const base_t *base)
 Notify that a base has been removed. More...
 
void CP_MissionNotifyInstallationDestroyed (const installation_t *installation)
 Notify missions that an installation has been destroyed. More...
 
const char * MIS_GetModel (const mission_t *mission)
 Get mission model that should be shown on the geoscape. More...
 
void CP_MissionRemoveFromGeoscape (mission_t *mission)
 Removes a mission from geoscape: make it non visible and call notify functions. More...
 
void CP_MissionAddToGeoscape (mission_t *mission, bool force)
 Add a mission to geoscape: make it visible and stop time. More...
 
void CP_UFORemoveFromGeoscape (mission_t *mission, bool destroyed)
 Removes (temporarily or permanently) a UFO from geoscape: make it land and call notify functions. More...
 
void CP_SpawnCrashSiteMission (aircraft_t *ufo)
 Spawn a new crash site after a UFO has been destroyed. More...
 
void CP_SpawnRescueMission (aircraft_t *aircraft, aircraft_t *ufo)
 Spawn a new rescue mission for a crashed (phalanx) aircraft. More...
 
ufoType_t CP_MissionChooseUFO (const mission_t *mission)
 Choose UFO type for a given mission category. More...
 
void CP_MissionStageEnd (const campaign_t *campaign, mission_t *mission)
 Determine what action should be performed when a mission stage ends. More...
 
void CP_InitializeSpawningDelay (void)
 Initialize spawning delay. More...
 
void CP_SpawnNewMissions (void)
 Spawn new missions. More...
 
void CP_MissionIsOver (mission_t *mission)
 Mission is finished because Phalanx team won it. More...
 
void CP_MissionIsOverByUFO (aircraft_t *ufocraft)
 Mission is finished because Phalanx team ended it. More...
 
void CP_MissionEnd (const campaign_t *campaign, mission_t *mission, const battleParam_t *battleParameters, bool won)
 Closing actions after fighting a battle. More...
 
void CP_MissionEndActions (mission_t *mission, aircraft_t *aircraft, bool won)
 Actions to be done after mission finished. More...
 
bool CP_ChooseMap (mission_t *mission, const vec2_t pos)
 Choose a map for given mission. More...
 
bool CP_CheckNextStageDestination (const struct campaign_s *campaign, struct aircraft_s *ufo)
 
int CP_CountMissionOnGeoscape (void)
 Count the number of mission active and displayed on geoscape. More...
 
void CP_UpdateMissionVisibleOnGeoscape (void)
 Update all mission visible on geoscape (in base radar range). More...
 
void MIS_InitStartup (void)
 Init actions for missions-subsystem. More...
 
void MIS_Shutdown (void)
 Closing actions for missions-subsystem. More...
 

Variables

const int MAX_POS_LOOP
 

Detailed Description

Campaign missions headers.

Definition in file cp_missions.h.

Macro Definition Documentation

Typedef Documentation

typedef struct mission_s mission_t

mission definition

Note
A mission is different from a map: a mission is the whole set of actions aliens will carry. For example, coming with a UFO on earth, land, explore earth, and leave with UFO

Structure with mission info needed to create results summary at menu won.

possible stage for campaign missions (i.e. possible actions for UFO)

Enumeration Type Documentation

possible stage for campaign missions (i.e. possible actions for UFO)

Enumerator
STAGE_NOT_ACTIVE 

mission did not begin yet

STAGE_COME_FROM_ORBIT 

UFO is arriving

STAGE_RECON_AIR 

Aerial Recon

STAGE_MISSION_GOTO 

Going to a new position

STAGE_RECON_GROUND 

Ground Recon

STAGE_TERROR_MISSION 

Terror mission

STAGE_BUILD_BASE 

Building a base

STAGE_BASE_ATTACK 

Base attack

STAGE_SUBVERT_GOV 

Subvert government

STAGE_SUPPLY 

Supply already existing base

STAGE_SPREAD_XVI 

Spreading XVI Virus

STAGE_INTERCEPT 

UFO attacks any encountered PHALANX aircraft or attack an installation

STAGE_BASE_DISCOVERED 

PHALANX discovered the base

STAGE_HARVEST 

Harvesting

STAGE_RETURN_TO_ORBIT 

UFO is going back to base

STAGE_OVER 

Mission is over

Definition at line 33 of file cp_missions.h.

Enumerator
WON 
DRAW 
LOST 

Definition at line 55 of file cp_missions.h.

Function Documentation

void BATTLE_SetVars ( const battleParam_t battleParameters)
void BATTLE_Start ( mission_t mission,
const battleParam_t battleParameters 
)

Select the mission type and start the map from mission definition.

Parameters
[in]missionMission definition to start the map from
[in]battleParametersContext data of the battle
See also
CP_StartSelectedMission
Note
Also sets the terrain textures
See also
Mod_LoadTexinfo
B_AssembleMap_f

Definition at line 106 of file cp_missions.cpp.

References B_AssembleMap(), mission_s::missionData_t::base, mission_s::category, ccs, cgi, mission_s::crashed, ccs_s::curCampaign, cgame_import_s::Cvar_Set(), mission_s::data, campaign_s::difficulty, ERR_DROP, GEO_IsNight(), mission_s::id, INTERESTCATEGORY_BASE_ATTACK, cgame_import_s::LIST_GetRandom(), mission_s::mapDef, mapDef_s::mapTheme, battleParam_s::param, mapDef_s::params, base_s::pos, mission_s::pos, and battleParam_s::zoneType.

Referenced by CP_StartSelectedMission().

bool CP_CheckMissionLimitedInTime ( const mission_t mission)

Check if mission should end because of limited time.

Note
This function is used for better readibility.
See also
CP_MissionDisableTimeLimit
Returns
true if function should end after finalDate

Definition at line 904 of file cp_missions.cpp.

References date_s::day, and mission_s::finalDate.

Referenced by CP_CheckMissionEnd(), and CP_EndRescueMission().

bool CP_CheckNewMissionDetectedOnGeoscape ( void  )

Check if mission has been detected by radar.

Note
called every DETECTION_INTERVAL.
See also
RADAR_CheckUFOSensored
Returns
True if a new mission was detected.

Definition at line 769 of file cp_missions.cpp.

References CP_CheckMissionVisibleOnGeoscape(), CP_MissionAddToGeoscape(), DETECTION_INTERVAL, frand(), MIS_Foreach, MISDET_MAY_BE_DETECTED, and UFO_DetectNewUFO().

Referenced by CP_CampaignFunctionPeriodicCall().

bool CP_CheckNextStageDestination ( const struct campaign_s campaign,
struct aircraft_s ufo 
)
bool CP_ChooseMap ( mission_t mission,
const vec2_t  pos 
)

Choose a map for given mission.

Parameters
[in,out]missionPointer to the mission where a new map should be added
[in]posposition of the mission (nullptr if the position will be chosen afterwards)
Returns
false if could not set mission

< Number of maps fulfilling mission conditions and appeared less often during game.

Definition at line 995 of file cp_missions.cpp.

References mission_s::category, cgi, cgame_import_s::Com_GetMapDefinitionByID(), cgame_import_s::Com_UFOTypeToShortName(), CP_MapIsSelectable(), cp_missiontest, mission_s::crashed, DEBUG_CLIENT, ERR_DROP, GEO_GetColor(), aircraft_s::getUfoType(), mapDef_s::id, cvar_s::integer, INTERESTCATEGORY_RESCUE, mission_s::mapDef, MapDef_ForeachSingleplayerCampaign, MapIsWater, MAPTYPE_TERRAIN, mapDef_s::timesAlreadyUsed, and mission_s::ufo.

Referenced by CP_HarvestMissionGo(), CP_ReconMissionGroundGo(), CP_SpawnCrashSiteMission(), CP_SpawnRescueMission(), CP_TerrorMissionGo(), and TEST_F().

int CP_CountMissionOnGeoscape ( void  )

Count the number of mission active and displayed on geoscape.

Returns
Number of active mission visible on geoscape

Definition at line 566 of file cp_missions.cpp.

References MIS_Foreach.

Referenced by GEO_GetGeoscapeAngle().

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 the mission.

Parameters
[in]missionPointer to the mission that generates the battle
[out]paramThe battle parameters to set
[in]aircraftthe aircraft to go to the mission with
See also
CP_CreateAlienTeam
CP_CreateCivilianTeam

Definition at line 338 of file cp_missions.cpp.

References _, mission_s::missionData_t::aircraft, mapDef_s::aircraft, mission_s::category, cgi, cgame_import_s::Com_GetRandomMapAssemblyNameForCraft(), cgame_import_s::Com_GetRandomMapAssemblyNameForCrashedCraft(), Com_sprintf(), cgame_import_s::Com_UFOCrashedTypeToShortName(), cgame_import_s::Com_UFOTypeToShortName(), cp_campaignPool, CP_CreateCivilianTeam(), mission_s::crashed, cgame_import_s::csi, cgame_import_s::Cvar_Set(), mission_s::data, frand(), GEO_GetColor(), TerrainDefs::getTerrainName(), aircraft_s::getUfoType(), TerrainDefs::getWeather(), aircraft_s::id, mapDef_s::id, INTERESTCATEGORY_ALIENBASE, INTERESTCATEGORY_RESCUE, cgame_import_s::LIST_ContainsString(), mission_s::mapDef, mapDef_s::mapTheme, MAPTYPE_TERRAIN, MAX_CRASHEDUFO_CONDITION, MIN_CRASHEDUFO_CONDITION, MIS_CreateAlienTeam(), battleParam_s::mission, aircraft_s::model, mission_s::onwin, battleParam_s::param, cgame_import_s::PoolStrDup(), mission_s::pos, mission_s::posAssigned, Q_streq, battleParam_s::retriable, csi_s::terrainDefs, mission_s::ufo, UFO_GetName(), mapDef_s::ufos, and battleParam_s::zoneType.

Referenced by AM_Go_f(), CP_StartSelectedMission(), and TEST_F().

mission_t* CP_GetMissionByID ( const char *  missionId)

Get a mission in ccs.missions by Id.

Parameters
[in]missionIdUnique string id for the mission
Returns
pointer to the mission or nullptr if Id was nullptr or mission not found

Definition at line 432 of file cp_missions.cpp.

References cgi, and CP_GetMissionByIDSilent().

Referenced by AIR_PostLoadInitMissions().

mission_t* CP_GetMissionByIDSilent ( const char *  missionId)

Get a mission in ccs.missions by Id without error messages.

Parameters
[in]missionIdUnique string id for the mission
Returns
pointer to the mission or nullptr if Id was nullptr or mission not found

Definition at line 414 of file cp_missions.cpp.

References MIS_Foreach, and Q_streq.

Referenced by CP_GetMissionByID(), and CP_SetMissionName().

void CP_InitializeSpawningDelay ( void  )

Initialize spawning delay.

See also
CP_SpawnNewMissions
Note
only called when new game is started, in order to spawn new event on the beginning of the game.

Definition at line 1786 of file cp_missions.cpp.

References ccs, DELAY_BETWEEN_MISSION_SPAWNING, ccs_s::lastMissionSpawnedDelay, and ccs_s::missionSpawnCallback.

Referenced by CP_CampaignInit().

bool CP_MissionBegin ( mission_t mission)
void CP_MissionEnd ( const campaign_t campaign,
mission_t mission,
const battleParam_t battleParameters,
bool  won 
)

Closing actions after fighting a battle.

Parameters
[in]campaignThe campaign we play
[in,out]missionThe mission the battle was on
[in]battleParametersParameters of the battle
[in]wonif PHALANX won
Note
both manual and automatic missions call this through won/lost UI screen
Todo:
replace HP check with some CHRSH->IsDead() function

Definition at line 1249 of file cp_missions.cpp.

References AIR_IsEmployeeInAircraft(), base_s::aircraftCurrent, mission_s::missionData_t::base, ccs_s::campaignStats, ccs, cgi, CHAR_UpdateData(), CHAR_UpdateStats(), CP_CheckLostCondition(), CP_ExecuteMissionTrigger(), CP_HandleNationData(), CP_MissionEndActions(), mission_s::data, DEBUG_CLIENT, E_DeleteEmployee(), E_Foreach, ccs_s::eMission, EMPL_SOLDIER, GEO_GetMissionAircraft, aircraft_s::homebase, campaign_s::minhappiness, mission_s::missionResults, stats_s::missionsLost, stats_s::missionsWon, battleParam_s::nation, mission_s::stage, STAGE_BASE_ATTACK, base_s::storage, and ccs_s::updateCharacters.

Referenced by GAME_CP_Results_f().

void CP_MissionEndActions ( mission_t mission,
aircraft_t aircraft,
bool  won 
)

Actions to be done after mission finished.

Parameters
[in,out]missionPointer to the finished mission
[in,out]aircraftPointer to the dropship done the mission
[in]wonBoolean flag if thew mission was successful (from PHALANX's PoV)

Definition at line 1214 of file cp_missions.cpp.

References _, AIR_AircraftReturnToBase(), B_DumpAircraftToHomeBase(), mission_s::category, Com_sprintf(), CP_BaseAttackMissionDestroyBase(), CP_BaseAttackMissionIsFailure(), CP_EndRescueMission(), cp_messageBuffer, CP_MissionIsOver(), aircraft_s::homebase, INTERESTCATEGORY_RESCUE, MS_AddNewMessage(), base_s::name, mission_s::stage, and STAGE_BASE_ATTACK.

Referenced by CP_MissionEnd().

void CP_MissionIsOverByUFO ( aircraft_t ufocraft)

Mission is finished because Phalanx team ended it.

Parameters
[in]ufocraftPointer to the UFO involved in this mission

Definition at line 1202 of file cp_missions.cpp.

References CP_MissionIsOver(), and aircraft_s::mission.

Referenced by AIRFIGHT_ActionsAfterAirfight().

void CP_MissionNotifyBaseDestroyed ( const base_t base)

Notify that a base has been removed.

Definition at line 919 of file cp_missions.cpp.

References CP_BaseAttackMissionLeave(), INTERESTCATEGORY_BASE_ATTACK, and MIS_Foreach.

Referenced by B_Destroy().

void CP_MissionNotifyInstallationDestroyed ( const installation_t installation)

Notify missions that an installation has been destroyed.

Parameters
[in]installationPointer to the installation that has been destroyed.

Definition at line 936 of file cp_missions.cpp.

References CP_InterceptMissionLeave(), INTERESTCATEGORY_INTERCEPT, and MIS_Foreach.

Referenced by INS_DestroyInstallation().

void CP_MissionRemove ( mission_t mission)
void CP_MissionRemoveFromGeoscape ( mission_t mission)
void CP_SpawnCrashSiteMission ( aircraft_t ufo)
void CP_SpawnRescueMission ( aircraft_t aircraft,
aircraft_t ufo 
)

Spawn a new rescue mission for a crashed (phalanx) aircraft.

Parameters
[in]aircraftThe crashed aircraft to spawn the rescue mission for.
[in]ufoThe UFO that shot down the phalanx aircraft, can also be nullptr if the UFO was destroyed.
Note
Don't use ufo's old mission pointer after this call! It might have been removed.
Todo:
Don't spawn rescue mission every time! It should depend on pilot's manoeuvring (piloting) skill
Todo:
don't "kill" everyone - this should depend on luck and a little bit on the skills
Todo:
find out what to do in this case

Definition at line 1394 of file cp_missions.cpp.

References aircraft_s::acTeam, AIR_CRASHED, AIR_DestroyAircraft(), AIR_GetFirstFromBase(), AIR_GetHangarCapacityType(), AIR_GetPilot(), AIR_PilotSurvivedCrash(), mission_s::missionData_t::aircraft, base_s::aircraftCurrent, CAP_AddCurrent(), cgi, CP_ChooseMap(), CP_CreateNewMission(), CP_MissionDisableTimeLimit(), CP_MissionRemove(), mission_s::data, E_DeleteEmployee(), ERR_DROP, GEO_IsAircraftSelected, GEO_SetSelectedAircraft, aircraft_s::homebase, mission_s::id, INTERESTCATEGORY_RESCUE, LIST_Foreach, mission_s::mapDef, MAX_CAP, aircraft_s::mission, mission_s::pos, aircraft_s::pos, character_s::score, mission_s::stage, STAGE_MISSION_GOTO, aircraft_s::status, mission_s::ufo, and Vector2Copy.

Referenced by AIRFIGHT_ActionsAfterAirfight(), and B_MoveAircraftOnGeoscapeToOtherBases().

void CP_UFOProceedMission ( const struct campaign_s campaign,
struct aircraft_s ufocraft 
)
void CP_UFORemoveFromGeoscape ( mission_t mission,
bool  destroyed 
)

Removes (temporarily or permanently) a UFO from geoscape: make it land and call notify functions.

Parameters
[in]missionPointer to mission.
[in]destroyedTrue if the UFO has been destroyed, false if it's only landed.
Note
We don't destroy the UFO if mission is not deleted because we can use it later, e.g. if it takes off.
See also
UFO_RemoveFromGeoscape
Todo:
remove me once the ufo list is a linked list

Definition at line 827 of file cp_missions.cpp.

References AIR_AircraftsNotifyUFORemoved(), AIRFIGHT_RemoveProjectileAimingAircraft(), aircraft_s::detected, GEO_NotifyUFORemoved(), aircraft_s::landed, MIS_Foreach, aircraft_s::pos, RADAR_CheckRadarSensored(), RADAR_NotifyUFORemoved(), mission_s::ufo, and UFO_RemoveFromGeoscape().

Referenced by CP_BaseAttackStartMission(), CP_BuildBaseSetUpBase(), CP_BuildBaseSubvertGovernment(), CP_HarvestMissionStart(), CP_MissionRemove(), CP_ReconMissionGround(), CP_SpawnCrashSiteMission(), CP_SupplySetStayAtBase(), CP_TerrorMissionStart(), and CP_XVIMissionStart().

void CP_UpdateMissionVisibleOnGeoscape ( void  )

Update all mission visible on geoscape (in base radar range).

Note
you can't see a mission with aircraft radar.
See also
CP_CheckMissionAddToGeoscape

Definition at line 806 of file cp_missions.cpp.

References CP_CheckMissionVisibleOnGeoscape(), CP_MissionAddToGeoscape(), CP_MissionRemoveFromGeoscape(), MIS_Foreach, MISDET_ALWAYS_DETECTED, and MISDET_CANT_BE_DETECTED.

Referenced by RADAR_UpdateBaseRadarCoverage_f(), and RADAR_UpdateInstallationRadarCoverage().

mission_t* MIS_GetByIdx ( int  id)

Find mission corresponding to idx.

Definition at line 447 of file cp_missions.cpp.

References MIS_Foreach.

Referenced by AIR_SendAircraftToMission_f(), GEO_GetMissionAngle(), and MIS_GeoSelectMission_f().

int MIS_GetIdx ( const mission_t mis)

Find idx corresponding to mission.

Definition at line 460 of file cp_missions.cpp.

References mission_s::idx.

Referenced by GEO_Click().

void MIS_InitStartup ( void  )

Init actions for missions-subsystem.

See also
UI_InitStartup

Definition at line 2210 of file cp_missions.cpp.

References cgi, and MIS_InitCallbacks().

Referenced by CP_InitStartup().

void MIS_Shutdown ( void  )

Closing actions for missions-subsystem.

Definition at line 2219 of file cp_missions.cpp.

References ccs, cgi, MIS_ShutdownCallbacks(), and ccs_s::missions.

Referenced by CP_Shutdown().

Variable Documentation

const int MAX_POS_LOOP

Maximum number of loops to choose a mission position (to avoid infinite loops)

Definition at line 61 of file cp_missions.cpp.

Referenced by CP_HarvestMissionGo(), CP_ReconMissionGroundGo(), and CP_TerrorMissionGo().