cp_campaign.h

Go to the documentation of this file.
00001 
00006 /*
00007 Copyright (C) 2002-2010 UFO: Alien Invasion.
00008 
00009 This program is free software; you can redistribute it and/or
00010 modify it under the terms of the GNU General Public License
00011 as published by the Free Software Foundation; either version 2
00012 of the License, or (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018 See the GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00023 
00024 */
00025 
00026 #ifndef CLIENT_CL_CAMPAIGN_H
00027 #define CLIENT_CL_CAMPAIGN_H
00028 
00029 extern memPool_t *cp_campaignPool;
00030 
00031 struct aircraft_s;
00032 struct installation_s;
00033 struct employee_s;
00034 struct ugv_s;
00035 struct uiNode_s; 
00037 #define MAX_CAMPAIGNS   16
00038 
00039 #define MAX_ASSEMBLIES  16
00040 
00042 #define BYTES_NONE  0xFF
00043 
00044 #include "cp_rank.h"
00045 #include "cp_save.h"
00046 #include "cp_parse.h"
00047 #include "cp_event.h"
00048 #include "cp_ufopedia.h"
00049 #include "cp_research.h"
00050 #include "cp_radar.h"
00051 #include "cp_aircraft.h"
00052 #include "cp_base.h"
00053 #include "cp_employee.h"
00054 #include "cp_transfer.h"
00055 #include "cp_nation.h"
00056 #include "cp_installation.h"
00057 #include "cp_produce.h"
00058 #include "cp_uforecovery.h"
00059 #include "cp_airfight.h"
00060 #include "cp_messageoptions.h"
00061 #include "cp_alienbase.h"
00062 #include "cp_market.h"
00063 #include "cp_statistics.h"
00064 
00065 /* check for water */
00066 /* blue value is 64 */
00067 #define MapIsWater(color)        (color[0] ==   0 && color[1] ==   0 && color[2] ==  64)
00068 
00069 /* terrain types */
00070 #define MapIsArctic(color)       (color[0] == 128 && color[1] == 255 && color[2] == 255)
00071 #define MapIsDesert(color)       (color[0] == 255 && color[1] == 128 && color[2] ==   0)
00072 #define MapIsMountain(color)     (color[0] == 255 && color[1] ==   0 && color[2] ==   0)
00073 #define MapIsTropical(color)     (color[0] == 128 && color[1] == 128 && color[2] == 255)
00074 #define MapIsGrass(color)        (color[0] == 128 && color[1] == 255 && color[2] ==   0)
00075 #define MapIsWasted(color)       (color[0] == 128 && color[1] ==   0 && color[2] == 128)
00076 #define MapIsCold(color)         (color[0] ==   0 && color[1] ==   0 && color[2] == 255)
00077 
00078 /* culture types */
00079 #define MapIsWestern(color)      (color[0] == 128 && color[1] == 255 && color[2] == 255)
00080 #define MapIsEastern(color)      (color[0] == 255 && color[1] == 128 && color[2] ==   0)
00081 #define MapIsOriental(color)     (color[0] == 255 && color[1] ==   0 && color[2] ==   0)
00082 #define MapIsAfrican(color)      (color[0] == 128 && color[1] == 128 && color[2] == 255)
00083 
00084 /* population types */
00085 #define MapIsUrban(color)        (color[0] == 128 && color[1] == 255 && color[2] == 255)
00086 #define MapIsSuburban(color)     (color[0] == 255 && color[1] == 128 && color[2] ==   0)
00087 #define MapIsVillage(color)      (color[0] == 255 && color[1] ==   0 && color[2] ==   0)
00088 #define MapIsRural(color)        (color[0] == 128 && color[1] == 128 && color[2] == 255)
00089 #define MapIsNopopulation(color) (color[0] == 128 && color[1] == 255 && color[2] ==   0)
00090 
00091 /* RASTER enables a better performance for CP_GetRandomPosOnGeoscapeWithParameters set it to 1-6
00092  * the higher the value the better the performance, but the smaller the coverage */
00093 #define RASTER 2
00094 
00095 /* nation happiness constants */
00096 #define HAPPINESS_SUBVERSION_LOSS           -0.15
00097 #define HAPPINESS_ALIEN_MISSION_LOSS        -0.02
00098 #define HAPPINESS_UFO_SALE_GAIN             0.02
00099 #define HAPPINESS_UFO_SALE_LOSS             0.005
00100 #define HAPPINESS_MAX_MISSION_IMPACT        0.07
00101 
00102 /* Maximum alien groups per alien team category */
00103 #define MAX_ALIEN_GROUP_PER_CATEGORY    4
00104 /* Maximum alien team category defined in scripts */
00105 #define ALIENCATEGORY_MAX   8
00106 #define BID_FACTOR 0.9
00107 #define MAX_PROJECTILESONGEOSCAPE 32
00108 
00112 #define HOURS_PER_ONE_INTEREST              22
00113 
00117 #define INITIAL_OVERALL_INTEREST            20
00118 #define FINAL_OVERALL_INTEREST              1000
00119 
00123 #define DELAY_BETWEEN_MISSION_SPAWNING      4
00124 
00129 #define MINIMUM_MISSIONS_PER_CYCLE          5
00130 #define MAXIMUM_MISSIONS_PER_CYCLE          40
00131 
00135 #define NON_OCCURRENCE_PROBABILITY          0.65
00136 
00138 typedef enum mapType_s {
00139     MAPTYPE_TERRAIN,
00140     MAPTYPE_CULTURE,
00141     MAPTYPE_POPULATION,
00142     MAPTYPE_NATIONS,
00143 
00144     MAPTYPE_MAX
00145 } mapType_t;
00146 
00148 typedef enum missionDetectionStatus_s {
00149     MISDET_CANT_BE_DETECTED,        
00150     MISDET_ALWAYS_DETECTED,         
00151     MISDET_MAY_BE_DETECTED          
00152 } missionDetectionStatus_t;
00153 
00155 typedef enum interestCategory_s {
00156     INTERESTCATEGORY_NONE,          
00157     INTERESTCATEGORY_RECON,         
00158     INTERESTCATEGORY_TERROR_ATTACK, 
00159     INTERESTCATEGORY_BASE_ATTACK,   
00160     INTERESTCATEGORY_BUILDING,      
00161     INTERESTCATEGORY_SUPPLY,        
00162     INTERESTCATEGORY_XVI,           
00163     INTERESTCATEGORY_INTERCEPT,     
00164     INTERESTCATEGORY_HARVEST,       
00165     INTERESTCATEGORY_ALIENBASE,     
00168     INTERESTCATEGORY_RESCUE,
00169 
00170     INTERESTCATEGORY_MAX
00171 } interestCategory_t;
00172 
00174 typedef enum missionStage_s {
00175     STAGE_NOT_ACTIVE,               
00176     STAGE_COME_FROM_ORBIT,          
00178     STAGE_RECON_AIR,                
00179     STAGE_MISSION_GOTO,             
00180     STAGE_RECON_GROUND,             
00181     STAGE_TERROR_MISSION,           
00182     STAGE_BUILD_BASE,               
00183     STAGE_BASE_ATTACK,              
00184     STAGE_SUBVERT_GOV,              
00185     STAGE_SUPPLY,                   
00186     STAGE_SPREAD_XVI,               
00187     STAGE_INTERCEPT,                
00188     STAGE_BASE_DISCOVERED,          
00189     STAGE_HARVEST,                  
00191     STAGE_RETURN_TO_ORBIT,          
00193     STAGE_OVER                      
00194 } missionStage_t;
00195 
00201 typedef struct alienTeamGroup_s {
00202     int idx;            
00203     int categoryIdx;    
00204     int minInterest;    
00205     int maxInterest;    
00207     teamDef_t *alienTeams[MAX_TEAMS_PER_MISSION];   
00209     int numAlienTeams;      
00210 } alienTeamGroup_t;
00211 
00217 typedef struct alienTeamCategory_s {
00218     char id[MAX_VAR];           
00219     interestCategory_t missionCategories[INTERESTCATEGORY_MAX];     
00221     int numMissionCategories;                   
00223     linkedList_t *equipment;        
00225     alienTeamGroup_t alienTeamGroups[MAX_ALIEN_GROUP_PER_CATEGORY];     
00227     int numAlienTeamGroups;     
00228 } alienTeamCategory_t;
00229 
00234 typedef struct mission_s {
00235     int idx;                        
00236     char id[MAX_VAR];               
00237     mapDef_t* mapDef;               
00238     qboolean active;                
00239     void* data;                     
00240     char location[MAX_VAR];         
00241     interestCategory_t category;    
00242     missionStage_t stage;           
00243     int initialOverallInterest;     
00244     int initialIndividualInterest;  
00245     date_t startDate;               
00246     date_t finalDate;               
00248     vec2_t pos;                     
00249     aircraft_t *ufo;                
00250     qboolean onGeoscape;            
00251     qboolean crashed;               
00253     char onwin[MAX_VAR];            
00254     char onlose[MAX_VAR];           
00255     qboolean posAssigned;           
00256 } mission_t;
00257 
00259 typedef struct battleParam_s {
00260     mission_t *mission;
00261     alienTeamGroup_t *alienTeamGroup;   
00262     char *param;                    
00264     char alienEquipment[MAX_VAR];                   
00265     char civTeam[MAX_VAR];                          
00266     qboolean day;                                   
00267     const char *zoneType;                           
00268     int aliens, civilians;          
00269     struct nation_s *nation;        
00270 } battleParam_t;
00271 
00273 typedef struct missionResults_s {
00274     int itemTypes;      
00275     int itemAmount;     
00276     qboolean recovery;  
00277     ufoType_t ufotype;  
00278     qboolean crashsite; 
00279     float ufoCondition; 
00280     int aliensKilled;
00281     int aliensStunned;
00282     int aliensSurvived;
00283     int ownKilled;
00284     int ownStunned;
00285     int ownKilledFriendlyFire;
00286     int ownSurvived;
00287     int civiliansKilled;
00288     int civiliansKilledFriendlyFire;
00289     int civiliansSurvived;
00290 } missionResults_t;
00291 
00293 typedef struct campaign_s {
00294     int idx;                    
00295     char id[MAX_VAR];           
00296     char name[MAX_VAR];         
00297     int team;                   
00298     char researched[MAX_VAR];   
00299     char equipment[MAX_VAR];    
00300     char market[MAX_VAR];       
00301     char asymptoticMarket[MAX_VAR];     
00302     const equipDef_t *marketDef;        
00303     const equipDef_t *asymptoticMarketDef;  
00304     char text[MAX_VAR];         
00305     char map[MAX_VAR];          
00306     int soldiers;               
00307     int scientists;             
00308     int workers;                
00309     int ugvs;                   
00310     int credits;                
00311     int num;
00312     signed int difficulty;      
00313     float minhappiness;         
00314     int negativeCreditsUntilLost;   
00315     int maxAllowedXVIRateUntilLost; 
00316     qboolean visible;           
00317     date_t date;                
00318     int basecost;               
00319     char firstBaseTemplate[MAX_VAR];    
00320     qboolean finished;
00321     const campaignEvents_t *events;
00322 } campaign_t;
00323 
00325 typedef struct salary_s {
00326     int base[MAX_EMPL];
00327     int rankBonus[MAX_EMPL];
00328     int admin[MAX_EMPL];
00329     int aircraftFactor;
00330     int aircraftDivisor;
00331     int baseUpkeep;
00332     int adminInitial;
00333     float debtInterest;
00334 } salary_t;
00335 
00336 #define SALARY_AIRCRAFT_FACTOR ccs.salaries[ccs.curCampaign->idx].aircraftFactor
00337 #define SALARY_AIRCRAFT_DIVISOR ccs.salaries[ccs.curCampaign->idx].aircraftDivisor
00338 #define SALARY_BASE_UPKEEP ccs.salaries[ccs.curCampaign->idx].baseUpkeep
00339 #define SALARY_ADMIN_INITIAL ccs.salaries[ccs.curCampaign->idx].adminInitial
00340 #define SALARY_DEBT_INTEREST ccs.salaries[ccs.curCampaign->idx].debtInterest
00341 
00342 int CP_GetSalaryBaseEmployee(employeeType_t type);
00343 int CP_GetSalaryAdminEmployee(employeeType_t type);
00344 int CP_GetSalaryRankBonusEmployee(employeeType_t type);
00345 int CP_GetSalaryAdministrative(void);
00346 int CP_GetSalaryUpKeepBase(const base_t *base);
00347 
00349 typedef enum mapAction_s {
00350     MA_NONE,
00351     MA_NEWBASE,             
00352     MA_NEWINSTALLATION,     
00353     MA_INTERCEPT,           
00354     MA_BASEATTACK,          
00355     MA_UFORADAR             
00356 } mapAction_t;
00357 
00362 typedef struct ccs_s {
00363     equipDef_t eMission;
00364     market_t eMarket;                       
00366     linkedList_t *missions;                 
00368     battleParam_t battleParameters;         
00370     int lastInterestIncreaseDelay;              
00371     int overallInterest;                        
00372     int interest[INTERESTCATEGORY_MAX];         
00373     int lastMissionSpawnedDelay;                
00375     vec2_t mapPos;      
00376     vec2_t mapSize;     
00378     int credits;            
00379     int civiliansKilled;    
00380     int aliensKilled;       
00381     date_t date;            
00382     qboolean XVIShowMap;            
00383     qboolean breathingMailSent;     
00384     float timer;
00385 
00386     vec3_t angles;          
00387     vec2_t center;          
00388     float zoom;             
00390     aircraft_t *interceptAircraft;      
00392     mission_t *selectedMission;         
00393     aircraft_t *selectedAircraft;       
00394     aircraft_t *selectedUFO;            
00396     /* == misc == */
00397     /* MA_NEWBASE, MA_INTERCEPT, MA_BASEATTACK, ... */
00398     mapAction_t mapAction;
00399 
00401     /* BA_NEWBUILDING ... */
00402     baseAction_t baseAction;
00403 
00404     /* how fast the game is running */
00405     int gameTimeScale;
00406     int gameLapse;
00407 
00408     aircraft_t *missionAircraft;    
00410     /* already paid in this month? */
00411     qboolean paid;
00412 
00413     /* == employees == */
00414     /* A list of all phalanx employees (soldiers, scientists, workers, etc...) */
00415     employee_t employees[MAX_EMPL][MAX_EMPLOYEES];
00416     /* Total number of employees. */
00417     int numEmployees[MAX_EMPL];
00418 
00419     /* == technologies == */
00420     /* A list of all research-topics resp. the research-tree. */
00421     technology_t technologies[MAX_TECHNOLOGIES];
00422     /* Total number of technologies. */
00423     int numTechnologies;
00424 
00425     /* == bases == */
00426     /* A list of _all_ bases ... even unbuilt ones. */
00427     base_t bases[MAX_BASES];
00428     /* Total number of built bases (how many are enabled). */
00429     int numBases;
00430 
00431     /* a list of all templates for building bases */
00432     baseTemplate_t baseTemplates[MAX_BASETEMPLATES];
00433     int numBaseTemplates;
00434 
00435     /* used for unique aircraft ids */
00436     int numAircraft;
00437 
00438     /* == Alien bases == */
00439     linkedList_t *alienBases;
00440 
00441     /* == Nations == */
00442     nation_t nations[MAX_NATIONS];
00443     int numNations;
00444 
00445     /* == Cities == */
00446     linkedList_t *cities;
00447     int numCities;
00448 
00449     /* Projectiles on geoscape (during fights) */
00450     aircraftProjectile_t projectiles[MAX_PROJECTILESONGEOSCAPE];
00451     int numProjectiles;
00452 
00453     /* == Transfers == */
00454     transfer_t transfers[MAX_TRANSFERS];
00455     int numTransfers;
00456 
00457     /* UFO components. */
00458     int numComponents;
00459     components_t components[MAX_ASSEMBLIES];
00460 
00461     /* == stored UFOs == */
00462     linkedList_t *storedUFOs;
00463 
00464     /* Alien Team Definitions. */
00465     teamDef_t *alienTeams[MAX_TEAMDEFS];
00466     int numAliensTD;
00467 
00468     /* Alien Team Package used during battle */
00469     alienTeamCategory_t alienCategories[ALIENCATEGORY_MAX]; 
00471     int numAlienCategories;     
00473     /* == ufopedia == */
00474     /* A list of all UFOpaedia chapters. */
00475     pediaChapter_t upChapters[MAX_PEDIACHAPTERS];
00476     /* Total number of UFOpaedia chapters */
00477     int numChapters;
00478     int numUnreadMails; 
00480     eventMail_t eventMails[MAX_EVENTMAILS]; 
00481     int numEventMails;  
00483     campaignEvents_t campaignEvents[MAX_CAMPAIGNS]; 
00484     int numCampaignEventDefinitions;    
00486     /* == buildings in bases == */
00487     /* A list of all possible unique buildings. */
00488     building_t buildingTemplates[MAX_BUILDINGS];
00489     int numBuildingTemplates;
00490     /*  A list of the building-list per base. (new buildings in a base get copied from buildingTypes) */
00491     building_t buildings[MAX_BASES][MAX_BUILDINGS];
00492     /* Total number of buildings per base. */
00493     int numBuildings[MAX_BASES];
00494 
00495     /* == installations == */
00496     /* A template for each possible installation with configurable values */
00497     installationTemplate_t installationTemplates[MAX_INSTALLATION_TEMPLATES];
00498     int numInstallationTemplates;
00499 
00500     /* A list of _all_ installations ... even unbuilt ones. */
00501     installation_t installations[MAX_INSTALLATIONS];
00502     /* Total number of built installations (how many are enabled). */
00503     int numInstallations;
00504 
00505     /* == production == */
00506     /* we will allow only one active production at the same time for each base */
00507     production_queue_t productions[MAX_BASES];
00508 
00509     /* == Aircraft == */
00510     /* UFOs on geoscape */
00511     aircraft_t ufos[MAX_UFOONGEOSCAPE];
00512     int numUFOs;    
00514     /* message categories */
00515     msgCategory_t messageCategories[MAX_MESSAGECATEGORIES];
00516     int numMsgCategories;
00517 
00518     /* entries for message categories */
00519     msgCategoryEntry_t msgCategoryEntries[NT_NUM_NOTIFYTYPE + MAX_MESSAGECATEGORIES];
00520     int numMsgCategoryEntries;
00521 
00522     /* == Ranks == */
00523     /* Global list of all ranks defined in medals.ufo. */
00524     rank_t ranks[MAX_RANKS];
00525     /* The number of entries in the list above. */
00526     int numRanks;
00527 
00528     /* cache for techdef technologies */
00529     technology_t *teamDefTechs[MAX_TEAMDEFS];
00530 
00531     /* cache for item technologies */
00532     technology_t *objDefTechs[MAX_OBJDEFS];
00533 
00534     campaign_t *curCampaign;            
00535     stats_t campaignStats;
00536     missionResults_t missionResults;
00537 
00538     campaign_t campaigns[MAX_CAMPAIGNS];
00539     int numCampaigns;
00540     salary_t salaries[MAX_CAMPAIGNS];
00541 
00542     aircraft_t aircraftTemplates[MAX_AIRCRAFT];     
00543     int numAircraftTemplates;       
00544 } ccs_t;
00545 
00552 typedef struct dateLong_s {
00553     short year; 
00554     byte month; 
00555     byte day;   
00556     byte hour;  
00557     byte min;   
00558     byte sec;   
00559 } dateLong_t;
00560 
00561 typedef struct {
00562     int x, y;
00563 } screenPoint_t;
00564 
00565 extern ccs_t ccs;
00566 extern const int DETECTION_INTERVAL;
00567 extern cvar_t *cp_campaign;
00568 extern cvar_t *cp_missiontest;
00569 extern cvar_t *cp_start_employees;
00570 
00571 void CP_ParseCharacterData(struct dbuffer *msg);
00572 qboolean CP_CheckNextStageDestination(aircraft_t *ufo);
00573 
00574 void CP_InitStartup(void);
00575 void CL_ResetSinglePlayerData(void);
00576 void CL_DateConvert(const date_t * date, byte *day, byte *month, short *year);
00577 void CL_DateConvertLong(const date_t * date, dateLong_t * dateLong);
00578 int CL_DateCreateDay(const short years, const byte months, const byte days);
00579 int CL_DateCreateSeconds(byte hours, byte minutes, byte seconds);
00580 void CL_CampaignRun(void);
00581 void CP_EndCampaign(qboolean won);
00582 void CL_UpdateCredits(int credits);
00583 aircraft_t* AIR_NewAircraft(base_t * base, const char *name);
00584 const char* CL_SecondConvert(int second);
00585 void CL_ReadSinglePlayerData(void);
00586 
00587 void CP_GetRandomPosOnGeoscape(vec2_t pos, qboolean noWater);
00588 qboolean CP_GetRandomPosOnGeoscapeWithParameters(vec2_t pos, const linkedList_t *terrainTypes, const linkedList_t *cultureTypes, const linkedList_t *populationTypes, const linkedList_t *nations);
00589 
00590 campaign_t* CL_GetCampaign(const char *name);
00591 void CL_GameAutoGo(mission_t *mission);
00592 
00593 void CP_InitMissionResults(qboolean won);
00594 void CP_CampaignInit(campaign_t *campaign, qboolean load);
00595 void CP_CampaignExit(void);
00596 qboolean CP_OnGeoscape(void);
00597 
00598 /* Mission related functions */
00599 int CP_CountMission(void);
00600 int CP_CountMissionActive(void);
00601 int CP_CountMissionOnGeoscape(void);
00602 void CP_UpdateMissionVisibleOnGeoscape(void);
00603 int CP_TerrorMissionAvailableUFOs(const mission_t const *mission, ufoType_t *ufoTypes);
00604 qboolean AIR_SendAircraftToMission(aircraft_t *aircraft, mission_t *mission);
00605 void AIR_AircraftsNotifyMissionRemoved(const mission_t *mission);
00606 
00607 void CP_UFOProceedMission(aircraft_t *ufocraft);
00608 qboolean CP_IsRunning(void);
00609 
00610 mission_t *CP_CreateNewMission(interestCategory_t category, qboolean beginNow);
00611 qboolean CP_ChooseMap(mission_t *mission, const vec2_t pos);
00612 void CP_StartSelectedMission(void);
00613 void CL_HandleNationData(qboolean won, mission_t * mis);
00614 void CP_CheckLostCondition(void);
00615 void CL_UpdateCharacterStats(const base_t *base, const aircraft_t *aircraft);
00616 
00617 #endif /* CLIENT_CL_CAMPAIGN_H */

Generated by  doxygen 1.6.2