cp_mission_harvest.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_xvi.h"
00033 #include "../cp_alien_interest.h"
00034 
00039 static void CP_HarvestMissionIsSuccess (mission_t *mission)
00040 {
00041     CL_ChangeIndividualInterest(-0.3f, INTERESTCATEGORY_HARVEST);
00042     CL_ChangeIndividualInterest(0.2f, INTERESTCATEGORY_RECON);
00043     CL_ChangeIndividualInterest(0.05f, INTERESTCATEGORY_BUILDING);
00044     if (CP_IsXVIResearched())
00045         CL_ChangeIndividualInterest(0.1f, INTERESTCATEGORY_XVI);
00046 
00047     CP_MissionRemove(mission);
00048 }
00049 
00054 void CP_HarvestMissionIsFailure (mission_t *mission)
00055 {
00056     CL_ChangeIndividualInterest(0.1f, INTERESTCATEGORY_INTERCEPT);
00057     CL_ChangeIndividualInterest(0.03f, INTERESTCATEGORY_BASE_ATTACK);
00058     CL_ChangeIndividualInterest(0.03f, INTERESTCATEGORY_TERROR_ATTACK);
00059 
00060     CP_MissionRemove(mission);
00061 }
00062 
00067 static void CP_HarvestMissionStart (mission_t *mission)
00068 {
00069     const date_t minMissionDelay = {2, 0};
00070     const date_t missionDelay = {3, 0};
00071 
00072     mission->stage = STAGE_HARVEST;
00073 
00074     /* mission appear on geoscape, player can go there */
00075     CP_MissionAddToGeoscape(mission, qfalse);
00076 
00077     if (mission->ufo) {
00078         mission->finalDate = Date_Add(ccs.date, Date_Random(minMissionDelay, missionDelay));
00079         /* ufo becomes invisible on geoscape, but don't remove it from ufo global array (may reappear)*/
00080         CP_UFORemoveFromGeoscape(mission, qfalse);
00081     } else {
00082         /* Go to next stage on next frame */
00083         mission->finalDate = ccs.date;
00084     }
00085 }
00086 
00094 static qboolean CP_ChooseNation (const mission_t *mission, linkedList_t **nationList)
00095 {
00096     nation_t *nation;
00097     int randomNumber, max = 0;
00098     /* Increase this factor to make probability to select non-infected nation higher
00099      * Used to make sure that non-infected nation can still be attacked */
00100     const int OFFSET = 1;
00101 
00102     if (mission->ufo)
00103         return qfalse;
00104 
00105     /* favour mission with higher XVI level */
00106     for (nation = ccs.nations; nation < ccs.nations + ccs.numNations; nation++)
00107         max += OFFSET + nation->stats[0].xviInfection;
00108 
00109     randomNumber = (int) (frand() * (float) max);
00110 
00111     /* Select the corresponding nation */
00112     for (nation = ccs.nations; nation < ccs.nations + ccs.numNations; nation++) {
00113         randomNumber -= OFFSET + nation->stats[0].xviInfection;
00114         if (randomNumber < 0) {
00115             LIST_AddString(nationList, nation->id);
00116             return qtrue;
00117         }
00118     }
00119 
00120     return qfalse;
00121 }
00122 
00130 void CP_HarvestMissionGo (mission_t *mission)
00131 {
00132     const nation_t *nation;
00133 
00134     mission->stage = STAGE_MISSION_GOTO;
00135 
00136     /* Choose a map */
00137     if (CP_ChooseMap(mission, NULL)) {
00138         int counter;
00139         linkedList_t *nationList = NULL;
00140         const qboolean nationTest = CP_ChooseNation(mission, &nationList);
00141         for (counter = 0; counter < MAX_POS_LOOP; counter++) {
00142             if (!CP_GetRandomPosOnGeoscapeWithParameters(mission->pos, mission->mapDef->terrains, mission->mapDef->cultures, mission->mapDef->populations, nationTest ? nationList : NULL))
00143                 continue;
00144             if (MAP_PositionCloseToBase(mission->pos))
00145                 continue;
00146             mission->posAssigned = qtrue;
00147             break;
00148         }
00149         if (counter >= MAX_POS_LOOP) {
00150             Com_Printf("CP_HarvestMissionGo: Error, could not set position.\n");
00151             CP_MissionRemove(mission);
00152             return;
00153         }
00154         LIST_Delete(&nationList);
00155     } else {
00156         Com_Printf("CP_HarvestMissionGo: No map found, remove mission.\n");
00157         CP_MissionRemove(mission);
00158         return;
00159     }
00160 
00161     nation = MAP_GetNation(mission->pos);
00162     if (nation) {
00163         Com_sprintf(mission->location, sizeof(mission->location), "%s", _(nation->name));
00164     } else {
00165         Com_sprintf(mission->location, sizeof(mission->location), "%s", _("No nation"));
00166     }
00167 
00168     if (mission->ufo) {
00169         CP_MissionDisableTimeLimit(mission);
00170         UFO_SendToDestination(mission->ufo, mission->pos);
00171     } else {
00172         /* Go to next stage on next frame */
00173         mission->finalDate = ccs.date;
00174     }
00175 }
00176 
00184 int CP_HarvestMissionAvailableUFOs (const mission_t const *mission, ufoType_t *ufoTypes)
00185 {
00186     int num = 0;
00187 
00188     ufoTypes[num++] = UFO_HARVESTER;
00189 
00190     return num;
00191 }
00192 
00197 void CP_HarvestMissionNextStage (mission_t *mission)
00198 {
00199     switch (mission->stage) {
00200     case STAGE_NOT_ACTIVE:
00201         /* Create Harvesting mission */
00202         CP_MissionBegin(mission);
00203         break;
00204     case STAGE_COME_FROM_ORBIT:
00205         /* Go to mission */
00206         CP_HarvestMissionGo(mission);
00207         break;
00208     case STAGE_MISSION_GOTO:
00209         /* just arrived on a new Harvesting mission: start it */
00210         CP_HarvestMissionStart(mission);
00211         break;
00212     case STAGE_HARVEST:
00213         /* Leave earth */
00214         CP_ReconMissionLeave(mission);
00215         break;
00216     case STAGE_RETURN_TO_ORBIT:
00217         /* mission is over, remove mission */
00218         CP_HarvestMissionIsSuccess(mission);
00219         break;
00220     default:
00221         Com_Printf("CP_HarvestMissionNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
00222         CP_MissionRemove(mission);
00223         break;
00224     }
00225 }

Generated by  doxygen 1.6.2