Exemple #1
0
    public void StartGame()
    {
        int samsToBuild    = samsToSpawn;
        int nukesToBuild   = nukeLaunchersToSpawn;
        int shieldsToSpawn = shieldGeneratorsToSpawn;

        while (CitySlot.availableSlots > 0)
        {
            CitySlot slot = CitySlot.GetRandomEmptySlot();
            if (samsToBuild > 0)
            {
                slot.SetOccupant((BO_Static)manager.SpawnObjectFromPool(BaseObject.Type.Sam, slot.position));
                samsToBuild--;
            }
            else if (nukesToBuild > 0)
            {
                slot.SetOccupant((BO_Static)manager.SpawnObjectFromPool(BaseObject.Type.NukeLauncher, slot.position));
                nukesToBuild--;
            }
            else if (shieldsToSpawn > 0)
            {
                slot.SetOccupant((BO_Static)manager.SpawnObjectFromPool(BaseObject.Type.ShieldGenerator, slot.position));
                shieldsToSpawn--;
            }
            else
            {
                slot.SetOccupant((BO_Static)manager.SpawnObjectFromPool(BaseObject.Type.Building, slot.position));
            }
        }
    }
Exemple #2
0
        public bool BuildNewBuilding(BaseObject.Type typeToBuild)
        {
            if (CitySlot.HasAvailableSlot)
            {
                CitySlot s = CitySlot.GetRandomEmptySlot();
                if (!s.IsNull)
                {
                    s.SetOccupant(((BO_Static)manager.manager.SpawnObjectFromPool(typeToBuild, s.position)));
                    return(true);
                }
                else
                {
                    Debug.LogError("Get Random Empty Slot error?");
                    return(false);
                }
            }
            else
            {
                BaseObject.Type replaceType;
                CitySlot        s = CitySlot.nullSlot;
                switch (typeToBuild)
                {
                case BaseObject.Type.Sam:
                    replaceType = BaseObject.Type.Building;
                    if ((s = CitySlot.GetRandomSlotOfType(replaceType)).IsNull)
                    {
                        return(false);
                    }
                    break;

                case BaseObject.Type.NukeLauncher:
                    replaceType = BaseObject.Type.Building;

                    if ((s = CitySlot.GetRandomSlotOfType(replaceType)).IsNull)
                    {
                        replaceType = BaseObject.Type.Sam;
                    }
                    if ((s = CitySlot.GetRandomSlotOfType(replaceType)).IsNull)
                    {
                        return(false);
                    }
                    break;

                case BaseObject.Type.ShieldGenerator:
                    replaceType = BaseObject.Type.Building;
                    if ((s = CitySlot.GetRandomSlotOfType(replaceType)).IsNull)
                    {
                        replaceType = BaseObject.Type.Sam;
                    }
                    if ((s = CitySlot.GetRandomSlotOfType(replaceType)).IsNull)
                    {
                        return(false);
                    }
                    break;
                }

                if (s.IsNull)
                {
                    return(false);
                }
                s.occupant.GetReplaced();
                s.SetOccupant(((BO_Static)manager.manager.SpawnObjectFromPool(typeToBuild, s.position)));
                return(true);
            }
            return(false);
        }