Inheritance: MonoBehaviour
    public void SetBuilding(Building building)
    {
        //if (UIUpgradeBuilding.CurrentBuilding != null) Debug.Log("Setting building to " + building.Name);

        if (building == Buildings.Road)
        {
            // only roads get their terrain colour changed
            terrainColour           = Buildings.RoadColour;
            renderer.material.color = Buildings.RoadColour;
        }
        if (building != Buildings.Road && building != Buildings.Generator)
        {
            // otherwise, turn the collider on and "build" the building
            buildingCollider.enabled = true;
            // Keep track of old prefab if one exists
            oldAnimatingPoint = animatingPoint;
            // set all other children to disabled
            var prefab = WorldBuilder.AllPossibleBuildings.First(x => x.name == building.Name);
            animatingPoint = Instantiate(prefab, buildingPivot.position, Quaternion.identity, transform).transform;
            animatingPoint.localEulerAngles = Vector3.zero;
            StartPivotAnim();
        }

        CurrentBuilding = building;
        WorldBuilder.RebuildNavmesh();
    }
Example #2
0
        public SystemView Get([FromQuery] int?index)
        {
            WorldBuilder wb = new WorldBuilder();

            Models.System s;
            World         world;
            State         initialState;

            switch (index)
            {
            case 1:
                world        = wb.GetMuseumWorld();
                initialState = new State(0, 0, world.Cameras);
                s            = new Models.System(world, initialState);
                break;

            case 2:
                world        = wb.GetEmptyWorld();
                initialState = new State(0, 0, world.Cameras);
                s            = new Models.System(world, initialState);
                break;

            default:
                world        = wb.GetDefaultWorld();
                initialState = new State(0, 0, world.Cameras);
                s            = new Models.System(world, initialState);
                break;
            }
            return(SetSystem(s));
        }
Example #3
0
        private static BenchmarkResult StartBenchmark()
        {
            var worldState = CreateWorldState();
            var model      = ModelLoader.LoadModel(RootDir, GeometryFile, TextureFile, NormalMapFile, SpecularMapFile);
            var buffer     = new Bitmap(ViewportWidth, ViewportHeight, PixelFormat.Format32bppRgb);

            using (var renderer = new Renderer(ViewportWidth, ViewportHeight))
            {
                var world = new WorldBuilder(model).BuildWorld(worldState);

                const int count = 500;

                // Heating
                for (var i = 0; i < count; i++)
                {
                    renderer.Render(world, buffer);
                }

                // Actual measuring
                var start = Stopwatch.GetTimestamp();
                for (var i = 0; i < count; i++)
                {
                    renderer.Render(world, buffer);
                }
                var end = Stopwatch.GetTimestamp();

                double runticks = end - start;
                double runtime  = runticks / Stopwatch.Frequency / count;

                return(new BenchmarkResult(runtime));
            }
        }
Example #4
0
    public void Update()
    {
        if (worldBuilder == null)
        {
            worldBuilder = GameObject.FindObjectOfType <WorldBuilder>();            // try to find it
            if (worldBuilder == null)
            {
                Quit();
                return;
            }
        }
        else if (worldBuilder.HasWorld())
        {
            if (worldBuilder.World.State.Mode == Shipwreck.WorldData.GameMode.Waiting)
            {
                countdownSlider.value = 1 - (worldBuilder.World.State.RemainingTime / Shipwreck.World.GameConstants.PlayerWaitTime);
                countdownText.text    = $"Loading in {worldBuilder.World.State.RemainingTime:0}s";
            }
            else if (waitAnimator.GetBool("Shown") && worldBuilder.World.State.Mode == Shipwreck.WorldData.GameMode.Playing)
            {
                var menuMusic = GameObject.FindObjectOfType <MenuMusicSingleton>();
                Destroy(menuMusic.gameObject);
                SceneManager.LoadScene(2);                 // Load Game
            }
        }

        DiscoverGamesList();
    }
Example #5
0
        private static void Spawn(MonStat monStat, int x, int y, int level, Transform root)
        {
            CollisionLayers collisionMask = CollisionLayers.Walk;

            if (!CollisionMap.Passable(new Vector2i(x, y) * Iso.SubTileCount, collisionMask, monStat.ext.sizeX))
            {
                return;
            }

            int count = Random.Range(monStat.minGrp, monStat.maxGrp + 1);

            for (int i = 0; i < count; ++i)
            {
                var mon = WorldBuilder.SpawnMonster(monStat, Iso.MapTileToWorld(x, y), root);
                mon.level = level;
            }

            if (monStat.minion1 != null)
            {
                int minionCount = Random.Range(monStat.partyMin, monStat.partyMax);
                for (int i = 0; i < minionCount; ++i)
                {
                    var mon = WorldBuilder.SpawnMonster(monStat.minion1, Iso.MapTileToWorld(x, y), root);
                    mon.level = level;
                }
            }
        }
Example #6
0
        public static WorldBuilder AddDestroyFeature <TScope>(this WorldBuilder self)
        {
            // @formatter:off
            return(self.AddFeature(Name)
                   .DependsOn()
                   .Feature(CoreFeature.Name)
                   .End()
                   .Components <TScope>()
                   .Add <Destroyed>()
                   .End()
                   .GlobalComponentNotifications <TScope>()
                   .AddAddedNotifications <Destroyed>()
                   .End()
                   .Systems()
                   .Cleanup((contexts, bus) => {
                var context = contexts.Get <TScope>();

                foreach (var message in bus.All <ComponentAdded <TScope, Destroyed> >())
                {
                    context.DestroyEntity(message.Entity);
                }
            })
                   .End()
                   .End());
            // @formatter:on
        }
Example #7
0
        public RealGame(int numberOfSections, int numPlayers, BlockBasedSceneGraph sceneGraph)
        {
            // setup
            Globals.gameInstance = this;
            this.sceneGraph      = sceneGraph;

            // object to store collisions (the size of the world)
            cellCollider = new CellCollider(32, numberOfSections * 32);

            // holds links between current spawn populations, doors and lights
            campaignManager = new CampaignManager(numberOfSections);

            // now build all the shit
            WorldBuilder.Build(numberOfSections, Vector3.Zero);

            // now spawn all player
            players = new PlayerObject[numPlayers];
            for (int i = 0; i < numPlayers; i++)
            {
                players[i] = new PlayerObject((i == 0) ? PlayerIndex.One : PlayerIndex.Two, playerColours[i], spawns[i], MathHelper.ToRadians(-90));
            }

            Globals.audioManager.SwitchToGame();
            //Globals.audioManager.PlayGameSound("start_game");
            Globals.audioManager.PlayGameSound("music");
        }
Example #8
0
        public World UpdateWorld(Action <IEditableWorld> update)
        {
            var worldBuilder = new WorldBuilder(this, _entities, _systemManager);

            update(worldBuilder);
            return(worldBuilder.ToImmutable());
        }
    public static void NightTriggered()
    {
        IsNight = true;

        // Spawn enemies.
        // Jeez, I'm really throwing style out the window, huh
        var numSpheres = Math.Min(Day + 2, 19);
        var numCubes   = Math.Min(Day + 2, 19);
        var tier3s     = Day / 9;
        var tier2s     = Day / 4;


        for (var i = 0; i < numCubes; i++)
        {
            var index = i < tier3s ? 2 : i < tier3s + tier2s ? 1 : 0;
            Instantiate(staticCubePrefabs[index], WorldBuilder.GetRandomEnemySpawnPoint(), Quaternion.identity);
        }
        for (var i = 0; i < numSpheres; i++)
        {
            var index = i < tier3s ? 2 : i < tier3s + tier2s ? 1 : 0;
            Instantiate(staticSpherePrefabs[index], WorldBuilder.GetRandomEnemySpawnPoint(), Quaternion.identity);
        }

        EnemiesRemaining = numSpheres + numCubes;
    }
Example #10
0
    void Awake()
    {
        _gameManager = FindObjectOfType <GameManager>();
        if (_gameManager == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }

        _locationManager = _gameManager._locationManager;
        if (_locationManager == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }


        _worldBuilder = GetComponentInChildren <WorldBuilder>();
        if (_worldBuilder == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }

        _gridBuilder = GetComponentInChildren <GridBuilder>();
        if (_gridBuilder == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }

        _cubeBuilder = GetComponentInChildren <CubeBuilder>();
        if (_cubeBuilder == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }

        _mapPieceBuilder = GetComponentInChildren <MapPieceBuilder>();
        if (_mapPieceBuilder == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }

        _outerZoneBuilder = GetComponentInChildren <OuterZoneBuilder>();
        if (_outerZoneBuilder == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }

        _nodeBuilder = GetComponentInChildren <NodeBuilder>();
        if (_nodeBuilder == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }



        _mapSettings = GetComponent <MapSettings>();
        if (_mapSettings == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }
    }
Example #11
0
        public void Solve_B_LoadUnloadShip()
        {
            var logger = new EmptyEventLogger();
            var world  = WorldBuilder.CreateForExercise2("B", logger);
            var hours  = world.Solve();

            Assert.That(hours, Is.EqualTo(5));
        }
Example #12
0
        public void Solve_ABBBABAAABBB()
        {
            var logger = new EmptyEventLogger();
            var world  = WorldBuilder.CreateForExercise1("A,B,B,B,A,B,A,A,A,B,B,B", logger);
            var hours  = world.Solve();

            Assert.That(hours, Is.EqualTo(41));
        }
Example #13
0
        static void Main(string[] args)
        {
            WorldBuilder builder = new WorldBuilder(40, 160);

            DisplayWorld(builder.World);

            Play(builder.World);
        }
Example #14
0
    void Start()
    {
        navMesh  = GetComponentInChildren <NavMeshSurface>();
        instance = this;

        BuildWorld();
        GameController.InitialiseGame();
    }
Example #15
0
    void Start()
    {
        InvokeStartGame();

        worldSingleton = this;

        builder = this.GetComponent <WorldBuilder>();
    }
Example #16
0
        private static void SolveInput(string[] args)
        {
            var input       = args[0];
            var eventLogger = new FileEventLogger(input.Replace(",", ""));
            var world       = WorldBuilder.CreateForExercise2(input, eventLogger);
            var totalTime   = world.Solve();

            Console.WriteLine($"Total time {totalTime}");
        }
        public override void Draw(Vector2 position)
        {
            if (label.Length == 0)
            {
                WorldBuilder world = GetWorldBuilder();
                int          total = 0;

                // count blocks
                for (int i = 0; i < world.Size.x; i++)
                {
                    for (int j = 0; j < world.Size.y; j++)
                    {
                        for (int k = 0; k < ChunkColumn.chunksPerColumn; k++)
                        {
                            if (world.chunkColumns[i, j].chunks[k] != null)
                            {
                                for (int l = 0; l < Chunk.size; l++)
                                {
                                    for (int m = 0; m < Chunk.size; m++)
                                    {
                                        for (int n = 0; n < Chunk.size; n++)
                                        {
                                            Block  block = world.chunkColumns[i, j].chunks[k].blocks[l, m, n];
                                            string type  = block.GetType().ToString();

                                            if (!blockCounts.ContainsKey(type))
                                            {
                                                blockCounts[type] = 0;
                                            }

                                            total++;
                                            blockCounts[type]++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                int totalSolid = total - blockCounts[typeof(Air).ToString()];

                foreach (KeyValuePair <string, int> blockCount in blockCounts)
                {
                    if (blockCount.Key != typeof(Air).ToString())
                    {
                        label += blockCount.Key + ": " + blockCount.Value.ToString("#,##") + " (" + ((float)blockCount.Value / (float)totalSolid).ToString("P", CultureInfo.InvariantCulture) + ")" + "\n";
                    }
                }

                label += "Total: " + totalSolid.ToString("#,##");
            }

            content.text = label;
            style.CalcSize(content);
            UnityEngine.GUI.Label(new Rect(position.x, position.y + 40, 20, 20), label, style);
        }
Example #18
0
 /// <summary>
 /// Initializes the ECS system. Users should override this method if custom systems are implemented.
 /// </summary>
 public virtual void InitializeECS()
 {
     SceneWorld = new WorldBuilder()
                  .AddSystem(new PlayerSystem())
                  .AddSystem(new PhysicsSystem())
                  .AddSystem(new RenderSystem(this))
                  .Build();
     SceneWorld.Initialize();
 }
Example #19
0
    void Awake()
    {
        me = this;

        if (FindObjectOfType <CreateNodesFromTilemaps>().unsortedNodes == null)
        {
            nodesCreated = false;
        }

        if (fromTilemap == false)
        {
            worldTiles = new GameObject[width, height];
        }
        else
        {
            if (nodesCreated == false)
            {
                //Debug.LogError("Nodes are not created");
                createNodes();
            }
            else
            {
                //Debug.LogError("Nodes already created, seeing if we can use");
                CreateNodesFromTilemaps ct = FindObjectOfType <CreateNodesFromTilemaps> ();
                worldTiles = ct.reassembleNodeArray();
                ct.nodes   = worldTiles;
                for (int x = 0; x < worldTiles.GetLength(0); x++)
                {
                    for (int y = 0; y < worldTiles.GetLength(1); y++)
                    {
                        if (worldTiles[x, y] != null)
                        {
                            startX = x;
                            startY = y;
                            return;
                        }
                    }
                }

                /*if (worldTiles == null) {
                 *                      //Debug.Log ("There were no world tiles found");
                 *                      //DebugFixNodes ();
                 *              }
                 *
                 *              if (ct.nodes == null && worldTiles != null) {
                 *                      //Debug.Log ("Create nodes from tilemaps had no nodes, passing in");
                 *                      ct.nodes = worldTiles;
                 *              }
                 *
                 *              Pathfinding p = FindObjectOfType<Pathfinding> ();
                 *              if (p.pathNodes == null) {
                 *                      //Debug.Log ("There were no threaded nodes");
                 *              }*/
            }
        }
    }
    void Awake()
    {
        builder = FindObjectOfType <WorldBuilder>();

        MeshFilter meshFilter = ground.GetComponent <MeshFilter>();

        dist = meshFilter.sharedMesh.bounds.size.z * ground.transform.localScale.z;

        WorldController.OnPlatformMovement += TryDelAndAddPlatform;
    }
        public void WorldBuilder_BuildRandomWorld_WorldAsExpected()
        {
            const int expectedWidth  = 10;
            const int expectedHeight = 10;

            var world = WorldBuilder.BuildRandomWorld();

            Assert.Equal(expectedWidth, world.Width);
            Assert.Equal(expectedHeight, world.Height);
        }
Example #22
0
    public static WorldBuilder WithDefault3D(this WorldBuilder builder, uint numberOfAssets = 20, uint numberOfModels = 100) =>
    builder
    .WithComponent <AssetComponent <Model> >(ComponentPoolTypes.DynamicPacked, numberOfAssets)
    .WithComponent <ModelComponent>(ComponentPoolTypes.DynamicPacked, numberOfModels)
    .WithSystem <Render3DSystem>()
    .WithSystem <ModelLoaderSystem>()
#if DEBUG
    .WithSystem <BoundingBox2DDebugSystem>()
#endif
    ;
Example #23
0
        public static WorldBuilder AddPhysics2DFeature(this WorldBuilder self, Func <ISetTimeStep, IConfigurationEnd> configure)
        {
            var configurer = new Configurer();

            configure(configurer);

            // @formatter:off
            return(self.AddFeature(Name)
                   .DependsOn()
                   .Feature(CoreFeature.Name)
                   .Feature(DestroyFeature.Name)
                   .Feature(TickFeature.Name)
                   .End()
                   .Components <Game>()
                   .Add <Position>()
                   .Add <Velocity>()
                   .Add <Damping>()
                   .Add <Force>()
                   .Add <MaxVelocity>()
                   .Add <Mass>()
                   .Add <Orientation>()
                   .Add <AngularVelocity>()
                   .Add <MaxAngularVelocity>()
                   .Add <AngularDamping>()
                   .Add <Torque>()
                   .Add <Inertia>()
                   .Add <BoundingShapes>()
                   .Add <Collisions>()
                   .End()
                   .Components <Configuration>()
                   .Add <TimeStep>()
                   .Add <GlobalForce>()
                   .End()
                   .Components <Singletons>()
                   .Add <Space>()
                   .End()
                   .Systems()
                   .Setup((contexts, bus) => SetupSystem.Setup(contexts, configurer.TimeStep, configurer.SpatialDatabase))
                   .Update((contexts, bus) => AccelerateSystem.Update(contexts))
                   .Update((contexts, bus) => AngularAccelerateSystem.Update(contexts))
                   .Update((contexts, bus) => MoveSystem.Update(contexts))
                   .Update((contexts, bus) => RotateSystem.Update(contexts))
                   .Update((contexts, bus) => SpaceReindexSystem.Update(contexts))
                   .Update((contexts, bus) => FindCollisionsSystem.Update(contexts))
                   .Cleanup((contexts, bus) => SpatialDatabaseCleanupSystem.Cleanup(contexts))
                   .Cleanup((contexts, bus) => ReturnCollisionsListOnDestroySystem.Cleanup(contexts))
                   .Cleanup((contexts, bus) => ReturnShapesOnDestroySystem.Cleanup(contexts))
                   .End()
                   .GlobalComponentNotifications <Game>()
                   .AddAllNotifications <Position>()
                   .AddAllNotifications <Orientation>()
                   .End()
                   .End());
            // @formatter:on
        }
Example #24
0
    void Awake()
    {
        Singleton = this;

        LandBlocksHolder.position -= new Vector3(BuildWidth / 2f, 0, 0);

        for (int lineHeight = 0; lineHeight < BuildHeight; lineHeight++)
        {
            AddLandBlocksLine(lineHeight);
        }
    }
Example #25
0
    void Awake()
    {
        if (Instance != null)
        {
            Destroy(this);
            return;
        }

        Instance = this;
        DontDestroyOnLoad(gameObject);
    }
Example #26
0
    ////////////////////////////////////////////////
    ////////////////////////////////////////////////

    void Awake()
    {
        if (_instance != null && _instance != this)
        {
            Destroy(gameObject);
        }
        else
        {
            _instance = this;
        }
    }
Example #27
0
 private void Awake()
 {
     if (instance == null || instance == this)
     {
         instance = this;
     }
     else
     {
         Destroy(this);
     }
 }
Example #28
0
    void Awake()
    {
        _gameManager = FindObjectOfType <GameManager>();
        if (_gameManager == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }


        _worldBuilder = GetComponentInChildren <WorldBuilder>();
        if (_worldBuilder == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }

        _gridBuilder = GetComponentInChildren <GridBuilder> ();
        if (_gridBuilder == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }

        _mapPieceBuilder = GetComponentInChildren <MapPieceBuilder> ();
        if (_mapPieceBuilder == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }

        _outerZoneBuilder = GetComponentInChildren <OuterZoneBuilder>();
        if (_outerZoneBuilder == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }

        _playerShipBuilder = GetComponentInChildren <PlayerShipBuilder>();
        if (_playerShipBuilder == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }



        _cubeConnections = GetComponent <CubeConnections> ();
        if (_cubeConnections == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }

        _mapSettings = GetComponent <MapSettings> ();
        if (_mapSettings == null)
        {
            Debug.LogError("OOPSALA we have an ERROR!");
        }
    }
        public GameOfLife(IInputReader inputReader, IOutputWriter outputWriter)
        {
            StateGenerator = new StateGenerator();
            var inputProcessor = new WorldBuilder(inputReader);

            GridFormatter = new GridFormatter();
            OutputWriter  = outputWriter;

            World = inputProcessor.GetWorld();

            DisplayInitialGameOutput();
        }
Example #30
0
        public override void Draw(Vector2 position)
        {
            string label = "Chunks: \n";

            WorldBuilder world = Game.currentGame.world;

            label       += "Loaded: " + world.loaded;
            content.text = label;

            style.CalcSize(content);
            UnityEngine.GUI.Label(new Rect(position.x, position.y + 20, 20, 20), label, style);
        }
 public void OnEnable()
 {
     wb = (WorldBuilder)target;
     pos = wb.selPos;
 }
Example #32
0
    // Use this for initialization
    void Start()
    {
        if (instance != null) {
            return;
        }
        instance = this;

        AtavismEventSystem.RegisterEvent("CLAIM_ADDED", this);
        AtavismEventSystem.RegisterEvent("CLAIMED_REMOVED", this);

        // Register for messages relating to the claim system
        NetworkAPI.RegisterExtensionMessageHandler("claim_object", ClaimObjectMessage);
        NetworkAPI.RegisterExtensionMessageHandler("claim_object_bulk", ClaimObjectBulkMessage);
        NetworkAPI.RegisterExtensionMessageHandler("move_claim_object", MoveClaimObjectMessage);
        NetworkAPI.RegisterExtensionMessageHandler("update_claim_object_state", UpdateClaimObjectStateMessage);
        NetworkAPI.RegisterExtensionMessageHandler("remove_claim_object", RemoveClaimObjectMessage);
        NetworkAPI.RegisterExtensionMessageHandler("set_claim", ClaimIDMessage);
        NetworkAPI.RegisterExtensionMessageHandler("claim_updated", ClaimUpdatedMessage);
        NetworkAPI.RegisterExtensionMessageHandler("remove_claim", RemoveClaimMessage);
        NetworkAPI.RegisterExtensionMessageHandler("claim_deleted", RemoveClaimMessage);
        NetworkAPI.RegisterExtensionMessageHandler("claim_made", ClaimMadeMessage);
        NetworkAPI.RegisterExtensionMessageHandler("buildingResources", HandleBuildingResources);
    }