Пример #1
0
 //==============
 // Initialize
 //==============
 public static void initialize()
 {
     plant_map = new PlantTile[CHUNK_WIDTH, CHUNK_HEIGHT];
     for (int j = 0; j < CHUNK_HEIGHT; ++j)
     {
         for (int i = 0; i < CHUNK_WIDTH; ++i)
         {
             plant_map[i, j] = new PlantTile();
         }
     }
     initPlantTypes();
 }
Пример #2
0
        //================
        // Helpers
        //================
        public static void fillMap()
        {
            // try spawn
            int i = 0;
            int j = 0;

            for (int y = top_left.y; y < top_left.y + CHUNK_HEIGHT; ++y)
            {
                i = 0;
                for (int x = top_left.x; x < top_left.x + CHUNK_WIDTH; ++x)
                {
                    if (map[i, j].isFlat)
                    {
                        Biomes.BiomeData biome = Biomes.BiomeSpawn.biome_ids[Biomes.BiomeSpawn.biome_map[i, j]];
                        foreach (string ps in biome.plants)
                        {
                            PlantObj p;
                            plant_ids.TryGetValue(Utils.getID(ps), out p);
                            if (p)
                            {
                                PlantObj p2;
                                plant_ids.TryGetValue(plant_map[i, j].ID, out p2);
                                if (!p2 || p.spawn_order >= p2.spawn_order)
                                {
                                    p.TrySpawn(i, j, x, y);
                                }
                            }
                        }
                    }
                    i++;
                }
                j++;
            }

            // actually spawn
            // this seperation allows me to replace chosen plants in the plant_map
            // before spawning in try_spawn by just changing the PlantTile after
            // comparing PlantObjs.spawn_order
            i = 0;
            j = 0;
            for (int y = top_left.y; y < top_left.y + CHUNK_HEIGHT; ++y)
            {
                i = 0;
                for (int x = top_left.x; x < top_left.x + CHUNK_WIDTH; ++x)
                {
                    if (map[i, j].isFlat)
                    {
                        PlantTile pt = plant_map[i, j];
                        if (pt.ID != Utils.getID("empty"))
                        {
                            PlantObj p;
                            PlantSpawn.plant_ids.TryGetValue(pt.ID, out p);
                            if (p)
                            {
                                p.Spawn(i, j, x, y, pt.stage);
                            }
                        }
                    }
                    i++;
                }
                j++;
            }
        }