train_cmd.c
changeset 4434 4175805666a5
parent 4432 33631ac88c40
child 4451 66603f0f732e
equal deleted inserted replaced
4433:2ee8e92ef389 4434:4175805666a5
    93 
    93 
    94 		if (IsBridgeTile(u->tile) && IsBridgeMiddle(u->tile) && DiagDirToAxis(DirToDiagDir(u->direction)) == GetBridgeAxis(u->tile)) {
    94 		if (IsBridgeTile(u->tile) && IsBridgeMiddle(u->tile) && DiagDirToAxis(DirToDiagDir(u->direction)) == GetBridgeAxis(u->tile)) {
    95 			if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeOnBridge(u->tile))) engine_has_power = false;
    95 			if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeOnBridge(u->tile))) engine_has_power = false;
    96 			if (!HasPowerOnRail(v->u.rail.railtype, GetRailTypeOnBridge(u->tile))) wagon_has_power = false;
    96 			if (!HasPowerOnRail(v->u.rail.railtype, GetRailTypeOnBridge(u->tile))) wagon_has_power = false;
    97 		} else if (IsLevelCrossingTile(u->tile)) {
    97 		} else if (IsLevelCrossingTile(u->tile)) {
    98 			if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeCrossing(u->tile)))	engine_has_power = false;
    98 			if (!HasPowerOnRail(u->u.rail.railtype, GetRailTypeCrossing(u->tile))) engine_has_power = false;
    99 			if (!HasPowerOnRail(v->u.rail.railtype, GetRailTypeCrossing(u->tile)))	wagon_has_power = false;
    99 			if (!HasPowerOnRail(v->u.rail.railtype, GetRailTypeCrossing(u->tile))) wagon_has_power = false;
   100 		} else {
   100 		} else {
   101 			if (!HasPowerOnRail(u->u.rail.railtype, GetRailType(u->tile))) engine_has_power = false;
   101 			if (!HasPowerOnRail(u->u.rail.railtype, GetRailType(u->tile))) engine_has_power = false;
   102 			if (!HasPowerOnRail(v->u.rail.railtype, GetRailType(u->tile))) wagon_has_power = false;
   102 			if (!HasPowerOnRail(v->u.rail.railtype, GetRailType(u->tile))) wagon_has_power = false;
   103 		}
   103 		}
   104 
   104 
   269 
   269 
   270 //new acceleration
   270 //new acceleration
   271 static int GetTrainAcceleration(Vehicle *v, bool mode)
   271 static int GetTrainAcceleration(Vehicle *v, bool mode)
   272 {
   272 {
   273 	const Vehicle *u;
   273 	const Vehicle *u;
   274 	int num = 0;	//number of vehicles, change this into the number of axles later
   274 	int num = 0; //number of vehicles, change this into the number of axles later
   275 	int power = 0;
   275 	int power = 0;
   276 	int mass = 0;
   276 	int mass = 0;
   277 	int max_speed = 2000;
   277 	int max_speed = 2000;
   278 	int area = 120;
   278 	int area = 120;
   279 	int friction = 35; //[1e-3]
   279 	int friction = 35; //[1e-3]
   280 	int drag_coeff = 20;	//[1e-4]
   280 	int drag_coeff = 20; //[1e-4]
   281 	int incl = 0;
   281 	int incl = 0;
   282 	int resistance;
   282 	int resistance;
   283 	int speed = v->cur_speed; //[mph]
   283 	int speed = v->cur_speed; //[mph]
   284 	int force = 0x3FFFFFFF;
   284 	int force = 0x3FFFFFFF;
   285 	int pos = 0;
   285 	int pos = 0;
   356 		drag_coeff += 3;
   356 		drag_coeff += 3;
   357 
   357 
   358 		if (u->u.rail.track == 0x80) max_speed = min(max_speed, 61);
   358 		if (u->u.rail.track == 0x80) max_speed = min(max_speed, 61);
   359 
   359 
   360 		if (HASBIT(u->u.rail.flags, VRF_GOINGUP)) {
   360 		if (HASBIT(u->u.rail.flags, VRF_GOINGUP)) {
   361 			incl += u->u.rail.cached_veh_weight * 60;		//3% slope, quite a bit actually
   361 			incl += u->u.rail.cached_veh_weight * 60; //3% slope, quite a bit actually
   362 		} else if (HASBIT(u->u.rail.flags, VRF_GOINGDOWN)) {
   362 		} else if (HASBIT(u->u.rail.flags, VRF_GOINGDOWN)) {
   363 			incl -= u->u.rail.cached_veh_weight * 60;
   363 			incl -= u->u.rail.cached_veh_weight * 60;
   364 		}
   364 		}
   365 	}
   365 	}
   366 
   366 
   808 			}
   808 			}
   809 
   809 
   810 			TrainConsistChanged(v);
   810 			TrainConsistChanged(v);
   811 			UpdateTrainAcceleration(v);
   811 			UpdateTrainAcceleration(v);
   812 
   812 
   813 			if (!HASBIT(p2, 1)) {	// check if the cars should be added to the new vehicle
   813 			if (!HASBIT(p2, 1)) { // check if the cars should be added to the new vehicle
   814 				NormalizeTrainVehInDepot(v);
   814 				NormalizeTrainVehInDepot(v);
   815 			}
   815 			}
   816 
   816 
   817 			InvalidateWindow(WC_VEHICLE_DEPOT, tile);
   817 			InvalidateWindow(WC_VEHICLE_DEPOT, tile);
   818 			RebuildVehicleLists();
   818 			RebuildVehicleLists();
  1181 		/* If there is an engine behind first_engine we moved away, it should become new first_engine
  1181 		/* If there is an engine behind first_engine we moved away, it should become new first_engine
  1182 		 * To do this, CmdMoveRailVehicle must be called once more
  1182 		 * To do this, CmdMoveRailVehicle must be called once more
  1183 		 * we can't loop forever here because next time we reach this line we will have a front engine */
  1183 		 * we can't loop forever here because next time we reach this line we will have a front engine */
  1184 		if (src_head != NULL && !IsFrontEngine(src_head) && IsTrainEngine(src_head)) {
  1184 		if (src_head != NULL && !IsFrontEngine(src_head) && IsTrainEngine(src_head)) {
  1185 			CmdMoveRailVehicle(0, flags, src_head->index | (INVALID_VEHICLE << 16), 1);
  1185 			CmdMoveRailVehicle(0, flags, src_head->index | (INVALID_VEHICLE << 16), 1);
  1186 			src_head = NULL;	// don't do anything more to this train since the new call will do it
  1186 			src_head = NULL; // don't do anything more to this train since the new call will do it
  1187 		}
  1187 		}
  1188 
  1188 
  1189 		if (src_head != NULL) {
  1189 		if (src_head != NULL) {
  1190 			NormaliseTrainConsist(src_head);
  1190 			NormaliseTrainConsist(src_head);
  1191 			TrainConsistChanged(src_head);
  1191 			TrainConsistChanged(src_head);
  3668 void ConvertOldMultiheadToNew(void)
  3668 void ConvertOldMultiheadToNew(void)
  3669 {
  3669 {
  3670 	Vehicle *v;
  3670 	Vehicle *v;
  3671 	FOR_ALL_VEHICLES(v) {
  3671 	FOR_ALL_VEHICLES(v) {
  3672 		if (v->type == VEH_Train) {
  3672 		if (v->type == VEH_Train) {
  3673 			SETBIT(v->subtype, 7);	// indicates that it's the old format and needs to be converted in the next loop
  3673 			SETBIT(v->subtype, 7); // indicates that it's the old format and needs to be converted in the next loop
  3674 		}
  3674 		}
  3675 	}
  3675 	}
  3676 
  3676 
  3677 	FOR_ALL_VEHICLES(v) {
  3677 	FOR_ALL_VEHICLES(v) {
  3678 		if (v->type == VEH_Train) {
  3678 		if (v->type == VEH_Train) {
  3682 				BEGIN_ENUM_WAGONS(u) {
  3682 				BEGIN_ENUM_WAGONS(u) {
  3683 					const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
  3683 					const RailVehicleInfo *rvi = RailVehInfo(u->engine_type);
  3684 
  3684 
  3685 					CLRBIT(u->subtype, 7);
  3685 					CLRBIT(u->subtype, 7);
  3686 					switch (u->subtype) {
  3686 					switch (u->subtype) {
  3687 						case 0:	/* TS_Front_Engine */
  3687 						case 0: /* TS_Front_Engine */
  3688 							if (rvi->flags & RVI_MULTIHEAD) SetMultiheaded(u);
  3688 							if (rvi->flags & RVI_MULTIHEAD) SetMultiheaded(u);
  3689 							SetFrontEngine(u);
  3689 							SetFrontEngine(u);
  3690 							SetTrainEngine(u);
  3690 							SetTrainEngine(u);
  3691 							break;
  3691 							break;
  3692 
  3692 
  3693 						case 1:	/* TS_Artic_Part */
  3693 						case 1: /* TS_Artic_Part */
  3694 							u->subtype = 0;
  3694 							u->subtype = 0;
  3695 							SetArticulatedPart(u);
  3695 							SetArticulatedPart(u);
  3696 							break;
  3696 							break;
  3697 
  3697 
  3698 						case 2:	/* TS_Not_First */
  3698 						case 2: /* TS_Not_First */
  3699 							u->subtype = 0;
  3699 							u->subtype = 0;
  3700 							if (rvi->flags & RVI_WAGON) {
  3700 							if (rvi->flags & RVI_WAGON) {
  3701 								// normal wagon
  3701 								// normal wagon
  3702 								SetTrainWagon(u);
  3702 								SetTrainWagon(u);
  3703 								break;
  3703 								break;
  3709 							}
  3709 							}
  3710 							if (rvi->flags & RVI_MULTIHEAD) SetMultiheaded(u);
  3710 							if (rvi->flags & RVI_MULTIHEAD) SetMultiheaded(u);
  3711 							SetTrainEngine(u);
  3711 							SetTrainEngine(u);
  3712 							break;
  3712 							break;
  3713 
  3713 
  3714 						case 4:	/* TS_Free_Car */
  3714 						case 4: /* TS_Free_Car */
  3715 							u->subtype = 0;
  3715 							u->subtype = 0;
  3716 							SetTrainWagon(u);
  3716 							SetTrainWagon(u);
  3717 							SetFreeWagon(u);
  3717 							SetFreeWagon(u);
  3718 							break;
  3718 							break;
  3719 						default: NOT_REACHED(); break;
  3719 						default: NOT_REACHED(); break;