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 specified square to being used by the specified person.  Requires marking first.
        /// </summary>
        /// <param name="worldX"></param>
        /// <param name="worldY"></param>
        /// <param name="user"></param>
        /// <param name="marker"></param>
        public void UseByPerson(int worldX, int worldY, Person user, FullTask marker)
        {
            if (!IsSquareMarkedByAndFor(worldX, worldY, marker, BuildingInteractionType.USE))
                throw new InvalidOperationException("Can't use what you didn't mark!");

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

            SetSquareState(worldX, worldY, BuildingInteractionType.USE, BuildingAvailabilityType.IN_USE);
            users[localX, localY] = user;
        }
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>
        /// Gets an object, and does with it as appropriate based on the state of the building
        /// and the specific square.
        /// </summary>
        /// <param name="worldX"></param>
        /// <param name="worldY"></param>
        /// <param name="worldObject"></param>
        public void ReceiveObject(int worldX, int worldY, Carryable worldObject, FullTask marker)
        {
            if (!this.ContainsSquare(worldX, worldY))
                throw new ArgumentOutOfRangeException("This building does not contain the specified cell!");

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

            if (squareAvailabilityModes[localX, localY] != BuildingAvailabilityType.MARKED)
                throw new NotImplementedException("Can't send an object without marking the square first.");

            switch (squareActionModes[localX, localY])
            {
                case BuildingInteractionType.STORAGE:
                    if (!IsSquareMarkedByAndFor(worldX, worldY, marker, BuildingInteractionType.STORAGE))
                        throw new InvalidOperationException("Cell is not marked for storage by this marker, so cannot be used for storage by this marker!");

                    if (!IsSquareMarkedByAndFor(worldX, worldY, marker, BuildingInteractionType.STORAGE))
                        throw new InvalidOperationException("Can't occupy without marking!");

                    SetSquareState(worldX, worldY, BuildingInteractionType.STORAGE, BuildingAvailabilityType.IN_USE);
                    occupants[localX, localY] = worldObject;

                    worldObject.GetPutInStockpile(this);

                    break;

                case BuildingInteractionType.LOAD_BUILDING_MATERIALS:
                    if (!IsSquareMarkedByAndFor(worldX, worldY, marker, BuildingInteractionType.LOAD_BUILDING_MATERIALS))
                        throw new InvalidOperationException("Wrong marker or coordinate.");

                    materials[localX, localY, materialIndices[localX, localY]] = worldObject;
                    materialIndices[localX, localY]++;

                    worldObject.GetUsedAsMaterial();

                    if (materialIndices[localX, localY] == NumberOfMaterialsPerSquare)
                        this.SetSquareState(worldX, worldY, BuildingInteractionType.BUILD, BuildingAvailabilityType.AVAILABLE);
                    else
                        this.SetSquareState(worldX, worldY, BuildingInteractionType.LOAD_BUILDING_MATERIALS, BuildingAvailabilityType.AVAILABLE);

                    break;

                default:
                    throw new NotImplementedException("Unclear how to receive an object in state " + squareActionModes[localX, localY]);
            }
        }
Exemple #5
0
        /// <summary>
        /// Attempts to build up the square in the building.
        /// Throws a fit if the square is not in the building, or
        /// if the square specified is not Unbuilt.
        /// </summary>
        /// <param name="worldX"></param>
        /// <param name="worldY"></param>
        public void BuildSquare(int worldX, int worldY, FullTask marker)
        {
            if (!this.ContainsSquare(worldX, worldY))
                throw new ArgumentOutOfRangeException("The specified cell is not in the building!");

            if (!this.IsSquareMarkedByAndFor(worldX, worldY, marker, BuildingInteractionType.BUILD))
                throw new InvalidOperationException("Have to mark the square first!");

            setSquareToBuilt(worldX, worldY);
        }
Exemple #6
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;
        }
        public override void UnMarkForCollection(FullTask collector)
        {
            if (this.currentState != CarryableState.MARKED_FOR_COLLECTION)
                throw new InvalidOperationException("This is not marked for collection!");

            if (IntendedCollector != collector)
                throw new InvalidOperationException("Only the marker can unmark the marked, and you are not it!");

            this.currentState = CarryableState.LOOSE;
            intendedCollector = null;
        }
        public override void MarkForCollection(FullTask collector)
        {
            if (!this.IsAvailableForUse)
                throw new InvalidOperationException("Not available for use!");

            currentState = CarryableState.MARKED_FOR_COLLECTION;
            intendedCollector = collector;
        }
        public override void GetUsedAsMaterial()
        {
            if (!IsBeingCarried)
                throw new InvalidOperationException("Isn't being carried right now.");

            carryingPerson = null;
            intendedCollector = null;

            this.currentState = CarryableState.LOCKED_AS_MATERIAL;
        }
        public override void GetPutInStockpile(Building stockpile)
        {
            if (!IsBeingCarried)
                throw new InvalidOperationException("Isn't being carried right now.");

            carryingPerson = null;
            intendedCollector = null;
            currentStockpile = stockpile;

            this.currentState = CarryableState.IN_STOCKPILE;
        }
        public override void Drop()
        {
            if (!IsBeingCarried)
                throw new InvalidOperationException("Isn't being carried right now.");

            carryingPerson = null;
            intendedCollector = null;

            currentState = CarryableState.LOOSE;
        }