1
0
Fork 0

Codechange: [Script] Use ScriptList::FillList() in more locations (#11762)

pull/11763/head
Loïc Guilloux 2024-01-12 21:19:08 +01:00 committed by GitHub
parent 60da6b992e
commit 54b57fbfeb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 17 deletions

View File

@ -21,9 +21,11 @@ ScriptStationList::ScriptStationList(ScriptStation::StationType station_type)
EnforceDeityOrCompanyModeValid_Void(); EnforceDeityOrCompanyModeValid_Void();
bool is_deity = ScriptCompanyMode::IsDeity(); bool is_deity = ScriptCompanyMode::IsDeity();
CompanyID owner = ScriptObject::GetCompany(); CompanyID owner = ScriptObject::GetCompany();
for (Station *st : Station::Iterate()) { ScriptList::FillList<Station>(this,
if ((is_deity || st->owner == owner) && (st->facilities & station_type) != 0) this->AddItem(st->index); [is_deity, owner, station_type](const Station *st) {
} return (is_deity || st->owner == owner) && (st->facilities & station_type) != 0;
}
);
} }
ScriptStationList_Vehicle::ScriptStationList_Vehicle(VehicleID vehicle_id) ScriptStationList_Vehicle::ScriptStationList_Vehicle(VehicleID vehicle_id)

View File

@ -17,9 +17,7 @@ ScriptStoryPageElementList::ScriptStoryPageElementList(ScriptStoryPage::StoryPag
{ {
if (!ScriptStoryPage::IsValidStoryPage(story_page_id)) return; if (!ScriptStoryPage::IsValidStoryPage(story_page_id)) return;
for (StoryPageElement *pe : StoryPageElement::Iterate()) { ScriptList::FillList<StoryPageElement>(this,
if (pe->page == story_page_id) { [story_page_id](const StoryPageElement *pe) {return pe->page == story_page_id; }
this->AddItem(pe->index); );
}
}
} }

View File

@ -19,9 +19,7 @@ ScriptStoryPageList::ScriptStoryPageList(ScriptCompany::CompanyID company)
uint8_t c = company; uint8_t c = company;
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY; if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
for (StoryPage *p : StoryPage::Iterate()) { ScriptList::FillList<StoryPage>(this,
if (p->company == c || p->company == INVALID_COMPANY) { [c](const StoryPage *p) {return p->company == c || p->company == INVALID_COMPANY; }
this->AddItem(p->index); );
}
}
} }

View File

@ -18,10 +18,14 @@
ScriptWaypointList::ScriptWaypointList(ScriptWaypoint::WaypointType waypoint_type) ScriptWaypointList::ScriptWaypointList(ScriptWaypoint::WaypointType waypoint_type)
{ {
EnforceDeityOrCompanyModeValid_Void(); EnforceDeityOrCompanyModeValid_Void();
for (const Waypoint *wp : Waypoint::Iterate()) {
if ((wp->facilities & waypoint_type) && bool is_deity = ScriptCompanyMode::IsDeity();
(wp->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity() || wp->owner == OWNER_NONE)) this->AddItem(wp->index); CompanyID owner = ScriptObject::GetCompany();
} ScriptList::FillList<Waypoint>(this,
[is_deity, owner, waypoint_type](const Waypoint *wp) {
return (is_deity || wp->owner == owner || wp->owner == OWNER_NONE) && (wp->facilities & waypoint_type) != 0;
}
);
} }
ScriptWaypointList_Vehicle::ScriptWaypointList_Vehicle(VehicleID vehicle_id) ScriptWaypointList_Vehicle::ScriptWaypointList_Vehicle(VehicleID vehicle_id)