Example #1
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]);
            }
        }