public AttackTask(Weapon weapon, Vec3 target)
 {
     this.taskTime = 0f;
     this.weapon = weapon;
     this.targetPosition = target;
     this.targetEntity = null;
 }
 public AttackTask(Weapon weapon, Dynamic target)
 {
     this.taskTime = 0f;
     this.weapon = weapon;
     this.targetPosition = new Vec3(float.NaN, float.NaN, float.NaN);
     this.targetEntity = target;
 }
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnDeleteSubscribedToDeletionEvent(Entity)"/></summary>
        protected override void OnDeleteSubscribedToDeletionEvent(Entity entity)
        {
            base.OnDeleteSubscribedToDeletionEvent(entity);

            if (targetTask == entity)
                targetTask = null;

            //remove deleted weapon
            Weapon weapon = entity as Weapon;
            if (weapon != null)
                unitWeapons.Remove(weapon);
        }
        private void ControlledObject_Damage(Dynamic entity, MapObject prejudicial, Vec3 pos, float damage)
        {
            if (generalTaskType != GeneralTaskTypes.Battle && prejudicial != null)
            {
                Unit sourceUnit = null;

                Bullet bullet = prejudicial as Bullet;
                if (bullet != null)
                    sourceUnit = bullet.SourceUnit;
                Explosion explosion = prejudicial as Explosion;
                if (explosion != null)
                    sourceUnit = explosion.SourceUnit;

                if (sourceUnit != null)
                {
                    Intellect unitIntellect = sourceUnit.Intellect as Intellect;
                    if (unitIntellect != null && unitIntellect.Faction != Faction)
                    {
                        //do battle task
                        DoGeneralTask(GeneralTaskTypes.Battle, null);

                        //move to enemy
                        DoMoveTask(sourceUnit.Position);

                        //notify allies
                        NotifyAlliesOnEnemy(sourceUnit.Position);
                    }
                }
            }
        }
        private void DoAttackTask(Weapon weapon, Dynamic target)
        {
            AttackTask task = attackTasks.Find(delegate(AttackTask t)
            {
                return t.Weapon == weapon;
            });

            if (task != null && task.TargetEntity == target)
                return;

            if (task != null)
                ResetAttackTask(task);

            task = new AttackTask(weapon, target);
            AddRelationship(target);
            attackTasks.Add(task);
        }
 public AttackTask(MechUnitAI owner, Weapon weapon, Vec3 target)
 {
     this.owner = owner;
     this.taskTime = 0f;
     this.weapon = weapon;
     this.targetPosition = target;
     this.targetEntity = null;
 }
Exemple #7
0
        void UpdateTask()
        {
            Unit newTarget = null;
            float newTargetPriority = 0;

            //find target
            {
                float radius = ControlledObject.ViewRadius;

                Map.Instance.GetObjects( new Sphere( ControlledObject.Position, radius ),
                    MapObjectSceneGraphGroups.UnitGroupMask, delegate( MapObject mapObject )
                {
                    Unit obj = (Unit)mapObject;

                    //check by distance
                    Vec3 diff = obj.Position - ControlledObject.Position;
                    float objDistance = diff.Length();
                    if( objDistance > radius )
                        return;

                    float priority = GetAttackObjectPriority( obj );
                    if( priority != 0 && priority > newTargetPriority )
                    {
                        newTarget = obj;
                        newTargetPriority = priority;
                    }
                } );
            }

            //update targetTask
            if( newTarget != targetTask )
            {
                if( targetTask != null )
                    UnsubscribeToDeletionEvent( targetTask );
                targetTask = newTarget;
                if( targetTask != null )
                    SubscribeToDeletionEvent( targetTask );
            }
        }
Exemple #8
0
        void DoAttackTask( Weapon weapon, Dynamic target )
        {
            AttackTask task = attackTasks.Find( delegate( AttackTask t )
            {
                return t.Weapon == weapon;
            } );

            if( task != null && task.TargetEntity == target )
                return;

            if( task != null )
                ResetAttackTask( task );

            task = new AttackTask( weapon, target );
            SubscribeToDeletionEvent( target );
            attackTasks.Add( task );
        }
        // NH & KEEN - a function to calculate the angle to target
        private Radian CalculateAngleToTarget(Dynamic target)
        {
            Vec3 needDirection = (target.GetInterpolatedPosition() - Position).GetNormalize();
            Vec3 weaponDirection = Rotation.GetForward();

            Radian angle = Math.Abs(MathFunctions.ACos(Vec3.Dot(needDirection, weaponDirection)));
            return angle;
        }
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnDeleteSubscribedToDeletionEvent(Entity)"/></summary>
        protected override void OnDeleteSubscribedToDeletionEvent(Entity entity)
        {
            base.OnDeleteSubscribedToDeletionEvent(entity);

            if (sourceUnit == entity)
                sourceUnit = null;
            if (reasonObject == entity)
                reasonObject = null;
        }
 public DamageItem(Dynamic dynamic, Vec3 position, float damage)
 {
     this.dynamic = dynamic;
     this.position = position;
     this.damage = damage;
 }
Exemple #12
0
 public Task( Types type, Dynamic entity )
 {
     this.type = type;
     this.position = new Vec3( float.NaN, float.NaN, float.NaN );
     this.entityType = null;
     this.entity = entity;
 }
Exemple #13
0
 public Task( Types type, Vec3 position, DynamicType entityType )
 {
     this.type = type;
     this.position = position;
     this.entityType = entityType;
     this.entity = null;
 }
Exemple #14
0
 public Task( Types type, Vec3 position )
 {
     this.type = type;
     this.position = position;
     this.entityType = null;
     this.entity = null;
 }
Exemple #15
0
 public Task( Types type )
 {
     this.type = type;
     this.position = new Vec3( float.NaN, float.NaN, float.NaN );
     this.entityType = null;
     this.entity = null;
 }
            public AttackTask(Weapon weapon, Dynamic target)
            {
                this.taskTime = 0f;
                this.weapon = weapon;
                if (target != null)
                {
                    this.targetPosition = target.Position;
                }
                else
                {
                    this.targetPosition = new Vec3(float.NaN, float.NaN, float.NaN);
                }

                this.targetEntity = target;
            }
        protected override void OnTick()
        {
            base.OnTick();

            if (target == null) return;

            if (firstTick)
            {
                startDistance = (target.Position - Position).Length();
                firstTick = false;

                // NH & KEEN - if our target is a unit, select a random bodypart to target, otherwise check if there is a physics body to follow
                AKunit targetUnit = target as AKunit;

                if (targetUnit != null)
                {
                    if (targetUnit.PhysicsModel != null && targetUnit.PhysicsModel.Bodies.Length != 0)
                    {
                        string targetBodyName = targetUnit.Type.BodyParts[World.Instance.Random.Next(0, targetUnit.Type.BodyParts.Count)].PhysicsShape;

                        FindTargetShape(targetUnit, targetBodyName, out targetBody, out targetShape);
                    }
                }
                else
                {
                    if (target.PhysicsModel != null && target.PhysicsModel.Bodies.Length != 0)
                    {
                        targetBody = target.PhysicsModel.Bodies[0];
                    }
                }
            }

            if (currentDelay < Type.HomingDelay)
            {
                currentDelay += TickDelta;
                return;
            }

            // NH & KEEN - lose target if it is out of our view angle (stops missiles from doing endless circles around the target)
            if (Type.HomingAngle < 360.0f)
            {
                float homingAngle = Type.HomingAngle / 2;

                if (CalculateAngleToTarget(target) > new Degree(homingAngle).InRadians())
                {
                    target = null;
                    return;
                }
            }

            // NH & KEEN - explode if we get closer than proximityDistance to the target (used for Bluestreak Missiles)
            if ((target.Position - Position).Length() < Type.ProximityDistance)
            {
                HitObjects_Create();
                Die();
            }

            if (Type.HomingCorrection > 0)
            {
                MomentaryTurnToPositionUpdate(target.Position);
            }

            Vec3 velocity = Rotation.GetForward().GetNormalize() * Type.Velocity;
            base.Velocity = velocity;
        }
Exemple #18
0
        void CopyInfluencesToObject( Dynamic destination )
        {
            foreach( Entity child in Children )
            {
                if( child.IsSetForDeletion )
                    continue;

                Influence influence = child as Influence;
                if( influence == null )
                    continue;

                Influence i = (Influence)Entities.Instance.Create( influence.Type, destination );
                i.RemainingTime = influence.RemainingTime;
                i.PostCreate();
            }
        }
        // NH & KEEN - searches all bodies of the target for a certain shape (used for bodypart targetting)
        private void FindTargetShape(Dynamic target, string targetShapeName, out Body targetBody, out Shape targetShape)
        {
            foreach (Body body in target.PhysicsModel.Bodies)
            {
                Shape shape = body.GetShape(targetShapeName);

                if (shape != null)
                {
                    targetBody = body;
                    targetShape = shape;

                    return;
                }
            }

            targetBody = null;
            targetShape = null;

            return;
        }
Exemple #20
0
 void GameBillboard_Damage( Dynamic entity, MapObject prejudicial, Vec3 pos, float damage )
 {
     if( gameTime == 0 )
         GameStart();
 }