Skip to content

Commit

Permalink
Merge branch 'drawable_units'
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Jun 17, 2014
2 parents f80f710 + 0be1d73 commit f0fc9ff
Show file tree
Hide file tree
Showing 19 changed files with 419 additions and 315 deletions.
2 changes: 2 additions & 0 deletions projectfiles/CodeBlocks-SCons/wesnoth.cbp
Expand Up @@ -193,6 +193,8 @@
<Unit filename="../../src/display.hpp" />
<Unit filename="../../src/display_context.cpp" />
<Unit filename="../../src/display_context.hpp" />
<Unit filename="../../src/drawable_unit.cpp" />
<Unit filename="../../src/drawable_unit.hpp" />
<Unit filename="../../src/editor/action/action_base.hpp" />
<Unit filename="../../src/editor/action/action.cpp" />
<Unit filename="../../src/editor/action/action.hpp" />
Expand Down
2 changes: 2 additions & 0 deletions projectfiles/CodeBlocks/wesnoth.cbp
Expand Up @@ -231,6 +231,8 @@
<Unit filename="..\..\src\display.hpp" />
<Unit filename="..\..\src\display_context.cpp" />
<Unit filename="..\..\src\display_context.hpp" />
<Unit filename="..\..\src\drawable_unit.cpp" />
<Unit filename="..\..\src\drawable_unit.hpp" />
<Unit filename="..\..\src\editor\action\action.cpp" />
<Unit filename="..\..\src\editor\action\action.hpp" />
<Unit filename="..\..\src\editor\action\action_base.hpp" />
Expand Down
8 changes: 8 additions & 0 deletions projectfiles/VC9/wesnoth.vcproj
Expand Up @@ -20060,6 +20060,14 @@
RelativePath="..\..\src\display_context.hpp"
>
</File>
<File
RelativePath="..\..\src\drawable_unit.cpp"
>
</File>
<File
RelativePath="..\..\src\drawable_unit.hpp"
>
</File>
<File
RelativePath="..\..\src\events.cpp"
>
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Expand Up @@ -700,6 +700,7 @@ set(wesnoth-main_SRC
controller_base.cpp
desktop_util.cpp
dialogs.cpp
drawable_unit.cpp
editor/action/action.cpp
editor/action/action_item.cpp
editor/action/action_label.cpp
Expand Down
1 change: 1 addition & 0 deletions src/SConscript
Expand Up @@ -233,6 +233,7 @@ wesnoth_sources = Split("""
controller_base.cpp
desktop_util.cpp
dialogs.cpp
drawable_unit.cpp
editor/action/action.cpp
editor/action/action_unit.cpp
editor/action/action_label.cpp
Expand Down
32 changes: 0 additions & 32 deletions src/actions/move.cpp
Expand Up @@ -1288,37 +1288,5 @@ size_t move_unit_from_replay(const std::vector<map_location> &steps,
return move_unit_internal(undo_stack, show_move, NULL, mover);
}

bool unit_can_move(const unit &u)
{
const team &current_team = (*resources::teams)[u.side() - 1];

if(!u.attacks_left() && u.movement_left()==0)
return false;

// Units with goto commands that have already done their gotos this turn
// (i.e. don't have full movement left) should have red globes.
if(u.has_moved() && u.has_goto()) {
return false;
}

map_location locs[6];
get_adjacent_tiles(u.get_location(), locs);
for(int n = 0; n != 6; ++n) {
if (resources::gameboard->map().on_board(locs[n])) {
const unit_map::const_iterator i = resources::units->find(locs[n]);
if (i.valid() && !i->incapacitated() &&
current_team.is_enemy(i->side())) {
return true;
}

if (u.movement_cost((resources::gameboard->map())[locs[n]]) <= u.movement_left()) {
return true;
}
}
}

return false;
}


}//namespace actions
7 changes: 0 additions & 7 deletions src/actions/move.hpp
Expand Up @@ -114,13 +114,6 @@ size_t move_unit_from_replay(const std::vector<map_location> &steps,
bool continued_move, bool skip_ally_sighted,
bool show_move = true);

/**
* Will return true iff the unit @a u has any possible moves
* it can do (including attacking etc).
*/
bool unit_can_move(const unit &u);


}//namespace actions


Expand Down
3 changes: 2 additions & 1 deletion src/display.cpp
Expand Up @@ -18,6 +18,7 @@
*/

#include "cursor.hpp"
#include "drawable_unit.hpp"
#include "display.hpp"
#include "fake_unit_manager.hpp"
#include "game_preferences.hpp"
Expand Down Expand Up @@ -2553,7 +2554,7 @@ void display::draw_invalidated() {
exclusive_unit_draw_requests_t::iterator request = exclusive_unit_draw_requests_.find(loc);
if (u_it != dc_->units().end()
&& (request == exclusive_unit_draw_requests_.end() || request->second == u_it->id()))
u_it->redraw_unit();
(static_cast<const drawable_unit*> (&*u_it))->redraw_unit();
}

}
Expand Down
2 changes: 2 additions & 0 deletions src/display.hpp
Expand Up @@ -165,6 +165,8 @@ class display

void change_display_context(const display_context * dc);

const display_context & get_disp_context() { return *dc_; }

static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
{ return 0xFF000000 | (red << 16) | (green << 8) | blue; }
static Uint8 red(Uint32 color)
Expand Down
38 changes: 38 additions & 0 deletions src/display_context.cpp
Expand Up @@ -29,3 +29,41 @@ const unit * display_context::get_visible_unit(const map_location & loc, const t
}
return &*u;
}

/**
* Will return true iff the unit @a u has any possible moves
* it can do (including attacking etc).
*/

bool display_context::unit_can_move(const unit &u) const
{
if(!u.attacks_left() && u.movement_left()==0)
return false;

// Units with goto commands that have already done their gotos this turn
// (i.e. don't have full movement left) should have red globes.
if(u.has_moved() && u.has_goto()) {
return false;
}

const team &current_team = teams()[u.side() - 1];

map_location locs[6];
get_adjacent_tiles(u.get_location(), locs);
for(int n = 0; n != 6; ++n) {
if (map().on_board(locs[n])) {
const unit_map::const_iterator i = units().find(locs[n]);
if (i.valid() && !i->incapacitated() &&
current_team.is_enemy(i->side())) {
return true;
}

if (u.movement_cost(map()[locs[n]]) <= u.movement_left()) {
return true;
}
}
}

return false;
}

8 changes: 8 additions & 0 deletions src/display_context.hpp
Expand Up @@ -37,8 +37,16 @@ class display_context {
virtual const gamemap & map() const = 0;
virtual const unit_map & units() const = 0;

// Needed for reports

const unit * get_visible_unit(const map_location &loc, const team &current_team, bool see_all = false) const;

// From actions:: namespace

bool unit_can_move(const unit & u) const;

// Dtor

virtual ~display_context() {}
};

Expand Down

0 comments on commit f0fc9ff

Please sign in to comment.