|
|
@ -283,8 +283,7 @@ CommandCost CmdBuildRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
|
|
|
|
|
|
|
|
|
|
|
/* Call various callbacks after the whole consist has been constructed */
|
|
|
|
/* Call various callbacks after the whole consist has been constructed */
|
|
|
|
for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
|
|
|
|
for (RoadVehicle *u = v; u != NULL; u = u->Next()) {
|
|
|
|
/* Cargo capacity is zero if and only if the vehicle cannot carry anything */
|
|
|
|
u->cargo_cap = GetVehicleCapacity(u);
|
|
|
|
if (u->cargo_cap != 0) u->cargo_cap = GetVehicleProperty(u, PROP_ROADVEH_CARGO_CAPACITY, u->cargo_cap);
|
|
|
|
|
|
|
|
v->InvalidateNewGRFCache();
|
|
|
|
v->InvalidateNewGRFCache();
|
|
|
|
u->InvalidateNewGRFCache();
|
|
|
|
u->InvalidateNewGRFCache();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -2008,7 +2007,6 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
|
|
|
CargoID new_cid = GB(p2, 0, 8);
|
|
|
|
CargoID new_cid = GB(p2, 0, 8);
|
|
|
|
byte new_subtype = GB(p2, 8, 8);
|
|
|
|
byte new_subtype = GB(p2, 8, 8);
|
|
|
|
bool only_this = HasBit(p2, 16);
|
|
|
|
bool only_this = HasBit(p2, 16);
|
|
|
|
uint16 capacity = CALLBACK_FAILED;
|
|
|
|
|
|
|
|
uint total_capacity = 0;
|
|
|
|
uint total_capacity = 0;
|
|
|
|
|
|
|
|
|
|
|
|
RoadVehicle *v = RoadVehicle::GetIfValid(p1);
|
|
|
|
RoadVehicle *v = RoadVehicle::GetIfValid(p1);
|
|
|
@ -2019,6 +2017,7 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
|
|
|
|
|
|
|
|
|
|
|
if (new_cid >= NUM_CARGO) return CMD_ERROR;
|
|
|
|
if (new_cid >= NUM_CARGO) return CMD_ERROR;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v->InvalidateNewGRFCacheOfChain();
|
|
|
|
for (; v != NULL; v = (only_this ? NULL : v->Next())) {
|
|
|
|
for (; v != NULL; v = (only_this ? NULL : v->Next())) {
|
|
|
|
/* XXX: We refit all the attached wagons en-masse if they can be
|
|
|
|
/* XXX: We refit all the attached wagons en-masse if they can be
|
|
|
|
* refitted. This is how TTDPatch does it. TODO: Have some nice
|
|
|
|
* refitted. This is how TTDPatch does it. TODO: Have some nice
|
|
|
@ -2028,43 +2027,17 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
|
|
|
|
const Engine *e = Engine::Get(v->engine_type);
|
|
|
|
const Engine *e = Engine::Get(v->engine_type);
|
|
|
|
if (!e->CanCarryCargo()) continue;
|
|
|
|
if (!e->CanCarryCargo()) continue;
|
|
|
|
|
|
|
|
|
|
|
|
if (HasBit(e->info.callback_mask, CBM_VEHICLE_REFIT_CAPACITY)) {
|
|
|
|
/* Back up the cargo type */
|
|
|
|
/* Back up the cargo type */
|
|
|
|
CargoID temp_cid = v->cargo_type;
|
|
|
|
CargoID temp_cid = v->cargo_type;
|
|
|
|
byte temp_subtype = v->cargo_subtype;
|
|
|
|
byte temp_subtype = v->cargo_subtype;
|
|
|
|
v->cargo_type = new_cid;
|
|
|
|
v->cargo_type = new_cid;
|
|
|
|
v->cargo_subtype = new_subtype;
|
|
|
|
v->cargo_subtype = new_subtype;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Check the refit capacity callback */
|
|
|
|
|
|
|
|
capacity = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Restore the original cargo type */
|
|
|
|
|
|
|
|
v->cargo_type = temp_cid;
|
|
|
|
|
|
|
|
v->cargo_subtype = temp_subtype;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (capacity == CALLBACK_FAILED) {
|
|
|
|
uint capacity = GetVehicleCapacity(v);
|
|
|
|
/* callback failed or not used, use default capacity */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CargoID old_cid = e->GetDefaultCargoType();
|
|
|
|
/* Restore the original cargo type */
|
|
|
|
/* normally, the capacity depends on the cargo type, a vehicle can
|
|
|
|
v->cargo_type = temp_cid;
|
|
|
|
* carry twice as much mail/goods as normal cargo, and four times as
|
|
|
|
v->cargo_subtype = temp_subtype;
|
|
|
|
* many passengers
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
capacity = GetVehicleProperty(v, PROP_ROADVEH_CARGO_CAPACITY, e->u.road.capacity);
|
|
|
|
|
|
|
|
switch (old_cid) {
|
|
|
|
|
|
|
|
case CT_PASSENGERS: break;
|
|
|
|
|
|
|
|
case CT_MAIL:
|
|
|
|
|
|
|
|
case CT_GOODS: capacity *= 2; break;
|
|
|
|
|
|
|
|
default: capacity *= 4; break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (new_cid) {
|
|
|
|
|
|
|
|
case CT_PASSENGERS: break;
|
|
|
|
|
|
|
|
case CT_MAIL:
|
|
|
|
|
|
|
|
case CT_GOODS: capacity /= 2; break;
|
|
|
|
|
|
|
|
default: capacity /= 4; break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
total_capacity += capacity;
|
|
|
|
total_capacity += capacity;
|
|
|
|
|
|
|
|
|
|
|
|