engine.c
changeset 4300 687a17c9c557
parent 4297 47ce9665b4af
child 4322 0bee6d9bc452
equal deleted inserted replaced
4299:b86602eaaff1 4300:687a17c9c557
    26 
    26 
    27 enum {
    27 enum {
    28 	ENGINE_AVAILABLE = 1,
    28 	ENGINE_AVAILABLE = 1,
    29 	ENGINE_INTRODUCING = 2,
    29 	ENGINE_INTRODUCING = 2,
    30 	ENGINE_PREVIEWING = 4,
    30 	ENGINE_PREVIEWING = 4,
       
    31 };
       
    32 
       
    33 enum {
       
    34 	YEAR_ENGINE_AGING_STOPS = 2050,
    31 };
    35 };
    32 
    36 
    33 /** Bitmasked values of what type of cargo is refittable for the given vehicle-type.
    37 /** Bitmasked values of what type of cargo is refittable for the given vehicle-type.
    34  * This coupled with the landscape information (_landscape_global_cargo_mask) gives
    38  * This coupled with the landscape information (_landscape_global_cargo_mask) gives
    35  * us exactly what is refittable and what is not */
    39  * us exactly what is refittable and what is not */
   133 
   137 
   134 void StartupEngines(void)
   138 void StartupEngines(void)
   135 {
   139 {
   136 	Engine *e;
   140 	Engine *e;
   137 	const EngineInfo *ei;
   141 	const EngineInfo *ei;
       
   142 	/* Aging of vehicles stops, so account for that when starting late */
       
   143 	const uint16 aging_date = min(_date, ConvertYMDToDate(YEAR_ENGINE_AGING_STOPS, 0, 1));
   138 
   144 
   139 	SetupEngineNames();
   145 	SetupEngineNames();
   140 
   146 
   141 	for (e = _engines, ei = _engine_info; e != endof(_engines); e++, ei++) {
   147 	for (e = _engines, ei = _engine_info; e != endof(_engines); e++, ei++) {
   142 		uint32 r;
   148 		uint32 r;
   150 		// base intro date is before 1922 then the random number of days is not
   156 		// base intro date is before 1922 then the random number of days is not
   151 		// added.
   157 		// added.
   152 		r = Random();
   158 		r = Random();
   153 		e->intro_date = ei->base_intro <= ConvertYMDToDate(1922, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro;
   159 		e->intro_date = ei->base_intro <= ConvertYMDToDate(1922, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro;
   154 		if (e->intro_date <= _date) {
   160 		if (e->intro_date <= _date) {
   155 			e->age = (_date - e->intro_date) >> 5;
   161 			e->age = (aging_date - e->intro_date) >> 5;
   156 			e->player_avail = (byte)-1;
   162 			e->player_avail = (byte)-1;
   157 			e->flags |= ENGINE_AVAILABLE;
   163 			e->flags |= ENGINE_AVAILABLE;
   158 		}
   164 		}
   159 
   165 
   160 		e->reliability_start = GB(r, 16, 14) + 0x7AE0;
   166 		e->reliability_start = GB(r, 16, 14) + 0x7AE0;
   235 
   241 
   236 void EnginesDailyLoop(void)
   242 void EnginesDailyLoop(void)
   237 {
   243 {
   238 	EngineID i;
   244 	EngineID i;
   239 
   245 
   240 	if (_cur_year >= 2050) return;
   246 	if (_cur_year >= YEAR_ENGINE_AGING_STOPS) return;
   241 
   247 
   242 	for (i = 0; i != lengthof(_engines); i++) {
   248 	for (i = 0; i != lengthof(_engines); i++) {
   243 		Engine *e = &_engines[i];
   249 		Engine *e = &_engines[i];
   244 
   250 
   245 		if (e->flags & ENGINE_INTRODUCING) {
   251 		if (e->flags & ENGINE_INTRODUCING) {
   356 
   362 
   357 void EnginesMonthlyLoop(void)
   363 void EnginesMonthlyLoop(void)
   358 {
   364 {
   359 	Engine *e;
   365 	Engine *e;
   360 
   366 
   361 	if (_cur_year < 2050) {
   367 	if (_cur_year < YEAR_ENGINE_AGING_STOPS) {
   362 		for (e = _engines; e != endof(_engines); e++) {
   368 		for (e = _engines; e != endof(_engines); e++) {
   363 			// Age the vehicle
   369 			// Age the vehicle
   364 			if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) {
   370 			if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) {
   365 				e->age++;
   371 				e->age++;
   366 				CalcEngineReliability(e);
   372 				CalcEngineReliability(e);