Exemplo n.º 1
0
        public void SimpleDestroyTest()
        {
            Clutch test = new Clutch();

            test.damageClutch();
            Assert.IsFalse(test.isFixed());
        }
Exemplo n.º 2
0
        public void RingsPickedCheck()
        {
            //add an egg
            ClutchEgg NewEgg = AddEgg();

            //add a ring
            IDMark NewRing = AddRing(NewEgg, "UK9876");

            //clone
            BirdRegistration ClonedApp = _birdReg.Clone(SSOUSerId_Sartain);
            int ClonedApplicationId    = ClonedApp.ApplicationId;

            ClonedApp = ValidateEggs(ClonedApp);

            //add a ring to egg - existing rings will have gone
            Clutch ClonedClutch = (Clutch)ClonedApp.RegistrationApplication;

            AddRing(ClonedClutch.Eggs[0], "UK1567");

            AddEggWithOneRing("UK1568");

            Assert.IsTrue(ClonedClutch.RingsPicked);

            //tidy up cloned app
            RemoveApplication(ClonedApplicationId);
        }
Exemplo n.º 3
0
        private void InitializeUI()
        {
            const int tileSize = 50;
            const int gridSize = 8;

            UIBoard = new PictureBox[gridSize, gridSize];
            for (int i = 0; i < gridSize; i++)
            {
                for (int j = 0; j < gridSize; j++)
                {
                    PictureBox newTile = new PictureBox
                    {
                        Size     = new Size(tileSize, tileSize),
                        Location = new Point(tileSize * j, tileSize * i)
                    };
                    Controls.Add(newTile);
                    if ((i + j) % 2 == 1)
                    {
                        newTile.Click += new EventHandler(Board_Click);
                    }
                    FillColor(newTile, i, j);
                    newTile.Name  = $"T{i}{j}";
                    UIBoard[i, j] = newTile;
                }
            }
            checkers.amendBoardListener.Set();
            if (!checkers.testMode)
            {
                Clutch.Dispose();
            }
        }
Exemplo n.º 4
0
 internal Car(Differential differential, Clutch clutch, Gearbox gearbox, Suspension suspension)
 {
     this.differential = differential;
     this.clutch       = clutch;
     this.gearbox      = gearbox;
     this.suspension   = suspension;
 }
Exemplo n.º 5
0
        public void CheckRingMarkIdCannotBeEnteredTwiceOnDiffEggsOnCloneWithNew()
        {
            //add an egg
            ClutchEgg NewEgg = AddEgg();

            //add a ring
            IDMark NewRing = AddRing(NewEgg, "UK9876");

            //clone
            BirdRegistration ClonedApp = _birdReg.Clone(SSOUSerId_Sartain);
            int ClonedApplicationId    = ClonedApp.ApplicationId;

            ClonedApp = ValidateEggs(ClonedApp);

            //add a ring to egg - existing rings will have gone
            Clutch ClonedClutch = (Clutch)ClonedApp.RegistrationApplication;

            AddRing(ClonedClutch.Eggs[0], "UK1567");

            AddEggWithOneRing("UK1567");

            //validate
            ValidateEggs();
            //make sure there has been validation errors
            Assert.IsNotNull(_birdReg.ValidationErrors);

            //the error should be RingOnEggIsUsed
            Assert.AreNotSame(Phoenix.BO.ValidationError.ValidationCodes.RingOnEggIsUsed, ((Phoenix.BO.ValidationError)_birdReg.ValidationErrors.Errors[0]).ValidationID);

            //tidy up cloned app
            RemoveApplication(ClonedApplicationId);
        }
Exemplo n.º 6
0
        private IDMark AddEggWithOneRing(Clutch clutch, string mark)
        {
            //add an egg
            ClutchEgg NewEgg = AddEgg(clutch);

            //add a ring
            IDMark NewRing = AddRing(NewEgg, mark);

            return(NewRing);
        }
Exemplo n.º 7
0
        private ClutchEgg AddEgg(Clutch clutch)
        {
            //add an egg
            ClutchEgg NewEgg = clutch.AddEgg();

            Assert.IsNotNull(NewEgg);
            Assert.IsTrue(clutch.Eggs.Length > 0, "Egg not added!");

            return(NewEgg);
        }
 void Awake()
 {
     engineTorqueFromFile = false;
     torqueRPMValuesLen   = 0;
     body          = rigidbody;
     myTransform   = transform;
     clutch        = new Clutch();
     carController = GetComponent <CarController>();
     setup         = GetComponent <Setup>();
     axles         = GetComponent <Axles>();
     fuelTanks     = GetComponentsInChildren <FuelTank>();
     poweredWheels = axles.rearAxle.wheels;       // to avoid NullReferenceException
 }
Exemplo n.º 9
0
        protected override void PacketReceived(Clutch.Net.UDP.UDPPacketBuffer buffer)
        {
            /*
            MessageWasReceivedEvent(buffer, new EventArgs());
            Clutch.Net.UDP.UDPPacketBuffer bufferToSend = new Clutch.Net.UDP.UDPPacketBuffer();
            bufferToSend.Data = Encoding.UTF8.GetBytes("Hello this is Server, You Said=\""+Encoding.UTF8.GetString(buffer.Data,0,buffer.DataLength)+"\" and time: "+ DateTime.Now.ToLongTimeString());
            bufferToSend.DataLength = bufferToSend.Data.Length;
            bufferToSend.RemoteEndPoint = buffer.RemoteEndPoint;

            AsyncBeginSend(bufferToSend);
             */
            AsyncBeginSend(buffer);
        }
Exemplo n.º 10
0
        public void CheckRingEnterOnAnotherApplicationBeforeDOR()
        {
            const string RingMark = "AY1235";

            //add a ring
            AddEggWithOneRing(RingMark);

            //add a specimen (required to persist ring info)
            ClutchSpecimen Spec1 = ClutchApp.Eggs[0].CreateSpecimenFrom(ClutchApp);

            Spec1.SpecimenType = new SpecimenType(BO.Application.GenderType.Male);
            ValidateEggs();
            IDMark NewRing = Spec1.AddRing(ClutchApp.Eggs[0].Rings[0]);

            NewRing.GetMarkType();

            //...and save it
            _birdReg = _birdReg.Save();

            //create another application
            BirdRegistration NewApp = InternalCreateApplication();

            //add a ring & egg
            Clutch NewClutch = (Clutch)NewApp.RegistrationApplication;

            AddEggWithOneRing(NewClutch, RingMark);

            //add a specimen (required to persist ring info)
            ClutchSpecimen Spec2 = NewClutch.Eggs[0].CreateSpecimenFrom(NewClutch);

            Spec2.SpecimenType = new SpecimenType(BO.Application.GenderType.Male);
            ValidateEggs(NewApp);
            Spec2.AddRing(NewClutch.Eggs[0].Rings[0]);

            //...and save it
            NewApp = NewApp.Save();

            //check to see if it picks up the ring from the other app
            NewApp = ValidateEggs(NewApp);

            //make sure there has been validation errors
            Assert.IsNotNull(NewApp.ValidationErrors);

            //tidy up additional app
            RemoveApplication(NewApp.ApplicationId);
        }
Exemplo n.º 11
0
        public Vehicle(agxSDK.Simulation simulation, Dictionary <string, agx.Hinge> wheelHinges)
        {
            m_simulation  = simulation;
            m_wheelHinges = wheelHinges;

            initVehicleParameters();

            initializeDrivetrain();

            Clutch.setEfficiency(1.0);
            Gearbox.setGear(2);

            m_brakes = new Brakes();

            // Initialize the brakes on the wheel hinges
            foreach (var h in m_wheelHinges)
            {
                h.Value.getLock1D().setEnable(false);
                m_brakes.Add(new Brake(h.Value, m_brakeForceRange));
            }
        }
Exemplo n.º 12
0
 protected override void PacketSent(Clutch.Net.UDP.UDPPacketBuffer buffer, int bytesSent)
 {
     MessageWasReceivedEvent("++ Package was sent",new EventArgs());
 }
Exemplo n.º 13
0
        private void LoadMetadata(SpecDB db)
        {
            if (TableName.StartsWith("CAR_NAME_"))
            {
                string locale = TableName.Split('_')[2];
                if (locale.Equals("ALPHABET") || locale.Equals("JAPAN"))
                {
                    locale = "UnistrDB.sdb";
                }
                else
                {
                    locale += "_StrDB.sdb";
                }

                TableMetadata = new CarName(db.SpecDBFolderType, locale);
            }
            else if (TableName.StartsWith("CAR_VARIATION_"))
            {
                string locale = TableName.Split('_')[2];
                if (locale.Equals("ALPHABET") || locale.Equals("JAPAN"))
                {
                    locale = "UnistrDB.sdb";
                }
                else
                {
                    locale += "_StrDB.sdb";
                }
                TableMetadata = new CarVariation(db.SpecDBFolderType, locale);
            }
            else if (TableName.StartsWith("COURSE_NAME_"))
            {
                string locale = TableName.Split('_')[2];
                if (locale.Equals("ALPHABET") || locale.Equals("JAPAN"))
                {
                    locale = "UnistrDB.sdb";
                }
                else
                {
                    locale += "_StrDB.sdb";
                }
                TableMetadata = new CourseName(db.SpecDBFolderType, locale);
            }
            else if (TableName.StartsWith("VARIATION"))
            {
                string locale = "UnistrDB.sdb";
                if (TableName.Length > 9)
                {
                    locale = TableName.Substring(9);
                    if (!locale.Equals("ALPHABET") && !locale.Equals("JAPAN"))
                    {
                        locale += "_StrDB.sdb";
                    }
                }
                TableMetadata = new Variation(db.SpecDBFolderType, locale);
            }
            else if (TableName.StartsWith("RIDER_EQUIPMENT"))
            {
                string locale = "UnistrDB.sdb";
                if (TableName.Length > 15)
                {
                    locale = TableName.Substring(15);
                    if (!locale.Equals("ALPHABET") && !locale.Equals("JAPAN"))
                    {
                        locale += "_StrDB.sdb";
                    }
                }
                TableMetadata = new RiderEquipment(db.SpecDBFolderType, locale);
            }
            else
            {
                switch (TableName)
                {
                case "AIR_CLEANER":
                    TableMetadata = new AirCleaner(db.SpecDBFolderType); break;

                case "ALLOW_ENTRY":
                    TableMetadata = new AllowEntry(db.SpecDBFolderType); break;

                case "ARCADEINFO_NORMAL":
                case "ARCADEINFO_TUNED":
                    TableMetadata = new ArcadeInfoNormal(db.SpecDBFolderType); break;

                case "ASCC":
                    TableMetadata = new ASCC(db.SpecDBFolderType); break;

                case "BRAKE":
                    TableMetadata = new Brake(db.SpecDBFolderType); break;

                case "BRAKECONTROLLER":
                    TableMetadata = new BrakeController(db.SpecDBFolderType); break;

                case "CATALYST":
                    TableMetadata = new Catalyst(db.SpecDBFolderType); break;

                case "CLUTCH":
                    TableMetadata = new Clutch(db.SpecDBFolderType); break;

                case "COMPUTER":
                    TableMetadata = new Computer(db.SpecDBFolderType); break;

                case "COURSE":
                    TableMetadata = new Course(db.SpecDBFolderType); break;

                case "CAR_CUSTOM_INFO":
                    TableMetadata = new CarCustomInfo(db.SpecDBFolderType); break;

                case "DEFAULT_PARAM":
                    TableMetadata = new DefaultParam(db.SpecDBFolderType); break;

                case "DEFAULT_PARTS":
                    TableMetadata = new DefaultParts(db.SpecDBFolderType); break;

                case "DISPLACEMENT":
                    TableMetadata = new Displacement(db.SpecDBFolderType); break;

                case "DRIVETRAIN":
                    TableMetadata = new Drivetrain(db.SpecDBFolderType); break;

                case "ENGINE":
                    TableMetadata = new Engine(db.SpecDBFolderType); break;

                case "EXHAUST_MANIFOLD":
                    TableMetadata = new ExhaustManifold(db.SpecDBFolderType); break;

                case "FLYWHEEL":
                    TableMetadata = new Flywheel(db.SpecDBFolderType); break;

                case "GEAR":
                    TableMetadata = new Gear(db.SpecDBFolderType); break;

                case "MAKER":
                    TableMetadata = new Maker(db.SpecDBFolderType); break;

                case "MODEL_INFO":
                    TableMetadata = new ModelInfo(db.SpecDBFolderType); break;

                case "PAINT_COLOR_INFO":
                    TableMetadata = new PaintColorInfo(db.SpecDBFolderType); break;

                case "GENERIC_CAR":
                    TableMetadata = new GenericCar(db.SpecDBFolderType); break;

                case "FRONTTIRE":
                    TableMetadata = new FrontTire(db.SpecDBFolderType); break;

                case "REARTIRE":
                    TableMetadata = new RearTire(db.SpecDBFolderType); break;

                case "RACINGMODIFY":
                    TableMetadata = new RacingModify(db.SpecDBFolderType); break;

                case "CHASSIS":
                    TableMetadata = new Chassis(db.SpecDBFolderType); break;

                case "INTAKE_MANIFOLD":
                    TableMetadata = new IntakeManifold(db.SpecDBFolderType); break;

                case "LIGHTWEIGHT":
                    TableMetadata = new Lightweight(db.SpecDBFolderType); break;

                case "LSD":
                    TableMetadata = new Lsd(db.SpecDBFolderType); break;

                case "MUFFLER":
                    TableMetadata = new Muffler(db.SpecDBFolderType); break;

                case "NATUNE":
                    TableMetadata = new Natune(db.SpecDBFolderType); break;

                case "NOS":
                    TableMetadata = new NOS(db.SpecDBFolderType); break;

                case "PROPELLERSHAFT":
                    TableMetadata = new PropellerShaft(db.SpecDBFolderType); break;

                case "RACE":
                    TableMetadata = new Race(db.SpecDBFolderType); break;

                case "STEER":
                    TableMetadata = new Steer(db.SpecDBFolderType); break;

                case "SUPERCHARGER":
                    TableMetadata = new Supercharger(db.SpecDBFolderType); break;

                case "SUSPENSION":
                    TableMetadata = new Suspension(db.SpecDBFolderType); break;

                case "TIRECOMPOUND":
                    TableMetadata = new TireCompound(db.SpecDBFolderType); break;

                case "TURBINEKIT":
                    TableMetadata = new TurbineKit(db.SpecDBFolderType); break;

                case "GENERIC_ITEMS":
                    TableMetadata = new GenericItems(db.SpecDBFolderType); break;

                case "TUNED_CARS":
                    TableMetadata = new TunedCars(db.SpecDBFolderType); break;

                case "TUNER":
                    TableMetadata = new Tuner(db.SpecDBFolderType); break;

                case "WHEEL":
                    TableMetadata = new Wheel(db.SpecDBFolderType); break;

                // Unmapped, but havent seen having rows
                case "TCSC":
                    TableMetadata = new TCSC(db.SpecDBFolderType); break;

                case "TIREFORCEVOL":
                    TableMetadata = new TireForceVol(db.SpecDBFolderType); break;

                case "GENERIC_CAR_INFO":
                    TableMetadata = new GenericCarInfo(db.SpecDBFolderType); break;

                case "INDEP_THROTTLE":
                    TableMetadata = new IndepThrottle(db.SpecDBFolderType); break;

                case "INTERCOOLER":
                    TableMetadata = new Intercooler(db.SpecDBFolderType); break;

                case "PORTPOLISH":
                    TableMetadata = new PortPolish(db.SpecDBFolderType); break;

                case "WING":
                    TableMetadata = new Wing(db.SpecDBFolderType); break;

                case "TUNER_LIST":
                    TableMetadata = new TunerList(db.SpecDBFolderType); break;

                case "TIRESIZE":
                    TableMetadata = new TireSize(db.SpecDBFolderType); break;

                case "ENEMY_CARS":
                    TableMetadata = new EnemyCars(db.SpecDBFolderType); break;

                case "ENGINEBALANCE":
                    TableMetadata = new EngineBalance(db.SpecDBFolderType); break;

                case "RIDER_SET_ASSIGN":
                    TableMetadata = new RiderSetAssign(db.SpecDBFolderType); break;

                case "RIDER_SET":
                    TableMetadata = new RiderSet(db.SpecDBFolderType); break;

                default:
                    throw new NotSupportedException($"This table ({TableName}) is not yet mapped.");
                }

                for (int i = 0; i < TableMetadata.Columns.Count; i++)
                {
                    TableMetadata.Columns[i].ColumnIndex = i;
                }
            }
        }
Exemplo n.º 14
0
	void FixedUpdate () 
	{		
		if (clutch==null) {clutch= new Clutch();CalcClutchTorque();}
		
		if (shifter==true) automatic=false;

		ratio = gearRatios[gear]*finalDriveRatio;
		
		if (rpm <= minRPM+maxRPM*0.05f)
			idlethrottle=idlethrottleMinRPMDown*((minRPM+500 - Mathf.Clamp(rpm,minRPM,rpm))*0.002f);
		else 
			idlethrottle=0;

		currentPower=CalcEnginePower(rpm,true,powerMultiplier);
				
		float m_engineInertia=engineInertia*powerMultiplier*externalMultiplier;
		float m_drivetrainInertia=drivetrainInertia*powerMultiplier*externalMultiplier;
		
		velo=Mathf.Abs(myTransform.InverseTransformDirection(body.velocity).z);
						
		if ((rpm >= engageRPM || engaging==true) && autoClutch==true && carController.clutchInput==0 && clutch.GetClutchPosition()!=1 && carController.handbrakeInput==0 && ratio!=0)  {
			EngageClutch();
		}
			
		if ((rpm <= disengageRPM && engaging==false) && autoClutch==true) {
			DisengageClutch();
		}
		
		// execute Gear shifting
		if (changingGear==true) DoGearShifting();
		else lastShiftTime = 0;
			
		// Automatic gear shifting
		if (automatic)
		{
			autoClutch=true;
			if (CanShiftAgain==false){
				TimeToShiftAgain= Mathf.Clamp01((Time.time - ShiftDelay)/(shiftTime + shiftTime/2));
				if (TimeToShiftAgain>=1) {
					CanShiftAgain=true;
				}	
			}
			
			if (changingGear==false){		
				if (rpm >= shiftUpRPM){
					if (gear >= 0 && gear < gearRatios.Length - 1 && Mathf.Abs(slipRatio/idealSlipRatio)<=1 && clutch.GetClutchPosition()!=0 && clutch.speedDiff<50 && engaging==false){
						if (CanShiftAgain==true && OnGround()) {
							if (gearRatios[gear]>0) Shift(gear+1);
							else Shift(gear-1);
						}
						CanShiftAgain=false;
						ShiftDelay = Time.time;	
					}
				}
				else if (rpm <= shiftDownRPM ){
					if (gear !=first && gear!=firstReverse && gear!=neutral && gear > 0 && gear < gearRatios.Length && clutch.GetClutchPosition()!=0 && Mathf.Abs(clutch.speedDiff)<50 && engaging==false) {	// we dont shiftdown if we are in the first gear
						if (CanShiftAgain==true && OnGround()) {
							if (velo<3) { // if speed < 10 km/h we shift directly to the first gear
								Shift(first);
							}
							else{
								if (gearRatios[gear]>0) Shift(gear-1);
								else Shift(gear+1);
							}
							CanShiftAgain=false;
							ShiftDelay= Time.time;	
						}
					}	
				}
			}
		}
				
		float averageWheelsAngularVelo = 0;
		wheelImpulse=0;
		rotationalInertia=0;
		wheelTireVelo=0;
		//TODO to be moved in differential class
		foreach(Wheel w in poweredWheels){
			averageWheelsAngularVelo += w.angularVelocity;
			wheelImpulse+=w.wheelImpulse;
			rotationalInertia+=w.rotationalInertia;
			wheelTireVelo+=w.wheelTireVelo; // used in dashboard to calc actual wheel speed 
		}
		
		averageWheelsAngularVelo*=drivetrainFraction;
		wheelTireVelo*=drivetrainFraction;
		
		float totalRotationalInertia=m_drivetrainInertia+rotationalInertia;
				
		//driveShaftSpeed=averageWheelsAngularVelo*finalDriveRatio;
		// we assume the engine stalled if rpm<20
		if (rpm<20 && startTorque==0) {differentialSpeed=0;wheelImpulse=0;}
		clutchSpeed=differentialSpeed*ratio;
		
		fuel=true;
		if (fuelTanks.Length!=0){
			float velokmh=velo*3.6f;
			// check the fuel consumption...
			float speedFactor=Mathf.Clamp(velokmh,50,velokmh)/fuelConsumptionSpeed; // speed (drag) influece on consumption normalized at fuelConsumptionSpeed (130km/h) (clamped at 50km/h cause at lower speed drag is negligible)
			speedFactor*=speedFactor; // drag force grows with square of speed 
			if (RPMAtSpeedInLastGear!=0) istantConsumption=rpm*throttle*fuelConsumptionAtCostantSpeed/(RPMAtSpeedInLastGear*secondsToCover100Km)*speedFactor;
			if (velo>1) currentConsumption=(istantConsumption/velo)*100000; // velo*0.001f -> km/s ; 100/velo*0.001f -> (1/velo)*100000 seconds taken to travel 100 kms
			else currentConsumption=0;
			fuel=false;
			foreach(FuelTank fuelTank in fuelTanks){
				if (fuelTank.currentFuel!=0) fuel=true;
			}
		}
		torque = CalcEngineTorque(powerMultiplier,rpm)*(throttle + startThrottle)*(fuel?1:0);
		frictionTorque=CalcEngineFrictionTorque(powerMultiplier,rpm);
		startThrottle=0;
		startTorque=0;
		netTorque = torque - frictionTorque;
		if (rpm<20 && startTorque==0) netTorque=0;
		if (rpm<minRPM) startThrottle=1 - rpm/minRPM;
		
		if (startEngine==true && rpm<minRPM &&  Time.time>nextStartImpulse) {
			if (duration==0) duration=Time.time + 0.1f; // duration if start impulse 0.1 secs
			if (Time.time>duration) nextStartImpulse = Time.time + 0.2f; // every 0.2 secs
			startThrottle=1;
			startTorque=idleNetTorque*(fuel?1:0);
		}
		else{
			duration=0;
		}
		netTorqueImpulse = (netTorque+startTorque)*Time.deltaTime;
		
		if (engineAngularVelo >=maxRPM*RPM2angularVelo) {
			if (revLimiterTime==0 && revLimiter==true)
				engineAngularVelo=maxRPM*RPM2angularVelo;
			else
				revLimiterTriggered=true; 
		}
		else if (engineAngularVelo <=minRPM*RPM2angularVelo && canStall==false) {
			engineAngularVelo=minRPM*RPM2angularVelo;
		}
		else if (engineAngularVelo<0) {
			engineAngularVelo=0;
		}
		
		rpm = engineAngularVelo*angularVelo2RPM;
		
		if (ratio == 0 || clutch.GetClutchPosition()==0)
		{
			clutchDragImpulse=0;
			differentialSpeed=averageWheelsAngularVelo;
			if (autoClutch) DisengageClutch();
			
			// Apply torque to car body
			body.AddTorque(-engineOrientation*Mathf.Min(Mathf.Abs(netTorque),2000)*Mathf.Sign(netTorque));
		}
		else //clutch engaged or clutch engaging
		{	
			clutchDragImpulse = clutch.GetDragImpulse(engineAngularVelo, clutchSpeed, m_engineInertia, totalRotationalInertia, ratio,wheelImpulse, netTorqueImpulse);
		}

		engineAngularVelo += (netTorqueImpulse - clutchDragImpulse)/(m_engineInertia);
		differentialSpeed += (wheelImpulse + clutchDragImpulse*ratio)/(totalRotationalInertia);
		if (float.IsNaN(differentialSpeed)) differentialSpeed=0; // to avoid NAN errors with zero powered wheels
		float deltaDifferentialSpeed=differentialSpeed - averageWheelsAngularVelo;
		
		slipRatio = 0;
		idealSlipRatio=0;
		float maxAngVel=maxRPM/(Mathf.Abs(ratio)*angularVelo2RPM);
		foreach(Wheel w in poweredWheels)
		{
			if (revLimiter==true && w.angularVelocity>maxAngVel) w.angularVelocity = maxAngVel;
			lockingTorqueImpulse = (averageWheelsAngularVelo - w.angularVelocity)*differentialLockCoefficient*Time.deltaTime;
			w.drivetrainInertia =  m_drivetrainInertia*ratio*ratio*drivetrainFraction*clutch.GetClutchPosition(); // should be clutch.GetClutchPosition()*(engineInertia + gearInertia[curGear])*Sqr(ratio)
			w.angularVelocity +=deltaDifferentialSpeed;
			w.lockingTorqueImpulse = lockingTorqueImpulse;
			slipRatio += w.slipRatio*drivetrainFraction;
			idealSlipRatio += w.idealSlipRatio*drivetrainFraction;
		}
		
		if (revLimiter==true){
			if (revLimiterTriggered==true) {
				revLimiterReleased=false;
				timer+=Time.deltaTime;
				if (timer >=revLimiterTime) {
					timer=0; 
					revLimiterTriggered=false;
					revLimiterReleased=true;
				}
			}
			else
				revLimiterReleased=false;
		}
		else{
			revLimiterTriggered=false;
			revLimiterReleased=false;
		}
	}
Exemplo n.º 15
0
 protected override void PacketSent(Clutch.Net.UDP.UDPPacketBuffer buffer, int bytesSent)
 {
     //Console.WriteLine("packet sent to {0}",buffer.RemoteEndPoint);
 }
Exemplo n.º 16
0
        public void SimpleConstructorTest()
        {
            Clutch test = new Clutch();

            Assert.IsTrue(test.isFixed());
        }
Exemplo n.º 17
0
        private void udpNetworking_PacketWasReceived(Clutch.Net.UDP.UDPPacketBuffer udpPacketBuffer)
        {
            try
            {
                IPacket packet = PacketTypeChecker.GetPacket(udpPacketBuffer.Data);
                if (PacketReceivedEvent != null)
                    PacketReceivedEvent(packet);
                switch (packet.PacketType)
                {
                    case PacketTypeEnumeration.PingRequest:
                        PingResponsePacket pingResponsePacket = new PingResponsePacket();
                        if (playerIdField.HasValue)
                        {
                            pingResponsePacket.PlayerId = playerIdField.Value;
                            pingResponsePacket.PacketId = packetIdCounter.Next();
                            pingResponsePacket.TimeStamp = DateTime.Now;
                            udpNetworking.SendPacket(pingResponsePacket.ToByte());
                        }
                        break;
                    case PacketTypeEnumeration.StandardServerPacket:
                        bool start = false;
                        if (last10Packeges.LastPacket == null)
                            start = true;
                        else
                        {
                            try
                            {
                                if (last10Packeges.LastPacket.PacketId.Value == packet.PacketId.Value)
                                {
                                    //the same packet - ignore it
                                    Diagnostic.NetworkingDiagnostics.Logging.Warn("Old ServerPacket was received and ignored id" + packet.PacketId);
                                    return;
                                }
                                else if (last10Packeges.LastPacket.PacketId > packet.PacketId)
                                {
                                    // old packet received
                                    Diagnostic.NetworkingDiagnostics.Logging.Warn("Old ServerPacket was received and ignored id" + packet.PacketId);
                                    List<Interfaces.IGameplayEvent> gpEvents = GameEvents.GameEventExtractor.GetGameplayEvents((ServerPacket)packet, null, playerIdField);
                                    lock (gameplayEventListLock)
                                    {
                                        for (int i = 0; i < gpEvents.Count; i++)
                                            gameplayEventList.Add(gpEvents[i]);
                                    }
                                    return;
                                }
                            }
                            catch (Usefull.IdCompareException idEx)
                            {
                                Diagnostic.NetworkingDiagnostics.Logging.Error("Error when comparing id " + packet.PacketId + " with id " + last10Packeges.LastPacket.PacketId, idEx);
                                return;
                            }
                        }

                        List<Interfaces.IGameplayEvent> gameplayEvents = GameEvents.GameEventExtractor.GetGameplayEvents((ServerPacket)packet, (ServerPacket)last10Packeges.LastPacket, playerIdField);
                        lock (gameplayEventListLock)
                        {
                            for (int i = 0; i < gameplayEvents.Count; i++)
                                gameplayEventList.Add(gameplayEvents[i]);
                        }
                        if (start)
                        {
                            lock (gameEventListLock)
                            {
                                gameEventList.Add(new GameEvents.GameStartedEvent());
                            }
                        }
                        last10Packeges.AddPacket(packet);
                        break;
                    case PacketTypeEnumeration.GameInfoPacket:
                        GameInfoPacket gameInfoPacket = (GameInfoPacket)packet;
                        lock (gameInfoPacketsLock)
                        {
                            if (gameInfoPackets.ContainsKey(gameInfoPacket.GameId))
                            {
                                if (gameInfoPackets[gameInfoPacket.GameId].LastPacket.PacketId > packet.PacketId || gameInfoPackets[gameInfoPacket.GameId].LastPacket.PacketId == packet.PacketId)
                                {
                                    Diagnostic.NetworkingDiagnostics.Logging.Warn("Old GameInfoPacket was received and ignored");
                                    return;
                                }
                                gameInfoPackets[gameInfoPacket.GameId].AddPacket(gameInfoPacket);
                            }
                            else
                            {
                                gameInfoPackets.Add(gameInfoPacket.GameId, new UDPClientServerCommons.Usefull.Last10Packages());
                                gameInfoPackets[gameInfoPacket.GameId].AddPacket(gameInfoPacket);
                            }

                            //if this is my game - get events
                            if (gameIdField.HasValue && gameInfoPacket.GameId == gameIdField.Value)
                            {
                                List<IGameEvent> gameEvents = GameEvents.GameEventExtractor.GetGameEvents(gameInfoPacket, (GameInfoPacket)gameInfoPackets[gameIdField.Value].GetPrevious(2), playerIdField);
                                lock (gameInfoPacketsLock)
                                {
                                    for (int i = 0; i < gameEvents.Count; i++)
                                        gameEventList.Add(gameEvents[i]);
                                }
                            }
                        }
                        //if this is my game - update player status'es
                        if (gameIdField.HasValue && gameInfoPacket.GameId == gameIdField)
                        {
                            for (int i = 0; i < gameInfoPacket.PlayerStatusList.Count; i++)
                            {
                                if (gameInfoPacket.PlayerStatusList[i].PlayerName == playerNameField)
                                {
                                    lock (clientPacketLock)
                                    {
                                        playerIdField = gameInfoPacket.PlayerStatusList[i].PlayerId;
                                        teamIdField = gameInfoPacket.PlayerStatusList[i].PlayerTeam;
                                    }
                                    break;
                                }
                            }
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                Diagnostic.NetworkingDiagnostics.Logging.Error("Packet was received", ex);
            }
        }
Exemplo n.º 18
0
 /* Constructs an engine given the sparkplugs and the clutch.
  */
 public Engine(Sparkplugs sparkplugs, Clutch clutch, Oil oil)
 {
     _sparkplugs = sparkplugs;
     _clutch     = clutch;
 }
    void FixedUpdate()
    {
        if (clutch == null)
        {
            clutch = new Clutch(); CalcClutchTorque();
        }

        if (shifter == true)
        {
            automatic = false;
        }

        ratio = gearRatios[gear] * finalDriveRatio;

        if (rpm <= minRPM + maxRPM * 0.05f)
        {
            idlethrottle = idlethrottleMinRPMDown * ((minRPM + 500 - Mathf.Clamp(rpm, minRPM, rpm)) * 0.002f);
        }
        else
        {
            idlethrottle = 0;
        }

        currentPower = CalcEnginePower(rpm, true, powerMultiplier);

        float m_engineInertia     = engineInertia * powerMultiplier * externalMultiplier;
        float m_drivetrainInertia = drivetrainInertia * powerMultiplier * externalMultiplier;

        velo = Mathf.Abs(myTransform.InverseTransformDirection(body.velocity).z);

        if ((rpm >= engageRPM || engaging == true) && autoClutch == true && carController.clutchInput == 0 && clutch.GetClutchPosition() != 1 && carController.handbrakeInput == 0 && ratio != 0)
        {
            EngageClutch();
        }

        if ((rpm <= disengageRPM && engaging == false) && autoClutch == true)
        {
            DisengageClutch();
        }

        // execute Gear shifting
        if (changingGear == true)
        {
            DoGearShifting();
        }
        else
        {
            lastShiftTime = 0;
        }

        // Automatic gear shifting
        if (automatic)
        {
            autoClutch = true;
            if (CanShiftAgain == false)
            {
                TimeToShiftAgain = Mathf.Clamp01((Time.time - ShiftDelay) / (shiftTime + shiftTime / 2));
                if (TimeToShiftAgain >= 1)
                {
                    CanShiftAgain = true;
                }
            }

            if (changingGear == false)
            {
                if (rpm >= shiftUpRPM)
                {
                    if (gear >= 0 && gear < gearRatios.Length - 1 && Mathf.Abs(slipRatio / idealSlipRatio) <= 1 && clutch.GetClutchPosition() != 0 && clutch.speedDiff < 50 && engaging == false)
                    {
                        if (CanShiftAgain == true && OnGround())
                        {
                            if (gearRatios[gear] > 0)
                            {
                                Shift(gear + 1);
                            }
                            else
                            {
                                Shift(gear - 1);
                            }
                        }
                        CanShiftAgain = false;
                        ShiftDelay    = Time.time;
                    }
                }
                else if (rpm <= shiftDownRPM)
                {
                    if (gear != first && gear != firstReverse && gear != neutral && gear > 0 && gear < gearRatios.Length && clutch.GetClutchPosition() != 0 && Mathf.Abs(clutch.speedDiff) < 50 && engaging == false)                   // we dont shiftdown if we are in the first gear
                    {
                        if (CanShiftAgain == true && OnGround())
                        {
                            if (velo < 3)                             // if speed < 10 km/h we shift directly to the first gear
                            {
                                Shift(first);
                            }
                            else
                            {
                                if (gearRatios[gear] > 0)
                                {
                                    Shift(gear - 1);
                                }
                                else
                                {
                                    Shift(gear + 1);
                                }
                            }
                            CanShiftAgain = false;
                            ShiftDelay    = Time.time;
                        }
                    }
                }
            }
        }

        float averageWheelsAngularVelo = 0;

        wheelImpulse      = 0;
        rotationalInertia = 0;
        wheelTireVelo     = 0;
        //TODO to be moved in differential class
        foreach (Wheel w in poweredWheels)
        {
            averageWheelsAngularVelo += w.angularVelocity;
            wheelImpulse             += w.wheelImpulse;
            rotationalInertia        += w.rotationalInertia;
            wheelTireVelo            += w.wheelTireVelo; // used in dashboard to calc actual wheel speed
        }

        averageWheelsAngularVelo *= drivetrainFraction;
        wheelTireVelo            *= drivetrainFraction;

        float totalRotationalInertia = m_drivetrainInertia + rotationalInertia;

        //driveShaftSpeed=averageWheelsAngularVelo*finalDriveRatio;
        // we assume the engine stalled if rpm<20
        if (rpm < 20 && startTorque == 0)
        {
            differentialSpeed = 0; wheelImpulse = 0;
        }
        clutchSpeed = differentialSpeed * ratio;

        fuel = true;
        if (fuelTanks.Length != 0)
        {
            float velokmh = velo * 3.6f;
            // check the fuel consumption...
            float speedFactor = Mathf.Clamp(velokmh, 50, velokmh) / fuelConsumptionSpeed; // speed (drag) influece on consumption normalized at fuelConsumptionSpeed (130km/h) (clamped at 50km/h cause at lower speed drag is negligible)
            speedFactor *= speedFactor;                                                   // drag force grows with square of speed
            if (RPMAtSpeedInLastGear != 0)
            {
                istantConsumption = rpm * throttle * fuelConsumptionAtCostantSpeed / (RPMAtSpeedInLastGear * secondsToCover100Km) * speedFactor;
            }
            if (velo > 1)
            {
                currentConsumption = (istantConsumption / velo) * 100000;               // velo*0.001f -> km/s ; 100/velo*0.001f -> (1/velo)*100000 seconds taken to travel 100 kms
            }
            else
            {
                currentConsumption = 0;
            }
            fuel = false;
            foreach (FuelTank fuelTank in fuelTanks)
            {
                if (fuelTank.currentFuel != 0)
                {
                    fuel = true;
                }
            }
        }
        torque         = CalcEngineTorque(powerMultiplier, rpm) * (throttle + startThrottle) * (fuel?1:0);
        frictionTorque = CalcEngineFrictionTorque(powerMultiplier, rpm);
        startThrottle  = 0;
        startTorque    = 0;
        netTorque      = torque - frictionTorque;
        if (rpm < 20 && startTorque == 0)
        {
            netTorque = 0;
        }
        if (rpm < minRPM)
        {
            startThrottle = 1 - rpm / minRPM;
        }

        if (startEngine == true && rpm < minRPM && Time.time > nextStartImpulse)
        {
            if (duration == 0)
            {
                duration = Time.time + 0.1f;                        // duration if start impulse 0.1 secs
            }
            if (Time.time > duration)
            {
                nextStartImpulse = Time.time + 0.2f;                                 // every 0.2 secs
            }
            startThrottle = 1;
            startTorque   = idleNetTorque * (fuel?1:0);
        }
        else
        {
            duration = 0;
        }
        netTorqueImpulse = (netTorque + startTorque) * Time.deltaTime;

        if (engineAngularVelo >= maxRPM * RPM2angularVelo)
        {
            if (revLimiterTime == 0 && revLimiter == true)
            {
                engineAngularVelo = maxRPM * RPM2angularVelo;
            }
            else
            {
                revLimiterTriggered = true;
            }
        }
        else if (engineAngularVelo <= minRPM * RPM2angularVelo && canStall == false)
        {
            engineAngularVelo = minRPM * RPM2angularVelo;
        }
        else if (engineAngularVelo < 0)
        {
            engineAngularVelo = 0;
        }

        rpm = engineAngularVelo * angularVelo2RPM;

        if (ratio == 0 || clutch.GetClutchPosition() == 0)
        {
            clutchDragImpulse = 0;
            differentialSpeed = averageWheelsAngularVelo;
            if (autoClutch)
            {
                DisengageClutch();
            }

            // Apply torque to car body
            body.AddTorque(-engineOrientation * Mathf.Min(Mathf.Abs(netTorque), 2000) * Mathf.Sign(netTorque));
        }
        else         //clutch engaged or clutch engaging
        {
            clutchDragImpulse = clutch.GetDragImpulse(engineAngularVelo, clutchSpeed, m_engineInertia, totalRotationalInertia, ratio, wheelImpulse, netTorqueImpulse);
        }

        engineAngularVelo += (netTorqueImpulse - clutchDragImpulse) / (m_engineInertia);
        differentialSpeed += (wheelImpulse + clutchDragImpulse * ratio) / (totalRotationalInertia);
        if (float.IsNaN(differentialSpeed))
        {
            differentialSpeed = 0;                                       // to avoid NAN errors with zero powered wheels
        }
        float deltaDifferentialSpeed = differentialSpeed - averageWheelsAngularVelo;

        slipRatio      = 0;
        idealSlipRatio = 0;
        float maxAngVel = maxRPM / (Mathf.Abs(ratio) * angularVelo2RPM);

        foreach (Wheel w in poweredWheels)
        {
            if (revLimiter == true && w.angularVelocity > maxAngVel)
            {
                w.angularVelocity = maxAngVel;
            }
            lockingTorqueImpulse   = (averageWheelsAngularVelo - w.angularVelocity) * differentialLockCoefficient * Time.deltaTime;
            w.drivetrainInertia    = m_drivetrainInertia * ratio * ratio * drivetrainFraction * clutch.GetClutchPosition();   // should be clutch.GetClutchPosition()*(engineInertia + gearInertia[curGear])*Sqr(ratio)
            w.angularVelocity     += deltaDifferentialSpeed;
            w.lockingTorqueImpulse = lockingTorqueImpulse;
            slipRatio      += w.slipRatio * drivetrainFraction;
            idealSlipRatio += w.idealSlipRatio * drivetrainFraction;
        }

        if (revLimiter == true)
        {
            if (revLimiterTriggered == true)
            {
                revLimiterReleased = false;
                timer += Time.deltaTime;
                if (timer >= revLimiterTime)
                {
                    timer = 0;
                    revLimiterTriggered = false;
                    revLimiterReleased  = true;
                }
            }
            else
            {
                revLimiterReleased = false;
            }
        }
        else
        {
            revLimiterTriggered = false;
            revLimiterReleased  = false;
        }
    }
Exemplo n.º 20
0
	void Awake(){
		engineTorqueFromFile=false;
		torqueRPMValuesLen=0;
		body=rigidbody;	
		myTransform=transform;
		clutch = new Clutch();
		carController = GetComponent <CarController>();
		setup= GetComponent <Setup>();
		axles=GetComponent <Axles>();
		fuelTanks=GetComponentsInChildren<FuelTank>();
		poweredWheels=axles.rearAxle.wheels; // to avoid NullReferenceException
	}
Exemplo n.º 21
0
 protected override void PacketReceived(Clutch.Net.UDP.UDPPacketBuffer buffer)
 {
     MessageWasReceivedEvent(buffer, new EventArgs());
 }