|
@@ -942,25 +942,25 @@ static void NormaliseTrainConsist(Vehicl
|
|
|
* @param tile unused
|
|
|
* @param p1 various bitstuffed elements
|
|
|
* - p1 (bit 0 - 15) source vehicle index
|
|
|
* - p1 (bit 16 - 31) what wagon to put the source wagon AFTER, XXX - INVALID_VEHICLE to make a new line
|
|
|
* @param p2 (bit 0) move all vehicles following the source vehicle
|
|
|
*/
|
|
|
int32 CmdMoveRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
VehicleID s = GB(p1, 0, 16);
|
|
|
VehicleID d = GB(p1, 16, 16);
|
|
|
Vehicle *src, *dst, *src_head, *dst_head;
|
|
|
|
|
|
if (!IsVehicleIndex(s)) return CMD_ERROR;
|
|
|
if (!IsValidVehicleID(s)) return CMD_ERROR;
|
|
|
|
|
|
src = GetVehicle(s);
|
|
|
|
|
|
if (src->type != VEH_Train) return CMD_ERROR;
|
|
|
|
|
|
// if nothing is selected as destination, try and find a matching vehicle to drag to.
|
|
|
if (d == INVALID_VEHICLE) {
|
|
|
dst = IsTrainEngine(src) ? NULL : FindGoodVehiclePos(src);
|
|
|
} else {
|
|
|
dst = GetVehicle(d);
|
|
|
}
|
|
|
|
|
@@ -1221,25 +1221,25 @@ int32 CmdMoveRailVehicle(TileIndex tile,
|
|
|
}
|
|
|
|
|
|
/** Start/Stop a train.
|
|
|
* @param tile unused
|
|
|
* @param p1 train to start/stop
|
|
|
* @param p2 unused
|
|
|
*/
|
|
|
int32 CmdStartStopTrain(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
Vehicle *v;
|
|
|
uint16 callback;
|
|
|
|
|
|
if (!IsVehicleIndex(p1)) return CMD_ERROR;
|
|
|
if (!IsValidVehicleID(p1)) return CMD_ERROR;
|
|
|
|
|
|
v = GetVehicle(p1);
|
|
|
|
|
|
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
|
|
|
|
|
|
/* Check if this train can be started/stopped. The callback will fail or
|
|
|
* return 0xFF if it can. */
|
|
|
callback = GetVehicleCallback(CBID_VEHICLE_START_STOP_CHECK, 0, 0, v->engine_type, v);
|
|
|
if (callback != CALLBACK_FAILED && callback != 0xFF) {
|
|
|
StringID error = GetGRFStringID(GetEngineGRFID(v->engine_type), 0xD000 + callback);
|
|
|
return_cmd_error(error);
|
|
|
}
|
|
@@ -1266,25 +1266,25 @@ int32 CmdStartStopTrain(TileIndex tile,
|
|
|
* - p2 = 0: only sell the single dragged wagon/engine (and any belonging rear-engines)
|
|
|
* - p2 = 1: sell the vehicle and all vehicles following it in the chain
|
|
|
if the wagon is dragged, don't delete the possibly belonging rear-engine to some front
|
|
|
* - p2 = 2: when selling attached locos, rearrange all vehicles after it to separate lines;
|
|
|
* all wagons of the same type will go on the same line. Used by the AI currently
|
|
|
*/
|
|
|
int32 CmdSellRailWagon(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
Vehicle *v, *tmp, *first;
|
|
|
Vehicle *new_f = NULL;
|
|
|
int32 cost = 0;
|
|
|
|
|
|
if (!IsVehicleIndex(p1) || p2 > 2) return CMD_ERROR;
|
|
|
if (!IsValidVehicleID(p1) || p2 > 2) return CMD_ERROR;
|
|
|
|
|
|
v = GetVehicle(p1);
|
|
|
|
|
|
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_NEW_VEHICLES);
|
|
|
|
|
|
while (IsArticulatedPart(v)) v = GetPrevVehicleInChain(v);
|
|
|
first = GetFirstVehicleInChain(v);
|
|
|
|
|
|
// make sure the vehicle is stopped in the depot
|
|
|
if (CheckTrainStoppedInDepot(first) < 0) {
|
|
@@ -1662,25 +1662,25 @@ static void ReverseTrainDirection(Vehicl
|
|
|
CLRBIT(v->u.rail.flags, VRF_REVERSING);
|
|
|
}
|
|
|
|
|
|
/** Reverse train.
|
|
|
* @param tile unused
|
|
|
* @param p1 train to reverse
|
|
|
* @param p2 if true, reverse a unit in a train (needs to be in a depot)
|
|
|
*/
|
|
|
int32 CmdReverseTrainDirection(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
Vehicle *v;
|
|
|
|
|
|
if (!IsVehicleIndex(p1)) return CMD_ERROR;
|
|
|
if (!IsValidVehicleID(p1)) return CMD_ERROR;
|
|
|
|
|
|
v = GetVehicle(p1);
|
|
|
|
|
|
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
|
|
|
|
|
|
if (p2) {
|
|
|
// turn a single unit around
|
|
|
Vehicle *front;
|
|
|
|
|
|
if (IsMultiheaded(v) || HASBIT(EngInfo(v->engine_type)->callbackmask, CBM_ARTIC_ENGINE)) {
|
|
|
return_cmd_error(STR_ONLY_TURN_SINGLE_UNIT);
|
|
|
}
|
|
@@ -1711,25 +1711,25 @@ int32 CmdReverseTrainDirection(TileIndex
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
/** Force a train through a red signal
|
|
|
* @param tile unused
|
|
|
* @param p1 train to ignore the red signal
|
|
|
* @param p2 unused
|
|
|
*/
|
|
|
int32 CmdForceTrainProceed(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
Vehicle *v;
|
|
|
|
|
|
if (!IsVehicleIndex(p1)) return CMD_ERROR;
|
|
|
if (!IsValidVehicleID(p1)) return CMD_ERROR;
|
|
|
|
|
|
v = GetVehicle(p1);
|
|
|
|
|
|
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
|
|
|
|
|
|
if (flags & DC_EXEC) v->u.rail.force_proceed = 0x50;
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
/** Refits a train to the specified cargo type.
|
|
|
* @param tile unused
|
|
@@ -1737,25 +1737,25 @@ int32 CmdForceTrainProceed(TileIndex til
|
|
|
* param p2 various bitstuffed elements
|
|
|
* - p2 = (bit 0-7) - the new cargo type to refit to
|
|
|
* - p2 = (bit 8-15) - the new cargo subtype to refit to
|
|
|
*/
|
|
|
int32 CmdRefitRailVehicle(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
CargoID new_cid = GB(p2, 0, 8);
|
|
|
byte new_subtype = GB(p2, 8, 8);
|
|
|
Vehicle *v;
|
|
|
int32 cost;
|
|
|
uint num;
|
|
|
|
|
|
if (!IsVehicleIndex(p1)) return CMD_ERROR;
|
|
|
if (!IsValidVehicleID(p1)) return CMD_ERROR;
|
|
|
|
|
|
v = GetVehicle(p1);
|
|
|
|
|
|
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
|
|
|
if (CheckTrainStoppedInDepot(v) < 0) return_cmd_error(STR_TRAIN_MUST_BE_STOPPED);
|
|
|
|
|
|
/* Check cargo */
|
|
|
if (new_cid > NUM_CARGO) return CMD_ERROR;
|
|
|
|
|
|
SET_EXPENSES_TYPE(EXPENSES_TRAIN_RUN);
|
|
|
|
|
|
cost = 0;
|
|
@@ -1921,25 +1921,25 @@ static TrainFindDepotData FindClosestTra
|
|
|
}
|
|
|
|
|
|
/** Send a train to a depot
|
|
|
* @param tile unused
|
|
|
* @param p1 train to send to the depot
|
|
|
* @param p2 unused
|
|
|
*/
|
|
|
int32 CmdSendTrainToDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
|
|
{
|
|
|
Vehicle *v;
|
|
|
TrainFindDepotData tfdd;
|
|
|
|
|
|
if (!IsVehicleIndex(p1)) return CMD_ERROR;
|
|
|
if (!IsValidVehicleID(p1)) return CMD_ERROR;
|
|
|
|
|
|
v = GetVehicle(p1);
|
|
|
|
|
|
if (v->type != VEH_Train || !CheckOwnership(v->owner)) return CMD_ERROR;
|
|
|
|
|
|
if (v->vehstatus & VS_CRASHED) return CMD_ERROR;
|
|
|
|
|
|
if (v->current_order.type == OT_GOTO_DEPOT) {
|
|
|
if (flags & DC_EXEC) {
|
|
|
if (HASBIT(v->current_order.flags, OFB_PART_OF_ORDERS)) {
|
|
|
v->u.rail.days_since_order_progr = 0;
|
|
|
v->cur_order_index++;
|