Example #1
0
        void UpdateFoley()
        {
            var count = DataGroup.DoActionCount(this);

            float zoom = (float)Math.Pow(CameraZoom / 80f, 1.25f);

            ThreeLevelPlay(
                AmbientSounds.SwordFight_Level1, _6,
                AmbientSounds.SwordFight_Level2, _30,
                AmbientSounds.SwordFight_Level3,
                count.UnitsAttacking, count.UnitsAttacking * zoom);

            ThreeLevelPlay(
                AmbientSounds.Walking_Level1, _6,
                AmbientSounds.Walking_Level2, _30,
                AmbientSounds.Walking_Level3,
                count.UnitsMoving, count.UnitsMoving * zoom);

            if (count.BuildingsExploding > 0)
            {
                Sounds.BuildingExplode.MaybePlay(1.25f * zoom);
            }

            if (count.UnitsDying > 0 && count.UnitsDying < _3)
            {
                Sounds.DyingUnit.MaybePlay(1.25f * zoom);
            }
        }
Example #2
0
        void SetEffectArea(vec2 Pos, float Radius, int PlayerNumber)
        {
            Pos.y -= .5f;

            vec2 rounded_pos = floor(Pos + vec(.5f, .5f));

            DataGroup.SelectInArea(rounded_pos, Radius, Player.Vals[PlayerNumber]);
        }
Example #3
0
        public static void PlaceBuilding(DataGroup d, vec2 coord, float building_type, float player, float team)
        {
            MakeBuilding(coord, building_type, player, team, 0, 0, 3, 3, _unit, _data, _target);

            vec2 size = new vec2(3, 3);

            d.CurrentUnits.SetData(coord, size, _unit);
            d.CurrentData.SetData(coord, size, _data);
            d.TargetData.SetData(coord, size, _target);
        }
Example #4
0
        private void UpdateAllPlayerUnitCounts()
        {
            // Alternate between counting units for each player, to spread out the computational load
            int   i      = SimStep % 4 + 1;
            float player = Player.Get(i);
            var   count  = DataGroup.DoUnitCount(player, false);

            DataGroup.UnitCount[i]     = count.Item1;
            DataGroup.BarracksCount[i] = count.Item2;

            PlayerInfo[i].Units = count.Item1;
            PlayerInfo[i][UnitType.Barracks].Count = count.Item2;
        }
Example #5
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();
        }
Example #6
0
 private void UpdateDragonLordTracking()
 {
     if (TrackDragonLord)
     {
         for (int player = 1; player <= 4; player++)
         {
             PrevDragonLordPos[player] = CurDragonLordPos[player];
             CurDragonLordPos[player]  = DataGroup.DragonLordPos(_[player]);
             if (PrevDragonLordPos[player] == vec2.Zero)
             {
                 PrevDragonLordPos[player] = CurDragonLordPos[player];
             }
         }
     }
 }
Example #7
0
        public static void PlaceUnit(DataGroup d, vec2 coord, float unit_type, float player, float team, bool SetPrevious = false)
        {
            MakeUnit(unit_type, player, team, 0, 0, 1, 1, _unit, _data, _target);

            vec2 size = new vec2(1, 1);

            d.CurrentUnits.SetData(coord, size, _unit);
            d.CurrentData.SetData(coord, size, _data);
            d.TargetData.SetData(coord, size, _target);

            if (SetPrevious)
            {
                d.PreviousUnits.SetData(coord, size, _unit);
                d.PreviousData.SetData(coord, size, _data);
            }
        }
Example #8
0
        void AttackMove()
        {
            DataGroup.SelectedUnitsBounds();

            if (DataGroup.SelectedUnits == 0)
            {
                return;
            }

            vec2 Pos = ScreenToGridCoord(Input.CurMousePos);

            if (MouseOverMinimap)
            {
                Pos = MinimapGridPos();
            }

            vec2 Selected_BL   = DataGroup.SelectedBound_BL;
            vec2 Selected_Size = DataGroup.SelectedBound_TR - DataGroup.SelectedBound_BL;

            if (Selected_Size.x < 1)
            {
                Selected_Size.x = 1;
            }
            if (Selected_Size.y < 1)
            {
                Selected_Size.y = 1;
            }

            float SquareWidth = (float)Math.Sqrt(DataGroup.SelectedUnits);

            if (SquareWidth < 2)
            {
                SquareWidth = 0;
            }
            Pos = floor(Pos);

            vec2 Destination_Size = new vec2(SquareWidth, SquareWidth) * .8f;
            vec2 Destination_BL   = Pos - Destination_Size / 2;

            Destination_Size = floor(Destination_Size);
            Destination_BL   = floor(Destination_BL);
            Destination_BL   = max(Destination_BL, vec2.Zero);

            Networking.ToServer(new MessageAttackMove(Pos, Selected_BL, Selected_Size, Destination_BL, Destination_Size, CurSelectionFilter));

            AddAttackMarker();
        }
Example #9
0
        public World(bool Skeleton = false, GameParameters GameParams = null, bool RemoveComputerDragonLords = false)
        {
            Guid = new Random().Next();

            this.RemoveComputerDragonLords = RemoveComputerDragonLords;

            MyPlayerNumber = Program.StartupPlayerNumber;
            PlayerTeams    = Program.Teams;
            PlayerTeamVals = vec(Team.Vals[PlayerTeams[1]], Team.Vals[PlayerTeams[2]], Team.Vals[PlayerTeams[3]], Team.Vals[PlayerTeams[4]]);
            MyTeamNumber   = PlayerTeams[MyPlayerNumber];

            CameraAspect = GameClass.ScreenAspect;

            if (GameParams != null)
            {
                Params = GameParams;
            }
            else
            {
                Params = new GameParameters();
            }

            TeamInfo   = new TeamInfo[5];
            PlayerInfo = new PlayerInfo[5];
            for (int i = 1; i <= 4; i++)
            {
                TeamInfo[i]   = new TeamInfo();
                PlayerInfo[i] = new PlayerInfo(i, Params);
            }

            if (Skeleton)
            {
                return;
            }

            int GridN = 1024;

            DataGroup = new DataGroup(GridN, GridN);

            Markers      = new MarkerList();
            UserMessages = new UserMessageList();

            Minimap = new RenderTarget2D(GameClass.Game.GraphicsDevice, 256, 256);
        }
Example #10
0
 void DestroyAllPlayerBuildings(float player)
 {
     DestroyAllBuildings.Apply(DataGroup.CurrentUnits, DataGroup.CurrentData, player, Output: DataGroup.Temp1);
     DataGroup.Swap(ref DataGroup.CurrentData, ref DataGroup.Temp1);
 }
Example #11
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();
        }
Example #12
0
        public void Draw()
        {
            ProcessInbox();

            DrawCount++;
            Render.StandardRenderSetup();

            double PreviousSecondsSinceLastUpdate = SecondsSinceLastUpdate;

            if (!DesyncPause)
            {
                CheckIfShouldPause();
                CheckIfShouldShowWaiting();
            }

            if (GameClass.GameActive && !ServerPaused && !DesyncPause)
            {
                if (NotPaused_SimulationUpdate)
                {
                    double Elapsed = GameClass.DeltaT; //GameClass.ElapsedSeconds;

                    if (SimStep + SecondsSinceLastUpdate / DelayBetweenUpdates < ServerSimStep - .25f)
                    {
                        Elapsed *= 1.15f;
                        if (Log.SpeedMods)
                        {
                            Console.WriteLine("            -- Speed up please, Elasped = {3}  # {0}/{1} :{2}", Elapsed, SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates);
                        }
                    }

                    SecondsSinceLastUpdate += Elapsed;
                    T += (float)Elapsed;
                }
                else
                {
                    DataGroup.PausedSimulationUpdate();

                    if (MapEditorActive)
                    {
                        SecondsSinceLastUpdate += DelayBetweenUpdates;
                        T += (float)DelayBetweenUpdates;
                    }
                }

                if (GameClass.HasFocus)
                {
                    switch (CurUserMode)
                    {
                    case UserMode.PlaceBuilding:
                        if (UnselectAll)
                        {
                            SelectionUpdate(SelectSize);
                            UnselectAll = false;
                        }

                        Update_BuildingPlacing();
                        break;

                    case UserMode.Painting:
                        if (UnselectAll || MapEditorActive)
                        {
                            SelectionUpdate(SelectSize);
                            UnselectAll = false;
                        }

                        Update_Painting();
                        break;

                    case UserMode.Select:
                        SelectionUpdate(SelectSize, LineSelect: LineSelect);
                        break;

                    case UserMode.CastSpell:
                        if (LeftMousePressed && MyPlayerInfo != null)
                        {
                            if (!MyPlayerInfo.DragonLordAlive)
                            {
                                Message_NoDragonLordMagic();
                            }
                            else if (MyPlayerInfo.CanAffordSpell(CurSpell))
                            {
                                CastSpell(CurSpell);
                            }
                            else
                            {
                                Message_InsufficientJade();
                            }
                        }

                        break;
                    }
                }

                SkipNextSelectionUpdate = false;

                if (Program.Server)
                {
                    if (SecondsSinceLastUpdate / DelayBetweenUpdates > .75f && SimStep == ServerSimStep && !SentBookend)
                    {
                        if (Log.UpdateSim)
                        {
                            Console.WriteLine("Ready for bookend. {0}/{1} : {2}", SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates);
                        }

                        SentBookend = true;

                        AckSimStep = ServerSimStep + 2;
                        Networking.ToClients(new MessageBookend(ServerSimStep + 1));
                    }
                }

                // Check if post-upate calculation still need to be done
                if (!PostUpdateFinished)
                {
                    PostSimulationUpdate();
                }

                // Check if we need to do a simulation update
                //if (true)
                //Console.WriteLine(ServerSimStep);
                if (GameClass.UnlimitedSpeed || SecondsSinceLastUpdate > DelayBetweenUpdates || SimStep + 2 < ServerSimStep)
                {
                    if (SimStep < ServerSimStep && !(Program.Server && MinClientSimStep + 2 < ServerSimStep))
                    {
                        WaitingTime = 0;

                        if (!PostUpdateFinished)
                        {
                            PostSimulationUpdate(); // If we are behind do another post-sim update to help catchup.
                        }
                        else
                        {
                            SecondsSinceLastUpdate -= DelayBetweenUpdates;
                            if (SecondsSinceLastUpdate < 0)
                            {
                                SecondsSinceLastUpdate = 0;
                            }

                            HashCheck();

                            DeququeActions(SimStep + 1);

                            HashCheck();

                            SimulationUpdate();

                            if (!Program.Spectate || Program.Spectate && SimStep % 15 == 0)
                            {
                                HashCheck(Send: true);
                            }

                            SentBookend = false;
                            Networking.ToServer(new MessageStartingStep(SimStep));

                            if (Log.UpdateSim)
                            {
                                Console.WriteLine("Just updated sim # {0}/{1} : {2}      min={3}", SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates, MinClientSimStep);
                            }
                        }
                    }
                    else
                    {
                        WaitingTime += GameClass.ElapsedSeconds;

                        if (Log.Delays)
                        {
                            Console.WriteLine("-Reverting from # {0}/{1} : {2}", SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates);
                        }
                        SecondsSinceLastUpdate = DelayBetweenUpdates;
                        T -= (float)GameClass.ElapsedSeconds;
                        if (Log.Delays)
                        {
                            Console.WriteLine("-Reverting to # {0}/{1} : {2}", SimStep, ServerSimStep, SecondsSinceLastUpdate / DelayBetweenUpdates);
                        }
                    }
                }
                else
                {
                    if (Program.Server)
                    {
                        if (Log.Draws)
                        {
                            Console.WriteLine("Draw step {0},  {1}", DrawCount, SecondsSinceLastUpdate / DelayBetweenUpdates);
                        }
                    }
                }
            }

            BenchmarkTests.Run(DataGroup.CurrentData, DataGroup.PreviousData);

            if (!Program.Headless)
            {
                try
                {
                    DrawWorld();
                }
                catch (Exception e)
                {
                }
            }
            else
            {
                GridHelper.GraphicsDevice.SetRenderTarget(null);
            }
        }
Example #13
0
        void PostSimulationUpdate()
        {
            //Render.UnsetDevice();

            switch (PostUpdateStep)
            {
            case 0:
                DataGroup.UpdateSelect();

                if (MapEditorActive)
                {
                    DataGroup.EditorSimulationUpdate();
                }
                else
                {
                    DataGroup.SimulationUpdate();
                }

                UpdateDragonLordTracking();

                break;

            case 1:
                DataGroup.UpdateIcons();
                DataGroup.DoDragonLordCount(PlayerInfo);     // This should happen soon after CurrentUnit.anim is updated, so it can catch the death switch with low latency.
                DragonLordDeathCheck();
                EndOfGameCheck();
                AddDragonLordDeathEffects();

                break;

            case 2:
                if (SimStep % 2 == 0)
                {
                    DataGroup.DoGoldMineCount(PlayerInfo);
                }
                else
                {
                    DataGroup.DoJadeMineCount(PlayerInfo);
                }

                DoGoldUpdate();
                DoJadeUpdate();

                break;

            case 3:
                UpdateAllPlayerUnitCounts();
                UpdateFoley();
                break;

            case 4:
                DataGroup.UpdateGradients();
                break;

            case 5:
                DataGroup.UpdateMagicFields();
                DataGroup.UpdateMagicAuras();
                break;

            case 6:
                DataGroup.UpdateRnd();
                DataGroup.UpdateMagicAuras();     // 2nd auro update

                break;

            case 7:
                if (SimStep % 2 == 0)
                {
                    UpdateDragonLordEngaged();
                }
                else
                {
                    UpdateMinimap();
                }

                break;

            default:
                //HashCheck();
                PostUpdateFinished = true;
                break;
            }

            PostUpdateStep++;
        }