1 /** 2 * @file 3 * @brief Header file for single player campaign control. 4 */ 5 6 /* 7 Copyright (C) 2002-2013 UFO: Alien Invasion. 8 9 This program is free software; you can redistribute it and/or 10 modify it under the terms of the GNU General Public License 11 as published by the Free Software Foundation; either version 2 12 of the License, or (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 17 18 See the GNU General Public License for more details. 19 20 You should have received a copy of the GNU General Public License 21 along with this program; if not, write to the Free Software 22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 23 24 */ 25 26 #pragma once 27 28 extern memPool_t* cp_campaignPool; 29 30 struct aircraft_s; 31 struct installation_s; 32 class Employee; 33 struct ugv_s; 34 struct campaign_s; 35 36 #define MAX_CAMPAIGNS 16 37 38 #define MAX_ASSEMBLIES 16 39 40 /* fraction of nation that can be below min happiness before the game is lost */ 41 #define NATIONBELOWLIMITPERCENTAGE 0.5f 42 43 /** @todo rename this after merging with savegame breakage branch and also change the value to -1 */ 44 #define BYTES_NONE 0xFF 45 46 #include "cp_cgame_callbacks.h" 47 #include "cp_rank.h" 48 #include "cp_save.h" 49 #include "cp_parse.h" 50 #include "cp_event.h" 51 #include "cp_ufopedia.h" 52 #include "cp_research.h" 53 #include "cp_radar.h" 54 #include "cp_aircraft.h" 55 #include "cp_base.h" 56 #include "cp_employee.h" 57 #include "cp_transfer.h" 58 #include "cp_nation.h" 59 #include "cp_installation.h" 60 #include "cp_produce.h" 61 #include "cp_uforecovery.h" 62 #include "cp_airfight.h" 63 #include "cp_messageoptions.h" 64 #include "cp_alienbase.h" 65 #include "cp_market.h" 66 #include "cp_statistics.h" 67 68 /* check for water */ 69 /* blue value is 64 */ 70 #define MapIsWater(color) (color[0] == 0 && color[1] == 0 && color[2] == 64) 71 72 /* terrain types */ 73 #define MapIsArctic(color) (color[0] == 128 && color[1] == 255 && color[2] == 255) 74 #define MapIsDesert(color) (color[0] == 255 && color[1] == 128 && color[2] == 0) 75 #define MapIsMountain(color) (color[0] == 255 && color[1] == 0 && color[2] == 0) 76 #define MapIsTropical(color) (color[0] == 128 && color[1] == 128 && color[2] == 255) 77 #define MapIsGrass(color) (color[0] == 128 && color[1] == 255 && color[2] == 0) 78 #define MapIsWasted(color) (color[0] == 128 && color[1] == 0 && color[2] == 128) 79 #define MapIsCold(color) (color[0] == 0 && color[1] == 0 && color[2] == 255) 80 81 /* culture types */ 82 #define MapIsWestern(color) (color[0] == 128 && color[1] == 255 && color[2] == 255) 83 #define MapIsEastern(color) (color[0] == 255 && color[1] == 128 && color[2] == 0) 84 #define MapIsOriental(color) (color[0] == 255 && color[1] == 0 && color[2] == 0) 85 #define MapIsAfrican(color) (color[0] == 128 && color[1] == 128 && color[2] == 255) 86 87 /* population types */ 88 #define MapIsUrban(color) (color[0] == 128 && color[1] == 255 && color[2] == 255) 89 #define MapIsSuburban(color) (color[0] == 255 && color[1] == 128 && color[2] == 0) 90 #define MapIsVillage(color) (color[0] == 255 && color[1] == 0 && color[2] == 0) 91 #define MapIsRural(color) (color[0] == 128 && color[1] == 128 && color[2] == 255) 92 #define MapIsNopopulation(color) (color[0] == 128 && color[1] == 255 && color[2] == 0) 93 94 /* RASTER enables a better performance for CP_GetRandomPosOnGeoscapeWithParameters set it to 1-6 95 * the higher the value the better the performance, but the smaller the coverage */ 96 #define RASTER 2 97 98 /* nation happiness constants */ 99 #define HAPPINESS_SUBVERSION_LOSS -0.15 100 #define HAPPINESS_ALIEN_MISSION_LOSS -0.02 101 #define HAPPINESS_UFO_SALE_GAIN 0.02 102 #define HAPPINESS_UFO_SALE_LOSS 0.005 103 #define HAPPINESS_MAX_MISSION_IMPACT 0.07 104 105 /* Maximum alien groups per alien team category */ 106 #define MAX_ALIEN_GROUP_PER_CATEGORY 8 107 /* Maximum alien team category defined in scripts */ 108 #define ALIENCATEGORY_MAX 64 109 #define BID_FACTOR 0.9 110 #define MAX_PROJECTILESONGEOSCAPE 32 111 112 /** 113 * @brief The amount of time (in hours) it takes for the interest to increase by 1. Is later affected by difficulty. 114 */ 115 #define HOURS_PER_ONE_INTEREST 24 116 117 /** 118 * @brief Determines the interest interval for a single campaign 119 */ 120 #define INITIAL_OVERALL_INTEREST 20 121 #define FINAL_OVERALL_INTEREST 400 122 123 /** 124 * @brief The length of a single mission spawn cycle 125 */ 126 #define DELAY_BETWEEN_MISSION_SPAWNING 12 127 128 /** 129 * @brief Determines the early game period during which DELAY_BETWEEN_MISSION_SPAWNING is halved. 130 * @note This is done to ensure the player is not bored early in the game. The rush will stop when alien interest reaches this level. 131 */ 132 #define EARLY_UFO_RUSH_INTEREST 50 133 134 /** 135 * @brief The minimum and maximum amount of missions per mission cycle. 136 * @note some of the missions can be non-occurrence missions. 137 */ 138 #define MINIMUM_MISSIONS_PER_CYCLE 5 139 #define MAXIMUM_MISSIONS_PER_CYCLE 17 140 141 /** 142 * @brief The probability that any new alien mission will be a non-occurrence mission. 143 */ 144 #define NON_OCCURRENCE_PROBABILITY 0.75 145 146 /** possible map types */ 147 typedef enum mapType_s { 148 MAPTYPE_TERRAIN, 149 MAPTYPE_CULTURE, 150 MAPTYPE_POPULATION, 151 MAPTYPE_NATIONS, 152 153 MAPTYPE_MAX 154 } mapType_t; 155 156 /** @brief possible mission detection status */ 157 typedef enum missionDetectionStatus_s { 158 MISDET_CANT_BE_DETECTED, /**< Mission can't be seen on geoscape */ 159 MISDET_ALWAYS_DETECTED, /**< Mission is seen on geoscape, whatever it's position */ 160 MISDET_MAY_BE_DETECTED /**< Mission may be seen on geoscape, if a probability test is done */ 161 } missionDetectionStatus_t; 162 163 /** possible campaign interest categories: type of missions that aliens can undertake */ 164 typedef enum interestCategory_s { 165 INTERESTCATEGORY_NONE, /**< No mission */ 166 INTERESTCATEGORY_RECON, /**< Aerial recon mission or ground mission (UFO may or not land) */ 167 INTERESTCATEGORY_TERROR_ATTACK, /**< Terror attack */ 168 INTERESTCATEGORY_BASE_ATTACK, /**< Alien attack a phalanx base */ 169 INTERESTCATEGORY_BUILDING, /**< Alien build a new base or subverse governments */ 170 INTERESTCATEGORY_SUPPLY, /**< Alien supply one of their bases */ 171 INTERESTCATEGORY_XVI, /**< Alien try to spread XVI */ 172 INTERESTCATEGORY_INTERCEPT, /**< Alien try to intercept PHALANX aircraft */ 173 INTERESTCATEGORY_HARVEST, /**< Alien try to harvest */ 174 INTERESTCATEGORY_ALIENBASE, /**< Alien base already built on earth 175 * @note This is not a mission alien can undertake, but the result of 176 * INTERESTCATEGORY_BUILDING */ 177 INTERESTCATEGORY_UFOCARRIER, /**< UFO-Carrier is detected */ 178 INTERESTCATEGORY_RESCUE, 179 180 INTERESTCATEGORY_MAX 181 } interestCategory_t; 182 183 /** possible stage for campaign missions (i.e. possible actions for UFO) */ 184 typedef enum missionStage_s { 185 STAGE_NOT_ACTIVE, /**< mission did not begin yet */ 186 STAGE_COME_FROM_ORBIT, /**< UFO is arriving */ 187 188 STAGE_RECON_AIR, /**< Aerial Recon */ 189 STAGE_MISSION_GOTO, /**< Going to a new position */ 190 STAGE_RECON_GROUND, /**< Ground Recon */ 191 STAGE_TERROR_MISSION, /**< Terror mission */ 192 STAGE_BUILD_BASE, /**< Building a base */ 193 STAGE_BASE_ATTACK, /**< Base attack */ 194 STAGE_SUBVERT_GOV, /**< Subvert government */ 195 STAGE_SUPPLY, /**< Supply already existing base */ 196 STAGE_SPREAD_XVI, /**< Spreading XVI Virus */ 197 STAGE_INTERCEPT, /**< UFO attacks any encountered PHALANX aircraft or attack an installation */ 198 STAGE_BASE_DISCOVERED, /**< PHALANX discovered the base */ 199 STAGE_HARVEST, /**< Harvesting */ 200 201 STAGE_RETURN_TO_ORBIT, /**< UFO is going back to base */ 202 203 STAGE_OVER /**< Mission is over */ 204 } missionStage_t; 205 206 /** @brief alien team group definition. 207 * @note This is the definition of one groups of aliens (several races) that can 208 * be used on the same map. 209 * @sa alienTeamCategory_s 210 */ 211 typedef struct alienTeamGroup_s { 212 int idx; /**< idx of the group in the alien team category */ 213 int categoryIdx; /**< idx of category it's used in */ 214 int minInterest; /**< Minimum interest value this group should be used with. */ 215 int maxInterest; /**< Maximum interest value this group should be used with. */ 216 int minAlienCount; /**< Minimum number of aliens in this group */ 217 int maxAlienCount; /**< Maximum number of aliens in this group */ 218 219 const teamDef_t* alienTeams[MAX_TEAMS_PER_MISSION]; /**< different alien teams available 220 * that will be used in mission */ 221 const chrTemplate_t* alienChrTemplates[MAX_TEAMS_PER_MISSION]; 222 int numAlienTeams; /**< Number of alienTeams defined in this group. */ 223 } alienTeamGroup_t; 224 225 /** @brief alien team category definition 226 * @note This is the definition of all groups of aliens that can be used for 227 * a mission category 228 * @sa alienTeamGroup_s 229 */ 230 typedef struct alienTeamCategory_s { 231 char id[MAX_VAR]; /**< id of the category */ 232 interestCategory_t missionCategories[INTERESTCATEGORY_MAX]; /**< Mission category that should use this 233 * alien team Category. */ 234 int numMissionCategories; /**< Number of category using this alien team Category. */ 235 236 linkedList_t* equipment; /**< Equipment definitions that may be used for this def. */ 237 238 alienTeamGroup_t alienTeamGroups[MAX_ALIEN_GROUP_PER_CATEGORY]; /**< Different alien group available 239 * for this category */ 240 int numAlienTeamGroups; /**< Number of alien group defined for this category */ 241 } alienTeamCategory_t; 242 243 /** @brief mission definition 244 * @note A mission is different from a map: a mission is the whole set of actions aliens will carry. 245 * For example, coming with a UFO on earth, land, explore earth, and leave with UFO 246 */ 247 typedef struct mission_s { 248 int idx; /**< unique id of this mission */ 249 char id[MAX_VAR]; /**< script id */ 250 mapDef_t* mapDef; /**< mapDef used for this mission */ 251 bool active; /**< aircraft at place? */ 252 union missionData_t { 253 base_t* base; 254 aircraft_t* aircraft; 255 installation_t* installation; 256 alienBase_t* alienBase; 257 city_t* city; 258 } data; /**< may be related to mission type (like pointer to base attacked, or to alien base) */ 259 interestCategory_t category; /**< The category of the event */ 260 missionStage_t stage; /**< in which stage is this event? */ 261 int initialOverallInterest; /**< The overall interest value when this event has been created */ 262 int initialIndividualInterest; /**< The individual interest value (of type type) when this event has been created */ 263 date_t startDate; /**< Date when the event should start */ 264 date_t finalDate; /**< Date when the event should finish (e.g. for aerial recon) 265 * if finaleDate.day == 0, then delay is not a limitating factor for next stage */ 266 vec2_t pos; /**< Position of the mission */ 267 aircraft_t* ufo; /**< UFO on geoscape fulfilling the mission (may be nullptr) */ 268 bool onGeoscape; /**< Should the mission be displayed on geoscape */ 269 bool crashed; /**< is UFO crashed ? (only used if mission is spawned from a UFO */ 270 271 char onwin[MAX_VAR]; /**< trigger command after you've won a battle, @sa CP_ExecuteMissionTrigger */ 272 char onlose[MAX_VAR]; /**< trigger command after you've lost a battle, @sa CP_ExecuteMissionTrigger */ 273 bool posAssigned; /**< is the position of this mission already set? */ 274 } mission_t; 275 276 /** 277 * @brief iterates through missions 278 */ 279 #define MIS_Foreach(var) LIST_Foreach(ccs.missions, mission_t, var) 280 281 /** battlescape parameters that were used */ 282 typedef struct battleParam_s { 283 mission_t* mission; 284 alienTeamGroup_t* alienTeamGroup; /**< Races of aliens present in battle */ 285 char* param; /**< in case of a random map assembly we can't use the param from mapDef - because 286 * this is global for the mapDef - but we need a local mission param */ 287 char alienEquipment[MAX_VAR]; /**< Equipment of alien team */ 288 char civTeam[MAX_VAR]; /**< Type of civilian (European, ...) */ 289 bool day; /**< Mission is played during day */ 290 const char* zoneType; /**< Terrain type (used for texture replacement in some missions (base, ufocrash)) */ 291 int aliens, civilians; /**< number of aliens and civilians in that particular mission */ 292 struct nation_s* nation; /**< nation where the mission takes place */ 293 bool retriable; /**< if the battle can be retried */ 294 } battleParam_t; 295 296 typedef enum { 297 WON, DRAW, LOST 298 } missionState_t; 299 300 /** @brief Structure with mission info needed to create results summary at menu won. */ 301 typedef struct missionResults_s { 302 const mission_t* mission; 303 missionState_t state; 304 bool recovery; /**< @c true if player secured a UFO (landed or crashed). */ 305 bool crashsite; /**< @c true if secured UFO was crashed one. */ 306 ufoType_t ufotype; /**< Type of UFO secured during the mission. */ 307 float ufoCondition; /**< How much the UFO is damaged */ 308 int itemTypes; /**< Types of items gathered from a mission. */ 309 int itemAmount; /**< Amount of items (all) gathered from a mission. */ 310 int aliensKilled; 311 int aliensStunned; 312 int aliensSurvived; 313 int ownKilled; 314 int ownStunned; 315 int ownKilledFriendlyFire; 316 int ownSurvived; 317 int civiliansKilled; 318 int civiliansKilledFriendlyFire; 319 int civiliansSurvived; 320 } missionResults_t; 321 322 /** salary values for a campaign */ 323 typedef struct salary_s { 324 int base[MAX_EMPL]; 325 int rankBonus[MAX_EMPL]; 326 int admin[MAX_EMPL]; 327 int aircraftFactor; 328 int aircraftDivisor; 329 int baseUpkeep; 330 int adminInitial; 331 float debtInterest; 332 } salary_t; 333 334 /** campaign definition */ 335 typedef struct campaign_s { 336 int idx; /**< own index in global campaign array */ 337 char id[MAX_VAR]; /**< id of the campaign */ 338 char name[MAX_VAR]; /**< name of the campaign */ 339 int team; /**< what team can play this campaign */ 340 char researched[MAX_VAR]; /**< name of the researched tech list to use on campaign start */ 341 char soldierEquipment[MAX_VAR]; /**< name of the equipment list that is used to equip soldiers on crafts that are added to the first base */ 342 char equipment[MAX_VAR]; /**< name of the equipment list to use on campaign start */ 343 char market[MAX_VAR]; /**< name of the market list containing initial items on market */ 344 char asymptoticMarket[MAX_VAR]; /**< name of the market list containing items on market at the end of the game */ 345 const equipDef_t* marketDef; /**< market definition for this campaign (how many items on the market) containing initial items */ 346 const equipDef_t* asymptoticMarketDef; /**< market definition for this campaign (how many items on the market) containing finale items */ 347 char text[MAX_VAR]; /**< placeholder for gettext stuff */ 348 char map[MAX_VAR]; /**< geoscape map */ 349 int soldiers; /**< start with x soldiers */ 350 int scientists; /**< start with x scientists */ 351 int workers; /**< start with x workers */ 352 int pilots; /**< start with x pilots */ 353 int credits; /**< start with x credits */ 354 int num; 355 signed int difficulty; /**< difficulty level -4 - 4 */ 356 float minhappiness; /**< minimum value of mean happiness before the game is lost */ 357 int negativeCreditsUntilLost; /**< bankrupt - negative credits until you've lost the game */ 358 int maxAllowedXVIRateUntilLost; /**< 0 - 100 - the average rate of XVI over all nations before you've lost the game */ 359 bool visible; /**< visible in campaign menu? */ 360 date_t date; /**< starting date for this campaign */ 361 int basecost; /**< base building cost for empty base */ 362 char firstBaseTemplate[MAX_VAR]; /**< template to use for setting up the first base */ 363 bool finished; 364 const campaignEvents_t* events; 365 salary_t salaries; 366 float produceRate; /**< higher number = faster production */ 367 float researchRate; /**< specifies the number of research hours that a single scientist produces in a single hour of game time */ 368 float healingRate; /**< the hospital healing rate */ 369 float ufoReductionRate; /**< is used in the equation which spawns UFOs to determine the probability that a UFO will not be spawned. 370 * It works like this: the game says: 10 UFOs can be spawned in this cycle. For each UFO it picks a number between 0.0 and 1.0. 371 * If the number is higher than ufoReductionRate, it is spawned. Otherwise it is not. So higher numbers lead to fewer UFOs. */ 372 float employeeRate; /**< Easier difficulties could offer more monthly recruits and harder difficulties less */ 373 int initialInterest; 374 int alienBaseInterest; /**< the alien interest level at which aliens begin trying to build bases. */ 375 } campaign_t; 376 377 int CP_GetSalaryBaseEmployee(const salary_t* salary, employeeType_t type); 378 int CP_GetSalaryAdminEmployee(const salary_t* salary, employeeType_t type); 379 int CP_GetSalaryRankBonusEmployee(const salary_t* salary, employeeType_t type); 380 int CP_GetSalaryAdministrative(const salary_t* salary); 381 int CP_GetSalaryUpKeepBase(const salary_t* salary, const base_t* base); 382 383 /** possible geoscape actions */ 384 typedef enum mapAction_s { 385 MA_NONE, 386 MA_NEWBASE, /**< build a new base */ 387 MA_NEWINSTALLATION, /**< build a new installation */ 388 MA_INTERCEPT, /**< intercept */ 389 MA_BASEATTACK, /**< base attacking */ 390 MA_UFORADAR /**< ufos are in our radar */ 391 } mapAction_t; 392 393 typedef void (*missionSpawnFunction_t) (void); 394 typedef void (*missionResultFunction_t) (const missionResults_t* results); 395 396 /** 397 * @brief client campaign structure 398 * @sa csi_t 399 */ 400 typedef struct ccs_s { 401 equipDef_t eMission; /**< this is a copy of the base storage we are starting a mission from. This is needed because 402 * we don't want to "waste" items on a retry. */ 403 market_t eMarket; /**< Prices, evolution and number of items on market */ 404 405 linkedList_t* missions; /**< Missions spawned (visible on geoscape or not) */ 406 407 battleParam_t battleParameters; /**< Structure used to remember every parameter used during last battle */ 408 409 int lastInterestIncreaseDelay; /**< How many hours since last increase of alien overall interest */ 410 int overallInterest; /**< overall interest of aliens: how far is the player in the campaign */ 411 int interest[INTERESTCATEGORY_MAX]; /**< interest of aliens: determine which actions aliens will undertake */ 412 int lastMissionSpawnedDelay; /**< How many days since last mission has been spawned */ 413 414 int credits; /**< actual credits amount */ 415 int civiliansKilled; /**< how many civilians were killed already */ 416 int aliensKilled; /**< how many aliens were killed already */ 417 date_t date; /**< current date */ 418 bool startXVI; /**< the aliens are starting to spread XVI */ 419 float timer; 420 float frametime; 421 422 struct { 423 mission_t* selectedMission; /**< Currently selected mission on geoscape */ 424 aircraft_t* selectedAircraft; /**< Currently selected aircraft on geoscape */ 425 aircraft_t* selectedUFO; /**< Currently selected UFO on geoscape */ 426 aircraft_t* interceptAircraft; /**< selected aircraft for interceptions */ 427 aircraft_t* missionAircraft; /**< aircraft pointer for mission handling */ 428 } geoscape; 429 430 /* == misc == */ 431 /* MA_NEWBASE, MA_INTERCEPT, MA_BASEATTACK, ... */ 432 mapAction_t mapAction; 433 434 /** @todo move into the base node extra data */ 435 /* BA_NEWBUILDING ... */ 436 baseAction_t baseAction; 437 438 /* how fast the game is running */ 439 int gameTimeScale; 440 int gameLapse; 441 442 /* already paid in this month? */ 443 bool paid; 444 445 /** Coordinates to place the new base at (long, lat) */ 446 vec2_t newBasePos; 447 448 /* == employees == */ 449 /* A list of all phalanx employees (soldiers, scientists, workers, etc...) */ 450 linkedList_t* employees[MAX_EMPL]; 451 452 /* == technologies == */ 453 /* A list of all research-topics resp. the research-tree. */ 454 technology_t technologies[MAX_TECHNOLOGIES]; 455 /* Total number of technologies. */ 456 int numTechnologies; 457 458 /* == bases == */ 459 /* A list of _all_ bases ... even unbuilt ones. */ 460 base_t bases[MAX_BASES]; 461 /* Total number of built bases (how many are enabled). */ 462 int numBases; 463 464 /* a list of all templates for building bases */ 465 baseTemplate_t baseTemplates[MAX_BASETEMPLATES]; 466 int numBaseTemplates; 467 468 /* == aircraft == */ 469 linkedList_t* aircraft; 470 471 /* == Alien bases == */ 472 linkedList_t* alienBases; 473 474 /* == Nations == */ 475 nation_t nations[MAX_NATIONS]; 476 int numNations; 477 478 /* == Cities == */ 479 linkedList_t* cities; 480 int numCities; 481 482 /* Projectiles on geoscape (during fights) */ 483 aircraftProjectile_t projectiles[MAX_PROJECTILESONGEOSCAPE]; 484 int numProjectiles; 485 486 /* == Transfers == */ 487 linkedList_t* transfers; 488 489 /* UFO components. */ 490 int numComponents; 491 components_t components[MAX_ASSEMBLIES]; 492 493 /* == stored UFOs == */ 494 linkedList_t* storedUFOs; 495 496 /* Alien Team Package used during battle */ 497 alienTeamCategory_t alienCategories[ALIENCATEGORY_MAX]; /**< different alien team available 498 * that will be used in mission */ 499 int numAlienCategories; /** number of alien team categories defined */ 500 501 /* == ufopedia == */ 502 /* A list of all UFOpaedia chapters. */ 503 pediaChapter_t upChapters[MAX_PEDIACHAPTERS]; 504 /* Total number of UFOpaedia chapters */ 505 int numChapters; 506 int numUnreadMails; /**< only for faster access (don't cycle all techs every frame) */ 507 508 eventMail_t eventMails[MAX_EVENTMAILS]; /**< holds all event mails (cl_event.c) */ 509 int numEventMails; /**< how many eventmails (script-id: mail) parsed */ 510 511 campaignEvents_t campaignEvents[MAX_CAMPAIGNS]; /**< holds all campaign events (cl_event.c) */ 512 int numCampaignEventDefinitions; /**< how many event definitions (script-id: events) parsed */ 513 514 campaignTriggerEvent_t campaignTriggerEvents[MAX_CAMPAIGN_TRIGGER_EVENTS]; 515 int numCampaignTriggerEvents; 516 517 /* == buildings in bases == */ 518 /* A list of all possible unique buildings. */ 519 building_t buildingTemplates[MAX_BUILDINGS]; 520 int numBuildingTemplates; 521 /* A list of the building-list per base. (new buildings in a base get copied from buildingTypes) */ 522 building_t buildings[MAX_BASES][MAX_BUILDINGS]; 523 /* Total number of buildings per base. */ 524 int numBuildings[MAX_BASES]; 525 526 /* == installations == */ 527 /* A template for each possible installation with configurable values */ 528 installationTemplate_t installationTemplates[MAX_INSTALLATION_TEMPLATES]; 529 int numInstallationTemplates; 530 531 /* A list of _all_ installations */ 532 linkedList_t* installations; 533 534 /* UFOs on geoscape */ 535 aircraft_t ufos[MAX_UFOONGEOSCAPE]; 536 int numUFOs; /**< The current amount of UFOS on the geoscape. */ 537 538 /* message categories */ 539 msgCategory_t messageCategories[MAX_MESSAGECATEGORIES]; 540 int numMsgCategories; 541 542 /* entries for message categories */ 543 msgCategoryEntry_t msgCategoryEntries[NT_NUM_NOTIFYTYPE + MAX_MESSAGECATEGORIES]; 544 int numMsgCategoryEntries; 545 546 /* == Ranks == */ 547 /* Global list of all ranks defined in medals.ufo. */ 548 rank_t ranks[MAX_RANKS]; 549 /* The number of entries in the list above. */ 550 int numRanks; 551 552 /* cache for techdef technologies */ 553 technology_t* teamDefTechs[MAX_TEAMDEFS]; 554 555 /* cache for item technologies */ 556 technology_t* objDefTechs[MAX_OBJDEFS]; 557 558 campaign_t* curCampaign; /**< Current running campaign */ 559 stats_t campaignStats; 560 missionResults_t missionResults; 561 562 campaign_t campaigns[MAX_CAMPAIGNS]; 563 int numCampaigns; 564 565 aircraft_t aircraftTemplates[MAX_AIRCRAFT]; /**< Available aircraft types/templates/samples. */ 566 int numAircraftTemplates; /**< Number of aircraft templates. */ 567 568 missionSpawnFunction_t missionSpawnCallback; 569 missionResultFunction_t missionResultCallback; 570 571 linkedList_t* updateCharacters; 572 } ccs_t; 573 574 typedef struct { 575 int x, y; 576 } screenPoint_t; 577 578 extern ccs_t ccs; 579 extern const int DETECTION_INTERVAL; 580 extern cvar_t* cp_campaign; 581 extern cvar_t* cp_missiontest; 582 extern cvar_t* cp_start_employees; 583 584 #define MAX_CREDITS 10000000 585 586 #include "../cgame.h" 587 extern const cgame_import_t* cgi; 588 589 /* Campaign functions */ 590 void CP_InitStartup(void); 591 campaign_t* CP_GetCampaign(const char* name); 592 void CP_CampaignInit(campaign_t* campaign, bool load); 593 void CP_ParseCampaignData(void); 594 void CP_ReadCampaignData(const campaign_t* campaign); 595 bool CP_IsRunning(void); 596 597 void CP_CampaignRun(campaign_t* campaign, float secondsSinceLastFrame); 598 void CP_CheckLostCondition(const campaign_t* campaign); 599 void CP_EndCampaign(bool won); 600 601 void CP_Shutdown(void); 602 void CP_ResetCampaignData(void); 603 604 /* Mission related functions */ 605 int CP_CountMissionOnGeoscape(void); 606 void CP_UpdateMissionVisibleOnGeoscape(void); 607 int CP_TerrorMissionAvailableUFOs(const mission_t* mission, ufoType_t* ufoTypes); 608 bool AIR_SendAircraftToMission(aircraft_t* aircraft, mission_t* mission); 609 void AIR_AircraftsNotifyMissionRemoved(const mission_t* mission); 610 611 void CP_UFOProceedMission(const campaign_t* campaign, aircraft_t* ufocraft); 612 mission_t* CP_CreateNewMission(interestCategory_t category, bool beginNow); 613 bool CP_ChooseMap(mission_t* mission, const vec2_t pos); 614 void CP_StartSelectedMission(void); 615 616 void CP_HandleNationData(float minHappiness, mission_t* mis, const nation_t* nation, const missionResults_t* results); 617 void CP_UpdateCharacterStats(const base_t* base, const aircraft_t* aircraft); 618 619 /* Credits management */ 620 bool CP_CheckCredits (int costs); 621 void CP_UpdateCredits(int credits); 622 623 /* Other functions */ 624 int CP_CharacterGetMaxExperiencePerMission(const abilityskills_t skill); 625 void CP_UpdateCharacterSkills(character_t* chr); 626 void CP_UpdateCharacterData(linkedList_t* updateCharacters); 627 void CP_ParseCharacterData(dbuffer* msg, linkedList_t** updateCharacters); 628 bool CP_CheckNextStageDestination(const campaign_t* campaign, aircraft_t* ufo); 629 630 aircraft_t* AIR_NewAircraft(base_t* base, const aircraft_t* aircraftTemplate); 631 632 void CP_GetRandomPosOnGeoscape(vec2_t pos, bool noWater); 633 bool CP_GetRandomPosOnGeoscapeWithParameters(vec2_t pos, const linkedList_t* terrainTypes, const linkedList_t* cultureTypes, const linkedList_t* populationTypes, const linkedList_t* nations); 634 635 void CP_GameAutoGo(mission_t* mission, aircraft_t* aircraft, const campaign_t* campaign, const battleParam_t* battleParameters, missionResults_t* results); 636 637 bool CP_OnGeoscape(void); 638