mirror of https://github.com/OpenTTD/OpenTTD
(svn r20390) -Codechange: Move company vehicle counting to vehicle.cpp.
parent
90a35d2e5b
commit
e0e66b6ed0
|
@ -20,7 +20,7 @@
|
||||||
#include "network/network_gui.h"
|
#include "network/network_gui.h"
|
||||||
#include "network/network_func.h"
|
#include "network/network_func.h"
|
||||||
#include "economy_func.h"
|
#include "economy_func.h"
|
||||||
#include "vehicle_base.h"
|
#include "vehicle_func.h"
|
||||||
#include "newgrf.h"
|
#include "newgrf.h"
|
||||||
#include "company_manager_face.h"
|
#include "company_manager_face.h"
|
||||||
#include "strings_func.h"
|
#include "strings_func.h"
|
||||||
|
@ -1852,19 +1852,10 @@ struct CompanyWindow : Window
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CW_WIDGET_DESC_VEHICLE_COUNTS: {
|
case CW_WIDGET_DESC_VEHICLE_COUNTS: {
|
||||||
uint amounts[] = { 0, 0, 0, 0 };
|
uint amounts[4];
|
||||||
|
CountCompanyVehicles((CompanyID)this->window_number, amounts);
|
||||||
|
|
||||||
int y = r.top;
|
int y = r.top;
|
||||||
|
|
||||||
const Vehicle *v;
|
|
||||||
FOR_ALL_VEHICLES(v) {
|
|
||||||
if (v->owner == c->index) {
|
|
||||||
if (v->IsPrimaryVehicle()) {
|
|
||||||
assert((size_t)v->type < lengthof(amounts));
|
|
||||||
amounts[v->type]++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (amounts[0] + amounts[1] + amounts[2] + amounts[3] == 0) {
|
if (amounts[0] + amounts[1] + amounts[2] + amounts[3] == 0) {
|
||||||
DrawString(r.left, r.right, y, STR_COMPANY_VIEW_VEHICLES_NONE);
|
DrawString(r.left, r.right, y, STR_COMPANY_VIEW_VEHICLES_NONE);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -592,6 +592,21 @@ uint CountVehiclesInChain(const Vehicle *v)
|
||||||
return count;
|
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
|
* Check if a vehicle is counted in num_engines in each company struct
|
||||||
* @return true if the vehicle is counted in num_engines
|
* @return true if the vehicle is counted in num_engines
|
||||||
|
|
|
@ -30,6 +30,7 @@ typedef Vehicle *VehicleFromPosProc(Vehicle *v, void *data);
|
||||||
|
|
||||||
void VehicleServiceInDepot(Vehicle *v);
|
void VehicleServiceInDepot(Vehicle *v);
|
||||||
uint CountVehiclesInChain(const Vehicle *v);
|
uint CountVehiclesInChain(const Vehicle *v);
|
||||||
|
void CountCompanyVehicles(CompanyID cid, uint counts[4]);
|
||||||
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
void FindVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
||||||
void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
|
void FindVehicleOnPosXY(int x, int y, void *data, VehicleFromPosProc *proc);
|
||||||
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
bool HasVehicleOnPos(TileIndex tile, void *data, VehicleFromPosProc *proc);
|
||||||
|
|
Loading…
Reference in New Issue