Go to the documentation of this file.
23 #include "table/strings.h"
30 GroupStatistics::GroupStatistics()
35 GroupStatistics::~GroupStatistics()
66 assert(g->
owner == company);
71 if (IsDefaultGroupID(id_g))
return Company::Get(company)->group_default[type];
105 c->group_all[type].Clear();
106 c->group_default[type].Clear();
112 g->statistics.Clear();
116 if (!v->IsEngineCountable())
continue;
134 assert(delta == 1 || delta == -1);
159 assert(delta == 1 || delta == -1);
198 c->group_all[type].ClearProfits();
199 c->group_default[type].ClearProfits();
205 g->statistics.ClearProfits();
209 if (v->IsPrimaryVehicle()) {
231 if (g->owner != company)
continue;
232 g->statistics.ClearAutoreplace();
255 if (old_g != new_g) {
269 return &c->livery[LS_DEFAULT];
285 if (v->group_id == g->
index && (!v->IsGroundVehicle() || v->IsFrontEngine())) {
286 for (
Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
287 u->colourmap = PAL_NONE;
288 u->InvalidateNewGRFCache();
294 if (cg->parent == g->
index) {
303 Group::Group(
Owner owner)
372 if (gp->parent == g->
index) {
420 bool reset = text.empty();
452 const Livery *livery = GetParentLivery(g);
486 default: NOT_REACHED();
496 for (
Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
497 u->colourmap = PAL_NONE;
498 u->InvalidateNewGRFCache();
499 u->UpdateViewport(
true);
532 if (ret.Failed())
return { ret, group_id };
577 if (v->type == type && v->IsPrimaryVehicle()) {
578 if (v->group_id != id_g)
continue;
609 if (v->IsPrimaryVehicle()) {
610 if (v->group_id != group_id)
continue;
636 if (colour >= COLOUR_END && colour != INVALID_COLOUR)
return CMD_ERROR;
641 if (colour == INVALID_COLOUR) colour = (Colours)GetParentLivery(g)->
colour1;
645 if (colour == INVALID_COLOUR) colour = (Colours)GetParentLivery(g)->
colour2;
669 if (!children)
return;
690 if (flag >= GroupFlags::GF_END)
return CMD_ERROR;
727 for (
Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
731 u->colourmap = PAL_NONE;
732 u->InvalidateNewGRFCache();
733 u->UpdateViewport(
true);
754 for (
Vehicle *u = v; u !=
nullptr; u = u->
Next()) {
758 u->colourmap = PAL_NONE;
759 u->InvalidateNewGRFCache();
836 void RemoveAllGroupsForCompany(
const CompanyID company)
839 if (company == g->
owner)
delete g;
855 if (search == group)
return true;
@ VEH_AIRCRAFT
Aircraft vehicle type.
CommandCost CmdAddSharedVehicleGroup(DoCommandFlag flags, GroupID id_g, VehicleType type)
Add all shared vehicles of all vehicles from a group.
static bool IsCompanyBuildableVehicleType(VehicleType type)
Is the given vehicle type buildable by a company?
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data, bool gui_scope)
Mark window data of the window of a given class and specific window number as invalid (in need of re-...
static Titem * Get(size_t index)
Returns Titem with given index.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
static void CountEngine(const Vehicle *v, int delta)
Update num_engines when adding/removing an engine.
GroupStatistics group_all[VEH_COMPANY_END]
NOSAVE: Statistics for the ALL_GROUP group.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
std::tuple< CommandCost, GroupID > CmdCreateGroup(DoCommandFlag flags, VehicleType vt, GroupID parent_group)
Create a new vehicle group.
CommandCost CmdDeleteGroup(DoCommandFlag flags, GroupID group_id)
Add all vehicles in the given group to the default group and then deletes the group.
bool IsEngineCountable() const
Check if a vehicle is counted in num_engines in each company struct.
AlterGroupMode
Action for CmdAlterGroup.
The information about a vehicle list.
Vehicle * Next() const
Get the next vehicle of this vehicle.
T * Next() const
Get next vehicle in the chain.
@ WC_COMPANY_COLOUR
Company colour selection; Window numbers:
GroupID parent
Parent group.
Tindex index
Index of this pool item.
GroupID group_id
Index of group Pool array.
static void UpdateNumEngineGroup(const Vehicle *v, GroupID old_g, GroupID new_g)
Update the num engines of a groupID.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static void CountVehicle(const Vehicle *v, int delta)
Update num_vehicle when adding or removing a vehicle.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
static void VehicleReachedMinAge(const Vehicle *v)
Add a vehicle to the profit sum of its group.
bool autoreplace_finished
Have all autoreplacement finished?
Livery livery
Custom colour scheme for vehicles in this group.
static const uint MAX_LENGTH_GROUP_NAME_CHARS
The maximum length of a group name in characters including '\0'.
@ VEH_ROAD
Road vehicle type.
Money profit_last_year
Sum of profits for all vehicles.
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Owner owner
Which company owns the vehicle?
Owner
Enum for all companies/owners.
@ DC_EXEC
execute the given command
VehicleType vehicle_type
Vehicle type of the group.
static const GroupID NEW_GROUP
Sentinel for a to-be-created group.
DoCommandFlag
List of flags for a command.
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-grou...
uint16 num_vehicle
Number of vehicles.
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.
static const GroupID ALL_GROUP
All vehicles are in this group.
uint16 num_vehicle_min_age
Number of vehicles considered for profit statistics;.
bool renew_keep_length
sell some wagons if after autoreplace the train is longer than before
size_t Utf8StringLength(const char *s)
Get the length of an UTF-8 encoded string in number of characters and thus not the number of bytes th...
@ Rename
Change group name.
static size_t GetPoolSize()
Returns first unused index.
Statistics and caches on the vehicles in a group.
uint16 EngineID
Unique identification number of an engine.
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
static const GroupID INVALID_GROUP
Sentinel for invalid groups.
Common return value for all commands.
@ WC_VEHICLE_VIEW
Vehicle view; Window numbers:
@ VEH_COMPANY_END
Last company-ownable type.
GroupStatistics statistics
NOSAVE: Statistics and caches on the vehicles in the group.
GroupStatistics group_default[VEH_COMPANY_END]
NOSAVE: Statistics for the DEFAULT_GROUP group.
TileIndex tile
Current tile index.
EngineID engine_type
The type of engine used for this vehicle.
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.
static T SB(T &x, const uint8 s, const uint8 n, const U d)
Set n bits in x starting at bit s to d.
@ WC_REPLACE_VEHICLE
Replace vehicle window; Window numbers:
uint32 Pack() const
Pack a VehicleListIdentifier in a single uint32.
bool IsFrontEngine() const
Check if the vehicle is a front engine.
byte in_use
Bit 0 set if this livery should override the default livery first colour, Bit 1 for the second colour...
CompanySettings settings
settings specific for each company
void PropagateChildLivery(const Group *g)
Propagate a livery change to a group's children.
@ WC_VEHICLE_DETAILS
Vehicle details; Window numbers:
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...
@ MAX_COMPANIES
Maximum number of companies.
static void UpdateAutoreplace(CompanyID company)
Update autoreplace_defined and autoreplace_finished of all statistics of a company.
'Train' is either a loco or a wagon.
static GroupStatistics & Get(CompanyID company, GroupID id_g, VehicleType type)
Returns the GroupStatistics for a specific group.
static const GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
uint16 * num_engines
Caches the number of engines of each type the company owns.
static GroupStatistics & GetAllGroup(const Vehicle *v)
Returns the GroupStatistic for the ALL_GROUPO of a vehicle type.
Money profit_last_year_min_age
Sum of profits for vehicles considered for profit statistics.
static bool IsAllGroupID(GroupID id_g)
Checks if a GroupID stands for all vehicles of a company.
GroupPool _group_pool("Group")
Pool of groups.
Struct to store engine replacements.
VehicleType
Available vehicle types.
CommandCost CmdRemoveAllVehiclesGroup(DoCommandFlag flags, GroupID group_id)
Remove all vehicles from a group.
static CommandCost RemoveEngineReplacementForCompany(Company *c, EngineID engine, GroupID group, DoCommandFlag flags)
Remove an engine replacement for the company.
bool autoreplace_defined
Are any autoreplace rules set?
CommandCost CmdSetGroupFlag(DoCommandFlag flags, GroupID group_id, GroupFlags flag, bool value, bool recursive)
(Un)set group flag from a group
static WindowClass GetWindowClassForVehicleType(VehicleType vt)
Get WindowClass for vehicle list of given vehicle type.
CommandCost CmdSetGroupLivery(DoCommandFlag flags, GroupID group_id, bool primary, Colours colour)
Set the livery for a vehicle group.
void RemoveVehicleFromGroup(const Vehicle *v)
Decrease the num_vehicle variable before delete an front engine from a group.
Vehicle * FirstShared() const
Get the first vehicle of this vehicle chain.
CompanyID _current_company
Company currently doing an action.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Base class for all pools.
uint16 GroupID
Type for all group identifiers.
static void UpdateProfits()
Recompute the profits for all groups.
static void SetGroupFlag(Group *g, GroupFlags flag, bool set, bool children)
Set group flag for a group and its sub-groups.
static Train * From(Vehicle *v)
Converts a Vehicle to SpecializedVehicle with type checking.
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.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
CommandCost CmdAlterGroup(DoCommandFlag flags, AlterGroupMode mode, GroupID group_id, GroupID parent_id, const std::string &text)
Alter a group.
Vehicle * NextShared() const
Get the next vehicle of the shared vehicle chain.
bool GroupIsInGroup(GroupID search, GroupID group)
Test if GroupID group is a descendant of (or is) GroupID search.
@ WC_VEHICLE_DEPOT
Depot view; Window numbers:
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
static void ClearGroup(GroupID group)
Clear the group of all backups having this group ID.
std::string name
Group Name.
std::tuple< CommandCost, GroupID > CmdAddVehicleGroup(DoCommandFlag flags, GroupID group_id, VehicleID veh_id, bool add_shared)
Add a vehicle to a group.
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
uint32 VehicleID
The type all our vehicle IDs have.
@ SetParent
Change group parent.
void Clear()
Clear all caches.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
bool folded
NOSAVE: Is this group folded in the group view?
bool IsFreeWagon() const
Check if the vehicle is a free wagon (got no engine in front of it).
@ VEH_TRAIN
Train vehicle type.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
VehicleType type
Type of vehicle.
EngineRenewList engine_renew_list
Engine renewals of this company.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
@ GF_REPLACE_WAGON_REMOVAL
If set, autoreplace will perform wagon removal on vehicles in this group.
@ VEH_SHIP
Ship vehicle type.
static void AddVehicleToGroup(Vehicle *v, GroupID new_g)
Do add a vehicle to a group.
Information about a particular livery.
Money GetDisplayProfitLastYear() const
Gets the profit vehicle had last year.
VehicleType type
Vehicle type, ie VEH_ROAD, VEH_TRAIN, etc.
static void UpdateAfterLoad()
Update all caches after loading a game, changing NewGRF, etc.
static const int VEHICLE_PROFIT_MIN_AGE
Only vehicles older than this have a meaningful profit.
static void AddProfitLastYear(const Vehicle *v)
Add a vehicle's last year profit to the profit sum of its group.
byte colour2
Second colour, for vehicles with 2CC support.
byte colour1
First colour, for all vehicles.