private void EvaluateTileAndNeighborsHeat(
     EnvironmentTileControl_3d mTileControl,
     List <EnvironmentTileControl_3d> neighbors
     )
 {
     // TODO
 }
 private void EvaluateTileAndNeighbors(
     EnvironmentTileControl_3d mTileControl,
     List <EnvironmentTileControl_3d> neighbors
     )
 {
     // water
     EvaluateTileAndNeighborsWater(mTileControl, neighbors);
     // TODO: heat
     // EvaluateTileAndNeighborsHeat(mTileControl, neighbors);
 }
    private void SetTileNeighbors(GameObject tile)
    {
        EnvironmentTileControl_3d tileControl = tile.GetComponent <EnvironmentTileControl_3d>();

        int[] tileCoord =
        {
            (int)tile.transform.position.x,
            (int)tile.transform.position.z
        };
        int[] upCoord = { tileCoord[0], tileCoord[1] + 1 };
        tileControl.neighborUp = GetTileAtCoordinate(upCoord);
        int[] rightCoord = { tileCoord[0] + 1, tileCoord[1] };
        tileControl.neighborRight = GetTileAtCoordinate(rightCoord);
        int[] downCoord = { tileCoord[0], tileCoord[1] - 1 };
        tileControl.neighborDown = GetTileAtCoordinate(downCoord);
        int[] leftCoord = { tileCoord[0] - 1, tileCoord[1] };
        tileControl.neighborLeft = GetTileAtCoordinate(leftCoord);
    }
 public void EvaluateEnvironmentTiles()
 {
     foreach (GameObject tile in environmentTiles)
     {
         EnvironmentTileControl_3d tileControl = tile.GetComponent <EnvironmentTileControl_3d>();
         // evaluate current tile and neighbors
         EvaluateTileAndNeighbors(
             tileControl,
             tileControl.GetTileNeighborsAsList()
             );
     }
     foreach (GameObject tile in environmentTiles)
     {
         EnvironmentTileControl_3d tileControl = tile.GetComponent <EnvironmentTileControl_3d>();
         tileControl.ApplyUpdateFromTempValues();
         tileControl.SetAppearanceFromState();
     }
 }
Esempio n. 5
0
    public void UpdateInfo(GameObject tile)
    {
        EnvironmentTileControl_3d tileControl = tile.GetComponent <EnvironmentTileControl_3d>();
        string tileEarthTypeString            = string.Format("Earth Type: {0}", tileControl.earthType);
        string tileEarthAmountString          = string.Format("Earth Amount: {0}", tileControl.earth);
        string tileWaterString          = string.Format("Water Amount: {0}", tileControl.water);
        string tileEarthPlusWaterString = string.Format(
            "Water Level (Earth + Water): {0}",
            tileControl.earth + tileControl.water
            );
        string tileHeatString = string.Format("Heat: {0}", tileControl.heat);

        text.text = string.Format(
            "{0}\n{1}\n{2}\n{3}\n{4}",
            tileEarthTypeString,
            tileEarthAmountString,
            tileWaterString,
            tileEarthPlusWaterString,
            tileHeatString
            );
    }
    private void EvaluateTileAndNeighborsWater(
        EnvironmentTileControl_3d mTileControl,
        List <EnvironmentTileControl_3d> neighbors
        )
    {
        float waterFlowCoefficient   = mTileControl.GetWaterFlowCoefficient();
        float totalWaterDiff         = 0;
        int   participatingNeighbors = 0;

        foreach (EnvironmentTileControl_3d nTileControl in neighbors)
        {
            // calculate total water height diff
            float mWaterHeight = mTileControl.earth + mTileControl.water;
            float nWaterHeight = nTileControl.earth + nTileControl.water;
            if (mTileControl.water > 0 && mWaterHeight > nWaterHeight)
            {
                float waterDiff = mWaterHeight - nWaterHeight;
                totalWaterDiff         += waterDiff;
                participatingNeighbors += 1;
            }
        }
        // calculate total water available for transfer
        float waterAvailForTransfer = ((totalWaterDiff / 2) / participatingNeighbors) * waterFlowCoefficient;

        foreach (EnvironmentTileControl_3d nTileControl in neighbors)
        {
            // calculate water trasfer amount and commit transfer
            float mWaterHeight = mTileControl.earth + mTileControl.water;
            float nWaterHeight = nTileControl.earth + nTileControl.water;
            if (mTileControl.water > 0 && mWaterHeight > nWaterHeight)
            {
                float waterDiff       = mWaterHeight - nWaterHeight;
                float waterToTransfer = (waterDiff / totalWaterDiff) * waterAvailForTransfer;
                nTileControl.updateWaterAmount += waterToTransfer;
                mTileControl.updateWaterAmount -= waterToTransfer;

                // DEBUG: should never see water go below 0 or above limit
                bool printDebug = false;
                if (printDebug && (waterToTransfer + nTileControl.water < 0 || waterToTransfer + nTileControl.water > 200))
                {
                    Debug.LogFormat(
                        "=====================>"
                        + "\nmain tile x={0} y={1}\nneighbor tile x={2} y={3}"
                        + "\nparticipating neighbors: {4}"
                        + "\ntotal water diff: {5}"
                        + "\nwater available for transfer: {6}"
                        + "\nlocal water diff: {7}"
                        + "\nlocal water to transfer: {8}",
                        mTileControl.gameObject.transform.position.x,
                        mTileControl.gameObject.transform.position.z,
                        nTileControl.gameObject.transform.position.x,
                        nTileControl.gameObject.transform.position.z,
                        participatingNeighbors,
                        totalWaterDiff,
                        waterAvailForTransfer,
                        waterDiff,
                        waterToTransfer
                        );
                }
            }
        }
    }