Merge lp:~widelands-dev/widelands/cleanup_playercommand_enums into lp:widelands
- cleanup_playercommand_enums
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 9186 |
Proposed branch: | lp:~widelands-dev/widelands/cleanup_playercommand_enums |
Merge into: | lp:widelands |
Diff against target: |
662 lines (+112/-151) 5 files modified
src/logic/playercommand.cc (+78/-129) src/logic/playercommand.h (+9/-6) src/logic/queue_cmd_factory.cc (+6/-6) src/logic/queue_cmd_ids.h (+13/-7) src/logic/replay.cc (+6/-3) |
To merge this branch: | bzr merge lp:~widelands-dev/widelands/cleanup_playercommand_enums |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Toni Förster | Approve | ||
Review via email: mp+369267@code.launchpad.net |
Commit message
Get rid of duplicate listing of player commands. This breaks compatibility for replays only.
Description of the change
Keeping 2 lists of the same player commands is a bit nuts, so I got rid of one of them.
Since replays become incompatible pretty fast anyway, I decided not to add any compatibility code.
bunnybot (widelandsofficial) wrote : | # |
Benedikt Straub (nordfriese) wrote : | # |
Looks good to me. Some comments in the diff.
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 5260. State: passed. Details: https:/
Appveyor build 5037. State: failed. Details: https:/
GunChleoc (gunchleoc) wrote : | # |
Addressed code review. Thanks for the review
Toni Förster (stonerl) : | # |
GunChleoc (gunchleoc) wrote : | # |
@bunnybot merge
bunnybot (widelandsofficial) wrote : | # |
Continuous integration builds have changed state:
Travis build 5341. State: passed. Details: https:/
Appveyor build 5111. State: success. Details: https:/
Preview Diff
1 | === modified file 'src/logic/playercommand.cc' |
2 | --- src/logic/playercommand.cc 2019-06-23 14:28:50 +0000 |
3 | +++ src/logic/playercommand.cc 2019-08-26 10:38:04 +0000 |
4 | @@ -74,108 +74,83 @@ |
5 | |
6 | } // namespace |
7 | |
8 | -// NOTE keep numbers of existing entries as they are to ensure backward compatible savegame loading |
9 | -enum { |
10 | - PLCMD_UNUSED = 0, |
11 | - PLCMD_BULLDOZE = 1, |
12 | - PLCMD_BUILD = 2, |
13 | - PLCMD_BUILDFLAG = 3, |
14 | - PLCMD_BUILDROAD = 4, |
15 | - PLCMD_FLAGACTION = 5, |
16 | - PLCMD_STARTSTOPBUILDING = 6, |
17 | - PLCMD_ENHANCEBUILDING = 7, |
18 | - PLCMD_CHANGETRAININGOPTIONS = 8, |
19 | - PLCMD_DROPSOLDIER = 9, |
20 | - PLCMD_CHANGESOLDIERCAPACITY = 10, |
21 | - PLCMD_ENEMYFLAGACTION = 11, |
22 | - PLCMD_SETWAREPRIORITY = 12, |
23 | - PLCMD_SETWARETARGETQUANTITY = 13, |
24 | - PLCMD_RESETWARETARGETQUANTITY = 14, |
25 | - PLCMD_SETWORKERTARGETQUANTITY = 15, |
26 | - PLCMD_RESETWORKERTARGETQUANTITY = 16, |
27 | - // Used to be PLCMD_CHANGEMILITARYCONFIG |
28 | - PLCMD_MESSAGESETSTATUSREAD = 18, |
29 | - PLCMD_MESSAGESETSTATUSARCHIVED = 19, |
30 | - PLCMD_SETSTOCKPOLICY = 20, |
31 | - PLCMD_SETINPUTMAXFILL = 21, |
32 | - PLCMD_DISMANTLEBUILDING = 22, |
33 | - PLCMD_EVICTWORKER = 23, |
34 | - PLCMD_MILITARYSITESETSOLDIERPREFERENCE = 24, |
35 | - PLCMD_SHIP_EXPEDITION = 25, |
36 | - PLCMD_SHIP_SCOUT = 26, |
37 | - PLCMD_SHIP_EXPLORE = 27, |
38 | - PLCMD_SHIP_CONSTRUCT = 28, |
39 | - PLCMD_SHIP_SINK = 29, |
40 | - PLCMD_SHIP_CANCELEXPEDITION = 30, |
41 | - PLCMD_PROPOSE_TRADE = 31, |
42 | -}; |
43 | - |
44 | /*** class PlayerCommand ***/ |
45 | |
46 | PlayerCommand::PlayerCommand(const uint32_t time, const PlayerNumber s) |
47 | : GameLogicCommand(time), sender_(s), cmdserial_(0) { |
48 | } |
49 | |
50 | +void PlayerCommand::write_id_and_sender(StreamWrite& ser) { |
51 | + ser.unsigned_8(static_cast<uint8_t>(id())); |
52 | + ser.unsigned_8(sender()); |
53 | +} |
54 | + |
55 | PlayerCommand* PlayerCommand::deserialize(StreamRead& des) { |
56 | - switch (des.unsigned_8()) { |
57 | - case PLCMD_BULLDOZE: |
58 | + switch (static_cast<QueueCommandTypes>(des.unsigned_8())) { |
59 | + case QueueCommandTypes::kBulldoze: |
60 | return new CmdBulldoze(des); |
61 | - case PLCMD_BUILD: |
62 | + case QueueCommandTypes::kBuild: |
63 | return new CmdBuild(des); |
64 | - case PLCMD_BUILDFLAG: |
65 | + case QueueCommandTypes::kBuildFlag: |
66 | return new CmdBuildFlag(des); |
67 | - case PLCMD_BUILDROAD: |
68 | + case QueueCommandTypes::kBuildRoad: |
69 | return new CmdBuildRoad(des); |
70 | - case PLCMD_FLAGACTION: |
71 | + case QueueCommandTypes::kFlagAction: |
72 | return new CmdFlagAction(des); |
73 | - case PLCMD_STARTSTOPBUILDING: |
74 | + case QueueCommandTypes::kStartStopBuilding: |
75 | return new CmdStartStopBuilding(des); |
76 | - case PLCMD_SHIP_EXPEDITION: |
77 | - return new CmdStartOrCancelExpedition(des); |
78 | - case PLCMD_SHIP_SCOUT: |
79 | - return new CmdShipScoutDirection(des); |
80 | - case PLCMD_SHIP_EXPLORE: |
81 | - return new CmdShipExploreIsland(des); |
82 | - case PLCMD_SHIP_CONSTRUCT: |
83 | - return new CmdShipConstructPort(des); |
84 | - case PLCMD_SHIP_SINK: |
85 | - return new CmdShipSink(des); |
86 | - case PLCMD_SHIP_CANCELEXPEDITION: |
87 | - return new CmdShipCancelExpedition(des); |
88 | - case PLCMD_ENHANCEBUILDING: |
89 | + case QueueCommandTypes::kEnhanceBuilding: |
90 | return new CmdEnhanceBuilding(des); |
91 | - case PLCMD_CHANGETRAININGOPTIONS: |
92 | + |
93 | + case QueueCommandTypes::kChangeTrainingOptions: |
94 | return new CmdChangeTrainingOptions(des); |
95 | - case PLCMD_DROPSOLDIER: |
96 | + case QueueCommandTypes::kDropSoldier: |
97 | return new CmdDropSoldier(des); |
98 | - case PLCMD_CHANGESOLDIERCAPACITY: |
99 | + case QueueCommandTypes::kChangeSoldierCapacity: |
100 | return new CmdChangeSoldierCapacity(des); |
101 | - case PLCMD_ENEMYFLAGACTION: |
102 | + case QueueCommandTypes::kEnemyFlagAction: |
103 | return new CmdEnemyFlagAction(des); |
104 | - case PLCMD_SETWAREPRIORITY: |
105 | + |
106 | + case QueueCommandTypes::kSetWarePriority: |
107 | return new CmdSetWarePriority(des); |
108 | - case PLCMD_SETWARETARGETQUANTITY: |
109 | + case QueueCommandTypes::kSetWareTargetQuantity: |
110 | return new CmdSetWareTargetQuantity(des); |
111 | - case PLCMD_RESETWARETARGETQUANTITY: |
112 | + case QueueCommandTypes::kResetWareTargetQuantity: |
113 | return new CmdResetWareTargetQuantity(des); |
114 | - case PLCMD_SETWORKERTARGETQUANTITY: |
115 | + case QueueCommandTypes::kSetWorkerTargetQuantity: |
116 | return new CmdSetWorkerTargetQuantity(des); |
117 | - case PLCMD_RESETWORKERTARGETQUANTITY: |
118 | + case QueueCommandTypes::kResetWorkerTargetQuantity: |
119 | return new CmdResetWorkerTargetQuantity(des); |
120 | - case PLCMD_MESSAGESETSTATUSREAD: |
121 | + |
122 | + case QueueCommandTypes::kMessageSetStatusRead: |
123 | return new CmdMessageSetStatusRead(des); |
124 | - case PLCMD_MESSAGESETSTATUSARCHIVED: |
125 | + case QueueCommandTypes::kMessageSetStatusArchived: |
126 | return new CmdMessageSetStatusArchived(des); |
127 | - case PLCMD_SETSTOCKPOLICY: |
128 | + |
129 | + case QueueCommandTypes::kSetStockPolicy: |
130 | return new CmdSetStockPolicy(des); |
131 | - case PLCMD_SETINPUTMAXFILL: |
132 | + case QueueCommandTypes::kSetInputMaxFill: |
133 | return new CmdSetInputMaxFill(des); |
134 | - case PLCMD_DISMANTLEBUILDING: |
135 | + case QueueCommandTypes::kDismantleBuilding: |
136 | return new CmdDismantleBuilding(des); |
137 | - case PLCMD_EVICTWORKER: |
138 | + case QueueCommandTypes::kEvictWorker: |
139 | return new CmdEvictWorker(des); |
140 | - case PLCMD_MILITARYSITESETSOLDIERPREFERENCE: |
141 | + case QueueCommandTypes::kMilitarysiteSetSoldierPreference: |
142 | return new CmdMilitarySiteSetSoldierPreference(des); |
143 | + |
144 | + case QueueCommandTypes::kStartOrCancelExpedition: |
145 | + return new CmdStartOrCancelExpedition(des); |
146 | + case QueueCommandTypes::kShipScoutDirection: |
147 | + return new CmdShipScoutDirection(des); |
148 | + case QueueCommandTypes::kShipExploreIsland: |
149 | + return new CmdShipExploreIsland(des); |
150 | + case QueueCommandTypes::kShipConstructPort: |
151 | + return new CmdShipConstructPort(des); |
152 | + case QueueCommandTypes::kShipSink: |
153 | + return new CmdShipSink(des); |
154 | + case QueueCommandTypes::kShipCancelExpedition: |
155 | + return new CmdShipCancelExpedition(des); |
156 | + |
157 | default: |
158 | throw wexception("PlayerCommand::deserialize(): Invalid command id encountered"); |
159 | } |
160 | @@ -226,8 +201,7 @@ |
161 | } |
162 | |
163 | void CmdBulldoze::serialize(StreamWrite& ser) { |
164 | - ser.unsigned_8(PLCMD_BULLDOZE); |
165 | - ser.unsigned_8(sender()); |
166 | + write_id_and_sender(ser); |
167 | ser.unsigned_32(serial); |
168 | ser.unsigned_8(recurse); |
169 | } |
170 | @@ -273,8 +247,7 @@ |
171 | } |
172 | |
173 | void CmdBuild::serialize(StreamWrite& ser) { |
174 | - ser.unsigned_8(PLCMD_BUILD); |
175 | - ser.unsigned_8(sender()); |
176 | + write_id_and_sender(ser); |
177 | ser.signed_16(bi); |
178 | write_coords_32(&ser, coords); |
179 | } |
180 | @@ -317,8 +290,7 @@ |
181 | } |
182 | |
183 | void CmdBuildFlag::serialize(StreamWrite& ser) { |
184 | - ser.unsigned_8(PLCMD_BUILDFLAG); |
185 | - ser.unsigned_8(sender()); |
186 | + write_id_and_sender(ser); |
187 | write_coords_32(&ser, coords); |
188 | } |
189 | |
190 | @@ -387,8 +359,7 @@ |
191 | } |
192 | |
193 | void CmdBuildRoad::serialize(StreamWrite& ser) { |
194 | - ser.unsigned_8(PLCMD_BUILDROAD); |
195 | - ser.unsigned_8(sender()); |
196 | + write_id_and_sender(ser); |
197 | write_coords_32(&ser, start); |
198 | ser.unsigned_16(nsteps); |
199 | |
200 | @@ -444,8 +415,7 @@ |
201 | } |
202 | |
203 | void CmdFlagAction::serialize(StreamWrite& ser) { |
204 | - ser.unsigned_8(PLCMD_FLAGACTION); |
205 | - ser.unsigned_8(sender()); |
206 | + write_id_and_sender(ser); |
207 | ser.unsigned_8(0); |
208 | ser.unsigned_32(serial); |
209 | } |
210 | @@ -497,8 +467,7 @@ |
211 | } |
212 | |
213 | void CmdStartStopBuilding::serialize(StreamWrite& ser) { |
214 | - ser.unsigned_8(PLCMD_STARTSTOPBUILDING); |
215 | - ser.unsigned_8(sender()); |
216 | + write_id_and_sender(ser); |
217 | ser.unsigned_32(serial); |
218 | } |
219 | |
220 | @@ -535,8 +504,7 @@ |
221 | } |
222 | |
223 | void CmdMilitarySiteSetSoldierPreference::serialize(StreamWrite& ser) { |
224 | - ser.unsigned_8(PLCMD_MILITARYSITESETSOLDIERPREFERENCE); |
225 | - ser.unsigned_8(sender()); |
226 | + write_id_and_sender(ser); |
227 | ser.unsigned_32(serial); |
228 | ser.unsigned_8(static_cast<uint8_t>(preference)); |
229 | } |
230 | @@ -605,8 +573,7 @@ |
231 | } |
232 | |
233 | void CmdStartOrCancelExpedition::serialize(StreamWrite& ser) { |
234 | - ser.unsigned_8(PLCMD_SHIP_EXPEDITION); |
235 | - ser.unsigned_8(sender()); |
236 | + write_id_and_sender(ser); |
237 | ser.unsigned_32(serial); |
238 | } |
239 | |
240 | @@ -653,8 +620,7 @@ |
241 | } |
242 | |
243 | void CmdEnhanceBuilding::serialize(StreamWrite& ser) { |
244 | - ser.unsigned_8(PLCMD_ENHANCEBUILDING); |
245 | - ser.unsigned_8(sender()); |
246 | + write_id_and_sender(ser); |
247 | ser.unsigned_32(serial); |
248 | ser.unsigned_16(bi); |
249 | } |
250 | @@ -700,8 +666,7 @@ |
251 | } |
252 | |
253 | void CmdDismantleBuilding::serialize(StreamWrite& ser) { |
254 | - ser.unsigned_8(PLCMD_DISMANTLEBUILDING); |
255 | - ser.unsigned_8(sender()); |
256 | + write_id_and_sender(ser); |
257 | ser.unsigned_32(serial); |
258 | } |
259 | |
260 | @@ -744,8 +709,7 @@ |
261 | } |
262 | |
263 | void CmdEvictWorker::serialize(StreamWrite& ser) { |
264 | - ser.unsigned_8(PLCMD_EVICTWORKER); |
265 | - ser.unsigned_8(sender()); |
266 | + write_id_and_sender(ser); |
267 | ser.unsigned_32(serial); |
268 | } |
269 | |
270 | @@ -799,8 +763,7 @@ |
271 | } |
272 | |
273 | void CmdShipScoutDirection::serialize(StreamWrite& ser) { |
274 | - ser.unsigned_8(PLCMD_SHIP_SCOUT); |
275 | - ser.unsigned_8(sender()); |
276 | + write_id_and_sender(ser); |
277 | ser.unsigned_32(serial); |
278 | ser.unsigned_8(static_cast<uint8_t>(dir)); |
279 | } |
280 | @@ -857,8 +820,7 @@ |
281 | } |
282 | |
283 | void CmdShipConstructPort::serialize(StreamWrite& ser) { |
284 | - ser.unsigned_8(PLCMD_SHIP_CONSTRUCT); |
285 | - ser.unsigned_8(sender()); |
286 | + write_id_and_sender(ser); |
287 | ser.unsigned_32(serial); |
288 | write_coords_32(&ser, coords); |
289 | } |
290 | @@ -918,8 +880,7 @@ |
291 | } |
292 | |
293 | void CmdShipExploreIsland::serialize(StreamWrite& ser) { |
294 | - ser.unsigned_8(PLCMD_SHIP_EXPLORE); |
295 | - ser.unsigned_8(sender()); |
296 | + write_id_and_sender(ser); |
297 | ser.unsigned_32(serial); |
298 | ser.unsigned_8(static_cast<uint8_t>(island_explore_direction)); |
299 | } |
300 | @@ -967,8 +928,7 @@ |
301 | } |
302 | |
303 | void CmdShipSink::serialize(StreamWrite& ser) { |
304 | - ser.unsigned_8(PLCMD_SHIP_SINK); |
305 | - ser.unsigned_8(sender()); |
306 | + write_id_and_sender(ser); |
307 | ser.unsigned_32(serial); |
308 | } |
309 | |
310 | @@ -1012,8 +972,7 @@ |
311 | } |
312 | |
313 | void CmdShipCancelExpedition::serialize(StreamWrite& ser) { |
314 | - ser.unsigned_8(PLCMD_SHIP_CANCELEXPEDITION); |
315 | - ser.unsigned_8(sender()); |
316 | + write_id_and_sender(ser); |
317 | ser.unsigned_32(serial); |
318 | } |
319 | |
320 | @@ -1124,8 +1083,7 @@ |
321 | } |
322 | |
323 | void CmdSetWarePriority::serialize(StreamWrite& ser) { |
324 | - ser.unsigned_8(PLCMD_SETWAREPRIORITY); |
325 | - ser.unsigned_8(sender()); |
326 | + write_id_and_sender(ser); |
327 | ser.unsigned_32(serial_); |
328 | ser.unsigned_8(type_); |
329 | ser.signed_32(index_); |
330 | @@ -1238,8 +1196,7 @@ |
331 | } |
332 | |
333 | void CmdSetInputMaxFill::serialize(StreamWrite& ser) { |
334 | - ser.unsigned_8(PLCMD_SETINPUTMAXFILL); |
335 | - ser.unsigned_8(sender()); |
336 | + write_id_and_sender(ser); |
337 | ser.unsigned_32(serial_); |
338 | ser.signed_32(index_); |
339 | if (type_ == wwWARE) { |
340 | @@ -1279,7 +1236,7 @@ |
341 | } |
342 | |
343 | void CmdChangeTargetQuantity::serialize(StreamWrite& ser) { |
344 | - ser.unsigned_8(sender()); |
345 | + // Subclasses take care of writing their id() and sender() |
346 | ser.unsigned_32(economy()); |
347 | ser.unsigned_8(ware_type()); |
348 | } |
349 | @@ -1330,7 +1287,7 @@ |
350 | } |
351 | |
352 | void CmdSetWareTargetQuantity::serialize(StreamWrite& ser) { |
353 | - ser.unsigned_8(PLCMD_SETWARETARGETQUANTITY); |
354 | + write_id_and_sender(ser); |
355 | CmdChangeTargetQuantity::serialize(ser); |
356 | ser.unsigned_32(permanent_); |
357 | } |
358 | @@ -1377,7 +1334,7 @@ |
359 | } |
360 | |
361 | void CmdResetWareTargetQuantity::serialize(StreamWrite& ser) { |
362 | - ser.unsigned_8(PLCMD_RESETWARETARGETQUANTITY); |
363 | + write_id_and_sender(ser); |
364 | CmdChangeTargetQuantity::serialize(ser); |
365 | } |
366 | |
367 | @@ -1428,7 +1385,7 @@ |
368 | } |
369 | |
370 | void CmdSetWorkerTargetQuantity::serialize(StreamWrite& ser) { |
371 | - ser.unsigned_8(PLCMD_SETWORKERTARGETQUANTITY); |
372 | + write_id_and_sender(ser); |
373 | CmdChangeTargetQuantity::serialize(ser); |
374 | ser.unsigned_32(permanent_); |
375 | } |
376 | @@ -1479,7 +1436,7 @@ |
377 | } |
378 | |
379 | void CmdResetWorkerTargetQuantity::serialize(StreamWrite& ser) { |
380 | - ser.unsigned_8(PLCMD_RESETWORKERTARGETQUANTITY); |
381 | + write_id_and_sender(ser); |
382 | CmdChangeTargetQuantity::serialize(ser); |
383 | } |
384 | |
385 | @@ -1497,8 +1454,7 @@ |
386 | } |
387 | |
388 | void CmdChangeTrainingOptions::serialize(StreamWrite& ser) { |
389 | - ser.unsigned_8(PLCMD_CHANGETRAININGOPTIONS); |
390 | - ser.unsigned_8(sender()); |
391 | + write_id_and_sender(ser); |
392 | ser.unsigned_32(serial); |
393 | ser.unsigned_8(static_cast<uint8_t>(attribute)); |
394 | ser.unsigned_16(value); |
395 | @@ -1550,8 +1506,7 @@ |
396 | } |
397 | |
398 | void CmdDropSoldier::serialize(StreamWrite& ser) { |
399 | - ser.unsigned_8(PLCMD_DROPSOLDIER); |
400 | - ser.unsigned_8(sender()); |
401 | + write_id_and_sender(ser); |
402 | ser.unsigned_32(serial); |
403 | ser.unsigned_32(soldier); |
404 | } |
405 | @@ -1625,8 +1580,7 @@ |
406 | } |
407 | |
408 | void CmdChangeSoldierCapacity::serialize(StreamWrite& ser) { |
409 | - ser.unsigned_8(PLCMD_CHANGESOLDIERCAPACITY); |
410 | - ser.unsigned_8(sender()); |
411 | + write_id_and_sender(ser); |
412 | ser.unsigned_32(serial); |
413 | ser.signed_16(val); |
414 | } |
415 | @@ -1702,8 +1656,7 @@ |
416 | } |
417 | |
418 | void CmdEnemyFlagAction::serialize(StreamWrite& ser) { |
419 | - ser.unsigned_8(PLCMD_ENEMYFLAGACTION); |
420 | - ser.unsigned_8(sender()); |
421 | + write_id_and_sender(ser); |
422 | ser.unsigned_8(1); |
423 | ser.unsigned_32(serial); |
424 | ser.unsigned_8(sender()); |
425 | @@ -1808,8 +1761,7 @@ |
426 | } |
427 | |
428 | void CmdMessageSetStatusRead::serialize(StreamWrite& ser) { |
429 | - ser.unsigned_8(PLCMD_MESSAGESETSTATUSREAD); |
430 | - ser.unsigned_8(sender()); |
431 | + write_id_and_sender(ser); |
432 | ser.unsigned_32(message_id().value()); |
433 | } |
434 | |
435 | @@ -1821,8 +1773,7 @@ |
436 | } |
437 | |
438 | void CmdMessageSetStatusArchived::serialize(StreamWrite& ser) { |
439 | - ser.unsigned_8(PLCMD_MESSAGESETSTATUSARCHIVED); |
440 | - ser.unsigned_8(sender()); |
441 | + write_id_and_sender(ser); |
442 | ser.unsigned_32(message_id().value()); |
443 | } |
444 | |
445 | @@ -1888,8 +1839,7 @@ |
446 | } |
447 | |
448 | void CmdSetStockPolicy::serialize(StreamWrite& ser) { |
449 | - ser.unsigned_8(PLCMD_SETSTOCKPOLICY); |
450 | - ser.unsigned_8(sender()); |
451 | + write_id_and_sender(ser); |
452 | ser.unsigned_32(warehouse_); |
453 | ser.unsigned_8(isworker_); |
454 | ser.unsigned_8(ware_); |
455 | @@ -1972,8 +1922,7 @@ |
456 | } |
457 | |
458 | void CmdProposeTrade::serialize(StreamWrite& ser) { |
459 | - ser.unsigned_8(PLCMD_PROPOSE_TRADE); |
460 | - ser.unsigned_8(sender()); |
461 | + write_id_and_sender(ser); |
462 | ser.unsigned_32(trade_.initiator); |
463 | ser.unsigned_32(trade_.receiver); |
464 | serialize_bill_of_materials(trade_.items_to_send, &ser); |
465 | |
466 | === modified file 'src/logic/playercommand.h' |
467 | --- src/logic/playercommand.h 2019-06-23 14:28:50 +0000 |
468 | +++ src/logic/playercommand.h 2019-08-26 10:38:04 +0000 |
469 | @@ -52,6 +52,8 @@ |
470 | PlayerCommand() : GameLogicCommand(0), sender_(0), cmdserial_(0) { |
471 | } |
472 | |
473 | + void write_id_and_sender(StreamWrite& ser); |
474 | + |
475 | PlayerNumber sender() const { |
476 | return sender_; |
477 | } |
478 | @@ -62,6 +64,7 @@ |
479 | cmdserial_ = s; |
480 | } |
481 | |
482 | + // For networking and replays |
483 | virtual void serialize(StreamWrite&) = 0; |
484 | static Widelands::PlayerCommand* deserialize(StreamRead&); |
485 | |
486 | @@ -138,7 +141,7 @@ |
487 | void read(FileRead&, EditorGameBase&, MapObjectLoader&) override; |
488 | |
489 | QueueCommandTypes id() const override { |
490 | - return QueueCommandTypes::kFlag; |
491 | + return QueueCommandTypes::kBuildFlag; |
492 | } |
493 | |
494 | void execute(Game&) override; |
495 | @@ -207,7 +210,7 @@ |
496 | void read(FileRead&, EditorGameBase&, MapObjectLoader&) override; |
497 | |
498 | QueueCommandTypes id() const override { |
499 | - return QueueCommandTypes::kStopBuilding; |
500 | + return QueueCommandTypes::kStartStopBuilding; |
501 | } |
502 | |
503 | explicit CmdStartStopBuilding(StreamRead&); |
504 | @@ -257,7 +260,7 @@ |
505 | void read(FileRead&, EditorGameBase&, MapObjectLoader&) override; |
506 | |
507 | QueueCommandTypes id() const override { |
508 | - return QueueCommandTypes::kPortStartExpedition; |
509 | + return QueueCommandTypes::kStartOrCancelExpedition; |
510 | } |
511 | |
512 | explicit CmdStartOrCancelExpedition(StreamRead&); |
513 | @@ -356,7 +359,7 @@ |
514 | void read(FileRead&, EditorGameBase&, MapObjectLoader&) override; |
515 | |
516 | QueueCommandTypes id() const override { |
517 | - return QueueCommandTypes::kShipScout; |
518 | + return QueueCommandTypes::kShipScoutDirection; |
519 | } |
520 | |
521 | explicit CmdShipScoutDirection(StreamRead&); |
522 | @@ -408,7 +411,7 @@ |
523 | void read(FileRead&, EditorGameBase&, MapObjectLoader&) override; |
524 | |
525 | QueueCommandTypes id() const override { |
526 | - return QueueCommandTypes::kShipExplore; |
527 | + return QueueCommandTypes::kShipExploreIsland; |
528 | } |
529 | |
530 | explicit CmdShipExploreIsland(StreamRead&); |
531 | @@ -431,7 +434,7 @@ |
532 | void read(FileRead&, EditorGameBase&, MapObjectLoader&) override; |
533 | |
534 | QueueCommandTypes id() const override { |
535 | - return QueueCommandTypes::kSinkShip; |
536 | + return QueueCommandTypes::kShipSink; |
537 | } |
538 | |
539 | explicit CmdShipSink(StreamRead&); |
540 | |
541 | === modified file 'src/logic/queue_cmd_factory.cc' |
542 | --- src/logic/queue_cmd_factory.cc 2019-06-09 10:33:51 +0000 |
543 | +++ src/logic/queue_cmd_factory.cc 2019-08-26 10:38:04 +0000 |
544 | @@ -34,13 +34,13 @@ |
545 | switch (id) { |
546 | case QueueCommandTypes::kBuild: |
547 | return *new CmdBuild(); |
548 | - case QueueCommandTypes::kFlag: |
549 | + case QueueCommandTypes::kBuildFlag: |
550 | return *new CmdBuildFlag(); |
551 | case QueueCommandTypes::kBuildRoad: |
552 | return *new CmdBuildRoad(); |
553 | case QueueCommandTypes::kFlagAction: |
554 | return *new CmdFlagAction(); |
555 | - case QueueCommandTypes::kStopBuilding: |
556 | + case QueueCommandTypes::kStartStopBuilding: |
557 | return *new CmdStartStopBuilding(); |
558 | case QueueCommandTypes::kEnhanceBuilding: |
559 | return *new CmdEnhanceBuilding(); |
560 | @@ -80,17 +80,17 @@ |
561 | return *new CmdMilitarySiteSetSoldierPreference(); |
562 | case QueueCommandTypes::kProposeTrade: |
563 | return *new CmdProposeTrade(); |
564 | - case QueueCommandTypes::kSinkShip: |
565 | + case QueueCommandTypes::kShipSink: |
566 | return *new CmdShipSink(); |
567 | case QueueCommandTypes::kShipCancelExpedition: |
568 | return *new CmdShipCancelExpedition(); |
569 | - case QueueCommandTypes::kPortStartExpedition: |
570 | + case QueueCommandTypes::kStartOrCancelExpedition: |
571 | return *new CmdStartOrCancelExpedition(); |
572 | case QueueCommandTypes::kShipConstructPort: |
573 | return *new CmdShipConstructPort(); |
574 | - case QueueCommandTypes::kShipScout: |
575 | + case QueueCommandTypes::kShipScoutDirection: |
576 | return *new CmdShipScoutDirection(); |
577 | - case QueueCommandTypes::kShipExplore: |
578 | + case QueueCommandTypes::kShipExploreIsland: |
579 | return *new CmdShipExploreIsland(); |
580 | case QueueCommandTypes::kDestroyMapObject: |
581 | return *new CmdDestroyMapObject(); |
582 | |
583 | === modified file 'src/logic/queue_cmd_ids.h' |
584 | --- src/logic/queue_cmd_ids.h 2019-06-09 10:33:51 +0000 |
585 | +++ src/logic/queue_cmd_ids.h 2019-08-26 10:38:04 +0000 |
586 | @@ -33,17 +33,21 @@ |
587 | |
588 | namespace Widelands { |
589 | |
590 | -enum class QueueCommandTypes { |
591 | +// The command types are used by the QueueCmdFactory, for network serialization |
592 | +// and for savegame compatibility. |
593 | +// DO NOT change the order |
594 | +// TODO(GunChleoc): Whenever we break savegame compatibility, clean this up and change data type to uint16_t. |
595 | +enum class QueueCommandTypes : uint8_t { |
596 | |
597 | /* ID zero is reserved and must never be used */ |
598 | kNone = 0, |
599 | |
600 | /* PLAYER COMMANDS BELOW */ |
601 | kBuild, |
602 | - kFlag, |
603 | + kBuildFlag, |
604 | kBuildRoad, |
605 | kFlagAction, |
606 | - kStopBuilding, |
607 | + kStartStopBuilding, |
608 | kEnhanceBuilding, |
609 | kBulldoze, |
610 | |
611 | @@ -73,12 +77,14 @@ |
612 | kMilitarysiteSetSoldierPreference, |
613 | kProposeTrade, // 27 |
614 | |
615 | - kSinkShip = 121, |
616 | + kShipSink = 121, |
617 | kShipCancelExpedition, |
618 | - kPortStartExpedition, |
619 | + kStartOrCancelExpedition, |
620 | kShipConstructPort, |
621 | - kShipScout, |
622 | - kShipExplore, |
623 | + kShipScoutDirection, |
624 | + kShipExploreIsland, |
625 | + |
626 | + // The commands below are never serialized, but we still keep the IDs stable for savegame compatibility. |
627 | |
628 | kDestroyMapObject, |
629 | kAct, // 128 |
630 | |
631 | === modified file 'src/logic/replay.cc' |
632 | --- src/logic/replay.cc 2019-02-24 22:50:04 +0000 |
633 | +++ src/logic/replay.cc 2019-08-26 10:38:04 +0000 |
634 | @@ -38,8 +38,9 @@ |
635 | namespace Widelands { |
636 | |
637 | // File format definitions |
638 | +constexpr uint32_t kReplayKnownToDesync = 0x2E21A100; |
639 | constexpr uint32_t kReplayMagic = 0x2E21A101; |
640 | -constexpr uint8_t kCurrentPacketVersion = 2; |
641 | +constexpr uint8_t kCurrentPacketVersion = 3; |
642 | constexpr uint32_t kSyncInterval = 200; |
643 | |
644 | enum { pkt_end = 2, pkt_playercommand = 3, pkt_syncreport = 4 }; |
645 | @@ -93,13 +94,15 @@ |
646 | |
647 | try { |
648 | const uint32_t magic = cmdlog_->unsigned_32(); |
649 | - if (magic == 0x2E21A100) |
650 | + if (magic == kReplayKnownToDesync) { |
651 | // Note: This was never released as part of a build |
652 | throw wexception("%s is a replay from a version that is known to have desync " |
653 | "problems", |
654 | filename.c_str()); |
655 | - if (magic != kReplayMagic) |
656 | + } |
657 | + if (magic != kReplayMagic) { |
658 | throw wexception("%s apparently not a valid replay file", filename.c_str()); |
659 | + } |
660 | |
661 | const uint8_t packet_version = cmdlog_->unsigned_8(); |
662 | if (packet_version != kCurrentPacketVersion) { |
Continuous integration builds have changed state:
Travis build 5244. State: passed. Details: https:/ /travis- ci.org/ widelands/ widelands/ builds/ 549982685. /ci.appveyor. com/project/ widelands- dev/widelands/ build/_ widelands_ dev_widelands_ cleanup_ playercommand_ enums-5023.
Appveyor build 5023. State: success. Details: https:/