mirror of https://github.com/OpenTTD/OpenTTD
(svn r10811) -Fix (r10097): Refit all the parts of an articulated road vehicle, not just the first part.
parent
a43370bf1c
commit
8c4a4baac1
|
@ -2009,7 +2009,7 @@ void RoadVehiclesYearlyLoop()
|
|||
* @param p2 Bitstuffed elements
|
||||
* - p2 = (bit 0-7) - the new cargo type to refit to
|
||||
* - p2 = (bit 8-15) - the new cargo subtype to refit to
|
||||
* - p2 = (bit 16) - refit only this vehicle (ignored)
|
||||
* - p2 = (bit 16) - refit only this vehicle
|
||||
* @return cost of refit or error
|
||||
*/
|
||||
CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
||||
|
@ -2018,7 +2018,9 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
CommandCost cost;
|
||||
CargoID new_cid = GB(p2, 0, 8);
|
||||
byte new_subtype = GB(p2, 8, 8);
|
||||
bool only_this = HASBIT(p2, 16);
|
||||
uint16 capacity = CALLBACK_FAILED;
|
||||
uint total_capacity = 0;
|
||||
|
||||
if (!IsValidVehicleID(p1)) return CMD_ERROR;
|
||||
|
||||
|
@ -2027,10 +2029,18 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
if (v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR;
|
||||
if (!CheckRoadVehInDepotStopped(v)) return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE);
|
||||
|
||||
if (new_cid >= NUM_CARGO || !CanRefitTo(v->engine_type, new_cid)) return CMD_ERROR;
|
||||
if (new_cid >= NUM_CARGO) return CMD_ERROR;
|
||||
|
||||
SET_EXPENSES_TYPE(EXPENSES_ROADVEH_RUN);
|
||||
|
||||
for (; v != NULL; v = v->next) {
|
||||
/* XXX: We refit all the attached wagons en-masse if they can be
|
||||
* refitted. This is how TTDPatch does it. TODO: Have some nice
|
||||
* [Refit] button near each wagon. */
|
||||
if (!CanRefitTo(v->engine_type, new_cid)) continue;
|
||||
|
||||
if (v->cargo_cap == 0) continue;
|
||||
|
||||
if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) {
|
||||
/* Back up the cargo type */
|
||||
CargoID temp_cid = v->cargo_type;
|
||||
|
@ -2069,10 +2079,13 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
default: capacity /= 4; break;
|
||||
}
|
||||
}
|
||||
_returned_refit_capacity = capacity;
|
||||
|
||||
if (capacity == 0) continue;
|
||||
|
||||
total_capacity += capacity;
|
||||
|
||||
if (IsHumanPlayer(v->owner) && new_cid != v->cargo_type) {
|
||||
cost = GetRefitCost(v->engine_type);
|
||||
cost.AddCost(GetRefitCost(v->engine_type));
|
||||
}
|
||||
|
||||
if (flags & DC_EXEC) {
|
||||
|
@ -2085,5 +2098,10 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|||
RebuildVehicleLists();
|
||||
}
|
||||
|
||||
if (only_this) break;
|
||||
}
|
||||
|
||||
_returned_refit_capacity = total_capacity;
|
||||
|
||||
return cost;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue