// awake happens too soon like a bitch
        void Update()
        {
            RoadGenerator rg = gameObject.GetComponent <RoadGenerator>();
            int           r  = Random.Range(0, 100);

            if (r < GrassPopulationManager.instance.ChanceFences)
            {
                int        f             = Random.Range(0, GrassPopulationManager.Fences.Length);
                GameObject FenceTemplate = GrassPopulationManager.Fences[f];
                int        d             = 2 * Random.Range(0, 4);

                rg.DoHits();
                WorldTile tiled = rg.GetNeighbours()[d];
                if (tiled && tiled.GetComponent <GrassPopulator>() && tiled.GetComponent <GrassPopulator>().FenceDir == RoadGenerator.Wrap0to7(d - 4))
                {
                    //Debug.Log("fence collision prevented");
                }
                else
                {
                    GameObject fence = Instantiate(FenceTemplate, transform.position + new Vector3((RoadGenerator.Xoffset(d) * WorldTileManager.TILE_SIZE) / 2, 0, (RoadGenerator.Zoffset(d) * WorldTileManager.TILE_SIZE) / 2), Quaternion.identity, transform);
                    fence.transform.Rotate(0, d * 45 - 90, 0);
                    FenceDir = d;
                }
            }

            int            t     = Random.Range(0, GrassPopulationManager.instance.MaximumTreeDensity);
            List <Vector3> trees = new List <Vector3>();

            trees.Clear();
            float x, y;

            x = y = 0.0f;
            bool bCollides = true;

            for (int i = 0; i < t; ++i)
            {
                bCollides = true;
                while (bCollides)
                {
                    x         = Random.Range(-9.0f, 9.0f);
                    y         = Random.Range(-9.0f, 9.0f);
                    bCollides = false;
                    foreach (Vector3 treepos in trees)
                    {
                        if ((treepos - new Vector3(x, 0, y)).magnitude < 4.0f)
                        {
                            bCollides = true;
                        }
                    }
                }
                trees.Add(new Vector3(x, 0, y));
                Instantiate(GrassPopulationManager.Tree, transform.position + new Vector3(x, 0, y), Quaternion.identity, transform);
            }

            enabled = false;
        }
        void FixedUpdate()
        {
            if (Input.GetKey(KeyCode.Keypad0))
            {
                bCull = !bCull;
            }

            Transform playerTransform = checkpoint.FollowCamera.target.transform;

            //Debug.Log(checkpoint.RoadMapRoot.GetComponentsInChildren<RoadGenerator>().Length + " 35:" + checkpoint.RoadMapRoot.GetComponentsInChildren<RoadGenerator>()[35].gameObject.name);

            if (checkpoint.RoadMapRoot.GetComponentsInChildren <RoadGenerator>().Length > 100 /*usually around 140, prevent checking until the map is up to size*/ && EmergencyFieldRemover == null && checkpoint.RoadMapRoot.GetComponentsInChildren <RoadGenerator>()[35] as DisabledRoadGenerator != null /*35 is around a quarter, meaning grass at this position indicates a map with three quarters grass*/)
            {
                int i = RoadGenerator.Wrap0to7(Mathf.RoundToInt(playerTransform.rotation.eulerAngles.y / 45.0f));

                Vector3 player = RoundDownToGrid(playerTransform.position);
                hitTest.x = Mathf.FloorToInt(player.x / WorldTileManager.TILE_SIZE) + RoadGenerator.Xoffset(i) * 8;
                hitTest.z = Mathf.FloorToInt(player.z / WorldTileManager.TILE_SIZE) + RoadGenerator.Zoffset(i) * 8;
                //Debug.Log("Testing for a hit at grid "+hitTest.x+","+hitTest.z+"; World location "+hitTest.GetWorldPosition());
                WorldTile Hit = WorldTileManager.instance.GetTile(hitTest);

                if (!Hit)
                {
                    //Debug.Log("F****N FIELD, heading " + playerTransform.rotation.eulerAngles.y + "≈" + (RoadGenerator.Direction)i);

                    EmergencyFieldRemover = Instantiate(FourWay, hitTest.GetWorldPosition() + new Vector3(0, FourWay.GetComponent <RoadGenerator>().YOffset, 0), Quaternion.identity, checkpoint.RoadMapRoot.transform);
                    //Debug.Log("EFR: "+EmergencyFieldRemover.gameObject.name + " at " + (hitTest.GetWorldPosition() + new Vector3(0, FourWay.GetComponent<RoadGenerator>().YOffset, 0)));
                    WorldTileManager.instance.AddTile(EmergencyFieldRemover.GetComponent <WorldTile>());
                    EmergencyFieldRemover.transform.SetAsFirstSibling();
                    RoadGenerator newRG = EmergencyFieldRemover.GetComponent <RoadGenerator>();
                    newRG.CullingExempt = true;
                    newRG.RefreshExits();
                    //newRG.Extend(true);
                    //checkpoint.RoadMapRoot.BroadcastMessage("Extend", true);
                }
            }
            else if             // Emergency Field Remover has come within the invisible boundary lines (σ回ω・)σ
            ((EmergencyFieldRemover != null && Vector3.Distance(playerTransform.position, EmergencyFieldRemover.transform.position) < checkpoint.FollowCamera.CullDistance)
             ||                 // Emergency Field Remover is no longer in front of the player
             (EmergencyFieldRemover != null && Vector3.Dot(playerTransform.position - EmergencyFieldRemover.transform.position, playerTransform.forward) > 90))
            {
                EmergencyFieldRemover.GetComponent <RoadGenerator>().CullingExempt = false;
                EmergencyFieldRemover = null;
            }
        }
Beispiel #3
0
        void Spawn()
        {
            if (UnlockManager.instance)
            {
                GameObject[] UnlockedCars = UnlockManager.instance.GetUnlockedItems(UnlockableType.VEHICLE);
                int          index        = Random.Range(0, UnlockedCars.Length);
                int          dir          = rg.Exit[(int)RoadGenerator.Direction.North] ? (int)RoadGenerator.Direction.West : (int)RoadGenerator.Direction.South;
                GameObject   car          = Instantiate(UnlockedCars[index], gameObject.transform.position + new Vector3((RoadGenerator.Xoffset(dir) * WorldTileManager.TILE_SIZE) / 4, 3, (RoadGenerator.Zoffset(dir) * WorldTileManager.TILE_SIZE) / 4), gameObject.transform.rotation);
                //if (RoadTileManager.bDebugEnv) rg.MySpecificDebug += "generated vehicle @ " + car.transform.position + "\n";

                if (RoadTileManager.bMainMenu)
                {
                    car.GetComponent <BaseVehicleClass>().health = 0;
                }
            }
            hasSpawned = true;
        }
Beispiel #4
0
        void SpawnNonVehicles()
        {
            GameObject player = RoadTileManager.checkpoint.FollowCamera.target;

            int i = rg.Exit[(int)RoadGenerator.Direction.North] ? (int)RoadGenerator.Direction.West : (int)RoadGenerator.Direction.South;

            if (rg.CullingExempt)
            {
                return;
            }

            int r = Random.Range(0, 10);

            if (r == 1)
            {
                r = Random.Range(0, 2);
                bool bSpinBench = false;
                if (r == 1)
                {
                    i -= 4; bSpinBench = true;
                }                                                          // place bench east or north instead of west or south

                GameObject benchTemplate = Resources.Load <GameObject>("Prefabs/Destructable Scenery/bench");
                GameObject bench         = Instantiate(benchTemplate, gameObject.transform.position + new Vector3((RoadGenerator.Xoffset(i) * WorldTileManager.TILE_SIZE) / 2.25f + (RoadGenerator.Xoffset(RoadGenerator.Wrap0to7(i - 2) * (int)WorldTileManager.TILE_SIZE)) / 5, 1.6f, (RoadGenerator.Zoffset(i) * WorldTileManager.TILE_SIZE) / 2.25f + (RoadGenerator.Zoffset(RoadGenerator.Wrap0to7(i - 2)) * WorldTileManager.TILE_SIZE) / 5), gameObject.transform.rotation);
                if (bSpinBench)
                {
                    bench.transform.Rotate(0, 180, 0);
                }

                hasSpawned = true;
            }

            r = Random.Range(0, 100);

            bool bInVehicle = player.GetComponent <BaseVehicleClass>();

            if ((RoadTileManager.bMainMenu || bInVehicle) && r > 100 - RoadTileManager.instance.ChanceBarrier)
            {
                GameObject[] RoadBlocks = Resources.LoadAll <GameObject>("Prefabs/Destructable Scenery/Fences/Road Barriers");
                r = Random.Range(0, RoadBlocks.Length);
                Instantiate(RoadBlocks[r], transform.position, transform.rotation, transform); hasSpawned = true;
            }
        }
Beispiel #5
0
        void Update()
        {
            bool bHasNeighbour = false;

            BuildingGenerator[] hit = new BuildingGenerator[8];

            TilePosition position = gameObject.GetComponent <WorldTile>().GetTilePosition();

            for (int i = 0; i < hit.Length; ++i)
            {
                hit[i] = WorldTileManager.instance.GetTile(position + new TilePosition(RoadGenerator.Xoffset(i), RoadGenerator.Zoffset(i)))?.GetComponent <BuildingGenerator>();
                if (hit[i] && hit[i].newBuilding)
                {
                    bHasNeighbour = true;
                }
                //if (RoadTileManager.bDebugEnv) gameObject.GetComponent<RoadGenerator>().MySpecificDebug += "Checking " + (RoadGenerator.Direction)i + " of " + gameObject.transform.position + " has hit " + (hit[i] ? hit[i].gameObject.name : "nothing") + "\n";
            }

            GameObject newBuildingClass = null;

            if (!bHasNeighbour)
            {
                //if (RoadTileManager.bDebugEnv) gameObject.GetComponent<RoadGenerator>().MySpecificDebug += "Random Building\n";
                newBuildingClass = BuildingManager.RandomBuilding();
            }
            else
            {
                List <GameObject> neighbours = new List <GameObject>();
                for (int i = 0; i < hit.Length; ++i)
                {
                    if (hit[i]?.newBuilding)
                    {
                        neighbours.Add(hit[i].newBuilding);
                    }
                }

                int        r = Random.Range(0, neighbours.Count);
                GameObject n = neighbours[r];
                //if (RoadTileManager.bDebugEnv) gameObject.GetComponent<RoadGenerator>().MySpecificDebug += n.GetComponent<Unlockable>().type.ToString()+"\n";

                if (BuildingManager.IsSkyscraper(n))
                {
                    newBuildingClass = BuildingManager.RandomSkyscraper();
                }
                else if (BuildingManager.IsHouse(n))
                {
                    newBuildingClass = BuildingManager.RandomHouse();
                }
                else if (BuildingManager.IsShop(n))
                {
                    newBuildingClass = BuildingManager.RandomShopOrHouse();
                }
            }

            if (newBuildingClass)
            {
                newBuilding = Instantiate(newBuildingClass, transform.position, transform.rotation, transform);
            }
            else
            {
                GameObject[] RoadBlocks = Resources.LoadAll <GameObject>("Prefabs/Destructable Scenery/Fences/Pavement Barriers");
                int          r          = Random.Range(0, RoadBlocks.Length);
                Instantiate(RoadBlocks[r], transform.position, transform.rotation, transform);
            }

            enabled = false;
        }