/// <summary> /// Tries to add the resources of another ResourcesPack into this one, if they do not overlap /// </summary> /// <returns>Was the addition successful (and they did not overlap)</returns> public bool AddResources(ResourcesPack other) { // if the ResourcesPacks overlap if (this.Overlaps(other)) { return(false); } // else, the addition is possible! this.myPirates |= other.myPirates; this.enemyPirates |= other.enemyPirates; this.treasures |= other.treasures; this.powerups |= other.powerups; this.freedUpLocations.UnionWith(other.freedUpLocations); this.takenLocations.UnionWith(other.takenLocations); this.imaginaryResources.UnionWith(other.imaginaryResources); this.objectResources.UnionWith(other.objectResources); this.actions += other.actions; return(true); }
/// <summary> /// Checks if this ResourcesPack and the other ResourcesPack use overlapping resources /// </summary> public bool Overlaps(ResourcesPack other) { return((this.myPirates & other.myPirates) > 0 || // there are pirates overlapping (this.enemyPirates & other.enemyPirates) > 0 || // there are pirates overlapping (this.treasures & other.treasures) > 0 || // there are treasures overlapping (this.powerups & other.powerups) > 0 || // there are powerups overlapping this.takenLocations.Overlaps(other.takenLocations) || this.imaginaryResources.Overlaps(other.imaginaryResources) || this.objectResources.Overlaps(other.objectResources) || this.actions + other.actions > this.game.ActionsPerTurn); }
/// <summary> /// Creates a new ResourcesPack, based on the pack given /// </summary> public ResourcesPack(ResourcesPack other) { this.myPirates = other.myPirates; this.enemyPirates = other.enemyPirates; this.treasures = other.treasures; this.powerups = other.powerups; this.freedUpLocations = new HashSet <Location>(other.freedUpLocations); this.takenLocations = new HashSet <Location>(other.takenLocations); this.imaginaryResources = new HashSet <int>(other.imaginaryResources); this.objectResources = new HashSet <object>(other.objectResources); this.actions = other.actions; this.game = other.game; }
/// <summary> /// Removes the resources in the other ResourcesPack from this one /// </summary> public void RemoveResources(ResourcesPack other) { if (other == null) { return; } this.myPirates -= this.myPirates & other.myPirates; this.enemyPirates -= this.enemyPirates & other.enemyPirates; this.treasures -= this.treasures & other.treasures; this.powerups -= this.powerups & other.powerups; this.takenLocations.ExceptWith(other.takenLocations); this.freedUpLocations.ExceptWith(other.freedUpLocations); this.imaginaryResources.ExceptWith(other.imaginaryResources); this.objectResources.ExceptWith(other.objectResources); this.actions -= other.actions; }