cp_mission_recon.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 
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         /* Display UFO on geoscape if it is detected */
00077         mission->ufo->landed = qfalse;
00078     } else {
00079         /* Go to next stage on next frame */
00080         mission->finalDate = ccs.date;
00081     }
00082     CP_MissionRemoveFromGeoscape(mission);
00083 }
00084 
00091 static qboolean CP_ReconMissionChoose (mission_t *mission)
00092 {
00093     /* mission without UFO is always a ground mission */
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};       /* How long the UFO will fly on earth */
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     /* maybe the UFO just finished a ground mission and starts a new one? */
00130     if (mission->ufo) {
00131         CP_MissionRemoveFromGeoscape(mission);
00132         mission->ufo->landed = qfalse;
00133     }
00134 
00135     /* Choose a map */
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         /* Go to next stage on next frame */
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     /* ufo becomes invisible on geoscape, but don't remove it from ufo global array (may reappear)*/
00187     if (mission->ufo)
00188         CP_UFORemoveFromGeoscape(mission, qfalse);
00189     /* mission appear on geoscape, player can go there */
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         /* this is the begining of the mission: choose between aerial or ground mission */
00212         if (CP_ReconMissionChoose(mission))
00213             /* This is a aerial mission */
00214             CP_ReconMissionAerial(mission);
00215         else
00216             /* This is a ground mission */
00217             CP_ReconMissionGroundGo(mission);
00218     } else if (mission->stage == STAGE_RECON_GROUND) {
00219         /* Ground mission may occur several times */
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         /* Create Recon mission */
00253         CP_MissionBegin(mission);
00254         break;
00255     case STAGE_COME_FROM_ORBIT:
00256     case STAGE_RECON_GROUND:
00257         /* Choose if a new ground mission should be started */
00258         CP_ReconMissionSelect(mission);
00259         break;
00260     case STAGE_MISSION_GOTO:
00261         /* just arrived on a new ground mission: start it */
00262         CP_ReconMissionGround(mission);
00263         break;
00264     case STAGE_RECON_AIR:
00265         /* Leave earth */
00266         CP_ReconMissionLeave(mission);
00267         break;
00268     case STAGE_RETURN_TO_ORBIT:
00269         /* mission is over, remove mission */
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 

Generated by  doxygen 1.6.2