mirror of https://github.com/OpenTTD/OpenTTD
Compare commits
No commits in common. "06a5fa6239a116f1fd616048b9e0d69493f2a1c8" and "34e8c8e1c1d1003ffa96ea439c265ca607b206e4" have entirely different histories.
06a5fa6239
...
34e8c8e1c1
|
@ -1521,25 +1521,30 @@ static void NetworkCheckRestartMap()
|
||||||
*/
|
*/
|
||||||
static void NetworkAutoCleanCompanies()
|
static void NetworkAutoCleanCompanies()
|
||||||
{
|
{
|
||||||
CompanyMask has_clients = 0;
|
bool clients_in_company[MAX_COMPANIES];
|
||||||
CompanyMask has_vehicles = 0;
|
int vehicles_in_company[MAX_COMPANIES];
|
||||||
|
|
||||||
if (!_settings_client.network.autoclean_companies) return;
|
if (!_settings_client.network.autoclean_companies) return;
|
||||||
|
|
||||||
|
memset(clients_in_company, 0, sizeof(clients_in_company));
|
||||||
|
|
||||||
/* Detect the active companies */
|
/* Detect the active companies */
|
||||||
for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
|
for (const NetworkClientInfo *ci : NetworkClientInfo::Iterate()) {
|
||||||
if (Company::IsValidID(ci->client_playas)) SetBit(has_clients, ci->client_playas);
|
if (Company::IsValidID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_network_dedicated) {
|
if (!_network_dedicated) {
|
||||||
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
|
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
|
||||||
assert(ci != nullptr);
|
assert(ci != nullptr);
|
||||||
if (Company::IsValidID(ci->client_playas)) SetBit(has_clients, ci->client_playas);
|
if (Company::IsValidID(ci->client_playas)) clients_in_company[ci->client_playas] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_settings_client.network.autoclean_novehicles != 0) {
|
if (_settings_client.network.autoclean_novehicles != 0) {
|
||||||
for (const Company *c : Company::Iterate()) {
|
memset(vehicles_in_company, 0, sizeof(vehicles_in_company));
|
||||||
if (std::any_of(std::begin(c->group_all), std::end(c->group_all), [](const GroupStatistics &gs) { return gs.num_vehicle != 0; })) SetBit(has_vehicles, c->index);
|
|
||||||
|
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||||
|
if (!Company::IsValidID(v->owner) || !v->IsPrimaryVehicle()) continue;
|
||||||
|
vehicles_in_company[v->owner]++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1548,7 +1553,7 @@ static void NetworkAutoCleanCompanies()
|
||||||
/* Skip the non-active once */
|
/* Skip the non-active once */
|
||||||
if (c->is_ai) continue;
|
if (c->is_ai) continue;
|
||||||
|
|
||||||
if (!HasBit(has_clients, c->index)) {
|
if (!clients_in_company[c->index]) {
|
||||||
/* The company is empty for one month more */
|
/* The company is empty for one month more */
|
||||||
_network_company_states[c->index].months_empty++;
|
_network_company_states[c->index].months_empty++;
|
||||||
|
|
||||||
|
@ -1567,7 +1572,7 @@ static void NetworkAutoCleanCompanies()
|
||||||
NetworkServerUpdateCompanyPassworded(c->index, false);
|
NetworkServerUpdateCompanyPassworded(c->index, false);
|
||||||
}
|
}
|
||||||
/* Is the company empty for autoclean_novehicles-months, and has no vehicles? */
|
/* Is the company empty for autoclean_novehicles-months, and has no vehicles? */
|
||||||
if (_settings_client.network.autoclean_novehicles != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_novehicles && !HasBit(has_vehicles, c->index)) {
|
if (_settings_client.network.autoclean_novehicles != 0 && _network_company_states[c->index].months_empty > _settings_client.network.autoclean_novehicles && vehicles_in_company[c->index] == 0) {
|
||||||
/* Shut the company down */
|
/* Shut the company down */
|
||||||
Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, c->index, CRR_AUTOCLEAN, INVALID_CLIENT_ID);
|
Command<CMD_COMPANY_CTRL>::Post(CCA_DELETE, c->index, CRR_AUTOCLEAN, INVALID_CLIENT_ID);
|
||||||
IConsolePrint(CC_INFO, "Auto-cleaned company #{} with no vehicles.", c->index + 1);
|
IConsolePrint(CC_INFO, "Auto-cleaned company #{} with no vehicles.", c->index + 1);
|
||||||
|
|
|
@ -1961,10 +1961,6 @@ bool UpdateOrderDest(Vehicle *v, const Order *order, int conditional_depth, bool
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
|
if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) {
|
||||||
/* If the vehicle can't find its destination, delay its next search.
|
|
||||||
* In case many vehicles are in this state, use the vehicle index to spread out pathfinder calls. */
|
|
||||||
if (v->dest_tile == 0 && TimerGameCalendar::date_fract != (v->index % Ticks::DAY_TICKS)) break;
|
|
||||||
|
|
||||||
/* We need to search for the nearest depot (hangar). */
|
/* We need to search for the nearest depot (hangar). */
|
||||||
ClosestDepot closestDepot = v->FindClosestDepot();
|
ClosestDepot closestDepot = v->FindClosestDepot();
|
||||||
|
|
||||||
|
|
|
@ -145,9 +145,9 @@ static const int CTMN_SPECTATOR = -3; ///< Show a company window as spectator
|
||||||
* Pop up a generic company list menu.
|
* Pop up a generic company list menu.
|
||||||
* @param w The toolbar window.
|
* @param w The toolbar window.
|
||||||
* @param widget The button widget id.
|
* @param widget The button widget id.
|
||||||
* @param grey A bitmask of which companies to mark as disabled.
|
* @param grey A bitbask of which items to mark as disabled.
|
||||||
*/
|
*/
|
||||||
static void PopupMainCompanyToolbMenu(Window *w, WidgetID widget, CompanyMask grey = 0)
|
static void PopupMainCompanyToolbMenu(Window *w, WidgetID widget, int grey = 0)
|
||||||
{
|
{
|
||||||
DropDownList list;
|
DropDownList list;
|
||||||
|
|
||||||
|
@ -728,10 +728,10 @@ static CallBackFunction MenuClickIndustry(int index)
|
||||||
|
|
||||||
static void ToolbarVehicleClick(Window *w, VehicleType veh)
|
static void ToolbarVehicleClick(Window *w, VehicleType veh)
|
||||||
{
|
{
|
||||||
CompanyMask dis = 0;
|
int dis = ~0;
|
||||||
|
|
||||||
for (const Company *c : Company::Iterate()) {
|
for (const Vehicle *v : Vehicle::Iterate()) {
|
||||||
if (c->group_all[veh].num_vehicle == 0) SetBit(dis, c->index);
|
if (v->type == veh && v->IsPrimaryVehicle()) ClrBit(dis, v->owner);
|
||||||
}
|
}
|
||||||
PopupMainCompanyToolbMenu(w, WID_TN_VEHICLE_START + veh, dis);
|
PopupMainCompanyToolbMenu(w, WID_TN_VEHICLE_START + veh, dis);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue