allow specifying owner type in building restriction has-unit

This commit is contained in:
Tim Felgentreff 2015-09-17 11:18:30 +02:00
parent 94ec3ca1ae
commit 2a0073c9d5
3 changed files with 24 additions and 1 deletions

View file

@ -440,6 +440,7 @@ public:
DistanceTypeType CountType;
std::string RestrictTypeName;
CUnitType *RestrictType;
std::string RestrictTypeOwner;
};
class CBuildRestrictionSurroundedBy : public CBuildRestriction

View file

@ -184,7 +184,27 @@ bool CBuildRestrictionHasUnit::Check(const CUnit *builder, const CUnitType &type
Vec2i pos1(0, 0);
Vec2i pos2(0, 0);
CPlayer* player = builder != NULL ? builder->Player : ThisPlayer;
int count = player->GetUnitTotalCount(*this->RestrictType);
int count = 0;
if (this->RestrictTypeOwner.size() == 0 || !this->RestrictTypeOwner.compare("self")) {
count = player->GetUnitTotalCount(*this->RestrictType);
} else if (!this->RestrictTypeOwner.compare("allied")) {
count = player->GetUnitTotalCount(*this->RestrictType);
for (int i = 0; i < NumPlayers; i++) {
if (player->IsAllied(Players[i])) {
count += Players[i].GetUnitTotalCount(*this->RestrictType);
}
}
} else if (!this->RestrictTypeOwner.compare("enemy")) {
for (int i = 0; i < NumPlayers; i++) {
if (player->IsEnemy(Players[i])) {
count += Players[i].GetUnitTotalCount(*this->RestrictType);
}
}
} else if (!this->RestrictTypeOwner.compare("any")) {
for (int i = 0; i < NumPlayers; i++) {
count += Players[i].GetUnitTotalCount(*this->RestrictType);
}
}
switch (this->CountType)
{
case LessThan: return count < this->Count;

View file

@ -314,6 +314,8 @@ static void ParseBuildingRules(lua_State *l, std::vector<CBuildRestriction *> &b
value = LuaToString(l, -2);
if (!strcmp(value, "Type")) {
b->RestrictTypeName = LuaToString(l, -1);
} else if (!strcmp(value, "Owner")) {
b->RestrictTypeOwner = LuaToString(l, -1);
} else if (!strcmp(value, "Count")) {
b->Count = LuaToNumber(l, -1);
} else if (!strcmp(value, "CountType")) {