39 |
39 |
40 for (u = v; u != NULL; u = u->next) { |
40 for (u = v; u != NULL; u = u->next) { |
41 const RailVehicleInfo *rvi = RailVehInfo(u->engine_type); |
41 const RailVehicleInfo *rvi = RailVehInfo(u->engine_type); |
42 uint16 vweight = 0; |
42 uint16 vweight = 0; |
43 |
43 |
44 // vehicle weight is the sum of the weight of the vehicle and the wait of its cargo |
44 // vehicle weight is the sum of the weight of the vehicle and the weight of its cargo |
45 vweight += rvi->weight; |
45 vweight += rvi->weight; |
46 vweight += (_cargoc.weights[u->cargo_type] * u->cargo_count) / 16; |
46 vweight += (_cargoc.weights[u->cargo_type] * u->cargo_count) / 16; |
|
47 // powered wagons have extra weight added |
|
48 if HASBIT(u->u.rail.flags, VRF_POWEREDWAGON) |
|
49 vweight += RailVehInfo(v->engine_type)->pow_wag_weight; |
47 |
50 |
48 // consist weight is the sum of the weight of all vehicles in the consist |
51 // consist weight is the sum of the weight of all vehicles in the consist |
49 weight += vweight; |
52 weight += vweight; |
50 |
53 |
51 // store vehicle weight in cache |
54 // store vehicle weight in cache |
60 * Recalculates the cached stuff of a train. Should be called each time a vehicle is added to/removed from |
63 * Recalculates the cached stuff of a train. Should be called each time a vehicle is added to/removed from |
61 * the consist, and when the game is loaded. |
64 * the consist, and when the game is loaded. |
62 * @param v First vehicle of the consist. |
65 * @param v First vehicle of the consist. |
63 */ |
66 */ |
64 void TrainConsistChanged(Vehicle *v) { |
67 void TrainConsistChanged(Vehicle *v) { |
|
68 const RailVehicleInfo *rvi_v = RailVehInfo(v->engine_type); |
65 Vehicle *u; |
69 Vehicle *u; |
66 uint16 max_speed = 0xFFFF; |
70 uint16 max_speed = 0xFFFF; |
67 uint32 power = 0; |
71 uint32 power = 0; |
68 |
72 |
69 // recalculate cached weights too |
|
70 TrainCargoChanged(v); |
|
71 |
|
72 for (u = v; u != NULL; u = u->next) { |
73 for (u = v; u != NULL; u = u->next) { |
73 const RailVehicleInfo *rvi = RailVehInfo(u->engine_type); |
74 const RailVehicleInfo *rvi_u = RailVehInfo(u->engine_type); |
74 |
75 |
75 // power is the sum of the powers of all engines in the consist |
76 // power is the sum of the powers of all engines and powered wagons in the consist |
76 power += rvi->power; |
77 power += rvi_u->power; |
77 |
78 |
78 // max speed is the minimun of the speed limits of all vehicles in the consist |
79 // check if its a powered wagon |
79 if (rvi->max_speed != 0) |
80 CLRBIT(u->u.rail.flags, VRF_POWEREDWAGON); |
80 max_speed = min(rvi->max_speed, max_speed); |
81 if ((rvi_v->pow_wag_power != 0) && (rvi_u->flags & RVI_WAGON) && UsesWagonOverride(u)) { |
|
82 uint16 callback; |
|
83 |
|
84 callback = GetCallBackResult(CBID_WAGON_POWER, u->engine_type, u); |
|
85 |
|
86 if (callback == CALLBACK_FAILED) |
|
87 callback = rvi_u->visual_effect; |
|
88 |
|
89 if (callback < 0x40) { |
|
90 /* wagon is powered */ |
|
91 SETBIT(u->u.rail.flags, VRF_POWEREDWAGON); // cache 'powered' status |
|
92 power += rvi_v->pow_wag_power; |
|
93 } |
|
94 } |
|
95 |
|
96 // max speed is the minimum of the speed limits of all vehicles in the consist |
|
97 if (rvi_u->max_speed != 0) |
|
98 max_speed = min(rvi_u->max_speed, max_speed); |
81 }; |
99 }; |
82 |
100 |
83 // store consist weight/max speed in cache |
101 // store consist weight/max speed in cache |
84 v->u.rail.cached_max_speed = max_speed; |
102 v->u.rail.cached_max_speed = max_speed; |
85 v->u.rail.cached_power = power; |
103 v->u.rail.cached_power = power; |
|
104 |
|
105 // recalculate cached weights too (we do this *after* the rest, so it is known which wagons are powered and need extra weight added) |
|
106 TrainCargoChanged(v); |
86 } |
107 } |
87 |
108 |
88 /* These two arrays are used for realistic acceleration. XXX: How should they |
109 /* These two arrays are used for realistic acceleration. XXX: How should they |
89 * be interpreted? */ |
110 * be interpreted? */ |
90 static const byte _curve_neighbours45[8][2] = { |
111 static const byte _curve_neighbours45[8][2] = { |