summaryrefslogtreecommitdiff
path: root/aircraft_cmd.c
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-06-07 07:33:56 +0000
committerpeter1138 <peter1138@openttd.org>2006-06-07 07:33:56 +0000
commiteade3d07b5d99b0bbbf2de7d123babb6d05d1722 (patch)
tree803d7b6b3bcd709990e7ce7573490cf76aee077e /aircraft_cmd.c
parent8c9de5e5932465575351f3722d72aac3c13682b1 (diff)
downloadopenttd-eade3d07b5d99b0bbbf2de7d123babb6d05d1722.tar.xz
(svn r5147) - NewGRF: Use refit capacity callback when refitting an aircraft (mart3p)
Diffstat (limited to 'aircraft_cmd.c')
-rw-r--r--aircraft_cmd.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/aircraft_cmd.c b/aircraft_cmd.c
index 2ef5b0c6f..1729dcdbe 100644
--- a/aircraft_cmd.c
+++ b/aircraft_cmd.c
@@ -544,6 +544,7 @@ int32 CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
CargoID new_cid = GB(p2, 0, 8);
byte new_subtype = GB(p2, 8, 8);
const AircraftVehicleInfo *avi;
+ uint16 callback = CALLBACK_FAILED;
if (!IsVehicleIndex(p1)) return CMD_ERROR;
@@ -559,21 +560,24 @@ int32 CmdRefitAircraft(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN);
- switch (new_cid) {
- case CT_PASSENGERS:
- pass = avi->passenger_capacity;
- break;
- case CT_MAIL:
- pass = avi->passenger_capacity + avi->mail_capacity;
- break;
- case CT_GOODS:
- pass = avi->passenger_capacity + avi->mail_capacity;
- pass /= 2;
- break;
- default:
- pass = avi->passenger_capacity + avi->mail_capacity;
- pass /= 4;
- break;
+ /* Check the refit capacity callback */
+ if (HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_REFIT_CAPACITY)) {
+ /* Back up the existing cargo type */
+ CargoID temp_cid = v->cargo_type;
+ v->cargo_type = new_cid;
+
+ callback = GetVehicleCallback(CBID_VEHICLE_REFIT_CAPACITY, 0, 0, v->engine_type, v);
+
+ /* Restore the cargo type */
+ v->cargo_type = temp_cid;
+ }
+
+ if (callback == CALLBACK_FAILED) {
+ /* If the callback failed, or wasn't executed, use the aircraft's
+ * default cargo capacity */
+ pass = AircraftDefaultCargoCapacity(new_cid, v->engine_type);
+ } else {
+ pass = callback;
}
_returned_refit_capacity = pass;