summaryrefslogtreecommitdiff
path: root/aircraft_cmd.c
diff options
context:
space:
mode:
authorDarkvater <Darkvater@openttd.org>2005-05-14 12:36:16 +0000
committerDarkvater <Darkvater@openttd.org>2005-05-14 12:36:16 +0000
commit7470322a3d0fd1d37ab95ba4625e3bed2ad22f84 (patch)
tree1e61fee7bb3cc51b1847fb0b48b1f3cec7699f5a /aircraft_cmd.c
parent5c8d40bb05a47f9df56296aa3e81f4f70189aeb6 (diff)
downloadopenttd-7470322a3d0fd1d37ab95ba4625e3bed2ad22f84.tar.xz
(svn r2306) - CodeChange: Check the last commands; refits. This needed an extensive rewrite and global/local-cargo ID juggling and bitmasking. However with this done it looks better as well and is compatible with newgrf handling. Big thanks to HackyKid for doing most of the work. This also closes patch "[ 1199277 ] Command checks"
Diffstat (limited to 'aircraft_cmd.c')
-rw-r--r--aircraft_cmd.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/aircraft_cmd.c b/aircraft_cmd.c
index b351fca6f..691005349 100644
--- a/aircraft_cmd.c
+++ b/aircraft_cmd.c
@@ -504,32 +504,38 @@ int32 CmdChangeAircraftServiceInt(int x, int y, uint32 flags, uint32 p1, uint32
return 0;
}
-// p1 = vehicle
-// p2 = new cargo type(0xFF)
-// p2 = skip check for stopped in hanger (0x0100)
+/** Refits an aircraft to the specified cargo type.
+ * @param x,y unused
+ * @param p1 vehicle ID of the aircraft to refit
+ * @param p2 various bitstuffed elements
+ * - p2 = (bit 0-7) - the new cargo type to refit to (p2 & 0xFF)
+ * - p2 = (bit 8) - skip check for stopped in hangar, used by autoreplace (p2 & 0x100)
+ * @todo p2 bit8 check <b>NEEDS TO GO</b>
+ */
int32 CmdRefitAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
- Vehicle *v,*u;
+ Vehicle *v;
int pass, mail;
int32 cost;
- byte SkipStoppedInHangerCheck = (p2 & 0x100) >> 8; //excludes the cargo value
- byte new_cargo_type = p2 & 0xFF; //gets the cargo number
- AircraftVehicleInfo *avi;
+ bool SkipStoppedInHangerCheck = !!HASBIT(p2, 8); // XXX - needs to go, yes?
+ CargoID new_cid = p2 & 0xFF; //gets the cargo number
+ const AircraftVehicleInfo *avi;
if (!IsVehicleIndex(p1)) return CMD_ERROR;
v = GetVehicle(p1);
- if (v->type != VEH_Aircraft) return CMD_ERROR;
+ if (v->type != VEH_Aircraft || !CheckOwnership(v->owner)) return CMD_ERROR;
+ if (!SkipStoppedInHangerCheck && !CheckStoppedInHangar(v)) return_cmd_error(STR_A01B_AIRCRAFT_MUST_BE_STOPPED);
avi = AircraftVehInfo(v->engine_type);
- if (!CheckOwnership(v->owner) || (!CheckStoppedInHangar(v) && !(SkipStoppedInHangerCheck)))
- return CMD_ERROR;
+ /* Check cargo */
+ if (new_cid > NUM_CARGO || !CanRefitTo(v, new_cid)) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_AIRCRAFT_RUN);
- switch (new_cargo_type) {
+ switch (new_cid) {
case CT_PASSENGERS:
pass = avi->passenger_capacity;
break;
@@ -548,24 +554,22 @@ int32 CmdRefitAircraft(int x, int y, uint32 flags, uint32 p1, uint32 p2)
_aircraft_refit_capacity = pass;
cost = 0;
- if (IS_HUMAN_PLAYER(v->owner) && new_cargo_type != v->cargo_type) {
+ if (IS_HUMAN_PLAYER(v->owner) && new_cid != v->cargo_type) {
cost = _price.aircraft_base >> 7;
}
if (flags & DC_EXEC) {
+ Vehicle *u;
v->cargo_cap = pass;
u = v->next;
- mail = avi->mail_capacity;
- if (new_cargo_type != CT_PASSENGERS) {
- mail = 0;
- }
+ mail = (new_cid != CT_PASSENGERS) ? 0 : avi->mail_capacity;
u->cargo_cap = mail;
//autorefitted planes wants to keep the cargo
//it will be checked if the cargo is valid in CmdReplaceVehicle
if (!(SkipStoppedInHangerCheck))
v->cargo_count = u->cargo_count = 0;
- v->cargo_type = new_cargo_type;
+ v->cargo_type = new_cid;
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
}