Changeset - r23960:7332b2a6afc5
[Not reviewed]
master
0 4 0
glx - 4 years ago 2019-12-16 16:53:40
glx@openttd.org
Codechange: Replace FOR_ALL_GOALS with range-based for loops
4 files changed with 7 insertions and 16 deletions:
0 comments (0 inline, 0 general)
src/economy.cpp
Show inline comments
 
@@ -529,14 +529,13 @@ void ChangeOwnershipOfCompanyItems(Owner
 
	Sign *si;
 
	FOR_ALL_SIGNS(si) {
 
		if (si->owner == old_owner) si->owner = new_owner == INVALID_OWNER ? OWNER_NONE : new_owner;
 
	}
 

	
 
	/* Remove Game Script created Goals, CargoMonitors and Story pages. */
 
	Goal *g;
 
	FOR_ALL_GOALS(g) {
 
	for (Goal *g : Goal::Iterate()) {
 
		if (g->company == old_owner) delete g;
 
	}
 

	
 
	ClearCargoPickupMonitoring(old_owner);
 
	ClearCargoDeliveryMonitoring(old_owner);
 

	
src/goal_base.h
Show inline comments
 
@@ -34,10 +34,7 @@ struct Goal : GoalPool::PoolItem<&_goal_
 
	/**
 
	 * (Empty) destructor has to be defined else operator delete might be called with nullptr parameter
 
	 */
 
	inline ~Goal() { free(this->text); free(this->progress); }
 
};
 

	
 
#define FOR_ALL_GOALS_FROM(var, start) FOR_ALL_ITEMS_FROM(Goal, goal_index, var, start)
 
#define FOR_ALL_GOALS(var) FOR_ALL_GOALS_FROM(var, 0)
 

	
 
#endif /* GOAL_BASE_H */
src/goal_gui.cpp
Show inline comments
 
@@ -63,14 +63,13 @@ struct GoalListWindow : public Window {
 
	void OnClick(Point pt, int widget, int click_count) override
 
	{
 
		if (widget != WID_GOAL_LIST) return;
 

	
 
		int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GOAL_LIST, WD_FRAMERECT_TOP);
 
		int num = 0;
 
		const Goal *s;
 
		FOR_ALL_GOALS(s) {
 
		for (const Goal *s : Goal::Iterate()) {
 
			if (s->company == INVALID_COMPANY) {
 
				y--;
 
				if (y == 0) {
 
					this->HandleClick(s);
 
					return;
 
				}
 
@@ -83,13 +82,13 @@ struct GoalListWindow : public Window {
 
			if (y < 0) return;
 
		}
 

	
 
		y -= 2; // "Company specific goals:" line.
 
		if (y < 0) return;
 

	
 
		FOR_ALL_GOALS(s) {
 
		for (const Goal *s : Goal::Iterate()) {
 
			if (s->company == this->window_number) {
 
				y--;
 
				if (y == 0) {
 
					this->HandleClick(s);
 
					return;
 
				}
 
@@ -155,14 +154,13 @@ struct GoalListWindow : public Window {
 
	 */
 
	uint CountLines()
 
	{
 
		/* Count number of (non) awarded goals. */
 
		uint num_global = 0;
 
		uint num_company = 0;
 
		const Goal *s;
 
		FOR_ALL_GOALS(s) {
 
		for (const Goal *s : Goal::Iterate()) {
 
			if (s->company == INVALID_COMPANY) {
 
				num_global++;
 
			} else if (s->company == this->window_number) {
 
				num_company++;
 
			}
 
		}
 
@@ -204,14 +202,13 @@ struct GoalListWindow : public Window {
 
		if (column == GC_GOAL && IsInsideMM(pos, 0, cap)) DrawString(x, right, y + pos * FONT_HEIGHT_NORMAL, global_section ? STR_GOALS_GLOBAL_TITLE : STR_GOALS_COMPANY_TITLE);
 
		pos++;
 

	
 
		bool rtl = _current_text_dir == TD_RTL;
 

	
 
		uint num = 0;
 
		const Goal *s;
 
		FOR_ALL_GOALS(s) {
 
		for (const Goal *s : Goal::Iterate()) {
 
			if (global_section ? s->company == INVALID_COMPANY : (s->company == this->window_number && s->company != INVALID_COMPANY)) {
 
				if (IsInsideMM(pos, 0, cap)) {
 
					switch (column) {
 
						case GC_GOAL: {
 
							/* Display the goal. */
 
							SetDParamStr(0, s->text);
 
@@ -275,14 +272,13 @@ struct GoalListWindow : public Window {
 
		this->DrawWidgets();
 

	
 
		if (this->IsShaded()) return; // Don't draw anything when the window is shaded.
 

	
 
		/* Calculate progress column width. */
 
		uint max_width = 0;
 
		Goal *s;
 
		FOR_ALL_GOALS(s) {
 
		for (const Goal *s : Goal::Iterate()) {
 
			if (s->progress != nullptr) {
 
				SetDParamStr(0, s->progress);
 
				StringID str = s->completed ? STR_GOALS_PROGRESS_COMPLETE : STR_GOALS_PROGRESS;
 
				uint str_width = GetStringBoundingBox(str).width;
 
				if (str_width > max_width) max_width = str_width;
 
			}
src/saveload/goal_sl.cpp
Show inline comments
 
@@ -23,14 +23,13 @@ static const SaveLoad _goals_desc[] = {
 
	SLE_CONDVAR(Goal, completed, SLE_BOOL, SLV_182, SL_MAX_VERSION),
 
	    SLE_END()
 
};
 

	
 
static void Save_GOAL()
 
{
 
	Goal *s;
 
	FOR_ALL_GOALS(s) {
 
	for (Goal *s : Goal::Iterate()) {
 
		SlSetArrayIndex(s->index);
 
		SlObject(s, _goals_desc);
 
	}
 
}
 

	
 
static void Load_GOAL()
0 comments (0 inline, 0 general)