Пример #1
0
        private void HandlePodRacerHitCheckpoint(PodRacer podRacer, CheckPoint checkPoint)
        {
            PodRacerRaceState podRacerRaceState = raceState.PodRacerRaceStates[podRacer];
            Team          team          = podRacer.Owner;
            TeamRaceState teamRaceState = raceState.TeamRaceStates[team];
            CheckPoint    nextCheckPoint;

            if (podRacerRaceState.CurrentCheckPoint == checkPoint)
            {
                podRacerRaceState.CheckPointsReached++;

                teamRaceState.Timeout = raceRules.TIMEOUT + 1;

                if (checkPoint == arena.GetStartFinish())
                {
                    podRacerRaceState.RoundsFinished++;

                    if (raceResult.WinningTeam == null)
                    {
                        if (podRacerRaceState.RoundsFinished == raceRules.RACE_LENGTH)
                        {
                            raceResult.WinningTeam     = team;
                            raceState.Finished         = true;
                            teamRaceState.FinishedRace = true;
                        }
                    }
                }

                nextCheckPoint = arena.GetNextCheckPoint(checkPoint);
                podRacerRaceState.CurrentCheckPoint = nextCheckPoint;
            }
        }
Пример #2
0
        public void Bounce(PodRacer unitA, PodRacer unitB)
        {
            Vector relativePosition = unitA.Position - unitB.Position;
            Vector relativeVelocity = unitA.Velocity - unitB.Velocity;
            double massFactor       = (unitA.Mass + unitB.Mass) / (unitA.Mass * unitB.Mass);
            Vector impulse          =
                (
                    (relativeVelocity * relativePosition) /
                    relativePosition.LengthSquared
                ) *
                relativePosition /
                massFactor;
            double impulseFactor;

            if (impulse.Length < raceRules.MIN_HALF_IMPULSE)
            {
                impulseFactor = 1.0 + raceRules.MIN_HALF_IMPULSE / impulse.Length;
            }
            else
            {
                impulseFactor = 2.0;
            }

            unitA.Velocity = unitA.Velocity - (impulseFactor / unitA.Mass) * impulse;
            unitB.Velocity = unitB.Velocity + (impulseFactor / unitB.Mass) * impulse;
        }
Пример #3
0
        private void FinalizeRoundForPodRacer(PodRacer podRacer, PodRacerRaceState podRacerRaceState)
        {
            podRacer.ConvertStateToInt();

            if (podRacerRaceState.ShieldPenaltyRoundsCounter > 0)
            {
                podRacerRaceState.ShieldPenaltyRoundsCounter--;
            }
        }
Пример #4
0
 public PodRacer(PodRacer podRacer)
     : base(podRacer)
 {
     Owner           = podRacer.Owner;
     Number          = podRacer.Number;
     Pilot           = podRacer.Pilot;
     PodRacerPhysics = podRacer.PodRacerPhysics;
     PureMass        = podRacer.PureMass;
     IsShielded      = podRacer.IsShielded;
 }
Пример #5
0
        public void AcceleratePodRacer(PodRacer podRacer, double thrust)
        {
            if ((thrust < podRacer.PodRacerPhysics.MIN_THRUST) || (thrust > podRacer.PodRacerPhysics.MAX_THRUST))
            {
                throw new ArgumentOutOfRangeException("PodRacer thrust out of range!");
            }

            podRacer.Thrust = thrust;
            podRacer.Accelerate(1.0);
        }
Пример #6
0
        public void RotatePodRacerToPosition(PodRacer podRacer, Vector position)
        {
            Vector to = position - podRacer.Position;

            double angle = podRacer.Orientation.GetAngle(to);

            angle = LimitRotationToMaxRotationSpeed(podRacer, angle);

            podRacer.Rotate(angle);
        }
 public PodRacerRaceState(PodRacer podRacer)
 {
     PodRacer                   = podRacer;
     CurrentCommand             = null;
     ShieldPenaltyRoundsCounter = 0;
     HasBoosted                 = false;
     Failed             = false;
     CurrentCheckPoint  = null;
     RoundsFinished     = 0;
     CheckPointsReached = 0;
 }
Пример #8
0
 private void HandleShieldCommandForPodRacer(PodRacer podRacer)
 {
     if (CurrentCommandForPodRacerIsShield(podRacer))
     {
         ShieldPodRacer(podRacer);
     }
     else
     {
         UnShieldPodRacer(podRacer);
     }
 }
Пример #9
0
        public PodRacer CreatePodRacer(Team team, int number, IPilot pilot, Vector position, double heading, IPodRacerPhysics podRacerPhysics)
        {
            PodRacer newPodRacer;

            newPodRacer = new PodRacer(team, number, pilot, position, heading, podRacerPhysics);
            team.PodRacers.Add(newPodRacer);
            pilot.PodRacer = newPodRacer;
            PodRacers.Add(newPodRacer);

            return(newPodRacer);
        }
        public PodRacerRaceState Copy()
        {
            PodRacerRaceState copy;

            copy = new PodRacerRaceState(PodRacer.Copy())
            {
                CurrentCommand             = CurrentCommand.Copy(),
                ShieldPenaltyRoundsCounter = ShieldPenaltyRoundsCounter,
                HasBoosted         = HasBoosted,
                Failed             = Failed,
                CurrentCheckPoint  = CurrentCheckPoint.Copy(),
                RoundsFinished     = RoundsFinished,
                CheckPointsReached = CheckPointsReached
            };

            return(copy);
        }
Пример #11
0
 private void HandleAccelerateCommandsForPodRacer(PodRacer podRacer)
 {
     if (CanPodRacerAccelerate(podRacer))
     {
         if (CurrentCommandForPodRacerIsBoost(podRacer))
         {
             if (CanPodRacerBoost(podRacer))
             {
                 BoostPodRacer(podRacer);
             }
             else
             {
                 throw new InvalidOperationException("PodRacer already boosted!");
             }
         }
         else
         {
             AcceleratePodRacer(podRacer);
         }
     }
 }
Пример #12
0
        static private double CollisionTimeBetweenTwoUnits(Unit unitA, Unit unitB)
        {
            double time = double.NaN;

            double radiiSumSquared;

            if ((unitA is CheckPoint) || ((unitB is CheckPoint)))
            {
                if (unitA.Size > unitB.Size)
                {
                    radiiSumSquared = unitA.Size * unitA.Size;
                }
                else
                {
                    radiiSumSquared = unitB.Size * unitB.Size;
                }
            }
            else
            {
                radiiSumSquared = (unitA.Size + unitB.Size) * (unitA.Size + unitB.Size);
            }

            Vector relativePosition = unitA.Position - unitB.Position;
            Vector relativeVelocity = unitA.Velocity - unitB.Velocity;

            if (unitA.Velocity.IsEqual(unitB.Velocity))
            {
                return(double.NaN);
            }

            if ((unitA is PodRacer) && (unitB is PodRacer))
            {
                if (relativePosition.LengthSquared - radiiSumSquared < 0)
                {
                    double   distanceDelta = relativePosition.Length / (unitA.Size + unitB.Size);
                    double   subTime;
                    PodRacer unitAShrinked;
                    PodRacer unitBShrinked;

                    unitAShrinked       = new PodRacer(unitA as PodRacer);
                    unitAShrinked.Size -= distanceDelta * unitAShrinked.Size;
                    unitBShrinked       = new PodRacer(unitB as PodRacer);
                    unitBShrinked.Size -= distanceDelta * unitBShrinked.Size;

                    subTime = CollisionTimeBetweenTwoUnits(unitAShrinked, unitBShrinked);

                    if (subTime > 0)
                    {
                        return(subTime);
                    }
                    else
                    {
                        return(double.NaN);
                    }
                }
            }

            double pHalf = (relativePosition * relativeVelocity) / relativeVelocity.LengthSquared;
            double q     = (relativePosition.LengthSquared - radiiSumSquared) / relativeVelocity.LengthSquared;

            double pHalfSquared = pHalf * pHalf;

            if (pHalfSquared >= q)
            {
                time = -pHalf - Math.Sqrt(pHalfSquared - q);
            }

            return(time);
        }
Пример #13
0
 private void BoostPodRacer(PodRacer podRacer)
 {
     podRacerRaceStates[podRacer].HasBoosted = true;
     racePodRacerMechanics.BoostPodRacer(podRacer);
 }
Пример #14
0
 private bool CanPodRacerBoost(PodRacer podRacer)
 {
     return(!podRacerRaceStates[podRacer].HasBoosted);
 }
Пример #15
0
 private bool CurrentCommandForPodRacerIsShield(PodRacer podRacer)
 {
     return(podRacerRaceStates[podRacer].CurrentCommand.Shield);
 }
Пример #16
0
 private void AcceleratePodRacer(PodRacer podRacer)
 {
     racePodRacerMechanics.AcceleratePodRacer(podRacer, podRacerRaceStates[podRacer].CurrentCommand.Thrust);
 }
Пример #17
0
 private bool CurrentCommandForPodRacerIsBoost(PodRacer podRacer)
 {
     return(podRacerRaceStates[podRacer].CurrentCommand.Boost);
 }
Пример #18
0
 public void ApplyFractionToPodRacer(PodRacer podRacer)
 {
     podRacer.ApplyFraction(podRacer.PodRacerPhysics.FRACTION_FACTOR);
 }
Пример #19
0
 private void ShieldPodRacer(PodRacer podRacer)
 {
     podRacerRaceStates[podRacer].ShieldPenaltyRoundsCounter = raceRules.SHIELD_PENALTY_ROUNDS;
     podRacer.TurnShieldOn();
 }
Пример #20
0
        private double LimitRotationToMaxRotationSpeed(PodRacer podRacer, double rotation)
        {
            rotation = Helper.LimitDoubleToAbsValue(rotation, podRacer.PodRacerPhysics.MAX_ROTATION_SPEED);

            return(rotation);
        }
Пример #21
0
 private static void UnShieldPodRacer(PodRacer podRacer)
 {
     podRacer.TurnShieldOff();
 }
Пример #22
0
 private void HandleDestinationCommandForPodRacer(PodRacer podRacer)
 {
     racePodRacerMechanics.RotatePodRacerToPosition(podRacer, podRacerRaceStates[podRacer].CurrentCommand.Destination);
 }
Пример #23
0
 public bool PodRacerIsDisqualified(PodRacer podRacer)
 {
     return(raceState.PodRacerRaceStates[podRacer].Failed);
 }
Пример #24
0
 public void BoostPodRacer(PodRacer podRacer)
 {
     AcceleratePodRacer(podRacer, podRacer.PodRacerPhysics.BOOST_THRUST);
 }
Пример #25
0
 private void EvaluatePostRoundForPodRacer(PodRacer podRacer)
 {
     racePodRacerMechanics.ApplyFractionToPodRacer(podRacer);
     FinalizeRoundForPodRacer(podRacer, raceState.PodRacerRaceStates[podRacer]);
 }
Пример #26
0
 private void EvaluatePreRoundForPodRacer(PodRacer podRacer)
 {
     HandleDestinationCommandForPodRacer(podRacer);
     HandleShieldCommandForPodRacer(podRacer);
     HandleAccelerateCommandsForPodRacer(podRacer);
 }
Пример #27
0
 private bool CanPodRacerAccelerate(PodRacer podRacer)
 {
     return(podRacerRaceStates[podRacer].ShieldPenaltyRoundsCounter == 0);
 }