Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "utility.hpp"
00021
00022 #include "manager.hpp"
00023
00024 #include "actions.hpp"
00025 #include "foreach.hpp"
00026 #include "game_display.hpp"
00027 #include "map.hpp"
00028 #include "play_controller.hpp"
00029 #include "resources.hpp"
00030 #include "team.hpp"
00031 #include "unit.hpp"
00032
00033 namespace wb {
00034
00035 size_t viewer_team()
00036 {
00037 return resources::screen->viewing_team();
00038 }
00039
00040 int viewer_side()
00041 {
00042 return resources::screen->viewing_side();
00043 }
00044
00045 side_actions_ptr viewer_actions()
00046 {
00047 side_actions_ptr side_actions =
00048 (*resources::teams)[resources::screen->viewing_team()].get_side_actions();
00049 return side_actions;
00050 }
00051
00052 side_actions_ptr current_side_actions()
00053 {
00054 side_actions_ptr side_actions =
00055 (*resources::teams)[resources::controller->current_side() - 1].get_side_actions();
00056 return side_actions;
00057 }
00058
00059 unit const* find_backup_leader(unit const& leader)
00060 {
00061 assert(leader.can_recruit());
00062 assert(resources::game_map->is_keep(leader.get_location()));
00063 foreach(unit const& unit, *resources::units)
00064 {
00065 if (unit.can_recruit() &&
00066 resources::game_map->is_keep(unit.get_location()) &&
00067 unit.id() != leader.id())
00068 {
00069 if (can_recruit_on(*resources::game_map, unit.get_location(), leader.get_location()))
00070 return &unit;
00071 }
00072 }
00073 return NULL;
00074 }
00075
00076 unit* find_recruiter(size_t team_index, map_location const& hex)
00077 {
00078 gamemap& map = *resources::game_map;
00079
00080 if(!map.on_board(hex))
00081 return NULL;
00082
00083 if(!map.is_castle(hex))
00084 return NULL;
00085
00086 foreach(unit& u, *resources::units)
00087 if(u.can_recruit()
00088 && u.side() == static_cast<int>(team_index+1)
00089 && can_recruit_on(map,u.get_location(),hex))
00090 return &u;
00091 return NULL;
00092 }
00093
00094 unit* future_visible_unit(map_location hex, int viewer_side)
00095 {
00096 future_map planned_unit_map;
00097 if(!resources::whiteboard->has_planned_unit_map())
00098 {
00099 ERR_WB << "future_visible_unit cannot find unit, future unit map failed to build.\n";
00100 return NULL;
00101 }
00102
00103 return get_visible_unit(hex, resources::teams->at(viewer_side - 1), false);
00104 }
00105
00106 unit* future_visible_unit(int on_side, map_location hex, int viewer_side)
00107 {
00108 unit* unit = future_visible_unit(hex, viewer_side);
00109 if (unit && unit->side() == on_side)
00110 return unit;
00111 else
00112 return NULL;
00113 }
00114
00115 int path_cost(std::vector<map_location> const& path, unit const& u)
00116 {
00117 if(path.size() < 2)
00118 return 0;
00119
00120 team const& u_team = resources::teams->at(u.side()-1);
00121 map_location const& dest = path.back();
00122 if ( (resources::game_map->is_village(dest) && !u_team.owns_village(dest))
00123 || pathfind::enemy_zoc(u_team, dest, u_team) )
00124 return u.total_movement();
00125
00126 int result = 0;
00127 gamemap const& map = *resources::game_map;
00128 foreach(map_location const& loc, std::make_pair(path.begin()+1,path.end()))
00129 result += u.movement_cost(map[loc]);
00130 return result;
00131 }
00132
00133 temporary_unit_hider::temporary_unit_hider(unit& u)
00134 : unit_(&u)
00135 {unit_->set_hidden(true);}
00136 temporary_unit_hider::~temporary_unit_hider()
00137 {unit_->set_hidden(false);}
00138
00139 void ghost_owner_unit(unit* unit)
00140 {
00141 unit->set_disabled_ghosted(false);
00142 resources::screen->invalidate(unit->get_location());
00143 }
00144
00145 void unghost_owner_unit(unit* unit)
00146 {
00147 unit->set_standing(true);
00148 resources::screen->invalidate(unit->get_location());
00149 }
00150
00151 bool has_actions()
00152 {
00153 foreach(team& t, *resources::teams)
00154 if (!t.get_side_actions()->empty())
00155 return true;
00156
00157 return false;
00158 }
00159
00160 }
00161