diff --git a/src/script/api/script_stationlist.cpp b/src/script/api/script_stationlist.cpp --- a/src/script/api/script_stationlist.cpp +++ b/src/script/api/script_stationlist.cpp @@ -21,9 +21,11 @@ ScriptStationList::ScriptStationList(Scr EnforceDeityOrCompanyModeValid_Void(); bool is_deity = ScriptCompanyMode::IsDeity(); CompanyID owner = ScriptObject::GetCompany(); - for (Station *st : Station::Iterate()) { - if ((is_deity || st->owner == owner) && (st->facilities & station_type) != 0) this->AddItem(st->index); - } + ScriptList::FillList(this, + [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) diff --git a/src/script/api/script_storypageelementlist.cpp b/src/script/api/script_storypageelementlist.cpp --- a/src/script/api/script_storypageelementlist.cpp +++ b/src/script/api/script_storypageelementlist.cpp @@ -17,9 +17,7 @@ ScriptStoryPageElementList::ScriptStoryP { if (!ScriptStoryPage::IsValidStoryPage(story_page_id)) return; - for (StoryPageElement *pe : StoryPageElement::Iterate()) { - if (pe->page == story_page_id) { - this->AddItem(pe->index); - } - } + ScriptList::FillList(this, + [story_page_id](const StoryPageElement *pe) {return pe->page == story_page_id; } + ); } diff --git a/src/script/api/script_storypagelist.cpp b/src/script/api/script_storypagelist.cpp --- a/src/script/api/script_storypagelist.cpp +++ b/src/script/api/script_storypagelist.cpp @@ -19,9 +19,7 @@ ScriptStoryPageList::ScriptStoryPageList uint8_t c = company; if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY; - for (StoryPage *p : StoryPage::Iterate()) { - if (p->company == c || p->company == INVALID_COMPANY) { - this->AddItem(p->index); - } - } + ScriptList::FillList(this, + [c](const StoryPage *p) {return p->company == c || p->company == INVALID_COMPANY; } + ); } diff --git a/src/script/api/script_waypointlist.cpp b/src/script/api/script_waypointlist.cpp --- a/src/script/api/script_waypointlist.cpp +++ b/src/script/api/script_waypointlist.cpp @@ -18,10 +18,14 @@ ScriptWaypointList::ScriptWaypointList(ScriptWaypoint::WaypointType waypoint_type) { EnforceDeityOrCompanyModeValid_Void(); - for (const Waypoint *wp : Waypoint::Iterate()) { - if ((wp->facilities & waypoint_type) && - (wp->owner == ScriptObject::GetCompany() || ScriptCompanyMode::IsDeity() || wp->owner == OWNER_NONE)) this->AddItem(wp->index); - } + + bool is_deity = ScriptCompanyMode::IsDeity(); + CompanyID owner = ScriptObject::GetCompany(); + ScriptList::FillList(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)