Example #1
0
        public static void CoverWithTrash(AI ai, Mission mission)
        {
            Fish fish   = mission.m_agent;
            int  weight = fish.CarryingWeight;

            if (weight == 0)
            {
                return;
            }

            Point fishPoint = fish.Point();

            Bb.Update(ai);

            BitArray targetsNotCovered = new BitArray(Bb.TrashMap).Not().And(mission.m_targets());

            Bb.Set(targetsNotCovered, fishPoint, false);
            BitArray passableOrNotCovered = Bb.GetPassable(fishPoint).Or(targetsNotCovered);

            var path = Pather.aStar(fishPoint, targetsNotCovered, passableOrNotCovered).ToArray();

            if (path.Length > 1 && MoveAlong(fish, path.Range(0, path.Length - 1), mission.m_attackAlongTheWay))
            {
                var dump = path[path.Length - 1];
                var tile = ai.getTile(dump.X, dump.Y);
                fish.drop(tile, weight);
            }
            else if (path.Length > 1)
            {
                onADropMission.Add(fish);
            }
        }
Example #2
0
        public static void GetTrash(AI ai, Mission mission)
        {
            Fish fish = mission.m_agent;
            int  availableCapacity = fish.CarryCap - fish.CarryingWeight;

            if (availableCapacity == 0)
            {
                return;
            }

            Point fishPoint = fish.Point();

            Bb.Update(ai);

            BitArray targetsInTrash           = new BitArray(mission.m_targets()).And(Bb.TrashMap);
            BitArray passableOrTargetsInTrash = Bb.GetPassable(fishPoint).Or(targetsInTrash);

            while (availableCapacity > 0)
            {
                var path   = Pather.aStar(fishPoint, targetsInTrash, passableOrTargetsInTrash).ToArray();
                var trash  = path[path.Length - 1];
                var tile   = ai.getTile(trash.X, trash.Y);
                var amount = Math.Min(Math.Min(tile.TrashAmount, availableCapacity), fish.CurrentHealth - 1);
                if (amount == 0)
                {
                    return; // Can't pick it up
                }
                if (path.Length > 1 && MoveAlong(fish, path.Range(0, path.Length - 1), mission.m_attackAlongTheWay))
                {
                    fish.pickUp(tile, amount);

                    fishPoint          = path[path.Length - 2];
                    availableCapacity -= amount;
                    if (tile.TrashAmount == 0)
                    {
                        Bb.Set(targetsInTrash, trash, false);
                    }
                }
                else
                {
                    return; // no trash found, or didn't move far enough.
                }
            }
        }
Example #3
0
        public static void AttackTarget(AI ai, Mission mission)
        {
            Fish fish = mission.m_agent;

            if (fish.AttacksLeft == 0)
            {
                return;
            }

            int range = fish.Range;

            HashSet <Fish> previousTargets = GetAlreadyAttacked(fish);

            while (fish.AttacksLeft > 0)
            {
                Bb.Update(ai);

                Point    fishPoint                    = fish.Point();
                BitArray dontAttack                   = Bb.ToBitArray(previousTargets);
                BitArray attackable                   = new BitArray(dontAttack).Not().And(Bb.TheirFishMap);
                BitArray targetsInAttackable          = new BitArray(mission.m_targets()).And(attackable);
                BitArray passableOrTargetInAttackable = Bb.GetPassable(fishPoint).Or(targetsInAttackable);

                var path = Pather.aStar(fishPoint, targetsInAttackable, passableOrTargetInAttackable).ToArray();
                if (path.Length > 1)
                {
                    int attacks = fish.AttacksLeft;
                    MoveAlong(fish, path.Range(0, path.Length - range), true);
                    if (fish.AttacksLeft == attacks)
                    {
                        return;
                    }
                }
                else
                {
                    return;
                }
                if (fish.MovementLeft == 0)
                {
                    return;
                }
            }
        }
Example #4
0
        public static void GoTo(AI ai, Mission mission)
        {
            Fish fish = mission.m_agent;

            if (fish.MovementLeft == 0)
            {
                return;
            }

            Point fishPoint = fish.Point();

            Bb.Update(ai);

            BitArray passable          = Bb.GetPassable(fishPoint);
            BitArray targetsInPassable = new BitArray(mission.m_targets()).And(passable);

            var path = Pather.aStar(fishPoint, targetsInPassable, passable);

            MoveAlong(fish, path, mission.m_attackAlongTheWay);
        }