Exemple #1
0
        /// <summary>
        /// Unmarks the square for use by the specified marker.  Current interaction type must match the
        /// supplied parameter, and the square must be marked for the specified task.
        /// </summary>
        /// <param name="worldX"></param>
        /// <param name="worldY"></param>
        /// <param name="marker"></param>
        /// <param name="bit"></param>
        public void UnMarkSquare(int worldX, int worldY, FullTask marker, BuildingInteractionType bit)
        {
            if (!this.IsSquareMarkedByAndFor(worldX, worldY, marker, bit))
                throw new InvalidOperationException("Can't unmark without marking!");

            int localX = worldX - XMin;
            int localY = worldY - YMin;

            SetSquareState(worldX, worldY, bit, BuildingAvailabilityType.AVAILABLE);
            markers[localX, localY] = null;
        }
Exemple #2
0
        /// <summary>
        /// Sets the designated square's occupancy status to state.
        /// This method maintains all the counts appropriately.
        /// </summary>
        /// <param name="worldX"></param>
        /// <param name="worldY"></param>
        /// <param name="bit"></param>
        /// <param name="bat"></param>
        protected void SetSquareState(int worldX, int worldY, BuildingInteractionType bit, BuildingAvailabilityType bat)
        {
            int localX = worldX - XMin;
            int localY = worldY - YMin;

            modeCounts[Tuple.Create(squareActionModes[localX, localY], squareAvailabilityModes[localX, localY])] -= 1;

            squareAvailabilityModes[localX, localY] = bat;
            squareActionModes[localX, localY] = bit;

            modeCounts[Tuple.Create(bit, bat)] += 1;
        }
Exemple #3
0
        /// <summary>
        /// Marks the square for use by the specified marker.  Current interaction type must match the
        /// supplied parameter, and the square supplied must be available.
        /// </summary>
        /// <param name="worldX"></param>
        /// <param name="worldY"></param>
        /// <param name="marker"></param>
        /// <param name="bit"></param>
        public void MarkSquare(int worldX, int worldY, FullTask marker, BuildingInteractionType bit)
        {
            if (!this.ContainsSquare(worldX, worldY))
                throw new InvalidOperationException("Cell is not in building.");

            int localX = worldX - XMin;
            int localY = worldY - YMin;

            BuildingInteractionType currentBit = squareActionModes[localX, localY];
            BuildingAvailabilityType currentBat = squareAvailabilityModes[localX, localY];

            if (currentBit != bit || currentBat != BuildingAvailabilityType.AVAILABLE)
                throw new InvalidOperationException("Building is not available for use as " + bit.ToString());

            SetSquareState(worldX, worldY, bit, BuildingAvailabilityType.MARKED);
            markers[localX, localY] = marker;
        }
Exemple #4
0
        /// <summary>
        /// Returns true if the specified square is marked by "marker" and is intended for the interaction type "bit."
        /// Returns false otherwise.
        /// 
        /// Throws a fit if (worldX,worldY) are not in the building.
        /// </summary>
        /// <param name="worldX"></param>
        /// <param name="worldY"></param>
        /// <param name="marker"></param>
        /// <param name="bit"></param>
        /// <returns></returns>
        public bool IsSquareMarkedByAndFor(int worldX, int worldY, FullTask marker, BuildingInteractionType bit)
        {
            if (!this.ContainsSquare(worldX, worldY))
                throw new InvalidOperationException("Cell is not in the building.");

            int localX = worldX - XMin;
            int localY = worldY - YMin;

            if (squareAvailabilityModes[localX, localY] != BuildingAvailabilityType.MARKED)
                return false;

            return markers[localX, localY] == marker;
        }
Exemple #5
0
 /// <summary>
 /// Whether or not there is a square in this building which is available for the supplied interaction type.
 /// </summary>
 /// <param name="bit"></param>
 /// <returns></returns>
 public bool HasAvailableSquare(BuildingInteractionType bit)
 {
     return modeCounts[Tuple.Create(bit, BuildingAvailabilityType.AVAILABLE)] > 0;
 }
Exemple #6
0
        /// <summary>
        /// Returns the world coordinates for the next unbuilt
        /// square which is available for the specified interaction.  Throws a fit
        /// if none exist.
        /// </summary>
        /// <param name="bit"></param>
        /// <returns></returns>
        public Point GetNextAvailableSquare(BuildingInteractionType bit)
        {
            for (int x = 0; x < Width; x++)
            {
                for (int y = 0; y < Height; y++)
                {
                    if (squareActionModes[x, y] == bit && squareAvailabilityModes[x, y] == BuildingAvailabilityType.AVAILABLE)
                    {
                        return new Point(x + XMin, y + YMin);
                    }
                }
            }

            throw new InvalidOperationException("There are no unbuilt squares!  Check first!");
        }
Exemple #7
0
 /// <summary>
 /// Enumerate all squares which are available for the specified interaction type.
 /// </summary>
 /// <param name="bit"></param>
 /// <returns></returns>
 public IEnumerable<Point> AvailableSquares(BuildingInteractionType bit)
 {
     for (int x = 0; x < Width; x++)
     {
         for (int y = 0; y < Height; y++)
         {
             if (squareActionModes[x, y] == bit && squareAvailabilityModes[x, y] == BuildingAvailabilityType.AVAILABLE)
             {
                 yield return new Point(x + XMin, y + YMin);
             }
         }
     }
 }