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/group_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/group_cmd.cpp')
-rw-r--r-- | src/group_cmd.cpp | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index aa8454171..2b56667f8 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -105,10 +105,8 @@ CommandCost CmdCreateGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 */ CommandCost CmdDeleteGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - if (!Group::IsValidID(p1)) return CMD_ERROR; - - Group *g = Group::Get(p1); - if (g->owner != _current_company) return CMD_ERROR; + Group *g = Group::GetIfValid(p1); + if (g == NULL || g->owner != _current_company) return CMD_ERROR; if (flags & DC_EXEC) { Vehicle *v; @@ -164,10 +162,8 @@ static bool IsUniqueGroupName(const char *name) */ CommandCost CmdRenameGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - if (!Group::IsValidID(p1)) return CMD_ERROR; - - Group *g = Group::Get(p1); - if (g->owner != _current_company) return CMD_ERROR; + Group *g = Group::GetIfValid(p1); + if (g == NULL || g->owner != _current_company) return CMD_ERROR; bool reset = StrEmpty(text); @@ -199,11 +195,10 @@ CommandCost CmdRenameGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 */ CommandCost CmdAddVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { + Vehicle *v = Vehicle::GetIfValid(p2); GroupID new_g = p1; - if (!Vehicle::IsValidID(p2) || (!Group::IsValidID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR; - - Vehicle *v = Vehicle::Get(p2); + if (v == NULL || (!Group::IsValidID(new_g) && !IsDefaultGroupID(new_g))) return CMD_ERROR; if (Group::IsValidID(new_g)) { Group *g = Group::Get(new_g); @@ -283,11 +278,10 @@ CommandCost CmdAddSharedVehicleGroup(TileIndex tile, DoCommandFlag flags, uint32 */ CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { + Group *g = Group::GetIfValid(p1); VehicleType type = (VehicleType)p2; - if (!Group::IsValidID(p1) || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR; - Group *g = Group::Get(p1); - if (g->owner != _current_company) return CMD_ERROR; + if (g == NULL || g->owner != _current_company || !IsCompanyBuildableVehicleType(type)) return CMD_ERROR; if (flags & DC_EXEC) { GroupID old_g = p1; @@ -320,10 +314,8 @@ CommandCost CmdRemoveAllVehiclesGroup(TileIndex tile, DoCommandFlag flags, uint3 */ CommandCost CmdSetGroupReplaceProtection(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) { - if (!Group::IsValidID(p1)) return CMD_ERROR; - - Group *g = Group::Get(p1); - if (g->owner != _current_company) return CMD_ERROR; + Group *g = Group::GetIfValid(p1); + if (g == NULL || g->owner != _current_company) return CMD_ERROR; if (flags & DC_EXEC) { g->replace_protection = HasBit(p2, 0); |