mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-13 02:52:37 +00:00
Codechange: Replace FOR_ALL_GROUPS with range-based for loops
This commit is contained in:
parent
f58ce3db19
commit
4ae829cb27
@ -517,8 +517,7 @@ void ResetCompanyLivery(Company *c)
|
|||||||
c->livery[scheme].colour2 = c->colour;
|
c->livery[scheme].colour2 = c->colour;
|
||||||
}
|
}
|
||||||
|
|
||||||
Group *g;
|
for (Group *g : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
if (g->owner == c->index) {
|
if (g->owner == c->index) {
|
||||||
g->livery.in_use = 0;
|
g->livery.in_use = 0;
|
||||||
g->livery.colour1 = c->colour;
|
g->livery.colour1 = c->colour;
|
||||||
|
@ -658,8 +658,7 @@ private:
|
|||||||
GUIGroupList list;
|
GUIGroupList list;
|
||||||
VehicleType vtype = (VehicleType)(this->livery_class - LC_GROUP_RAIL);
|
VehicleType vtype = (VehicleType)(this->livery_class - LC_GROUP_RAIL);
|
||||||
|
|
||||||
const Group *g;
|
for (const Group *g : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
if (g->owner == owner && g->vehicle_type == vtype) {
|
if (g->owner == owner && g->vehicle_type == vtype) {
|
||||||
list.push_back(g);
|
list.push_back(g);
|
||||||
}
|
}
|
||||||
@ -750,8 +749,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* And group names */
|
/* And group names */
|
||||||
const Group *g;
|
for (const Group *g : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
if (g->owner == (CompanyID)this->window_number) {
|
if (g->owner == (CompanyID)this->window_number) {
|
||||||
SetDParam(0, g->index);
|
SetDParam(0, g->index);
|
||||||
d = maxdim(d, GetStringBoundingBox(STR_GROUP_NAME));
|
d = maxdim(d, GetStringBoundingBox(STR_GROUP_NAME));
|
||||||
|
@ -410,8 +410,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
|
|||||||
if (new_owner == INVALID_OWNER) {
|
if (new_owner == INVALID_OWNER) {
|
||||||
RemoveAllGroupsForCompany(old_owner);
|
RemoveAllGroupsForCompany(old_owner);
|
||||||
} else {
|
} else {
|
||||||
Group *g;
|
for (Group *g : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
if (g->owner == old_owner) g->owner = new_owner;
|
if (g->owner == old_owner) g->owner = new_owner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,9 +95,6 @@ static inline bool IsAllGroupID(GroupID id_g)
|
|||||||
return id_g == ALL_GROUP;
|
return id_g == ALL_GROUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FOR_ALL_GROUPS_FROM(var, start) FOR_ALL_ITEMS_FROM(Group, group_index, var, start)
|
|
||||||
#define FOR_ALL_GROUPS(var) FOR_ALL_GROUPS_FROM(var, 0)
|
|
||||||
|
|
||||||
|
|
||||||
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
|
uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e);
|
||||||
uint GetGroupNumVehicle(CompanyID company, GroupID id_g, VehicleType type);
|
uint GetGroupNumVehicle(CompanyID company, GroupID id_g, VehicleType type);
|
||||||
|
@ -109,8 +109,7 @@ void GroupStatistics::Clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Recalculate */
|
/* Recalculate */
|
||||||
Group *g;
|
for (Group *g : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
g->statistics.Clear();
|
g->statistics.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,8 +189,7 @@ void GroupStatistics::Clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Recalculate */
|
/* Recalculate */
|
||||||
Group *g;
|
for (Group *g : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
g->statistics.ClearProfits();
|
g->statistics.ClearProfits();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,8 +213,7 @@ void GroupStatistics::Clear()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Recalculate */
|
/* Recalculate */
|
||||||
Group *g;
|
for (Group *g : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
if (g->owner != company) continue;
|
if (g->owner != company) continue;
|
||||||
g->statistics.ClearAutoreplace();
|
g->statistics.ClearAutoreplace();
|
||||||
}
|
}
|
||||||
@ -280,8 +277,7 @@ void PropagateChildLivery(const Group *g)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Group *cg;
|
for (Group *cg : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(cg) {
|
|
||||||
if (cg->parent == g->index) {
|
if (cg->parent == g->index) {
|
||||||
if (!HasBit(cg->livery.in_use, 0)) cg->livery.colour1 = g->livery.colour1;
|
if (!HasBit(cg->livery.in_use, 0)) cg->livery.colour1 = g->livery.colour1;
|
||||||
if (!HasBit(cg->livery.in_use, 1)) cg->livery.colour2 = g->livery.colour2;
|
if (!HasBit(cg->livery.in_use, 1)) cg->livery.colour2 = g->livery.colour2;
|
||||||
@ -370,8 +366,7 @@ CommandCost CmdDeleteGroup(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
|
|||||||
DoCommand(0, p1, 0, flags, CMD_REMOVE_ALL_VEHICLES_GROUP);
|
DoCommand(0, p1, 0, flags, CMD_REMOVE_ALL_VEHICLES_GROUP);
|
||||||
|
|
||||||
/* Delete sub-groups */
|
/* Delete sub-groups */
|
||||||
Group *gp;
|
for (const Group *gp : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(gp) {
|
|
||||||
if (gp->parent == g->index) {
|
if (gp->parent == g->index) {
|
||||||
DoCommand(0, gp->index, 0, flags, CMD_DELETE_GROUP);
|
DoCommand(0, gp->index, 0, flags, CMD_DELETE_GROUP);
|
||||||
}
|
}
|
||||||
@ -683,8 +678,7 @@ static void SetGroupReplaceProtection(Group *g, bool protect)
|
|||||||
{
|
{
|
||||||
g->replace_protection = protect;
|
g->replace_protection = protect;
|
||||||
|
|
||||||
Group *pg;
|
for (Group *pg : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(pg) {
|
|
||||||
if (pg->parent == g->index) SetGroupReplaceProtection(pg, protect);
|
if (pg->parent == g->index) SetGroupReplaceProtection(pg, protect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -797,8 +791,7 @@ uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e)
|
|||||||
{
|
{
|
||||||
uint count = 0;
|
uint count = 0;
|
||||||
const Engine *e = Engine::Get(id_e);
|
const Engine *e = Engine::Get(id_e);
|
||||||
const Group *g;
|
for (const Group *g : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
if (g->parent == id_g) count += GetGroupNumEngines(company, g->index, id_e);
|
if (g->parent == id_g) count += GetGroupNumEngines(company, g->index, id_e);
|
||||||
}
|
}
|
||||||
return count + GroupStatistics::Get(company, id_g, e->type).num_engines[id_e];
|
return count + GroupStatistics::Get(company, id_g, e->type).num_engines[id_e];
|
||||||
@ -815,8 +808,7 @@ uint GetGroupNumEngines(CompanyID company, GroupID id_g, EngineID id_e)
|
|||||||
uint GetGroupNumVehicle(CompanyID company, GroupID id_g, VehicleType type)
|
uint GetGroupNumVehicle(CompanyID company, GroupID id_g, VehicleType type)
|
||||||
{
|
{
|
||||||
uint count = 0;
|
uint count = 0;
|
||||||
const Group *g;
|
for (const Group *g : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
if (g->parent == id_g) count += GetGroupNumVehicle(company, g->index, type);
|
if (g->parent == id_g) count += GetGroupNumVehicle(company, g->index, type);
|
||||||
}
|
}
|
||||||
return count + GroupStatistics::Get(company, id_g, type).num_vehicle;
|
return count + GroupStatistics::Get(company, id_g, type).num_vehicle;
|
||||||
@ -833,8 +825,7 @@ uint GetGroupNumVehicle(CompanyID company, GroupID id_g, VehicleType type)
|
|||||||
uint GetGroupNumProfitVehicle(CompanyID company, GroupID id_g, VehicleType type)
|
uint GetGroupNumProfitVehicle(CompanyID company, GroupID id_g, VehicleType type)
|
||||||
{
|
{
|
||||||
uint count = 0;
|
uint count = 0;
|
||||||
const Group *g;
|
for (const Group *g : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
if (g->parent == id_g) count += GetGroupNumProfitVehicle(company, g->index, type);
|
if (g->parent == id_g) count += GetGroupNumProfitVehicle(company, g->index, type);
|
||||||
}
|
}
|
||||||
return count + GroupStatistics::Get(company, id_g, type).num_profit_vehicle;
|
return count + GroupStatistics::Get(company, id_g, type).num_profit_vehicle;
|
||||||
@ -851,8 +842,7 @@ uint GetGroupNumProfitVehicle(CompanyID company, GroupID id_g, VehicleType type)
|
|||||||
Money GetGroupProfitLastYear(CompanyID company, GroupID id_g, VehicleType type)
|
Money GetGroupProfitLastYear(CompanyID company, GroupID id_g, VehicleType type)
|
||||||
{
|
{
|
||||||
Money sum = 0;
|
Money sum = 0;
|
||||||
const Group *g;
|
for (const Group *g : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
if (g->parent == id_g) sum += GetGroupProfitLastYear(company, g->index, type);
|
if (g->parent == id_g) sum += GetGroupProfitLastYear(company, g->index, type);
|
||||||
}
|
}
|
||||||
return sum + GroupStatistics::Get(company, id_g, type).profit_last_year;
|
return sum + GroupStatistics::Get(company, id_g, type).profit_last_year;
|
||||||
@ -860,9 +850,7 @@ Money GetGroupProfitLastYear(CompanyID company, GroupID id_g, VehicleType type)
|
|||||||
|
|
||||||
void RemoveAllGroupsForCompany(const CompanyID company)
|
void RemoveAllGroupsForCompany(const CompanyID company)
|
||||||
{
|
{
|
||||||
Group *g;
|
for (Group *g : Group::Iterate()) {
|
||||||
|
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
if (company == g->owner) delete g;
|
if (company == g->owner) delete g;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,8 +178,7 @@ private:
|
|||||||
|
|
||||||
GUIGroupList list;
|
GUIGroupList list;
|
||||||
|
|
||||||
const Group *g;
|
for (const Group *g : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
if (g->owner == owner && g->vehicle_type == this->vli.vtype) {
|
if (g->owner == owner && g->vehicle_type == this->vli.vtype) {
|
||||||
list.push_back(g);
|
list.push_back(g);
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,7 @@ static const SaveLoad _group_desc[] = {
|
|||||||
|
|
||||||
static void Save_GRPS()
|
static void Save_GRPS()
|
||||||
{
|
{
|
||||||
Group *g;
|
for (Group *g : Group::Iterate()) {
|
||||||
|
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
SlSetArrayIndex(g->index);
|
SlSetArrayIndex(g->index);
|
||||||
SlObject(g, _group_desc);
|
SlObject(g, _group_desc);
|
||||||
}
|
}
|
||||||
|
@ -15,8 +15,7 @@
|
|||||||
|
|
||||||
ScriptGroupList::ScriptGroupList()
|
ScriptGroupList::ScriptGroupList()
|
||||||
{
|
{
|
||||||
Group *g;
|
for (const Group *g : Group::Iterate()) {
|
||||||
FOR_ALL_GROUPS(g) {
|
|
||||||
if (g->owner == ScriptObject::GetCompany()) this->AddItem(g->index);
|
if (g->owner == ScriptObject::GetCompany()) this->AddItem(g->index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user