|
OpenTTD Source
13.2.1
|
#include "stdafx.h"#include "command_func.h"#include "train.h"#include "vehiclelist.h"#include "vehicle_func.h"#include "autoreplace_base.h"#include "autoreplace_func.h"#include "string_func.h"#include "company_func.h"#include "core/pool_func.hpp"#include "order_backup.h"#include "group_cmd.h"#include "table/strings.h"#include "safeguards.h"Go to the source code of this file.
Functions | |
| static void | UpdateNumEngineGroup (const Vehicle *v, GroupID old_g, GroupID new_g) |
| Update the num engines of a groupID. More... | |
| const Livery * | GetParentLivery (const Group *g) |
| void | PropagateChildLivery (const Group *g) |
| Propagate a livery change to a group's children. More... | |
| std::tuple< CommandCost, GroupID > | CmdCreateGroup (DoCommandFlag flags, VehicleType vt, GroupID parent_group) |
| Create a new vehicle group. More... | |
| CommandCost | CmdDeleteGroup (DoCommandFlag flags, GroupID group_id) |
| Add all vehicles in the given group to the default group and then deletes the group. More... | |
| CommandCost | CmdAlterGroup (DoCommandFlag flags, AlterGroupMode mode, GroupID group_id, GroupID parent_id, const std::string &text) |
| Alter a group. More... | |
| static void | AddVehicleToGroup (Vehicle *v, GroupID new_g) |
| Do add a vehicle to a group. More... | |
| std::tuple< CommandCost, GroupID > | CmdAddVehicleGroup (DoCommandFlag flags, GroupID group_id, VehicleID veh_id, bool add_shared) |
| Add a vehicle to a group. More... | |
| CommandCost | CmdAddSharedVehicleGroup (DoCommandFlag flags, GroupID id_g, VehicleType type) |
| Add all shared vehicles of all vehicles from a group. More... | |
| CommandCost | CmdRemoveAllVehiclesGroup (DoCommandFlag flags, GroupID group_id) |
| Remove all vehicles from a group. More... | |
| CommandCost | CmdSetGroupLivery (DoCommandFlag flags, GroupID group_id, bool primary, Colours colour) |
| Set the livery for a vehicle group. More... | |
| static void | SetGroupFlag (Group *g, GroupFlags flag, bool set, bool children) |
| Set group flag for a group and its sub-groups. More... | |
| CommandCost | CmdSetGroupFlag (DoCommandFlag flags, GroupID group_id, GroupFlags flag, bool value, bool recursive) |
| (Un)set group flag from a group More... | |
| void | RemoveVehicleFromGroup (const Vehicle *v) |
| Decrease the num_vehicle variable before delete an front engine from a group. More... | |
| void | SetTrainGroupID (Train *v, GroupID new_g) |
| Affect the groupID of a train to new_g. More... | |
| void | UpdateTrainGroupID (Train *v) |
| Recalculates the groupID of a train. More... | |
| uint | GetGroupNumEngines (CompanyID company, GroupID id_g, EngineID id_e) |
| Get the number of engines with EngineID id_e in the group with GroupID id_g and its sub-groups. More... | |
| uint | GetGroupNumVehicle (CompanyID company, GroupID id_g, VehicleType type) |
| Get the number of vehicles in the group with GroupID id_g and its sub-groups. More... | |
| uint | GetGroupNumVehicleMinAge (CompanyID company, GroupID id_g, VehicleType type) |
| Get the number of vehicles above profit minimum age in the group with GroupID id_g and its sub-groups. More... | |
| Money | GetGroupProfitLastYearMinAge (CompanyID company, GroupID id_g, VehicleType type) |
| Get last year's profit of vehicles above minimum age for the group with GroupID id_g and its sub-groups. More... | |
| void | RemoveAllGroupsForCompany (const CompanyID company) |
| bool | GroupIsInGroup (GroupID search, GroupID group) |
| Test if GroupID group is a descendant of (or is) GroupID search. More... | |
Variables | |
| GroupPool | _group_pool ("Group") |
| Pool of groups. | |
Handling of the engine groups
Definition in file group_cmd.cpp.
Do add a vehicle to a group.
Definition at line 481 of file group_cmd.cpp.
References GroupStatistics::CountVehicle(), and BaseVehicle::type.
| CommandCost CmdAddSharedVehicleGroup | ( | DoCommandFlag | flags, |
| GroupID | id_g, | ||
| VehicleType | type | ||
| ) |
Add all shared vehicles of all vehicles from a group.
| flags | type of operation |
| id_g | index of group |
| type | type of vehicles |
Definition at line 569 of file group_cmd.cpp.
References CMD_ERROR, DC_EXEC, Vehicle::FirstShared(), GetWindowClassForVehicleType(), InvalidateWindowData(), IsCompanyBuildableVehicleType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::IsValidID(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), and Vehicle::NextShared().
| std::tuple<CommandCost, GroupID> CmdAddVehicleGroup | ( | DoCommandFlag | flags, |
| GroupID | group_id, | ||
| VehicleID | veh_id, | ||
| bool | add_shared | ||
| ) |
Add a vehicle to a group.
| flags | type of operation |
| group_id | index of group |
| veh_id | vehicle to add to a group |
| add_shared | Add shared vehicles as well. |
Definition at line 515 of file group_cmd.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::IsValidID().
| CommandCost CmdAlterGroup | ( | DoCommandFlag | flags, |
| AlterGroupMode | mode, | ||
| GroupID | group_id, | ||
| GroupID | parent_id, | ||
| const std::string & | text | ||
| ) |
Alter a group.
| flags | type of operation |
| mode | Operation to perform. |
| group_id | GroupID |
| parent_id | parent group index |
| text | the new name or an empty string when resetting to the default |
Definition at line 413 of file group_cmd.cpp.
References _current_company, CMD_ERROR, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::GetIfValid(), GroupIsInGroup(), Livery::in_use, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, INVALID_GROUP, Group::livery, MAX_LENGTH_GROUP_NAME_CHARS, Group::name, Group::owner, Group::parent, Rename, return_cmd_error, SetParent, GroupStatistics::UpdateAutoreplace(), Utf8StringLength(), and Group::vehicle_type.
| std::tuple<CommandCost, GroupID> CmdCreateGroup | ( | DoCommandFlag | flags, |
| VehicleType | vt, | ||
| GroupID | parent_group | ||
| ) |
Create a new vehicle group.
| flags | type of operation |
| vt | vehicle type |
| parent_group | parent groupid |
Definition at line 317 of file group_cmd.cpp.
References _current_company, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::CanAllocateItem(), CMD_ERROR, Livery::colour1, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::GetIfValid(), INVALID_GROUP, IsCompanyBuildableVehicleType(), Group::livery, Group::owner, Group::parent, and Group::vehicle_type.
| CommandCost CmdDeleteGroup | ( | DoCommandFlag | flags, |
| GroupID | group_id | ||
| ) |
Add all vehicles in the given group to the default group and then deletes the group.
| flags | type of operation |
| group_id | index of group |
Definition at line 362 of file group_cmd.cpp.
References _current_company, OrderBackup::ClearGroup(), CloseWindowById(), CMD_ERROR, DC_EXEC, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_company_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::GetIfValid(), GetWindowClassForVehicleType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_enginerenew_pool >::Iterate(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Iterate(), MAX_COMPANIES, Group::owner, RemoveEngineReplacementForCompany(), Group::vehicle_type, and WC_REPLACE_VEHICLE.
| CommandCost CmdRemoveAllVehiclesGroup | ( | DoCommandFlag | flags, |
| GroupID | group_id | ||
| ) |
Remove all vehicles from a group.
| flags | type of operation |
| group_id | index of group |
Definition at line 600 of file group_cmd.cpp.
References _current_company, CMD_ERROR, DC_EXEC, DEFAULT_GROUP, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::GetIfValid(), GetWindowClassForVehicleType(), InvalidateWindowData(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), Group::owner, and Group::vehicle_type.
| CommandCost CmdSetGroupFlag | ( | DoCommandFlag | flags, |
| GroupID | group_id, | ||
| GroupFlags | flag, | ||
| bool | value, | ||
| bool | recursive | ||
| ) |
(Un)set group flag from a group
| flags | type of operation |
| group_id | index of group array |
| flag | flag to set, by value not bit. |
| value | value to set the flag to. |
| recursive | to apply to sub-groups. |
Definition at line 685 of file group_cmd.cpp.
References _current_company, CMD_ERROR, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::GetIfValid(), and Group::owner.
| CommandCost CmdSetGroupLivery | ( | DoCommandFlag | flags, |
| GroupID | group_id, | ||
| bool | primary, | ||
| Colours | colour | ||
| ) |
Set the livery for a vehicle group.
| flags | Command flags. |
| group_id | Group ID. |
| primary | Set primary instead of secondary colour |
| colour | Colour. |
Definition at line 630 of file group_cmd.cpp.
References _current_company, CMD_ERROR, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::GetIfValid(), and Group::owner.
Get the number of engines with EngineID id_e in the group with GroupID id_g and its sub-groups.
| company | The company the group belongs to |
| id_g | The GroupID of the group used |
| id_e | The EngineID of the engine to count |
Definition at line 775 of file group_cmd.cpp.
References GroupStatistics::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Iterate(), GroupStatistics::num_engines, Group::parent, and Engine::type.
Referenced by ReplaceVehicleWindow::GenerateReplaceVehList(), and InvalidateAutoreplaceWindow().
| uint GetGroupNumVehicle | ( | CompanyID | company, |
| GroupID | id_g, | ||
| VehicleType | type | ||
| ) |
Get the number of vehicles in the group with GroupID id_g and its sub-groups.
| company | The company the group belongs to |
| id_g | The GroupID of the group used |
| type | The vehicle type of the group |
Definition at line 793 of file group_cmd.cpp.
References GroupStatistics::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Iterate(), GroupStatistics::num_vehicle, and Group::parent.
| uint GetGroupNumVehicleMinAge | ( | CompanyID | company, |
| GroupID | id_g, | ||
| VehicleType | type | ||
| ) |
Get the number of vehicles above profit minimum age in the group with GroupID id_g and its sub-groups.
| company | The company the group belongs to |
| id_g | The GroupID of the group used |
| type | The vehicle type of the group |
Definition at line 810 of file group_cmd.cpp.
References GroupStatistics::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Iterate(), GroupStatistics::num_vehicle_min_age, and Group::parent.
| Money GetGroupProfitLastYearMinAge | ( | CompanyID | company, |
| GroupID | id_g, | ||
| VehicleType | type | ||
| ) |
Get last year's profit of vehicles above minimum age for the group with GroupID id_g and its sub-groups.
| company | The company the group belongs to |
| id_g | The GroupID of the group used |
| type | The vehicle type of the group |
Definition at line 827 of file group_cmd.cpp.
References GroupStatistics::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Iterate(), Group::parent, and GroupStatistics::profit_last_year_min_age.
Test if GroupID group is a descendant of (or is) GroupID search.
| search | The GroupID to search in |
| group | The GroupID to search for |
Definition at line 850 of file group_cmd.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Get(), INVALID_GROUP, and Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::IsValidID().
Referenced by CmdAlterGroup(), and GetEngineReplacement().
| void PropagateChildLivery | ( | const Group * | g | ) |
Propagate a livery change to a group's children.
| g | Group. |
Definition at line 281 of file group_cmd.cpp.
References Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::Iterate(), and Vehicle::Next().
| void RemoveVehicleFromGroup | ( | const Vehicle * | v | ) |
Decrease the num_vehicle variable before delete an front engine from a group.
| v | FrontEngine of the train we want to remove. |
Definition at line 707 of file group_cmd.cpp.
References Vehicle::IsPrimaryVehicle().
|
static |
Set group flag for a group and its sub-groups.
| g | initial group. |
| set | 1 to set or 0 to clear protection. |
Definition at line 661 of file group_cmd.cpp.
References ClrBit(), Group::flags, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Iterate(), and SetBit().
Affect the groupID of a train to new_g.
| v | First vehicle of the chain. |
| new_g | index of array group |
Definition at line 721 of file group_cmd.cpp.
Update the num engines of a groupID.
Decrease the old one and increase the new one
| v | Vehicle we have to update |
| old_g | index of the old group |
| new_g | index of the new group |
Definition at line 253 of file group_cmd.cpp.
References Vehicle::engine_type, GroupStatistics::Get(), GroupStatistics::num_engines, Vehicle::owner, and BaseVehicle::type.
Referenced by UpdateTrainGroupID().
| void UpdateTrainGroupID | ( | Train * | v | ) |
Recalculates the groupID of a train.
Should be called each time a vehicle is added to/removed from the chain,.
| v | First vehicle of the chain. |
Definition at line 749 of file group_cmd.cpp.
References DEFAULT_GROUP, Vehicle::group_id, GroundVehicle< T, Type >::IsFreeWagon(), Vehicle::IsFrontEngine(), SpecializedVehicle< T, Type >::Next(), and UpdateNumEngineGroup().
Referenced by NormaliseTrainHead().