replace most direct check of stoned units with generic incapacitated check
This commit is contained in:
parent
0da4d13244
commit
d22294a270
9 changed files with 1438 additions and 1433 deletions
|
@ -1948,7 +1948,7 @@ time_of_day timeofday_at(const gamestatus& status,const unit_map& units,const ga
|
|||
for(int i = 0; i != 7; ++i) {
|
||||
const unit_map::const_iterator itor = units.find(locs[i]);
|
||||
if(itor != units.end() &&
|
||||
itor->second.get_ability_bool("illuminates",itor->first) && !utils::string_bool(itor->second.get_state("stoned"))) {
|
||||
itor->second.get_ability_bool("illuminates",itor->first) && !itor->second.incapacitated()) {
|
||||
unit_ability_list illum = itor->second.get_abilities("illuminates",itor->first);
|
||||
unit_abilities::effect illum_effect(illum,lighten,false);
|
||||
int mod = illum_effect.get_composite_value();
|
||||
|
@ -2407,7 +2407,7 @@ bool unit_can_move(const gamemap::location& loc, const unit_map& units,
|
|||
if(map.on_board(locs[n])) {
|
||||
const unit_map::const_iterator i = units.find(locs[n]);
|
||||
if(i != units.end()) {
|
||||
if(!utils::string_bool(i->second.get_state("stoned")) && current_team.is_enemy(i->second.side())) {
|
||||
if(!i->second.incapacitated() && current_team.is_enemy(i->second.side())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2495,7 +2495,7 @@ bool backstab_check(const gamemap::location& attacker_loc,
|
|||
const units_map::const_iterator opp =
|
||||
units.find(adj[(i+3)%6]);
|
||||
if(opp == units.end()) return false; // No opposite unit
|
||||
if(utils::string_bool(opp->second.get_state("stoned"))) return false;
|
||||
if(opp->second.incapacitated()) return false;
|
||||
if(size_t(defender->second.side()-1) >= teams.size() ||
|
||||
size_t(opp->second.side()-1) >= teams.size())
|
||||
return true; // If sides aren't valid teams, then they are enemies
|
||||
|
|
18
src/ai.cpp
18
src/ai.cpp
|
@ -582,7 +582,7 @@ gamemap::location ai::move_unit(location from, location to, std::map<location,pa
|
|||
for(adjacent_tiles_array::const_iterator adj_i = locs.begin(); adj_i != locs.end(); ++adj_i) {
|
||||
const unit_map::const_iterator itor = units_.find(*adj_i);
|
||||
if(itor != units_.end() && current_team().is_enemy(itor->second.side()) &&
|
||||
!utils::string_bool(itor->second.get_state("stoned"))) {
|
||||
!itor->second.incapacitated()) {
|
||||
battle_stats stats;
|
||||
const int weapon = choose_weapon(res,itor->first,stats,0);
|
||||
attack_enemy(res,itor->first,weapon);
|
||||
|
@ -627,7 +627,7 @@ void ai_interface::calculate_possible_moves(std::map<location,paths>& res, move_
|
|||
}
|
||||
|
||||
//discount incapacitated units
|
||||
if(utils::string_bool(un_it->second.get_state("stoned"))) {
|
||||
if(un_it->second.incapacitated()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -988,7 +988,7 @@ void ai_interface::attack_enemy(const location& u, const location& target, int w
|
|||
const events::command_disabler disable_commands;
|
||||
|
||||
if(info_.units.count(u) && info_.units.count(target)) {
|
||||
if(utils::string_bool(info_.units.find(target)->second.get_state("stoned"))) {
|
||||
if(info_.units.find(target)->second.incapacitated()) {
|
||||
LOG_STREAM(err, ai) << "attempt to attack unit that is turned to stone\n";
|
||||
return;
|
||||
}
|
||||
|
@ -1377,7 +1377,7 @@ bool ai::move_to_targets(std::map<gamemap::location,paths>& possible_moves, move
|
|||
teams_,current_team());
|
||||
|
||||
if(enemy != units_.end() &&
|
||||
current_team().is_enemy(enemy->second.side()) && !utils::string_bool(enemy->second.get_state("stoned"))) {
|
||||
current_team().is_enemy(enemy->second.side()) && !enemy->second.incapacitated()) {
|
||||
const int res = choose_weapon(move.first,adj[n],bat_stats,
|
||||
map_[move.second.x][move.second.y]);
|
||||
|
||||
|
@ -1404,7 +1404,7 @@ bool ai::move_to_targets(std::map<gamemap::location,paths>& possible_moves, move
|
|||
const unit_map::const_iterator un_it = units_.find(arrived_at);
|
||||
|
||||
//if we're going to attack someone
|
||||
if(u_it != units_.end() && !utils::string_bool(u_it->second.get_state("stoned")) && weapon != -1) {
|
||||
if(u_it != units_.end() && !u_it->second.incapacitated() && weapon != -1) {
|
||||
attack_enemy(move.second,target,weapon);
|
||||
}
|
||||
|
||||
|
@ -1727,7 +1727,7 @@ void ai::move_leader_to_goals( const move_map& enemy_dstsrc)
|
|||
}
|
||||
|
||||
const unit_map::iterator leader = find_leader(units_,team_num_);
|
||||
if(leader == units_.end() || utils::string_bool(leader->second.get_state("stoned"))) {
|
||||
if(leader == units_.end() || leader->second.incapacitated()) {
|
||||
WRN_AI << "Leader not found\n";
|
||||
return;
|
||||
}
|
||||
|
@ -1764,7 +1764,7 @@ void ai::move_leader_to_goals( const move_map& enemy_dstsrc)
|
|||
void ai::move_leader_to_keep(const move_map& enemy_dstsrc)
|
||||
{
|
||||
const unit_map::iterator leader = find_leader(units_,team_num_);
|
||||
if(leader == units_.end() || utils::string_bool(leader->second.get_state("stoned"))) {
|
||||
if(leader == units_.end() || leader->second.incapacitated()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1813,7 +1813,7 @@ void ai::move_leader_after_recruit(const move_map& enemy_dstsrc)
|
|||
LOG_AI << "moving leader after recruit...\n";
|
||||
|
||||
const unit_map::iterator leader = find_leader(units_,team_num_);
|
||||
if(leader == units_.end() || utils::string_bool(leader->second.get_state("stoned"))) {
|
||||
if(leader == units_.end() || leader->second.incapacitated()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1901,7 +1901,7 @@ void ai::move_leader_after_recruit(const move_map& enemy_dstsrc)
|
|||
bool ai::leader_can_reach_keep() const
|
||||
{
|
||||
const unit_map::iterator leader = find_leader(units_,team_num_);
|
||||
if(leader == units_.end() || utils::string_bool(leader->second.get_state("stoned"))) {
|
||||
if(leader == units_.end() || leader->second.incapacitated()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -691,7 +691,7 @@ std::vector<ai::attack_analysis> ai::analyze_targets(
|
|||
for(unit_map::const_iterator j = units_.begin(); j != units_.end(); ++j) {
|
||||
|
||||
//attack anyone who is on the enemy side, and who is not invisible or turned to stone
|
||||
if(current_team().is_enemy(j->second.side()) && !utils::string_bool(j->second.get_state("stoned")) &&
|
||||
if(current_team().is_enemy(j->second.side()) && !j->second.incapacitated() &&
|
||||
j->second.invisible(map_.underlying_union_terrain(map_[j->first.x][j->first.y]),
|
||||
state_.get_time_of_day().lawful_bonus,j->first,
|
||||
units_,teams_) == false) {
|
||||
|
|
|
@ -399,7 +399,7 @@ std::pair<gamemap::location,gamemap::location> ai::choose_move(std::vector<targe
|
|||
|
||||
//find the first eligible unit
|
||||
for(u = units_.begin(); u != units_.end(); ++u) {
|
||||
if(!(u->second.side() != team_num_ || u->second.can_recruit() || u->second.movement_left() <= 0 || utils::string_bool(u->second.get_state("stoned")))) {
|
||||
if(!(u->second.side() != team_num_ || u->second.can_recruit() || u->second.movement_left() <= 0 || u->second.incapacitated())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -505,7 +505,7 @@ std::pair<gamemap::location,gamemap::location> ai::choose_move(std::vector<targe
|
|||
//now see if any other unit can put a better bid forward
|
||||
for(++u; u != units_.end(); ++u) {
|
||||
if(u->second.side() != team_num_ || u->second.can_recruit() ||
|
||||
u->second.movement_left() <= 0 || utils::string_bool(u->second.get_state("guardian")) || utils::string_bool(u->second.get_state("stoned"))) {
|
||||
u->second.movement_left() <= 0 || utils::string_bool(u->second.get_state("guardian")) || u->second.incapacitated()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -912,7 +912,7 @@ namespace events{
|
|||
.lawful_bonus,
|
||||
u->first, units_, teams_);
|
||||
|
||||
if(teams_[team_num - 1].is_enemy(u->second.side()) && !gui_->fogged(u->first.x,u->first.y) && !utils::string_bool(u->second.get_state("stoned")) && !invisible) {
|
||||
if(teams_[team_num - 1].is_enemy(u->second.side()) && !gui_->fogged(u->first.x,u->first.y) && !u->second.incapacitated() && !invisible) {
|
||||
const unit_movement_resetter move_reset(u->second);
|
||||
const bool is_skirmisher = u->second.get_ability_bool("skirmisher",u->first);
|
||||
const bool teleports = u->second.get_ability_bool("teleport",u->first);
|
||||
|
|
2822
src/mouse_events.cpp
2822
src/mouse_events.cpp
File diff suppressed because it is too large
Load diff
10
src/unit.cpp
10
src/unit.cpp
|
@ -513,7 +513,11 @@ fixed_t unit::alpha() const
|
|||
|
||||
bool unit::can_recruit() const
|
||||
{
|
||||
return !recruits_.empty() || cfg_["canrecruit"]=="1";
|
||||
return !recruits_.empty() || utils::string_bool(cfg_["canrecruit"]);
|
||||
}
|
||||
bool unit::incapacitated() const
|
||||
{
|
||||
return utils::string_bool(get_state("stoned"),false);
|
||||
}
|
||||
const std::vector<std::string>& unit::recruits() const
|
||||
{
|
||||
|
@ -582,7 +586,7 @@ void unit::new_turn(const gamemap::location& loc)
|
|||
} else {
|
||||
set_state("hides","");
|
||||
}
|
||||
if(utils::string_bool(get_state("stoned"))) {
|
||||
if(incapacitated()) {
|
||||
set_attacks(0);
|
||||
}
|
||||
if (hold_position_) {
|
||||
|
@ -691,7 +695,7 @@ bool unit::has_goto() const
|
|||
}
|
||||
int unit::emits_zoc() const
|
||||
{
|
||||
if(utils::string_bool(get_state("stoned"))) {
|
||||
if(incapacitated()) {
|
||||
return false;
|
||||
}
|
||||
return emit_zoc_;
|
||||
|
|
|
@ -107,6 +107,7 @@ class unit
|
|||
fixed_t alpha() const;
|
||||
|
||||
bool can_recruit() const;
|
||||
bool incapacitated() const;
|
||||
const std::vector<std::string>& recruits() const;
|
||||
int total_movement() const;
|
||||
int movement_left() const;
|
||||
|
|
|
@ -114,7 +114,7 @@ bool unit::get_ability_bool(const std::string& ability, const gamemap::location&
|
|||
for(int i = 0; i != 6; ++i) {
|
||||
const unit_map::const_iterator it = units_->find(adjacent[i]);
|
||||
if(it != units_->end() &&
|
||||
!utils::string_bool(it->second.get_state("stoned"))) {
|
||||
!it->second.incapacitated()) {
|
||||
const config* adj_abilities = it->second.cfg_.child("abilities");
|
||||
if(adj_abilities) {
|
||||
const config::child_list& list = adj_abilities->get_children(ability);
|
||||
|
@ -152,7 +152,7 @@ unit_ability_list unit::get_abilities(const std::string& ability, const gamemap:
|
|||
for(int i = 0; i != 6; ++i) {
|
||||
const unit_map::const_iterator it = units_->find(adjacent[i]);
|
||||
if(it != units_->end() &&
|
||||
!utils::string_bool(it->second.get_state("stoned"))) {
|
||||
!it->second.incapacitated()) {
|
||||
const config* adj_abilities = it->second.cfg_.child("abilities");
|
||||
if(adj_abilities) {
|
||||
const config::child_list& list = adj_abilities->get_children(ability);
|
||||
|
@ -220,7 +220,7 @@ std::vector<std::string> unit::ability_tooltips(const gamemap::location& loc) co
|
|||
for(int i = 0; i != 6; ++i) {
|
||||
const unit_map::const_iterator it = units_->find(adjacent[i]);
|
||||
if(it != units_->end() && 0 &&
|
||||
!utils::string_bool(it->second.get_state("stoned"))) {
|
||||
!it->second.incapacitated()) {
|
||||
const config* adj_abilities = it->second.cfg_.child("abilities");
|
||||
if(adj_abilities) {
|
||||
const config::child_map& adj_list_map = adj_abilities->all_children();
|
||||
|
|
Loading…
Add table
Reference in a new issue