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

Proposed by Nicolai Hähnle
Status: Merged
Merged at revision: 6522
Proposed branch: lp:~widelands-dev/widelands/bug1132466
Merge into: lp:widelands
Diff against target: 238 lines (+70/-32)
5 files modified
src/logic/playercommand.cc (+1/-2)
src/logic/soldier.cc (+6/-1)
src/logic/soldier.h (+3/-1)
src/logic/worker.cc (+57/-27)
src/logic/worker.h (+3/-1)
To merge this branch: bzr merge lp:~widelands-dev/widelands/bug1132466
Reviewer Review Type Date Requested Status
SirVer Approve
Review via email: mp+150244@code.launchpad.net

Commit message

Fix bug #1132466 and a potential cheat related to evicting soldiers

The worker leavebuilding task now deals more robustly with situations in which the evicted worker is currently outside of the building.

Furthermore, it is no longer possible to evict soldiers whose current position on the map is not their assigned building (i.e., their location). Note that this was not possible with the standard user interface anyway, but a cheater could have modified her version of the game such that an eviction player command would be sent automatically for her soldiers when they reach low HP during a battle. Such soldiers would have immediately stopped battle and returned home.

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

lgtm.

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

Thank you. However, I just realized myself that the eviction still has a problem that I would like to fix first: When evicting a worker that is in the middle of walking, the reset_tasks() approach that is being taken right now causes the worker to be "warped".

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

This fixes the warping issue, and seems to be the correct of doing it.

Revision history for this message
SirVer (sirver) wrote :

+ const Coords flagpos = baseflag.get_position();
can this be a const reference? Haven't checked.

still lgtm.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/logic/playercommand.cc'
--- src/logic/playercommand.cc 2013-02-04 21:52:38 +0000
+++ src/logic/playercommand.cc 2013-02-25 17:40:30 +0000
@@ -638,8 +638,7 @@
638{638{
639 upcast(Worker, worker, game.objects().get_object(serial));639 upcast(Worker, worker, game.objects().get_object(serial));
640 if (worker && worker->owner().player_number() == sender()) {640 if (worker && worker->owner().player_number() == sender()) {
641 worker->reset_tasks(game);641 worker->evict(game);
642 worker->start_task_gowarehouse(game);
643 }642 }
644}643}
645644
646645
=== modified file 'src/logic/soldier.cc'
--- src/logic/soldier.cc 2013-02-10 19:36:24 +0000
+++ src/logic/soldier.cc 2013-02-25 17:40:30 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2002-2004, 2006-2011 by the Widelands Development Team2 * Copyright (C) 2002-2004, 2006-2013 by the Widelands Development Team
3 *3 *
4 * This program is free software; you can redistribute it and/or4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License5 * modify it under the terms of the GNU General Public License
@@ -347,6 +347,11 @@
347 Worker::cleanup(egbase);347 Worker::cleanup(egbase);
348}348}
349349
350bool Soldier::is_evict_allowed()
351{
352 return !isOnBattlefield();
353}
354
350/*355/*
351 * Set this soldiers level. Automatically sets the new values356 * Set this soldiers level. Automatically sets the new values
352 */357 */
353358
=== modified file 'src/logic/soldier.h'
--- src/logic/soldier.h 2013-02-10 19:36:24 +0000
+++ src/logic/soldier.h 2013-02-25 17:40:30 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2002-2004, 2006-2010 by the Widelands Development Team2 * Copyright (C) 2002-2004, 2006-2013 by the Widelands Development Team
3 *3 *
4 * This program is free software; you can redistribute it and/or4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License5 * modify it under the terms of the GNU General Public License
@@ -287,6 +287,8 @@
287 // May be this can be moved this to bob when finished287 // May be this can be moved this to bob when finished
288 static Task const taskDie;288 static Task const taskDie;
289289
290 virtual bool is_evict_allowed();
291
290private:292private:
291 uint32_t m_hp_current;293 uint32_t m_hp_current;
292 uint32_t m_hp_level;294 uint32_t m_hp_level;
293295
=== modified file 'src/logic/worker.cc'
--- src/logic/worker.cc 2013-02-11 18:01:26 +0000
+++ src/logic/worker.cc 2013-02-25 17:40:30 +0000
@@ -1441,30 +1441,20 @@
1441 }1441 }
1442 }1442 }
14431443
1444 // If our location is a building, make sure we're actually in it.1444 // If our location is a building, our position may be somewhere else:
1445 // If we're a building's worker, and we've just been released from1445 // We may be on the building's flag for a fetch_from_flag or dropoff task.
1446 // the building, we may be somewhere else entirely (e.g. lumberjack, soldier)1446 // We may also be somewhere else entirely (e.g. lumberjack, soldier).
1447 // or we may be on the building's flag for a fetch_from_flag or dropoff
1448 // task.
1449 // Similarly for flags.1447 // Similarly for flags.
1450 if (dynamic_cast<Building const *>(location)) {1448 if (upcast(Building, building, location)) {
1451 BaseImmovable * const position = map[get_position()].get_immovable();1449 if (building->get_position() != get_position())
14521450 return start_task_leavebuilding(game, true);
1453 if (position != location) {
1454 if (upcast(Flag, flag, position)) {
1455 location = flag;
1456 set_location(flag);
1457 } else
1458 return set_location(0);
1459 }
1460 } else if (upcast(Flag, flag, location)) {1451 } else if (upcast(Flag, flag, location)) {
1461 BaseImmovable * const position = map[get_position()].get_immovable();1452 BaseImmovable * const position = map[get_position()].get_immovable();
14621453
1463 if (position != flag) {1454 if (position != flag) {
1464 if (position == flag->get_building()) {1455 if (position == flag->get_building()) {
1465 upcast(Building, building, position);1456 location = flag->get_building();
1466 set_location(building);1457 set_location(location);
1467 location = building;
1468 } else1458 } else
1469 return set_location(0);1459 return set_location(0);
1470 }1460 }
@@ -1681,6 +1671,7 @@
1681 *1671 *
1682 * ivar1 - 0: no task has failed; 1: currently in buildingwork;1672 * ivar1 - 0: no task has failed; 1: currently in buildingwork;
1683 * 2: signal failure of buildingwork1673 * 2: signal failure of buildingwork
1674 * ivar2 - whether the worker is to be evicted
1684 */1675 */
1685const Bob::Task Worker::taskBuildingwork = {1676const Bob::Task Worker::taskBuildingwork = {
1686 "buildingwork",1677 "buildingwork",
@@ -1697,7 +1688,9 @@
1697void Worker::start_task_buildingwork(Game & game)1688void Worker::start_task_buildingwork(Game & game)
1698{1689{
1699 push_task(game, taskBuildingwork);1690 push_task(game, taskBuildingwork);
1700 top_state().ivar1 = 0;1691 State & state = top_state();
1692 state.ivar1 = 0;
1693 state.ivar2 = 0;
1701}1694}
17021695
17031696
@@ -1710,6 +1703,9 @@
1710 if (state.ivar1 == 1)1703 if (state.ivar1 == 1)
1711 state.ivar1 = (signal == "fail") * 2;1704 state.ivar1 = (signal == "fail") * 2;
17121705
1706 if (state.ivar2 == 1)
1707 return pop_task(game); // evict worker
1708
1713 // Return to building, if necessary1709 // Return to building, if necessary
1714 upcast(Building, building, get_location(game));1710 upcast(Building, building, get_location(game));
1715 if (!building)1711 if (!building)
@@ -1743,6 +1739,23 @@
1743 send_signal(game, "update");1739 send_signal(game, "update");
1744}1740}
17451741
1742/**
1743 * Evict the worker from its current building.
1744 */
1745void Worker::evict(Game & game)
1746{
1747 if (State * state = get_state(taskBuildingwork)) {
1748 if (is_evict_allowed()) {
1749 state->ivar2 = 1;
1750 send_signal(game, "evict");
1751 }
1752 }
1753}
1754
1755bool Worker::is_evict_allowed()
1756{
1757 return true;
1758}
17461759
1747/**1760/**
1748 * Return to our owning building.1761 * Return to our owning building.
@@ -1998,9 +2011,7 @@
19982011
1999 // Always leave buildings in an orderly manner,2012 // Always leave buildings in an orderly manner,
2000 // even when no warehouses are left to return to2013 // even when no warehouses are left to return to
2001 if2014 if (location->get_type() == BUILDING)
2002 (location->get_type() == BUILDING &&
2003 get_position() == static_cast<Building *>(location)->get_position())
2004 return start_task_leavebuilding(game, true);2015 return start_task_leavebuilding(game, true);
20052016
2006 if (!get_economy()->warehouses().size()) {2017 if (!get_economy()->warehouses().size()) {
@@ -2384,14 +2395,19 @@
2384 else if (signal.size())2395 else if (signal.size())
2385 return pop_task(game);2396 return pop_task(game);
23862397
2387 if (upcast(Building, building, game.map().get_immovable(get_position()))) {2398 upcast(Building, building, get_location(game));
2399 if (!building)
2400 return pop_task(game);
2401
2402 Flag & baseflag = building->base_flag();
2403
2404 if (get_position() == building->get_position()) {
2388 assert(building == state.objvar1.get(game));2405 assert(building == state.objvar1.get(game));
2389
2390 if (!building->leave_check_and_wait(game, *this))2406 if (!building->leave_check_and_wait(game, *this))
2391 return skip_act();2407 return skip_act();
23922408
2393 if (state.ivar1)2409 if (state.ivar1)
2394 set_location(&building->base_flag());2410 set_location(&baseflag);
23952411
2396 return2412 return
2397 start_task_move2413 start_task_move
@@ -2399,8 +2415,22 @@
2399 WALK_SE,2415 WALK_SE,
2400 &descr().get_right_walk_anims(does_carry_ware()),2416 &descr().get_right_walk_anims(does_carry_ware()),
2401 true);2417 true);
2402 } else2418 } else {
2403 return pop_task(game);2419 const Coords flagpos = baseflag.get_position();
2420
2421 if (state.ivar1)
2422 set_location(&baseflag);
2423
2424 if (get_position() == flagpos)
2425 return pop_task(game);
2426
2427 if (!start_task_movepath(game, flagpos, 0, descr().get_right_walk_anims(does_carry_ware()))) {
2428 molog("[leavebuilding]: outside of building, but failed to walk back to flag");
2429 set_location(0);
2430 return pop_task(game);
2431 }
2432 return;
2433 }
2404}2434}
24052435
24062436
24072437
=== modified file 'src/logic/worker.h'
--- src/logic/worker.h 2013-02-10 19:36:24 +0000
+++ src/logic/worker.h 2013-02-25 17:40:30 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2002-2004, 2006-2010 by the Widelands Development Team2 * Copyright (C) 2002-2004, 2006-2013 by the Widelands Development Team
3 *3 *
4 * This program is free software; you can redistribute it and/or4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License5 * modify it under the terms of the GNU General Public License
@@ -171,6 +171,7 @@
171171
172 void start_task_buildingwork(Game &);172 void start_task_buildingwork(Game &);
173 void update_task_buildingwork(Game &);173 void update_task_buildingwork(Game &);
174 void evict(Game &);
174175
175 void start_task_return(Game & game, bool dropitem);176 void start_task_return(Game & game, bool dropitem);
176 void start_task_program(Game & game, const std::string & programname);177 void start_task_program(Game & game, const std::string & programname);
@@ -192,6 +193,7 @@
192 void start_task_scout(Game &, uint16_t, uint32_t);193 void start_task_scout(Game &, uint16_t, uint32_t);
193194
194protected:195protected:
196 virtual bool is_evict_allowed();
195 void draw_inner(const Editor_Game_Base &, RenderTarget &, Point) const;197 void draw_inner(const Editor_Game_Base &, RenderTarget &, Point) const;
196 virtual void draw(const Editor_Game_Base &, RenderTarget &, Point) const;198 virtual void draw(const Editor_Game_Base &, RenderTarget &, Point) const;
197 virtual void init_auto_task(Game &);199 virtual void init_auto_task(Game &);

Subscribers

People subscribed via source and target branches

to status/vote changes: