cp_mission_supply.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_ufo.h"
00030 #include "../cp_missions.h"
00031 #include "../cp_time.h"
00032 #include "../cp_xvi.h"
00033 #include "../cp_alien_interest.h"
00034
00039 void CP_SupplyMissionIsSuccess (mission_t *mission)
00040 {
00041 alienBase_t *base;
00042 CL_ChangeIndividualInterest(-0.2f, INTERESTCATEGORY_SUPPLY);
00043
00044
00045 base = (alienBase_t *) mission->data;
00046 assert(base);
00047 CP_SpreadXVIAtPos(base->pos);
00048
00049 CP_MissionRemove(mission);
00050 }
00051
00056 void CP_SupplyMissionIsFailure (mission_t *mission)
00057 {
00058 CL_ChangeIndividualInterest(0.1f, INTERESTCATEGORY_SUPPLY);
00059 CL_ChangeIndividualInterest(0.1f, INTERESTCATEGORY_INTERCEPT);
00060 CL_ChangeIndividualInterest(0.05f, INTERESTCATEGORY_BASE_ATTACK);
00061
00062 CP_MissionRemove(mission);
00063 }
00064
00069 static void CP_SupplyMissionLeave (mission_t *mission)
00070 {
00071 assert(mission->ufo);
00072
00073 assert(mission->data);
00074
00075 mission->stage = STAGE_RETURN_TO_ORBIT;
00076
00077 CP_MissionDisableTimeLimit(mission);
00078 UFO_SetRandomDest(mission->ufo);
00079
00080 mission->ufo->landed = qfalse;
00081 }
00082
00088 static void CP_SupplySetStayAtBase (mission_t *mission)
00089 {
00090 const date_t minSupplyTime = {3, 0};
00091 const date_t supplyTime = {10, 0};
00093 assert(mission->ufo);
00094
00095 assert(mission->data);
00096
00097 mission->stage = STAGE_SUPPLY;
00098
00099
00100 if (!AB_CheckSupplyMissionPossible()) {
00101 Com_DPrintf(DEBUG_CLIENT, "No base in game: removing supply mission.\n");
00102 CP_MissionRemove(mission);
00103 return;
00104 }
00105
00106 mission->finalDate = Date_Add(ccs.date, Date_Random(minSupplyTime, supplyTime));
00107
00108 AB_SupplyBase((alienBase_t *) mission->data, mission->ufo->detected);
00109
00110
00111 CP_UFORemoveFromGeoscape(mission, qfalse);
00112 }
00113
00119 static void CP_SupplyGoToBase (mission_t *mission)
00120 {
00121 alienBase_t *alienBase;
00122
00123 assert(mission->ufo);
00124
00125 mission->stage = STAGE_MISSION_GOTO;
00126
00127
00128 if (!AB_CheckSupplyMissionPossible()) {
00129 Com_DPrintf(DEBUG_CLIENT, "No base in game: removing supply mission.\n");
00130 CP_MissionRemove(mission);
00131 return;
00132 }
00133
00134 alienBase = AB_ChooseBaseToSupply();
00135 assert(alienBase);
00136 mission->data = (void *) alienBase;
00137 Vector2Copy(alienBase->pos, mission->pos);
00138
00139 UFO_SendToDestination(mission->ufo, mission->pos);
00140 }
00141
00146 static void CP_SupplyMissionCreate (mission_t *mission)
00147 {
00148 int ufoType;
00149
00150 mission->stage = STAGE_COME_FROM_ORBIT;
00151
00152
00153 if (!AB_CheckSupplyMissionPossible()) {
00154 Com_DPrintf(DEBUG_CLIENT, "No base in game: removing supply mission.\n");
00155 CP_MissionRemove(mission);
00156 return;
00157 }
00158
00159 ufoType = CP_MissionChooseUFO(mission);
00160 if (ufoType == UFO_MAX) {
00161 Com_DPrintf(DEBUG_CLIENT, "Supply mission can't be spawned without UFO: removing supply mission.\n");
00162 CP_MissionRemove(mission);
00163 } else {
00164 CP_MissionDisableTimeLimit(mission);
00165 mission->ufo = UFO_AddToGeoscape(ufoType, NULL, mission);
00166 if (!mission->ufo) {
00167 Com_Printf("CP_SupplyMissionCreate: Could not add UFO '%s', remove mission\n", Com_UFOTypeToShortName(ufoType));
00168 CP_MissionRemove(mission);
00169 }
00170 }
00171 }
00172
00180 int CP_SupplyMissionAvailableUFOs (const mission_t const *mission, ufoType_t *ufoTypes)
00181 {
00182 int num = 0;
00183
00184 ufoTypes[num++] = UFO_SUPPLY;
00185
00186 return num;
00187 }
00188
00193 void CP_SupplyMissionNextStage (mission_t *mission)
00194 {
00195 switch (mission->stage) {
00196 case STAGE_NOT_ACTIVE:
00197
00198 CP_SupplyMissionCreate(mission);
00199 break;
00200 case STAGE_COME_FROM_ORBIT:
00201
00202 CP_SupplyGoToBase(mission);
00203 break;
00204 case STAGE_MISSION_GOTO:
00205
00206 CP_SupplySetStayAtBase(mission);
00207 break;
00208 case STAGE_SUPPLY:
00209
00210 CP_SupplyMissionLeave(mission);
00211 break;
00212 case STAGE_RETURN_TO_ORBIT:
00213
00214 CP_SupplyMissionIsSuccess(mission);
00215 break;
00216 default:
00217 Com_Printf("CP_SupplyMissionNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
00218 CP_MissionRemove(mission);
00219 break;
00220 }
00221 }