Merge lp:~aber/widelands/bug984110 into lp:widelands

Proposed by David Allwicher
Status: Merged
Merged at revision: 6362
Proposed branch: lp:~aber/widelands/bug984110
Merge into: lp:widelands
Diff against target: 59 lines (+16/-12)
1 file modified
src/ai/defaultai.cc (+16/-12)
To merge this branch: bzr merge lp:~aber/widelands/bug984110
Reviewer Review Type Date Requested Status
Widelands Developers Pending
Review via email: mp+103729@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/ai/defaultai.cc'
2--- src/ai/defaultai.cc 2012-04-04 14:06:44 +0000
3+++ src/ai/defaultai.cc 2012-04-26 16:23:01 +0000
4@@ -1412,7 +1412,7 @@
5 }
6
7
8-/// connects a specific flag to another economy
9+// connects a specific flag to another economy
10 bool DefaultAI::connect_flag_to_another_economy (const Flag & flag)
11 {
12 FindNodeWithFlagOrRoad functor;
13@@ -1431,20 +1431,22 @@
14 return false;
15
16 // then choose the one with the shortest path
17- Path & path = *new Path();;
18+ Path * path = new Path();
19 bool found = false;
20 check.set_openend(false);
21 Coords closest;
22 container_iterate_const(std::vector<Coords>, reachable, i) {
23- Path & path2 = *new Path();
24- if (map.findpath(flag.get_position(), *i.current, 0, path2, check) < 0)
25- continue;
26-
27- if (!found || path.get_nsteps() > path2.get_nsteps()) {
28- path = path2;
29- closest = *i.current;
30- found = true;
31+ Path * path2 = new Path();
32+ if (map.findpath(flag.get_position(), *i.current, 0, *path2, check) >= 0) {
33+ if (!found || path->get_nsteps() > path2->get_nsteps()) {
34+ delete path;
35+ path = path2;
36+ path2 = NULL;
37+ closest = *i.current;
38+ found = true;
39+ }
40 }
41+ delete path2;
42 }
43
44 if (found) {
45@@ -1453,10 +1455,12 @@
46 game().send_player_build_flag(player_number(), closest);
47
48 // and finally build the road
49- game().send_player_build_road(player_number(), path);
50+ game().send_player_build_road(player_number(), *path);
51 return true;
52+ } else {
53+ delete path;
54+ return false;
55 }
56- return false;
57 }
58
59 /// adds alternative ways to already existing ones

Subscribers

People subscribed via source and target branches

to status/vote changes: