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

@@ -2280,19 +2280,19 @@ bool AfterLoadGame()
case TAE_MAIL:
/* Town -> Town */
s->src.type = s->dst.type = SourceType::Town;
if (Town::IsValidID(s->src.id) && Town::IsValidID(s->dst.id)) continue;
if (Town::IsValidID(s->src.ToTownID()) && Town::IsValidID(s->dst.ToTownID())) continue;
break;
case TAE_GOODS:
case TAE_FOOD:
/* Industry -> Town */
s->src.type = SourceType::Industry;
s->dst.type = SourceType::Town;
if (Industry::IsValidID(s->src.id) && Town::IsValidID(s->dst.id)) continue;
if (Industry::IsValidID(s->src.ToIndustryID()) && Town::IsValidID(s->dst.ToTownID())) continue;
break;
default:
/* Industry -> Industry */
s->src.type = s->dst.type = SourceType::Industry;
if (Industry::IsValidID(s->src.id) && Industry::IsValidID(s->dst.id)) continue;
if (Industry::IsValidID(s->src.ToIndustryID()) && Industry::IsValidID(s->dst.ToIndustryID())) continue;
break;
}
} else {
@@ -2310,8 +2310,8 @@ bool AfterLoadGame()
if (ss != nullptr && sd != nullptr && ss->owner == sd->owner &&
Company::IsValidID(ss->owner)) {
s->src.type = s->dst.type = SourceType::Town;
s->src.id = ss->town->index;
s->dst.id = sd->town->index;
s->src.SetIndex(ss->town->index);
s->dst.SetIndex(sd->town->index);
s->awarded = ss->owner;
continue;
}