src/engine.cpp
changeset 6500 08ea5741ee39
parent 6451 7baba06b4b85
child 6535 1a5437f36d78
equal deleted inserted replaced
6499:95b494e25329 6500:08ea5741ee39
    26 ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
    26 ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
    27 AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
    27 AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
    28 RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];
    28 RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];
    29 
    29 
    30 enum {
    30 enum {
    31 	ENGINE_AVAILABLE   = 1,
       
    32 	ENGINE_INTRODUCING = 2,
       
    33 	ENGINE_PREVIEWING  = 4,
       
    34 };
       
    35 
       
    36 enum {
       
    37 	YEAR_ENGINE_AGING_STOPS = 2050,
    31 	YEAR_ENGINE_AGING_STOPS = 2050,
    38 };
    32 };
    39 
    33 
    40 
    34 
    41 void ShowEnginePreviewWindow(EngineID engine);
    35 void ShowEnginePreviewWindow(EngineID engine);
   222 	if (_cur_year >= YEAR_ENGINE_AGING_STOPS) return;
   216 	if (_cur_year >= YEAR_ENGINE_AGING_STOPS) return;
   223 
   217 
   224 	for (i = 0; i != lengthof(_engines); i++) {
   218 	for (i = 0; i != lengthof(_engines); i++) {
   225 		Engine *e = &_engines[i];
   219 		Engine *e = &_engines[i];
   226 
   220 
   227 		if (e->flags & ENGINE_INTRODUCING) {
   221 		if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
   228 			if (e->flags & ENGINE_PREVIEWING) {
   222 			if (e->flags & ENGINE_OFFER_WINDOW_OPEN) {
   229 				if (e->preview_player != 0xFF && !--e->preview_wait) {
   223 				if (e->preview_player != 0xFF && !--e->preview_wait) {
   230 					e->flags &= ~ENGINE_PREVIEWING;
   224 					e->flags &= ~ENGINE_OFFER_WINDOW_OPEN;
   231 					DeleteWindowById(WC_ENGINE_PREVIEW, i);
   225 					DeleteWindowById(WC_ENGINE_PREVIEW, i);
   232 					e->preview_player++;
   226 					e->preview_player++;
   233 				}
   227 				}
   234 			} else if (e->preview_player != 0xFF) {
   228 			} else if (e->preview_player != 0xFF) {
   235 				PlayerID best_player = GetBestPlayer(e->preview_player);
   229 				PlayerID best_player = GetBestPlayer(e->preview_player);
   241 
   235 
   242 				if (!IsHumanPlayer(best_player)) {
   236 				if (!IsHumanPlayer(best_player)) {
   243 					/* XXX - TTDBUG: TTD has a bug here ???? */
   237 					/* XXX - TTDBUG: TTD has a bug here ???? */
   244 					AcceptEnginePreview(i, best_player);
   238 					AcceptEnginePreview(i, best_player);
   245 				} else {
   239 				} else {
   246 					e->flags |= ENGINE_PREVIEWING;
   240 					e->flags |= ENGINE_OFFER_WINDOW_OPEN;
   247 					e->preview_wait = 20;
   241 					e->preview_wait = 20;
   248 					if (IsInteractivePlayer(best_player)) ShowEnginePreviewWindow(i);
   242 					if (IsInteractivePlayer(best_player)) ShowEnginePreviewWindow(i);
   249 				}
   243 				}
   250 			}
   244 			}
   251 		}
   245 		}
   283 	Player *p;
   277 	Player *p;
   284 	EngineID index = e - _engines;
   278 	EngineID index = e - _engines;
   285 
   279 
   286 	/* In case the player didn't build the vehicle during the intro period,
   280 	/* In case the player didn't build the vehicle during the intro period,
   287 	 * prevent that player from getting future intro periods for a while. */
   281 	 * prevent that player from getting future intro periods for a while. */
   288 	if (e->flags & ENGINE_INTRODUCING) {
   282 	if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
   289 		FOR_ALL_PLAYERS(p) {
   283 		FOR_ALL_PLAYERS(p) {
   290 			uint block_preview = p->block_preview;
   284 			uint block_preview = p->block_preview;
   291 
   285 
   292 			if (!HASBIT(e->player_avail, p->index)) continue;
   286 			if (!HASBIT(e->player_avail, p->index)) continue;
   293 
   287 
   305 				}
   299 				}
   306 			}
   300 			}
   307 		}
   301 		}
   308 	}
   302 	}
   309 
   303 
   310 	e->flags = (e->flags & ~ENGINE_INTRODUCING) | ENGINE_AVAILABLE;
   304 	e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE;
   311 	AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
   305 	AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
   312 
   306 
   313 	/* Now available for all players */
   307 	/* Now available for all players */
   314 	e->player_avail = (byte)-1;
   308 	e->player_avail = (byte)-1;
   315 
   309 
   347 			}
   341 			}
   348 
   342 
   349 			if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + 365)) {
   343 			if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + 365)) {
   350 				/* Introduce it to all players */
   344 				/* Introduce it to all players */
   351 				NewVehicleAvailable(e);
   345 				NewVehicleAvailable(e);
   352 			} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_INTRODUCING)) && _date >= e->intro_date) {
   346 			} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) {
   353 				/* Introduction date has passed.. show introducing dialog to one player. */
   347 				/* Introduction date has passed.. show introducing dialog to one player. */
   354 				e->flags |= ENGINE_INTRODUCING;
   348 				e->flags |= ENGINE_EXCLUSIVE_PREVIEW;
   355 
   349 
   356 				/* Do not introduce new rail wagons */
   350 				/* Do not introduce new rail wagons */
   357 				if (!IsWagon(e - _engines))
   351 				if (!IsWagon(e - _engines))
   358 					e->preview_player = (PlayerID)1; // Give to the player with the highest rating.
   352 					e->preview_player = (PlayerID)1; // Give to the player with the highest rating.
   359 			}
   353 			}