1 /**
2 * @file
3 * @brief UI callbacks for missions.
4 * @note Automission related function prefix: AM_
5 * @note Other mission function prefix: MIS_
6 */
7
8 /*
9 Copyright (C) 2002-2013 UFO: Alien Invasion.
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19
20 See the GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 */
26
27 #include "cp_mission_callbacks.h"
28 #include "../../cl_shared.h"
29 #include "../../ui/ui_dataids.h"
30 #include "cp_campaign.h"
31 #include "cp_geoscape.h"
32 #include "cp_missions.h"
33 #include "cp_auto_mission.h"
34
35 /**
36 * @brief Callback function to start automission
37 */
AM_Go_f(void)38 static void AM_Go_f (void)
39 {
40 mission_t* mission = GEO_GetSelectedMission();
41 missionResults_t* results = &ccs.missionResults;
42 battleParam_t* battleParam = &ccs.battleParameters;
43
44 if (!mission) {
45 Com_DPrintf(DEBUG_CLIENT, "GAME_CP_MissionAutoGo_f: No update after automission\n");
46 return;
47 }
48
49 if (GEO_GetMissionAircraft() == nullptr) {
50 Com_Printf("GAME_CP_MissionAutoGo_f: No aircraft at target pos\n");
51 return;
52 }
53
54 if (GEO_GetInterceptorAircraft() == nullptr) {
55 Com_Printf("GAME_CP_MissionAutoGo_f: No intercept aircraft given\n");
56 return;
57 }
58
59 cgi->UI_PopWindow(false);
60
61 if (mission->stage != STAGE_BASE_ATTACK) {
62 if (!mission->active) {
63 MS_AddNewMessage(_("Notice"), _("Your dropship is not near the landing zone"));
64 return;
65 } else if (mission->mapDef->storyRelated) {
66 Com_DPrintf(DEBUG_CLIENT, "You have to play this mission, because it's story related\n");
67 /* ensure, that the automatic button is no longer visible */
68 cgi->Cvar_Set("cp_mission_autogo_available", "0");
69 return;
70 }
71 }
72
73 /* start the map */
74 CP_CreateBattleParameters(mission, battleParam, GEO_GetMissionAircraft());
75 battleParam->retriable = false;
76
77 results->state = LOST;
78 AM_Go(mission, GEO_GetInterceptorAircraft(), ccs.curCampaign, battleParam, results);
79 }
80
81 /**
82 * @brief Checks whether you have to play this mission or can be done via automission
83 * You can mark a mission as story related.
84 * If a mission is story related the cvar @c cp_mission_autogo_available is set to @c 0
85 * If this cvar is @c 1 - the mission dialog will have a auto mission button
86 * @sa AM_Go_f
87 */
AM_Check_f(void)88 static void AM_Check_f (void)
89 {
90 const mission_t* mission = GEO_GetSelectedMission();
91
92 if (!mission || GEO_GetInterceptorAircraft() == nullptr) {
93 Com_DPrintf(DEBUG_CLIENT, "GAME_CP_MissionAutoCheck_f: No update after automission\n");
94 return;
95 }
96
97 if (mission->mapDef->storyRelated) {
98 Com_DPrintf(DEBUG_CLIENT, "GAME_CP_MissionAutoCheck_f: story related - auto mission is disabled\n");
99 cgi->Cvar_Set("cp_mission_autogo_available", "0");
100 } else {
101 Com_DPrintf(DEBUG_CLIENT, "GAME_CP_MissionAutoCheck_f: auto mission is enabled\n");
102 cgi->Cvar_Set("cp_mission_autogo_available", "1");
103 }
104 }
105
106 /**
107 * @brief Updates mission result menu text with appropriate values
108 * @param[in] results Initialized mission results
109 */
MIS_InitResultScreen(const missionResults_t * results)110 void MIS_InitResultScreen (const missionResults_t* results)
111 {
112 linkedList_t* list = nullptr;
113
114 /* init result text */
115 cgi->UI_ResetData(TEXT_LIST2);
116
117 /* aliens */
118 cgi->LIST_AddString(&list, va("%s\t%i", _("Aliens killed"), results->aliensKilled));
119 cgi->LIST_AddString(&list, va("%s\t%i", _("Aliens captured"), results->aliensStunned));
120 cgi->LIST_AddString(&list, va("%s\t%i", _("Alien survivors"), results->aliensSurvived));
121 cgi->LIST_AddString(&list, "");
122 /* phalanx */
123 cgi->LIST_AddString(&list, va("%s\t%i", _("PHALANX soldiers killed in action"), results->ownKilled));
124 /* @todo FIXME right now stunned soldiers are shown as MIA when the game ends in a draw or the
125 * mission is aborted and they are in the rescue zone, and in both cases they aren't MIA they'll,
126 * return safely to base, on the other hand stunned soldiers left behind when aborting are
127 * killed at mission end, so there's never a valid case of soldiers going MIA */
128 cgi->LIST_AddString(&list, va("%s\t%i", _("PHALANX soldiers missing in action"), results->ownStunned));
129 cgi->LIST_AddString(&list, va("%s\t%i", _("PHALANX friendly fire losses"), results->ownKilledFriendlyFire));
130 cgi->LIST_AddString(&list, va("%s\t%i", _("PHALANX survivors"), results->ownSurvived));
131 cgi->LIST_AddString(&list, "");
132
133 cgi->LIST_AddString(&list, va("%s\t%i", _("Civilians killed"), results->civiliansKilled));
134 cgi->LIST_AddString(&list, va("%s\t%i", _("Civilians killed by friendly fire"), results->civiliansKilledFriendlyFire));
135 cgi->LIST_AddString(&list, va("%s\t%i", _("Civilians saved"), results->civiliansSurvived));
136 cgi->LIST_AddString(&list, "");
137
138 if (results->itemTypes > 0 && results->itemAmount > 0)
139 cgi->LIST_AddString(&list, va("%s\t%i/%i", _("Gathered items (types/all)"), results->itemTypes, results->itemAmount));
140
141 cgi->UI_RegisterLinkedListText(TEXT_LIST2, list);
142 }
143
144 /**
145 * @brief Init UI callbacks for missions-subsystem
146 */
MIS_InitCallbacks(void)147 void MIS_InitCallbacks (void)
148 {
149 cgi->Cmd_AddCommand("cp_missionauto_check", AM_Check_f, "Checks whether this mission can be done automatically");
150 cgi->Cmd_AddCommand("cp_mission_autogo", AM_Go_f, "Let the current selection mission be done automatically");
151 }
152
153 /**
154 * @brief Close UI callbacks for missions-subsystem
155 */
MIS_ShutdownCallbacks(void)156 void MIS_ShutdownCallbacks (void)
157 {
158 cgi->Cmd_RemoveCommand("cp_missionauto_check");
159 cgi->Cmd_RemoveCommand("cp_mission_autogo");
160 }
161