1 /**
2  * @file
3  * @brief Campaign mission code
4  */
5 
6 /*
7 Copyright (C) 2002-2013 UFO: Alien Invasion.
8 
9 This program is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License
11 as published by the Free Software Foundation; either version 2
12 of the License, or (at your option) any later version.
13 
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 
18 See the GNU General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23 
24 */
25 
26 #include "../../../cl_shared.h"
27 #include "../cp_campaign.h"
28 #include "../cp_missions.h"
29 #include "../cp_time.h"
30 #include "../cp_alien_interest.h"
31 #include "../cp_ufo.h"
32 
33 /**
34  * @brief XVI Spreading mission is over and is a success: change interest values.
35  * @note XVI Spreading mission
36  */
CP_XVIMissionIsSuccess(mission_t * mission)37 void CP_XVIMissionIsSuccess (mission_t* mission)
38 {
39 	INT_ChangeIndividualInterest(-0.3f, INTERESTCATEGORY_XVI);
40 	INT_ChangeIndividualInterest(0.1f, INTERESTCATEGORY_HARVEST);
41 	INT_ChangeIndividualInterest(0.05f, INTERESTCATEGORY_BUILDING);
42 
43 	CP_MissionRemove(mission);
44 }
45 
46 /**
47  * @brief XVI Spreading mission is over and is a failure: change interest values.
48  * @note XVI Spreading mission
49  */
CP_XVIMissionIsFailure(mission_t * mission)50 void CP_XVIMissionIsFailure (mission_t* mission)
51 {
52 	INT_ChangeIndividualInterest(0.1f, INTERESTCATEGORY_INTERCEPT);
53 	INT_ChangeIndividualInterest(0.05f, INTERESTCATEGORY_TERROR_ATTACK);
54 	INT_ChangeIndividualInterest(0.01f, INTERESTCATEGORY_BASE_ATTACK);
55 
56 	CP_MissionRemove(mission);
57 }
58 
59 /**
60  * @brief Start XVI Spreading mission.
61  * @note XVI Spreading mission -- Stage 2
62  */
CP_XVIMissionStart(mission_t * mission)63 static void CP_XVIMissionStart (mission_t* mission)
64 {
65 	const date_t minMissionDelay = {2, 0};
66 	const date_t missionDelay = {3, 0};
67 
68 	mission->stage = STAGE_SPREAD_XVI;
69 
70 	if (mission->ufo) {
71 		mission->finalDate = Date_Add(ccs.date, Date_Random(minMissionDelay, missionDelay));
72 		/* ufo becomes invisible on geoscape, but don't remove it from ufo global array (may reappear)*/
73 		CP_UFORemoveFromGeoscape(mission, false);
74 	} else {
75 		/* Go to next stage on next frame */
76 		mission->finalDate = ccs.date;
77 	}
78 
79 	/* mission appear on geoscape, player can go there */
80 	CP_MissionAddToGeoscape(mission, false);
81 }
82 
83 /**
84  * @brief Fill an array with available UFOs for XVI Spreading mission type.
85  * @param[in] mission Pointer to the mission we are currently creating.
86  * @param[out] ufoTypes Array of ufoType_t that may be used for this mission.
87  * @note XVI Spreading mission -- Stage 0
88  * @return number of elements written in @c ufoTypes
89  */
CP_XVIMissionAvailableUFOs(const mission_t * mission,ufoType_t * ufoTypes)90 int CP_XVIMissionAvailableUFOs (const mission_t* mission, ufoType_t* ufoTypes)
91 {
92 	int num = 0;
93 
94 	if (UFO_ShouldAppearOnGeoscape(UFO_CORRUPTER))
95 		ufoTypes[num++] = UFO_CORRUPTER;
96 
97 	return num;
98 }
99 
100 /**
101  * @brief Determine what action should be performed when a XVI Spreading mission stage ends.
102  * @param[in] mission Pointer to the mission which stage ended.
103  */
CP_XVIMissionNextStage(mission_t * mission)104 void CP_XVIMissionNextStage (mission_t* mission)
105 {
106 	switch (mission->stage) {
107 	case STAGE_NOT_ACTIVE:
108 		/* Create XVI Spreading mission */
109 		CP_MissionBegin(mission);
110 		break;
111 	case STAGE_COME_FROM_ORBIT:
112 		/* Go to mission */
113 		CP_HarvestMissionGo(mission);
114 		break;
115 	case STAGE_MISSION_GOTO:
116 		/* just arrived on a new XVI Spreading mission: start it */
117 		CP_XVIMissionStart(mission);
118 		break;
119 	case STAGE_SPREAD_XVI:
120 		/* Leave earth */
121 		CP_ReconMissionLeave(mission);
122 		break;
123 	case STAGE_RETURN_TO_ORBIT:
124 		/* mission is over, remove mission */
125 		CP_XVIMissionIsSuccess(mission);
126 		break;
127 	default:
128 		Com_Printf("CP_XVIMissionNextStage: Unknown stage: %i, removing mission.\n", mission->stage);
129 		CP_MissionRemove(mission);
130 		break;
131 	}
132 }
133