Merge lp:~widelands-dev/widelands/find_portdock_reworked into lp:widelands

Proposed by TiborB
Status: Merged
Merged at revision: 7845
Proposed branch: lp:~widelands-dev/widelands/find_portdock_reworked
Merge into: lp:widelands
Diff against target: 66 lines (+31/-23)
1 file modified
src/logic/map.cc (+31/-23)
To merge this branch: bzr merge lp:~widelands-dev/widelands/find_portdock_reworked
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+286408@code.launchpad.net

Description of the change

This needs a discussion. Generally it works good enough, but I dont fully understand old logic. The code:
- returns portdock of size up to 2 (fields)
- makes sure all fields are valid
- but the problem (not invoked by this change) is when function returns 0 fields of portdock. The calling code is not ready for portdock of size 0. It crashes the game.

During my testing I had not run into such situation though...

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

Continuous integration builds have changed state:

Travis build 727. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/109980041.
Appveyor build 574. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_find_portdock_reworked-574.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Bunnybot encountered an error while working on this merge proposal:

Running 'bzr pull --overwrite' failed. Output:

Permission denied (publickey).
ConnectionReset reading response for 'BzrDir.open_2.1', retrying
Permission denied (publickey).
bzr: ERROR: Connection closed: Unexpected end of message. Please check connectivity and permissions, and report a bug if problems persist.
Using saved parent location: bzr+ssh://bazaar.launchpad.net/~widelands-dev/widelands/find_portdock_reworked/

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 727. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/109980041.
Appveyor build 574. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_find_portdock_reworked-574.

Revision history for this message
GunChleoc (gunchleoc) wrote :

LGTM :)

@bunnybot merge

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/logic/map.cc'
2--- src/logic/map.cc 2016-02-18 08:42:46 +0000
3+++ src/logic/map.cc 2016-02-20 12:53:00 +0000
4@@ -1340,31 +1340,39 @@
5 WALK_E, WALK_E, WALK_E
6 };
7 const FCoords start = br_n(br_n(get_fcoords(c)));
8- FCoords f[16];
9- bool iswater[16];
10- int firstwater = -1;
11- int lastnonwater = -1;
12- f[0] = start;
13+ const Widelands::PlayerNumber owner = start.field->get_owned_by();
14+ bool is_good_water;
15+ FCoords f = start;
16+ std::vector<Coords> portdock;
17 for (uint32_t i = 0; i < 16; ++i) {
18- iswater[i] = (f[i].field->get_caps() & (MOVECAPS_SWIM|MOVECAPS_WALK)) == MOVECAPS_SWIM;
19- if (iswater[i]) {
20- if (firstwater < 0)
21- firstwater = i;
22- } else {
23- lastnonwater = i;
24- }
25+ is_good_water = (f.field->get_caps() & (MOVECAPS_SWIM|MOVECAPS_WALK)) == MOVECAPS_SWIM;
26+
27+ // Any immovable here? (especially another portdock)
28+ if (is_good_water && f.field->get_immovable()) {
29+ is_good_water = false;
30+ }
31+
32+ // If starting point is owned we make sure this field has the same owner
33+ if (is_good_water && owner > 0 && f.field->get_owned_by() != owner) {
34+ is_good_water = false;
35+ }
36+
37+ // ... and is not on a border
38+ if (is_good_water && owner > 0 && f.field->is_border()) {
39+ is_good_water = false;
40+ }
41+
42+ if (is_good_water) {
43+ portdock.push_back(f);
44+ // Occupy 2 fields maximum in order not to block space for other ports that
45+ // might be built in the vicinity.
46+ if (portdock.size() == 2) {
47+ return portdock;
48+ }
49+ }
50+
51 if (i < 15)
52- f[i + 1] = get_neighbour(f[i], cycledirs[i]);
53- }
54-
55- std::vector<Coords> portdock;
56- if (firstwater >= 0) {
57- for (uint32_t i = firstwater; i < 16 && iswater[i]; ++i)
58- portdock.push_back(f[i]);
59- if (firstwater == 0 && lastnonwater >= 0) {
60- for (uint32_t i = lastnonwater + 1; i < 16; ++i)
61- portdock.push_back(f[i]);
62- }
63+ f = get_neighbour(f, cycledirs[i]);
64 }
65
66 return portdock;

Subscribers

People subscribed via source and target branches

to status/vote changes: