summaryrefslogtreecommitdiff
path: root/ship_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
commit5174d3adfe9e3b120fd2c50847c7f9cf772a702b (patch)
tree1e61fee7bb3cc51b1847fb0b48b1f3cec7699f5a /ship_cmd.c
parent3a4bedaad61c990c511cd1c23380546a9eebd358 (diff)
downloadopenttd-5174d3adfe9e3b120fd2c50847c7f9cf772a702b.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 'ship_cmd.c')
-rw-r--r--ship_cmd.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/ship_cmd.c b/ship_cmd.c
index 24d21fc47..b8190d6b7 100644
--- a/ship_cmd.c
+++ b/ship_cmd.c
@@ -1067,36 +1067,39 @@ int32 CmdChangeShipServiceInt(int x, int y, uint32 flags, uint32 p1, uint32 p2)
return 0;
}
-
-// p1 = vehicle
-// p2 = new cargo (0xFF)
-// p2 = skip check for stopped in hanger (0x0100)
+/** Refits a ship to the specified cargo type.
+ * @param x,y unused
+ * @param p1 vehicle ID of the ship 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 depot, used by autoreplace (p2 & 0x100)
+ * @todo p2 bit8 check <b>NEEDS TO GO</b>
+ */
int32 CmdRefitShip(int x, int y, uint32 flags, uint32 p1, uint32 p2)
{
Vehicle *v;
int32 cost;
- byte SkipStoppedInDepotCheck = (p2 & 0x100) >> 8; //excludes the cargo value
-
- p2 = p2 & 0xFF;
+ CargoID new_cid = p2 & 0xFF; //gets the cargo number
+ bool SkipStoppedInDepotCheck = !!HASBIT(p2, 8); // XXX - needs to go, yes?
if (!IsVehicleIndex(p1)) return CMD_ERROR;
v = GetVehicle(p1);
- if (v->type != VEH_Ship || !CheckOwnership(v->owner))
- return CMD_ERROR;
-
- if (!( SkipStoppedInDepotCheck )) {
- if (!IsTileDepotType(v->tile, TRANSPORT_WATER) ||
- !(v->vehstatus&VS_STOPPED) ||
- v->u.ship.state != 0x80)
+ if (v->type != VEH_Ship || !CheckOwnership(v->owner)) return CMD_ERROR;
+ if (!SkipStoppedInDepotCheck) {
+ if (!IsTileDepotType(v->tile, TRANSPORT_WATER) || !(v->vehstatus&VS_STOPPED) || v->u.ship.state != 0x80)
return_cmd_error(STR_980B_SHIP_MUST_BE_STOPPED_IN);
- }
+ }
+
+ /* Check cargo */
+ if (!ShipVehInfo(v->engine_type)->refittable) return CMD_ERROR;
+ if (new_cid > NUM_CARGO || !CanRefitTo(v, new_cid)) return CMD_ERROR;
SET_EXPENSES_TYPE(EXPENSES_SHIP_RUN);
cost = 0;
- if (IS_HUMAN_PLAYER(v->owner) && (byte)p2 != v->cargo_type) {
+ if (IS_HUMAN_PLAYER(v->owner) && new_cid != v->cargo_type) {
cost = _price.ship_base >> 7;
}
@@ -1105,12 +1108,10 @@ int32 CmdRefitShip(int x, int y, uint32 flags, uint32 p1, uint32 p2)
//it will be checked if the cargo is valid in CmdRenewVehicle
if (!(SkipStoppedInDepotCheck))
v->cargo_count = 0;
- v->cargo_type = (byte)p2;
+ v->cargo_type = new_cid;
InvalidateWindow(WC_VEHICLE_DETAILS, v->index);
}
return cost;
}
-
-