Merge lp:~janosch-peters-deactivatedaccount/widelands/bugfix_1395238 into lp:widelands

Proposed by xxx-deleted
Status: Merged
Merged at revision: 7687
Proposed branch: lp:~janosch-peters-deactivatedaccount/widelands/bugfix_1395238
Merge into: lp:widelands
Diff against target: 183 lines (+37/-19)
4 files modified
src/logic/bob.cc (+8/-6)
src/logic/bob.h (+2/-1)
src/logic/soldier.cc (+22/-10)
src/logic/soldier.h (+5/-2)
To merge this branch: bzr merge lp:~janosch-peters-deactivatedaccount/widelands/bugfix_1395238
Reviewer Review Type Date Requested Status
GunChleoc Approve
SirVer Approve
Tino Approve
TiborB Approve
Review via email: mp+281402@code.launchpad.net

Description of the change

Fix for Bug #1395238: Soldiers now recognize when they are stuck. If they are, they walk along their path without honoring blocked nodes (e.g. they just walk through other soldiers).

This is also a fix for Bug #1522290 (as this bug is caused by #1395238).

To test this fix load the savegame attached in #1522290 and verify that the soldiers return home (they are not stuck anymore).

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

I couldn't test if this works, but the code seems OK. Just one code style nit: We are moving away from using defines and using constexpr instead. So, instead of

    #define BLOCK_COUNT_IS_STUCK 10

it would be better to use something like:

    constexpr int kBlockCountIsStuck = 10;

The type should match state.ivar3.

Revision history for this message
TiborB (tiborb95) wrote :

I tested it. I believe the problem is more frequent than it seems - I watched output in console. But generally I think it is good design. Unless there will be no complains in near time I would approve it.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Hi, I am bunnybot (https://github.com/widelands/bunnybot).

I am keeping the source branch lp:~janosch-peters/widelands/bugfix_1395238 mirrored to
  https://github.com/widelands/widelands/tree/_janosch_peters_widelands_bugfix_1395238

The latest continuous integration build can always be found here:
  https://travis-ci.org/widelands/widelands/branches
Please do not merge without making sure that it passes.

You can give me commands by starting a line with @bunnybot <command>. I understand:
 merge: Merges the source branch into the target branch, closing the pull request.

Revision history for this message
TiborB (tiborb95) wrote :

OK, I looked at it again and do think it can go

review: Approve
Revision history for this message
xxx-deleted (janosch-peters-deactivatedaccount) wrote :

1. Changed following defines to static constexpr:

#define SOLDIER_HP_BAR_WIDTH 13
#define BLOCK_COUNT_IS_STUCK 10

2. Removed unused function remove_spaces

Revision history for this message
Tino (tino79) wrote :

LGTM, nice work.

I would suggest to merge trunk, then we get a successful build on travis and we can merge it into trunk.

review: Approve
Revision history for this message
bunnybot (widelandsofficial) wrote :

Travis build 129 has changed state to: failed. Details: https://travis-ci.org/widelands/widelands/builds/99815629.

Revision history for this message
bunnybot (widelandsofficial) wrote :

Travis build 129 has changed state to: failed. Details: https://travis-ci.org/widelands/widelands/builds/99815629.

Revision history for this message
TiborB (tiborb95) wrote :

Why has this not been merged yet? And why travis fails - especially with error:

 error: ‘UBLOCK_ARABIC_MATHEMATICAL_ALPHABETIC_SYMBOLS’ is not a member of ‘UBlockCode’
    UBlockCode::UBLOCK_ARABIC_MATHEMATICAL_ALPHABETIC_SYMBOLS,

that is completely unrelated?

What now? Can we use that bunny stuff to automatically merge or do we (Janosh) need to merge trunk to get rid of compilation bug?

Revision history for this message
Tino (tino79) wrote :

Janosch has to merge trunk into his own branch, because trunk contains an updated .travis.yml.
This should fix building by travis.

When the travis build is ok, Janosch (or anyone) can issue the bunnybot command to merge to trunk.

Revision history for this message
xxx-deleted (janosch-peters-deactivatedaccount) wrote :

I allready did the merge ony my pc. However, I get an exception if I load the savegame I attached to the bug report. I dont think it has something to do with my changes, but I have to verify that. Ia m doing that right now.

Revision history for this message
Tino (tino79) wrote :

This only(!) applies to the fact that travis fails to build this branch:
The online branch lp:~janosch-peters/widelands/bugfix_1395238 does not contain recent trunk.
In particular this revision is missing: https://bazaar.launchpad.net/~widelands-dev/widelands/trunk/revision/7675

As soon you merge trunk and push your local branch to launchpad travis build will succeed.

This won't change the diff of your branch to trunk.

Revision history for this message
xxx-deleted (janosch-peters-deactivatedaccount) wrote :

I pushed a new revision where I merged trunk into. However, I get an exception because of a missing animation "crop" (for an imperial ranger) when I load the savegame attached to the bug report. I could not figure out what went wrong. I do not get an exception if I start a new game.

As I am pretty sure it has nothing to do with my changes, I pushed it anyway. It seems that some push one lp:widelands broke backwards-compatibility. It would be great if someone could look into that.

Revision history for this message
TiborB (tiborb95) wrote :

I think there was a change/renaming of actions from crop to plant lately somewhere. So you are probably right and this will be an broken savegame compatibility in trunk....

Revision history for this message
SirVer (sirver) wrote :

Yes, we are not caring about backwards compatibility between b18 and b19 - for the first time in Wideland's history. That allowed us to clean out some of the cruft we had in the code base. But that has bitten you here.

The code lgtm. I am a bit concerned that now many soldiers can rush through tight spots and overwhelm an opponent instead of going through one by one - that might attacks stronger. But if that is a real concern must be seen through in-game experience.

@bunnybot merge

review: Approve
Revision history for this message
TiborB (tiborb95) wrote :

> that might attacks stronger

By my understanding the exemption is used only for soldiers heading home....

Revision history for this message
bunnybot (widelandsofficial) wrote :

Travis build 177 has changed state to: passed. Details: https://travis-ci.org/widelands/widelands/builds/100087243.

Revision history for this message
GunChleoc (gunchleoc) wrote :

 error: ‘UBLOCK_ARABIC_MATHEMATICAL_ALPHABETIC_SYMBOLS’ is not a member of ‘UBlockCode’
    UBlockCode::UBLOCK_ARABIC_MATHEMATICAL_ALPHABETIC_SYMBOLS,

When you see this error, it means that the version of the ICU library is too old.

Revision history for this message
GunChleoc (gunchleoc) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/logic/bob.cc'
2--- src/logic/bob.cc 2015-12-05 10:59:02 +0000
3+++ src/logic/bob.cc 2016-01-04 10:23:26 +0000
4@@ -568,7 +568,8 @@
5 int32_t const persist,
6 const DirAnimations & anims,
7 bool const forceonlast,
8- int32_t const only_step)
9+ int32_t const only_step,
10+ bool const forceall)
11 {
12 Path path;
13 BlockedTracker tracker(game, *this, dest);
14@@ -580,6 +581,9 @@
15 cstep.add(CheckStepDefault(descr().movecaps()));
16 cstep.add(CheckStepBlocked(tracker));
17
18+ if (forceall)
19+ tracker.disabled = true;
20+
21 Map & map = game.map();
22 if (map.findpath(m_position, dest, persist, path, cstep) < 0) {
23 if (!tracker.nrblocked)
24@@ -600,7 +604,7 @@
25 State & state = top_state();
26 state.path = new Path(path);
27 state.ivar1 = 0; // step #
28- state.ivar2 = forceonlast ? 1 : 0;
29+ state.ivar2 = forceonlast ? 1 : (forceall ? 2 : 0);
30 state.ivar3 = only_step;
31 state.diranims = anims;
32 return true;
33@@ -676,7 +680,6 @@
34 return false;
35 }
36
37-
38 void Bob::movepath_update(Game & game, State & state)
39 {
40 if (get_signal().size()) {
41@@ -718,12 +721,11 @@
42 }
43
44 ++state.ivar1;
45- return start_task_move(game, dir, state.diranims, forcemove);
46+ return start_task_move(game, dir, state.diranims, state.ivar2 == 2 ? true : forcemove);
47 // Note: state pointer is invalid beyond this point
48 }
49
50-
51-/**
52+ /**
53 * Move into one direction for one step.
54 * \li ivar1: direction
55 * \li ivar2: non-zero if the move should be forced
56
57=== modified file 'src/logic/bob.h'
58--- src/logic/bob.h 2016-01-02 12:36:38 +0000
59+++ src/logic/bob.h 2016-01-04 10:23:26 +0000
60@@ -271,7 +271,8 @@
61 const int32_t persist,
62 const DirAnimations &,
63 const bool forceonlast = false,
64- const int32_t only_step = -1)
65+ const int32_t only_step = -1,
66+ const bool forceall = false)
67 __attribute__((warn_unused_result));
68
69 /// This can fail (and return false). Therefore the caller must check the
70
71=== modified file 'src/logic/soldier.cc'
72--- src/logic/soldier.cc 2015-12-30 23:07:55 +0000
73+++ src/logic/soldier.cc 2016-01-04 10:23:26 +0000
74@@ -514,7 +514,7 @@
75 {
76 // Gather information to determine coordinates
77 uint32_t w;
78- w = SOLDIER_HP_BAR_WIDTH;
79+ w = kSoldierHpBarWidth;
80
81 const Image* hppic = get_hp_level_pic();
82 const Image* attackpic = get_attack_level_pic();
83@@ -592,7 +592,7 @@
84 uint16_t evh = evadepic->height();
85
86 uint16_t animw;
87- animw = SOLDIER_HP_BAR_WIDTH;
88+ animw = kSoldierHpBarWidth;
89
90 w = std::max(std::max(atw + dew, hpw + evw), 2 * animw);
91 h = 5 + std::max(hph + ath, evh + deh);
92@@ -729,7 +729,8 @@
93 State & state = top_state();
94 state.objvar1 = &building;
95 state.coords = building.get_position();
96- state.ivar2 = 0; // Thre return state 1=go home 2=go back in known land
97+ state.ivar2 = 0; // The return state 1=go home 2=go back in known land
98+ state.ivar3 = 0; // Counts how often the soldier is blocked in a row
99
100 state.ivar1 |= CF_RETREAT_WHEN_INJURED;
101 state.ui32var3 = kRetreatWhenHealthDropsBelowThisPercentage * get_max_hitpoints() / 100;
102@@ -746,11 +747,15 @@
103 uint32_t defenders = 0;
104
105 if (signal.size()) {
106- if
107- (signal == "blocked" || signal == "battle" || signal == "wakeup" ||
108- signal == "sleep")
109- signal_handled();
110+ if (signal == "battle" || signal == "wakeup" || signal == "sleep") {
111+ state.ivar3 = 0;
112+ signal_handled();
113+ } else if (signal == "blocked") {
114+ state.ivar3++;
115+ signal_handled();
116+ }
117 else if (signal == "fail") {
118+ state.ivar3 = 0;
119 signal_handled();
120 if (state.objvar1.get(game)) {
121 molog("[attack] failed to reach enemy\n");
122@@ -761,6 +766,7 @@
123 }
124 } else if (signal == "location") {
125 molog("[attack] Location destroyed\n");
126+ state.ivar3 = 0;
127 signal_handled();
128 if (state.ivar2 == 0) {
129 state.ivar2 = 1;
130@@ -770,6 +776,9 @@
131 ("[attack] cancelled by unexpected signal '%s'\n", signal.c_str());
132 return pop_task(game);
133 }
134+ } else {
135+ // no signals means no consecutive block -> we're not stuck anymore
136+ state.ivar3 = 0;
137 }
138
139 // We are at enemy building flag, and a defender is coming, sleep until he
140@@ -810,12 +819,15 @@
141 return start_task_leavebuilding(game, false);
142 }
143 // Head to home
144- if
145- (start_task_movepath
146+ if (state.ivar3 > kBockCountIsStuck)
147+ molog("[attack] soldier is stuck, blocked nodes will be ignored\n");
148+
149+ if (start_task_movepath
150 (game,
151 baseflag.get_position(),
152 4, // use larger persist when returning home
153- descr().get_right_walk_anims(does_carry_ware())))
154+ descr().get_right_walk_anims(does_carry_ware()),
155+ false, -1, state.ivar3 > kBockCountIsStuck))
156 return;
157 else {
158 molog("[attack] failed to return home\n");
159
160=== modified file 'src/logic/soldier.h'
161--- src/logic/soldier.h 2015-11-25 08:42:28 +0000
162+++ src/logic/soldier.h 2016-01-04 10:23:26 +0000
163@@ -26,8 +26,6 @@
164 #include "logic/training_attribute.h"
165 #include "logic/worker.h"
166
167-#define SOLDIER_HP_BAR_WIDTH 13
168-
169 struct RGBColor;
170
171 namespace Widelands {
172@@ -287,6 +285,11 @@
173 */
174 Battle * m_battle;
175
176+ static constexpr uint8_t kSoldierHpBarWidth = 13;
177+
178+ /// Number of consecutive blocked signals until the soldiers are considered permanently stuck
179+ static constexpr uint8_t kBockCountIsStuck = 10;
180+
181 // saving and loading
182 protected:
183 struct Loader : public Worker::Loader {

Subscribers

People subscribed via source and target branches

to status/vote changes: