We need to combine this with the already existing methods to find a car close for battles.
Run after trackmediator move, here's what happens:
We sort the cars by on track position.
We either do it by telemetry
Save it into object
difference = FD-PD = 50m
time delta = difference/PS = 50/90 = 0.5s
When a driver is within 6 seconds for 15 (& it's for position) this will also show up as an actual battle.
When a car is within 6 seconds create a Battle object. These battle objects added / removed / kept every tick. if inside 6 seconds (no matter the order of the cars)
A = Car in front, B = Car behind
class carbattles {
existingBattles: [];
cars: Record<string | number, CarBattle>;
HandleBattles(cars) {
}
CarInBattleWith(carInFront, carInBack) {
// check if CarF exists in this.cars, if so add carInBack and save him in the list too.
}
}
class CarBattle {
constructor(entry: Entry) {
this.start = new Date();
this.entries = [entry];
}
AddCar(car) {
// Add car to list
}
RemoveCar(car) {
// Remove car
// If 1 car left destroy this battle.
}
handleBattle() {
// Check algorithm mentioned above.
return ; //cars still in the battle
}
}
// bit of FP, why not.
export BattleNegotiator = (carF, carB, distance, distanceToCorner, corner, speed) => {
// calculate defence level for carF
// This is based on wether or not it's for position, the driver and his personality
// and also most importantly the orders from it's team boss.
// will be put out in a number 0 is normal, -10 is a blue flag, -100 for a longer one
// The almost exact same counts for CarB but then attacking, -100 would only be from team orders
// or during a yellow flag, SC, w/e
//
}
class BattleNegotiator {
Negotiate(car1, car2) {
}
}
Now now check the distance from the car.