Merge lp:~nha/widelands/bug1132473 into lp:widelands

Proposed by Nicolai Hähnle
Status: Merged
Merged at revision: 6540
Proposed branch: lp:~nha/widelands/bug1132473
Merge into: lp:widelands
Diff against target: 119 lines (+17/-19)
2 files modified
src/logic/bob.cc (+1/-1)
src/logic/soldier.cc (+16/-18)
To merge this branch: bzr merge lp:~nha/widelands/bug1132473
Reviewer Review Type Date Requested Status
SirVer Approve
Review via email: mp+153657@code.launchpad.net

Commit message

Fix bug #1132473 and other cleanups in the soldier code

Attacking soldiers no longer get stuck when their location disappears while they are in battle. Furthermore, replace some polling in the battle code by a signal mechanism to avoid unnecessary work, and remove some particularly spammy log messages.

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

Late to the party - as always lately :/. LGTM, I think all changes improve the code.

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 2013-03-03 19:46:00 +0000
3+++ src/logic/bob.cc 2013-03-16 12:44:24 +0000
4@@ -1040,7 +1040,7 @@
5 molog("* svar1: %s\n", m_stack[i].svar1.c_str());
6
7 molog("* coords: (%i, %i)\n", m_stack[i].coords.x, m_stack[i].coords.y);
8- molog("* diranims:", m_stack[i].diranims);
9+ molog("* diranims:");
10 for (Direction dir = FIRST_DIRECTION; dir <= LAST_DIRECTION; ++dir) {
11 molog(" %d", m_stack[i].diranims.get_animation(dir));
12 }
13
14=== modified file 'src/logic/soldier.cc'
15--- src/logic/soldier.cc 2013-03-03 19:46:00 +0000
16+++ src/logic/soldier.cc 2013-03-16 12:44:24 +0000
17@@ -292,7 +292,6 @@
18 run = m_die_e_name[i];
19 }
20
21- log(" get %s\n", run.c_str());
22 return get_animation(run.c_str());
23 }
24
25@@ -832,11 +831,10 @@
26 return start_task_idle(game, get_animation("idle"), -1);
27 }
28
29- PlayerImmovable * const location = get_location(game);
30- BaseImmovable * const imm = game.map()[get_position()].get_immovable();
31+ upcast(Building, location, get_location(game));
32 upcast(Building, enemy, state.objvar1.get(game));
33
34- if (imm == location) {
35+ if (location && get_position() == location->get_position()) {
36 if (!enemy) {
37 molog("[attack] returned home\n");
38 return pop_task(game);
39@@ -847,12 +845,13 @@
40 if (m_battle)
41 return start_task_battle(game);
42
43- if (signal == "blocked")
44+ if (signal == "blocked") {
45 // Wait before we try again. Note that this must come *after*
46 // we check for a battle
47 // Note that we *should* be woken via sendSpaceSignals,
48 // so the timeout is just an additional safety net.
49 return start_task_idle(game, get_animation("idle"), 5000);
50+ }
51
52 if (!location) {
53 molog("[attack] our location disappeared during a battle\n");
54@@ -915,7 +914,7 @@
55 }
56 }
57 Flag & baseflag = location->base_flag();
58- if (imm == &baseflag)
59+ if (get_position() == baseflag.get_position())
60 return
61 start_task_move
62 (game,
63@@ -938,7 +937,7 @@
64
65 // At this point, we know that the enemy building still stands,
66 // and that we're outside in the plains.
67- if (imm != &enemy->base_flag()) {
68+ if (get_position() != enemy->base_flag().get_position()) {
69 if
70 (start_task_movepath
71 (game,
72@@ -1414,6 +1413,7 @@
73 return skip_act(); // we will get a signal via setBattle()
74 } else {
75 if (m_combat_walking != CD_COMBAT_E) {
76+ opponent.send_signal(game, "wakeup");
77 return start_task_move_in_battle(game, CD_WALK_E);
78 }
79 }
80@@ -1495,7 +1495,6 @@
81 }
82 }
83 } else {
84-
85 assert(opponent.get_position() == get_position());
86 assert(m_battle == opponent.getBattle());
87
88@@ -1503,22 +1502,21 @@
89 molog
90 ("[battle]: Opponent '%d' is walking, sleeping\n",
91 opponent.serial());
92- return start_task_idle(game, descr().get_animation("idle"), 100);
93+ // We should be woken up by our opponent, but add a timeout anyway for robustness
94+ return start_task_idle(game, descr().get_animation("idle"), 5000);
95 }
96
97 if (m_battle->first()->serial() == serial()) {
98- molog("[battle]: I am first: '%d'\n", m_combat_walking);
99 if (m_combat_walking != CD_COMBAT_W) {
100- start_task_move_in_battle(game, CD_WALK_W);
101- return;
102+ molog("[battle]: Moving west\n");
103+ opponent.send_signal(game, "wakeup");
104+ return start_task_move_in_battle(game, CD_WALK_W);
105 }
106- }
107-
108- if (m_battle->second()->serial() == serial()) {
109- molog("[battle]: I am second: '%d'\n", m_combat_walking);
110+ } else {
111 if (m_combat_walking != CD_COMBAT_E) {
112- start_task_move_in_battle(game, CD_WALK_E);
113- return;
114+ molog("[battle]: Moving east\n");
115+ opponent.send_signal(game, "wakeup");
116+ return start_task_move_in_battle(game, CD_WALK_E);
117 }
118 }
119 }

Subscribers

People subscribed via source and target branches

to status/vote changes: