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

Proposed by Nicolai Hähnle
Status: Merged
Merged at revision: 6511
Proposed branch: lp:~widelands-dev/widelands/bug995011
Merge into: lp:widelands
Diff against target: 101 lines (+34/-15)
3 files modified
src/logic/findimmovable.cc (+13/-1)
src/logic/findimmovable.h (+11/-4)
src/logic/player.cc (+10/-10)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug995011
Reviewer Review Type Date Requested Status
SirVer Approve
Review via email: mp+147776@code.launchpad.net

Description of the change

I'm going to be super-consistent about this now and just put up a merge proposal even for a small change like this. I'm curious how that plays out as a process?

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

:). I do not really know myself where to draw the line - it costs the reviewer very little to read a few lines but having the delay in the push process is sometimes annoying for the coder. I pushed some bug fixes yesterday also without reviews... so, I just don't know.

if (Building * building = flag->get_building()) -> I once was bitten by a refactoring bug which didn't handle assignements in if correctly Since them I prefer to split this out into two lines - just to be safe. Your call.
FindImmovable finder_; -> Can be const I think.
CheckStepWalkOn is now CheckStepDefault -> Can you elaborate? I think this changes the semantics of when you can attack, or not?

otherwise lgtm.

review: Approve
Revision history for this message
Nicolai Hähnle (nha) wrote :

Well, this time certainly helped make the code a little neater, if only in a small detail. And it might also encourage people to read each other's code more, which could increase the bus count ;-)

I am going to change the const thing.

As for the variable declaration + assignment in the if clause: I actually like this pattern because it neatly puts the scope exactly where it makes the most sense. Can you explain what went wrong with refactoring?

CheckStepWalkOn used to be necessary because the code searched for buildings. Fields with buildings don't have MOVECAPS_WALK, so the only way the old code could ever have found any buildings at all is by allowing a special case exception on the last step of the search. Now that the code searches for flags, which are walkable by definition, this is no longer necessary.

Now that I think about it, this might also fix some weirdness in those already buggy cases when a military sites seals a narrow passage off completely: The findAttackSoldiers code may have decided that an attack in northwestern direction is possible (because it searches from the attackees flag and hits one of the fields of the military sites that seals passage), but when the attack is launched, the soldiers would fail to find a way. The new code guarantees that there is a path for the soldiers to follow.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/logic/findimmovable.cc'
2--- src/logic/findimmovable.cc 2013-02-10 19:36:24 +0000
3+++ src/logic/findimmovable.cc 2013-02-12 10:17:23 +0000
4@@ -1,5 +1,5 @@
5 /*
6- * Copyright (C) 2008-2009 by the Widelands Development Team
7+ * Copyright (C) 2008-2013 by the Widelands Development Team
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11@@ -24,6 +24,8 @@
12 #include "militarysite.h"
13 #include "upcast.h"
14
15+#include "economy/flag.h"
16+
17 namespace Widelands {
18
19 struct FindImmovableAlwaysTrueImpl {
20@@ -71,4 +73,14 @@
21 return false;
22 }
23
24+bool FindFlagOf::accept(const BaseImmovable & baseimm) const {
25+ if (upcast(const Flag, flag, &baseimm)) {
26+ if (Building * building = flag->get_building()) {
27+ if (finder_.accept(*building))
28+ return true;
29+ }
30+ }
31+ return false;
32 }
33+
34+} // namespace Widelands
35
36=== modified file 'src/logic/findimmovable.h'
37--- src/logic/findimmovable.h 2013-02-10 19:36:24 +0000
38+++ src/logic/findimmovable.h 2013-02-12 10:17:23 +0000
39@@ -1,5 +1,5 @@
40 /*
41- * Copyright (C) 2008-2009 by the Widelands Development Team
42+ * Copyright (C) 2008-2013 by the Widelands Development Team
43 *
44 * This program is free software; you can redistribute it and/or
45 * modify it under the terms of the GNU General Public License
46@@ -131,8 +131,15 @@
47
48 const Immovable_Descr & descr;
49 };
50-
51-
52-}
53+struct FindFlagOf {
54+ FindFlagOf(const FindImmovable & finder) : finder_(finder) {}
55+
56+ bool accept(const BaseImmovable &) const;
57+
58+ const FindImmovable finder_;
59+};
60+
61+
62+} // namespace Widelands
63
64 #endif
65
66=== modified file 'src/logic/player.cc'
67--- src/logic/player.cc 2013-02-10 19:36:24 +0000
68+++ src/logic/player.cc 2013-02-12 10:17:23 +0000
69@@ -797,22 +797,22 @@
70 soldiers->clear();
71
72 Map & map = egbase().map();
73- std::vector<BaseImmovable *> immovables;
74+ std::vector<BaseImmovable *> flags;
75
76 map.find_reachable_immovables_unique
77 (Area<FCoords>(map.get_fcoords(flag.get_position()), 25),
78- immovables,
79- CheckStepWalkOn(MOVECAPS_WALK, false),
80- FindImmovablePlayerMilitarySite(*this));
81+ flags,
82+ CheckStepDefault(MOVECAPS_WALK),
83+ FindFlagOf(FindImmovablePlayerMilitarySite(*this)));
84
85- if (immovables.empty())
86+ if (flags.empty())
87 return 0;
88
89- container_iterate_const(std::vector<BaseImmovable *>, immovables, i) {
90- const MilitarySite & ms =
91- ref_cast<MilitarySite, BaseImmovable>(**i.current);
92- std::vector<Soldier *> const present = ms.presentSoldiers();
93- uint32_t const nr_staying = ms.minSoldierCapacity();
94+ container_iterate_const(std::vector<BaseImmovable *>, flags, i) {
95+ const Flag * attackerflag = static_cast<Flag *>(*i.current);
96+ const MilitarySite * ms = static_cast<MilitarySite *>(attackerflag->get_building());
97+ std::vector<Soldier *> const present = ms->presentSoldiers();
98+ uint32_t const nr_staying = ms->minSoldierCapacity();
99 uint32_t const nr_present = present.size();
100 if (nr_staying < nr_present) {
101 uint32_t const nr_taken =

Subscribers

People subscribed via source and target branches

to status/vote changes: