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

Proposed by TiborB
Status: Merged
Merged at revision: 7451
Proposed branch: lp:~widelands-dev/widelands/bug-978138
Merge into: lp:widelands
Diff against target: 45 lines (+27/-2)
1 file modified
src/logic/production_program.cc (+27/-2)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-978138
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+257005@code.launchpad.net

Description of the change

This is relatively simple fix. For every possible field where a ship could be built the game counts immovables within radius 2 and picks the spot with lowest count of immovables. Up to now the game flatly used first spot (though order of spots were quasi random)

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

LGTM :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/logic/production_program.cc'
2--- src/logic/production_program.cc 2015-01-30 23:10:35 +0000
3+++ src/logic/production_program.cc 2015-05-03 19:07:01 +0000
4@@ -1625,14 +1625,39 @@
5
6 // No object found, look for a field where we can build
7 std::vector<Coords> fields;
8+ Map & map = g.map();
9 FindNodeAnd fna;
10 fna.add(FindNodeShore());
11 fna.add(FindNodeImmovableSize(FindNodeImmovableSize::sizeNone));
12 if
13- (g.map().find_reachable_fields
14+ (map.find_reachable_fields
15 (area, &fields, cstep, fna))
16 {
17- state.coord = fields[0];
18+ //testing received fields to get one with less immovables
19+ //nearby
20+ Coords best_coords = fields.back(); //just to initialize it
21+ uint32_t best_score = std::numeric_limits<uint32_t>::max();
22+ while (!fields.empty()) {
23+ Coords coords = fields.back();
24+
25+ //counting immovables nearby
26+ std::vector<ImmovableFound> found_immovables;
27+ const uint32_t imm_count =
28+ map.find_immovables(Area<FCoords>(map.get_fcoords(coords), 2), &found_immovables);
29+ if (best_score > imm_count){
30+ best_score = imm_count;
31+ best_coords = coords;
32+ }
33+
34+ //no need to go on, it cannot be better
35+ if (imm_count == 0) {
36+ break;
37+ }
38+
39+ fields.pop_back();
40+ }
41+
42+ state.coord = best_coords;
43
44 psite.m_working_positions[0].worker->update_task_buildingwork(g);
45 return;

Subscribers

People subscribed via source and target branches

to status/vote changes: