Beispiel #1
0
        public override void OnSourceCreation(GameResult gameResult, IShip source)
        {
            GameResult IgnoreResult = new GameResult();

            OnSourceCreation(gameResult, (Ship)source, (Ship)mirrorShip.Clone());
            other.OnCreation(IgnoreResult, real.FactionInfo);
            if (other.ControlHandler == null)
            {
                other.ControlHandler = real.ControlHandler;
            }
            other.ControlHandler.OnCreation(real);
            other.Actions.OnCreation(IgnoreResult, real);
            int actioncount = other.Actions.Count;

            for (int pos = 0; pos < actioncount; ++pos)
            {
                if (other.Actions[pos] is NullTransformAction)
                {
                    this.mirrorAIInfo = other.Actions[pos].AIInfo;
                    if (this.mirrorAIInfo != null)
                    {
                        this.mirrorAIInfo.OnSourceCreation(IgnoreResult, source, this);
                    }
                    other.Actions[pos] = this;
                    break;
                }
            }
            Functions.Swap <ActionSounds>(ref actionSounds, ref mirrorActionSounds);
        }
 protected BaseAction(BaseAction copy)
 {
     this.source          = copy.source;
     this.target          = copy.target;
     this.delay           = new Bounded <float>(copy.delay);
     this.targetableTypes = copy.targetableTypes;
     this.costs           = copy.costs;
     this.needsTarget     = copy.needsTarget;
     this.actionSounds    = copy.actionSounds;
     this.aIInfo          = Functions.Clone <IActionAIInfo>(copy.aIInfo);
 }
Beispiel #3
0
 public override bool IsThreatTo(IControlable other)
 {
     for (int pos = 0; pos < actions.Count; ++pos)
     {
         IActionAIInfo actionAIInfo = actions[pos].AIInfo;
         if (actionAIInfo != null && actionAIInfo.IsThreatTo(other))
         {
             return(true);
         }
     }
     return(base.IsThreatTo(other));
 }
Beispiel #4
0
        public override ControlInput GetControlInput(float dt, ControlInput original)
        {
            if (rand.Next(0, 99) == 1)
            {
                base.target = null;
                base.CheckTarget();
            }
            overideDesired = false;


            IControlable[] obstacles = this.obstacles.ToArray();
            bool[]         threats   = new bool[obstacles.Length];
            for (int pos = 0; pos < obstacles.Length; ++pos)
            {
                threats[pos] = obstacles[pos].IsThreatTo(this.host);
            }
            AIStateInfo stateInfo    = null;
            int         actionsCount = Math.Min(3, shipHost.Actions.Count);

            if (target != null)
            {
                stateInfo = new AIStateInfo(
                    target,
                    target.Current.Position.Linear - host.Current.Position.Linear,
                    obstacles,
                    threats
                    );
                for (int pos = 0; pos < actionsCount; ++pos)
                {
                    IActionAIInfo actionAIInfo = shipHost.Actions[pos].AIInfo;
                    if (actionAIInfo != null)
                    {
                        actionAIInfo.Update(stateInfo);
                        if (!overideDesired && actionAIInfo.ShouldAim)
                        {
                            desiredAngle   = actionAIInfo.AimAngle;
                            overideDesired = true;
                        }
                        if (actionAIInfo.ShouldActivate)
                        {
                            original[InputAction.Action] = true;
                            original.ActiveActions[pos]  = true;
                        }
                    }
                }
            }
            if (!overideDesired)
            {
                for (int pos = 0; pos < obstacles.Length; ++pos)
                {
                    if (threats[pos])
                    {
                        IControlable obstacle = obstacles[pos];
                        Vector2D     dir2     = obstacle.Current.Position.Linear - host.Current.Position.Linear;
                        if ((obstacle.ControlableType & ControlableType.Ship) == ControlableType.Ship)
                        {
                            desiredAngle   = (-host.DirectionVector).Angle;
                            overideDesired = true;
                        }
                        else
                        {
                            desiredAngle   = (dir2 ^ (host.DirectionVector ^ dir2)).Angle;
                            overideDesired = true;
                        }
                        break;
                    }
                }
            }
            if (target != null)
            {
                IShipAIInfo shipAIInfo = shipHost.AIInfo;
                if (shipAIInfo != null)
                {
                    shipAIInfo.Update(stateInfo);
                    if (shipAIInfo.ShouldSetAngle)
                    {
                        overideDesired = true;
                        desiredAngle   = shipAIInfo.DesiredAngle;
                    }
                }
            }
            else if (!overideDesired)
            {
                if (host.Current.Velocity.Linear.Magnitude > host.MovementInfo.MaxLinearVelocity.Value * .05f)
                {
                    desiredAngle   = (-host.Current.Velocity.Linear).Angle;
                    overideDesired = true;
                    original       = base.GetControlInput(dt, original);
                    if (MathHelper.Abs(MathHelper.GetAngleDifference(desiredAngle, host.DirectionAngle)) < .1f)
                    {
                        original.ThrustPercent = 1;
                    }
                    else
                    {
                        original.ThrustPercent = 0;
                    }
                    return(original);
                }
            }
            return(base.GetControlInput(dt, original));
        }