1
0
Fork 0

Codechange: Replace story related FOR_ALL with range-based for loops

pull/7871/head
glx 2019-12-17 21:21:33 +01:00 committed by Niels Martin Hansen
parent 869581eb23
commit 847e5f33d4
7 changed files with 10 additions and 26 deletions

View File

@ -533,8 +533,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
ClearCargoPickupMonitoring(old_owner); ClearCargoPickupMonitoring(old_owner);
ClearCargoDeliveryMonitoring(old_owner); ClearCargoDeliveryMonitoring(old_owner);
StoryPage *sp; for (StoryPage *sp : StoryPage::Iterate()) {
FOR_ALL_STORY_PAGES(sp) {
if (sp->company == old_owner) delete sp; if (sp->company == old_owner) delete sp;
} }

View File

@ -39,8 +39,7 @@ static const SaveLoad _story_page_elements_desc[] = {
static void Save_STORY_PAGE_ELEMENT() static void Save_STORY_PAGE_ELEMENT()
{ {
StoryPageElement *s; for (StoryPageElement *s : StoryPageElement::Iterate()) {
FOR_ALL_STORY_PAGE_ELEMENTS(s) {
SlSetArrayIndex(s->index); SlSetArrayIndex(s->index);
SlObject(s, _story_page_elements_desc); SlObject(s, _story_page_elements_desc);
} }
@ -75,8 +74,7 @@ static const SaveLoad _story_pages_desc[] = {
static void Save_STORY_PAGE() static void Save_STORY_PAGE()
{ {
StoryPage *s; for (StoryPage *s : StoryPage::Iterate()) {
FOR_ALL_STORY_PAGES(s) {
SlSetArrayIndex(s->index); SlSetArrayIndex(s->index);
SlObject(s, _story_pages_desc); SlObject(s, _story_pages_desc);
} }

View File

@ -17,8 +17,7 @@ ScriptStoryPageElementList::ScriptStoryPageElementList(ScriptStoryPage::StoryPag
{ {
if (!ScriptStoryPage::IsValidStoryPage(story_page_id)) return; if (!ScriptStoryPage::IsValidStoryPage(story_page_id)) return;
StoryPageElement *pe; for (StoryPageElement *pe : StoryPageElement::Iterate()) {
FOR_ALL_STORY_PAGE_ELEMENTS(pe) {
if (pe->page == story_page_id) { if (pe->page == story_page_id) {
this->AddItem(pe->index); this->AddItem(pe->index);
} }

View File

@ -19,8 +19,7 @@ ScriptStoryPageList::ScriptStoryPageList(ScriptCompany::CompanyID company)
uint8 c = company; uint8 c = company;
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY; if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
StoryPage *p; for (StoryPage *p : StoryPage::Iterate()) {
FOR_ALL_STORY_PAGES(p) {
if (p->company == c || p->company == INVALID_COMPANY) { if (p->company == c || p->company == INVALID_COMPANY) {
this->AddItem(p->index); this->AddItem(p->index);
} }

View File

@ -157,8 +157,7 @@ CommandCost CmdCreateStoryPageElement(TileIndex tile, DoCommandFlag flags, uint3
/* Allow at most 128 elements per page. */ /* Allow at most 128 elements per page. */
uint16 element_count = 0; uint16 element_count = 0;
StoryPageElement *iter; for (StoryPageElement *iter : StoryPageElement::Iterate()) {
FOR_ALL_STORY_PAGE_ELEMENTS(iter) {
if (iter->page == page_id) element_count++; if (iter->page == page_id) element_count++;
} }
if (element_count >= 128) return CMD_ERROR; if (element_count >= 128) return CMD_ERROR;
@ -317,8 +316,7 @@ CommandCost CmdRemoveStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (flags & DC_EXEC) { if (flags & DC_EXEC) {
StoryPage *p = StoryPage::Get(page_id); StoryPage *p = StoryPage::Get(page_id);
StoryPageElement *pe; for (StoryPageElement *pe : StoryPageElement::Iterate()) {
FOR_ALL_STORY_PAGE_ELEMENTS(pe) {
if (pe->page == p->index) { if (pe->page == p->index) {
delete pe; delete pe;
} }

View File

@ -60,9 +60,6 @@ struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_po
inline ~StoryPageElement() { free(this->text); } inline ~StoryPageElement() { free(this->text); }
}; };
#define FOR_ALL_STORY_PAGE_ELEMENTS_FROM(var, start) FOR_ALL_ITEMS_FROM(StoryPageElement, story_page_element_index, var, start)
#define FOR_ALL_STORY_PAGE_ELEMENTS(var) FOR_ALL_STORY_PAGE_ELEMENTS_FROM(var, 0)
/** Struct about stories, current and completed */ /** Struct about stories, current and completed */
struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> { struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
uint32 sort_value; ///< A number that increases for every created story page. Used for sorting. The id of a story page is the pool index. uint32 sort_value; ///< A number that increases for every created story page. Used for sorting. The id of a story page is the pool index.
@ -82,8 +79,7 @@ struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
inline ~StoryPage() inline ~StoryPage()
{ {
if (!this->CleaningPool()) { if (!this->CleaningPool()) {
StoryPageElement *spe; for (StoryPageElement *spe : StoryPageElement::Iterate()) {
FOR_ALL_STORY_PAGE_ELEMENTS(spe) {
if (spe->page == this->index) delete spe; if (spe->page == this->index) delete spe;
} }
} }
@ -91,8 +87,5 @@ struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
} }
}; };
#define FOR_ALL_STORY_PAGES_FROM(var, start) FOR_ALL_ITEMS_FROM(StoryPage, story_page_index, var, start)
#define FOR_ALL_STORY_PAGES(var) FOR_ALL_STORY_PAGES_FROM(var, 0)
#endif /* STORY_BASE_H */ #endif /* STORY_BASE_H */

View File

@ -52,8 +52,7 @@ protected:
if (this->story_pages.NeedRebuild()) { if (this->story_pages.NeedRebuild()) {
this->story_pages.clear(); this->story_pages.clear();
const StoryPage *p; for (const StoryPage *p : StoryPage::Iterate()) {
FOR_ALL_STORY_PAGES(p) {
if (this->IsPageAvailable(p)) { if (this->IsPageAvailable(p)) {
this->story_pages.push_back(p); this->story_pages.push_back(p);
} }
@ -80,8 +79,7 @@ protected:
const StoryPage *p = GetSelPage(); const StoryPage *p = GetSelPage();
if (p != nullptr) { if (p != nullptr) {
const StoryPageElement *pe; for (const StoryPageElement *pe : StoryPageElement::Iterate()) {
FOR_ALL_STORY_PAGE_ELEMENTS(pe) {
if (pe->page == p->index) { if (pe->page == p->index) {
this->story_page_elements.push_back(pe); this->story_page_elements.push_back(pe);
} }