Handling of the engine groups. More...
#include "stdafx.h"
#include "cmd_helper.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 "table/strings.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. | |
CommandCost | CmdCreateGroup (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Create a new vehicle group. | |
CommandCost | CmdDeleteGroup (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Add all vehicles in the given group to the default group and then deletes the group. | |
static bool | IsUniqueGroupName (const char *name) |
CommandCost | CmdRenameGroup (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Rename a group. | |
static void | AddVehicleToGroup (Vehicle *v, GroupID new_g) |
Do add a vehicle to a group. | |
CommandCost | CmdAddVehicleGroup (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Add a vehicle to a group. | |
CommandCost | CmdAddSharedVehicleGroup (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Add all shared vehicles of all vehicles from a group. | |
CommandCost | CmdRemoveAllVehiclesGroup (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
Remove all vehicles from a group. | |
CommandCost | CmdSetGroupReplaceProtection (TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text) |
(Un)set global replace protection from a group | |
void | RemoveVehicleFromGroup (const Vehicle *v) |
Decrease the num_vehicle variable before delete an front engine from a group. | |
void | SetTrainGroupID (Train *v, GroupID new_g) |
Affect the groupID of a train to new_g. | |
void | UpdateTrainGroupID (Train *v) |
Recalculates the groupID of a train. | |
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. | |
void | RemoveAllGroupsForCompany (const CompanyID company) |
Variables | |
GroupID | _new_group_id |
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 395 of file group_cmd.cpp.
References GroupStatistics::CountVehicle(), SpecializedVehicle< Train, Type >::From(), Vehicle::group_id, Vehicle::IsEngineCountable(), SetTrainGroupID(), BaseVehicle::type, UpdateNumEngineGroup(), VEH_AIRCRAFT, VEH_ROAD, VEH_SHIP, and VEH_TRAIN.
Referenced by CmdAddVehicleGroup().
CommandCost CmdAddSharedVehicleGroup | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Add all shared vehicles of all vehicles from a group.
tile | unused | |
flags | type of operation | |
p1 | index of group array
| |
p2 | type of vehicles | |
text | unused |
Definition at line 480 of file group_cmd.cpp.
References _current_company, CMD_ADD_VEHICLE_GROUP, CMD_ERROR, DC_EXEC, DoCommand(), Vehicle::FirstShared(), FOR_ALL_VEHICLES, GetWindowClassForVehicleType(), Vehicle::group_id, InvalidateWindowData(), IsCompanyBuildableVehicleType(), Vehicle::IsPrimaryVehicle(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::IsValidID(), Vehicle::NextShared(), and BaseVehicle::type.
CommandCost CmdAddVehicleGroup | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Add a vehicle to a group.
tile | unused | |
flags | type of operation | |
p1 | index of array group
| |
p2 | vehicle to add to a group
| |
text | unused |
Definition at line 428 of file group_cmd.cpp.
References _current_company, AddVehicleToGroup(), CMD_ERROR, CmdCreateGroup(), DC_EXEC, CommandCost::Failed(), Vehicle::FirstShared(), GB(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_vehicle_pool >::GetIfValid(), GetWindowClassForVehicleType(), HasBit(), InvalidateWindowData(), Vehicle::IsPrimaryVehicle(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::IsValidID(), NEW_GROUP, Vehicle::NextShared(), Vehicle::owner, Group::owner, SetWindowDirty(), BaseVehicle::type, GroupStatistics::UpdateAutoreplace(), Group::vehicle_type, and WC_REPLACE_VEHICLE.
CommandCost CmdCreateGroup | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Create a new vehicle group.
tile | unused | |
flags | type of operation | |
p1 | vehicle type | |
p2 | unused | |
text | unused |
Definition at line 277 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, DC_EXEC, GetWindowClassForVehicleType(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowData(), IsCompanyBuildableVehicleType(), Group::replace_protection, and Group::vehicle_type.
Referenced by CmdAddVehicleGroup().
CommandCost CmdDeleteGroup | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Add all vehicles in the given group to the default group and then deletes the group.
tile | unused | |
flags | type of operation | |
p1 | index of array group
| |
p2 | unused | |
text | unused |
Definition at line 308 of file group_cmd.cpp.
References _current_company, OrderBackup::ClearGroup(), CMD_ERROR, CMD_REMOVE_ALL_VEHICLES_GROUP, DC_EXEC, DeleteWindowById(), DoCommand(), 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(), MAX_COMPANIES, Group::owner, RemoveEngineReplacementForCompany(), Group::vehicle_type, and WC_REPLACE_VEHICLE.
CommandCost CmdRemoveAllVehiclesGroup | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Remove all vehicles from a group.
tile | unused | |
flags | type of operation | |
p1 | index of group array
| |
p2 | unused | |
text | unused |
Definition at line 519 of file group_cmd.cpp.
References _current_company, CMD_ADD_VEHICLE_GROUP, CMD_ERROR, DC_EXEC, DEFAULT_GROUP, DoCommand(), FOR_ALL_VEHICLES, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::GetIfValid(), GetWindowClassForVehicleType(), Vehicle::group_id, Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem< Tpool >::index, InvalidateWindowData(), Vehicle::IsPrimaryVehicle(), Group::owner, and Group::vehicle_type.
CommandCost CmdRenameGroup | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
Rename a group.
tile | unused | |
flags | type of operation | |
p1 | index of array group
| |
p2 | unused | |
text | the new name or an empty string when resetting to the default |
Definition at line 364 of file group_cmd.cpp.
References _current_company, CMD_ERROR, DC_EXEC, free(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::GetIfValid(), GetWindowClassForVehicleType(), InvalidateWindowData(), MAX_LENGTH_GROUP_NAME_CHARS, Group::name, Group::owner, return_cmd_error, SetWindowDirty(), StrEmpty(), Utf8StringLength(), Group::vehicle_type, and WC_REPLACE_VEHICLE.
CommandCost CmdSetGroupReplaceProtection | ( | TileIndex | tile, | |
DoCommandFlag | flags, | |||
uint32 | p1, | |||
uint32 | p2, | |||
const char * | text | |||
) |
(Un)set global replace protection from a group
tile | unused | |
flags | type of operation | |
p1 | index of group array
| |
p2 |
| |
text | unused |
Definition at line 557 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(), GetWindowClassForVehicleType(), HasBit(), InvalidateWindowData(), Group::owner, Group::replace_protection, SetWindowDirty(), Group::vehicle_type, and WC_REPLACE_VEHICLE.
Get the number of engines with EngineID id_e in the group with GroupID id_g.
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 640 of file group_cmd.cpp.
References GroupStatistics::Get(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_engine_pool >::Get(), GroupStatistics::num_engines, and Engine::type.
Referenced by DrawEngineList(), ReplaceVehicleWindow::GenerateReplaceVehList(), and InvalidateAutoreplaceWindow().
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 577 of file group_cmd.cpp.
References GroupStatistics::CountVehicle(), Vehicle::group_id, and Vehicle::IsPrimaryVehicle().
Referenced by CmdMoveRailVehicle().
Affect the groupID of a train to new_g.
v | First vehicle of the chain. | |
new_g | index of array group |
Definition at line 591 of file group_cmd.cpp.
References Vehicle::IsFrontEngine(), Pool< Titem, Tindex, Tgrowth_step, Tmax_size, Tpool_type, Tcache, Tzero >::PoolItem<&_group_pool >::IsValidID(), SpecializedVehicle< T, Type >::Next(), Vehicle::owner, SetWindowDirty(), GroupStatistics::UpdateAutoreplace(), UpdateNumEngineGroup(), VEH_TRAIN, and WC_REPLACE_VEHICLE.
Referenced by AddVehicleToGroup(), and CmdMoveRailVehicle().
static void UpdateNumEngineGroup | ( | const Vehicle * | v, | |
GroupID | old_g, | |||
GroupID | new_g | |||
) | [inline, static] |
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 244 of file group_cmd.cpp.
References Vehicle::engine_type, GroupStatistics::Get(), GroupStatistics::num_engines, Vehicle::owner, and BaseVehicle::type.
Referenced by AddVehicleToGroup(), SetTrainGroupID(), and 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 616 of file group_cmd.cpp.
References DEFAULT_GROUP, Vehicle::group_id, GroundVehicle< T, Type >::IsFreeWagon(), Vehicle::IsFrontEngine(), SpecializedVehicle< T, Type >::Next(), Vehicle::owner, SetWindowDirty(), GroupStatistics::UpdateAutoreplace(), UpdateNumEngineGroup(), VEH_TRAIN, and WC_REPLACE_VEHICLE.
Referenced by CmdBuildRailVehicle(), CmdBuildRailWagon(), and NormaliseTrainHead().