src/train_cmd.cpp
branchgamebalance
changeset 9910 0b2aebc8283e
parent 9909 dce9a6923bb7
child 9911 0b8b245a2391
--- a/src/train_cmd.cpp	Wed Jun 13 11:00:24 2007 +0000
+++ b/src/train_cmd.cpp	Wed Jun 13 11:17:30 2007 +0000
@@ -63,7 +63,7 @@
  */
 void TrainPowerChanged(Vehicle* v)
 {
-	uint32 power = 0;
+	uint32 total_power = 0;
 	uint32 max_te = 0;
 
 	for (const Vehicle *u = v; u != NULL; u = u->next) {
@@ -76,19 +76,22 @@
 
 		const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type);
 
-		if (engine_has_power && rvi_u->power != 0) {
-			power += rvi_u->power;
-			/* Tractive effort in (tonnes * 1000 * 10 =) N */
-			max_te += (u->u.rail.cached_veh_weight * 10000 * rvi_u->tractive_effort) / 256;
+		if (engine_has_power) {
+			uint16 power = GetVehicleProperty(u, 0x0B, rvi_u->power);
+			if (power != 0) {
+				total_power += power;
+				/* Tractive effort in (tonnes * 1000 * 10 =) N */
+				max_te += (u->u.rail.cached_veh_weight * 10000 * GetVehicleProperty(u, 0x1F, rvi_u->tractive_effort)) / 256;
+			}
 		}
 
 		if (HASBIT(u->u.rail.flags, VRF_POWEREDWAGON) && (wagon_has_power)) {
-			power += RailVehInfo(u->u.rail.first_engine)->pow_wag_power;
+			total_power += RailVehInfo(u->u.rail.first_engine)->pow_wag_power;
 		}
 	}
 
-	if (v->u.rail.cached_power != power || v->u.rail.cached_max_te != max_te) {
-		v->u.rail.cached_power = power;
+	if (v->u.rail.cached_power != total_power || v->u.rail.cached_max_te != max_te) {
+		v->u.rail.cached_power = total_power;
 		v->u.rail.cached_max_te = max_te;
 		InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
 		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
@@ -208,9 +211,10 @@
 			}
 
 			/* max speed is the minimum of the speed limits of all vehicles in the consist */
-			if ((rvi_u->railveh_type != RAILVEH_WAGON || _patches.wagon_speed_limits) &&
-				rvi_u->max_speed != 0 && !UsesWagonOverride(u))
-				max_speed = min(rvi_u->max_speed, max_speed);
+			if ((rvi_u->railveh_type != RAILVEH_WAGON || _patches.wagon_speed_limits) && !UsesWagonOverride(u)) {
+				uint16 speed = GetVehicleProperty(u, 0x09, rvi_u->max_speed);
+				if (speed != 0) max_speed = min(speed, max_speed);
+			}
 		}
 
 		/* check the vehicle length (callback) */
@@ -1981,6 +1985,8 @@
 	if (tfdd.best_length == (uint)-1) return_cmd_error(STR_883A_UNABLE_TO_FIND_ROUTE_TO);
 
 	if (flags & DC_EXEC) {
+		if (v->current_order.type == OT_LOADING) v->LeaveStation();
+
 		v->dest_tile = tfdd.tile;
 		v->current_order.type = OT_GOTO_DEPOT;
 		v->current_order.flags = OF_NON_STOP;
@@ -1989,8 +1995,7 @@
 		v->current_order.refit_cargo = CT_INVALID;
 		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, STATUS_BAR);
 		/* If there is no depot in front, reverse automatically */
-		if (tfdd.reverse)
-			DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
+		if (tfdd.reverse) DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_REVERSE_TRAIN_DIRECTION);
 	}
 
 	return 0;
@@ -2984,7 +2989,7 @@
 						} else if (HasSignalOnTrackdir(gp.new_tile, i)) {
 							v->cur_speed = 0;
 							v->subspeed = 0;
-							v->progress = 255-10;
+							v->progress = 255 - 10;
 							if (++v->load_unload_time_rem < _patches.wait_twoway_signal * 73) {
 								TileIndex o_tile = gp.new_tile + TileOffsByDiagDir(enterdir);
 								VehicleAtSignalData vasd;
@@ -3473,16 +3478,17 @@
 
 	do {
 		const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
-		if (rvi->running_cost_base > 0) {
-			int32 cost_class;
-			switch (rvi->running_cost_class) {
-				default:
-				case 0: cost_class = _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
-				case 1: cost_class = _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
-				case 2: cost_class = _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
-			}
-			cost += rvi->running_cost_base * cost_class;
+
+		byte cost_factor = GetVehicleProperty(v, 0x0D, rvi->running_cost_base);
+		if (cost_factor == 0) continue;
+		switch (rvi->running_cost_class) {
+			default:
+			case 0: cost_factor *= _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
+			case 1: cost_factor *= _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
+			case 2: cost_factor *= _eco->GetPrice(CEconomy::RUNNING_RAIL0); break;
 		}
+		cost += rvi->running_cost_base * cost_factor;
+
 	} while ((v = GetNextVehicle(v)) != NULL);
 
 	return cost;