Esempio n. 1
0
 public static bool ApplyWaterChecks(
     this Transform transform,
     WaterCheck[] anchors,
     Vector3 pos,
     Quaternion rot,
     Vector3 scale)
 {
     if (anchors.Length == 0)
     {
         return(true);
     }
     for (int index = 0; index < anchors.Length; ++index)
     {
         WaterCheck anchor  = anchors[index];
         Vector3    vector3 = Vector3.Scale(anchor.worldPosition, scale);
         if (anchor.Rotate)
         {
             vector3 = Quaternion.op_Multiply(rot, vector3);
         }
         if (!anchor.Check(Vector3.op_Addition(pos, vector3)))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 2
0
 public BaseBuilderQueueManager(BaseBuilderBotModule baseBuilder, string category, Player p, PowerManager pm,
                                PlayerResources pr, IResourceLayer rl)
 {
     this.baseBuilder   = baseBuilder;
     world              = p.World;
     player             = p;
     playerPower        = pm;
     playerResources    = pr;
     resourceLayer      = rl;
     this.category      = category;
     failRetryTicks     = baseBuilder.Info.StructureProductionResumeDelay;
     minimumExcessPower = baseBuilder.Info.MinimumExcessPower;
     if (!baseBuilder.Info.NavalProductionTypes.Any())
     {
         waterState = WaterCheck.DontCheck;
     }
 }
Esempio n. 3
0
        public CustomBaseBuilderQueueManager(CustomBaseBuilderBotModule baseBuilder, string category, Player player,
                                             PowerManager powerManager, PlayerResources playerResources, IResourceLayer resourceLayer)
        {
            this.baseBuilder     = baseBuilder;
            world                = player.World;
            this.player          = player;
            this.powerManager    = powerManager;
            this.playerResources = playerResources;
            this.resourceLayer   = resourceLayer;
            this.category        = category;
            failRetryTicks       = baseBuilder.Info.StructureProductionResumeDelay;
            minimumExcessPower   = baseBuilder.Info.MinimumExcessPower;
            if (!baseBuilder.Info.NavalProductionTypes.Any())
            {
                waterState = WaterCheck.DontCheck;
            }

            buildingInfluence = world.WorldActor.Trait <BuildingInfluence>();
        }
 public static bool ApplyWaterChecks(this Transform transform, WaterCheck[] anchors, Vector3 pos, Quaternion rot, Vector3 scale)
 {
     if (anchors.Length == 0)
     {
         return(true);
     }
     for (int i = 0; i < (int)anchors.Length; i++)
     {
         WaterCheck waterCheck = anchors[i];
         Vector3    vector3    = Vector3.Scale(waterCheck.worldPosition, scale);
         if (waterCheck.Rotate)
         {
             vector3 = rot * vector3;
         }
         if (!waterCheck.Check(pos + vector3))
         {
             return(false);
         }
     }
     return(true);
 }
Esempio n. 5
0
        public void Tick(IBot bot)
        {
            // If failed to place something N consecutive times, wait M ticks until resuming building production
            if (failCount >= baseBuilder.Info.MaximumFailedPlacementAttempts && --failRetryTicks <= 0)
            {
                var currentBuildings = world.ActorsHavingTrait <Building>().Count(a => a.Owner == player);
                var baseProviders    = world.ActorsHavingTrait <BaseProvider>().Count(a => a.Owner == player);

                // Only bother resetting failCount if either a) the number of buildings has decreased since last failure M ticks ago,
                // or b) number of BaseProviders (construction yard or similar) has increased since then.
                // Otherwise reset failRetryTicks instead to wait again.
                if (currentBuildings < cachedBuildings || baseProviders > cachedBases)
                {
                    failCount = 0;
                }
                else
                {
                    failRetryTicks = baseBuilder.Info.StructureProductionResumeDelay;
                }
            }

            if (waterState == WaterCheck.NotChecked)
            {
                if (AIUtils.IsAreaAvailable <BaseProvider>(world, player, world.Map, baseBuilder.Info.MaxBaseRadius, baseBuilder.Info.WaterTerrainTypes))
                {
                    waterState = WaterCheck.EnoughWater;
                }
                else
                {
                    waterState         = WaterCheck.NotEnoughWater;
                    checkForBasesTicks = baseBuilder.Info.CheckForNewBasesDelay;
                }
            }

            if (waterState == WaterCheck.NotEnoughWater && --checkForBasesTicks <= 0)
            {
                var currentBases = world.ActorsHavingTrait <BaseProvider>().Count(a => a.Owner == player);

                if (currentBases > cachedBases)
                {
                    cachedBases = currentBases;
                    waterState  = WaterCheck.NotChecked;
                }
            }

            // Only update once per second or so
            if (--waitTicks > 0)
            {
                return;
            }

            playerBuildings = world.ActorsHavingTrait <Building>().Where(a => a.Owner == player).ToArray();
            var excessPowerBonus = baseBuilder.Info.ExcessPowerIncrement * (playerBuildings.Count() / baseBuilder.Info.ExcessPowerIncreaseThreshold.Clamp(1, int.MaxValue));

            minimumExcessPower = (baseBuilder.Info.MinimumExcessPower + excessPowerBonus).Clamp(baseBuilder.Info.MinimumExcessPower, baseBuilder.Info.MaximumExcessPower);

            var active = false;

            foreach (var queue in AIUtils.FindQueues(player, category))
            {
                if (TickQueue(bot, queue))
                {
                    active = true;
                }
            }

            // Add a random factor so not every AI produces at the same tick early in the game.
            // Minimum should not be negative as delays in HackyAI could be zero.
            var randomFactor = world.LocalRandom.Next(0, baseBuilder.Info.StructureProductionRandomBonusDelay);

            // Needs to be at least 4 * OrderLatency because otherwise the AI frequently duplicates build orders (i.e. makes the same build decision twice)
            waitTicks = active ? 4 * world.OrderLatency + baseBuilder.Info.StructureProductionActiveDelay + randomFactor
                                : baseBuilder.Info.StructureProductionInactiveDelay + randomFactor;
        }