/// <summary> /// Updates the treasure. All of the pirates' objects + some of the map object need to be updated BEFORE calling this method /// </summary> /// <param name="map">Both map.GetFreeToTakeTreasures() and map.GetPirateAt() need to be updated BEFORE calling this method</param> public void Update(Map map) { // if the pirate doesn't know in advance what he's carrying if (map.GetTreasures(TreasureState.FreeToTake).Contains(this)) { // the FreeToTake list is updated, thus this treasure is free to take this.state = TreasureState.FreeToTake; this.carryingPirate = null; this.location = this.InitialLocation; } else { // the treasure is NOT FreeToTake // lets divide the cases, based on the last state of the treasure switch (this.State) { case TreasureState.FreeToTake: // if the treasure was free to take last turn and now is not, then it must be carried right now by the pirate // who is at its initial location this.state = TreasureState.BeingCarried; this.carryingPirate = map.GetPirateOn(this.InitialLocation); // the map's pirate matrix is updated this.location = this.InitialLocation; break; case TreasureState.BeingCarried: // if the treasure was being carried last turn, the treasure will be taken if and only if the carrying pirate is now // at its initial location and is free. Otherwise, it will be carried by the same pirate (if it is still carrying something) // or by the pirate at the treasure's initial location (not sure if it is even possible) if (this.CarryingPirate.Location.Equals(this.CarryingPirate.InitialLocation) && this.CarryingPirate.State == PirateState.Free) { this.state = TreasureState.Taken; this.carryingPirate = null; this.location = null; } else { if (this.CarryingPirate.State == PirateState.CarryingTreasure) { // only need to update the location of the treasure this.location = this.CarryingPirate.Location; } else { // only need to update the location and the carrying pirate this.carryingPirate = map.GetPirateOn(this.InitialLocation); this.location = this.InitialLocation; } } break; case TreasureState.Taken: // if the treasure was taken last turn, then it must also be taken now; there is nothing to update break; } } // if the pirate DOES know in advance what he's carrying //// if the treasure is free //if (map.GetTreasures(TreasureState.FreeToTake).Contains(this)) //{ // // the FreeToTake list is updated, thus this treasure is free to take // this.state = TreasureState.FreeToTake; // this.carryingPirate = null; // this.location = this.InitialLocation; //} //else //{ // // else, assume the treasure is taken, and change it if the treasure is being carried // this.state = TreasureState.Taken; // this.carryingPirate = null; // this.location = null; // foreach (Pirate p in map.MyPirateManager.GetAllPirates().Union(map.EnemyPirateManager.GetAllPirates())) // { // if ("p carries this.Id") // <-- change the check here, to see if p actually carries this treasure // { // this.state = TreasureState.BeingCarried; // this.carryingPirate = p; // this.location = p.Location; // } // } //} }
/// <summary> /// Returns the predicted location of the pirate, or null if no prediction was made /// </summary> public Location PredictMovement(Pirate p) { return(this.movementPrediction.Predict(p)); }
/// <summary> /// Returns a list of possible immediate destinations for the sail and the calculated distance to the destination /// </summary> /// <param name="pirate">The start location</param> /// <param name="to">The destination</param> /// <param name="minToDistance">The minimum distance from the destination, which is OK to get to</param> /// <param name="maxToDistance">The maximum distance from the destination, which is OK to get to</param> /// <param name="dontStayInRange">should you avoid staying in the attack range of an enemy pirate</param> /// <param name="disallowedTerrain">the list of disallowed terrain to NOT walk on</param> /// <returns>A list of possible immediate destinations for the sail and their calculated distance to the destination</returns> public List <KeyValuePair <Location, int> > GetCompleteSailOptions(Pirate pirate, ILocateable to, int minToDistance, int maxToDistance, bool dontStayInRange, params Terrain[] disallowedTerrain) { return(this.map.SailManager.GetCompleteSailOptions(pirate, to, minToDistance, maxToDistance, dontStayInRange, disallowedTerrain)); }
/// <summary> /// Returns a list of possible immediate destinations for the sail and the calculated distance to the destination /// </summary> /// <param name="pirate">The start location</param> /// <param name="to">The destination</param> /// <param name="disallowedTerrain">the list of disallowed terrain to NOT walk on</param> /// <returns>A list of possible immediate destinations for the sail and their calculated distance to the destination</returns> public List <KeyValuePair <Location, int> > GetCompleteSailOptions(Pirate pirate, ILocateable to, params Terrain[] disallowedTerrain) { return(this.map.SailManager.GetCompleteSailOptions(pirate, to, disallowedTerrain)); }
/// <summary> /// Returns the naive sail options that the native game object returns /// </summary> public List <Location> GetNaiveSailOptions(Pirate pirate, ILocateable destination, int moves) { return(this.map.SailManager.GetNaiveSailOptions(pirate, destination, moves)); }