cp_mission_recon.c
Go to the documentation of this file.00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "../../cl_shared.h"
00027 #include "../cp_campaign.h"
00028 #include "../cp_alienbase.h"
00029 #include "../cp_map.h"
00030 #include "../cp_ufo.h"
00031 #include "../cp_missions.h"
00032 #include "../cp_time.h"
00033 #include "../cp_xvi.h"
00034 #include "../cp_alien_interest.h"
00035
00040 static void CP_ReconMissionIsSuccess (mission_t *mission)
00041 {
00042 CL_ChangeIndividualInterest(-0.2f, INTERESTCATEGORY_RECON);
00043 CL_ChangeIndividualInterest(0.1f, INTERESTCATEGORY_HARVEST);
00044 if (AB_GetAlienBaseNumber())
00045 CL_ChangeIndividualInterest(0.1f, INTERESTCATEGORY_SUPPLY);
00046 if (CP_IsXVIResearched())
00047 CL_ChangeIndividualInterest(0.1f, INTERESTCATEGORY_XVI);
00048
00049 CP_MissionRemove(mission);
00050 }
00051
00056 void CP_ReconMissionIsFailure (mission_t *mission)
00057 {
00058 CL_ChangeIndividualInterest(0.05f, INTERESTCATEGORY_RECON);
00059 CL_ChangeIndividualInterest(0.1f, INTERESTCATEGORY_INTERCEPT);
00060 CL_ChangeIndividualInterest(0.05f, INTERESTCATEGORY_TERROR_ATTACK);
00061
00062 CP_MissionRemove(mission);
00063 }
00064
00069 void CP_ReconMissionLeave (mission_t *mission)
00070 {
00071 mission->stage = STAGE_RETURN_TO_ORBIT;
00072
00073 if (mission->ufo) {
00074 CP_MissionDisableTimeLimit(mission);
00075 UFO_SetRandomDest(mission->ufo);
00076
00077 mission->ufo->landed = qfalse;
00078 } else {
00079
00080 mission->finalDate = ccs.date;
00081 }
00082 CP_MissionRemoveFromGeoscape(mission);
00083 }
00084
00091 static qboolean CP_ReconMissionChoose (mission_t *mission)
00092 {
00093
00094 if (!mission->ufo)
00095 return qfalse;
00096
00097 return (frand() > 0.5f);
00098 }
00099
00105 void CP_ReconMissionAerial (mission_t *mission)
00106 {
00107 const date_t minReconDelay = {1, 0};
00108 const date_t reconDelay = {2, 0};
00109
00110 assert(mission->ufo);
00111
00112 mission->stage = STAGE_RECON_AIR;
00113
00114 mission->finalDate = Date_Add(ccs.date, Date_Random(minReconDelay, reconDelay));
00115 }
00116
00123 void CP_ReconMissionGroundGo (mission_t *mission)
00124 {
00125 const nation_t *nation;
00126
00127 mission->stage = STAGE_MISSION_GOTO;
00128
00129
00130 if (mission->ufo) {
00131 CP_MissionRemoveFromGeoscape(mission);
00132 mission->ufo->landed = qfalse;
00133 }
00134
00135
00136 if (CP_ChooseMap(mission, NULL)) {
00137 int counter;
00138 for (counter = 0; counter < MAX_POS_LOOP; counter++) {
00139 if (!CP_GetRandomPosOnGeoscapeWithParameters(mission->pos, mission->mapDef->terrains, mission->mapDef->cultures, mission->mapDef->populations, NULL))
00140 continue;
00141 if (MAP_PositionCloseToBase(mission->pos))
00142 continue;
00143 mission->posAssigned = qtrue;
00144 break;
00145 }
00146 if (counter >= MAX_POS_LOOP) {
00147 Com_Printf("CP_ReconMissionGroundGo: Error, could not set position.\n");
00148 CP_MissionRemove(mission);
00149 return;
00150 }
00151 } else {
00152 Com_Printf("CP_ReconMissionGroundGo: No map found, remove mission.\n");
00153 CP_MissionRemove(mission);
00154 return;
00155 }
00156
00157 nation = MAP_GetNation(mission->pos);
00158 if (nation) {
00159 Com_sprintf(mission->location, sizeof(mission->location), "%s", _(nation->name));
00160 } else {
00161 Com_sprintf(mission->location, sizeof(mission->location), "%s", _("No nation"));
00162 }
00163
00164 if (mission->ufo) {
00165 CP_MissionDisableTimeLimit(mission);
00166 UFO_SendToDestination(mission->ufo, mission->pos);
00167 } else {
00168
00169 mission->finalDate = ccs.date;
00170 }
00171 }
00172
00177 static void CP_ReconMissionGround (mission_t *mission)
00178 {
00179 const date_t minMissionDelay = {2, 0};
00180 const date_t missionDelay = {3, 0};
00181
00182 mission->stage = STAGE_RECON_GROUND;
00183 mission->posAssigned = qtrue;
00184
00185 mission->finalDate = Date_Add(ccs.date, Date_Random(minMissionDelay, missionDelay));
00186
00187 if (mission->ufo)
00188 CP_UFORemoveFromGeoscape(mission, qfalse);
00189
00190 CP_MissionAddToGeoscape(mission, qfalse);
00191 }
00192
00199 static qboolean CP_ReconMissionNewGroundMission (mission_t *mission)
00200 {
00201 return (frand() > 0.7f);
00202 }
00203
00208 static void CP_ReconMissionSelect (mission_t *mission)
00209 {
00210 if (mission->stage == STAGE_COME_FROM_ORBIT) {
00211
00212 if (CP_ReconMissionChoose(mission))
00213
00214 CP_ReconMissionAerial(mission);
00215 else
00216
00217 CP_ReconMissionGroundGo(mission);
00218 } else if (mission->stage == STAGE_RECON_GROUND) {
00219
00220 if (CP_ReconMissionNewGroundMission(mission))
00221 CP_ReconMissionGroundGo(mission);
00222 else
00223 CP_ReconMissionLeave(mission);
00224 }
00225 }
00226
00234 int CP_ReconMissionAvailableUFOs (const mission_t const *mission, ufoType_t *ufoTypes)
00235 {
00236 int num = 0;
00237
00238 ufoTypes[num++] = UFO_SCOUT;
00239 ufoTypes[num++] = UFO_FIGHTER;
00240
00241 return num;
00242 }
00243
00248 void CP_ReconMissionNextStage (mission_t *mission)
00249 {
00250 switch (mission->stage) {
00251 case STAGE_NOT_ACTIVE:
00252
00253 CP_MissionBegin(mission);
00254 break;
00255 case STAGE_COME_FROM_ORBIT:
00256 case STAGE_RECON_GROUND:
00257
00258 CP_ReconMissionSelect(mission);
00259 break;
00260 case STAGE_MISSION_GOTO:
00261
00262 CP_ReconMissionGround(mission);
00263 break;
00264 case STAGE_RECON_AIR:
00265
00266 CP_ReconMissionLeave(mission);
00267 break;
00268 case STAGE_RETURN_TO_ORBIT:
00269
00270 CP_ReconMissionIsSuccess(mission);
00271 break;
00272 default:
00273 Com_Printf("CP_ReconMissionNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
00274 CP_MissionRemove(mission);
00275 break;
00276 }
00277 }
00278