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; } }
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; }
private void FinalizeRoundForPodRacer(PodRacer podRacer, PodRacerRaceState podRacerRaceState) { podRacer.ConvertStateToInt(); if (podRacerRaceState.ShieldPenaltyRoundsCounter > 0) { podRacerRaceState.ShieldPenaltyRoundsCounter--; } }
public PodRacer(PodRacer podRacer) : base(podRacer) { Owner = podRacer.Owner; Number = podRacer.Number; Pilot = podRacer.Pilot; PodRacerPhysics = podRacer.PodRacerPhysics; PureMass = podRacer.PureMass; IsShielded = podRacer.IsShielded; }
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); }
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; }
private void HandleShieldCommandForPodRacer(PodRacer podRacer) { if (CurrentCommandForPodRacerIsShield(podRacer)) { ShieldPodRacer(podRacer); } else { UnShieldPodRacer(podRacer); } }
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); }
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); } } }
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); }
private void BoostPodRacer(PodRacer podRacer) { podRacerRaceStates[podRacer].HasBoosted = true; racePodRacerMechanics.BoostPodRacer(podRacer); }
private bool CanPodRacerBoost(PodRacer podRacer) { return(!podRacerRaceStates[podRacer].HasBoosted); }
private bool CurrentCommandForPodRacerIsShield(PodRacer podRacer) { return(podRacerRaceStates[podRacer].CurrentCommand.Shield); }
private void AcceleratePodRacer(PodRacer podRacer) { racePodRacerMechanics.AcceleratePodRacer(podRacer, podRacerRaceStates[podRacer].CurrentCommand.Thrust); }
private bool CurrentCommandForPodRacerIsBoost(PodRacer podRacer) { return(podRacerRaceStates[podRacer].CurrentCommand.Boost); }
public void ApplyFractionToPodRacer(PodRacer podRacer) { podRacer.ApplyFraction(podRacer.PodRacerPhysics.FRACTION_FACTOR); }
private void ShieldPodRacer(PodRacer podRacer) { podRacerRaceStates[podRacer].ShieldPenaltyRoundsCounter = raceRules.SHIELD_PENALTY_ROUNDS; podRacer.TurnShieldOn(); }
private double LimitRotationToMaxRotationSpeed(PodRacer podRacer, double rotation) { rotation = Helper.LimitDoubleToAbsValue(rotation, podRacer.PodRacerPhysics.MAX_ROTATION_SPEED); return(rotation); }
private static void UnShieldPodRacer(PodRacer podRacer) { podRacer.TurnShieldOff(); }
private void HandleDestinationCommandForPodRacer(PodRacer podRacer) { racePodRacerMechanics.RotatePodRacerToPosition(podRacer, podRacerRaceStates[podRacer].CurrentCommand.Destination); }
public bool PodRacerIsDisqualified(PodRacer podRacer) { return(raceState.PodRacerRaceStates[podRacer].Failed); }
public void BoostPodRacer(PodRacer podRacer) { AcceleratePodRacer(podRacer, podRacer.PodRacerPhysics.BOOST_THRUST); }
private void EvaluatePostRoundForPodRacer(PodRacer podRacer) { racePodRacerMechanics.ApplyFractionToPodRacer(podRacer); FinalizeRoundForPodRacer(podRacer, raceState.PodRacerRaceStates[podRacer]); }
private void EvaluatePreRoundForPodRacer(PodRacer podRacer) { HandleDestinationCommandForPodRacer(podRacer); HandleShieldCommandForPodRacer(podRacer); HandleAccelerateCommandsForPodRacer(podRacer); }
private bool CanPodRacerAccelerate(PodRacer podRacer) { return(podRacerRaceStates[podRacer].ShieldPenaltyRoundsCounter == 0); }