- it is now possible to explicitly specify which units should count towards victory conditions. In the unit's xml file add:

<?xml version="1.0" standalone="no"?>
<unit>
	<parameters>
               <!-- valid values are true or false for this optional parameter -->
		<count-in-victory-conditions value="false"/>
        </parameters>
</unit>
This commit is contained in:
Mark Vejvoda 2012-05-03 20:25:35 +00:00
parent 0120c5211a
commit 3b9f799d26
4 changed files with 46 additions and 3 deletions

View File

@ -3263,7 +3263,8 @@ void Game::checkWinnerStandard() {
std::map<int,int> teamsAlive;
for(int i = 0; i < world.getFactionCount(); ++i) {
if(i != world.getThisFactionIndex()) {
if(hasBuilding(world.getFaction(i))) {
//if(hasBuilding(world.getFaction(i))) {
if(factionLostGame(world.getFaction(i)) == false) {
teamsAlive[world.getFaction(i)->getTeam()] = teamsAlive[world.getFaction(i)->getTeam()] + 1;
}
}
@ -3306,7 +3307,8 @@ void Game::checkWinnerStandard() {
else {
//lose
bool lose= false;
if(hasBuilding(world.getThisFaction()) == false) {
//if(hasBuilding(world.getThisFaction()) == false) {
if(factionLostGame(world.getThisFaction()) == true) {
lose= true;
for(int i=0; i<world.getFactionCount(); ++i) {
if(world.getFaction(i)->getPersonalityType() != fpt_Observer) {
@ -3342,7 +3344,9 @@ void Game::checkWinnerStandard() {
for(int i = 0; i < world.getFactionCount(); ++i) {
if(i != world.getThisFactionIndex()) {
if(world.getFaction(i)->getPersonalityType() != fpt_Observer) {
if(hasBuilding(world.getFaction(i)) && world.getFaction(i)->isAlly(world.getThisFaction()) == false) {
//if(hasBuilding(world.getFaction(i)) &&
if(factionLostGame(world.getFaction(i)) == false &&
world.getFaction(i)->isAlly(world.getThisFaction()) == false) {
win= false;
}
}
@ -3413,6 +3417,22 @@ void Game::checkWinnerScripted() {
}
}
bool Game::factionLostGame(const Faction *faction) {
for(int i=0; i<faction->getUnitCount(); ++i) {
const UnitType *ut = faction->getUnit(i)->getType();
if(ut->getCountInVictoryConditions() == ucvcNotSet) {
if(faction->getUnit(i)->getType()->hasSkillClass(scBeBuilt)) {
return false;
}
}
else if(ut->getCountInVictoryConditions() == ucvcTrue) {
return false;
}
}
return true;
}
bool Game::hasBuilding(const Faction *faction) {
for(int i=0; i<faction->getUnitCount(); ++i) {
if(faction->getUnit(i)->getType()->hasSkillClass(scBeBuilt)) {

View File

@ -256,6 +256,7 @@ private:
void checkWinnerStandard();
void checkWinnerScripted();
bool hasBuilding(const Faction *faction);
bool factionLostGame(const Faction *faction);
void incSpeed();
void decSpeed();
int getUpdateLoops();

View File

@ -76,6 +76,7 @@ const char *UnitType::propertyNames[]= {"burnable", "rotated_climb"};
UnitType::UnitType() : ProducibleType() {
countInVictoryConditions = ucvcNotSet;
meetingPointImage = NULL;
lightColor= Vec3f(0.f);
light= false;
@ -173,6 +174,16 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, const
const XmlNode *parametersNode= unitNode->getChild("parameters");
if(parametersNode->hasChild("count-in-victory-conditions") == true) {
bool countUnit = parametersNode->getChild("count-in-victory-conditions")->getAttribute("value")->getBoolValue();
if(countUnit == true) {
countInVictoryConditions = ucvcTrue;
}
else {
countInVictoryConditions = ucvcFalse;
}
}
//size
//checkItemInVault(&(this->size),this->size);
size= parametersNode->getChild("size")->getAttribute("value")->getIntValue();
@ -1053,6 +1064,8 @@ std::string UnitType::toString() const {
result += " meetingPoint = " + intToStr(meetingPoint);
result += " countInVictoryConditions = " + intToStr(countInVictoryConditions);
return result;
}

View File

@ -77,6 +77,12 @@ enum UnitClass {
typedef vector<UnitParticleSystemType*> DamageParticleSystemTypes;
enum UnitCountsInVictoryConditions {
ucvcNotSet,
ucvcTrue,
ucvcFalse
};
class UnitType: public ProducibleType, public ValueCheckerVault {
public:
enum Property {
@ -148,6 +154,8 @@ private:
const CommandType *firstCommandTypeOfClass[ccCount];
const SkillType *firstSkillTypeOfClass[scCount];
UnitCountsInVictoryConditions countInVictoryConditions;
public:
//creation and loading
UnitType();
@ -159,6 +167,7 @@ public:
virtual string getName(bool translatedValue=false) const;
UnitCountsInVictoryConditions getCountInVictoryConditions() const { return countInVictoryConditions; }
//get
inline int getId() const {return id;}
inline int getMaxHp() const {return maxHp;}