mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Replace story related FOR_ALL with range-based for loops
This commit is contained in:
parent
869581eb23
commit
847e5f33d4
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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 */
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue