Exemplo n.º 1
0
    //xi yi -> plant group list's center.
    public void AddPlantToGroup(MapTileInfo[,] mapTiles, int xi, int yi, PlantGroupInfo info, PlantGroupTableInfo tableInfo)
    {
        int range = tableInfo.GroupRange;

        PlantTableInfo plantInfo = null;
        Plant          plant     = null;

        for (int x_i = xi - range; x_i < xi + range; x_i++)
        {
            if (x_i < 0)
            {
                continue;
            }
            if (x_i >= MapTileInfo.ColumnCount)
            {
                break;
            }

            for (int y_i = yi - range; y_i < yi + range; y_i++)
            {
                if (y_i < 0)
                {
                    continue;
                }
                if (y_i >= MapTileInfo.RowCount)
                {
                    break;
                }
                if (JUtil.NextFloat() > tableInfo.Chance)
                {
                    continue;
                }

                int         index   = JUtil.NextInt(0, tableInfo.Plants.Count);
                int         plantId = tableInfo.Plants [index];
                MapTileInfo curTile = mapTiles [x_i, y_i];

                if (curTile.GetBuildableObject <BuildableObject>() == null &&
                    TableManager.Instance.PlantList.TryGetValue(plantId, out plantInfo))
                {
                    if (!TableManager.Instance.IsAdaptableEnvironment(plantInfo.ProperTemperature, plantInfo.ProperHumidity, curTile.Temperature, curTile.Humidity))
                    {
                        continue;
                    }

                    GameObject obj = ResourcesManager.Instance.GetObject("Plant");

                    plant = obj.GetComponent <Plant> ();
                    plant.SetPlantInfo(plantInfo, x_i, y_i);
                    plant.transform.position = MapTile.IndexToPosition(x_i, y_i);

                    mapTiles [x_i, y_i].SetBuildableObject(plant);
                    info.AddPlant(plant);
                }
            }
        }
    }
Exemplo n.º 2
0
    public PlantGroupTableInfo GetAdaptablePlantGroup(float temperature, float humididy)
    {
        var iter = PlantGroupList.GetEnumerator();
        List <PlantGroupTableInfo> list = new List <PlantGroupTableInfo> ();

        while (iter.MoveNext())
        {
            PlantGroupTableInfo info = iter.Current.Value;
            if (IsAdaptableEnvironment(temperature, humididy, info.ProperTemperature, info.ProperHumidity))
            {
                list.Add(info);
            }
        }

        return(list.Count > 0 ? list [JUtil.NextInt(0, list.Count)] : null);
    }
Exemplo n.º 3
0
    public void CreateMapInfo(MapTileInfo[,] tileInfoList)
    {
        int columnCount = MapTileInfo.ColumnCount;
        int rowCount    = MapTileInfo.RowCount;

        //tileInfoList = new MapTileInfo[columnCount, rowCount];

        //Create Map First
        for (int x = 0; x < columnCount; x++)
        {
            for (int y = 0; y < rowCount; y++)
            {
                MapTileInfo info = new MapTileInfo();

                //this is for temp -> almost ground
                MapTileInfo.Type type = JUtil.NextInt(0, 75) != 0 ? MapTileInfo.Type.Ground : MapTileInfo.Type.Water;
                info.Init(x, y, type);
                tileInfoList [x, y] = info;
            }
        }

        int humididyRange = 5;

        //Set temperature and humidity
        for (int x = 0; x < columnCount; x++)
        {
            for (int y = 0; y < rowCount; y++)
            {
                if (tileInfoList[x, y].TileType == MapTileInfo.Type.Water)
                {
                    for (int tx = x - humididyRange; tx <= x + humididyRange; tx++)
                    {
                        if (tx < 0)
                        {
                            continue;
                        }
                        if (tx >= columnCount)
                        {
                            break;
                        }

                        for (int ty = y - humididyRange; ty <= y + humididyRange; ty++)
                        {
                            if (ty < 0)
                            {
                                continue;
                            }
                            if (ty >= rowCount)
                            {
                                break;
                            }
                            if (tileInfoList [tx, ty].TileType == MapTileInfo.Type.Water)
                            {
                                continue;
                            }

                            float temperature = 25;
                            float humidity    = 0;

                            if (Mathf.Abs(tx - x) == 5 || Mathf.Abs(ty - y) == 5)
                            {
                                humidity = 0.1f;
                            }
                            else if (Mathf.Abs(tx - x) == 4 || Mathf.Abs(ty - y) == 4)
                            {
                                humidity = 0.2f;
                            }
                            else if (Mathf.Abs(tx - x) == 3 || Mathf.Abs(ty - y) == 3)
                            {
                                humidity = 0.3f;
                            }
                            else if (Mathf.Abs(tx - x) == 2 || Mathf.Abs(ty - y) == 2)
                            {
                                humidity = 0.4f;
                            }
                            else if (Mathf.Abs(tx - x) == 1 || Mathf.Abs(ty - y) == 1)
                            {
                                humidity = 0.5f;
                            }

                            SetHumidity(tileInfoList[tx, ty], humidity);
                            tileInfoList [tx, ty].Temperature = temperature;
                        }
                    }
                }
            }
        }
    }