Example #1
0
    /// <summary>
    /// When destroyed, it's called
    /// </summary>
    public override void OnDestroy()
    {
        GameObject gridGO = GameObject.Find("GameController");

        if (gridGO != null)
        {
            ConstructionGrid grid     = gridGO.GetComponent <ConstructionGrid>();
            Vector3          disc_pos = grid.discretizeMapCoords(gameObject.transform.position);
            grid.liberatePosition(disc_pos);
        }

        ResourcesEvents.get.unregisterBuildingToEvents(this);

        base.OnDestroy();

        Assert.IsTrue(status == EntityStatus.DESTROYED);
    }
Example #2
0
        /// <summary>
        /// This this method in order to maintain the base, when someone destroys our buildings
        /// </summary>
        /// <param name="obj"></param>
        public void onDestroy(System.Object obj)
        {
            GameObject    gob      = (GameObject)obj;
            Vector3       position = gob.transform.position;
            float         yRot     = gob.transform.rotation.eulerAngles.y;
            BuildingTypes type     = gob.GetComponent <IGameEntity>().getType <BuildingTypes>();

            //Add back the building to the queue in order to reconstruct it as soon as it is possible
            buildingPrefs.Add(type);
            constructionGrid.liberatePosition(constructionGrid.discretizeMapCoords(position));

            //We need to inform the architect that new positions are avaliable
            StructureType buildingType = StructureType.RESOURCE_BUILDING;

            switch (type)
            {
            case BuildingTypes.FARM:
                buildingType = StructureType.RESOURCE_BUILDING;
                break;

            case BuildingTypes.MINE:
                buildingType = StructureType.RESOURCE_BUILDING;
                break;

            case BuildingTypes.SAWMILL:
                buildingType = StructureType.RESOURCE_BUILDING;
                break;

            case BuildingTypes.ARCHERY:
                buildingType = StructureType.MILITARY_BUILDING;
                break;

            case BuildingTypes.BARRACK:
                buildingType = StructureType.MILITARY_BUILDING;
                break;

            case BuildingTypes.STABLE:
                buildingType = StructureType.MILITARY_BUILDING;
                break;

            case BuildingTypes.ARTILLERY:
                buildingType = StructureType.MILITARY_BUILDING;
                break;

            case BuildingTypes.WORKSHOP:
                buildingType = StructureType.MILITARY_BUILDING;
                break;

            case BuildingTypes.ENT:
                buildingType = StructureType.MILITARY_BUILDING;
                break;

            case BuildingTypes.GRYPHON:
                buildingType = StructureType.MILITARY_BUILDING;
                break;

            case BuildingTypes.WALL:
                if (Mathf.Round(yRot) == 90f)
                {
                    buildingType = ai.race == Races.MEN ? StructureType.HORIZONTALL_WALL : StructureType.VERTICALL_WALL;
                }
                else
                {
                    buildingType = ai.race == Races.MEN ? StructureType.VERTICALL_WALL : StructureType.HORIZONTALL_WALL;
                }
                break;

            case BuildingTypes.WALLCORNER:
                buildingType = StructureType.CORNER_WALL;
                break;

            case BuildingTypes.WATCHTOWER:
                buildingType = StructureType.TOWER;
                break;

            default:
                Debug.Log("AIArchitect: Unknown type maibe there are new buildings?");
                break;
            }

            avaliablePositions[buildingType].Add(position);
        }