Esempio n. 1
0
        internal override float GetTacticWeight()
        {
            float           num1            = this.team.QuerySystem.OverallPowerRatio / this.team.QuerySystem.PowerRatioIncludingCasualties;
            float           num2            = Math.Max(this.team.QuerySystem.InfantryRatio, Math.Max(this.team.QuerySystem.RangedRatio, this.team.QuerySystem.CavalryRatio)) + (this.team.Side == BattleSideEnum.Defender ? 0.33f : 0.0f);
            float           num3            = this.team.Side == BattleSideEnum.Defender ? 0.33f : 0.5f;
            double          num4            = (double)this.team.Formations.Sum <Formation>((Func <Formation, float>)(f => f.QuerySystem.FormationPower)) + (double)this.team.QuerySystem.EnemyTeams.SelectMany <TeamQuerySystem, Formation>((Func <TeamQuerySystem, IEnumerable <Formation> >)(t => t.Team.Formations)).Sum <Formation>((Func <Formation, float>)(f => f.QuerySystem.FormationPower));
            CasualtyHandler casualtyHandler = Mission.Current.GetMissionBehaviour <CasualtyHandler>();
            float           num5            = (float)num4 / ((float)num4 + (this.team.Formations.Sum <Formation>((Func <Formation, float>)(f => casualtyHandler.GetCasualtyPowerLossOfFormation(f))) + this.team.QuerySystem.EnemyTeams.SelectMany <TeamQuerySystem, Formation>((Func <TeamQuerySystem, IEnumerable <Formation> >)(t => t.Team.Formations)).Sum <Formation>((Func <Formation, float>)(f => casualtyHandler.GetCasualtyPowerLossOfFormation(f)))));

            return(Math.Max(this.team.Side != BattleSideEnum.Attacker || (double)num1 >= 0.5 ? MBMath.LinearExtrapolation(0.0f, 1.6f * num2, (float)((1.0 - (double)num5) / (1.0 - (double)num3))) : 0.0f, MBMath.LinearExtrapolation(0.0f, 1.6f * num2, (float)((double)this.team.QuerySystem.OverallPowerRatio * (double)num3 * 0.5))));
        }
Esempio n. 2
0
        public TeamQuerySystem(Team team)
        {
            TeamQuerySystem teamQuerySystem = this;

            this.Team                  = team;
            this._mission              = Mission.Current;
            this._memberCount          = new QueryData <int>((Func <int>)(() => teamQuerySystem.Team.FormationsIncludingSpecial.Sum <Formation>((Func <Formation, int>)(f => f.CountOfUnits))), 2f);
            this._allyMemberCount      = new QueryData <int>((Func <int>)(() => teamQuerySystem.AllyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(t => t.MemberCount))), 2f);
            this._enemyMemberCount     = new QueryData <int>((Func <int>)(() => teamQuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(t => t.MemberCount))), 2f);
            this._averagePosition      = new QueryData <Vec2>((Func <Vec2>)(() => teamQuerySystem._mission.GetAveragePositionOfTeam(team)), 5f);
            this._medianPosition       = new QueryData <WorldPosition>((Func <WorldPosition>)(() => teamQuerySystem._mission.GetMedianPositionOfTeam(team, teamQuerySystem.AveragePosition)), 5f);
            this._averageEnemyPosition = new QueryData <Vec2>((Func <Vec2>)(() =>
            {
                Vec2 positionOfEnemies = teamQuerySystem._mission.GetAveragePositionOfEnemies(team);
                if (positionOfEnemies.IsValid)
                {
                    return(positionOfEnemies);
                }
                if (team.Side == BattleSideEnum.Attacker)
                {
                    SiegeDeploymentHandler missionBehaviour = teamQuerySystem._mission.GetMissionBehaviour <SiegeDeploymentHandler>();
                    if (missionBehaviour != null)
                    {
                        return(missionBehaviour.GetEstimatedAverageDefenderPosition());
                    }
                }
                return(teamQuerySystem.AveragePosition.IsValid ? teamQuerySystem.AveragePosition : teamQuerySystem._mission.GetAveragePositionOfTeam(team));
            }), 5f);
            this._medianTargetFormationPosition = new QueryData <WorldPosition>((Func <WorldPosition>)(() => !teamQuerySystem._mission.Teams.Where <Team>((Func <Team, bool>)(t => t.IsEnemyOf(teamQuerySystem.Team))).SelectMany <Team, Formation>((Func <Team, IEnumerable <Formation> >)(t => t.FormationsIncludingSpecial)).Any <Formation>() ? teamQuerySystem.MedianPosition : teamQuerySystem._mission.Teams.Where <Team>((Func <Team, bool>)(t => t.IsEnemyOf(teamQuerySystem.Team))).SelectMany <Team, Formation>((Func <Team, IEnumerable <Formation> >)(t => t.FormationsIncludingSpecial)).MinBy <Formation, float>((Func <Formation, float>)(f => f.QuerySystem.MedianPosition.AsVec2.DistanceSquared(teamQuerySystem.AverageEnemyPosition))).QuerySystem.MedianPosition), 1f);
            QueryData <WorldPosition> .SetupSyncGroup((IQueryData)this._averageEnemyPosition, (IQueryData)this._medianTargetFormationPosition);

            this._leftFlankEdgePosition = new QueryData <WorldPosition>((Func <WorldPosition>)(() =>
            {
                Vec2 vec2  = (teamQuerySystem.MedianTargetFormationPosition.AsVec2 - teamQuerySystem.AveragePosition).RightVec();
                double num = (double)vec2.Normalize();
                WorldPosition formationPosition = teamQuerySystem.MedianTargetFormationPosition;
                formationPosition.SetVec2(formationPosition.AsVec2 - vec2 * 50f);
                return(formationPosition);
            }), 5f);
            this._rightFlankEdgePosition = new QueryData <WorldPosition>((Func <WorldPosition>)(() =>
            {
                Vec2 vec2  = (teamQuerySystem.MedianTargetFormationPosition.AsVec2 - teamQuerySystem.AveragePosition).RightVec();
                double num = (double)vec2.Normalize();
                WorldPosition formationPosition = teamQuerySystem.MedianTargetFormationPosition;
                formationPosition.SetVec2(formationPosition.AsVec2 + vec2 * 50f);
                return(formationPosition);
            }), 5f);
            this._infantryRatio      = new QueryData <float>((Func <float>)(() => teamQuerySystem.MemberCount != 0 ? (teamQuerySystem.Team.FormationsIncludingSpecial.Sum <Formation>((Func <Formation, float>)(f => f.QuerySystem.InfantryUnitRatio * (float)f.CountOfUnits)) + (float)team.Heroes.Count <Agent>((Func <Agent, bool>)(h => QueryLibrary.IsInfantry(h)))) / (float)teamQuerySystem.MemberCount : 0.0f), 15f);
            this._rangedRatio        = new QueryData <float>((Func <float>)(() => teamQuerySystem.MemberCount != 0 ? (teamQuerySystem.Team.FormationsIncludingSpecial.Sum <Formation>((Func <Formation, float>)(f => f.QuerySystem.RangedUnitRatio * (float)f.CountOfUnits)) + (float)team.Heroes.Count <Agent>((Func <Agent, bool>)(h => QueryLibrary.IsRanged(h)))) / (float)teamQuerySystem.MemberCount : 0.0f), 15f);
            this._cavalryRatio       = new QueryData <float>((Func <float>)(() => teamQuerySystem.MemberCount != 0 ? (teamQuerySystem.Team.FormationsIncludingSpecial.Sum <Formation>((Func <Formation, float>)(f => f.QuerySystem.CavalryUnitRatio * (float)f.CountOfUnits)) + (float)team.Heroes.Count <Agent>((Func <Agent, bool>)(h => QueryLibrary.IsCavalry(h)))) / (float)teamQuerySystem.MemberCount : 0.0f), 15f);
            this._rangedCavalryRatio = new QueryData <float>((Func <float>)(() => teamQuerySystem.MemberCount != 0 ? (teamQuerySystem.Team.FormationsIncludingSpecial.Sum <Formation>((Func <Formation, float>)(f => f.QuerySystem.RangedCavalryUnitRatio * (float)f.CountOfUnits)) + (float)team.Heroes.Count <Agent>((Func <Agent, bool>)(h => QueryLibrary.IsRangedCavalry(h)))) / (float)teamQuerySystem.MemberCount : 0.0f), 15f);
            QueryData <float> .SetupSyncGroup((IQueryData)this._infantryRatio, (IQueryData)this._rangedRatio, (IQueryData)this._cavalryRatio, (IQueryData)this._rangedCavalryRatio);

            this._allyInfantryRatio = new QueryData <float>((Func <float>)(() =>
            {
                int num = teamQuerySystem.AllyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(a => a.MemberCount));
                return(num == 0 ? 0.0f : teamQuerySystem.AllyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, float>)(a => a.InfantryRatio * (float)a.MemberCount)) / (float)num);
            }), 15f);
            this._allyRangedRatio = new QueryData <float>((Func <float>)(() =>
            {
                int num = teamQuerySystem.AllyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(a => a.MemberCount));
                return(num == 0 ? 0.0f : teamQuerySystem.AllyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, float>)(a => a.RangedRatio * (float)a.MemberCount)) / (float)num);
            }), 15f);
            this._allyCavalryRatio = new QueryData <float>((Func <float>)(() =>
            {
                int num = teamQuerySystem.AllyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(a => a.MemberCount));
                return(num == 0 ? 0.0f : teamQuerySystem.AllyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, float>)(a => a.CavalryRatio * (float)a.MemberCount)) / (float)num);
            }), 15f);
            this._allyRangedCavalryRatio = new QueryData <float>((Func <float>)(() =>
            {
                int num = teamQuerySystem.AllyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(a => a.MemberCount));
                return(num == 0 ? 0.0f : teamQuerySystem.AllyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, float>)(a => a.RangedCavalryRatio * (float)a.MemberCount)) / (float)num);
            }), 15f);
            QueryData <float> .SetupSyncGroup((IQueryData)this._allyInfantryRatio, (IQueryData)this._allyRangedRatio, (IQueryData)this._allyCavalryRatio, (IQueryData)this._allyRangedCavalryRatio);

            this._enemyInfantryRatio      = new QueryData <float>((Func <float>)(() => teamQuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(e => e.MemberCount)) != 0 ? teamQuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, float>)(e => e.InfantryRatio * (float)e.MemberCount)) / (float)teamQuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(e => e.MemberCount)) : 0.0f), 15f);
            this._enemyRangedRatio        = new QueryData <float>((Func <float>)(() => teamQuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(e => e.MemberCount)) != 0 ? teamQuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, float>)(e => e.RangedRatio * (float)e.MemberCount)) / (float)teamQuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(e => e.MemberCount)) : 0.0f), 15f);
            this._enemyCavalryRatio       = new QueryData <float>((Func <float>)(() => teamQuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(e => e.MemberCount)) != 0 ? teamQuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, float>)(e => e.CavalryRatio * (float)e.MemberCount)) / (float)teamQuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(e => e.MemberCount)) : 0.0f), 15f);
            this._enemyRangedCavalryRatio = new QueryData <float>((Func <float>)(() => teamQuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(e => e.MemberCount)) != 0 ? teamQuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, float>)(e => e.RangedCavalryRatio * (float)e.MemberCount)) / (float)teamQuerySystem.EnemyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, int>)(e => e.MemberCount)) : 0.0f), 15f);
            this._teamPower                     = new QueryData <float>((Func <float>)(() => team.FormationsIncludingSpecial.Sum <Formation>((Func <Formation, float>)(f => f.GetFormationPower()))), 5f);
            this._overallPowerRatio             = new QueryData <float>((Func <float>)(() => (float)((double)teamQuerySystem.AllyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, float>)(at => at.Team.FormationsIncludingSpecial.Sum <Formation>((Func <Formation, float>)(f => f.QuerySystem.FormationPower)) + 1f)) * 1.0 / ((double)teamQuerySystem._mission.Teams.GetEnemiesOf(team).Sum <Team>((Func <Team, float>)(et => et.FormationsIncludingSpecial.Sum <Formation>((Func <Formation, float>)(f => f.QuerySystem.FormationPower)))) + 1.0))), 5f);
            this._powerRatioIncludingCasualties = new QueryData <float>((Func <float>)(() =>
            {
                CasualtyHandler casualtyHandler = teamQuerySystem._mission.GetMissionBehaviour <CasualtyHandler>();
                return((float)(((double)teamQuerySystem.AllyTeams.Sum <TeamQuerySystem>((Func <TeamQuerySystem, float>)(at => at.Team.FormationsIncludingSpecialAndEmpty.Sum <Formation>((Func <Formation, float>)(f => f.GetFormationPower() + casualtyHandler.GetCasualtyPowerLossOfFormation(f))))) + 1.0) / ((double)teamQuerySystem._mission.Teams.GetEnemiesOf(team).Sum <Team>((Func <Team, float>)(et => et.FormationsIncludingSpecialAndEmpty.Sum <Formation>((Func <Formation, float>)(f => f.GetFormationPower() + casualtyHandler.GetCasualtyPowerLossOfFormation(f))))) + 1.0)));
            }), 10f);
            this._insideWallsRatio = new QueryData <float>((Func <float>)(() =>
            {
                if (!(team.TeamAI is TeamAISiegeComponent))
                {
                    return(1f);
                }
                if (teamQuerySystem.AllyUnitCount == 0)
                {
                    return(0.0f);
                }
                int num = 0;
                foreach (Team team1 in Mission.Current.Teams.GetAlliesOf(team, true))
                {
                    foreach (Formation formation in team1.FormationsIncludingSpecial)
                    {
                        num += formation.CountUnitsOnNavMeshIDMod10(1, false);
                    }
                }
                return((float)num / (float)teamQuerySystem.AllyUnitCount);
            }), 10f);
            this._maxUnderRangedAttackRatio = new QueryData <float>((Func <float>)(() =>
            {
                float num1;
                if (teamQuerySystem.AllyUnitCount == 0)
                {
                    num1 = 0.0f;
                }
                else
                {
                    float currentTime = MBCommon.TimeType.Mission.GetTime();
                    int num2          = 0;
                    foreach (TeamQuerySystem allyTeam in teamQuerySystem.AllyTeams)
                    {
                        foreach (Formation formation in allyTeam.Team.Formations)
                        {
                            num2 += formation.GetCountOfUnitsWithCondition((Func <Agent, bool>)(agent => (double)currentTime - (double)agent.LastRangedHitTime < 10.0 && !agent.Equipment.HasShield()));
                        }
                    }
                    num1 = (float)num2 / (float)teamQuerySystem.AllyUnitCount;
                }
                return((double)num1 > (double)teamQuerySystem._maxUnderRangedAttackRatio.GetCachedValue() ? num1 : teamQuerySystem._maxUnderRangedAttackRatio.GetCachedValue());
            }), 3f);
            this.DeathCount         = 0;
            this.DeathByRangedCount = 0;
            this.InitializeTelemetryScopeNames();
        }