Exemple #1
0
        /// <summary>
        /// Obtains a suitable target player
        /// </summary>
        protected Vehicle getTargetZombie(Script_ZombieZone.TeamState state)
        {               //Find the closest valid zombie
            Vector3 selfpos = _state.position();
            IEnumerable <ZombieBot> zombies = state.zombies.OrderBy(zomb => zomb._state.position().DistanceSquared(selfpos));

            foreach (ZombieBot zombie in zombies)
            {
                if (isValidTarget(zombie))
                {
                    return(zombie);
                }
            }

            IEnumerable <Player> zombiePlayers = state.zombiePlayers.OrderBy(zomb => zomb._state.position().DistanceSquared(selfpos));

            foreach (Player zombie in zombiePlayers)
            {
                if (!zombie.IsSpectator && isValidTarget(zombie._baseVehicle))
                {
                    return(zombie._baseVehicle);
                }
            }

            return(null);
        }
Exemple #2
0
        /// <summary>
        /// Obtains a suitable target player
        /// </summary>
        protected Vehicle getTargetZombie(Script_ZombieZone.TeamState state)
        {               //Find the closest valid zombie
            Vector3 selfpos = _state.position();

            IEnumerable <ZombieBot> zombies = state.zombies.ToList().Where(zomb => zomb != null).OrderBy(zomb => zomb._state.position().DistanceSquared(selfpos));

            //goes after zombies first
            foreach (ZombieBot zombie in zombies)
            {
                if (isValidTarget(zombie))
                {
                    return(zombie);
                }
            }

            //then the king
            if (state.kingZombie != null && isValidTarget(state.kingZombie))
            {
                return(state.kingZombie);
            }

            //then finally the players
            IEnumerable <Player> zombiePlayers = state.zombiePlayers.ToList().Where(zomb => zomb != null).OrderBy(zomb => zomb._state.position().DistanceSquared(selfpos));

            foreach (Player zombie in zombiePlayers)
            {
                if (!zombie.IsSpectator && isValidTarget(zombie._baseVehicle))
                {
                    return(zombie._baseVehicle);
                }
            }


            return(null);
        }
            public void tryFinalAction(Script_ZombieZone.TeamState state)
            {
                if (!performed_finalAction)
                {
                    if (final != null)
                    {
                        final(state);
                    }

                    performed_finalAction = true;
                }
            }
Exemple #4
0
        /// <summary>
        /// Checks for any distractions we should approach
        /// </summary>
        protected virtual bool checkForCloak(Script_ZombieZone.TeamState state)
        {       //Is the team cloaked?
            if (!state.bCloaked)
            {
                return(false);
            }

            //Just wander about!
            steering.steerDelegate = delegate(InfantryVehicle vehicle)
            {
                return(vehicle.SteerForWander(0.5f));
            };

            return(true);
        }
Exemple #5
0
        /// <summary>
        /// Obtains a suitable target player
        /// </summary>
        protected Vehicle getTargetZombie(Script_ZombieZone.TeamState state)
        {               //Find the closest valid zombie
            Vector3 selfpos = _state.position();

            IEnumerable <ZombieBot> zombies = state.zombies.ToList().Where(zomb => zomb != null).OrderBy(zomb => zomb._state.position().DistanceSquared(selfpos));

            foreach (ZombieBot zombie in zombies)
            {
                if (isValidTarget(zombie))
                {
                    return(zombie);
                }
            }


            return(null);
        }
Exemple #6
0
        /// <summary>
        /// Checks for any special circumstances we should be handling
        /// </summary>
        protected bool checkCircumstances()
        {       //Check for extraordinary circumstances
            Script_ZombieZone.TeamState state = zz.getTeamState(targetTeam);
            if (state != null)
            {
                if (checkForDistractions(state))
                {
                    return(true);
                }

                if (checkForCloak(state))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #7
0
        /// <summary>
        /// Checks for any distractions we should approach
        /// </summary>
        protected virtual bool checkForDistractions(Script_ZombieZone.TeamState state)
        {       //Do we already have a distraction?
            if (distraction != null)
            {
                if (distraction.bActive)
                {
                    if (!headToDistraction(distraction))
                    {
                        distraction = null;
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    distraction = null;
                }
            }

            //Are there any distractions we can see?
            foreach (Script_ZombieZone.ZombieDistraction distract in state.distractions)
            {   //At it's limit?
                if (distract.distractLimit <= 0)
                {
                    continue;
                }

                //If it works, use it
                if (headToDistraction(distract))
                {
                    distraction = distract;
                    distract.distractLimit--;
                    return(true);
                }
            }

            return(false);
        }
Exemple #8
0
        /// <summary>
        /// Keeps the vehicle state updated, and sends an update packet if necessary
        /// </summary>
        /// <returns>A boolean indicating whether an update packet should be sent</returns>
        public override bool poll()
        {               //If it isn't a turret then do nothing
            if (_primaryGun == null)
            {
                return(false);
            }

            //If below non-operational HP don't fire
            if (_state.health < _type.HitpointsRequiredToOperate)
            {
                return(false);
            }

            if (zz == null)
            {
                return(false);
            }

            //Make sure our creator is still on our team
            if (_creator._team == null || _creator._team != _team)
            {
                return(false);
            }

            //Get the team state
            Script_ZombieZone.TeamState state = zz.getTeamState(_team);

            //Do we need to seek a new target?
            if (targetZombie == null || !isValidTarget(targetZombie))
            {
                targetZombie = getTargetZombie(state);
            }

            //Valid target?
            if (targetZombie == null)
            {
                return(false);
            }

            //Look at our target!
            _state.fireAngle = Helpers.computeLeadFireAngle(_state, targetZombie._state, _primaryProjectile.muzzleVelocity / 1000);

            //If not reloaded yet don't fire
            int now = Environment.TickCount;

            if (_tickShotTime + _fireDelay > now ||
                _tickReloadTime > now)
            {                   //But maybe send an update packet?
                if (now - _tickLastUpdate > 300)
                {
                    _tickLastUpdate = now;
                    return(true);
                }

                return(false);
            }

            //We're firing! On a bot?
            if (targetZombie._bBotVehicle)
            {
                targetZombie.applyExplosionDamage(true, _creator,
                                                  targetZombie._state.positionX, targetZombie._state.positionY, _primaryProjectile);
            }

            _shouldFire   = true;
            _tickShotTime = Environment.TickCount;

            //Adjust ammo accordingly
            if (_ammoCapacity != 0 && --_ammoRemaining <= 0)
            {
                _tickReloadTime = Environment.TickCount + _reloadTime;
                _ammoRemaining  = _ammoCapacity;
            }

            return(true);
        }
 public TickerInfo(Player p, Script_ZombieZone.TeamState s, int t)
 {
     player = p;
     state  = s;
     time   = t;
 }
Exemple #10
0
 /// <summary>
 /// Checks for any distractions we should approach
 /// </summary>
 protected override bool checkForDistractions(Script_ZombieZone.TeamState state)
 {       //We don't get distracted!
     return(false);
 }
Exemple #11
0
        /// <summary>
        /// Looks after the bot's functionality
        /// </summary>
        public override bool poll()
        {               //Dead? Do nothing
            if (IsDead)
            {
                steering.steerDelegate = null;
                return(base.poll());
            }

            //Do we have a player to follow?
            if (creator == null || creator.IsDead || creator.IsSpectator)
            {
                kill(null);
                return(false);
            }

            int now = Environment.TickCount;

            //Get the team state
            Script_ZombieZone.TeamState state = zz.getTeamState(_team);

            //Stay close to our owner
            bool bClearPath = Helpers.calcBresenhemsPredicate(_arena,
                                                              _state.positionX, _state.positionY, creator._state.positionX, creator._state.positionY,
                                                              delegate(LvlInfo.Tile t)
            {
                return(!t.Blocked);
            }
                                                              );

            if (bClearPath)
            {
                //Persue directly!
                steering.steerDelegate = steerForFollowOwner;
            }
            else
            {                   //Does our path need to be updated?
                if (now - _tickLastPath > Script_ZombieZone.c_combatBotPathUpdateInterval)
                {               //Update it!
                    _tickLastPath = int.MaxValue;

                    _arena._pathfinder.queueRequest(
                        (short)(_state.positionX / 16), (short)(_state.positionY / 16),
                        (short)(creator._state.positionX / 16), (short)(creator._state.positionY / 16),
                        delegate(List <Vector3> path, int pathLength)
                    {
                        if (path != null)
                        {                                       //Is the path too long?
                            if (pathLength > Script_ZombieZone.c_zombieMaxPath)
                            {                                   //Destroy ourself and let another zombie take our place
                                _path = null;
                                destroy(true);
                            }
                            else
                            {
                                _path       = path;
                                _pathTarget = 1;
                            }
                        }

                        _tickLastPath = now;
                    }
                        );
                }

                //Navigate to him
                if (_path == null)
                {
                    //If we can't find out way to him, just mindlessly walk in his direction for now
                    steering.steerDelegate = steerForFollowOwner;
                }
                else
                {
                    steering.steerDelegate = steerAlongPath;
                }
            }

            //Do we need to seek a new target?
            if (targetZombie == null || !isValidTarget(targetZombie))
            {
                targetZombie = getTargetZombie(state);
            }

            if (targetZombie != null)
            {
                if (bClearPath)
                {                       //Can we shoot?
                    if (_weapon.ableToFire())
                    {
                        int aimResult = _weapon.getAimAngle(targetZombie._state);

                        if (_weapon.isAimed(aimResult) && creator.inventoryModify(2000, -_weapon.AmmoUse))
                        {                               //Spot on! Fire?
                            _itemUseID = _weapon.ItemID;
                            _weapon.shotFired();

                            //Simulate the damage if we're attacking a bot
                            if (targetZombie._bBotVehicle)
                            {
                                targetZombie.applyExplosionDamage(true, creator, targetZombie._state.positionX, targetZombie._state.positionY, _weapon.Projectile);
                            }
                        }

                        steering.bSkipAim = true;
                        steering.angle    = aimResult;
                    }
                    else
                    {
                        steering.bSkipAim = false;
                    }
                }
            }

            //Handle normal functionality
            return(base.poll());
        }