@name Complete e2 car chip
@inputs [Base Pod]:wirelink
@inputs [FL FR RL RR]:entity
@outputs Brakes Grip RPM Gear
@persist AngS T A D RPM1 RPM2 RPM3 RPM4
@persist W S Space Shift On Mouse1 Mouse2
@persist Force:vector DownF DownFrear
@trigger Mouse1 Mouse2
@model models/sprops/rectangles/size_2/rect_12x12x3.mdl
if(first()|duped())
{runOnTick(1)}
#############################Steering##################################
if(->Pod){entity():propFreeze(1)}
if( !(A|D) | (A&D) )
{
    if(AngS>0){AngS-=1.8, if(AngS<=0){AngS=0} }
    if(AngS<0){AngS+=1.8, if(AngS>=0){AngS=0} }  
}
if(D){AngS-=1.3, if(AngS<=-40){AngS=-40}}
if(A){AngS+=1.3, if(AngS>=40){AngS=40}}
entity():setAng(Base:entity():toWorld(ang(0,AngS,0)))
###############################Pod#####################################
A=Pod["A",number]
D=Pod["D",number]
W=Pod["W",number]
S=Pod["S",number]
Space=Pod["Space",number]
Shift=Pod["Shift",number]
On=Pod["Active",number]
Mouse1=Pod["Mouse1",number]
Mouse2=Pod["Mouse2",number]
###############################Movement################################
if(W){FL:applyTorque(vec(0,T,0))}
if(S){FL:applyTorque(vec(0,-T,0))}
if(W){FR:applyTorque(vec(0,-T,0))}
if(S){FR:applyTorque(vec(0,T,0))}
if(W){RL:applyTorque(vec(0,T,0))}
if(S){RL:applyTorque(vec(0,-T,0))}
if(W){RR:applyTorque(vec(0,-T,0))}
if(S){RR:applyTorque(vec(0,T,0))}
if (RPM > 50*Gear){T=0}else{T=100000}
###############################Brakes##################################
if(Space){FL:applyTorque(-FL:angVelVector()*FL:mass()*1)}
if(Space){FR:applyTorque(-FR:angVelVector()*RL:mass()*1)}
if(Space){RL:applyTorque(-RL:angVelVector()*RL:mass()*1)}
if(Space){RR:applyTorque(-RR:angVelVector()*RR:mass()*1)}
if(On == 0){Space=1}
###############################RPM_Stuff###############################
RPM1 = abs(FL:angVel():pitch() / 6)
RPM2 = abs(FR:angVel():pitch() / 6)
RPM3 = abs(RL:angVel():pitch() / 6)
RPM4 = abs(RR:angVel():pitch() / 6)
###############################Gears###################################
RPM = (RPM1 + RPM2 + RPM3 + RPM4)/4
if (~Mouse1 & Mouse1) {
    if (Gear < 5) {Gear += 1}}
elseif (~Mouse2 & Mouse2) {
    if (Gear > 0) {Gear -= 1}}
###############################DownForce#################################
if (~Shift & Shift) { Grip = !Grip }
if(first())
{
    DownF = -10  
    DownFrear = -10
}
    Force = vec()
if(clk())
{
    Force = Force + entity():up() * FL:mass() * DownF * Grip
    Force = Force + entity():up() * FR:mass() * DownFrear * Grip
    Force = Force + entity():up() * RL:mass() * DownF * Grip
    Force = Force + entity():up() * RR:mass() * DownFrear * Grip
}
if(clk())
{
    FL:applyForce(Force)
    FR:applyForce(Force)
    RL:applyForce(Force)
    RR:applyForce(Force)
}
