Beispiel #1
0
    public void GenerateDetails()
    {
        if (IsUnderwater)
        {
            return;
        }

        // POPULATION BUILDINGS //
        if (currentOccupants != null)
        {
            GameObject buildingPrefab      = null;
            int        buildingsToGenerate = 0;
            // TENTS //
            if (currentOccupants.GetPopulation() > 10 &&
                currentOccupants.GetPopulation() < 100)
            {
                buildingsToGenerate = currentOccupants.GetPopulation() / 15;
                if (buildingsToGenerate == 0)
                {
                    buildingsToGenerate = 1;
                }
                buildingPrefab = RAKUtilities.getWorldPrefab(Civilization.PREFABTENT);
            }
            // VILLAGE //
            else if (currentOccupants.GetPopulation() >= 100)
            {
                // BUILD ROADS //
                if (currentOccupants.GetPopulation() >=
                    Civilization.STARTBUILDINGROADSATPOPULATION)
                {
                    for (int count = 0; count < neighbors.Length; count++)
                    {
                        if (neighbors[count] != null &&
                            neighbors[count].CurrentOccupants != null &&
                            neighbors[count].CurrentOccupants.GetPopulation() >= 100)
                        {
                            roads[count] = true;
                        }
                    }
                }
                // BUILD HOUSES //
                if (currentOccupants.GetPopulation() <= 1000)
                {
                    buildingsToGenerate = currentOccupants.GetPopulation() / 150;
                    if (buildingsToGenerate == 0)
                    {
                        buildingsToGenerate = 1;
                    }
                    buildingPrefab = RAKUtilities.getWorldPrefab(Civilization.PREFABTOWNHOUSE1);
                }
                // Big Village //
                else
                {
                    buildingsToGenerate = 1;
                    buildingPrefab      = RAKUtilities.getWorldPrefab(Civilization.PREFABTOWNWINDMILL);
                }

                // INSTANTIATE BUILDINGS //
                if (buildingPrefab != null && buildingsToGenerate > 0)
                {
                    GameObject building = null;
                    if (buildingsToGenerate > 1)
                    {
                        for (int count = 0; count < buildingsToGenerate; count++)
                        {
                            building = Instantiate(buildingPrefab);
                            building.transform.SetParent(transform, false);
                            building.transform.RotateAround(transform.position, Vector3.up, 60 * count);
                            building.transform.rotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
                        }
                    }
                    // Center if only building //
                    else
                    {
                        building = Instantiate(buildingPrefab);
                        building.transform.SetParent(transform, false);
                        building.transform.position = transform.position;
                        building.transform.rotation = Quaternion.Euler(0, Random.Range(0, 360), 0);
                    }
                }
            }
        }
    }