Beispiel #1
0
        /// <summary>Scans the map in chunks, evaluating all actors in each.</summary>
        CPos?FindCoarseAttackLocationToSupportPower(SupportPowerInstance readyPower)
        {
            CPos?bestLocation       = null;
            var  bestAttractiveness = 0;
            var  powerDecision      = powerDecisions[readyPower.Info.OrderName];

            if (powerDecision == null)
            {
                HackyAI.BotDebug("Bot Bug: FindAttackLocationToSupportPower, couldn't find powerDecision for {0}", readyPower.Info.OrderName);
                return(null);
            }

            var map         = world.Map;
            var checkRadius = powerDecision.CoarseScanRadius;

            for (var i = 0; i < map.MapSize.X; i += checkRadius)
            {
                for (var j = 0; j < map.MapSize.Y; j += checkRadius)
                {
                    var tl     = new MPos(i, j);
                    var br     = new MPos(i + checkRadius, j + checkRadius);
                    var region = new CellRegion(map.Grid.Type, tl, br);

                    // HACK: The AI code should not be messing with raw coordinate transformations
                    var wtl     = world.Map.CenterOfCell(tl.ToCPos(map));
                    var wbr     = world.Map.CenterOfCell(br.ToCPos(map));
                    var targets = world.ActorMap.ActorsInBox(wtl, wbr);

                    var frozenTargets            = frozenLayer.FrozenActorsInRegion(region);
                    var consideredAttractiveness = powerDecision.GetAttractiveness(targets, player) + powerDecision.GetAttractiveness(frozenTargets, player);
                    if (consideredAttractiveness <= bestAttractiveness || consideredAttractiveness < powerDecision.MinimumAttractiveness)
                    {
                        continue;
                    }

                    bestAttractiveness = consideredAttractiveness;
                    bestLocation       = new MPos(i, j).ToCPos(map);
                }
            }

            return(bestLocation);
        }
Beispiel #2
0
        /// <summary>Evaluates the attractiveness of a position according to all considerations</summary>
        public int GetAttractiveness(WPos pos, Player firedBy, FrozenActorLayer frozenLayer)
        {
            var answer     = 0;
            var world      = firedBy.World;
            var targetTile = world.Map.CellContaining(pos);

            if (!world.Map.Contains(targetTile))
            {
                return(0);
            }

            foreach (var consideration in Considerations)
            {
                var radiusToUse = new WDist(consideration.CheckRadius.Length);

                var checkActors = world.FindActorsInCircle(pos, radiusToUse);
                foreach (var scrutinized in checkActors)
                {
                    answer += consideration.GetAttractiveness(scrutinized, firedBy.Stances[scrutinized.Owner], firedBy);
                }

                var delta       = new WVec(radiusToUse, radiusToUse, WDist.Zero);
                var tl          = world.Map.CellContaining(pos - delta);
                var br          = world.Map.CellContaining(pos + delta);
                var checkFrozen = frozenLayer.FrozenActorsInRegion(new CellRegion(world.Map.Grid.Type, tl, br));

                // IsValid check filters out Frozen Actors that have not initizialized their Owner
                foreach (var scrutinized in checkFrozen)
                {
                    if (scrutinized.IsValid)
                    {
                        answer += consideration.GetAttractiveness(scrutinized, firedBy.Stances[scrutinized.Owner], firedBy);
                    }
                }
            }

            return(answer);
        }