Changeset - r23971:14d1b3311615
[Not reviewed]
master
0 7 0
glx - 5 years ago 2019-12-17 20:21:33
glx@openttd.org
Codechange: Replace story related FOR_ALL with range-based for loops
7 files changed with 10 insertions and 26 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -533,8 +533,7 @@ void ChangeOwnershipOfCompanyItems(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;
 
	}
 

	
src/saveload/story_sl.cpp
Show inline comments
 
@@ -39,8 +39,7 @@ static const SaveLoad _story_page_elemen
 

	
 
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);
 
	}
src/script/api/script_storypageelementlist.cpp
Show inline comments
 
@@ -17,8 +17,7 @@ ScriptStoryPageElementList::ScriptStoryP
 
{
 
	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);
 
		}
src/script/api/script_storypagelist.cpp
Show inline comments
 
@@ -19,8 +19,7 @@ ScriptStoryPageList::ScriptStoryPageList
 
	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);
 
		}
src/story.cpp
Show inline comments
 
@@ -157,8 +157,7 @@ CommandCost CmdCreateStoryPageElement(Ti
 

	
 
	/* 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
 
	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;
 
			}
src/story_base.h
Show inline comments
 
@@ -60,9 +60,6 @@ struct StoryPageElement : StoryPageEleme
 
	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::PoolIt
 
	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::PoolIt
 
	}
 
};
 

	
 
#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 */
 

	
src/story_gui.cpp
Show inline comments
 
@@ -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);
 
					}
0 comments (0 inline, 0 general)