1 /***************************************************************************
2  *      Mechanized Assault and Exploration Reloaded Projectfile            *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18  ***************************************************************************/
19 
20 #include "game/data/report/savedreport.h"
21 
22 #include "game/data/report/savedreportchat.h"
23 #include "game/data/report/savedreportsimple.h"
24 
25 #include "game/data/report/unit/savedreportattacked.h"
26 #include "game/data/report/unit/savedreportattackingenemy.h"
27 #include "game/data/report/unit/savedreportcapturedbyenemy.h"
28 #include "game/data/report/unit/savedreportdestroyed.h"
29 #include "game/data/report/unit/savedreportdetected.h"
30 #include "game/data/report/unit/savedreportdisabled.h"
31 #include "game/data/report/unit/savedreportpathinterrupted.h"
32 #include "game/data/report/unit/savedreportsurveyoraiconfused.h"
33 #include "game/data/report/unit/savedreportsurveyoraisenseless.h"
34 
35 #include "game/data/report/special/savedreporthostcommand.h"
36 #include "game/data/report/special/savedreportresourcechanged.h"
37 #include "game/data/report/special/savedreportlostconnection.h"
38 #include "game/data/report/special/savedreportplayerendedturn.h"
39 #include "game/data/report/special/savedreportplayerdefeated.h"
40 #include "game/data/report/special/savedreportplayerleft.h"
41 #include "game/data/report/special/savedreportupgraded.h"
42 #include "game/data/report/special/savedreportturnstart.h"
43 
44 #include "netmessage.h"
45 #include "utility/tounderlyingtype.h"
46 #include "main.h"
47 
48 //------------------------------------------------------------------------------
pushInto(cNetMessage & message) const49 void cSavedReport::pushInto (cNetMessage& message) const
50 {
51 	message.pushInt32 (toUnderlyingType (getType()));
52 }
53 
54 //------------------------------------------------------------------------------
pushInto(tinyxml2::XMLElement & element) const55 void cSavedReport::pushInto (tinyxml2::XMLElement& element) const
56 {
57 	element.SetAttribute ("type", iToStr (toUnderlyingType (getType())).c_str());
58 }
59 
60 //------------------------------------------------------------------------------
hasUnitId() const61 bool cSavedReport::hasUnitId() const
62 {
63 	return false;
64 }
65 
66 //------------------------------------------------------------------------------
getUnitId() const67 const sID& cSavedReport::getUnitId() const
68 {
69 	static sID dummy;
70 	return dummy;
71 }
72 
73 //------------------------------------------------------------------------------
hasPosition() const74 bool cSavedReport::hasPosition() const
75 {
76 	return false;
77 }
78 
79 //------------------------------------------------------------------------------
getPosition() const80 const cPosition& cSavedReport::getPosition() const
81 {
82 	static cPosition dummy;
83 	return dummy;
84 }
85 
86 //------------------------------------------------------------------------------
playSound(cSoundManager & soundManager) const87 void cSavedReport::playSound (cSoundManager& soundManager) const
88 {}
89 
90 //------------------------------------------------------------------------------
createFrom(cNetMessage & message)91 std::unique_ptr<cSavedReport> cSavedReport::createFrom (cNetMessage& message)
92 {
93 	auto type = (eSavedReportType)message.popInt32();
94 
95 	switch (type)
96 	{
97 		case eSavedReportType::Chat:
98 			return std::make_unique<cSavedReportChat> (message);
99 		case eSavedReportType::Attacked:
100 			return std::make_unique<cSavedReportAttacked> (message);
101 		case eSavedReportType::AttackingEnemy:
102 			return std::make_unique<cSavedReportAttackingEnemy> (message);
103 		case eSavedReportType::CapturedByEnemy:
104 			return std::make_unique<cSavedReportCapturedByEnemy> (message);
105 		case eSavedReportType::Destroyed:
106 			return std::make_unique<cSavedReportDestroyed> (message);
107 		case eSavedReportType::Detected:
108 			return std::make_unique<cSavedReportDetected> (message);
109 		case eSavedReportType::Disabled:
110 			return std::make_unique<cSavedReportDisabled> (message);
111 		case eSavedReportType::PathInterrupted:
112 			return std::make_unique<cSavedReportPathInterrupted> (message);
113 		case eSavedReportType::SurveyorAiConfused:
114 			return std::make_unique<cSavedReportSurveyorAiConfused> (message);
115 		case eSavedReportType::SurveyorAiSenseless:
116 			return std::make_unique<cSavedReportSurveyorAiSenseless> (message);
117 		case eSavedReportType::HostCommand:
118 			return std::make_unique<cSavedReportHostCommand> (message);
119 		case eSavedReportType::ResourceChanged:
120 			return std::make_unique<cSavedReportResourceChanged> (message);
121 		case eSavedReportType::PlayerEndedTurn:
122 			return std::make_unique<cSavedReportPlayerEndedTurn> (message);
123 		case eSavedReportType::LostConnection:
124 			return std::make_unique<cSavedReportLostConnection> (message);
125 		case eSavedReportType::PlayerDefeated:
126 			return std::make_unique<cSavedReportPlayerDefeated> (message);
127 		case eSavedReportType::PlayerLeft:
128 			return std::make_unique<cSavedReportPlayerLeft> (message);
129 		case eSavedReportType::Upgraded:
130 			return std::make_unique<cSavedReportUpgraded> (message);
131 		case eSavedReportType::TurnStart:
132 			return std::make_unique<cSavedReportTurnStart> (message);
133 		case eSavedReportType::MetalInsufficient:
134 		case eSavedReportType::FuelInsufficient:
135 		case eSavedReportType::GoldInsufficient:
136 		case eSavedReportType::EnergyInsufficient:
137 		case eSavedReportType::TeamInsufficient:
138 		case eSavedReportType::MetalLow:
139 		case eSavedReportType::FuelLow:
140 		case eSavedReportType::GoldLow:
141 		case eSavedReportType::EnergyLow:
142 		case eSavedReportType::TeamLow:
143 		case eSavedReportType::EnergyToLow:
144 		case eSavedReportType::EnergyIsNeeded:
145 		case eSavedReportType::BuildingDisabled:
146 		case eSavedReportType::ProducingError:
147 		case eSavedReportType::TurnWait:
148 		case eSavedReportType::TurnAutoMove:
149 			return std::make_unique<cSavedReportSimple> (type);
150 		default:
151 			return nullptr;
152 	}
153 }
154 
155 //------------------------------------------------------------------------------
createFrom(const tinyxml2::XMLElement & element)156 std::unique_ptr<cSavedReport> cSavedReport::createFrom (const tinyxml2::XMLElement& element)
157 {
158 	auto type = (eSavedReportType)element.IntAttribute ("type");
159 
160 	switch (type)
161 	{
162 		case eSavedReportType::Chat:
163 			return std::make_unique<cSavedReportChat> (element);
164 		case eSavedReportType::Attacked:
165 			return std::make_unique<cSavedReportAttacked> (element);
166 		case eSavedReportType::AttackingEnemy:
167 			return std::make_unique<cSavedReportAttackingEnemy> (element);
168 		case eSavedReportType::CapturedByEnemy:
169 			return std::make_unique<cSavedReportCapturedByEnemy> (element);
170 		case eSavedReportType::Destroyed:
171 			return std::make_unique<cSavedReportDestroyed> (element);
172 		case eSavedReportType::Detected:
173 			return std::make_unique<cSavedReportDetected> (element);
174 		case eSavedReportType::Disabled:
175 			return std::make_unique<cSavedReportDisabled> (element);
176 		case eSavedReportType::PathInterrupted:
177 			return std::make_unique<cSavedReportPathInterrupted> (element);
178 		case eSavedReportType::SurveyorAiConfused:
179 			return std::make_unique<cSavedReportSurveyorAiConfused> (element);
180 		case eSavedReportType::SurveyorAiSenseless:
181 			return std::make_unique<cSavedReportSurveyorAiSenseless> (element);
182 		case eSavedReportType::HostCommand:
183 			return std::make_unique<cSavedReportHostCommand> (element);
184 		case eSavedReportType::ResourceChanged:
185 			return std::make_unique<cSavedReportResourceChanged> (element);
186 		case eSavedReportType::PlayerEndedTurn:
187 			return std::make_unique<cSavedReportPlayerEndedTurn> (element);
188 		case eSavedReportType::LostConnection:
189 			return std::make_unique<cSavedReportLostConnection> (element);
190 		case eSavedReportType::PlayerDefeated:
191 			return std::make_unique<cSavedReportPlayerDefeated> (element);
192 		case eSavedReportType::PlayerLeft:
193 			return std::make_unique<cSavedReportPlayerLeft> (element);
194 		case eSavedReportType::Upgraded:
195 			return std::make_unique<cSavedReportUpgraded> (element);
196 		case eSavedReportType::TurnStart:
197 			return std::make_unique<cSavedReportTurnStart> (element);
198 		case eSavedReportType::MetalInsufficient:
199 		case eSavedReportType::FuelInsufficient:
200 		case eSavedReportType::GoldInsufficient:
201 		case eSavedReportType::EnergyInsufficient:
202 		case eSavedReportType::TeamInsufficient:
203 		case eSavedReportType::MetalLow:
204 		case eSavedReportType::FuelLow:
205 		case eSavedReportType::GoldLow:
206 		case eSavedReportType::EnergyLow:
207 		case eSavedReportType::TeamLow:
208 		case eSavedReportType::EnergyToLow:
209 		case eSavedReportType::EnergyIsNeeded:
210 		case eSavedReportType::BuildingDisabled:
211 		case eSavedReportType::ProducingError:
212 		case eSavedReportType::TurnWait:
213 		case eSavedReportType::TurnAutoMove:
214 			return std::make_unique<cSavedReportSimple> (type);
215 		default:
216 			return nullptr;
217 	}
218 }
219