Codechange: change Source into a class with conversion helpers

A Source is either a CompanyID (Headquarters), IndustryID or TownID.
When making those types stronger a lot of casts would be needed, but
with these simple helpers the intent is shown more clearly.
This commit is contained in:
Rubidium
2025-02-08 15:02:13 +01:00
committed by rubidium42
parent 2929411130
commit 155d7de132
14 changed files with 87 additions and 54 deletions

View File

@@ -118,17 +118,17 @@ void AddCargoDelivery(CargoType cargo_type, CompanyID company, uint32_t amount,
{
if (amount == 0) return;
if (src.id != INVALID_SOURCE) {
if (src.IsValid()) {
/* Handle pickup update. */
switch (src.type) {
case SourceType::Industry: {
CargoMonitorID num = EncodeCargoIndustryMonitor(company, cargo_type, src.id);
CargoMonitorID num = EncodeCargoIndustryMonitor(company, cargo_type, src.ToIndustryID());
CargoMonitorMap::iterator iter = _cargo_pickups.find(num);
if (iter != _cargo_pickups.end()) iter->second += amount;
break;
}
case SourceType::Town: {
CargoMonitorID num = EncodeCargoTownMonitor(company, cargo_type, src.id);
CargoMonitorID num = EncodeCargoTownMonitor(company, cargo_type, src.ToTownID());
CargoMonitorMap::iterator iter = _cargo_pickups.find(num);
if (iter != _cargo_pickups.end()) iter->second += amount;
break;