Merge lp:~widelands-dev/widelands/bug-1817664-overlooping-eva_fail into lp:widelands

Proposed by Benedikt Straub
Status: Merged
Merged at revision: 8995
Proposed branch: lp:~widelands-dev/widelands/bug-1817664-overlooping-eva_fail
Merge into: lp:widelands
Diff against target: 119 lines (+41/-5)
3 files modified
src/logic/map_objects/tribes/battle.cc (+19/-4)
src/logic/map_objects/tribes/battle.h (+2/-0)
src/logic/map_objects/tribes/soldier.cc (+20/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug-1817664-overlooping-eva_fail
Reviewer Review Type Date Requested Status
GunChleoc Approve
Review via email: mp+363679@code.launchpad.net

Commit message

Shorten a soldier's last evade_failure animation if the soldier is about to die to prevent overlooping. The health bar falls gradually during an attack instead of one-shot.

Description of the change

During battles, the evade_failure animation may overloop. If the soldier dies immediately afterwards, this can look like he is attacking while he dies (especially noticeable with ATL vs FRI). Shorten the last eva_fail anim if the soldier is going to die.

Debugging this, I also implemented that the soldierĀ“s health bar falls gradually while he is being attacked, instead of one-shot half a second after the attack is visually over.

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

Continuous integration builds have changed state:

Travis build 4530. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/498892692.
Appveyor build 4317. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1817664_overlooping_eva_fail-4317.

8996. By GunChleoc

Some code style tweaks.

Revision history for this message
GunChleoc (gunchleoc) wrote :

LGTM - thanks for the fix :)

I have pushed some small code style tweaks - have a look at them if you want.

@bunnybot merge

review: Approve
Revision history for this message
hessenfarmer (stephan-lutz) wrote :

travis fails due to sphinx not happy.

should be fixed after merging trunk

Revision history for this message
bunnybot (widelandsofficial) wrote :

Refusing to merge, since Travis is not green. Use @bunnybot merge force for merging anyways.

Travis build 4531. State: failed. Details: https://travis-ci.org/widelands/widelands/builds/499122948.

8997. By Nordfriese

Merged trunk

Revision history for this message
Benedikt Straub (nordfriese) wrote :

Merged trunk

@bunnybot merge

Revision history for this message
bunnybot (widelandsofficial) wrote :

Continuous integration builds have changed state:

Travis build 4533. State: passed. Details: https://travis-ci.org/widelands/widelands/builds/499220518.
Appveyor build 4320. State: success. Details: https://ci.appveyor.com/project/widelands-dev/widelands/build/_widelands_dev_widelands_bug_1817664_overlooping_eva_fail-4320.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/logic/map_objects/tribes/battle.cc'
2--- src/logic/map_objects/tribes/battle.cc 2019-02-23 11:00:49 +0000
3+++ src/logic/map_objects/tribes/battle.cc 2019-02-27 10:46:34 +0000
4@@ -137,6 +137,13 @@
5 return other_soldier;
6 }
7
8+unsigned int Battle::get_pending_damage(const Soldier* for_whom) const {
9+ if (for_whom == (first_strikes_ ? first_ : second_)) {
10+ return damage_;
11+ }
12+ return 0;
13+}
14+
15 // TODO(unknown): Couldn't this code be simplified tremendously by doing all scheduling
16 // for one soldier and letting the other sleep until the battle is over?
17 // Could be, but we need to be able change the animations of the soldiers
18@@ -167,10 +174,11 @@
19 // Apply pending damage
20 if (damage_ && oneReadyToFight) {
21 // Current attacker is last defender, so damage goes to current attacker
22- if (first_strikes_)
23+ if (first_strikes_) {
24 first_->damage(damage_);
25- else
26+ } else {
27 second_->damage(damage_);
28+ }
29 damage_ = 0;
30 }
31
32@@ -184,8 +192,9 @@
33 return schedule_destroy(game);
34 }
35
36- if (!first_ || !second_)
37+ if (!first_ || !second_) {
38 return soldier.skip_act();
39+ }
40
41 // Here is a timeout to prevent battle freezes
42 if (waitingForOpponent && (game.get_gametime() - creationtime_) > 90 * 1000) {
43@@ -248,10 +257,12 @@
44 molog("[battle] (%u) vs (%u) is %d, first strikes %d, last hit %d\n", soldier.serial(),
45 opponent(soldier)->serial(), this_soldier_is, first_strikes_, last_attack_hits_);
46
47+ bool shorten_animation = false;
48 if (this_soldier_is == 1) {
49 if (first_strikes_) {
50 if (last_attack_hits_) {
51 what_anim = "evade_failure_e";
52+ shorten_animation = true;
53 } else {
54 what_anim = "evade_success_e";
55 }
56@@ -272,13 +283,17 @@
57 } else {
58 if (last_attack_hits_) {
59 what_anim = "evade_failure_w";
60+ shorten_animation = true;
61 } else {
62 what_anim = "evade_success_w";
63 }
64 }
65 }
66+ // If the soldier will die as soon as the animation is complete, don't
67+ // show it for the full length to prevent overlooping (bug 1817664)
68+ shorten_animation &= damage_ >= soldier.get_current_health();
69 molog("[battle] Starting animation %s for soldier %d\n", what_anim.c_str(), soldier.serial());
70- soldier.start_task_idle(game, soldier.descr().get_rand_anim(game, what_anim.c_str()), 1000);
71+ soldier.start_task_idle(game, soldier.descr().get_rand_anim(game, what_anim.c_str()), shorten_animation ? 850 : 1000);
72 }
73
74 void Battle::calculate_round(Game& game) {
75
76=== modified file 'src/logic/map_objects/tribes/battle.h'
77--- src/logic/map_objects/tribes/battle.h 2019-02-23 11:00:49 +0000
78+++ src/logic/map_objects/tribes/battle.h 2019-02-27 10:46:34 +0000
79@@ -74,6 +74,8 @@
80 return second_;
81 }
82
83+ uint32_t get_pending_damage(const Soldier* for_whom) const;
84+
85 // Returns the other soldier involved in this battle. CHECKs that the given
86 // soldier is participating in this battle. Can return nullptr, probably when the
87 // opponent has died.
88
89=== modified file 'src/logic/map_objects/tribes/soldier.cc'
90--- src/logic/map_objects/tribes/soldier.cc 2019-02-23 11:00:49 +0000
91+++ src/logic/map_objects/tribes/soldier.cc 2019-02-27 10:46:34 +0000
92@@ -505,7 +505,26 @@
93 kSoldierHealthBarWidth * 2 * scale, 5 * scale);
94 dst->fill_rect(energy_outer, RGBColor(255, 255, 255));
95
96- int health_width = 2 * (kSoldierHealthBarWidth - 1) * current_health_ / get_max_health();
97+ // Adjust health to current animation tick
98+ uint32_t health_to_show = current_health_;
99+ if (battle_) {
100+ uint32_t pending_damage = battle_->get_pending_damage(this);
101+ if (pending_damage > 0) {
102+ int32_t timeshift = owner().egbase().get_gametime() - get_animstart();
103+ timeshift = std::min(std::max(0, timeshift), 1000);
104+
105+ pending_damage *= timeshift;
106+ pending_damage /= 1000;
107+
108+ if (pending_damage > health_to_show) {
109+ health_to_show = 0;
110+ } else {
111+ health_to_show -= pending_damage;
112+ }
113+ }
114+ }
115+
116+ int health_width = 2 * (kSoldierHealthBarWidth - 1) * health_to_show / get_max_health();
117 Recti energy_inner(draw_position + Vector2i(-kSoldierHealthBarWidth + 1, 1) * scale,
118 health_width * scale, 3 * scale);
119 Recti energy_complement(energy_inner.origin() + Vector2i(health_width, 0) * scale,

Subscribers

People subscribed via source and target branches

to status/vote changes: