summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2010-04-17 14:55:49 +0000
committerfrosch <frosch@openttd.org>2010-04-17 14:55:49 +0000
commit2365a4dea0ffa0eac31193c70680368c4774903d (patch)
tree13f3c3eaed24c14c6ec6e8ec589ecf07af9400e5
parent5ecf2f7f8cb157d959c42b3396398f03d3f3fffb (diff)
downloadopenttd-2365a4dea0ffa0eac31193c70680368c4774903d.tar.xz
(svn r19657) -Fix: Add saneness checks for front vehicles.
-rw-r--r--src/order_cmd.cpp24
-rw-r--r--src/vehicle_cmd.cpp6
2 files changed, 15 insertions, 15 deletions
diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp
index 5f0fe4149..25b9162ad 100644
--- a/src/order_cmd.cpp
+++ b/src/order_cmd.cpp
@@ -469,7 +469,7 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
Order new_order(p2);
Vehicle *v = Vehicle::GetIfValid(veh);
- if (v == NULL) return CMD_ERROR;
+ if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
@@ -560,8 +560,6 @@ CommandCost CmdInsertOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
default: return CMD_ERROR;
}
}
- } else {
- if (!IsCompanyBuildableVehicleType(v)) return CMD_ERROR;
}
if (new_order.GetNonStopType() != ONSF_STOP_EVERYWHERE && v->type != VEH_TRAIN && v->type != VEH_ROAD) return CMD_ERROR;
@@ -748,7 +746,7 @@ CommandCost CmdDeleteOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
Vehicle *v = Vehicle::GetIfValid(veh_id);
- if (v == NULL) return CMD_ERROR;
+ if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
@@ -817,7 +815,7 @@ CommandCost CmdSkipToOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
Vehicle *v = Vehicle::GetIfValid(veh_id);
- if (v == NULL || sel_ord == v->cur_order_index || sel_ord >= v->GetNumOrders() || v->GetNumOrders() < 2) return CMD_ERROR;
+ if (v == NULL || !v->IsPrimaryVehicle() || sel_ord == v->cur_order_index || sel_ord >= v->GetNumOrders() || v->GetNumOrders() < 2) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
@@ -857,7 +855,7 @@ CommandCost CmdMoveOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
VehicleOrderID target_order = GB(p2, 16, 16);
Vehicle *v = Vehicle::GetIfValid(veh);
- if (v == NULL) return CMD_ERROR;
+ if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
@@ -940,7 +938,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
if (mof >= MOF_END) return CMD_ERROR;
Vehicle *v = Vehicle::GetIfValid(veh);
- if (v == NULL) return CMD_ERROR;
+ if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
@@ -1166,7 +1164,7 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
VehicleID veh_dst = GB(p1, 0, 16);
Vehicle *dst = Vehicle::GetIfValid(veh_dst);
- if (dst == NULL) return CMD_ERROR;
+ if (dst == NULL || !dst->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(dst->owner);
if (ret.Failed()) return ret;
@@ -1176,7 +1174,7 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
Vehicle *src = Vehicle::GetIfValid(veh_src);
/* Sanity checks */
- if (src == NULL || dst->type != src->type || dst == src) return CMD_ERROR;
+ if (src == NULL || !src->IsPrimaryVehicle() || dst->type != src->type || dst == src) return CMD_ERROR;
CommandCost ret = CheckOwnership(src->owner);
if (ret.Failed()) return ret;
@@ -1218,7 +1216,7 @@ CommandCost CmdCloneOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
Vehicle *src = Vehicle::GetIfValid(veh_src);
/* Sanity checks */
- if (src == NULL || dst->type != src->type || dst == src) return CMD_ERROR;
+ if (src == NULL || !src->IsPrimaryVehicle() || dst->type != src->type || dst == src) return CMD_ERROR;
CommandCost ret = CheckOwnership(src->owner);
if (ret.Failed()) return ret;
@@ -1294,8 +1292,10 @@ CommandCost CmdOrderRefit(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
CargoID cargo = GB(p2, 0, 8);
byte subtype = GB(p2, 8, 8);
+ if (cargo >= NUM_CARGO) return CMD_ERROR;
+
const Vehicle *v = Vehicle::GetIfValid(veh);
- if (v == NULL) return CMD_ERROR;
+ if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
@@ -1450,7 +1450,7 @@ CommandCost CmdRestoreOrderIndex(TileIndex tile, DoCommandFlag flags, uint32 p1,
Vehicle *v = Vehicle::GetIfValid(p1);
/* Check the vehicle type and ownership, and if the service interval and order are in range */
- if (v == NULL) return CMD_ERROR;
+ if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp
index 6a72fbbff..c621ed271 100644
--- a/src/vehicle_cmd.cpp
+++ b/src/vehicle_cmd.cpp
@@ -410,7 +410,7 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
uint32 build_argument = 2;
Vehicle *v = Vehicle::GetIfValid(p1);
- if (v == NULL) return CMD_ERROR;
+ if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
Vehicle *v_front = v;
Vehicle *w = NULL;
Vehicle *w_front = NULL;
@@ -629,7 +629,7 @@ CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool s
CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
Vehicle *v = Vehicle::GetIfValid(p1);
- if (v == NULL) return CMD_ERROR;
+ if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;
@@ -663,7 +663,7 @@ CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uin
CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
Vehicle *v = Vehicle::GetIfValid(p1);
- if (v == NULL) return CMD_ERROR;
+ if (v == NULL || !v->IsPrimaryVehicle()) return CMD_ERROR;
CommandCost ret = CheckOwnership(v->owner);
if (ret.Failed()) return ret;