use a tag trait to determine what actors must be destroyed in order to win/lose

This commit is contained in:
Chris Forbes
2010-04-23 20:42:17 +12:00
parent 826373ae75
commit b20a8d193e
5 changed files with 14 additions and 10 deletions

View File

@@ -18,23 +18,23 @@ namespace OpenRA.Traits
public bool HasLost { get; private set; }
public bool HasWon { get; private set; }
public VictoryConditions(Actor self)
{
}
public VictoryConditions(Actor self) { }
public void Tick(Actor self)
{
var info = self.Info.Traits.Get<VictoryConditionsInfo>();
var hasAnyBuildings = self.World.Queries.OwnedBy[self.Owner]
.WithTrait<Building>().Any();
var hasAnyShortGameUnits = self.World.Queries.OwnedBy[self.Owner]
.Any(a => info.ShortGameUnits.Contains(a.Info.Name));
var hasAnything = self.World.Queries.OwnedBy[self.Owner]
.WithTrait<MustBeDestroyed>().Any();
var hasLost = !(hasAnyBuildings || hasAnyShortGameUnits);
if (hasLost && !HasLost)
if (!hasAnything && !HasLost)
Game.Debug("{0} is defeated.".F(self.Owner.PlayerName));
HasLost = hasLost;
HasLost = !hasAnything;
}
}
/* tag trait for things that must be destroyed for a short game to end */
class MustBeDestroyedInfo : TraitInfo<MustBeDestroyed> { }
class MustBeDestroyed { }
}