cp_mission_terror.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_map.h"
00029 #include "../cp_ufo.h"
00030 #include "../cp_missions.h"
00031 #include "../cp_time.h"
00032 #include "../cp_alien_interest.h"
00033 
00038 void CP_TerrorMissionIsSuccess (mission_t *mission)
00039 {
00040     CL_ChangeIndividualInterest(-0.2f, INTERESTCATEGORY_BASE_ATTACK);
00041     CL_ChangeIndividualInterest(0.03f, INTERESTCATEGORY_HARVEST);
00042 
00043     CP_MissionRemove(mission);
00044 }
00045 
00050 void CP_TerrorMissionIsFailure (mission_t *mission)
00051 {
00052     CL_ChangeIndividualInterest(0.05f, INTERESTCATEGORY_TERROR_ATTACK);
00053     CL_ChangeIndividualInterest(0.1f, INTERESTCATEGORY_INTERCEPT);
00054     CL_ChangeIndividualInterest(0.05f, INTERESTCATEGORY_BUILDING);
00055     CL_ChangeIndividualInterest(0.02f, INTERESTCATEGORY_BASE_ATTACK);
00056 
00057     CP_MissionRemove(mission);
00058 }
00059 
00060 
00064 void CP_TerrorMissionOnSpawn (void)
00065 {
00066     /* Prevent multiple terror missions per cycle by resetting interest. */
00067     CL_ChangeIndividualInterest(-1.0f, INTERESTCATEGORY_TERROR_ATTACK);
00068 }
00069 
00070 
00075 void CP_TerrorMissionStart (mission_t *mission)
00076 {
00077     const date_t minMissionDelay = {2, 0};
00078     const date_t missionDelay = {3, 0};
00079 
00080     mission->stage = STAGE_TERROR_MISSION;
00081 
00082     mission->finalDate = Date_Add(ccs.date, Date_Random(minMissionDelay, missionDelay));
00083     /* ufo becomes invisible on geoscape, but don't remove it from ufo global array (may reappear)*/
00084     if (mission->ufo)
00085         CP_UFORemoveFromGeoscape(mission, qfalse);
00086     /* mission appear on geoscape, player can go there */
00087     CP_MissionAddToGeoscape(mission, qfalse);
00088 }
00089 
00090 
00095 static const city_t* CP_ChooseCity (void)
00096 {
00097     if (ccs.numCities > 0) {
00098         const int randnumber = rand() % ccs.numCities;
00099 
00100         return (city_t*) LIST_GetByIdx(ccs.cities, randnumber);
00101     } else {
00102         return NULL;
00103     }
00104 }
00105 
00106 static const mission_t* CP_TerrorInCity (const city_t *city)
00107 {
00108     const linkedList_t *list = ccs.missions;
00109 
00110     if (!city)
00111         return NULL;
00112 
00113     for (;list; list = list->next) {
00114         mission_t *mission = (mission_t *)list->data;
00115         if (mission->category == INTERESTCATEGORY_TERROR_ATTACK
00116          && mission->stage <= STAGE_TERROR_MISSION
00117          && mission->pos[0] == city->pos[0]
00118          && mission->pos[1] == city->pos[1])
00119             return mission;
00120     }
00121     return NULL;
00122 }
00123 
00129 static void CP_TerrorMissionGo (mission_t *mission)
00130 {
00131     int counter;
00132 
00133     mission->stage = STAGE_MISSION_GOTO;
00134 
00135     /* Choose a map */
00136     for (counter = 0; counter < MAX_POS_LOOP; counter++) {
00137         const city_t const *city = CP_ChooseCity();
00138 
00139         if (!city)
00140             continue;
00141 
00142         if (MAP_PositionCloseToBase(city->pos))
00143             continue;
00144 
00145         if (!CP_ChooseMap(mission, city->pos))
00146             continue;
00147 
00148         if (CP_TerrorInCity(city))
00149             continue;
00150 
00151         Vector2Copy(city->pos, mission->pos);
00152         mission->posAssigned = qtrue;
00153         Com_sprintf(mission->location, sizeof(mission->location), "%s", _(city->name));
00154         break;
00155     }
00156     if (counter >= MAX_POS_LOOP) {
00157         Com_DPrintf(DEBUG_CLIENT, "CP_TerrorMissionGo: Could not set position.\n");
00158         CP_MissionRemove(mission);
00159         return;
00160     }
00161 
00162     if (mission->ufo) {
00163         CP_MissionDisableTimeLimit(mission);
00164         UFO_SendToDestination(mission->ufo, mission->pos);
00165     } else {
00166         /* Go to next stage on next frame */
00167         mission->finalDate = ccs.date;
00168     }
00169 }
00170 
00179 int CP_TerrorMissionAvailableUFOs (const mission_t const *mission, ufoType_t *ufoTypes)
00180 {
00181     int num = 0;
00182 
00183     ufoTypes[num++] = UFO_HARVESTER;
00184     if (UFO_ShouldAppearOnGeoscape(UFO_CORRUPTER))
00185         ufoTypes[num++] = UFO_CORRUPTER;
00186     if (UFO_ShouldAppearOnGeoscape(UFO_BOMBER))
00187         ufoTypes[num++] = UFO_BOMBER;
00190     return num;
00191 }
00192 
00197 void CP_TerrorMissionNextStage (mission_t *mission)
00198 {
00199     switch (mission->stage) {
00200     case STAGE_NOT_ACTIVE:
00201         /* Create Terror attack mission */
00202         CP_MissionBegin(mission);
00203         break;
00204     case STAGE_COME_FROM_ORBIT:
00205         /* Go to mission */
00206         CP_TerrorMissionGo(mission);
00207         break;
00208     case STAGE_MISSION_GOTO:
00209         /* just arrived on a new Terror attack mission: start it */
00210         CP_TerrorMissionStart(mission);
00211         break;
00212     case STAGE_TERROR_MISSION:
00213         /* Leave earth */
00214         CP_ReconMissionLeave(mission);
00215         break;
00216     case STAGE_RETURN_TO_ORBIT:
00217         /* mission is over, remove mission */
00218         CP_TerrorMissionIsSuccess(mission);
00219         break;
00220     default:
00221         Com_Printf("CP_TerrorMissionNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
00222         CP_MissionRemove(mission);
00223         break;
00224     }
00225 }

Generated by  doxygen 1.6.2