Example #1
0
    public int MovementCostToEnterHex(Hex hex)
    {
        //TODO override base movement cost based on our
        //movement mode + tile type (flying, walking etc)

        // Example of how to alter default movement
        //if (WeAreaHillWalker && hex.ElevationType == Hex.ELEVATION_TYPE.HILL)
        //return 1;

        //TODO implement other unit traits
        return(hex.BaseMovementCost(false, false, false, false, false));
    }
Example #2
0
    public int MovementCostToEnterHex(Hex hex)
    {
        // TODO:  Implement different movement traits

        return(hex.BaseMovementCost(false, false, false));
    }
    public void UpdateHexVisuals()
    {
        for (int column = 0; column < NumColumns; column++)
        {
            for (int row = 0; row < NumRows; row++)
            {
                Hex        h     = hexes[column, row];
                GameObject hexGO = hexToGameObjectMap[h];

                HexComponent hexComp = hexGO.GetComponentInChildren <HexComponent>();
                MeshRenderer mr      = hexGO.GetComponentInChildren <MeshRenderer>();
                MeshFilter   mf      = hexGO.GetComponentInChildren <MeshFilter>();


                if (h.Elevation >= HeightFlat && h.Elevation < HeightMountain)
                {
                    if (h.Moisture >= MoistureJungle)
                    {
                        mr.material   = MatGrasslands;
                        h.TerrainType = Hex.TERRAIN_TYPE.GRASSLANDS;
                        h.FeatureType = Hex.FEATURE_TYPE.RAINFOREST;

                        // Spawn trees
                        Vector3 p = hexGO.transform.position;
                        if (h.Elevation >= HeightHill)
                        {
                            p.y += 0.25f;
                        }


                        GameObject.Instantiate(JunglePrefab, p, Quaternion.identity, hexGO.transform);
                    }
                    else if (h.Moisture >= MoistureForest)
                    {
                        mr.material   = MatGrasslands;
                        h.TerrainType = Hex.TERRAIN_TYPE.GRASSLANDS;
                        h.FeatureType = Hex.FEATURE_TYPE.FOREST;

                        // Spawn trees
                        Vector3 p = hexGO.transform.position;
                        if (h.Elevation >= HeightHill)
                        {
                            p.y += 0.25f;
                        }
                        GameObject.Instantiate(ForestPrefab, p, Quaternion.identity, hexGO.transform);
                    }
                    else if (h.Moisture >= MoistureGrasslands)
                    {
                        mr.material   = MatGrasslands;
                        h.TerrainType = Hex.TERRAIN_TYPE.GRASSLANDS;
                    }
                    else if (h.Moisture >= MoisturePlains)
                    {
                        mr.material   = MatPlains;
                        h.TerrainType = Hex.TERRAIN_TYPE.PLAINS;
                    }
                    else
                    {
                        mr.material   = MatDesert;
                        h.TerrainType = Hex.TERRAIN_TYPE.DESERT;
                    }
                }

                if (h.Elevation >= HeightMountain)
                {
                    mr.material     = MatMountains;
                    mf.mesh         = MeshMountain;
                    h.ElevationType = Hex.ELEVATION_TYPE.MOUNTAIN;
                }
                else if (h.Elevation >= HeightHill)
                {
                    h.ElevationType        = Hex.ELEVATION_TYPE.HILL;
                    mf.mesh                = MeshHill;
                    hexComp.VerticalOffset = 0.25f;
                }
                else if (h.Elevation >= HeightFlat)
                {
                    h.ElevationType = Hex.ELEVATION_TYPE.FLAT;
                    mf.mesh         = MeshFlat;
                }
                else
                {
                    h.ElevationType = Hex.ELEVATION_TYPE.WATER;
                    mr.material     = MatOcean;
                    mf.mesh         = MeshWater;
                }

                hexGO.GetComponentInChildren <TextMesh>().text =
                    string.Format("{0},{1}\n{2}", column, row, h.BaseMovementCost(false, false, false));
            }
        }
    }
Example #4
0
    public void UpdateHexVisuals()
    {
        //loop through all our hexes
        for (int column = 0; column < numColumns; column++)
        {
            for (int row = 0; row < numRows; row++)
            {
                Hex        h     = hexes[column, row];
                GameObject hexGO = hexToGameObjectMap[h];

                //Set material and mesh
                //grab GameObject Mesh Renderer materials slot
                MeshRenderer mr = hexGO.GetComponentInChildren <MeshRenderer>();
                //grab GameObject Mesh Filter component
                MeshFilter mf = hexGO.GetComponentInChildren <MeshFilter>();

                //set moisture level
                if (h.Elevation >= flatHeight && h.Elevation < mountainHeight)
                {
                    if (h.Moisture >= MoistureJungle)
                    {
                        mr.material = MatGrasslands;
                        //Spawn jungle adjusting for hill height
                        Vector3 p = hexGO.transform.position;
                        if (h.Elevation >= hillHeight)
                        {
                            p.y += 0.25f;
                        }
                        h.MovementCost = 2; //jungles cost two to move through
                        GameObject.Instantiate(JunglePrefab, p, Quaternion.identity, hexGO.transform);
                    }
                    else if (h.Moisture >= MoistureForest)
                    {
                        mr.material = MatGrasslands;
                        //Spawn forests adjusting for hill height
                        Vector3 p = hexGO.transform.position;
                        if (h.Elevation >= hillHeight)
                        {
                            p.y += 0.25f;
                        }
                        h.MovementCost = 2; //forests cost two to move through
                        GameObject.Instantiate(ForestPrefab, p, Quaternion.identity, hexGO.transform);
                    }
                    else if (h.Moisture >= MoistureGrasslands)
                    {
                        mr.material = MatGrasslands;
                    }
                    else if (h.Moisture >= MoisturePlains)
                    {
                        mr.material = MatPlains;
                    }
                    else
                    {
                        mr.material = MatDesert; //set materials slot to ocean
                    }
                }

                //apply models to terrain based on elevation (will override mountain texture)
                if (h.Elevation >= mountainHeight)
                {
                    mr.material    = MatMountain;
                    mf.mesh        = MeshMountain;
                    h.MovementCost = -999; //mountains are impassable (this is so low the pathfinding will always go around it but need to figure out a better solution)
                }
                else if (h.Elevation >= hillHeight)
                {
                    mf.mesh        = MeshHill;
                    h.MovementCost = 2; //hills cost two to move through
                }
                else if (h.Elevation >= flatHeight)
                {
                    mf.mesh        = MeshFlat;
                    h.MovementCost = 1.001f; //adding small amount to terrain to reduce sizgzagging in path finding and favor hills over flatland (if paths are equal)
                }
                else
                {
                    mr.material    = MatOcean;  //set materials slot to ocean
                    mf.mesh        = MeshWater; //set materials slot to ocean
                    h.MovementCost = -999;      //TEMP: no walking on water either
                }

                //show debug hex coordinates
                hexGO.GetComponentInChildren <TextMesh>().text = string.Format("{0}, {1}\n{2}", column, row, h.BaseMovementCost());
            }
        }
    }
Example #5
0
 //Two helper functions for pathfinding
 public float MovementCostToEnterHex(Hex hex)
 {
     //TEST: Assume it costs one movement to enter a HEX
     //TODO: Override base movement cost based on movement mode & tile type
     return(hex.BaseMovementCost());
 }
Example #6
0
    public void UpdateHexVisuals()
    {
        for (int column = 0; column < numColumns; column++)
        {
            for (int row = 0; row < numRows; row++)
            {
                Hex          hex     = hexes[column, row];
                GameObject   hexGO   = hexToGameObjectMap[hex];
                HexComponent hexComp = hexGO.GetComponentInChildren <HexComponent>();
                MeshRenderer hexMR   = hexGO.GetComponentInChildren <MeshRenderer>();
                MeshFilter   hexMF   = hexGO.GetComponentInChildren <MeshFilter>();

                setHexTypeFromElevationAndMoisture(hex, hexMR, hexMF, hexGO, hexComp);
                hexGO.GetComponentInChildren <TextMesh>().text = string.Format("{0}, {1} \n{2}", column, row, hex.BaseMovementCost(false, false, false));
            }
        }
    }
    virtual public void GenerateMap()
    {
        //Generate ocean filled map
        //Some ways to do lists
        //List<List<Hex>> hexes = new List<List<Hex>>();
        //hexes[0] = new List<Hex>();

        hexes = new Hex[numColumns, numRows];
        hexToGameObjectMap = new Dictionary <Hex, GameObject>();
        gameObjectToHexMap = new Dictionary <GameObject, Hex>();

        for (int column = 0; column < numColumns; column++)
        {
            for (int row = 0; row < numRows; row++)
            {
                //Ocean hex
                Hex h = new Hex(this, column, row);
                h.Elevation = -0.5f;

                hexes[column, row] = h;

                //Instantiate a hex
                GameObject hexGO = (GameObject)Instantiate(HexPrefab, h.Position(), Quaternion.identity, this.transform);

                hexToGameObjectMap[h]     = hexGO;
                gameObjectToHexMap[hexGO] = h;


                h.TerrainType   = Hex.TERRAIN_TYPE.OCEAN;
                h.ElevationType = Hex.ELEVATION_TYPE.SHALLOWWATER;

                var _hexcomp = hexGO.GetComponent <HexComponent>();
                _hexcomp.Hex    = h;
                _hexcomp.HexMap = this;

                //Set the hex label
                hexGO.transform.GetChild(1).GetComponent <TextMeshPro>().text = string.Format("{0},{1}\n{2}", column, row, h.BaseMovementCost(false, false, false, false, false));
            }
        }

        //If our map doesn't move we can do this
        //StaticBatchingUtility.Combine(this.gameObject);
        UpdateHexVisuals();

        Unit unit = new Unit();

        //For Debug, let this unit build cities
        unit.CanBuildCities = true;

        SpawnUnitAt(unit, GameManager.instance.playerUnit, (int)GameManager.instance.playerStartPos.x, (int)GameManager.instance.playerStartPos.y);

        City city = new City();

        SpawnCityAt(city, GameManager.instance.CityLevel1Prefab, (int)GameManager.instance.playerStartPos.x + 1, (int)GameManager.instance.playerStartPos.y);
    }
 public int MovementCostToEnterHex(Hex hex)
 {
     // TODO:  Override base movement cost based on
     // our movement mode + tile type
     return(hex.BaseMovementCost());
 }
Example #9
0
    virtual public void GenerateMap()
    {
        hexes = new Hex[NumColumns, NumRows];
        hexToGameObjectMap = new Dictionary <Hex, GameObject>();
        gameObjectToHexMap = new Dictionary <GameObject, Hex>();

        for (int column = 0; column < NumColumns; column++)
        {
            for (int row = 0; row < NumRows; row++)
            {
                // Instantiate a hex
                Hex h = new Hex(this, column, row);
                h.Elevation = -0.5f;

                hexes[column, row] = h;

                Vector3 pos = h.PositionFromCamera(
                    Camera.main.transform.position,
                    NumRows,
                    NumColumns
                    );

                GameObject hexGO = (GameObject)Instantiate(
                    HexPrefab,
                    pos,
                    Quaternion.identity,
                    this.transform
                    );

                hexToGameObjectMap[h]     = hexGO;
                gameObjectToHexMap[hexGO] = h;

                h.TerrainType   = Hex.TERRAIN_TYPE.OCEAN;
                h.ElevationType = Hex.ELEVATION_TYPE.WATER;

                hexGO.name = string.Format("{0},{1}", column, row);
                hexGO.GetComponent <HexComponent>().Hex    = h;
                hexGO.GetComponent <HexComponent>().HexMap = this;

                hexGO.GetComponentInChildren <TextMesh>().text = string.Format("{0},{1}\n{2}", column, row, h.BaseMovementCost(false, false, false));
            }
        }

        UpdateHexVisuals();

        //StaticBatchingUtility.Combine(this.gameObject);
    }
Example #10
0
    public void UpdateHexVisuals()
    {
        for (int column = 0; column < NumColumns; column++)
        {
            for (int row = 0; row < NumRows; row++)
            {
                Hex        h     = hexes[column, row];
                GameObject hexGO = hexToGameObjectMap[h];

                MeshRenderer mr = hexGO.GetComponentInChildren <MeshRenderer>();
                MeshFilter   mf = hexGO.GetComponentInChildren <MeshFilter>();

                h.MovementCost = 1;


                if (h.Elevation >= HeightFlat && h.Elevation < HeightMountain)
                {
                    if (h.Moisture >= MoistureJungle)
                    {
                        mr.material = MatGrasslands;
                        // Spawn trees
                        Vector3 p = hexGO.transform.position;
                        if (h.Elevation >= HeightHill)
                        {
                            p.y += 0.25f;
                        }
                        h.MovementCost = 2;
                        GameObject.Instantiate(JunglePrefab, p, Quaternion.identity, hexGO.transform);
                    }
                    else if (h.Moisture >= MoistureForest)
                    {
                        mr.material = MatGrasslands;
                        // Spawn trees
                        Vector3 p = hexGO.transform.position;
                        if (h.Elevation >= HeightHill)
                        {
                            p.y += 0.25f;
                        }
                        h.MovementCost = 2;
                        GameObject.Instantiate(ForestPrefab, p, Quaternion.identity, hexGO.transform);
                    }
                    else if (h.Moisture >= MoistureGrasslands)
                    {
                        mr.material = MatGrasslands;
                    }
                    else if (h.Moisture >= MoisturePlains)
                    {
                        mr.material = MatPlains;
                    }
                    else
                    {
                        mr.material = MatDesert;
                    }
                }

                if (h.Elevation >= HeightMountain)
                {
                    mr.material    = MatMountains;
                    mf.mesh        = MeshMountain;
                    h.MovementCost = -99;
                }
                else if (h.Elevation >= HeightHill)
                {
                    h.MovementCost = 2;
                    mf.mesh        = MeshHill;
                }
                else if (h.Elevation >= HeightFlat)
                {
                    mf.mesh = MeshFlat;
                }
                else
                {
                    h.MovementCost = -99;
                    mr.material    = MatOcean;
                    mf.mesh        = MeshWater;
                }

                hexGO.GetComponentInChildren <TextMesh>().text =
                    string.Format("{0},{1}\n{2}", column, row, h.BaseMovementCost());
            }
        }
    }
Example #11
0
 public int MovementCostToEnterHex(Hex hex)
 {
     return(hex.BaseMovementCost());
 }