Ejemplo n.º 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));
            }
        }
    }
Ejemplo n.º 2
0
 private static bool TypeAdd(CitySlot toAdd)
 {
     if (toAdd.hasOccupant)
     {
         TypeToList(toAdd.occupant.type).Add(toAdd);
         return(true);
     }
     Debug.LogError("Type add on an empty city slot? fill city slot first...");
     return(false);
 }
Ejemplo n.º 3
0
        public static CitySlot[] CreateNewCity(SpawnManager manager)
        {
            boTypeDict = new Dictionary <BaseObject.Type, List <CitySlot> >();
            float totalSize = manager.citySize * 2;
            int   nbSlots   = Mathf.FloorToInt(totalSize / manager.buildingSeperation);

            city           = new CitySlot[nbSlots];
            freeSlotList   = new List <CitySlot>(nbSlots);
            availableSlots = nbSlots;

            for (int i = 0; i < nbSlots; i++)
            {
                city[i] = new CitySlot(i, new Vector3(manager.planetFloor.position.x + i * (manager.buildingSeperation) - (totalSize / 2), manager.planetFloor.position.y, 0));
                freeSlotList.Add(city[i]);
            }

            nullSlot = new CitySlot(-1, Vector3.zero);
            return(city);
        }
Ejemplo n.º 4
0
 private static bool TypeRemove(CitySlot toRemove)
 {
     if (toRemove.hasOccupant)
     {
         List <CitySlot> list = TypeToList(toRemove.occupant.type);
         if (list.Contains(toRemove))
         {
             list.Remove(toRemove);
             return(true);
         }
         else
         {
             Debug.Log("Trying to type remove an empty city slot.");
             return(false);
         }
     }
     Debug.LogError("Type add on an empty city slot? fill city slot first...");
     return(false);
 }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
 public CityManager(SpawnManager newMan) //float citySize, float buildingSeperation)
 {
     manager = newMan;
     CitySlot.CreateNewCity(manager);
 }
        public static ConcreteSettlement GenerateSettlement(NamelessGame namelessGame, WorldTile tile, TimelineLayer board,
                                                            IWorldProvider worldProvider)
        {
            var result = new ConcreteSettlement();

            int chunksPerTile = worldProvider.ChunkResolution / namelessGame.WorldSettings.WorldBoardWidth;

            var squareToCheck = 5;

            List <KeyValuePair <Point, Chunk> > allChunksToWorkWith = new List <KeyValuePair <Point, Chunk> >();

            //find chunks to work with
            for (int x = tile.WorldBoardPosiiton.X - squareToCheck; x <= tile.WorldBoardPosiiton.X + squareToCheck; x++)
            {
                for (int y = tile.WorldBoardPosiiton.Y - squareToCheck;
                     y <= tile.WorldBoardPosiiton.Y + squareToCheck;
                     y++)
                {
                    List <KeyValuePair <Point, Chunk> > chunks = new List <KeyValuePair <Point, Chunk> >();

                    int chunkX = x * chunksPerTile;
                    int chunkY = y * chunksPerTile;

                    for (int i = chunkX; i < chunkX + chunksPerTile; i++)
                    {
                        for (int j = chunkY; j < chunkY + chunksPerTile; j++)
                        {
                            var point = new Point(i, j);
                            chunks.Add(new KeyValuePair <Point, Chunk>(point, worldProvider.GetChunks()[point]));
                        }
                    }

                    foreach (var keyValuePair in chunks)
                    {
                        //place them into reality bubble for convenience
                        worldProvider.GetRealityBubbleChunks().Add(keyValuePair.Key, keyValuePair.Value);
                        worldProvider.RealityChunks.Add(keyValuePair.Value);
                        allChunksToWorkWith.Add(keyValuePair);
                    }
                }
            }

            Point minPoint, maxPoint;

            var firstChunk = allChunksToWorkWith.First().Value;

            minPoint = firstChunk.ChunkWorldMapLocationPoint;
            maxPoint = firstChunk.ChunkWorldMapLocationPoint;

            foreach (var keyValuePair in allChunksToWorkWith)
            {
                var currentPoint = keyValuePair.Value.ChunkWorldMapLocationPoint;
                if (currentPoint.X > maxPoint.X || currentPoint.Y > maxPoint.Y)
                {
                    maxPoint = currentPoint;
                }

                if (currentPoint.X < minPoint.X || currentPoint.Y < minPoint.Y)
                {
                    minPoint = currentPoint;
                }
            }

            maxPoint.X += Constants.ChunkSize;
            maxPoint.Y += Constants.ChunkSize;

            var maxVector = maxPoint.ToVector2();
            var minVector = minPoint.ToVector2();

            var center = (minVector + maxVector) / 2;

            var citySize    = 100;
            var streetWidth = 10;

            var slots = new CitySlot[citySize / streetWidth, citySize / streetWidth];



            GenerateCityBuildingForTest(center, namelessGame, worldProvider);



            result.Center = center.ToPoint();

            foreach (var keyValuePair in allChunksToWorkWith)
            {
                worldProvider.GetRealityBubbleChunks().Remove(keyValuePair.Key);
            }



            return(result);
        }