コード例 #1
0
ファイル: Area.cs プロジェクト: Rakjavik/EmergenceOfRak
        public void Initialize(Tribe tribe)
        {
            if (debug) // DEBUG
            {
                InitializeDebug(tribe);
                return;
            }
            areaSize = world.masterTerrain.GetSize();
            for (int count = 0; count < walls.Length; count++)
            {
                walls[count] = GameObject.Instantiate(RAKUtilities.getWorldPrefab("Wall"), null);
                walls[count].transform.GetChild(0).localScale = new Vector3(areaSize.x, 256, 1);
            }
            walls[0].transform.position = new Vector3(areaSize.x / 2, 128, 1);
            walls[1].transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
            walls[1].transform.position = new Vector3(0, 0, areaSize.z / 2);
            walls[2].transform.position = new Vector3(areaSize.x / 2, 0, areaSize.z);
            walls[3].transform.rotation = Quaternion.Euler(new Vector3(0, 90, 0));
            walls[3].transform.position = new Vector3(areaSize.x, 0, areaSize.z / 2);
            if (thingContainer == null)
            {
                thingContainer = new GameObject("ThingContainer");
            }
            if (creatureContainer == null)
            {
                creatureContainer = new GameObject("CreatureContainer");
            }
            if (disabledContainer == null)
            {
                disabledContainer = new GameObject("DisabledContainer");
            }
            allThings = new List <Thing>();
            // Scan the TerrainObjects placed in map for Things //
            foreach (RAKTerrain terrain in world.masterTerrain.getTerrain())
            {
                foreach (RAKTerrainObject terrainObject in terrain.nonTerrainObjects)
                {
                    Thing thing = terrainObject.gameObject.GetComponent <Thing>();
                    if (thing != null)
                    {
                        allThings.Add(thing);
                        thing.initialize(thing.name);
                    }
                }
            }
            int populationToCreate = tribe.GetPopulation();
            int MAXPOP             = 100;

            if (populationToCreate > MAXPOP)
            {
                populationToCreate = MAXPOP;
            }
            Debug.LogWarning("Generating a population of - " + populationToCreate);
            for (int count = 0; count < populationToCreate; count++)
            {
                addCreatureToWorld("Gnat");
            }
        }
コード例 #2
0
ファイル: World.cs プロジェクト: Rakjavik/EmergenceOfRak
        private void Awake()
        {
            ISDEBUGSCENE = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name.ToLower().Contains("debug");
            if (ISDEBUGSCENE && !_initialized)
            {
                InitializeDebugWorld();
                return;
            }
            world          = this;
            FollowCamera   = this.followCamera;
            WORLD_DATAPATH = Application.persistentDataPath + "/Worlds/";
            if (!Directory.Exists(WORLD_DATAPATH))
            {
                Directory.CreateDirectory(WORLD_DATAPATH);
            }
            worldType     = WorldType.CLASSM;
            worldName     = "AlphaWorld";
            tribes        = new Dictionary <HexCell, Tribe>();
            civilizations = new List <Civilization>();
            civilizations.Add(new Civilization(BASE_SPECIES.Gnat, "DaGnats", true, 5, 15));
            HexMetrics.Initialize(worldType);
            hexGrid     = HexGrid.generate(this);
            mapCam.grid = hexGrid;
            //masterTerrain = GetComponent<RAKTerrainMaster>();
            if (editing)
            {
                editor = Instantiate(RAKUtilities.getWorldPrefab("HexMapEditor")).GetComponent <HexMapEditor>();
            }

            for (int count = 0; count < NUMBEROFSTARTINGCIVS; count++)
            {
                Tribe   tribe = new Tribe(1200, BASE_SPECIES.Gnat);
                HexCell cell  = tribe.FindHome(this, true);
                //civilizations[0].AddTribe(tribe);
                addTribe(tribe, cell);
            }
            hexGrid.RefreshAllChunks();
            mainMenu = new MenuController(creatureBrowserPrefab, worldBrowserPrefab, debugMenuPrefab);
            if (AutoLoadArea)
            {
                HexCell autoLoadCell = hexGrid.GetCell(new Vector3(0, 0, 0));
                LoadArea(autoLoadCell);
                mainMenu.Initialize(RootMenu.CreatureBrowser);
            }
            else
            {
                mainMenu.Initialize(RootMenu.WorldBrowser);
            }
            _initialized = true;
        }
コード例 #3
0
    public static HexGrid generate(World world)
    {
        HexGrid grid = Instantiate(RAKUtilities.getWorldPrefab("HexGrid").GetComponent <HexGrid>());

        if (world.worldType == World.WorldType.CLASSM)
        {
            grid.cellPrefab      = RAKUtilities.getWorldPrefab("Hex Cell").GetComponent <HexCell>();
            grid.cellLabelPrefab = RAKUtilities.getWorldPrefab("Hex Cell Label").GetComponent <Text>();
            grid.chunkPrefab     = RAKUtilities.getWorldPrefab("Hex Grid Chunk").GetComponent <HexGridChunk>();
            grid.cellCountX      = grid.chunkCountX * HexMetrics.chunkSizeX;
            grid.cellCountZ      = grid.chunkCountZ * HexMetrics.chunkSizeZ;
        }
        grid.SetWorld(world);
        grid.CreateChunks(world.worldType);
        grid.CreateCells();
        return(grid);
    }
コード例 #4
0
ファイル: HexCell.cs プロジェクト: Rakjavik/EmergenceOfRak
    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);
                    }
                }
            }
        }
    }