1 /************************************************************************************
2
3 AstroMenace
4 Hardcore 3D space scroll-shooter with spaceship upgrade possibilities.
5 Copyright (c) 2006-2019 Mikhail Kurinnoi, Viewizard
6
7
8 AstroMenace is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 AstroMenace is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with AstroMenace. If not, see <https://www.gnu.org/licenses/>.
20
21
22 Website: https://viewizard.com/
23 Project: https://github.com/viewizard/astromenace
24 E-mail: viewizard@viewizard.com
25
26 *************************************************************************************/
27
28 #include "command.h"
29 #include "config/config.h"
30 #include "object3d/object3d.h"
31 #include "gfx/star_system.h"
32 #include "assets/audio.h"
33 #include "game.h" // FIXME "game.h" should be replaced by individual headers
34
35 // NOTE switch to nested namespace definition (namespace A::B::C { ... }) (since C++17)
36 namespace viewizard {
37 namespace astromenace {
38
39 /*
40 * Prepare to switch status.
41 */
PrepareToSwitchStatus()42 static void PrepareToSwitchStatus() {
43 SaveXMLConfigFile();
44 ReleaseAllObject3D();
45 vw_ReleaseAllParticleSystems();
46 vw_ReleaseAllLights();
47 StarSystemRelease();
48 vw_StopAllSoundsIfAllowed();
49 }
50
51 /*
52 * Proceed command.
53 */
Proceed()54 void cCommand::Proceed()
55 {
56 if (Command_ == eCommand::DO_NOTHING)
57 return;
58
59 switch (Command_) {
60 case eCommand::SWITCH_TO_MAIN_MENU:
61 SetMenu(eMenuStatus::MAIN_MENU);
62 break;
63
64 case eCommand::SWITCH_TO_TOP_SCORES:
65 SetMenu(eMenuStatus::TOP_SCORES);
66 break;
67
68 case eCommand::SWITCH_TO_INTERFACE:
69 SetMenu(eMenuStatus::INTERFACE);
70 break;
71
72 case eCommand::SWITCH_TO_OPTIONS:
73 SetMenu(eMenuStatus::OPTIONS);
74 break;
75
76 case eCommand::SWITCH_TO_OPTIONS_ADVANCED:
77 SetMenu(eMenuStatus::OPTIONS_ADVANCED);
78 break;
79
80 case eCommand::SWITCH_TO_INFORMATION:
81 SetMenu(eMenuStatus::INFORMATION);
82 break;
83
84 case eCommand::SWITCH_TO_CREDITS:
85 SetMenu(eMenuStatus::CREDITS);
86 break;
87
88 case eCommand::SWITCH_TO_CONFCONTROL:
89 SetMenu(eMenuStatus::CONFCONTROL);
90 break;
91
92 case eCommand::SWITCH_TO_PROFILE:
93 SetMenu(eMenuStatus::PROFILE);
94 break;
95
96 case eCommand::SWITCH_TO_DIFFICULTY:
97 SetMenu(eMenuStatus::DIFFICULTY);
98 break;
99
100 case eCommand::SWITCH_TO_MISSION:
101 SetMenu(eMenuStatus::MISSION);
102 break;
103
104 case eCommand::SWITCH_TO_WORKSHOP:
105 SetMenu(eMenuStatus::WORKSHOP);
106 break;
107
108 case eCommand::SWITCH_FROM_MENU_TO_GAME: // also used for mission restart
109 PrepareToSwitchStatus();
110 InitGame();
111 PlayMusicTheme(eMusicTheme::GAME, 2000, 2000);
112 PlayVoicePhrase(eVoicePhrase::PrepareForAction, 1.0f);
113 break;
114
115 case eCommand::SWITCH_FROM_GAME_TO_MISSION_MENU:
116 PrepareToSwitchStatus();
117 InitMenu(eMenuStatus::MISSION);
118 PlayMusicTheme(eMusicTheme::MENU, 2000, 2000);
119 // FIXME code duplication, see SetMenu()
120 vw_ResetWheelStatus();
121 // mission list
122 StartMission = 0;
123 EndMission = 4;
124 if (CurrentMission != -1)
125 if (CurrentMission > 2) { // should be centered
126 StartMission = CurrentMission - 2;
127 EndMission = CurrentMission + 2;
128
129 if (CurrentMission >= AllMission - 2) {
130 StartMission = AllMission - 5;
131 EndMission = AllMission - 1;
132 }
133 }
134 break;
135
136 case eCommand::SWITCH_FROM_GAME_TO_MAIN_MENU:
137 PrepareToSwitchStatus();
138 InitMenu(eMenuStatus::MAIN_MENU);
139 PlayMusicTheme(eMusicTheme::MENU, 2000, 2000);
140 break;
141
142 case eCommand::SWITCH_FROM_GAME_TO_CREDITS:
143 PrepareToSwitchStatus();
144 InitMenu(eMenuStatus::CREDITS);
145 PlayMusicTheme(eMusicTheme::CREDITS, 2000, 2000);
146 // FIXME code duplication, see SetMenu()
147 InitCreditsMenu(vw_GetTimeThread(0));
148 break;
149
150 default:
151 std::cerr << __func__ << "(): " << "ComBuffer = " << static_cast<int>(Command_) << " ... error!\n";
152 break;
153 }
154
155 Command_ = eCommand::DO_NOTHING;
156 }
157
158 /*
159 * Set command.
160 */
Set(eCommand Command)161 void cCommand::Set(eCommand Command)
162 {
163 Command_ = Command;
164 }
165
166 } // astromenace namespace
167 } // viewizard namespace
168