Changeset - r6606:113b1820d4cb
[Not reviewed]
master
0 4 0
peter1138 - 17 years ago 2007-05-10 23:10:23
peter1138@openttd.org
(svn r9825) -Codechange: [NewGRF] Add support for early vehicle retirement.
4 files changed with 31 insertions and 13 deletions:
0 comments (0 inline, 0 general)
src/engine.cpp
Show inline comments
 
@@ -67,12 +67,22 @@ static void SetupEngineNames()
 

	
 

	
 
static void CalcEngineReliability(Engine *e)
 
{
 
	uint age = e->age;
 

	
 
	/* Check for early retirement */
 
	if (e->player_avail != 0 && !_patches.never_expire_vehicles) {
 
		uint retire_early = EngInfo(e - _engines)->retire_early;
 
		if (retire_early > 0 && age >= e->duration_phase_1 + e->duration_phase_2 - retire_early * 12) {
 
			/* Early retirement is enabled and we're past the date... */
 
			e->player_avail = 0;
 
			AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
 
		}
 
	}
 

	
 
	if (age < e->duration_phase_1) {
 
		uint start = e->reliability_start;
 
		e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start;
 
	} else if ((age -= e->duration_phase_1) < e->duration_phase_2 || _patches.never_expire_vehicles) {
 
		/* We are at the peak of this engines life. It will have max reliability.
 
		 * This is also true if the engines never expire. They will not go bad over time */
src/engine.h
Show inline comments
 
@@ -102,12 +102,13 @@ struct EngineInfo {
 
	byte load_amount;
 
	byte climates;
 
	uint32 refit_mask;
 
	byte refit_cost;
 
	byte misc_flags;
 
	byte callbackmask;
 
	byte retire_early; ///< Number of years early to retire vehicle
 
};
 

	
 
struct Engine {
 
	Date intro_date;
 
	Date age;
 
	uint16 reliability;
src/newgrf.cpp
Show inline comments
 
@@ -528,12 +528,16 @@ static bool RailVehicleChangeInfo(uint e
 
			break;
 

	
 
		case 0x25: // User-defined bit mask to set when checking veh. var. 42
 
			FOR_EACH_OBJECT rvi[i].user_def_data = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x26: // Retire vehicle early
 
			FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x27: // Miscellaneous flags
 
			FOR_EACH_OBJECT {
 
				ei[i].misc_flags = grf_load_byte(&buf);
 
				if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) _have_2cc = true;
 
			}
 
			break;
 
@@ -550,13 +554,12 @@ static bool RailVehicleChangeInfo(uint e
 
			FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf);
 
			break;
 

	
 
		/* @todo air drag and retire vehicle early
 
		 * Fall-through for unimplemented one byte long properties. */
 
		case 0x20: // Air drag
 
		case 0x26: // Retire vehicle early
 
			FOR_EACH_OBJECT grf_load_byte(&buf);
 
			ret = true;
 
			break;
 

	
 
		default:
 
			ret = true;
 
@@ -647,12 +650,16 @@ static bool RoadVehicleChangeInfo(uint e
 
			break;
 

	
 
		case 0x1A: // Refit cost
 
			FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x1B: // Retire vehicle early
 
			FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x1C: // Miscellaneous flags
 
			FOR_EACH_OBJECT {
 
				ei[i].misc_flags = grf_load_byte(&buf);
 
				if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) _have_2cc = true;
 
			}
 
			break;
 
@@ -668,13 +675,12 @@ static bool RoadVehicleChangeInfo(uint e
 
		case 0x1F: // Long format introduction date (days since year 0)
 
			FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf);
 
			break;
 

	
 
		case 0x18: // Tractive effort
 
		case 0x19: // Air drag
 
		case 0x1B: // Retire vehicle early
 
			/* @todo */
 
			FOR_EACH_OBJECT grf_load_byte(&buf);
 
			ret = true;
 
			break;
 

	
 
		default:
 
@@ -755,12 +761,16 @@ static bool ShipVehicleChangeInfo(uint e
 
			break;
 

	
 
		case 0x13: // Refit cost
 
			FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x16: // Retire vehicle early
 
			FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x17: // Miscellaneous flags
 
			FOR_EACH_OBJECT {
 
				ei[i].misc_flags = grf_load_byte(&buf);
 
				if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) _have_2cc = true;
 
			}
 
			break;
 
@@ -776,13 +786,12 @@ static bool ShipVehicleChangeInfo(uint e
 
		case 0x1A: // Long format introduction date (days since year 0)
 
			FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf);
 
			break;
 

	
 
		case 0x14: // Ocean speed fraction
 
		case 0x15: // Canal speed fraction
 
		case 0x16: // Retire vehicle early
 
			/* @todo */
 
			FOR_EACH_OBJECT grf_load_byte(&buf);
 
			ret = true;
 
			break;
 

	
 
		default:
 
@@ -868,12 +877,16 @@ static bool AircraftVehicleChangeInfo(ui
 
			break;
 

	
 
		case 0x15: // Refit cost
 
			FOR_EACH_OBJECT ei[i].refit_cost = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x16: // Retire vehicle early
 
			FOR_EACH_OBJECT ei[i].retire_early = grf_load_byte(&buf);
 
			break;
 

	
 
		case 0x17: // Miscellaneous flags
 
			FOR_EACH_OBJECT {
 
				ei[i].misc_flags = grf_load_byte(&buf);
 
				if (HASBIT(ei[i].misc_flags, EF_USES_2CC)) _have_2cc = true;
 
			}
 
			break;
 
@@ -887,18 +900,12 @@ static bool AircraftVehicleChangeInfo(ui
 
			break;
 

	
 
		case 0x1A: // Long format introduction date (days since year 0)
 
			FOR_EACH_OBJECT ei[i].base_intro = grf_load_dword(&buf);
 
			break;
 

	
 
		case 0x16: // Retire vehicle early
 
			/* @todo */
 
			FOR_EACH_OBJECT grf_load_byte(&buf);
 
			ret = true;
 
			break;
 

	
 
		default:
 
			ret = true;
 
			break;
 
	}
 

	
 
	*bufp = buf;
src/table/engines.h
Show inline comments
 
@@ -16,46 +16,46 @@
 
 * @param c life length
 
 * @param d base life
 
 * @param e Bitmask of the climates
 
 * @note the 0x80 in parameter b sets the "is carriage bit"
 
 * @note the 5 between d and e is the load amount
 
 */
 
#define MK(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, e, 0, 8, 0, 0 }
 
#define MK(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 5, e, 0, 8, 0, 0, 0 }
 

	
 
/** Writes the properties of a train carriage into the EngineInfo struct.
 
 * @param a Introduction date
 
 * @param b unk2, flag for carriage(bit 7) and decay speed(bits0..6)
 
 * @param c life length
 
 * @param d base life
 
 * @param e Bitmask of the climates
 
 * @see MK
 
 * @note the 5 between d and e is the load amount
 
 */
 
#define MW(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b | 0x80, 5, e, 0, 8, 0, 0 }
 
#define MW(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b | 0x80, 5, e, 0, 8, 0, 0, 0 }
 

	
 
/** Writes the properties of a ship into the EngineInfo struct.
 
 * @param a Introduction date
 
 * @param b unk2, flag for carriage(bit 7) and decay speed(bits0..6)
 
 * @param c life length
 
 * @param d base life
 
 * @param e Bitmask of the climates
 
 * @see MK
 
 * @note the 10 between d and e is the load amount
 
 */
 
#define MS(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 10, e, 0, 8, 0, 0 }
 
#define MS(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 10, e, 0, 8, 0, 0, 0 }
 

	
 
/** Writes the properties of an aeroplane into the EngineInfo struct.
 
 * @param a Introduction date
 
 * @param b unk2, flag for carriage(bit 7) and decay speed(bits0..6)
 
 * @param c life length
 
 * @param d base life
 
 * @param e Bitmask of the climates
 
 * @see MK
 
 * @note the 20 between d and e is the load amount
 
 */
 
#define MA(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 20, e, 0, 8, 0, 0 }
 
#define MA(a, b, c, d, e) { DAYS_TILL_ORIGINAL_BASE_YEAR + a, c, d, b, 20, e, 0, 8, 0, 0, 0 }
 

	
 
// Climates
 
// T = Temperate
 
// A = Arctic
 
// S = Sub-Tropic
 
// Y = Toyland
0 comments (0 inline, 0 general)