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
=== modified file 'src/logic/bob.cc'
--- src/logic/bob.cc 2015-12-05 10:59:02 +0000
+++ src/logic/bob.cc 2016-01-04 10:23:26 +0000
@@ -568,7 +568,8 @@
568 int32_t const persist,568 int32_t const persist,
569 const DirAnimations & anims,569 const DirAnimations & anims,
570 bool const forceonlast,570 bool const forceonlast,
571 int32_t const only_step)571 int32_t const only_step,
572 bool const forceall)
572{573{
573 Path path;574 Path path;
574 BlockedTracker tracker(game, *this, dest);575 BlockedTracker tracker(game, *this, dest);
@@ -580,6 +581,9 @@
580 cstep.add(CheckStepDefault(descr().movecaps()));581 cstep.add(CheckStepDefault(descr().movecaps()));
581 cstep.add(CheckStepBlocked(tracker));582 cstep.add(CheckStepBlocked(tracker));
582583
584 if (forceall)
585 tracker.disabled = true;
586
583 Map & map = game.map();587 Map & map = game.map();
584 if (map.findpath(m_position, dest, persist, path, cstep) < 0) {588 if (map.findpath(m_position, dest, persist, path, cstep) < 0) {
585 if (!tracker.nrblocked)589 if (!tracker.nrblocked)
@@ -600,7 +604,7 @@
600 State & state = top_state();604 State & state = top_state();
601 state.path = new Path(path);605 state.path = new Path(path);
602 state.ivar1 = 0; // step #606 state.ivar1 = 0; // step #
603 state.ivar2 = forceonlast ? 1 : 0;607 state.ivar2 = forceonlast ? 1 : (forceall ? 2 : 0);
604 state.ivar3 = only_step;608 state.ivar3 = only_step;
605 state.diranims = anims;609 state.diranims = anims;
606 return true;610 return true;
@@ -676,7 +680,6 @@
676 return false;680 return false;
677}681}
678682
679
680void Bob::movepath_update(Game & game, State & state)683void Bob::movepath_update(Game & game, State & state)
681{684{
682 if (get_signal().size()) {685 if (get_signal().size()) {
@@ -718,12 +721,11 @@
718 }721 }
719722
720 ++state.ivar1;723 ++state.ivar1;
721 return start_task_move(game, dir, state.diranims, forcemove);724 return start_task_move(game, dir, state.diranims, state.ivar2 == 2 ? true : forcemove);
722 // Note: state pointer is invalid beyond this point725 // Note: state pointer is invalid beyond this point
723}726}
724727
725728 /**
726/**
727 * Move into one direction for one step.729 * Move into one direction for one step.
728 * \li ivar1: direction730 * \li ivar1: direction
729 * \li ivar2: non-zero if the move should be forced731 * \li ivar2: non-zero if the move should be forced
730732
=== modified file 'src/logic/bob.h'
--- src/logic/bob.h 2016-01-02 12:36:38 +0000
+++ src/logic/bob.h 2016-01-04 10:23:26 +0000
@@ -271,7 +271,8 @@
271 const int32_t persist,271 const int32_t persist,
272 const DirAnimations &,272 const DirAnimations &,
273 const bool forceonlast = false,273 const bool forceonlast = false,
274 const int32_t only_step = -1)274 const int32_t only_step = -1,
275 const bool forceall = false)
275 __attribute__((warn_unused_result));276 __attribute__((warn_unused_result));
276277
277 /// This can fail (and return false). Therefore the caller must check the278 /// This can fail (and return false). Therefore the caller must check the
278279
=== modified file 'src/logic/soldier.cc'
--- src/logic/soldier.cc 2015-12-30 23:07:55 +0000
+++ src/logic/soldier.cc 2016-01-04 10:23:26 +0000
@@ -514,7 +514,7 @@
514{514{
515 // Gather information to determine coordinates515 // Gather information to determine coordinates
516 uint32_t w;516 uint32_t w;
517 w = SOLDIER_HP_BAR_WIDTH;517 w = kSoldierHpBarWidth;
518518
519 const Image* hppic = get_hp_level_pic();519 const Image* hppic = get_hp_level_pic();
520 const Image* attackpic = get_attack_level_pic();520 const Image* attackpic = get_attack_level_pic();
@@ -592,7 +592,7 @@
592 uint16_t evh = evadepic->height();592 uint16_t evh = evadepic->height();
593593
594 uint16_t animw;594 uint16_t animw;
595 animw = SOLDIER_HP_BAR_WIDTH;595 animw = kSoldierHpBarWidth;
596596
597 w = std::max(std::max(atw + dew, hpw + evw), 2 * animw);597 w = std::max(std::max(atw + dew, hpw + evw), 2 * animw);
598 h = 5 + std::max(hph + ath, evh + deh);598 h = 5 + std::max(hph + ath, evh + deh);
@@ -729,7 +729,8 @@
729 State & state = top_state();729 State & state = top_state();
730 state.objvar1 = &building;730 state.objvar1 = &building;
731 state.coords = building.get_position();731 state.coords = building.get_position();
732 state.ivar2 = 0; // Thre return state 1=go home 2=go back in known land732 state.ivar2 = 0; // The return state 1=go home 2=go back in known land
733 state.ivar3 = 0; // Counts how often the soldier is blocked in a row
733734
734 state.ivar1 |= CF_RETREAT_WHEN_INJURED;735 state.ivar1 |= CF_RETREAT_WHEN_INJURED;
735 state.ui32var3 = kRetreatWhenHealthDropsBelowThisPercentage * get_max_hitpoints() / 100;736 state.ui32var3 = kRetreatWhenHealthDropsBelowThisPercentage * get_max_hitpoints() / 100;
@@ -746,11 +747,15 @@
746 uint32_t defenders = 0;747 uint32_t defenders = 0;
747748
748 if (signal.size()) {749 if (signal.size()) {
749 if750 if (signal == "battle" || signal == "wakeup" || signal == "sleep") {
750 (signal == "blocked" || signal == "battle" || signal == "wakeup" ||751 state.ivar3 = 0;
751 signal == "sleep")752 signal_handled();
752 signal_handled();753 } else if (signal == "blocked") {
754 state.ivar3++;
755 signal_handled();
756 }
753 else if (signal == "fail") {757 else if (signal == "fail") {
758 state.ivar3 = 0;
754 signal_handled();759 signal_handled();
755 if (state.objvar1.get(game)) {760 if (state.objvar1.get(game)) {
756 molog("[attack] failed to reach enemy\n");761 molog("[attack] failed to reach enemy\n");
@@ -761,6 +766,7 @@
761 }766 }
762 } else if (signal == "location") {767 } else if (signal == "location") {
763 molog("[attack] Location destroyed\n");768 molog("[attack] Location destroyed\n");
769 state.ivar3 = 0;
764 signal_handled();770 signal_handled();
765 if (state.ivar2 == 0) {771 if (state.ivar2 == 0) {
766 state.ivar2 = 1;772 state.ivar2 = 1;
@@ -770,6 +776,9 @@
770 ("[attack] cancelled by unexpected signal '%s'\n", signal.c_str());776 ("[attack] cancelled by unexpected signal '%s'\n", signal.c_str());
771 return pop_task(game);777 return pop_task(game);
772 }778 }
779 } else {
780 // no signals means no consecutive block -> we're not stuck anymore
781 state.ivar3 = 0;
773 }782 }
774783
775 // We are at enemy building flag, and a defender is coming, sleep until he784 // We are at enemy building flag, and a defender is coming, sleep until he
@@ -810,12 +819,15 @@
810 return start_task_leavebuilding(game, false);819 return start_task_leavebuilding(game, false);
811 }820 }
812 // Head to home821 // Head to home
813 if822 if (state.ivar3 > kBockCountIsStuck)
814 (start_task_movepath823 molog("[attack] soldier is stuck, blocked nodes will be ignored\n");
824
825 if (start_task_movepath
815 (game,826 (game,
816 baseflag.get_position(),827 baseflag.get_position(),
817 4, // use larger persist when returning home828 4, // use larger persist when returning home
818 descr().get_right_walk_anims(does_carry_ware())))829 descr().get_right_walk_anims(does_carry_ware()),
830 false, -1, state.ivar3 > kBockCountIsStuck))
819 return;831 return;
820 else {832 else {
821 molog("[attack] failed to return home\n");833 molog("[attack] failed to return home\n");
822834
=== modified file 'src/logic/soldier.h'
--- src/logic/soldier.h 2015-11-25 08:42:28 +0000
+++ src/logic/soldier.h 2016-01-04 10:23:26 +0000
@@ -26,8 +26,6 @@
26#include "logic/training_attribute.h"26#include "logic/training_attribute.h"
27#include "logic/worker.h"27#include "logic/worker.h"
2828
29#define SOLDIER_HP_BAR_WIDTH 13
30
31struct RGBColor;29struct RGBColor;
3230
33namespace Widelands {31namespace Widelands {
@@ -287,6 +285,11 @@
287 */285 */
288 Battle * m_battle;286 Battle * m_battle;
289287
288 static constexpr uint8_t kSoldierHpBarWidth = 13;
289
290 /// Number of consecutive blocked signals until the soldiers are considered permanently stuck
291 static constexpr uint8_t kBockCountIsStuck = 10;
292
290 // saving and loading293 // saving and loading
291protected:294protected:
292 struct Loader : public Worker::Loader {295 struct Loader : public Worker::Loader {

Subscribers

People subscribed via source and target branches

to status/vote changes: