diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-11-30 22:59:23 +0100 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-12-16 22:28:32 +0100 |
commit | 57b82e2e99aa30a649d1fd80f192ccf5338dc7c4 (patch) | |
tree | b059cf0f22ab065166dd3b0391772b6e83aef49b /src/group_cmd.cpp | |
parent | 3e85e833a707e6b781d00eae09c9465bacbf1d69 (diff) | |
download | openttd-57b82e2e99aa30a649d1fd80f192ccf5338dc7c4.tar.xz |
Codechange: Don't use globals for story/goal/sign/group command proc return values.
Diffstat (limited to 'src/group_cmd.cpp')
-rw-r--r-- | src/group_cmd.cpp | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/src/group_cmd.cpp b/src/group_cmd.cpp index 4b34ad382..c8772e5c1 100644 --- a/src/group_cmd.cpp +++ b/src/group_cmd.cpp @@ -25,8 +25,6 @@ #include "safeguards.h" -GroupID _new_group_id; - GroupPool _group_pool("Group"); INSTANTIATE_POOL_METHODS(Group) @@ -299,16 +297,16 @@ Group::Group(Owner owner) * @param parent_group parent groupid * @return the cost of this operation or an error */ -CommandCost CmdCreateGroup(DoCommandFlag flags, VehicleType vt, GroupID parent_group) +std::tuple<CommandCost, GroupID> CmdCreateGroup(DoCommandFlag flags, VehicleType vt, GroupID parent_group) { - if (!IsCompanyBuildableVehicleType(vt)) return CMD_ERROR; + if (!IsCompanyBuildableVehicleType(vt)) return { CMD_ERROR, INVALID_GROUP }; - if (!Group::CanAllocateItem()) return CMD_ERROR; + if (!Group::CanAllocateItem()) return { CMD_ERROR, INVALID_GROUP }; const Group *pg = Group::GetIfValid(parent_group); if (pg != nullptr) { - if (pg->owner != _current_company) return CMD_ERROR; - if (pg->vehicle_type != vt) return CMD_ERROR; + if (pg->owner != _current_company) return { CMD_ERROR, INVALID_GROUP }; + if (pg->vehicle_type != vt) return { CMD_ERROR, INVALID_GROUP }; } if (flags & DC_EXEC) { @@ -328,13 +326,13 @@ CommandCost CmdCreateGroup(DoCommandFlag flags, VehicleType vt, GroupID parent_g g->flags = pg->flags; } - _new_group_id = g->index; - InvalidateWindowData(GetWindowClassForVehicleType(vt), VehicleListIdentifier(VL_GROUP_LIST, vt, _current_company).Pack()); InvalidateWindowData(WC_COMPANY_COLOUR, g->owner, g->vehicle_type); + + return { CommandCost(), g->index }; } - return CommandCost(); + return { CommandCost(), INVALID_GROUP}; } @@ -497,26 +495,26 @@ static void AddVehicleToGroup(Vehicle *v, GroupID new_g) * @param add_shared Add shared vehicles as well. * @return the cost of this operation or an error */ -CommandCost CmdAddVehicleGroup(DoCommandFlag flags, GroupID group_id, VehicleID veh_id, bool add_shared) +std::tuple<CommandCost, GroupID> CmdAddVehicleGroup(DoCommandFlag flags, GroupID group_id, VehicleID veh_id, bool add_shared) { Vehicle *v = Vehicle::GetIfValid(veh_id); GroupID new_g = group_id; - if (v == nullptr || (!Group::IsValidID(new_g) && !IsDefaultGroupID(new_g) && new_g != NEW_GROUP)) return CMD_ERROR; + if (v == nullptr || (!Group::IsValidID(new_g) && !IsDefaultGroupID(new_g) && new_g != NEW_GROUP)) return { CMD_ERROR, INVALID_GROUP }; if (Group::IsValidID(new_g)) { Group *g = Group::Get(new_g); - if (g->owner != _current_company || g->vehicle_type != v->type) return CMD_ERROR; + if (g->owner != _current_company || g->vehicle_type != v->type) return { CMD_ERROR, INVALID_GROUP }; } - if (v->owner != _current_company || !v->IsPrimaryVehicle()) return CMD_ERROR; + if (v->owner != _current_company || !v->IsPrimaryVehicle()) return { CMD_ERROR, INVALID_GROUP }; if (new_g == NEW_GROUP) { /* Create new group. */ - CommandCost ret = CmdCreateGroup(flags, v->type, INVALID_GROUP); - if (ret.Failed()) return ret; + auto [ret, group_id] = CmdCreateGroup(flags, v->type, INVALID_GROUP); + if (ret.Failed()) return { ret, group_id }; - new_g = _new_group_id; + new_g = group_id; } if (flags & DC_EXEC) { @@ -541,7 +539,7 @@ CommandCost CmdAddVehicleGroup(DoCommandFlag flags, GroupID group_id, VehicleID InvalidateWindowData(WC_VEHICLE_DETAILS, v->index); } - return CommandCost(); + return { CommandCost(), new_g }; } /** |