Ejemplo n.º 1
0
    void PlaceBuildings2(List <Vector2> factionPoints, Faction fac)
    {
        GameObject capital = objectToPlace[0]; //one per faction, can hire troops or get resources
        GameObject city    = objectToPlace[1]; //can hire troops here
        GameObject village = objectToPlace[2]; //can get resources here

        fac.SetChallengersToFaction();         //makes sure challengers in list of faction have this faction as their faction
        //Debug.Log(" length is : " + factionPoints.Count);
        var result = PickNPoints(factionPoints, 1);
        //place city
        float posy = Terrain.activeTerrain.SampleHeight(new Vector3(result.GetFirst()[0].x, 0, result.GetFirst()[0].y)); //finds the y given x and z
                                                                                                                         //generate the object
        Vector3    capPos     = new Vector3(result.GetFirst()[0].x, posy + cubeOffset, result.GetFirst()[0].y);
        GameObject capitalObj = (GameObject)Instantiate(capital, capPos, Quaternion.identity);
        Town       capitalRef = capitalObj.GetComponent <Town>();

        //set capital cities properties
        capitalRef.Setup(true, 3, 10, fac, capPos);       //todo randomise as appropr
        capitalRef.buildingName = SpawnManager.AssignName();
        capitalRef.AddTroops(new Unit(troopPic, 10), 10); //10 as setup is 10 above
        fac.capital    = capitalRef;                      //sets capital of faction in class
        factionAPoints = result.GetSecond();
        int            aSize  = factionAPoints.Count;
        int            offset = aSize % 3; //we want every town to have 2 villages so we are splitting array into chunks of 3
        VectorTuple    threePoints;
        List <Vector2> t;
        VectorTuple    t2;
        Vector2        townPoint;
        List <Vector2> villagePoints;
        float          posY;

        //int count = 1;
        for (int i = 0; i < targetPoints / 2; i += 3)
        {
            threePoints    = PickNPoints(factionAPoints, 3);
            factionAPoints = threePoints.GetSecond();
            t             = threePoints.GetFirst();
            t2            = PickNPoints(t, 1);
            townPoint     = t2.GetFirst()[0];                                                             //this is the town, the other 2 are the attached smaller villages
            villagePoints = t2.GetSecond();
            posY          = Terrain.activeTerrain.SampleHeight(new Vector3(townPoint.x, 0, townPoint.y)); //finds the y given x and z
            //placing town
            Vector3    townPos = new Vector3(townPoint.x, posY, townPoint.y);
            GameObject cityObj = (GameObject)Instantiate(city, townPos, Quaternion.identity);
            Town       cityRef = cityObj.GetComponent <Town>();
            //set capital cities properties
            cityRef.Setup(false, 2, 5, fac, townPos); //todo randomise as appropr
            cityRef.buildingName = SpawnManager.AssignName();
            cityRef.AddTroops(new Unit(troopPic, 5), 5);
            fac.towns.Add(cityRef); //adds town
            //place villages
            //Debug.Log("village length (should be 2): " + villagePoints.Count);
            foreach (Vector2 v in villagePoints)
            {
                float      y          = Terrain.activeTerrain.SampleHeight(new Vector3(v.x, 0, v.y)); //finds the y given x and z
                Vector3    pos        = new Vector3(v.x, y + cubeOffset, v.y);
                GameObject villageObj = (GameObject)Instantiate(village, pos, Quaternion.identity);
                //setup village objects (TODO)
                Village vilRef = villageObj.GetComponent <Village>();
                vilRef.buildingName = SpawnManager.AssignName();
                vilRef.Setup(fac, pos);
                fac.villages.Add(vilRef);
            }
            //factionAPoints = threePoints.GetSecond();
            // count += 3;
        }
    }