summaryrefslogtreecommitdiff
path: root/src/train_cmd.cpp
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-11-05 23:55:23 +0100
committerMichael Lutz <michi@icosahedron.de>2021-12-16 22:28:32 +0100
commit21675ec7e22bfe53f20300cc27b4d50c84aeb4dc (patch)
treebfc6a1ef650ac6def3b80f86ec8d1a424900f459 /src/train_cmd.cpp
parent2637c06f88ed6f9dea55449883f42a62c30f19d8 (diff)
downloadopenttd-21675ec7e22bfe53f20300cc27b4d50c84aeb4dc.tar.xz
Codechange: Un-bitstuff vehicle/engine commands.
Diffstat (limited to 'src/train_cmd.cpp')
-rw-r--r--src/train_cmd.cpp46
1 files changed, 17 insertions, 29 deletions
diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp
index d2517d65b..8bfc332f6 100644
--- a/src/train_cmd.cpp
+++ b/src/train_cmd.cpp
@@ -656,7 +656,7 @@ static CommandCost CmdBuildRailWagon(DoCommandFlag flags, TileIndex tile, const
w->engine_type == e->index && ///< Same type
w->First() != v && ///< Don't connect to ourself
!(w->vehstatus & VS_CRASHED)) { ///< Not crashed/flooded
- if (Command<CMD_MOVE_RAIL_VEHICLE>::Do(DC_EXEC, 0, v->index | 1 << 20, w->Last()->index, {}).Succeeded()) {
+ if (Command<CMD_MOVE_RAIL_VEHICLE>::Do(DC_EXEC, v->index, w->Last()->index, true).Succeeded()) {
break;
}
}
@@ -672,7 +672,7 @@ static void NormalizeTrainVehInDepot(const Train *u)
for (const Train *v : Train::Iterate()) {
if (v->IsFreeWagon() && v->tile == u->tile &&
v->track == TRACK_BIT_DEPOT) {
- if (Command<CMD_MOVE_RAIL_VEHICLE>::Do(DC_EXEC, 0, v->index | 1 << 20, u->index, {}).Failed()) {
+ if (Command<CMD_MOVE_RAIL_VEHICLE>::Do(DC_EXEC, v->index, u->index, true).Failed()) {
break;
}
}
@@ -1162,21 +1162,14 @@ static void NormaliseTrainHead(Train *head)
* Move a rail vehicle around inside the depot.
* @param flags type of operation
* Note: DC_AUTOREPLACE is set when autoreplace tries to undo its modifications or moves vehicles to temporary locations inside the depot.
- * @param tile unused
- * @param p1 various bitstuffed elements
- * - p1 (bit 0 - 19) source vehicle index
- * - p1 (bit 20) move all vehicles following the source vehicle
- * @param p2 what wagon to put the source wagon AFTER, XXX - INVALID_VEHICLE to make a new line
- * @param text unused
+ * @param src_veh source vehicle index
+ * @param dest_veh what wagon to put the source wagon AFTER, XXX - INVALID_VEHICLE to make a new line
+ * @param move_chain move all vehicles following the source vehicle
* @return the cost of this operation or an error
*/
-CommandCost CmdMoveRailVehicle(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
+CommandCost CmdMoveRailVehicle(DoCommandFlag flags, VehicleID src_veh, VehicleID dest_veh, bool move_chain)
{
- VehicleID s = GB(p1, 0, 20);
- VehicleID d = GB(p2, 0, 20);
- bool move_chain = HasBit(p1, 20);
-
- Train *src = Train::GetIfValid(s);
+ Train *src = Train::GetIfValid(src_veh);
if (src == nullptr) return CMD_ERROR;
CommandCost ret = CheckOwnership(src->owner);
@@ -1187,10 +1180,10 @@ CommandCost CmdMoveRailVehicle(DoCommandFlag flags, TileIndex tile, uint32 p1, u
/* if nothing is selected as destination, try and find a matching vehicle to drag to. */
Train *dst;
- if (d == INVALID_VEHICLE) {
+ if (dest_veh == INVALID_VEHICLE) {
dst = (src->IsEngine() || (flags & DC_AUTOREPLACE)) ? nullptr : FindGoodVehiclePos(src);
} else {
- dst = Train::GetIfValid(d);
+ dst = Train::GetIfValid(dest_veh);
if (dst == nullptr) return CMD_ERROR;
CommandCost ret = CheckOwnership(dst->owner);
@@ -1908,22 +1901,20 @@ void ReverseTrainDirection(Train *v)
/**
* Reverse train.
- * @param tile unused
* @param flags type of operation
- * @param p1 train to reverse
- * @param p2 if true, reverse a unit in a train (needs to be in a depot)
- * @param text unused
+ * @param veh_id train to reverse
+ * @param reverse_single_veh if true, reverse a unit in a train (needs to be in a depot)
* @return the cost of this operation or an error
*/
-CommandCost CmdReverseTrainDirection(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
+CommandCost CmdReverseTrainDirection(DoCommandFlag flags, VehicleID veh_id, bool reverse_single_veh)
{
- Train *v = Train::GetIfValid(p1);
+ Train *v = Train::GetIfValid(veh_id);
if (v == nullptr) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
- if (p2 != 0) {
+ if (reverse_single_veh) {
/* turn a single unit around */
if (v->IsMultiheaded() || HasBit(EngInfo(v->engine_type)->callback_mask, CBM_VEHICLE_ARTIC_ENGINE)) {
@@ -1982,15 +1973,12 @@ CommandCost CmdReverseTrainDirection(DoCommandFlag flags, TileIndex tile, uint32
/**
* Force a train through a red signal
* @param flags type of operation
- * @param tile unused
- * @param p1 train to ignore the red signal
- * @param p2 unused
- * @param text unused
+ * @param veh_id train to ignore the red signal
* @return the cost of this operation or an error
*/
-CommandCost CmdForceTrainProceed(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
+CommandCost CmdForceTrainProceed(DoCommandFlag flags, VehicleID veh_id)
{
- Train *t = Train::GetIfValid(p1);
+ Train *t = Train::GetIfValid(veh_id);
if (t == nullptr) return CMD_ERROR;
if (!t->IsPrimaryVehicle()) return CMD_ERROR;