コード例 #1
0
 public static void StopFactoryProduction(FacilityEx facility)
 {
     facility.LastAssignedVehicleType = null;
     facility.ProductionCount         = 0;
     facility.FacilityGroupCreating   = false;
     ActionHelper.StopFactoryProduction(facility.Id);
 }
コード例 #2
0
        public static void StartFactoryProduction(FacilityEx facility, List <List <DbScanHelper.Point> > clusters)
        {
            var productionParams = GetStartProductionParams(clusters);

            facility.LastAssignedVehicleType = productionParams.VehicleType;
            facility.ProductionCount         = productionParams.Count;
            facility.FacilityGroupCreating   = false;
            ActionHelper.StartFactoryProduction(facility.Id, productionParams.VehicleType);
        }
コード例 #3
0
        public static MyLivingUnit[] GetCreatedUnassignedUnits(this FacilityEx facilityEx)
        {
            if (facilityEx.Type == FacilityType.ControlCenter)
            {
                return(new MyLivingUnit[0]);
            }

            var facilityWidth  = GlobalHelper.Game.FacilityWidth;
            var facilityHeight = GlobalHelper.Game.FacilityHeight;

            var createdUnassignedUnits = UnitHelper.UnitsAlly
                                         .Where(x => x.Groups.Length == 0)
                                         .Where(x =>
                                                x.X >= facilityEx.Left &&
                                                x.X <= facilityEx.Left + facilityWidth &&
                                                x.Y >= facilityEx.Top &&
                                                x.Y <= facilityEx.Top + facilityHeight
                                                ).ToArray();

            return(createdUnassignedUnits);
        }
コード例 #4
0
        /// <summary>
        /// Пока примитивная логика, не стартуем если враги есть рядом
        /// </summary>
        /// <param name="facility"></param>
        /// <param name="createdUnassignedUnits"></param>
        /// <returns></returns>
        private static bool CanStartProduction(FacilityEx facility, MyLivingUnit[] createdUnassignedUnits)
        {
            var isProductionTickExceed = GlobalHelper.Game.TickCount - GlobalHelper.World.TickIndex <
                                         ConfigurationHelper.StopProductionWhenTicksToEndGameRemaining;

            //var testStopProduction = (GlobalHelper.World.TickIndex / 1000) % 2 == 1;

            //Остановим производство, если слишком много юнитов
            //Для варианта с туманом, если их больше n
            //Для варианта без тумана, если количество превышает кол-во врага в n раз
            var isUnitsTooMuch = (GlobalHelper.Mode == GameMode.FacFow
                                     ? UnitHelper.UnitsAlly.Length > 750
                                     : UnitHelper.UnitsAlly.Length - UnitHelper.UnitsEnemy.Length > 300) &&
                                 GlobalHelper.World.TickIndex > 10000;

            var clusters = MyStrategy.LazyClusters.Value;

            var facilityX = facility.Left + GlobalHelper.Game.FacilityWidth / 2;
            var facilityY = facility.Top + GlobalHelper.Game.FacilityHeight / 2;

            var isEnemyNear = clusters.Any(cluster =>
            {
                var clusterUnitsX = cluster.Sum(x => x.X) / cluster.Count;
                var clusterUnitsY = cluster.Sum(x => x.Y) / cluster.Count;

                var isInRange =
                    GeometryHelper.GetDistancePower2To(facilityX, facilityY, clusterUnitsX, clusterUnitsY)
                    <= ConfigurationHelper.EnemyNearOurFacilityWarningLostRangePow2;

                return(isInRange);
            });

            var result = !isProductionTickExceed && !isUnitsTooMuch && !isEnemyNear;

            return(result);
        }
コード例 #5
0
 public StopProduction(FacilityEx facility)
 {
     Facility = facility;
 }
コード例 #6
0
        private static bool NeedStopProduction(FacilityEx facility, MyLivingUnit[] createdUnassignedUnits)
        {
            var isProductionTickExceed = GlobalHelper.Game.TickCount - GlobalHelper.World.TickIndex <
                                         ConfigurationHelper.StopProductionWhenTicksToEndGameRemaining;

            //var testStopProduction = (GlobalHelper.World.TickIndex / 1000) % 2 == 1;

            //Остановим производство, если слишком много юнитов
            //Для варианта с туманом, если их больше n
            //Для варианта без тумана, если количество превышает кол-во врага в n раз
            var isUnitsTooMuch = (GlobalHelper.Mode == GameMode.FacFow
                                     ? UnitHelper.UnitsAlly.Length > 750
                                     : UnitHelper.UnitsAlly.Length - UnitHelper.UnitsEnemy.Length > 300) &&
                                 GlobalHelper.World.TickIndex > 10000;

            var clusters = MyStrategy.LazyClusters.Value;
            //var res = BattleHelper.CalculatePower(enemies, currentSelectedGroup.VehicleType, basePower);
            var isEnemyCanBeatProducingGroupTooClose = false;

            if (facility.Side == Side.Our && clusters.Count > 0 && createdUnassignedUnits.Length > 0)
            {
                var vehicleType = createdUnassignedUnits[0].Type;

                var basePower = PotentialFieldsHelper.EnemyPowerToDodge;

                var facilityUnitsX = createdUnassignedUnits.Sum(x => x.X) / createdUnassignedUnits.Length;
                var facilityUnitsY = createdUnassignedUnits.Sum(x => x.Y) / createdUnassignedUnits.Length;

                isEnemyCanBeatProducingGroupTooClose = clusters.Any(cluster =>
                {
                    var clusterUnitsX = cluster.Sum(x => x.X) / cluster.Count;
                    var clusterUnitsY = cluster.Sum(x => x.Y) / cluster.Count;

                    var isInRange =
                        GeometryHelper.GetDistancePower2To(facilityUnitsX, facilityUnitsY, clusterUnitsX, clusterUnitsY)
                        <= ConfigurationHelper.EnemyNearOurFacilityWarningRangePow2;

                    if (!isInRange)
                    {
                        return(false);
                    }

                    var res = BattleHelper.CalculatePower(cluster, vehicleType, PotentialFieldsHelper.EnemyPowerToDodge);

                    var enemyPower       = res.EnemyPower;
                    var canAttackSomeone = res.CanAttackSomeone;

                    var existGroupPower =
                        createdUnassignedUnits.Sum(y => BattleHelper.GetPowerHealthMulitplier(y.Type, y.Durability)) *
                        basePower;

                    bool needStayOnFacility;

                    //Если строящаяся группа сильнее или чуть чуть слабее, то не уходим
                    if (existGroupPower * 1.2 > enemyPower)
                    {
                        needStayOnFacility = true;
                        //needStayOnFacility = canAttackSomeone;
                    }
                    else
                    {
                        //Если у врага нулевая сила, никуда не уходим
                        needStayOnFacility = (Math.Abs(enemyPower) < PotentialFieldsHelper.Epsilon);
                    }

                    return(!needStayOnFacility);
                });
            }

            var result = isProductionTickExceed || isUnitsTooMuch || isEnemyCanBeatProducingGroupTooClose /*|| testStopProduction*/;

            if (result)
            {
                var a = 0;
            }

            return(result);
        }