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

Proposed by TiborB
Status: Merged
Merged at revision: 7454
Proposed branch: lp:~widelands-dev/widelands/bug-1428396
Merge into: lp:widelands
Diff against target: 35 lines (+10/-5)
1 file modified
src/game_io/game_player_economies_packet.cc (+10/-5)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1428396
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+256857@code.launchpad.net

Description of the change

This fixes special situation, when two ships (both in expedition mode) of two players are on same field in the time of game saving.

See the also the bug report. A savefile attached to the bug is functional now and I run regression tests as well.

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

You found it :)

How about only writing the ships that the player owns as well? We still need the test when loading for older savegames, but not writing it in the first place would be a good idea I think.

Around line 137:

if (ship->get_economy() == temp_economy) {

We could have:

if (ship->get_economy() == temp_economy && ship->get_owner() == player) {

I also spotted a typo in a comment: curent -> current. It would also be good to have a blank space between // and We, makes it easier to read. :)

Revision history for this message
TiborB (tiborb95) wrote :

@GunChleoc

I was considering exactly this, but this is of no benefit because if economy of ship is the same as current economy (we are saving now) than it is obvious that the ship is ours.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Makes sense to me. Go ahead and merge :)

review: Approve
Revision history for this message
Hans Joachim Desserud (hjd) wrote :

Hi, just a post-review comment:

Please write more descriptive commit messages when merging to trunk. This makes it easier to tell what was changed, both when reading through the commit log, but also when someone wants to know why a block of code was added six months later.

Including the bug number is great, but it should say a bit more about how the code has changed from the previous commit (and depending on the situation something about the issue which was fixed.) The description you have at the beginning of this merge proposal is a good starting point.

As a hypothetical example; if you're looking up the history/changes of a piece of code you're working on; "Fixed bug 123" doesn't say a lot unless you remember all the bug numbers. You can of course look it up in a browser and skim through it, but then the next code line was added to fix another bug.

If it instead said "Ports now check if it has a ship available before starting expeditions. Used to attempt to load wares onto nothing and crashed. (Fixes bug 123)" it immediately gives you a context on why the code was added and what problem it solves. And when moving on to the next line, you can see that it was added to "Fixed warning. Doesn't need to assign value to unused variable".

Ideally, the commit log should tell a story about how the code has evolved over time.

Other than that, keep up the good work. :)

Revision history for this message
TiborB (tiborb95) wrote :

Oh, I did not realize that this might be important, I will be more elaborate next time

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_economies_packet.cc'
2--- src/game_io/game_player_economies_packet.cc 2014-09-20 09:37:47 +0000
3+++ src/game_io/game_player_economies_packet.cc 2015-05-04 18:24:59 +0000
4@@ -65,10 +65,15 @@
5 Bob* bob = map[read_map_index_32(&fr, max_index)].get_first_bob();
6 while (bob) {
7 if (upcast(Ship const, ship, bob)) {
8- assert(ship->get_economy());
9- EconomyDataPacket d(ship->get_economy());
10- d.read(fr);
11- read_this_economy = true;
12+
13+ // We are interested only in current player's ships
14+ if (ship->get_owner() == player) {
15+ assert(ship->get_economy());
16+ EconomyDataPacket d(ship->get_economy());
17+ d.read(fr);
18+ read_this_economy = true;
19+ break;
20+ }
21 }
22 bob = bob->get_next_bob();
23 }
24@@ -133,10 +138,10 @@
25 // TODO(sirver): the 0xffffffff is ugly and fragile.
26 fw.unsigned_32(0xffffffff); // Sentinel value.
27 fw.unsigned_32(field - &field_0);
28-
29 EconomyDataPacket d(ship->get_economy());
30 d.write(fw);
31 wrote_this_economy = true;
32+ break;
33 }
34 }
35 bob = bob->get_next_bob();

Subscribers

People subscribed via source and target branches

to status/vote changes: