Changeset - r12433:78c0a45f0d40
[Not reviewed]
master
0 6 0
smatz - 15 years ago 2009-07-18 19:54:35
smatz@openttd.org
(svn r16877) -Codechange: use Subsidy::IsAwarded() instead of testing subsidy's age
6 files changed with 24 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/ai/api/ai_subsidy.cpp
Show inline comments
 
@@ -17,7 +17,7 @@
 
{
 
	if (!IsValidSubsidy(subsidy_id)) return false;
 

	
 
	return Subsidy::Get(subsidy_id)->age >= 12;
 
	return Subsidy::Get(subsidy_id)->IsAwarded();
 
}
 

	
 
/* static */ AICompany::CompanyID AISubsidy::GetAwardedTo(SubsidyID subsidy_id)
src/economy.cpp
Show inline comments
 
@@ -329,7 +329,7 @@ void ChangeOwnershipOfCompanyItems(Owner
 
	if (new_owner == INVALID_OWNER) {
 
		Subsidy *s;
 
		FOR_ALL_SUBSIDIES(s) {
 
			if (s->age >= 12 && Station::Get(s->to)->owner == old_owner) {
 
			if (s->IsAwarded() && Station::Get(s->to)->owner == old_owner) {
 
				s->cargo_type = CT_INVALID;
 
			}
 
		}
src/saveload/afterload.cpp
Show inline comments
 
@@ -1887,7 +1887,7 @@ bool AfterLoadGame()
 
		/* Delete invalid subsidies possibly present in old versions (but converted to new savegame) */
 
		Subsidy *s;
 
		FOR_ALL_SUBSIDIES(s) {
 
			if (s->age >= 12) {
 
			if (s->IsAwarded()) {
 
				/* Station -> Station */
 
				const Station *from = Station::GetIfValid(s->from);
 
				const Station *to = Station::GetIfValid(s->to);
src/subsidy.cpp
Show inline comments
 
@@ -60,7 +60,7 @@ Pair SetupSubsidyDecodeParam(const Subsi
 
	const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
 
	SetDParam(0, mode ? cs->name : cs->name_single);
 

	
 
	if (s->age < 12) {
 
	if (!s->IsAwarded()) {
 
		if (cs->town_effect != TE_PASSENGERS && cs->town_effect != TE_MAIL) {
 
			SetDParam(1, STR_INDUSTRY);
 
			SetDParam(2, s->from);
 
@@ -102,7 +102,7 @@ void DeleteSubsidyWithTown(TownID index)
 
{
 
	Subsidy *s;
 
	FOR_ALL_SUBSIDIES(s) {
 
		if (s->age < 12) {
 
		if (!s->IsAwarded()) {
 
			const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
 
			if (((cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) && (index == s->from || index == s->to)) ||
 
				((cs->town_effect == TE_GOODS || cs->town_effect == TE_FOOD) && index == s->to)) {
 
@@ -116,7 +116,7 @@ void DeleteSubsidyWithIndustry(IndustryI
 
{
 
	Subsidy *s;
 
	FOR_ALL_SUBSIDIES(s) {
 
		if (s->age < 12) {
 
		if (!s->IsAwarded()) {
 
			const CargoSpec *cs = CargoSpec::Get(s->cargo_type);
 
			if (cs->town_effect != TE_PASSENGERS && cs->town_effect != TE_MAIL &&
 
				(index == s->from || (cs->town_effect != TE_GOODS && cs->town_effect != TE_FOOD && index == s->to))) {
 
@@ -132,7 +132,7 @@ void DeleteSubsidyWithStation(StationID 
 

	
 
	Subsidy *s;
 
	FOR_ALL_SUBSIDIES(s) {
 
		if (s->age >= 12 && (s->from == index || s->to == index)) {
 
		if (s->IsAwarded() && (s->from == index || s->to == index)) {
 
			s->cargo_type = CT_INVALID;
 
			dirty = true;
 
		}
 
@@ -315,7 +315,7 @@ bool CheckSubsidised(const Station *from
 
	/* check if there is an already existing subsidy that applies to us */
 
	FOR_ALL_SUBSIDIES(s) {
 
		if (s->cargo_type == cargo_type &&
 
				s->age >= 12 &&
 
				s->IsAwarded() &&
 
				s->from == from->index &&
 
				s->to == to->index) {
 
			return true;
 
@@ -324,7 +324,7 @@ bool CheckSubsidised(const Station *from
 

	
 
	/* check if there's a new subsidy that applies.. */
 
	FOR_ALL_SUBSIDIES(s) {
 
		if (s->cargo_type == cargo_type && s->age < 12) {
 
		if (s->cargo_type == cargo_type && !s->IsAwarded()) {
 
			/* Check distance from source */
 
			const CargoSpec *cs = CargoSpec::Get(cargo_type);
 
			if (cs->town_effect == TE_PASSENGERS || cs->town_effect == TE_MAIL) {
src/subsidy_base.h
Show inline comments
 
@@ -18,6 +18,15 @@ struct Subsidy {
 
	uint16 to;          ///< Index of destination. Either TownID, IndustryID or StationID, when awarded
 

	
 
	/**
 
	 * Tests whether this subsidy has been awarded to someone
 
	 * @return is this subsidy awarded?
 
	 */
 
	FORCEINLINE bool IsAwarded() const
 
	{
 
		return this->age >= 12;
 
	}
 

	
 
	/**
 
	 * Determines index of this subsidy
 
	 * @return index (in the Subsidy::array array)
 
	 */
src/subsidy_gui.cpp
Show inline comments
 
@@ -47,7 +47,7 @@ struct SubsidyListWindow : Window {
 

	
 
		const Subsidy *s;
 
		FOR_ALL_SUBSIDIES(s) {
 
			if (s->age < 12) {
 
			if (!s->IsAwarded()) {
 
				y -= FONT_HEIGHT_NORMAL;
 
				if (y < 0) {
 
					this->HandleClick(s);
 
@@ -66,7 +66,7 @@ struct SubsidyListWindow : Window {
 
		if (y < 0) return;
 

	
 
		FOR_ALL_SUBSIDIES(s) {
 
			if (s->age >= 12) {
 
			if (s->IsAwarded()) {
 
				y -= FONT_HEIGHT_NORMAL;
 
				if (y < 0) {
 
					this->HandleClick(s);
 
@@ -83,7 +83,7 @@ struct SubsidyListWindow : Window {
 

	
 
		/* determine from coordinate for subsidy and try to scroll to it */
 
		uint offs = s->from;
 
		if (s->age >= 12) {
 
		if (s->IsAwarded()) {
 
			xy = Station::Get(offs)->xy;
 
		} else if (te == TE_PASSENGERS || te == TE_MAIL) {
 
			xy = Town::Get(offs)->xy;
 
@@ -96,7 +96,7 @@ struct SubsidyListWindow : Window {
 

	
 
			/* otherwise determine to coordinate for subsidy and scroll to it */
 
			offs = s->to;
 
			if (s->age >= 12) {
 
			if (s->IsAwarded()) {
 
				xy = Station::Get(offs)->xy;
 
			} else if (te == TE_PASSENGERS || te == TE_MAIL || te == TE_GOODS || te == TE_FOOD) {
 
				xy = Town::Get(offs)->xy;
 
@@ -131,7 +131,7 @@ struct SubsidyListWindow : Window {
 
		uint num = 0;
 

	
 
		FOR_ALL_SUBSIDIES(s) {
 
			if (s->age < 12) {
 
			if (!s->IsAwarded()) {
 
				/* Displays the two offered towns */
 
				SetupSubsidyDecodeParam(s, 1);
 
				SetDParam(7, _date - ymd.day + 384 - s->age * 32);
 
@@ -153,7 +153,7 @@ struct SubsidyListWindow : Window {
 
		num = 0;
 

	
 
		FOR_ALL_SUBSIDIES(s) {
 
			if (s->age >= 12) {
 
			if (s->IsAwarded()) {
 
				SetupSubsidyDecodeParam(s, 1);
 
				SetDParam(3, Station::Get(s->to)->owner);
 
				SetDParam(4, _date - ymd.day + 768 - s->age * 32);
0 comments (0 inline, 0 general)