示例#1
0
        bool CheckBuildingAvailability(vec2 GridCoord, int PlayerNum, int TeamNum, float BuildingToPlace, bool[] CanPlace)
        {
            int _w = 3, _h = 3;

            Render.UnsetDevice();

            bool CanPlaceItem = false;

            for (int i = 0; i < _w; i++)
            {
                for (int j = 0; j < _h; j++)
                {
                    CanPlace[i + j * _w] = false;
                }
            }

            if (BuildingToPlace == UnitType.Barracks && PlayerNum > 0)
            {
                var _data = DataGroup.CurrentData.GetData <building>(GridCoord, new vec2(_w, _h));
                var _dist = DataGroup.DistanceToPlayers.GetData <PlayerTuple>(GridCoord, new vec2(_w, _h));

                color clr = color.TransparentBlack;
                if (_data != null)
                {
                    CanPlaceItem = true;
                    for (int i = 0; i < _w; i++)
                    {
                        for (int j = 0; j < _h; j++)
                        {
                            var building_here = _data[i + j * _w];
                            var distance_to   = _dist[i + j * _w];

                            var distance = GetPlayerVal(distance_to, PlayerNum);

                            bool occupied     = building_here.direction > 0;
                            bool in_territory = distance < DrawTerritoryPlayer.TerritoryCutoff;

                            bool can_place = !occupied && (in_territory || MapEditorActive);
                            CanPlace[i + j * _w] = can_place;

                            if (!can_place)
                            {
                                CanPlaceItem = false;
                            }
                        }
                    }
                }
            }

            if (BuildingToPlace == UnitType.GoldMine || BuildingToPlace == UnitType.JadeMine)
            {
                var _data = DataGroup.CurrentUnits.GetData <unit>(GridCoord, new vec2(_w, _h));
                var _dist = DataGroup.DistanceToPlayers.GetData <PlayerTuple>(GridCoord, new vec2(_w, _h));

                color clr = color.TransparentBlack;
                if (_data != null)
                {
                    CanPlaceItem = true;
                    for (int i = 0; i < _w; i++)
                    {
                        for (int j = 0; j < _h; j++)
                        {
                            var unit_here   = _data[i + j * _w];
                            var distance_to = _dist[i + j * _w];

                            var distance = GetPlayerVal(distance_to, PlayerNum);

                            bool occupied        = unit_here.type > 0;
                            bool is_valid_source = unit_here.team == Team.None && unit_here.type == BuildingToPlace;
                            bool in_territory    = distance < DrawTerritoryPlayer.TerritoryCutoff;

                            bool can_place = (is_valid_source || MapEditorActive && !occupied) && (in_territory || MapEditorActive);
                            CanPlace[i + j * _w] = can_place;

                            if (!can_place)
                            {
                                CanPlaceItem = false;
                            }
                        }
                    }
                }
            }

            return(CanPlaceItem);
        }
示例#2
0
        void GameLogic(GameTime gameTime)
        {
            //Send("setMode", "in-game");
            //Send("setScreen", "in-game-ui");

            switch (State)
            {
            case GameState.ToEditor:
                NewWorldEditor();
                State = GameState.Game;

                Send("setMode", "in-game");
                Send("setScreen", "editor-ui");

                break;

            case GameState.ToMap:
                Render.StandardRenderSetup();
                DrawFullScreen(Assets.ScreenLoading);

                if (Program.StartupMap == null)
                {
                    Program.StartupMap = "Beset.m3n";
                }
                SetScenarioToLoad(Program.StartupMap);

                break;

            case GameState.TitleScreen:
                StartMenuMusicIfNeeded();
                AmbientSounds.EndAll();

                // No mouse input to web browser.
                SteamWrapper.SteamHtml.AllowMouseEvents = false;

                Render.StandardRenderSetup();

                DrawFullScreen(Assets.ScreenTitle);

                if (gameTime.TotalGameTime.Seconds < .005f)
                {
                    break;
                }

                if (MouseMovedSome)
                {
                    World.DrawArrowCursor();
                }
                else
                {
                    if (Input.DeltaMousPos.Length() > 40)
                    {
                        MouseMovedSome = true;
                    }
                }

                if (InputHelper.SomethingPressed())
                {
                    State = GameState.MainMenu;
                    Send("setMode", "main-menu");
                    Send("setScreen", "game-menu");
                }

                break;

            case GameState.MainMenu:
                StartMenuMusicIfNeeded();
                AmbientSounds.EndAll();

                if (!InputHelper.SomethingDown())
                {
                    SteamWrapper.SteamHtml.AllowMouseEvents = true;
                }

                if (_MapLoading != MapLoading)
                {
                    _MapLoading = MapLoading;
                    SetMapLoading();
                }

                if (MapLoading && NewMap != null)
                {
                    World      = NewMap;
                    MapLoading = false;

                    SetMapLoading();
                }

                Render.StandardRenderSetup();
                if (DrawMapPreview && World != null && World.DataGroup != null)
                {
                    Render.UnsetDevice();
                    try
                    {
                        World.DataGroup.UpdateGradient_ToPlayers();
                        World.DataGroup.UpdateGradient_ToBuildings();
                        World.DataGroup.UpdateGradient_ToPlayers();
                        World.DataGroup.UpdateGradient_ToBuildings();
                    }
                    catch
                    {
                    }

                    World.UpdateMinimap();

                    GridHelper.GraphicsDevice.SetRenderTarget(null);
                }

                Render.StandardRenderSetup();
                DrawFullScreen(Assets.ScreenDark);
                DrawWebView();

                if (DrawMapPreview && World != null && World.DataGroup != null)
                {
                    MapPreviewPos  = new vec2(0.76f, 0.32f);
                    MapPreviewSize = new vec2(.4f, .4f);

                    bool UseSolidColor = MapLoading || World == BlankWorld;
                    World.DrawMinimap(MapPreviewPos, MapPreviewSize, ShowCameraBox: false, SolidColor: UseSolidColor);
                }

                World.DrawArrowCursor();

                break;

            case GameState.Loading:
                FadeOutMenuMusicIfNeeded();

                PreGame();

                Render.StandardRenderSetup();
                DrawFullScreen(Assets.ScreenLoading);

                if (ScenarioToLoad != null)
                {
                    Send("setMode", "in-game");
                    Send("setScreen", "in-game-ui");

                    World = new World(
                        GameParams: Program.StartupGameParams,
                        RemoveComputerDragonLords: Program.RemoveComputerDragonLords);

                    TimeLoading          = 0;
                    World.LoadPlayerInfo = false;
                    World.Load(Path.Combine(MapDirectory, ScenarioToLoad));

                    Program.WorldLoaded = true;
                    Networking.ToServer(new Message(MessageType.DoneLoading));

                    ScenarioToLoad = null;
                    TimeSinceLoad  = 0;
                    DrawFullScreen(Assets.ScreenLoading);

                    GetNames();


                    //World.SaveCurrentStateInBuffer();
                    ////var m = new MessageGameState(World.SimStep, World.WorldBytes);
                    //var m = new Message(MessageType.DoneLoading);
                    //var s = m.Encode();

                    //Networking.SendString(new SteamPlayer(SteamCore.PlayerId()), s);
                    //var t = Networking.ReceiveString();
                    //var _s = t.Item2;

                    //Console.WriteLine("!");
                }

                if (Program.GameStarted)
                {
                    if (Program.Spectate)
                    {
                        State = GameState.Game;
                    }
                }
                else
                {
                    TimeLoading += DeltaT;

                    if (TimeLoading > 25)
                    {
                        OnFailedToJoinGame();
                    }

                    TimeSinceLoad = 0;
                    break;
                }

                FadeOutLoading();

                break;

            case GameState.Game:
                StartGameMusicIfNeeded();

                CalculateMouseDownOverUi();

                DrawGame(gameTime);

                if (Program.Spectate && ShouldDrawFading())
                {
                    Render.StandardRenderSetup();
                    DrawFullScreen(Assets.ScreenLoading);

                    FadeOutLoading();
                }
                else
                {
                    DrawWebView();

                    World.DrawUi();

                    if (TimeSinceLoad < 1.5f)
                    {
                        BlackOverlay(1f - (float)(TimeSinceLoad - 1.3f) / .2f);
                    }
                }

                break;
            }
        }