made it so that allies cannot capture each other's villages

This commit is contained in:
Dave White 2004-03-23 23:15:54 +00:00
parent 4ce4cada4e
commit 39cc9b5a52
4 changed files with 42 additions and 11 deletions

View file

@ -742,16 +742,18 @@ int tower_owner(const gamemap::location& loc, std::vector<team>& teams)
void get_tower(const gamemap::location& loc, std::vector<team>& teams, void get_tower(const gamemap::location& loc, std::vector<team>& teams,
size_t team_num, const unit_map& units) size_t team_num, const unit_map& units)
{ {
for(size_t i = 0; i != teams.size(); ++i) { if(team_num >= teams.size()) {
if(i != team_num && teams[i].owns_tower(loc)) { return;
teams[i].lose_tower(loc);
}
} }
//if the side doesn't have a leader, captured villages become neutral //get the village, and strip it off any enemies
teams[team_num].get_tower(loc);
//if the side doesn't have a leader, it should become neutral
const bool has_leader = find_leader(units,int(team_num+1)) != units.end(); const bool has_leader = find_leader(units,int(team_num+1)) != units.end();
if(has_leader && team_num < teams.size()) if(has_leader == false) {
teams[team_num].get_tower(loc); teams[team_num].lose_tower(loc);
}
} }
std::map<gamemap::location,unit>::iterator std::map<gamemap::location,unit>::iterator

View file

@ -440,6 +440,11 @@ bool ai::do_combat(std::map<gamemap::location,paths>& possible_moves, const move
void ai_interface::attack_enemy(const location& u, const location& target, int weapon) void ai_interface::attack_enemy(const location& u, const location& target, int weapon)
{ {
if(info_.units.count(u) && info_.units.count(target)) { if(info_.units.count(u) && info_.units.count(target)) {
if(info_.units.find(target)->second.stone()) {
std::cerr << "ERROR: attempt to attack unit that is turned to stone\n";
return;
}
recorder.add_attack(u,target,weapon); recorder.add_attack(u,target,weapon);
game_events::fire("attack",u,target); game_events::fire("attack",u,target);

View file

@ -21,10 +21,10 @@
#include <sstream> #include <sstream>
namespace { namespace {
const std::vector<team>* teams = NULL; std::vector<team>* teams = NULL;
} }
teams_manager::teams_manager(const std::vector<team>& teams_list) teams_manager::teams_manager(std::vector<team>& teams_list)
{ {
teams = &teams_list; teams = &teams_list;
} }
@ -272,7 +272,31 @@ void team::write(config& cfg) const
void team::get_tower(const gamemap::location& loc) void team::get_tower(const gamemap::location& loc)
{ {
towers_.insert(loc); if(teams == NULL || owns_tower(loc)) {
return;
}
std::cerr << "checking if village at " << (loc.x+1) << "," << (loc.y+1) << " is friendly\n";
//find out who owns the village at the moment
std::vector<team>::iterator i;
for(i = teams->begin(); i != teams->end(); ++i) {
if(i->owns_tower(loc)) {
break;
}
}
assert(&*i != this);
//only get neutral or enemy villages
const int side = i - teams->begin() + 1;
if(i == teams->end() || is_enemy(side)) {
if(i != teams->end()) {
i->lose_tower(loc);
}
towers_.insert(loc);
}
} }
void team::lose_tower(const gamemap::location& loc) void team::lose_tower(const gamemap::location& loc)

View file

@ -131,7 +131,7 @@ private:
}; };
struct teams_manager { struct teams_manager {
teams_manager(const std::vector<team>& teams); teams_manager(std::vector<team>& teams);
~teams_manager(); ~teams_manager();
}; };