Exemple #1
0
        public float ArgTo0to1(float arg)
        {
            string stringVal;

            try
            {
                stringVal = arg.ToString();
            }
            catch (Exception e)
            {
                return(0);
            }

            float val = (float)CoreMath.ParseDouble(stringVal);

            if (val < 0)
            {
                val = 0;
            }
            if (val > 1)
            {
                val = 1;
            }

            return(val);
        }
Exemple #2
0
        public static void RotatedBasis(float Degrees, ref Vector2 v)
        {
            Vector2 e1 = CoreMath.DegreesToDir(Degrees);
            Vector2 e2 = CoreMath.DegreesToDir(Degrees + 90);

            v = v.X * e1 + v.Y * e2;
        }
Exemple #3
0
        void PostPaintUpdate()
        {
            PaintTiles_UpdateData.Apply(DataGroup.Tiles, DataGroup.CurrentUnits, DataGroup.CurrentData, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.CurrentData);

            PaintTiles_UpdateUnits.Apply(DataGroup.Tiles, DataGroup.CurrentUnits, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.CurrentUnits);

            PaintTiles_UpdateTiles.Apply(DataGroup.Tiles, DataGroup.SelectField, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.Tiles);

            Render.UnsetDevice();
            DataGroup.Geo.Clear();
            DataGroup.AntiGeo.Clear();
            DataGroup.MockTiles.Clear();
            DataGroup.OuterGeo.Clear();
            DataGroup.TempGeo.Clear();
            DataGroup.GeoInfo.Clear();
            foreach (var dir in Dir.Vals)
            {
                DataGroup.Dirward[dir].Clear();
            }
            UpdateGeo(false);
            UpdateGeo(true);
        }
Exemple #4
0
        protected static vec2 PopVec2(ref string s)
        {
            string vecString = Pop(ref s);

            var parts = vecString.Split(':');

            return(new vec2(CoreMath.ParseFloat(parts[0]), CoreMath.ParseFloat(parts[1])));
        }
Exemple #5
0
        void SetReducedGeoId(bool Anti)
        {
            SwapTempGeo(Anti);

            Geodesic_SetGeoId.Apply(DataGroup.TempGeo, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.TempGeo);

            SwapTempGeo(Anti);
        }
Exemple #6
0
        void PaintTiles()
        {
            float tile = TileUserIsPlacing;

            Action_PaintTiles.Apply(DataGroup.Tiles, DataGroup.SelectField, DataGroup.RandomField, tile, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.Tiles);

            PostPaintUpdate();
        }
Exemple #7
0
        void MarkGeoBoundary(bool Anti)
        {
            SwapTempGeo(Anti);

            Geodesic_Boundary.Apply(DataGroup.TempGeo, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.TempGeo);

            SwapTempGeo(Anti);
        }
Exemple #8
0
        public bool FireballApply(int PlayerNumber, int TeamNumber, vec2 GridCoord)
        {
            AddExplosion(GridToWorldCood(GridCoord), 2 * vec(Spells.FlameRadius, Spells.FlameRadius));

            SetEffectArea(GridCoord, Spells.FlameRadius, PlayerNumber);

            Kill.Apply(DataGroup.SelectField, DataGroup.Magic, DataGroup.AntiMagic, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.Magic);

            return(true);
        }
Exemple #9
0
 void SwapTempGeo(bool Anti)
 {
     if (Anti)
     {
         CoreMath.Swap(ref DataGroup.AntiGeo, ref DataGroup.TempGeo);
     }
     else
     {
         CoreMath.Swap(ref DataGroup.Geo, ref DataGroup.TempGeo);
     }
 }
Exemple #10
0
 public static float SmoothLerp(float v1, float v2, float t)
 {
     return(FancyLerp(t, new float[] {
         CoreMath.Lerp(v1, v2, 0),
         CoreMath.Lerp(v1, v2, 0.5f),
         CoreMath.Lerp(v1, v2, 0.75f),
         CoreMath.Lerp(v1, v2, 0.875f),
         CoreMath.Lerp(v1, v2, 0.9375f),
         CoreMath.Lerp(v1, v2, 1)
     }));
 }
Exemple #11
0
        void PropagateFullGeoId(bool Anti)
        {
            SwapTempGeo(Anti);

            for (int i = 0; i < 1024; i++)
            {
                Geodesic_ExtremityPropagation.Apply(DataGroup.TempGeo, Output: DataGroup.Temp1);
                CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.TempGeo);
            }

            SwapTempGeo(Anti);
        }
Exemple #12
0
        void DeleteUnits()
        {
            ActionDelete_Data.Apply(DataGroup.CurrentData, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.CurrentData);

            ActionDelete_Data.Apply(DataGroup.PreviousData, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.PreviousData);

            BuildingInfusion_Delete.Apply(DataGroup.CurrentUnits, DataGroup.CurrentData, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.CurrentData, ref DataGroup.Temp1);

            DataGroup.Building_InfusionDiffusion();
        }
Exemple #13
0
        public void Migrate()
        {
            Render.UnsetDevice();

            //DataGroup.Corpses.Clear();

            UnitMigrate.Apply(DataGroup.CurrentUnits, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.CurrentUnits);

            UnitMigrate.Apply(DataGroup.PreviousUnits, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.PreviousUnits);

            Render.UnsetDevice();
        }
Exemple #14
0
        void DirwardExtend(bool Anti)
        {
            SwapTempGeo(Anti);

            for (int i = 0; i <= 100; i++)
            {
                foreach (var dir in Dir.Vals)
                {
                    Geodesic_DirwardExtend.Apply(DataGroup.Tiles, DataGroup.TempGeo, DataGroup.Dirward[dir], dir, Output: DataGroup.Temp1);
                    DataGroup.Dirward[dir] = CoreMath.SwapReturn(ref DataGroup.Temp1, DataGroup.Dirward[dir]);
                }
            }

            SwapTempGeo(Anti);
        }
Exemple #15
0
        void UpdateGeo(bool Anti)
        {
            Geodesic_Outline.Apply(DataGroup.Tiles, Anti, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.TempGeo);

            for (int i = 0; i < 5; i++)
            {
                Geodesic_OutlineCleanup.Apply(DataGroup.Tiles, DataGroup.TempGeo, Anti, Output: DataGroup.Temp1);
                CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.TempGeo);
            }

            Geodesic_StorePos.Apply(DataGroup.TempGeo, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.TempGeo);

            SwapTempGeo(Anti);
        }
Exemple #16
0
        public void Play(float volume, float pitch, float pan)
        {
            if (SoundWad.SuppressSounds)
            {
                return;
            }

            volume = CoreMath.Restrict(0, 1, volume);

            try
            {
                sound.Play(volume * GameClass.Game.CurrentConfig.SoundVolume * DefaultVolume, CoreMath.Restrict(-1, 1, pitch), CoreMath.Restrict(-1, 1, pan));
            }
            catch (Exception e)
            {
            }
        }
Exemple #17
0
        public void SpawnUnits(vec2 grid_coord, float player, float team, float type, float distribution, bool raising = true)
        {
            if (MapEditorActive)
            {
                raising = false;
            }

            if (distribution == UnitDistribution.Single)
            {
                bool placed = false;
                PlaceUnit(ref placed, type, grid_coord, player, team);
                return;
            }

            ActionSpawn_Filter.Apply(DataGroup.SelectField, DataGroup.CurrentData, DataGroup.CurrentUnits, DataGroup.Corpses, DataGroup.AntiMagic, distribution, team, Output: DataGroup.Temp2);
            var Filter = DataGroup.Temp2;

            ActionSpawn_Unit.Apply(Filter, DataGroup.CurrentUnits, player, team, type, raising, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.CurrentUnits);

            if (SimulationPaused)
            {
                ActionSpawn_Unit.Apply(Filter, DataGroup.PreviousUnits, player, team, type, raising, Output: DataGroup.Temp1);
                CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.PreviousUnits);
            }

            ActionSpawn_Target.Apply(Filter, DataGroup.TargetData, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.TargetData);

            ActionSpawn_Data.Apply(Filter, DataGroup.CurrentData, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.CurrentData);

            if (SimulationPaused)
            {
                ActionSpawn_Data.Apply(Filter, DataGroup.PreviousData, Output: DataGroup.Temp1);
                CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.PreviousData);
            }

            if (distribution == UnitDistribution.OnCorpses)
            {
                ActionSpawn_Corpse.Apply(Filter, DataGroup.Corpses, Output: DataGroup.Temp1);
                CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.Corpses);
            }
        }
Exemple #18
0
        void CalculatePolarDistance()
        {
            for (int i = 0; i < 1024; i++)
            {
                Geodesic_PolarDistance.Apply(DataGroup.Geo, DataGroup.GeoInfo, Output: DataGroup.Temp1);
                CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.GeoInfo);
            }

            Geodesic_SetCircumference.Apply(DataGroup.Geo, DataGroup.GeoInfo, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.GeoInfo);


            foreach (var dir in Dir.Vals)
            {
                Identity.Apply(DataGroup.Geo, Output: DataGroup.Temp1);
                CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.ShiftedGeo);
                Identity.Apply(DataGroup.GeoInfo, Output: DataGroup.Temp1);
                CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.ShiftedGeoInfo);


                for (int i = 0; i < 256; i++)
                {
                    Shift.Apply(DataGroup.ShiftedGeo, dir, Output: DataGroup.Temp1);
                    CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.ShiftedGeo);
                    Shift.Apply(DataGroup.ShiftedGeoInfo, dir, Output: DataGroup.Temp1);
                    CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.ShiftedGeoInfo);

                    Geodesic_Polarity.Apply(DataGroup.Dirward[dir], DataGroup.Geo, DataGroup.ShiftedGeo, DataGroup.GeoInfo, DataGroup.ShiftedGeoInfo, dir, Output: DataGroup.Temp1);
                    DataGroup.Dirward[dir] = CoreMath.SwapReturn(ref DataGroup.Temp1, DataGroup.Dirward[dir]);
                }

                for (int i = 0; i < 50; i++)
                {
                    Geodesic_FillMissingPolarity.Apply(DataGroup.Dirward[dir], DataGroup.Geo, Output: DataGroup.Temp1);
                    DataGroup.Dirward[dir] = CoreMath.SwapReturn(ref DataGroup.Temp1, DataGroup.Dirward[dir]);
                }

                Geodesic_ClearImportance.Apply(DataGroup.Dirward[dir], Output: DataGroup.Temp1);
                DataGroup.Dirward[dir] = CoreMath.SwapReturn(ref DataGroup.Temp1, DataGroup.Dirward[dir]);
            }
            // probably want a larger total shift than 256 eventually, but keep it less than the width of the map (maybe width minus 1, to avoid boundary condition)
            // set signal on movement data output once polarity is set, then capture signal and store polarity and geo_id
        }
Exemple #19
0
        void GameOverLogic()
        {
            if (World == null || !World.GameOver || World.MapEditor)
            {
                return;
            }

            float dist    = (World.DragonLordDeathPos - World.GameOverPos).Length();
            float PanTime = CoreMath.LerpRestrict(0, .5f, 1.35f, 2, dist);

            if (T - World.GameOverTime < PanTime)
            {
                DeltaT            *= .03f;
                World.Markers.Hide = true;
            }
            else if (T - World.GameOverTime < PanTime + 1.25)
            {
                DeltaT *= .35f;

                if (!World.End_PlayedDeathGroan && T - World.GameOverTime > PanTime + 0.0)
                {
                    Sounds.DyingDragonLord.MaybePlay();
                    World.End_PlayedDeathGroan = true;
                }
            }
            else
            {
                World.Markers.Hide = false;

                if (!World.End_PlayedDeathExplosion)
                {
                    Sounds.EndOfGameDyingDragonLord.MaybePlay();
                    World.End_PlayedDeathExplosion = true;
                }
            }

            GameInputEnabled = false;

            float s = (float)Math.Min(1, (T - World.GameOverTime) / PanTime);

            World.CameraPos  = s * World.DragonLordDeathPos + (1 - s) * World.GameOverPos;
            World.CameraZoom = CoreMath.LogLerpRestrict((float)World.GameOverTime, World.GameOverZoom, (float)World.GameOverTime + 1.25f, 100, (float)T);
        }
Exemple #20
0
        void _GrowGeo(bool Anti)
        {
            SwapTempGeo(Anti);

            Geodesic_ConvertToBlocking.Apply(DataGroup.Tiles, DataGroup.TempGeo, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.MockTiles);

            Geodesic_Outline.Apply(DataGroup.MockTiles, Anti, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.OuterGeo);

            for (int i = 0; i < 5; i++)
            {
                Geodesic_OutlineCleanup.Apply(DataGroup.MockTiles, DataGroup.OuterGeo, Anti, Output: DataGroup.Temp1);
                CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.OuterGeo);
            }

            Geodesic_Flatten.Apply(DataGroup.TempGeo, DataGroup.OuterGeo, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.TempGeo);

            SwapTempGeo(Anti);
        }
Exemple #21
0
        private void MakeMapSymmetric(float type, bool convert_dragonlords)
        {
            MakeSymmetric.Apply(DataGroup.Tiles, type, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.Tiles);

            MakeSymmetric.Apply(DataGroup.CurrentData, type, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.CurrentData);

            MakeSymmetric.Apply(DataGroup.PreviousData, type, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.PreviousData);

            MakeUnitsSymmetric.Apply(DataGroup.CurrentUnits, type, convert_dragonlords, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.CurrentUnits);

            MakeUnitsSymmetric.Apply(DataGroup.PreviousUnits, type, convert_dragonlords, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.PreviousUnits);

            MakeSymmetric.Apply(DataGroup.Extra, type, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.Extra);

            MakeTargetSymmetric.Apply(DataGroup.TargetData, type, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.TargetData);

            MakeSymmetric.Apply(DataGroup.Corpses, type, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.Corpses);

            FixBuildings_1.Apply(DataGroup.CurrentData, DataGroup.CurrentUnits, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.CurrentData);

            FixBuildings_1.Apply(DataGroup.PreviousData, DataGroup.PreviousUnits, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.PreviousData);

            FixBuildings_2.Apply(DataGroup.CurrentData, DataGroup.CurrentUnits, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.CurrentData);

            FixBuildings_2.Apply(DataGroup.PreviousData, DataGroup.PreviousUnits, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.PreviousData);

            PostPaintUpdate();
        }
Exemple #22
0
        public static void SetVolume(this SoundEffectInstance instance, float volume)
        {
            float restrictedVolume = CoreMath.Restrict(0, 1, volume);

            instance.Volume = restrictedVolume;
        }
Exemple #23
0
 public static void CopyFromTo(RenderTarget2D Source, ref RenderTarget2D Destination, ref RenderTarget2D Temporary)
 {
     Identity.Apply(Source, Output: Temporary);
     CoreMath.Swap(ref Destination, ref Temporary);
 }
Exemple #24
0
        public void Update()
        {
            if (!GameClass.Game.GameInputEnabled || DesyncPause)
            {
                return;
            }

            EditorUpdate();

            float FpsRateModifier = 1;

            //const float MaxZoomOut = 5.33333f, MaxZoomIn = 200f;
            //const float MaxZoomOut = 3.2f, MaxZoomIn = 200f;
            //const float MaxZoomOut = 1f, MaxZoomIn = 200f; // Full zoom-in/out

            float MaxZoomOut, MaxZoomIn;

            if (MapEditorActive)
            {
                // Full zoom-in/out
                MaxZoomOut = .733f;
                MaxZoomIn  = 200f;
            }
            else
            {
                MaxZoomOut = World.StaticMaxZoomOut;
                MaxZoomIn  = 200f; // Full zoom-in, Partial zoom-out
            }

            // Focus on player's dragon lord.
            if (!GameClass.Game.ShowChat && Keys.Space.Down())
            {
                var dl_pos = PrevDragonLordPos[MyPlayerNumber];

                if (dl_pos > vec(1, 1))
                {
                    CameraPos  = GridToWorldCood(dl_pos);
                    CameraZoom = 24;
                }
            }

            // Zoom all the way out
            //if (!GameClass.Game.ShowChat && Keys.Space.Down())
            //{
            //    CameraZoom = MaxZoomOut;
            //}

            // Zoom in/out, into the location of the cursor
            var world_mouse_pos = ScreenToWorldCoord(Input.CurMousePos);
            var hold_camvec     = camvec;

            if (GameClass.MouseEnabled)
            {
                float MouseWheelZoomRate = 1.3333f * FpsRateModifier;
                if (Input.DeltaMouseScroll < 0)
                {
                    CameraZoom /= MouseWheelZoomRate;
                }
                else if (Input.DeltaMouseScroll > 0)
                {
                    CameraZoom *= MouseWheelZoomRate;
                }
            }

            float KeyZoomRate = 1.125f * FpsRateModifier;

            if (!GameClass.Game.ShowChat && (Buttons.X.Down() || Keys.X.Down() || Keys.E.Down()))
            {
                CameraZoom /= KeyZoomRate;
            }
            else if (!GameClass.Game.ShowChat && (Buttons.A.Down() || Keys.Z.Down() || Keys.Q.Down()))
            {
                CameraZoom *= KeyZoomRate;
            }

            if (CameraZoom < MaxZoomOut)
            {
                CameraZoom = MaxZoomOut;
            }
            if (CameraZoom > MaxZoomIn)
            {
                CameraZoom = MaxZoomIn;
            }

            if (GameClass.MouseEnabled && !(Buttons.A.Pressed() || Buttons.X.Pressed()))
            {
                if (MouseOverMinimap)
                {
                    //var zoom_center = (UiMousePos - MinimapQuad.pos) / MinimapQuad.size;

                    //var shifted = GetShiftedCameraMinimap(Input.CurMousePos, camvec, zoom_center);
                    //CameraPos = shifted;
                }
                else
                {
                    vec2 zoom_center = world_mouse_pos;

                    var shifted = GetShiftedCamera(Input.CurMousePos, camvec, zoom_center);
                    CameraPos = shifted;
                }
            }

            // Move the camera via: Click And Drag
            //float MoveRate_ClickAndDrag = .00165f * FpsRateModifier;
            //if (Input.LeftMouseDown)
            //    CameraPos += Input.DeltaMousPos / CameraZoom * MoveRate_ClickAndDrag * new vec2(-1, 1);

            // Move the camera via: Push Edge
            if (GameClass.MouseEnabled &&
                (GameClass.Game.CurrentConfig.Fullscreen || BoxSelecting) &&
                (!Program.DisableScreenEdge || BoxSelecting))
            {
                float MoveRate_PushEdge = .075f * FpsRateModifier;
                var   push_dir          = vec2.Zero;
                float EdgeRatio         = .005f;
                push_dir.x += -CoreMath.Restrict(0, 1, (EdgeRatio * GameClass.Screen.x - Input.CurMousePos.x) / (EdgeRatio * GameClass.Screen.x));
                push_dir.x += CoreMath.Restrict(0, 1, (Input.CurMousePos.x - (1 - EdgeRatio) * GameClass.Screen.x) / (EdgeRatio * GameClass.Screen.x));
                push_dir.y -= -CoreMath.Restrict(0, 1, (EdgeRatio * GameClass.Screen.y - Input.CurMousePos.y) / (EdgeRatio * GameClass.Screen.y));
                push_dir.y -= CoreMath.Restrict(0, 1, (Input.CurMousePos.y - (1 - EdgeRatio) * GameClass.Screen.y) / (EdgeRatio * GameClass.Screen.y));

                CameraPos += push_dir / CameraZoom * MoveRate_PushEdge;
            }

            // Move the camera via: Keyboard or Gamepad
            if (!GameClass.Game.ShowChat && !(MapEditorActive && InputHelper.CtrlDown()))
            {
                var dir = Input.Direction();

                float MoveRate_Keyboard = .07f * FpsRateModifier;
                CameraPos += dir / CameraZoom * MoveRate_Keyboard;
            }

            // Move the camera via: Minimap
            if ((LeftMouseDown || Input.DeltaMouseScroll != 0) && !BoxSelecting && MouseOverMinimap)
            {
                CameraPos = MinimapWorldPos();
            }


            // Make sure the camera doesn't go too far offscreen
            y_edge = 1 + 0.433f / CameraZoom;
            x_edge = Math.Max(.5f * (CameraAspect / CameraZoom) + .5f * (CameraAspect / MaxZoomOut), 1); // Old style zoom out bounds.
            x_edge = Math.Min(x_edge, y_edge * CameraAspect);
            x_edge = CoreMath.LogLerpRestrict(MaxZoomIn, 1 + .35f / CameraZoom, MaxZoomOut, x_edge, CameraZoom);

            if (CameraZoom == MaxZoomOut)
            {
                CameraPos = vec(0, -0.07f);
            }

            var TR = ScreenToWorldCoord(new vec2(GameClass.Screen.x, 0));

            if (TR.x > x_edge)
            {
                CameraPos = new vec2(CameraPos.x - (TR.x - x_edge), CameraPos.y);
            }
            if (TR.y > y_edge)
            {
                CameraPos = new vec2(CameraPos.x, CameraPos.y - (TR.y - y_edge));
            }
            var BL = ScreenToWorldCoord(new vec2(0, GameClass.Screen.y));

            if (BL.x < -x_edge)
            {
                CameraPos = new vec2(CameraPos.x - (BL.x + x_edge), CameraPos.y);
            }
            if (BL.y < -y_edge)
            {
                CameraPos = new vec2(CameraPos.x, CameraPos.y - (BL.y + y_edge));
            }


            // Switch to chat
            if (!GameClass.Game.ShowChat && Keys.Enter.Pressed() && ChatInhibitor <= 0)
            {
                GameClass.Game.ChatGlobal = !(Keys.LeftShift.Down() || Keys.RightShift.Down());
                GameClass.Game.ToggleChatViaFlag();
            }
            if (GameClass.Game.ShowChat)
            {
                ChatInhibitor = 5; return;
            }
            if (ChatInhibitor > 0 && !Keys.Enter.Down())
            {
                ChatInhibitor--;
            }

            // Switch input modes

            // Switch to spells (must be playing, not in editor)
            if (!SimulationPaused)
            {
                if (Keys.D1.Pressed())
                {
                    StartSpell(Spells.Fireball);
                }
                if (Keys.D2.Pressed())
                {
                    StartSpell(Spells.SkeletonArmy);
                }
                if (Keys.D3.Pressed())
                {
                    StartSpell(Spells.Necromancer);
                }
                if (Keys.D4.Pressed())
                {
                    StartSpell(Spells.TerracottaArmy);
                }
            }

            // Switch to building placement
            if (Keys.B.Down())
            {
                StartPlacingBuilding(UnitType.Barracks);
            }
            if (Keys.G.Down())
            {
                StartPlacingBuilding(UnitType.GoldMine);
            }
            if (Keys.J.Down())
            {
                StartPlacingBuilding(UnitType.JadeMine);
            }

            // Switch to standard select
            if (Keys.Escape.Down() || Keys.Back.Down() || Input.RightMousePressed)
            {
                SetModeToSelect();
            }

            // Switch to unit placement (editor only)
            if (MapEditorActive)
            {
                if (Keys.R.Down())
                {
                    StartUnitPaint(UnitType.Footman);
                }
                if (Keys.T.Down())
                {
                    StartUnitPaint(UnitType.DragonLord);
                }
                if (Keys.Y.Down())
                {
                    StartUnitPaint(UnitType.Necromancer);
                }
                if (Keys.U.Down())
                {
                    StartUnitPaint(UnitType.Skeleton);
                }
                if (Keys.I.Down())
                {
                    StartUnitPaint(UnitType.ClaySoldier);
                }

                if (Keys.C.Down())
                {
                    StartTilePaint(TileType.Dirt);
                }
                if (Keys.V.Down())
                {
                    StartTilePaint(TileType.Grass);
                }
                if (Keys.N.Down())
                {
                    StartTilePaint(TileType.Trees);
                }

                if (Keys.Tab.Pressed())
                {
                    SetUnitPlaceStyle((int)Math.Round(UnitPlaceStyle) + 1);
                }
            }
        }
Exemple #25
0
        public void Startup()
        {
            Render.UnsetDevice();

            int user_count = 0;

            for (int p = 1; p <= 4; p++)
            {
                if (Program.SteamUsers[p - 1] != 0)
                {
                    user_count++;
                }
            }

            if (RemoveComputerDragonLords && user_count > 1)
            {
                for (int player = 1; player <= 4; player++)
                {
                    if (Program.PlayersSteamUser[player] == 0)
                    {
                        RemoveDragonLordData.Apply(DataGroup.CurrentUnits, DataGroup.CurrentData, Player.Vals[player], Output: DataGroup.Temp1);
                        RemoveDragonLordUnit.Apply(DataGroup.CurrentUnits, DataGroup.CurrentData, Player.Vals[player], Output: DataGroup.Temp2);
                        CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.CurrentData);
                        CoreMath.Swap(ref DataGroup.Temp2, ref DataGroup.CurrentUnits);

                        RemoveDragonLordData.Apply(DataGroup.PreviousUnits, DataGroup.PreviousData, Player.Vals[player], Output: DataGroup.Temp1);
                        RemoveDragonLordUnit.Apply(DataGroup.PreviousUnits, DataGroup.PreviousData, Player.Vals[player], Output: DataGroup.Temp2);
                        CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.PreviousData);
                        CoreMath.Swap(ref DataGroup.Temp2, ref DataGroup.PreviousUnits);
                    }
                }
            }

            // Set datagroup team data.
            SetTeams.Apply(DataGroup.CurrentUnits, DataGroup.CurrentData, PlayerTeamVals, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.CurrentUnits);

            SetTeams.Apply(DataGroup.PreviousUnits, DataGroup.PreviousData, PlayerTeamVals, Output: DataGroup.Temp1);
            CoreMath.Swap(ref DataGroup.Temp1, ref DataGroup.PreviousUnits);

            DataGroup.DistanceToOtherTeams.Clear();
            for (int i = 0; i < 24; i++)
            {
                DataGroup.UpdateGradient_ToOtherTeams();
            }

            if (MyPlayerNumber > 0)
            {
                // Focus camera on a dragon lord.
                vec2 pos = DataGroup.DragonLordPos(MyPlayerValue);

                CameraPos  = GridToWorldCood(pos);
                CameraZoom = 80f;
            }
            else
            {
                // We're a spectator, so choose netural position.
                CameraPos  = vec2.Zero;
                CameraZoom = 1.45f;
            }

            Render.UnsetDevice();
        }
Exemple #26
0
 protected static float PopFloat(ref string s)
 {
     return(CoreMath.ParseFloat(Pop(ref s)));
 }
Exemple #27
0
 public static float LerpRestrict(float v1, float v2, float t)
 {
     return(Lerp(v1, v2, CoreMath.Restrict(0, 1, t)));
 }
Exemple #28
0
        void DrawDragonLordMarker(int player, bool After = false)
        {
            if (!TrackDragonLord)
            {
                return;
            }

            vec2 cur  = CurDragonLordPos[player];
            vec2 prev = PrevDragonLordPos[player];

            if (cur.x < 1 && cur.y < 1)
            {
                return;
            }

            var q = new RectangleQuad();
            var p = cur * PercentSimStepComplete + prev * (1 - PercentSimStepComplete);

            p = GridToWorldCood(p);
            var   s     = vec(.01f, .01f) + .0001f * vec2.Ones * (float)Math.Cos(GameClass.Game.DrawCount * .08f);
            float alpha = 1;

            bool selected = DataGroup.UnitSummary[Int(UnitType.DragonLord) - 1];

            if (!After)
            {
                alpha = selected ? .11f : .05f;
                color clr = selected ? new color(1f, 1f, 1f, alpha) : new color(.8f, .8f, .8f, alpha);

                q.SetupVertices(p - s * 3, p + s * 3, vec(0, 0), vec(1, 1));
                q.SetColor(clr);

                DrawTexture.Using(camvec, CameraAspect, Assets.DragonLord_Marker);
                q.Draw(GameClass.Game.GraphicsDevice);

                q.SetupVertices(p - s * .5f, p + s * .5f, vec(0, 0), vec(1, 1));
                q.SetColor(clr);

                DrawTexture.Using(camvec, CameraAspect, Assets.DragonLord_Marker);
                q.Draw(GameClass.Game.GraphicsDevice);
            }

            if (After)
            {
                float z = 14;
                if (CameraZoom <= z / 4f)
                {
                    s    *= 7;
                    alpha = CoreMath.LerpRestrict(z / 4, 0, z / 8, 1, CameraZoom);
                }
                else
                {
                    return;
                }

                q.SetupVertices(p - s, p + s, vec(0, 0), vec(1, 1));
                q.SetColor(new color(.8f, .8f, .8f, 1f * alpha));

                var texture = Assets.AoE_DragonLord[player];
                if (player == MyPlayerNumber && selected)
                {
                    texture = Assets.AoE_DragonLord_Selected;
                }

                DrawTexture.Using(camvec, CameraAspect, texture);
                q.Draw(GameClass.Game.GraphicsDevice);
            }
        }
Exemple #29
0
        void DrawGrids()
        {
            // Draw texture to screen
            //GameClass.Graphics.SetRenderTarget(null);
            GameClass.Graphics.Clear(Color.Black);

            if (MapEditorActive)
            {
                PercentSimStepComplete = .9f;
            }
            else
            {
                PercentSimStepComplete = (float)(SecondsSinceLastUpdate / DelayBetweenUpdates);
            }

            float z = 14;

            // Draw parts of the world outside the playable map
            float tiles_solid_blend      = CoreMath.LogLerpRestrict(1f, 0, 5f, 1, CameraZoom);
            bool  tiles_solid_blend_flag = tiles_solid_blend < 1;

            if (x_edge > 1 || y_edge > 1)
            {
                DrawOutsideTiles.Using(camvec, CameraAspect, DataGroup.Tiles, TileSprite, tiles_solid_blend_flag, tiles_solid_blend);

                OutsideTiles.SetupVertices(vec(-2.5f, -2f), vec(2.5f, 2), vec(0, 0), vec(-5 / 2, 2 / 1));
                OutsideTiles.Draw(GameClass.Graphics);
            }

            // The the map tiles
            DrawTiles.Using(camvec, CameraAspect, DataGroup.Tiles, TileSprite, MapEditorActive && DrawGridLines, tiles_solid_blend_flag, tiles_solid_blend);
            GridHelper.DrawGrid();

            //DrawGeoInfo.Using(camvec, CameraAspect, DataGroup.Geo, Assets.DebugTexture_Arrows); GridHelper.DrawGrid();
            //DrawGeoInfo.Using(camvec, CameraAspect, DataGroup.AntiGeo, Assets.DebugTexture_Arrows); GridHelper.DrawGrid();
            //DrawDirwardInfo.Using(camvec, CameraAspect, DataGroup.Dirward[Dir.Right], Assets.DebugTexture_Arrows); GridHelper.DrawGrid();
            //DrawPolarInfo.Using(camvec, CameraAspect, DataGroup.Geo, DataGroup.GeoInfo, Assets.DebugTexture_Num); GridHelper.DrawGrid();

            // Territory and corpses
            if ((CurUserMode == UserMode.PlaceBuilding || CurUserMode == UserMode.CastSpell && CurSpell.Info.TerritoryRange < float.MaxValue) &&
                !MapEditorActive)
            {
                float cutoff = _0;

                if (CurUserMode == UserMode.PlaceBuilding)
                {
                    cutoff = DrawTerritoryPlayer.TerritoryCutoff;
                }
                else if (CurUserMode == UserMode.CastSpell)
                {
                    cutoff = CurSpell.Info.TerritoryRange;
                }

                DrawTerritoryPlayer.Using(camvec, CameraAspect, DataGroup.DistanceToPlayers, MyPlayerValue, cutoff);
                GridHelper.DrawGrid();
            }
            else
            {
                if (CameraZoom <= z / 4)
                {
                    float territory_blend = CoreMath.LerpRestrict(z / 4, 0, z / 8, 1, CameraZoom);
                    DrawTerritoryColors.Using(camvec, CameraAspect, DataGroup.DistanceToPlayers, territory_blend);
                    GridHelper.DrawGrid();
                }

                if (CameraZoom >= z / 8)
                {
                    float corpse_blend = .35f * CoreMath.LerpRestrict(z / 2, 1, z / 16, 0, CameraZoom);

                    DrawCorpses.Using(camvec, CameraAspect, DataGroup.Corpses, UnitsSprite, corpse_blend);
                    GridHelper.DrawGrid();
                }
            }

            // Dragon Lord marker, before
            DrawDragonLordMarker(After: false);

            // Units
            if (CameraZoom > z / 8)
            {
                float second = (DrawCount % 60) / 60f;

                float selection_blend = CoreMath.LogLerpRestrict(60.0f, 1, 1.25f, 0, CameraZoom);
                float selection_size  = CoreMath.LogLerpRestrict(6.0f, .6f, z / 4, 0, CameraZoom);

                float solid_blend      = CoreMath.LogLerpRestrict(z / 7, 0, z / 2, 1, CameraZoom);
                bool  solid_blend_flag = solid_blend < 1;

                DrawUnits.Using(camvec, CameraAspect, DataGroup.CurrentData, DataGroup.PreviousData, DataGroup.CurrentUnits, DataGroup.PreviousUnits,
                                UnitsSprite, Assets.ShadowTexture,
                                MyPlayerValue,
                                PercentSimStepComplete, second,
                                selection_blend, selection_size,
                                solid_blend_flag, solid_blend);
            }
            else
            {
                DrawUnitsZoomedOutBlur.Using(camvec, CameraAspect, DataGroup.CurrentData, DataGroup.CurrentUnits, MyPlayerValue);
            }
            GridHelper.DrawGrid();

            // Buildings
            DrawBuildings.Using(camvec, CameraAspect, DataGroup.CurrentData, DataGroup.CurrentUnits, BuildingsSprite, ExsplosionSprite,
                                MyPlayerValue,
                                PercentSimStepComplete);
            GridHelper.DrawGrid();

            // Markers
            Markers.Update();
            Markers.Draw(DrawOrder.AfterTiles);

            // Antimagic
            if (CurUserMode == UserMode.CastSpell)
            {
                DrawAntiMagic.Using(camvec, CameraAspect, DataGroup.AntiMagic, MyTeamValue);
                GridHelper.DrawGrid();
            }

            // Markers
            Markers.Draw(DrawOrder.AfterUnits);

            // Building icons
            if (CameraZoom <= z / 4)
            {
                float blend  = CoreMath.LogLerpRestrict(z / 4, 0, z / 8, 1, CameraZoom);
                float radius = 5.5f / CameraZoom;

                DrawBuildingsIcons.Using(camvec, CameraAspect, DataGroup.DistanceToBuildings, DataGroup.CurrentData, DataGroup.CurrentUnits, blend, radius, MyPlayerValue);
                GridHelper.DrawGrid();
            }

            // Dragon Lord marker, after
            DrawDragonLordMarker(After: true);
        }
Exemple #30
0
        public static float Periodic(float A, float B, float period, float t, float PhaseDegree)
        {
            float Normalized = .5f - .5f * (float)Math.Cos(t * 2 * Math.PI / period + CoreMath.Radians(PhaseDegree));

            return(A + (B - A) * Normalized);
        }