diff options
author | smatz <smatz@openttd.org> | 2009-05-18 16:21:28 +0000 |
---|---|---|
committer | smatz <smatz@openttd.org> | 2009-05-18 16:21:28 +0000 |
commit | 8808f3beea881af5652716c883a21c8031b5e390 (patch) | |
tree | bc14c65d1e66c407b72d254fc926d105eea2f1e4 /src/vehicle_cmd.cpp | |
parent | 5fe906e14992f7a301ae94c357e80af076ab7a63 (diff) | |
download | openttd-8808f3beea881af5652716c883a21c8031b5e390.tar.xz |
(svn r16352) -Codechange: use PoolItem::GetIfValid() instead of PoolItem::IsValidID() and PoolItem::Get()
Diffstat (limited to 'src/vehicle_cmd.cpp')
-rw-r--r-- | src/vehicle_cmd.cpp | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/src/vehicle_cmd.cpp b/src/vehicle_cmd.cpp index 72e1df6d2..5a78c747c 100644 --- a/src/vehicle_cmd.cpp +++ b/src/vehicle_cmd.cpp @@ -61,12 +61,8 @@ CommandCost CmdStartStopVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, /* Disable the effect of p2 bit 0, when DC_AUTOREPLACE is not set */ if ((flags & DC_AUTOREPLACE) == 0) SetBit(p2, 0); - if (!Vehicle::IsValidID(p1)) return CMD_ERROR; - - Vehicle *v = Vehicle::Get(p1); - - if (!CheckOwnership(v->owner)) return CMD_ERROR; - if (!v->IsPrimaryVehicle()) return CMD_ERROR; + Vehicle *v = Vehicle::GetIfValid(p1); + if (v == NULL || !CheckOwnership(v->owner) || !v->IsPrimaryVehicle()) return CMD_ERROR; switch (v->type) { case VEH_TRAIN: @@ -334,9 +330,8 @@ CommandCost CmdCloneVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint CommandCost total_cost(EXPENSES_NEW_VEHICLES); uint32 build_argument = 2; - if (!Vehicle::IsValidID(p1)) return CMD_ERROR; - - Vehicle *v = Vehicle::Get(p1); + Vehicle *v = Vehicle::GetIfValid(p1); + if (v == NULL) return CMD_ERROR; Vehicle *v_front = v; Vehicle *w = NULL; Vehicle *w_front = NULL; @@ -532,10 +527,8 @@ CommandCost SendAllVehiclesToDepot(VehicleType type, DoCommandFlag flags, bool s */ CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - if (!Vehicle::IsValidID(p1)) return CMD_ERROR; - - Vehicle *v = Vehicle::Get(p1); - if (!CheckOwnership(v->owner)) return CMD_ERROR; + Vehicle *v = Vehicle::GetIfValid(p1); + if (v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR; bool reset = StrEmpty(text); @@ -564,12 +557,9 @@ CommandCost CmdRenameVehicle(TileIndex tile, DoCommandFlag flags, uint32 p1, uin CommandCost CmdChangeServiceInt(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { uint16 serv_int = GetServiceIntervalClamped(p2); // Double check the service interval from the user-input + Vehicle *v = Vehicle::GetIfValid(p1); - if (serv_int != p2 || !Vehicle::IsValidID(p1)) return CMD_ERROR; - - Vehicle *v = Vehicle::Get(p1); - - if (!CheckOwnership(v->owner)) return CMD_ERROR; + if (serv_int != p2 || v == NULL || !CheckOwnership(v->owner)) return CMD_ERROR; if (flags & DC_EXEC) { v->service_interval = serv_int; |