mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-13 02:52:37 +00:00
(svn r22982) -Cleanup: Remove CountCompanyVehicles() and use ALL_GROUP statistics instead.
This commit is contained in:
parent
dd74536bef
commit
1a12008fcf
@ -610,15 +610,14 @@ void InitializeCompanies()
|
||||
*/
|
||||
bool MayCompanyTakeOver(CompanyID cbig, CompanyID csmall)
|
||||
{
|
||||
uint big_counts[4], small_counts[4];
|
||||
CountCompanyVehicles(cbig, big_counts);
|
||||
CountCompanyVehicles(csmall, small_counts);
|
||||
const Company *c1 = Company::Get(cbig);
|
||||
const Company *c2 = Company::Get(csmall);
|
||||
|
||||
/* Do the combined vehicle counts stay within the limits? */
|
||||
return big_counts[VEH_TRAIN] + small_counts[VEH_TRAIN] <= _settings_game.vehicle.max_trains &&
|
||||
big_counts[VEH_ROAD] + small_counts[VEH_ROAD] <= _settings_game.vehicle.max_roadveh &&
|
||||
big_counts[VEH_SHIP] + small_counts[VEH_SHIP] <= _settings_game.vehicle.max_ships &&
|
||||
big_counts[VEH_AIRCRAFT] + small_counts[VEH_AIRCRAFT] <= _settings_game.vehicle.max_aircraft;
|
||||
return c1->group_all[VEH_TRAIN].num_vehicle + c2->group_all[VEH_TRAIN].num_vehicle <= _settings_game.vehicle.max_trains &&
|
||||
c1->group_all[VEH_ROAD].num_vehicle + c2->group_all[VEH_ROAD].num_vehicle <= _settings_game.vehicle.max_roadveh &&
|
||||
c1->group_all[VEH_SHIP].num_vehicle + c2->group_all[VEH_SHIP].num_vehicle <= _settings_game.vehicle.max_ships &&
|
||||
c1->group_all[VEH_AIRCRAFT].num_vehicle + c2->group_all[VEH_AIRCRAFT].num_vehicle <= _settings_game.vehicle.max_aircraft;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1888,7 +1888,10 @@ struct CompanyWindow : Window
|
||||
|
||||
case CW_WIDGET_DESC_VEHICLE_COUNTS: {
|
||||
uint amounts[4];
|
||||
CountCompanyVehicles((CompanyID)this->window_number, amounts);
|
||||
amounts[0] = c->group_all[VEH_TRAIN].num_vehicle;
|
||||
amounts[1] = c->group_all[VEH_ROAD].num_vehicle;
|
||||
amounts[2] = c->group_all[VEH_SHIP].num_vehicle;
|
||||
amounts[3] = c->group_all[VEH_AIRCRAFT].num_vehicle;
|
||||
|
||||
int y = r.top;
|
||||
if (amounts[0] + amounts[1] + amounts[2] + amounts[3] == 0) {
|
||||
|
@ -599,21 +599,6 @@ uint CountVehiclesInChain(const Vehicle *v)
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of vehicles of a company.
|
||||
* @param c Company owning the vehicles.
|
||||
* @param [out] counts Array of counts. Contains the vehicle count ordered by type afterwards.
|
||||
*/
|
||||
void CountCompanyVehicles(CompanyID cid, uint counts[4])
|
||||
{
|
||||
for (uint i = 0; i < 4; i++) counts[i] = 0;
|
||||
|
||||
const Vehicle *v;
|
||||
FOR_ALL_VEHICLES(v) {
|
||||
if (v->owner == cid && v->IsPrimaryVehicle()) counts[v->type]++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a vehicle is counted in num_engines in each company struct
|
||||
* @return true if the vehicle is counted in num_engines
|
||||
@ -1518,10 +1503,8 @@ UnitID GetFreeUnitNumber(VehicleType type)
|
||||
default: NOT_REACHED();
|
||||
}
|
||||
|
||||
uint amounts[4];
|
||||
CountCompanyVehicles(_current_company, amounts);
|
||||
assert((uint)type < lengthof(amounts));
|
||||
if (amounts[type] >= max_veh) return UINT16_MAX; // Currently already at the limit, no room to make a new one.
|
||||
const Company *c = Company::Get(_current_company);
|
||||
if (c->group_all[type].num_vehicle >= max_veh) return UINT16_MAX; // Currently already at the limit, no room to make a new one.
|
||||
|
||||
FreeUnitIDGenerator gen(type, _current_company);
|
||||
|
||||
|
@ -30,7 +30,6 @@ typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
|
||||
|
||||
void VehicleServiceInDepot(Vehicle *v);
|
||||
uint CountVehiclesInChain(const Vehicle *v);
|
||||
void CountCompanyVehicles(CompanyID cid, uint counts[4]);
|
||||
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
||||
void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
|
||||
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
||||
|
Loading…
Reference in New Issue
Block a user