Changeset - r12969:5e7f0342aa53
[Not reviewed]
master
0 3 0
rubidium - 15 years ago 2009-09-08 12:27:27
rubidium@openttd.org
(svn r17473) -Codechange: use the post destructor for destroying companies too instead of complicating the graph GUI invalidate code.
3 files changed with 14 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/company_base.h
Show inline comments
 
@@ -94,23 +94,25 @@ struct Company : CompanyPool::PoolItem<&
 
	}
 

	
 
	static FORCEINLINE bool IsValidHumanID(size_t index)
 
	{
 
		const Company *c = Company::GetIfValid(index);
 
		return c != NULL && !c->is_ai;
 
	}
 

	
 
	static FORCEINLINE bool IsHumanID(size_t index)
 
	{
 
		return !Company::Get(index)->is_ai;
 
	}
 

	
 
	static void PostDestructor(size_t index);
 
};
 

	
 
#define FOR_ALL_COMPANIES_FROM(var, start) FOR_ALL_ITEMS_FROM(Company, company_index, var, start)
 
#define FOR_ALL_COMPANIES(var) FOR_ALL_COMPANIES_FROM(var, 0)
 

	
 
Money CalculateCompanyValue(const Company *c);
 

	
 
extern uint _next_competitor_start;
 
extern uint _cur_company_tick_index;
 

	
 
#endif /* COMPANY_BASE_H */
src/company_cmd.cpp
Show inline comments
 
@@ -60,26 +60,34 @@ Company::Company(uint16 name_1, bool is_
 
	InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, INVALID_COMPANY);
 
}
 

	
 
Company::~Company()
 
{
 
	free(this->name);
 
	free(this->president_name);
 
	free(this->num_engines);
 

	
 
	if (CleaningPool()) return;
 

	
 
	DeleteCompanyWindows(this->index);
 
	InvalidateWindowData(WC_GRAPH_LEGEND, 0, this->index);
 
	InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, this->index);
 
}
 

	
 
/**
 
 * Invalidating some stuff after removing item from the pool.
 
 * @param index index of deleted item
 
 */
 
void Company::PostDestructor(size_t index)
 
{
 
	InvalidateWindowData(WC_GRAPH_LEGEND, 0, index);
 
	InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, index);
 
}
 

	
 
/**
 
 * Sets the local company and updates the settings that are set on a
 
 * per-company basis to reflect the core's state in the GUI.
 
 * @param new_company the new company
 
 * @pre Company::IsValidID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE
 
 */
 
void SetLocalCompany(CompanyID new_company)
 
{
 
	/* company could also be COMPANY_SPECTATOR or OWNER_NONE */
 
	assert(Company::IsValidID(new_company) || new_company == COMPANY_SPECTATOR || new_company == OWNER_NONE);
src/graph_gui.cpp
Show inline comments
 
@@ -1189,38 +1189,37 @@ struct PerformanceRatingDetailWindow : W
 
			this->SetDirty();
 
		}
 
	}
 

	
 
	/**
 
	 * Invalidate the data of this window.
 
	 * @param data the company ID of the company that is going to be removed
 
	 */
 
	virtual void OnInvalidateData(int data)
 
	{
 
		/* Disable the companies who are not active */
 
		for (CompanyID i = COMPANY_FIRST; i < MAX_COMPANIES; i++) {
 
			this->SetWidgetDisabledState(i + PRW_COMPANY_FIRST, !Company::IsValidID(i) || i == data);
 
			this->SetWidgetDisabledState(i + PRW_COMPANY_FIRST, !Company::IsValidID(i));
 
		}
 

	
 
		/* Check if the currently selected company is still active. */
 
		if (this->company == data || (this->company != INVALID_COMPANY && !Company::IsValidID(this->company))) {
 
		if (this->company != INVALID_COMPANY && !Company::IsValidID(this->company)) {
 
			/* Raise the widget for the previous selection. */
 
			this->RaiseWidget(this->company + PRW_COMPANY_FIRST);
 
			this->company = INVALID_COMPANY;
 
		}
 

	
 
		if (this->company == INVALID_COMPANY) {
 
			const Company *c;
 
			FOR_ALL_COMPANIES(c) {
 
				if (c->index == data) continue; // Ignore to-be-removed company
 
				this->company = c->index;
 
				break;
 
			}
 
		}
 

	
 
		/* Make sure the widget is lowered */
 
		this->LowerWidget(this->company + PRW_COMPANY_FIRST);
 
	}
 
};
 

	
 
CompanyID PerformanceRatingDetailWindow::company = INVALID_COMPANY;
 

	
0 comments (0 inline, 0 general)