Merge lp:~widelands-dev/widelands/reed-compatibility into lp:widelands

Proposed by GunChleoc
Status: Merged
Merged at revision: 9146
Proposed branch: lp:~widelands-dev/widelands/reed-compatibility
Merge into: lp:widelands
Diff against target: 823 lines (+122/-91)
19 files modified
src/economy/expedition_bootstrap.cc (+3/-3)
src/economy/expedition_bootstrap.h (+1/-1)
src/economy/input_queue.cc (+7/-6)
src/economy/input_queue.h (+1/-1)
src/economy/request.cc (+3/-3)
src/economy/request.h (+2/-1)
src/game_io/game_player_info_packet.cc (+2/-2)
src/map_io/map_buildingdata_packet.cc (+42/-38)
src/map_io/map_buildingdata_packet.h (+9/-8)
src/map_io/map_flagdata_packet.cc (+2/-2)
src/map_io/map_flagdata_packet.h (+8/-1)
src/map_io/map_object_packet.cc (+4/-4)
src/map_io/map_object_packet.h (+1/-1)
src/map_io/map_players_view_packet.cc (+9/-9)
src/map_io/map_players_view_packet.h (+10/-1)
src/map_io/map_roaddata_packet.cc (+2/-2)
src/map_io/map_roaddata_packet.h (+8/-1)
src/map_io/tribes_legacy_lookup_table.cc (+2/-1)
src/map_io/widelands_map_loader.cc (+6/-6)
To merge this branch: bzr merge lp:~widelands-dev/widelands/reed-compatibility
Reviewer Review Type Date Requested Status
hessenfarmer Approve
Review via email: mp+367935@code.launchpad.net

Commit message

Fix savegame compatibility for reed, buildings, players view and economy requests.

To post a comment you must log in.
Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 5058. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/537337141.
Appveyor build 4838. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_reed_compatibility-4838.

Revision history for this message
Notabilis (notabilis27) wrote :

So ... you created a diff of 800 lines by passing objects around so you can call a method in only a handful of places?? I like it! :)
The changes are mostly looking good to me. Replacing the GOTO might be broken, though, see my diff comment below.

I haven't tested the changes, mostly because I have no sensible idea how to do so. But based on the code I guess it shouldn't break anything.

Revision history for this message
GunChleoc (gunchleoc) wrote :

> So ... you created a diff of 800 lines by passing objects around so you can call a method in only a handful of places?? I like it! :)

Lol yep. It will save a bit of memory though if the objects are created only once.

For triggering the bug, you need a savegame created with bzr9118 or older that has reed or wheat fields on it.

9124. By GunChleoc

Addressed code review.

9125. By GunChleoc

Merged trunk.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 5154. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/541619525.
Appveyor build 4936. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_reed_compatibility-4936.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I have added a second if statement for the test variable to simulate the effect of the goto and break out of the outer loop. Thanks for the review!

@bunybot merge

9126. By GunChleoc

Merged trunk.

Revision history for this message
Notabilis (notabilis27) wrote :

Sorry, I am having second thoughts about the goto-part. Actually, I am not only unsure about the goto-replacement but over the whole code part independent of your changes. :-/
If I understand it right, the code iterates over the possible jobs in the production site. If there is a job the loaded worker can work on, we iterate over all working positions of the site and check if *any* of these is empty, so we can assign the worker. Shouldn't we only check the working positions that are for the required job? Otherwise, the code could break with production sites which have multiple types of worker positions (Mines probably? These need a miner and a master miner).

Maybe I am just confused and the code is fine, but it would be good if someone could check it.

Revision history for this message
GunChleoc (gunchleoc) wrote :

This code is pretty old, so I'm sure we would have had bug reports for it in the past if it was broken. It should be fine if iterating starts with the most advanced working position, because then we won't put a master miner i a miner's slot and end up stumped when we have to put a miner in a master miner's slot, which is not allowed.

I'll reinstate the goto to make sure we can't possibly have any accidental semantic changes, so that we can get this bugfix in.

9127. By GunChleoc

Merged trunk.

9128. By GunChleoc

Undo goto cleanup.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Done. Thanks for the review!

@bunnybot merge

Revision history for this message
GunChleoc (gunchleoc) wrote :

Inputqueues again

@bunnybot merge force

Revision history for this message
bunnybot (widelandsofficial) wrote :

Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.

Travis build 5164. State: errored. Details: https://travis-ci.org/widelands/widelands/builds/542121335.

Revision history for this message
hessenfarmer (stephan-lutz) wrote :

@bunnybot merge force

Revision history for this message
hessenfarmer (stephan-lutz) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/economy/expedition_bootstrap.cc'
2--- src/economy/expedition_bootstrap.cc 2019-02-23 11:00:49 +0000
3+++ src/economy/expedition_bootstrap.cc 2019-06-08 16:55:17 +0000
4@@ -203,7 +203,7 @@
5 }
6
7 void ExpeditionBootstrap::load(
8- Warehouse& warehouse, FileRead& fr, Game& game, MapObjectLoader& mol, uint16_t packet_version) {
9+ Warehouse& warehouse, FileRead& fr, Game& game, MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table, uint16_t packet_version) {
10
11 static const uint16_t kCurrentPacketVersion = 7;
12 assert(queues_.empty());
13@@ -214,7 +214,7 @@
14 uint8_t num_queues = fr.unsigned_8();
15 for (uint8_t i = 0; i < num_queues; ++i) {
16 WorkersQueue* wq = new WorkersQueue(warehouse, INVALID_INDEX, 0);
17- wq->read(fr, game, mol);
18+ wq->read(fr, game, mol, tribes_lookup_table);
19 wq->set_callback(input_callback, this);
20
21 if (wq->get_index() == INVALID_INDEX) {
22@@ -232,7 +232,7 @@
23 uint8_t num_queues = fr.unsigned_8();
24 for (uint8_t i = 0; i < num_queues; ++i) {
25 WaresQueue* wq = new WaresQueue(warehouse, INVALID_INDEX, 0);
26- wq->read(fr, game, mol);
27+ wq->read(fr, game, mol, tribes_lookup_table);
28 wq->set_callback(input_callback, this);
29
30 if (wq->get_index() == INVALID_INDEX) {
31
32=== modified file 'src/economy/expedition_bootstrap.h'
33--- src/economy/expedition_bootstrap.h 2019-02-23 11:00:49 +0000
34+++ src/economy/expedition_bootstrap.h 2019-06-08 16:55:17 +0000
35@@ -88,7 +88,7 @@
36 * packet, and there in the warehouse data packet.
37 */
38 void
39- load(Warehouse& warehouse, FileRead& fr, Game& game, MapObjectLoader& mol, uint16_t version);
40+ load(Warehouse& warehouse, FileRead& fr, Game& game, MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table, uint16_t version);
41
42 /** Save this into a file.
43 *
44
45=== modified file 'src/economy/input_queue.cc'
46--- src/economy/input_queue.cc 2019-02-23 11:00:49 +0000
47+++ src/economy/input_queue.cc 2019-06-08 16:55:17 +0000
48@@ -130,7 +130,7 @@
49
50 constexpr uint16_t kCurrentPacketVersion = 3;
51
52-void InputQueue::read(FileRead& fr, Game& game, MapObjectLoader& mol) {
53+void InputQueue::read(FileRead& fr, Game& game, MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table) {
54
55 uint16_t const packet_version = fr.unsigned_16();
56 try {
57@@ -140,25 +140,26 @@
58 if (packet_version == 1 || packet_version == kCurrentPacketVersion) {
59 if (fr.unsigned_8() == 0) {
60 assert(type_ == wwWARE);
61- index_ = owner().tribe().ware_index(fr.c_string());
62+ index_ = owner().tribe().ware_index(tribes_lookup_table.lookup_ware(fr.c_string()));
63 } else {
64 assert(type_ == wwWORKER);
65- index_ = owner().tribe().worker_index(fr.c_string());
66+ index_ = owner().tribe().worker_index(tribes_lookup_table.lookup_worker(fr.c_string()));
67 }
68 max_size_ = fr.unsigned_32();
69 max_fill_ = fr.signed_32();
70 consume_interval_ = fr.unsigned_32();
71 if (fr.unsigned_8()) {
72 request_.reset(new Request(owner_, 0, InputQueue::request_callback, type_));
73- request_->read(fr, game, mol);
74+ request_->read(fr, game, mol, tribes_lookup_table);
75 } else {
76 request_.reset();
77 }
78
79 read_child(fr, game, mol);
80 } else if (packet_version == 2) {
81+ // TODO(GunChleoc): Savegame compatibility, get rid after Build 21
82 assert(type_ == wwWARE);
83- index_ = owner().tribe().ware_index(fr.c_string());
84+ index_ = owner().tribe().ware_index(tribes_lookup_table.lookup_ware(fr.c_string()));
85 max_size_ = fr.unsigned_32();
86 max_fill_ = fr.signed_32();
87 // No read_child() call here, doing it manually since there is no child-version number
88@@ -166,7 +167,7 @@
89 consume_interval_ = fr.unsigned_32();
90 if (fr.unsigned_8()) {
91 request_.reset(new Request(owner_, 0, InputQueue::request_callback, type_));
92- request_->read(fr, game, mol);
93+ request_->read(fr, game, mol, tribes_lookup_table);
94 } else {
95 request_.reset();
96 }
97
98=== modified file 'src/economy/input_queue.h'
99--- src/economy/input_queue.h 2019-02-27 19:00:36 +0000
100+++ src/economy/input_queue.h 2019-06-08 16:55:17 +0000
101@@ -184,7 +184,7 @@
102 * @param game The game this queue will be part of.
103 * @param mol The game/map loader that handles the lading. Required to pass to Request::read().
104 */
105- void read(FileRead& f, Game& g, MapObjectLoader& mol);
106+ void read(FileRead& f, Game& g, MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table);
107
108 /**
109 * Writes the state of this class.
110
111=== modified file 'src/economy/request.cc'
112--- src/economy/request.cc 2019-02-23 11:00:49 +0000
113+++ src/economy/request.cc 2019-06-08 16:55:17 +0000
114@@ -98,18 +98,18 @@
115 * might have been initialized. We have to kill them and replace
116 * them through the data in the file
117 */
118-void Request::read(FileRead& fr, Game& game, MapObjectLoader& mol) {
119+void Request::read(FileRead& fr, Game& game, MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table) {
120 try {
121 uint16_t const packet_version = fr.unsigned_16();
122 if (packet_version == kCurrentPacketVersion) {
123 const TribeDescr& tribe = target_.owner().tribe();
124 char const* const type_name = fr.c_string();
125- DescriptionIndex const wai = tribe.ware_index(type_name);
126+ DescriptionIndex const wai = tribe.ware_index(tribes_lookup_table.lookup_ware(type_name));
127 if (tribe.has_ware(wai)) {
128 type_ = wwWARE;
129 index_ = wai;
130 } else {
131- DescriptionIndex const woi = tribe.worker_index(type_name);
132+ DescriptionIndex const woi = tribe.worker_index(tribes_lookup_table.lookup_worker(type_name));
133 if (tribe.has_worker(woi)) {
134 type_ = wwWORKER;
135 index_ = woi;
136
137=== modified file 'src/economy/request.h'
138--- src/economy/request.h 2019-02-23 11:00:49 +0000
139+++ src/economy/request.h 2019-06-08 16:55:17 +0000
140@@ -24,6 +24,7 @@
141 #include "logic/map_objects/tribes/requirements.h"
142 #include "logic/map_objects/tribes/wareworker.h"
143 #include "logic/widelands.h"
144+#include "map_io/tribes_legacy_lookup_table.h"
145
146 class FileRead;
147 class FileWrite;
148@@ -116,7 +117,7 @@
149
150 void start_transfer(Game&, Supply&);
151
152- void read(FileRead&, Game&, MapObjectLoader&);
153+ void read(FileRead&, Game&, MapObjectLoader&, const TribesLegacyLookupTable& tribes_lookup_table);
154 void write(FileWrite&, Game&, MapObjectSaver&) const;
155 Worker* get_transfer_worker();
156
157
158=== modified file 'src/game_io/game_player_info_packet.cc'
159--- src/game_io/game_player_info_packet.cc 2019-05-19 12:25:24 +0000
160+++ src/game_io/game_player_info_packet.cc 2019-06-08 16:55:17 +0000
161@@ -37,7 +37,7 @@
162
163 void GamePlayerInfoPacket::read(FileSystem& fs, Game& game, MapObjectLoader*) {
164 try {
165- std::unique_ptr<TribesLegacyLookupTable> tribe_lookup_table(new TribesLegacyLookupTable());
166+ std::unique_ptr<TribesLegacyLookupTable> tribes_lookup_table(new TribesLegacyLookupTable());
167 FileRead fr;
168 fr.open(fs, "binary/player_info");
169 uint16_t const packet_version = fr.unsigned_16();
170@@ -72,7 +72,7 @@
171 }
172 }
173
174- player->read_statistics(fr, packet_version, *tribe_lookup_table.get());
175+ player->read_statistics(fr, packet_version, *tribes_lookup_table.get());
176 player->read_remaining_shipnames(fr);
177
178 player->casualties_ = fr.unsigned_32();
179
180=== modified file 'src/map_io/map_buildingdata_packet.cc'
181--- src/map_io/map_buildingdata_packet.cc 2019-05-28 21:04:36 +0000
182+++ src/map_io/map_buildingdata_packet.cc 2019-06-08 16:55:17 +0000
183@@ -71,7 +71,7 @@
184 void MapBuildingdataPacket::read(FileSystem& fs,
185 EditorGameBase& egbase,
186 bool const skip,
187- MapObjectLoader& mol) {
188+ MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table) {
189 if (skip)
190 return;
191
192@@ -180,18 +180,18 @@
193 Game& game = dynamic_cast<Game&>(egbase);
194
195 if (upcast(ConstructionSite, constructionsite, &building)) {
196- read_constructionsite(*constructionsite, fr, game, mol);
197+ read_constructionsite(*constructionsite, fr, game, mol, tribes_lookup_table);
198 } else if (upcast(DismantleSite, dms, &building)) {
199- read_dismantlesite(*dms, fr, game, mol);
200+ read_dismantlesite(*dms, fr, game, mol, tribes_lookup_table);
201 } else if (upcast(MilitarySite, militarysite, &building)) {
202- read_militarysite(*militarysite, fr, game, mol);
203+ read_militarysite(*militarysite, fr, game, mol, tribes_lookup_table);
204 } else if (upcast(Warehouse, warehouse, &building)) {
205- read_warehouse(*warehouse, fr, game, mol);
206+ read_warehouse(*warehouse, fr, game, mol, tribes_lookup_table);
207 } else if (upcast(ProductionSite, productionsite, &building)) {
208 if (upcast(TrainingSite, trainingsite, productionsite)) {
209- read_trainingsite(*trainingsite, fr, game, mol);
210+ read_trainingsite(*trainingsite, fr, game, mol, tribes_lookup_table);
211 } else {
212- read_productionsite(*productionsite, fr, game, mol);
213+ read_productionsite(*productionsite, fr, game, mol, tribes_lookup_table);
214 }
215 } else {
216 // type of building is not one of (or derived from)
217@@ -215,7 +215,7 @@
218 void MapBuildingdataPacket::read_partially_finished_building(PartiallyFinishedBuilding& pfb,
219 FileRead& fr,
220 Game& game,
221- MapObjectLoader& mol) {
222+ MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table) {
223 try {
224 uint16_t const packet_version = fr.unsigned_16();
225 if (packet_version == kCurrentPacketPFBuilding) {
226@@ -226,7 +226,7 @@
227 if (fr.unsigned_8()) {
228 pfb.builder_request_ =
229 new Request(pfb, 0, PartiallyFinishedBuilding::request_builder_callback, wwWORKER);
230- pfb.builder_request_->read(fr, game, mol);
231+ pfb.builder_request_->read(fr, game, mol, tribes_lookup_table);
232 } else
233 pfb.builder_request_ = nullptr;
234
235@@ -244,7 +244,7 @@
236 pfb.wares_.resize(size);
237 for (uint16_t i = 0; i < pfb.wares_.size(); ++i) {
238 pfb.wares_[i] = new WaresQueue(pfb, INVALID_INDEX, 0);
239- pfb.wares_[i]->read(fr, game, mol);
240+ pfb.wares_[i]->read(fr, game, mol, tribes_lookup_table);
241 }
242 } catch (const WException& e) {
243 throw GameDataError("wares: %s", e.what());
244@@ -266,11 +266,11 @@
245 void MapBuildingdataPacket::read_constructionsite(ConstructionSite& constructionsite,
246 FileRead& fr,
247 Game& game,
248- MapObjectLoader& mol) {
249+ MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table) {
250 try {
251 uint16_t const packet_version = fr.unsigned_16();
252 if (packet_version >= kCurrentPacketVersionConstructionsite) {
253- read_partially_finished_building(constructionsite, fr, game, mol);
254+ read_partially_finished_building(constructionsite, fr, game, mol, tribes_lookup_table);
255
256 for (ConstructionSite::Wares::iterator wares_iter = constructionsite.wares_.begin();
257 wares_iter != constructionsite.wares_.end(); ++wares_iter) {
258@@ -291,11 +291,11 @@
259 void MapBuildingdataPacket::read_dismantlesite(DismantleSite& dms,
260 FileRead& fr,
261 Game& game,
262- MapObjectLoader& mol) {
263+ MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table) {
264 try {
265 uint16_t const packet_version = fr.unsigned_16();
266 if (packet_version == kCurrentPacketVersionDismantlesite) {
267- read_partially_finished_building(dms, fr, game, mol);
268+ read_partially_finished_building(dms, fr, game, mol, tribes_lookup_table);
269
270 // Nothing to do
271 } else {
272@@ -310,7 +310,7 @@
273 void MapBuildingdataPacket::read_warehouse(Warehouse& warehouse,
274 FileRead& fr,
275 Game& game,
276- MapObjectLoader& mol) {
277+ MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table) {
278 try {
279 uint16_t const packet_version = fr.unsigned_16();
280 if (packet_version >= 6) {
281@@ -319,7 +319,7 @@
282 const TribeDescr& tribe = player->tribe();
283
284 while (fr.unsigned_8()) {
285- const DescriptionIndex& id = tribe.ware_index(fr.c_string());
286+ const DescriptionIndex& id = tribe.ware_index(tribes_lookup_table.lookup_ware(fr.c_string()));
287 Quantity amount = fr.unsigned_32();
288 Warehouse::StockPolicy policy = static_cast<Warehouse::StockPolicy>(fr.unsigned_8());
289
290@@ -329,7 +329,7 @@
291 }
292 }
293 while (fr.unsigned_8()) {
294- const DescriptionIndex& id = tribe.worker_index(fr.c_string());
295+ const DescriptionIndex& id = tribe.worker_index(tribes_lookup_table.lookup_worker(fr.c_string()));
296 uint32_t amount = fr.unsigned_32();
297 Warehouse::StockPolicy policy = static_cast<Warehouse::StockPolicy>(fr.unsigned_8());
298
299@@ -364,15 +364,16 @@
300 tribe.worker_types_without_cost();
301
302 for (;;) {
303- char const* const worker_typename = fr.c_string();
304- if (!*worker_typename) // encountered the terminator ("")
305+ const std::string worker_typename = tribes_lookup_table.lookup_worker(fr.c_string());
306+ if (worker_typename.empty()) { // No more workers found
307 break;
308+ }
309 uint32_t const next_spawn = fr.unsigned_32();
310 DescriptionIndex const worker_index = tribe.safe_worker_index(worker_typename);
311 if (!game.tribes().worker_exists(worker_index)) {
312 log("WARNING: %s %u has a next_spawn time for nonexistent "
313 "worker type \"%s\" set to %u, ignoring\n",
314- warehouse.descr().name().c_str(), warehouse.serial(), worker_typename,
315+ warehouse.descr().name().c_str(), warehouse.serial(), worker_typename.c_str(),
316 next_spawn);
317 continue;
318 }
319@@ -380,7 +381,7 @@
320 log("WARNING: %s %u has a next_spawn time for worker type "
321 "\"%s\", that costs something to build, set to %u, "
322 "ignoring\n",
323- warehouse.descr().name().c_str(), warehouse.serial(), worker_typename,
324+ warehouse.descr().name().c_str(), warehouse.serial(), worker_typename.c_str(),
325 next_spawn);
326 continue;
327 }
328@@ -392,7 +393,7 @@
329 "\"%s\" set to %u, but it was previously set "
330 "to %u\n",
331 warehouse.descr().name().c_str(), warehouse.serial(),
332- worker_typename, next_spawn,
333+ worker_typename.c_str(), next_spawn,
334 warehouse.next_worker_without_cost_spawn_[i]);
335 warehouse.next_worker_without_cost_spawn_[i] = next_spawn;
336 break;
337@@ -409,13 +410,13 @@
338 while (nr_planned_workers--) {
339 warehouse.planned_workers_.push_back(Warehouse::PlannedWorkers());
340 Warehouse::PlannedWorkers& pw = warehouse.planned_workers_.back();
341- pw.index = tribe.worker_index(fr.c_string());
342+ pw.index = tribe.worker_index(tribes_lookup_table.lookup_worker(fr.c_string()));
343 pw.amount = fr.unsigned_32();
344
345 uint32_t nr_requests = fr.unsigned_32();
346 while (nr_requests--) {
347 pw.requests.push_back(new Request(warehouse, 0, &Warehouse::request_cb, wwWORKER));
348- pw.requests.back()->read(fr, game, mol);
349+ pw.requests.back()->read(fr, game, mol, tribes_lookup_table);
350 }
351 }
352
353@@ -430,7 +431,7 @@
354 // doesn't lend itself to request and other stuff.
355 if (warehouse.portdock_->expedition_started()) {
356 warehouse.portdock_->expedition_bootstrap()->load(
357- warehouse, fr, game, mol, packet_version);
358+ warehouse, fr, game, mol, tribes_lookup_table, packet_version);
359 }
360 }
361 }
362@@ -463,7 +464,7 @@
363 void MapBuildingdataPacket::read_militarysite(MilitarySite& militarysite,
364 FileRead& fr,
365 Game& game,
366- MapObjectLoader& mol) {
367+ MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table) {
368 try {
369 uint16_t const packet_version = fr.unsigned_16();
370 if (packet_version >= 5 && packet_version <= kCurrentPacketVersionMilitarysite) {
371@@ -472,18 +473,20 @@
372 if (fr.unsigned_8()) {
373 militarysite.normal_soldier_request_.reset(
374 new Request(militarysite, 0, MilitarySite::request_soldier_callback, wwWORKER));
375- militarysite.normal_soldier_request_->read(fr, game, mol);
376- } else
377+ militarysite.normal_soldier_request_->read(fr, game, mol, tribes_lookup_table);
378+ } else {
379 militarysite.normal_soldier_request_.reset();
380+ }
381
382 if (fr.unsigned_8()) {
383 militarysite.upgrade_soldier_request_.reset(new Request(
384 militarysite,
385 (!militarysite.normal_soldier_request_) ? 0 : militarysite.owner().tribe().soldier(),
386 MilitarySite::request_soldier_callback, wwWORKER));
387- militarysite.upgrade_soldier_request_->read(fr, game, mol);
388- } else
389+ militarysite.upgrade_soldier_request_->read(fr, game, mol, tribes_lookup_table);
390+ } else {
391 militarysite.upgrade_soldier_request_.reset();
392+ }
393
394 if ((militarysite.didconquer_ = fr.unsigned_8())) {
395 // Add to map of military influence.
396@@ -549,7 +552,7 @@
397 void MapBuildingdataPacket::read_productionsite(ProductionSite& productionsite,
398 FileRead& fr,
399 Game& game,
400- MapObjectLoader& mol) {
401+ MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table) {
402 try {
403 uint16_t const packet_version = fr.unsigned_16();
404 // TODO(GunChleoc): Savegame compatibility, remove after Build 21.
405@@ -562,7 +565,7 @@
406 for (uint16_t i = nr_worker_requests; i; --i) {
407 Request& req =
408 *new Request(productionsite, 0, ProductionSite::request_worker_callback, wwWORKER);
409- req.read(fr, game, mol);
410+ req.read(fr, game, mol, tribes_lookup_table);
411 const DescriptionIndex& worker_index = req.get_index();
412
413 // Find a working position that matches this request.
414@@ -587,8 +590,9 @@
415 }
416 found_working_position = true;
417 break;
418- } else
419+ } else {
420 wp += count;
421+ }
422 }
423
424 if (!found_working_position)
425@@ -682,7 +686,7 @@
426 assert(!productionsite.input_queues_.size());
427 for (uint16_t i = 0; i < nr_queues; ++i) {
428 WaresQueue* wq = new WaresQueue(productionsite, INVALID_INDEX, 0);
429- wq->read(fr, game, mol);
430+ wq->read(fr, game, mol, tribes_lookup_table);
431
432 if (!game.tribes().ware_exists(wq->get_index())) {
433 delete wq;
434@@ -695,7 +699,7 @@
435 nr_queues = fr.unsigned_16();
436 for (uint16_t i = 0; i < nr_queues; ++i) {
437 WorkersQueue* wq = new WorkersQueue(productionsite, INVALID_INDEX, 0);
438- wq->read(fr, game, mol);
439+ wq->read(fr, game, mol, tribes_lookup_table);
440
441 if (!game.tribes().worker_exists(wq->get_index())) {
442 delete wq;
443@@ -732,18 +736,18 @@
444 void MapBuildingdataPacket::read_trainingsite(TrainingSite& trainingsite,
445 FileRead& fr,
446 Game& game,
447- MapObjectLoader& mol) {
448+ MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table) {
449 try {
450 uint16_t const packet_version = fr.unsigned_16();
451 if (packet_version == kCurrentPacketVersionTrainingsite) {
452- read_productionsite(trainingsite, fr, game, mol);
453+ read_productionsite(trainingsite, fr, game, mol, tribes_lookup_table);
454
455 delete trainingsite.soldier_request_;
456 trainingsite.soldier_request_ = nullptr;
457 if (fr.unsigned_8()) {
458 trainingsite.soldier_request_ =
459 new Request(trainingsite, 0, TrainingSite::request_soldier_callback, wwWORKER);
460- trainingsite.soldier_request_->read(fr, game, mol);
461+ trainingsite.soldier_request_->read(fr, game, mol, tribes_lookup_table);
462 }
463
464 trainingsite.capacity_ = fr.unsigned_8();
465
466=== modified file 'src/map_io/map_buildingdata_packet.h'
467--- src/map_io/map_buildingdata_packet.h 2019-02-23 11:00:49 +0000
468+++ src/map_io/map_buildingdata_packet.h 2019-06-08 16:55:17 +0000
469@@ -21,6 +21,7 @@
470 #define WL_MAP_IO_MAP_BUILDINGDATA_PACKET_H
471
472 #include "map_io/map_data_packet.h"
473+#include "map_io/tribes_legacy_lookup_table.h"
474
475 class FileRead;
476 class FileWrite;
477@@ -42,18 +43,18 @@
478 */
479 class MapBuildingdataPacket {
480 public:
481- void read(FileSystem&, EditorGameBase&, bool, MapObjectLoader&);
482+ void read(FileSystem&, EditorGameBase&, bool, MapObjectLoader&, const TribesLegacyLookupTable& tribes_lookup_table);
483 void write(FileSystem&, EditorGameBase&, MapObjectSaver&);
484
485 private:
486- void read_constructionsite(ConstructionSite&, FileRead&, Game&, MapObjectLoader&);
487- void read_dismantlesite(DismantleSite&, FileRead&, Game&, MapObjectLoader&);
488+ void read_constructionsite(ConstructionSite&, FileRead&, Game&, MapObjectLoader&, const TribesLegacyLookupTable& tribes_lookup_table);
489+ void read_dismantlesite(DismantleSite&, FileRead&, Game&, MapObjectLoader&, const TribesLegacyLookupTable& tribes_lookup_table);
490 void
491- read_partially_finished_building(PartiallyFinishedBuilding&, FileRead&, Game&, MapObjectLoader&);
492- void read_warehouse(Warehouse&, FileRead&, Game&, MapObjectLoader&);
493- void read_militarysite(MilitarySite&, FileRead&, Game&, MapObjectLoader&);
494- void read_trainingsite(TrainingSite&, FileRead&, Game&, MapObjectLoader&);
495- void read_productionsite(ProductionSite&, FileRead&, Game&, MapObjectLoader&);
496+ read_partially_finished_building(PartiallyFinishedBuilding&, FileRead&, Game&, MapObjectLoader&, const TribesLegacyLookupTable& tribes_lookup_table);
497+ void read_warehouse(Warehouse&, FileRead&, Game&, MapObjectLoader&, const TribesLegacyLookupTable& tribes_lookup_table);
498+ void read_militarysite(MilitarySite&, FileRead&, Game&, MapObjectLoader&, const TribesLegacyLookupTable& tribes_lookup_table);
499+ void read_trainingsite(TrainingSite&, FileRead&, Game&, MapObjectLoader&, const TribesLegacyLookupTable& tribes_lookup_table);
500+ void read_productionsite(ProductionSite&, FileRead&, Game&, MapObjectLoader&, const TribesLegacyLookupTable& tribes_lookup_table);
501
502 void write_constructionsite(const ConstructionSite&, FileWrite&, Game&, MapObjectSaver&);
503 void write_dismantlesite(const DismantleSite&, FileWrite&, Game&, MapObjectSaver&);
504
505=== modified file 'src/map_io/map_flagdata_packet.cc'
506--- src/map_io/map_flagdata_packet.cc 2019-02-23 11:00:49 +0000
507+++ src/map_io/map_flagdata_packet.cc 2019-06-08 16:55:17 +0000
508@@ -43,7 +43,7 @@
509 void MapFlagdataPacket::read(FileSystem& fs,
510 EditorGameBase& egbase,
511 bool const skip,
512- MapObjectLoader& mol) {
513+ MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table) {
514 if (skip)
515 return;
516
517@@ -131,7 +131,7 @@
518 Flag::FlagJob f;
519 if (fr.unsigned_8()) {
520 f.request = new Request(flag, 0, Flag::flag_job_request_callback, wwWORKER);
521- f.request->read(fr, dynamic_cast<Game&>(egbase), mol);
522+ f.request->read(fr, dynamic_cast<Game&>(egbase), mol, tribes_lookup_table);
523 } else {
524 f.request = nullptr;
525 }
526
527=== modified file 'src/map_io/map_flagdata_packet.h'
528--- src/map_io/map_flagdata_packet.h 2019-02-23 11:00:49 +0000
529+++ src/map_io/map_flagdata_packet.h 2019-06-08 16:55:17 +0000
530@@ -21,7 +21,14 @@
531 #define WL_MAP_IO_MAP_FLAGDATA_PACKET_H
532
533 #include "map_io/map_data_packet.h"
534+#include "map_io/tribes_legacy_lookup_table.h"
535
536-MAP_DATA_PACKET(MapFlagdataPacket)
537+namespace Widelands {
538+class MapFlagdataPacket {
539+public:
540+ void read(FileSystem&, EditorGameBase&, bool, MapObjectLoader&, const TribesLegacyLookupTable& tribes_lookup_table);
541+ void write(FileSystem&, EditorGameBase&, MapObjectSaver&);
542+};
543+}
544
545 #endif // end of include guard: WL_MAP_IO_MAP_FLAGDATA_PACKET_H
546
547=== modified file 'src/map_io/map_object_packet.cc'
548--- src/map_io/map_object_packet.cc 2019-02-23 11:00:49 +0000
549+++ src/map_io/map_object_packet.cc 2019-06-08 16:55:17 +0000
550@@ -49,7 +49,7 @@
551 EditorGameBase& egbase,
552 MapObjectLoader& mol,
553 const WorldLegacyLookupTable& world_lookup_table,
554- const TribesLegacyLookupTable& tribe_lookup_table) {
555+ const TribesLegacyLookupTable& tribes_lookup_table) {
556 try {
557 FileRead fr;
558 fr.open(fs, "binary/mapobjects");
559@@ -66,7 +66,7 @@
560 return;
561 case MapObject::HeaderImmovable:
562 loaders.insert(
563- Immovable::load(egbase, mol, fr, world_lookup_table, tribe_lookup_table));
564+ Immovable::load(egbase, mol, fr, world_lookup_table, tribes_lookup_table));
565 break;
566
567 case MapObject::HeaderBattle:
568@@ -81,11 +81,11 @@
569 // We can't use the worker's savegame version, because some stuff is loaded before
570 // that
571 // packet version, and we removed the tribe name.
572- loaders.insert(Worker::load(egbase, mol, fr, tribe_lookup_table, packet_version));
573+ loaders.insert(Worker::load(egbase, mol, fr, tribes_lookup_table, packet_version));
574 break;
575
576 case MapObject::HeaderWareInstance:
577- loaders.insert(WareInstance::load(egbase, mol, fr, tribe_lookup_table));
578+ loaders.insert(WareInstance::load(egbase, mol, fr, tribes_lookup_table));
579 break;
580
581 case MapObject::HeaderShip:
582
583=== modified file 'src/map_io/map_object_packet.h'
584--- src/map_io/map_object_packet.h 2019-02-23 11:00:49 +0000
585+++ src/map_io/map_object_packet.h 2019-06-08 16:55:17 +0000
586@@ -57,7 +57,7 @@
587 EditorGameBase&,
588 MapObjectLoader&,
589 const WorldLegacyLookupTable& world_lookup_table,
590- const TribesLegacyLookupTable& tribe_lookup_table);
591+ const TribesLegacyLookupTable& tribes_lookup_table);
592
593 void load_finish();
594
595
596=== modified file 'src/map_io/map_players_view_packet.cc'
597--- src/map_io/map_players_view_packet.cc 2019-04-09 16:43:49 +0000
598+++ src/map_io/map_players_view_packet.cc 2019-06-08 16:55:17 +0000
599@@ -192,17 +192,17 @@
600 };
601
602 // reads an immovable depending on whether it is a tribe or world immovable
603-const ImmovableDescr& read_immovable_type(StreamRead* fr, const EditorGameBase& egbase) {
604+const ImmovableDescr& read_immovable_type(StreamRead* fr, const EditorGameBase& egbase, const TribesLegacyLookupTable& tribes_lookup_table, const WorldLegacyLookupTable& world_lookup_table) {
605 uint8_t owner = fr->unsigned_8();
606 char const* const name = fr->c_string();
607 if (owner == static_cast<uint8_t>(MapObjectDescr::OwnerType::kWorld)) {
608- DescriptionIndex const index = egbase.world().get_immovable_index(name);
609+ DescriptionIndex const index = egbase.world().get_immovable_index(world_lookup_table.lookup_immovable(name));
610 if (index == Widelands::INVALID_INDEX)
611 throw WorldImmovableNonexistent(name);
612 return *egbase.world().get_immovable_descr(index);
613 } else {
614 assert(owner == static_cast<uint8_t>(MapObjectDescr::OwnerType::kTribe));
615- DescriptionIndex const index = egbase.tribes().immovable_index(name);
616+ DescriptionIndex const index = egbase.tribes().immovable_index(tribes_lookup_table.lookup_immovable(name));
617 if (index == Widelands::INVALID_INDEX)
618 throw TribeImmovableNonexistent(name);
619 return *egbase.tribes().get_immovable_descr(index);
620@@ -238,7 +238,7 @@
621
622 inline static MapObjectData read_unseen_immovable(const EditorGameBase& egbase,
623 uint8_t& immovable_kind,
624- FileRead& immovables_file,
625+ FileRead& immovables_file, const TribesLegacyLookupTable& tribes_lookup_table, const WorldLegacyLookupTable& world_lookup_table,
626 uint8_t& version) {
627 MapObjectData m;
628 try {
629@@ -247,7 +247,7 @@
630 m.map_object_descr = nullptr;
631 break;
632 case UNSEEN_TRIBEORWORLD: // The player sees a tribe or world immovable.
633- m.map_object_descr = &read_immovable_type(&immovables_file, egbase);
634+ m.map_object_descr = &read_immovable_type(&immovables_file, egbase, tribes_lookup_table, world_lookup_table);
635 break;
636 case UNSEEN_FLAG: // The player sees a flag.
637 m.map_object_descr = &g_flag_descr;
638@@ -284,7 +284,7 @@
639 void MapPlayersViewPacket::read(FileSystem& fs,
640 EditorGameBase& egbase,
641 bool const skip,
642- MapObjectLoader&)
643+ MapObjectLoader&, const TribesLegacyLookupTable& tribes_lookup_table, const WorldLegacyLookupTable& world_lookup_table)
644
645 {
646 if (skip)
647@@ -559,7 +559,7 @@
648 kCurrentPacketVersionImmovableKinds);
649 }
650 MapObjectData mod = read_unseen_immovable(
651- egbase, imm_kind, node_immovables_file, node_immovables_file_version);
652+ egbase, imm_kind, node_immovables_file, tribes_lookup_table, world_lookup_table, node_immovables_file_version);
653 f_player_field.map_object_descr = mod.map_object_descr;
654 f_player_field.constructionsite = mod.csi;
655
656@@ -633,7 +633,7 @@
657 // TODO(sirver): Remove this logic the next time we break
658 // savegame compatibility.
659 read_unseen_immovable(
660- egbase, im_kind, triangle_immovables_file, triangle_immovables_file_version);
661+ egbase, im_kind, triangle_immovables_file, tribes_lookup_table, world_lookup_table, triangle_immovables_file_version);
662 }
663 if (f_seen | br_seen | r_seen) {
664 // The player currently sees the R triangle. Therefore his
665@@ -662,7 +662,7 @@
666 // suporting immovables on the triangles instead as on the
667 // nodes.
668 read_unseen_immovable(
669- egbase, im_kind, triangle_immovables_file, triangle_immovables_file_version);
670+ egbase, im_kind, triangle_immovables_file, tribes_lookup_table, world_lookup_table, triangle_immovables_file_version);
671 }
672
673 { // edges
674
675=== modified file 'src/map_io/map_players_view_packet.h'
676--- src/map_io/map_players_view_packet.h 2019-02-23 11:00:49 +0000
677+++ src/map_io/map_players_view_packet.h 2019-06-08 16:55:17 +0000
678@@ -21,6 +21,10 @@
679 #define WL_MAP_IO_MAP_PLAYERS_VIEW_PACKET_H
680
681 #include "map_io/map_data_packet.h"
682+#include "map_io/tribes_legacy_lookup_table.h"
683+#include "map_io/world_legacy_lookup_table.h"
684+
685+namespace Widelands {
686
687 /// For each player, its view of each node, edge and triangle that he has seen
688 /// but does not see currently. Information that he currently sees is not
689@@ -31,6 +35,11 @@
690 /// This information can not be loaded before the terrains, roads, immovables
691 /// and players' vision maps are loaded. The vision maps are completely loaded
692 /// after MapBobdataPacket has been loaded.
693-MAP_DATA_PACKET(MapPlayersViewPacket)
694+class MapPlayersViewPacket {
695+public:
696+ void read(FileSystem&, EditorGameBase&, bool, MapObjectLoader&, const TribesLegacyLookupTable& tribes_lookup_table, const WorldLegacyLookupTable& world_lookup_table);
697+ void write(FileSystem&, EditorGameBase&, MapObjectSaver&);
698+};
699+}
700
701 #endif // end of include guard: WL_MAP_IO_MAP_PLAYERS_VIEW_PACKET_H
702
703=== modified file 'src/map_io/map_roaddata_packet.cc'
704--- src/map_io/map_roaddata_packet.cc 2019-02-23 11:00:49 +0000
705+++ src/map_io/map_roaddata_packet.cc 2019-06-08 16:55:17 +0000
706@@ -44,7 +44,7 @@
707 void MapRoaddataPacket::read(FileSystem& fs,
708 EditorGameBase& egbase,
709 bool const skip,
710- MapObjectLoader& mol) {
711+ MapObjectLoader& mol, const TribesLegacyLookupTable& tribes_lookup_table) {
712 if (skip)
713 return;
714
715@@ -136,7 +136,7 @@
716 if (fr.unsigned_8()) {
717 (carrier_request =
718 new Request(road, 0, Road::request_carrier_callback, wwWORKER))
719- ->read(fr, game, mol);
720+ ->read(fr, game, mol, tribes_lookup_table);
721 } else {
722 carrier_request = nullptr;
723 }
724
725=== modified file 'src/map_io/map_roaddata_packet.h'
726--- src/map_io/map_roaddata_packet.h 2019-02-23 11:00:49 +0000
727+++ src/map_io/map_roaddata_packet.h 2019-06-08 16:55:17 +0000
728@@ -21,11 +21,18 @@
729 #define WL_MAP_IO_MAP_ROADDATA_PACKET_H
730
731 #include "map_io/map_data_packet.h"
732+#include "map_io/tribes_legacy_lookup_table.h"
733
734 /*
735 * This parses the roads data (where it is, where it belongs to
736 * and so on)
737 */
738-MAP_DATA_PACKET(MapRoaddataPacket)
739+namespace Widelands {
740+class MapRoaddataPacket {
741+public:
742+ void read(FileSystem&, EditorGameBase&, bool, MapObjectLoader&, const TribesLegacyLookupTable& tribes_lookup_table);
743+ void write(FileSystem&, EditorGameBase&, MapObjectSaver&);
744+};
745+}
746
747 #endif // end of include guard: WL_MAP_IO_MAP_ROADDATA_PACKET_H
748
749=== modified file 'src/map_io/tribes_legacy_lookup_table.cc'
750--- src/map_io/tribes_legacy_lookup_table.cc 2019-05-25 10:47:18 +0000
751+++ src/map_io/tribes_legacy_lookup_table.cc 2019-06-08 16:55:17 +0000
752@@ -18,6 +18,7 @@
753 */
754
755 #include "map_io/tribes_legacy_lookup_table.h"
756+
757 // Whenever we break savegame compatibility, we can empty these maps
758 TribesLegacyLookupTable::TribesLegacyLookupTable()
759 : // Workers
760@@ -36,7 +37,7 @@
761 {"reed_medium", "reedfield_medium"},
762 {"reed_small", "reedfield_small"},
763 {"reed_tiny", "reedfield_tiny"},
764- {"reed_tiny", "reedfield_ripe"},
765+ {"reed_ripe", "reedfield_ripe"},
766 } {
767 }
768
769
770=== modified file 'src/map_io/widelands_map_loader.cc'
771--- src/map_io/widelands_map_loader.cc 2019-03-09 10:01:09 +0000
772+++ src/map_io/widelands_map_loader.cc 2019-06-08 16:55:17 +0000
773@@ -152,7 +152,7 @@
774
775 std::unique_ptr<WorldLegacyLookupTable> world_lookup_table(
776 create_world_legacy_lookup_table(old_world_name_));
777- std::unique_ptr<TribesLegacyLookupTable> tribe_lookup_table(new TribesLegacyLookupTable());
778+ std::unique_ptr<TribesLegacyLookupTable> tribes_lookup_table(new TribesLegacyLookupTable());
779 log("Reading Terrain Data ... ");
780 {
781 MapTerrainPacket p;
782@@ -163,7 +163,7 @@
783 MapObjectPacket mapobjects;
784
785 log("Reading Map Objects ... ");
786- mapobjects.read(*fs_, egbase, *mol_, *world_lookup_table, *tribe_lookup_table);
787+ mapobjects.read(*fs_, egbase, *mol_, *world_lookup_table, *tribes_lookup_table);
788 log("took %ums\n ", timer.ms_since_last_query());
789
790 log("Reading Player Start Position Data ... ");
791@@ -259,21 +259,21 @@
792 log("Reading Flagdata Data ... ");
793 {
794 MapFlagdataPacket p;
795- p.read(*fs_, egbase, is_game, *mol_);
796+ p.read(*fs_, egbase, is_game, *mol_, *tribes_lookup_table);
797 }
798 log("took %ums\n ", timer.ms_since_last_query());
799
800 log("Reading Roaddata Data ... ");
801 {
802 MapRoaddataPacket p;
803- p.read(*fs_, egbase, is_game, *mol_);
804+ p.read(*fs_, egbase, is_game, *mol_, *tribes_lookup_table);
805 }
806 log("took %ums\n ", timer.ms_since_last_query());
807
808 log("Reading Buildingdata Data ... ");
809 {
810 MapBuildingdataPacket p;
811- p.read(*fs_, egbase, is_game, *mol_);
812+ p.read(*fs_, egbase, is_game, *mol_, *tribes_lookup_table);
813 }
814 log("took %ums\n ", timer.ms_since_last_query());
815
816@@ -297,7 +297,7 @@
817 log("Reading Players View Data ... ");
818 {
819 MapPlayersViewPacket p;
820- p.read(*fs_, egbase, is_game, *mol_);
821+ p.read(*fs_, egbase, is_game, *mol_, *tribes_lookup_table, *world_lookup_table);
822 }
823 log("took %ums\n ", timer.ms_since_last_query());
824

Subscribers

People subscribed via source and target branches

to status/vote changes: