summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglx <glx@openttd.org>2019-12-17 21:21:33 +0100
committerNiels Martin Hansen <nielsm@indvikleren.dk>2019-12-21 20:13:03 +0100
commit847e5f33d4749568cda696b8940ec10b540bd6fb (patch)
tree1e61e1586e351722db89f537b9222a50f278abb0
parent869581eb238b820574d64cd8dabc9324cd7a0dd5 (diff)
downloadopenttd-847e5f33d4749568cda696b8940ec10b540bd6fb.tar.xz
Codechange: Replace story related FOR_ALL with range-based for loops
-rw-r--r--src/economy.cpp3
-rw-r--r--src/saveload/story_sl.cpp6
-rw-r--r--src/script/api/script_storypageelementlist.cpp3
-rw-r--r--src/script/api/script_storypagelist.cpp3
-rw-r--r--src/story.cpp6
-rw-r--r--src/story_base.h9
-rw-r--r--src/story_gui.cpp6
7 files changed, 10 insertions, 26 deletions
diff --git a/src/economy.cpp b/src/economy.cpp
index b4a7d6809..47c73bd52 100644
--- a/src/economy.cpp
+++ b/src/economy.cpp
@@ -533,8 +533,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner)
ClearCargoPickupMonitoring(old_owner);
ClearCargoDeliveryMonitoring(old_owner);
- StoryPage *sp;
- FOR_ALL_STORY_PAGES(sp) {
+ for (StoryPage *sp : StoryPage::Iterate()) {
if (sp->company == old_owner) delete sp;
}
diff --git a/src/saveload/story_sl.cpp b/src/saveload/story_sl.cpp
index 800cacbab..dba2a064f 100644
--- a/src/saveload/story_sl.cpp
+++ b/src/saveload/story_sl.cpp
@@ -39,8 +39,7 @@ static const SaveLoad _story_page_elements_desc[] = {
static void Save_STORY_PAGE_ELEMENT()
{
- StoryPageElement *s;
- FOR_ALL_STORY_PAGE_ELEMENTS(s) {
+ for (StoryPageElement *s : StoryPageElement::Iterate()) {
SlSetArrayIndex(s->index);
SlObject(s, _story_page_elements_desc);
}
@@ -75,8 +74,7 @@ static const SaveLoad _story_pages_desc[] = {
static void Save_STORY_PAGE()
{
- StoryPage *s;
- FOR_ALL_STORY_PAGES(s) {
+ for (StoryPage *s : StoryPage::Iterate()) {
SlSetArrayIndex(s->index);
SlObject(s, _story_pages_desc);
}
diff --git a/src/script/api/script_storypageelementlist.cpp b/src/script/api/script_storypageelementlist.cpp
index 5df7dbf0a..ce60963f2 100644
--- a/src/script/api/script_storypageelementlist.cpp
+++ b/src/script/api/script_storypageelementlist.cpp
@@ -17,8 +17,7 @@ ScriptStoryPageElementList::ScriptStoryPageElementList(ScriptStoryPage::StoryPag
{
if (!ScriptStoryPage::IsValidStoryPage(story_page_id)) return;
- StoryPageElement *pe;
- FOR_ALL_STORY_PAGE_ELEMENTS(pe) {
+ for (StoryPageElement *pe : StoryPageElement::Iterate()) {
if (pe->page == story_page_id) {
this->AddItem(pe->index);
}
diff --git a/src/script/api/script_storypagelist.cpp b/src/script/api/script_storypagelist.cpp
index fc515472a..63f835ada 100644
--- a/src/script/api/script_storypagelist.cpp
+++ b/src/script/api/script_storypagelist.cpp
@@ -19,8 +19,7 @@ ScriptStoryPageList::ScriptStoryPageList(ScriptCompany::CompanyID company)
uint8 c = company;
if (company == ScriptCompany::COMPANY_INVALID) c = INVALID_COMPANY;
- StoryPage *p;
- FOR_ALL_STORY_PAGES(p) {
+ for (StoryPage *p : StoryPage::Iterate()) {
if (p->company == c || p->company == INVALID_COMPANY) {
this->AddItem(p->index);
}
diff --git a/src/story.cpp b/src/story.cpp
index 86fd059dd..0d465fde8 100644
--- a/src/story.cpp
+++ b/src/story.cpp
@@ -157,8 +157,7 @@ CommandCost CmdCreateStoryPageElement(TileIndex tile, DoCommandFlag flags, uint3
/* Allow at most 128 elements per page. */
uint16 element_count = 0;
- StoryPageElement *iter;
- FOR_ALL_STORY_PAGE_ELEMENTS(iter) {
+ for (StoryPageElement *iter : StoryPageElement::Iterate()) {
if (iter->page == page_id) element_count++;
}
if (element_count >= 128) return CMD_ERROR;
@@ -317,8 +316,7 @@ CommandCost CmdRemoveStoryPage(TileIndex tile, DoCommandFlag flags, uint32 p1, u
if (flags & DC_EXEC) {
StoryPage *p = StoryPage::Get(page_id);
- StoryPageElement *pe;
- FOR_ALL_STORY_PAGE_ELEMENTS(pe) {
+ for (StoryPageElement *pe : StoryPageElement::Iterate()) {
if (pe->page == p->index) {
delete pe;
}
diff --git a/src/story_base.h b/src/story_base.h
index 869a6b6a9..e82b9d696 100644
--- a/src/story_base.h
+++ b/src/story_base.h
@@ -60,9 +60,6 @@ struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_po
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 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.
@@ -82,8 +79,7 @@ struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> {
inline ~StoryPage()
{
if (!this->CleaningPool()) {
- StoryPageElement *spe;
- FOR_ALL_STORY_PAGE_ELEMENTS(spe) {
+ for (StoryPageElement *spe : StoryPageElement::Iterate()) {
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 */
diff --git a/src/story_gui.cpp b/src/story_gui.cpp
index a14dab994..677d88bba 100644
--- a/src/story_gui.cpp
+++ b/src/story_gui.cpp
@@ -52,8 +52,7 @@ protected:
if (this->story_pages.NeedRebuild()) {
this->story_pages.clear();
- const StoryPage *p;
- FOR_ALL_STORY_PAGES(p) {
+ for (const StoryPage *p : StoryPage::Iterate()) {
if (this->IsPageAvailable(p)) {
this->story_pages.push_back(p);
}
@@ -80,8 +79,7 @@ protected:
const StoryPage *p = GetSelPage();
if (p != nullptr) {
- const StoryPageElement *pe;
- FOR_ALL_STORY_PAGE_ELEMENTS(pe) {
+ for (const StoryPageElement *pe : StoryPageElement::Iterate()) {
if (pe->page == p->index) {
this->story_page_elements.push_back(pe);
}