Merge lp:~majcherlk/widelands/seafaring-check into lp:widelands

Proposed by Lukasz
Status: Merged
Merged at revision: 7490
Proposed branch: lp:~majcherlk/widelands/seafaring-check
Merge into: lp:widelands
Diff against target: 124 lines (+70/-1)
3 files modified
src/editor/ui_menus/editor_main_menu_save_map.cc (+7/-0)
src/logic/map.cc (+60/-0)
src/logic/map.h (+3/-1)
To merge this branch: bzr merge lp:~majcherlk/widelands/seafaring-check
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+263192@code.launchpad.net

Description of the change

Now according to suggestion #1449420 seafaring tag is calculated automatically (tag is set only when map has at least 2 port spaces) and I have question: I was trying to remove seafaring checkbox but I couldn't find it in code, it exists?

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

I changed a way of testing whether the map is seafaring (two port spaces constraint is not enough strong - we can have two port spaces incident to two different water tanks and a seafaring is still impossible). Now tag is set when there are at least two port spaces that are reachable to each other.

Revision history for this message
GunChleoc (gunchleoc) wrote :

I have recently done the same in a branch that isn't quite ready yet: http://bazaar.launchpad.net/~widelands-dev/widelands/bug-1390793/revision/7415

Your function is a lot better. I have delete_tag instead of remove_tag, which has an additional check in it:

void Map::delete_tag(const std::string& tag) {
       if (has_tag(tag)) {
               m_tags.erase(m_tags.find(tag));
        }
}

I have also added some diff comments.

Revision history for this message
Lukasz (majcherlk) :
Revision history for this message
GunChleoc (gunchleoc) :
Revision history for this message
Lukasz (majcherlk) wrote :

I've made some changes according to your suggestions.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks - I will merge this now :)

review: Approve
Revision history for this message
SirVer (sirver) wrote :

Thanks Lukasz! Great addition!

I added you to ~widelands-dev. Could you push your branches in the future to ~widelands-dev/widelands/<branch name> so that collaboration becomes easier? Others can add commits to this branch then too.

Also, feel free to pick up other peoples merge request and look through them. Ideally every contributor also reviews code - it is the best way to spread knowledge and establish a consistent style in the code base.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/editor/ui_menus/editor_main_menu_save_map.cc'
2--- src/editor/ui_menus/editor_main_menu_save_map.cc 2015-01-27 20:43:52 +0000
3+++ src/editor/ui_menus/editor_main_menu_save_map.cc 2015-07-25 21:18:13 +0000
4@@ -188,6 +188,13 @@
5 filename.substr(0, filename_size - 4) : filename)
6 .c_str());
7 }
8+
9+ // check if map has at least two port spaces that are reachable for each other
10+ if (map.allows_seafaring())
11+ map.add_tag("seafaring");
12+ else
13+ map.delete_tag("seafaring");
14+
15 if
16 (save_map
17 (filename,
18
19=== modified file 'src/logic/map.cc'
20--- src/logic/map.cc 2015-02-24 13:51:38 +0000
21+++ src/logic/map.cc 2015-07-25 21:18:13 +0000
22@@ -580,6 +580,12 @@
23 m_tags.insert(tag);
24 }
25
26+void Map::delete_tag(const std::string& tag) {
27+ if (has_tag(tag)) {
28+ m_tags.erase(m_tags.find(tag));
29+ }
30+}
31+
32 NodeCaps Map::get_max_nodecaps(const World& world, FCoords & fc) {
33 NodeCaps caps = _calc_nodecaps_pass1(world, fc, false);
34 caps = _calc_nodecaps_pass2(world, fc, false, caps);
35@@ -1991,6 +1997,60 @@
36 check_neighbour_heights(n[i], area);
37 }
38
39+/*
40+===========
41+Map::allows_seafaring()
42+
43+This function checks if there are two ports that are reachable
44+for each other - then the map is seafaring.
45+=============
46+*/
47+bool Map::allows_seafaring() {
48+ Map::PortSpacesSet port_spaces = get_port_spaces();
49+ std::vector<Coords> portdocks;
50+ std::set<Coords, Coords::OrderingFunctor> swim_coords;
51+
52+ for (const Coords& c : port_spaces) {
53+ std::queue<Coords> q_positions;
54+ std::set<Coords, Coords::OrderingFunctor> visited_positions;
55+ FCoords fc = get_fcoords(c);
56+ portdocks = find_portdock(fc);
57+
58+ /* remove the port space if it is not longer valid port space */
59+ if ((fc.field->get_caps() & BUILDCAPS_SIZEMASK) != BUILDCAPS_BIG || portdocks.empty()) {
60+ set_port_space(c, false);
61+ continue;
62+ }
63+
64+ for (const Coords& portdock: portdocks) {
65+ visited_positions.insert(portdock);
66+ q_positions.push(portdock);
67+ }
68+
69+ while (!q_positions.empty()) {
70+ const Coords& swim_coord = q_positions.front();
71+ q_positions.pop();
72+ for (uint8_t i = 1; i <= 6; ++i) {
73+ FCoords neighbour;
74+ get_neighbour(get_fcoords(swim_coord), i, &neighbour);
75+ if ((neighbour.field->get_caps() & (MOVECAPS_SWIM | MOVECAPS_WALK)) == MOVECAPS_SWIM) {
76+ if (visited_positions.count(neighbour) == 0) {
77+ visited_positions.insert(neighbour);
78+ q_positions.push(neighbour);
79+ }
80+ }
81+ }
82+ }
83+
84+ for (const Coords& swim_coord: visited_positions)
85+ if (swim_coords.count(swim_coord) == 0)
86+ swim_coords.insert(swim_coord);
87+ else
88+ return true;
89+ }
90+ return false;
91+}
92+
93
94 #define MAX_RADIUS 32
95 MilitaryInfluence Map::calc_influence
96
97=== modified file 'src/logic/map.h'
98--- src/logic/map.h 2015-06-10 06:46:40 +0000
99+++ src/logic/map.h 2015-07-25 21:18:13 +0000
100@@ -200,6 +200,7 @@
101 void set_hint (const std::string& hint);
102 void set_background (const std::string& image_path);
103 void add_tag (const std::string& tag);
104+ void delete_tag (const std::string& tag);
105 void set_scenario_types(ScenarioTypes t) {m_scenario_types = t;}
106
107 // Allows access to the filesystem of the map to access auxiliary files.
108@@ -216,7 +217,7 @@
109
110 using Tags = std::set<std::string>;
111 const Tags & get_tags() const {return m_tags;}
112- bool has_tag(std::string & s) const {return m_tags.count(s);}
113+ bool has_tag(const std::string & s) const {return m_tags.count(s);}
114
115 const std::vector<SuggestedTeamLineup>& get_suggested_teams() const {return m_suggested_teams;}
116
117@@ -387,6 +388,7 @@
118 void set_port_space(Coords c, bool allowed);
119 const PortSpacesSet& get_port_spaces() {return m_port_spaces;}
120 std::vector<Coords> find_portdock(const Widelands::Coords& c) const;
121+ bool allows_seafaring();
122
123 protected: /// These functions are needed in Testclasses
124 void set_size(uint32_t w, uint32_t h);

Subscribers

People subscribed via source and target branches

to status/vote changes: