cp_mission_buildbase.c

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 #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 
00037 const int STARTING_BASEBUILD_INTEREST = 300;
00038 
00044 qboolean CP_BasemissionIsSubvertingGovernmentMission (const mission_t *mission)
00045 {
00046     return mission->initialOverallInterest < STARTING_BASEBUILD_INTEREST;
00047 }
00048 
00053 void CP_BuildBaseMissionIsSuccess (mission_t *mission)
00054 {
00055     if (CP_BasemissionIsSubvertingGovernmentMission(mission)) {
00056         /* This is a subverting government mission */
00057         CL_ChangeIndividualInterest(0.1f, INTERESTCATEGORY_TERROR_ATTACK);
00058     } else {
00059         /* An alien base has been built */
00060         const alienBase_t *base = (alienBase_t *) mission->data;
00061         assert(base);
00062         CP_SpreadXVIAtPos(base->pos);
00063 
00064         CL_ChangeIndividualInterest(0.4f, INTERESTCATEGORY_XVI);
00065         CL_ChangeIndividualInterest(0.4f, INTERESTCATEGORY_SUPPLY);
00066         CL_ChangeIndividualInterest(0.1f, INTERESTCATEGORY_HARVEST);
00067     }
00068 
00069     CP_MissionRemove(mission);
00070 }
00071 
00076 void CP_BuildBaseMissionIsFailure (mission_t *mission)
00077 {
00078     /* Restore some alien interest for build base that has been removed when mission has been created */
00079     CL_ChangeIndividualInterest(0.5f, INTERESTCATEGORY_BUILDING);
00080     CL_ChangeIndividualInterest(0.05f, INTERESTCATEGORY_BASE_ATTACK);
00081 
00082     CP_MissionRemove(mission);
00083 }
00084 
00088 void CP_BuildBaseMissionOnSpawn (void)
00089 {
00090     CL_ChangeIndividualInterest(-0.7f, INTERESTCATEGORY_BUILDING);
00091 }
00092 
00097 void CP_BuildBaseMissionBaseDestroyed (mission_t *mission)
00098 {
00099     /* An alien base has been built */
00100     alienBase_t *base = (alienBase_t *) mission->data;
00101     assert(base);
00102 
00103     CL_ChangeIndividualInterest(+0.1f, INTERESTCATEGORY_BUILDING);
00104     CL_ChangeIndividualInterest(+0.3f, INTERESTCATEGORY_INTERCEPT);
00105 
00106     AB_DestroyBase(base);
00107     mission->data = NULL;
00108     CP_MissionRemove(mission);
00109 }
00110 
00115 static void CP_BuildBaseMissionLeave (mission_t *mission)
00116 {
00117     assert(mission->ufo);
00118     /* there must be an alien base set */
00119     assert(mission->data);
00120 
00121     mission->stage = STAGE_RETURN_TO_ORBIT;
00122 
00123     CP_MissionDisableTimeLimit(mission);
00124     UFO_SetRandomDest(mission->ufo);
00125     /* Display UFO on geoscape if it is detected */
00126     mission->ufo->landed = qfalse;
00127 }
00128 
00134 static void CP_BuildBaseSetUpBase (mission_t *mission)
00135 {
00136     alienBase_t *base;
00137     const date_t minBuildingTime = {5, 0};  
00138     const date_t buildingTime = {10, 0};    
00140     assert(mission->ufo);
00141 
00142     mission->stage = STAGE_BUILD_BASE;
00143 
00144     mission->finalDate = Date_Add(ccs.date, Date_Random(minBuildingTime, buildingTime));
00145 
00146     base = AB_BuildBase(mission->pos);
00147     if (!base) {
00148         Com_DPrintf(DEBUG_CLIENT, "CP_BuildBaseSetUpBase: could not create alien base\n");
00149         CP_MissionRemove(mission);
00150         return;
00151     }
00152     mission->data = (void *) base;
00153 
00154     /* ufo becomes invisible on geoscape */
00155     CP_UFORemoveFromGeoscape(mission, qfalse);
00156 }
00157 
00163 static void CP_BuildBaseGoToBase (mission_t *mission)
00164 {
00165     assert(mission->ufo);
00166 
00167     mission->stage = STAGE_MISSION_GOTO;
00168 
00169     AB_SetAlienBasePosition(mission->pos);
00170 
00171     UFO_SendToDestination(mission->ufo, mission->pos);
00172 }
00173 
00178 static void CP_BuildBaseGovernmentLeave (mission_t *mission)
00179 {
00180     nation_t *nation;
00181 
00182     assert(mission);
00183     assert(mission->ufo);
00184 
00185     mission->stage = STAGE_RETURN_TO_ORBIT;
00186 
00187     /* Mission is a success: government is subverted => lower happiness */
00188     nation = MAP_GetNation(mission->pos);
00191     if (nation)
00192         NAT_SetHappiness(nation, nation->stats[0].happiness + HAPPINESS_SUBVERSION_LOSS);
00193 
00194     CP_MissionDisableTimeLimit(mission);
00195     UFO_SetRandomDest(mission->ufo);
00196     /* Display UFO on geoscape if it is detected */
00197     mission->ufo->landed = qfalse;
00198 }
00199 
00204 static void CP_BuildBaseSubvertGovernment (mission_t *mission)
00205 {
00206     const date_t minMissionDelay = {3, 0};
00207     const date_t missionDelay = {5, 0};
00208 
00209     assert(mission->ufo);
00210 
00211     mission->stage = STAGE_SUBVERT_GOV;
00212 
00213     /* mission appear on geoscape, player can go there */
00214     CP_MissionAddToGeoscape(mission, qfalse);
00215 
00216     mission->finalDate = Date_Add(ccs.date, Date_Random(minMissionDelay, missionDelay));
00217     /* ufo becomes invisible on geoscape, but don't remove it from ufo global array (may reappear)*/
00218     CP_UFORemoveFromGeoscape(mission, qfalse);
00219 }
00220 
00225 static void CP_BuildBaseChooseMission (mission_t *mission)
00226 {
00227     if (CP_BasemissionIsSubvertingGovernmentMission(mission))
00228         CP_ReconMissionGroundGo(mission);
00229     else
00230         CP_BuildBaseGoToBase(mission);
00231 }
00232 
00240 int CP_BuildBaseMissionAvailableUFOs (const mission_t const *mission, ufoType_t *ufoTypes)
00241 {
00242     int num = 0;
00243 
00244     if (CP_BasemissionIsSubvertingGovernmentMission(mission)) {
00245         /* This is a subverting government mission */
00246         ufoTypes[num++] = UFO_SCOUT;
00247     } else {
00248         /* This is a Building base mission */
00249         ufoTypes[num++] = UFO_SUPPLY;
00250     }
00251 
00252     return num;
00253 }
00254 
00259 void CP_BuildBaseMissionNextStage (mission_t *mission)
00260 {
00261     switch (mission->stage) {
00262     case STAGE_NOT_ACTIVE:
00263         /* Create mission */
00264         CP_MissionBegin(mission);
00265         break;
00266     case STAGE_COME_FROM_ORBIT:
00267         /* Choose type of mission */
00268         CP_BuildBaseChooseMission(mission);
00269         break;
00270     case STAGE_MISSION_GOTO:
00271         if (CP_BasemissionIsSubvertingGovernmentMission(mission))
00272             /* subverting mission */
00273             CP_BuildBaseSubvertGovernment(mission);
00274         else
00275             /* just arrived on base location: build base */
00276             CP_BuildBaseSetUpBase(mission);
00277         break;
00278     case STAGE_BUILD_BASE:
00279         /* Leave earth */
00280         CP_BuildBaseMissionLeave(mission);
00281         break;
00282     case STAGE_SUBVERT_GOV:
00283         /* Leave earth */
00284         CP_BuildBaseGovernmentLeave(mission);
00285         break;
00286     case STAGE_RETURN_TO_ORBIT:
00287         /* mission is over, remove mission */
00288         CP_BuildBaseMissionIsSuccess(mission);
00289         break;
00290     default:
00291         Com_Printf("CP_BuildBaseMissionNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
00292         CP_MissionRemove(mission);
00293         break;
00294     }
00295 }

Generated by  doxygen 1.6.2