src/aircraft_cmd.cpp
changeset 6986 168d3add1f13
parent 6949 72d11a1e1e60
child 6991 dafa5a916340
equal deleted inserted replaced
6985:6fd300b20503 6986:168d3add1f13
   391 		u->random_bits = VehicleRandomBits();
   391 		u->random_bits = VehicleRandomBits();
   392 
   392 
   393 		v->vehicle_flags = 0;
   393 		v->vehicle_flags = 0;
   394 		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SETBIT(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
   394 		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) SETBIT(v->vehicle_flags, VF_BUILT_AS_PROTOTYPE);
   395 
   395 
       
   396 		UpdateAircraftCache(v);
       
   397 
   396 		VehiclePositionChanged(v);
   398 		VehiclePositionChanged(v);
   397 		VehiclePositionChanged(u);
   399 		VehiclePositionChanged(u);
   398 
   400 
   399 		/* Aircraft with 3 vehicles (chopper)? */
   401 		/* Aircraft with 3 vehicles (chopper)? */
   400 		if (v->subtype == AIR_HELICOPTER) {
   402 		if (v->subtype == AIR_HELICOPTER) {
   860 	if (!PlayVehicleSound(v, VSE_START)) {
   862 	if (!PlayVehicleSound(v, VSE_START)) {
   861 		SndPlayVehicleFx(AircraftVehInfo(v->engine_type)->sfx, v);
   863 		SndPlayVehicleFx(AircraftVehInfo(v->engine_type)->sfx, v);
   862 	}
   864 	}
   863 }
   865 }
   864 
   866 
       
   867 
       
   868 void UpdateAircraftCache(Vehicle *v)
       
   869 {
       
   870 	uint max_speed = GetVehicleProperty(v, 0x0C, 0);
       
   871 	if (max_speed != 0) {
       
   872 		/* Convert from original units to (approx) km/h */
       
   873 		max_speed = (max_speed * 129) / 10;
       
   874 
       
   875 		v->u.air.cached_max_speed = max_speed;
       
   876 	} else {
       
   877 		v->u.air.cached_max_speed = 0xFFFF;
       
   878 	}
       
   879 }
       
   880 
       
   881 
   865 /**
   882 /**
   866  * Special velocities for aircraft
   883  * Special velocities for aircraft
   867  */
   884  */
   868 enum AircraftSpeedLimits {
   885 enum AircraftSpeedLimits {
   869 	SPEED_LIMIT_TAXI     =     50,  ///< Maximum speed of an aircraft while taxiing
   886 	SPEED_LIMIT_TAXI     =     50,  ///< Maximum speed of an aircraft while taxiing
   882  */
   899  */
   883 static int UpdateAircraftSpeed(Vehicle *v, uint speed_limit = SPEED_LIMIT_NONE, bool hard_limit = true)
   900 static int UpdateAircraftSpeed(Vehicle *v, uint speed_limit = SPEED_LIMIT_NONE, bool hard_limit = true)
   884 {
   901 {
   885 	uint spd = v->acceleration * 16;
   902 	uint spd = v->acceleration * 16;
   886 	byte t;
   903 	byte t;
       
   904 
       
   905 	if (v->u.air.cached_max_speed < speed_limit) {
       
   906 		if (v->cur_speed < speed_limit) hard_limit = false;
       
   907 		speed_limit = v->u.air.cached_max_speed;
       
   908 	}
   887 
   909 
   888 	speed_limit = min(speed_limit, v->max_speed);
   910 	speed_limit = min(speed_limit, v->max_speed);
   889 
   911 
   890 	v->subspeed = (t=v->subspeed) + (byte)spd;
   912 	v->subspeed = (t=v->subspeed) + (byte)spd;
   891 
   913 
  1854 
  1876 
  1855 	const AirportFTA *current = &apc->layout[v->u.air.pos];
  1877 	const AirportFTA *current = &apc->layout[v->u.air.pos];
  1856 	/* we have arrived in an important state (eg terminal, hangar, etc.) */
  1878 	/* we have arrived in an important state (eg terminal, hangar, etc.) */
  1857 	if (current->heading == v->u.air.state) {
  1879 	if (current->heading == v->u.air.state) {
  1858 		byte prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand
  1880 		byte prev_pos = v->u.air.pos; // location could be changed in state, so save it before-hand
       
  1881 		byte prev_state = v->u.air.state;
  1859 		_aircraft_state_handlers[v->u.air.state](v, apc);
  1882 		_aircraft_state_handlers[v->u.air.state](v, apc);
  1860 		if (v->u.air.state != FLYING) v->u.air.previous_pos = prev_pos;
  1883 		if (v->u.air.state != FLYING) v->u.air.previous_pos = prev_pos;
       
  1884 		if (v->u.air.state != prev_state) UpdateAircraftCache(v);
  1861 		return true;
  1885 		return true;
  1862 	}
  1886 	}
  1863 
  1887 
  1864 	v->u.air.previous_pos = v->u.air.pos; // save previous location
  1888 	v->u.air.previous_pos = v->u.air.pos; // save previous location
  1865 
  1889