Merge lp:~widelands-dev/widelands/bug-1734199 into lp:widelands

Proposed by TiborB
Status: Merged
Merged at revision: 8516
Proposed branch: lp:~widelands-dev/widelands/bug-1734199
Merge into: lp:widelands
Diff against target: 57 lines (+17/-6)
1 file modified
src/game_io/game_player_ai_persistent_packet.cc (+17/-6)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1734199
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+334369@code.launchpad.net

Description of the change

Buildings in remaining_basic_buildings are now stored as strings.

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

Code LGTM, not tested. It would be even better though to reinitialize the remaining buildings when the old packet version is used, because we can't trust the numbers. I leave it up to you if you wish to change that though.

review: Approve
Revision history for this message
TiborB (tiborb95) wrote :

It is a big question. Usually buildings by index are fine. And alternative is to make the set empty, and this would indicate that basic economy was achieved and it might not be yet, and it would confuse AI.

So I personally prefer just to trust the indexes as it is done now...

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 2876. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/308392427.
Appveyor build 2685. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1734199-2685.

Revision history for this message
GunChleoc (gunchleoc) wrote :

After a game has been started, using the indexes is good, because it's more efficient. During game startup, those indexes are automatically generated from names. Configuration looks like this:

    tribes:new_militarysite_type {
       name = "atlanteans_guardhall",
       descname = pgettext("atlanteans_building", "Guardhall"),

       ....
    }

This is loaded before the savegame is loaded.

So, the configurations doesn't know anything about indexes at all. Configuring it like this instead:

    tribes:new_militarysite_type {
       id = 42,
       descname = pgettext("atlanteans_building", "Guardhall"),

       ....
    }

Would not be manageable for humans.

So, whenever we add a new building type, or change the order in which we load them, using indexes during saveloading will break.

@bunnybot merge

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/game_io/game_player_ai_persistent_packet.cc'
2--- src/game_io/game_player_ai_persistent_packet.cc 2017-11-20 07:54:19 +0000
3+++ src/game_io/game_player_ai_persistent_packet.cc 2017-11-28 11:00:28 +0000
4@@ -29,7 +29,9 @@
5 namespace Widelands {
6
7 // Introduction of genetic algorithm with all structures that are needed for it
8-constexpr uint16_t kCurrentPacketVersion = 3;
9+constexpr uint16_t kCurrentPacketVersion = 4;
10+// First version with genetics
11+constexpr uint16_t kPacketVersion3 = 3;
12 // Old Version before using genetics
13 constexpr uint16_t kPacketVersion2 = 2;
14
15@@ -66,7 +68,7 @@
16 // Make the AI initialize itself
17 player->ai_data.initialized = 0;
18 } else {
19- // kCurrentPacketVersion
20+ // Contains Genetic algorithm data
21 player->ai_data.initialized = (fr.unsigned_8() == 1) ? true : false;
22 player->ai_data.colony_scan_area = fr.unsigned_32();
23 player->ai_data.trees_around_cutters = fr.unsigned_32();
24@@ -131,8 +133,16 @@
25
26 size_t remaining_basic_buildings_size = fr.unsigned_32();
27 for (uint16_t i = 0; i < remaining_basic_buildings_size; ++i) {
28- player->ai_data.remaining_basic_buildings.emplace(
29- static_cast<Widelands::DescriptionIndex>(fr.unsigned_32()), fr.unsigned_32());
30+ if (packet_version == kPacketVersion3) { // Old genetics (buildings saved as idx)
31+ player->ai_data.remaining_basic_buildings.emplace(
32+ static_cast<Widelands::DescriptionIndex>(fr.unsigned_32()),
33+ fr.unsigned_32());
34+ } else { // New genetics (buildings saved as strigs)
35+ const std::string building_string = fr.string();
36+ const Widelands::DescriptionIndex bld_idx =
37+ player->tribe().building_index(building_string);
38+ player->ai_data.remaining_basic_buildings.emplace(bld_idx, fr.unsigned_32());
39+ }
40 }
41 // Basic sanity check for remaining basic buildings
42 assert(player->ai_data.remaining_basic_buildings.size() <
43@@ -203,11 +213,12 @@
44 // Remaining buildings for basic economy
45 fw.unsigned_32(player->ai_data.remaining_basic_buildings.size());
46 for (auto bb : player->ai_data.remaining_basic_buildings) {
47- fw.unsigned_32(bb.first);
48+ const std::string bld_name = game.tribes().get_building_descr(bb.first)->name().c_str();
49+ fw.string(bld_name);
50 fw.unsigned_32(bb.second);
51 }
52 }
53
54 fw.write(fs, "binary/player_ai");
55 }
56-}
57+} // namespace Widelands

Subscribers

People subscribed via source and target branches

to status/vote changes: