made it so that allies cannot capture each other's villages
This commit is contained in:
parent
4ce4cada4e
commit
39cc9b5a52
4 changed files with 42 additions and 11 deletions
|
@ -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,
|
||||
size_t team_num, const unit_map& units)
|
||||
{
|
||||
for(size_t i = 0; i != teams.size(); ++i) {
|
||||
if(i != team_num && teams[i].owns_tower(loc)) {
|
||||
teams[i].lose_tower(loc);
|
||||
}
|
||||
if(team_num >= teams.size()) {
|
||||
return;
|
||||
}
|
||||
|
||||
//if the side doesn't have a leader, captured villages become neutral
|
||||
const bool has_leader = find_leader(units,int(team_num+1)) != units.end();
|
||||
if(has_leader && team_num < teams.size())
|
||||
//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();
|
||||
if(has_leader == false) {
|
||||
teams[team_num].lose_tower(loc);
|
||||
}
|
||||
}
|
||||
|
||||
std::map<gamemap::location,unit>::iterator
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
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);
|
||||
game_events::fire("attack",u,target);
|
||||
|
||||
|
|
28
src/team.cpp
28
src/team.cpp
|
@ -21,10 +21,10 @@
|
|||
#include <sstream>
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -272,8 +272,32 @@ void team::write(config& cfg) const
|
|||
|
||||
void team::get_tower(const gamemap::location& 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)
|
||||
{
|
||||
|
|
|
@ -131,7 +131,7 @@ private:
|
|||
};
|
||||
|
||||
struct teams_manager {
|
||||
teams_manager(const std::vector<team>& teams);
|
||||
teams_manager(std::vector<team>& teams);
|
||||
~teams_manager();
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue