public void Tick() { // Only update once per second or so if (--waitTicks > 0) { return; } playerBuildings = world.ActorsWithTrait <Building>() .Where(a => a.Actor.Owner == player) .Select(a => a.Actor) .ToArray(); var active = false; foreach (var queue in ai.FindQueues(category)) { if (TickQueue(queue)) { active = true; } } waitTicks = active ? ai.Info.StructureProductionActiveDelay : ai.Info.StructureProductionInactiveDelay; }
public void Tick() { // If failed to place something N consecutive times, wait M ticks until resuming building production if (failCount >= ai.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 = ai.Info.StructureProductionResumeDelay; } } if (waterState == Water.NotChecked) { if (ai.EnoughWaterToBuildNaval()) { waterState = Water.EnoughWater; } else { waterState = Water.NotEnoughWater; checkForBasesTicks = ai.Info.CheckForNewBasesDelay; } } if (waterState == Water.NotEnoughWater && --checkForBasesTicks <= 0) { var currentBases = world.ActorsHavingTrait <BaseProvider>().Count(a => a.Owner == player); if (currentBases > cachedBases) { cachedBases = currentBases; waterState = Water.NotChecked; } } // Only update once per second or so if (--waitTicks > 0) { return; } playerBuildings = world.ActorsHavingTrait <Building>().Where(a => a.Owner == player).ToArray(); var active = false; foreach (var queue in ai.FindQueues(category)) { if (TickQueue(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 = ai.Random.Next(0, ai.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.LobbyInfo.GlobalSettings.OrderLatency + ai.Info.StructureProductionActiveDelay + randomFactor : ai.Info.StructureProductionInactiveDelay + randomFactor; }