src/engine.cpp
branchnoai
changeset 9723 eee46cb39750
parent 9722 ebf0ece7d8f6
child 9724 b39bc69bb2f2
equal deleted inserted replaced
9722:ebf0ece7d8f6 9723:eee46cb39750
     3 /** @file engine.cpp */
     3 /** @file engine.cpp */
     4 
     4 
     5 #include "stdafx.h"
     5 #include "stdafx.h"
     6 #include "openttd.h"
     6 #include "openttd.h"
     7 #include "debug.h"
     7 #include "debug.h"
     8 #include "functions.h"
       
     9 #include "table/strings.h"
     8 #include "table/strings.h"
    10 #include "engine.h"
     9 #include "engine.h"
    11 #include "gfx.h"
       
    12 #include "player.h"
    10 #include "player.h"
    13 #include "command.h"
    11 #include "command_func.h"
    14 #include "vehicle.h"
       
    15 #include "news.h"
    12 #include "news.h"
    16 #include "saveload.h"
    13 #include "saveload.h"
    17 #include "variables.h"
    14 #include "variables.h"
    18 #include "train.h"
    15 #include "train.h"
    19 #include "aircraft.h"
    16 #include "aircraft.h"
    20 #include "newgrf_cargo.h"
    17 #include "newgrf_cargo.h"
    21 #include "date.h"
       
    22 #include "table/engines.h"
    18 #include "table/engines.h"
    23 #include "group.h"
    19 #include "group.h"
    24 #include "string.h"
       
    25 #include "strings.h"
       
    26 #include "misc/autoptr.hpp"
    20 #include "misc/autoptr.hpp"
       
    21 #include "strings_func.h"
       
    22 #include "gfx_func.h"
       
    23 #include "functions.h"
       
    24 #include "window_func.h"
       
    25 #include "date_func.h"
       
    26 #include "autoreplace_base.h"
       
    27 #include "autoreplace_gui.h"
       
    28 #include "string_func.h"
    27 
    29 
    28 EngineInfo _engine_info[TOTAL_NUM_ENGINES];
    30 EngineInfo _engine_info[TOTAL_NUM_ENGINES];
    29 RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
    31 RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
    30 ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
    32 ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
    31 AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
    33 AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
    32 RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];
    34 RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];
    33 
    35 
    34 enum {
    36 enum {
    35 	YEAR_ENGINE_AGING_STOPS = 2050,
    37 	YEAR_ENGINE_AGING_STOPS = 2050,
    36 };
    38 };
       
    39 
       
    40 
       
    41 void SetupEngines()
       
    42 {
       
    43 	/* Copy original static engine data */
       
    44 	memcpy(&_engine_info, &_orig_engine_info, sizeof(_orig_engine_info));
       
    45 	memcpy(&_rail_vehicle_info, &_orig_rail_vehicle_info, sizeof(_orig_rail_vehicle_info));
       
    46 	memcpy(&_ship_vehicle_info, &_orig_ship_vehicle_info, sizeof(_orig_ship_vehicle_info));
       
    47 	memcpy(&_aircraft_vehicle_info, &_orig_aircraft_vehicle_info, sizeof(_orig_aircraft_vehicle_info));
       
    48 	memcpy(&_road_vehicle_info, &_orig_road_vehicle_info, sizeof(_orig_road_vehicle_info));
       
    49 
       
    50 	/* Add type to engines */
       
    51 	Engine* e = _engines;
       
    52 	do e->type = VEH_TRAIN;    while (++e < &_engines[ROAD_ENGINES_INDEX]);
       
    53 	do e->type = VEH_ROAD;     while (++e < &_engines[SHIP_ENGINES_INDEX]);
       
    54 	do e->type = VEH_SHIP;     while (++e < &_engines[AIRCRAFT_ENGINES_INDEX]);
       
    55 	do e->type = VEH_AIRCRAFT; while (++e < &_engines[TOTAL_NUM_ENGINES]);
       
    56 }
    37 
    57 
    38 
    58 
    39 void ShowEnginePreviewWindow(EngineID engine);
    59 void ShowEnginePreviewWindow(EngineID engine);
    40 
    60 
    41 void DeleteCustomEngineNames()
    61 void DeleteCustomEngineNames()
   104 	}
   124 	}
   105 	InvalidateWindowClasses(WC_BUILD_VEHICLE); // Update to show the new reliability
   125 	InvalidateWindowClasses(WC_BUILD_VEHICLE); // Update to show the new reliability
   106 	InvalidateWindowClasses(WC_REPLACE_VEHICLE);
   126 	InvalidateWindowClasses(WC_REPLACE_VEHICLE);
   107 }
   127 }
   108 
   128 
   109 void AddTypeToEngines()
       
   110 {
       
   111 	Engine* e = _engines;
       
   112 
       
   113 	do e->type = VEH_TRAIN;    while (++e < &_engines[ROAD_ENGINES_INDEX]);
       
   114 	do e->type = VEH_ROAD;     while (++e < &_engines[SHIP_ENGINES_INDEX]);
       
   115 	do e->type = VEH_SHIP;     while (++e < &_engines[AIRCRAFT_ENGINES_INDEX]);
       
   116 	do e->type = VEH_AIRCRAFT; while (++e < &_engines[TOTAL_NUM_ENGINES]);
       
   117 }
       
   118 
       
   119 void StartupEngines()
   129 void StartupEngines()
   120 {
   130 {
   121 	Engine *e;
   131 	Engine *e;
   122 	const EngineInfo *ei;
   132 	const EngineInfo *ei;
   123 	/* Aging of vehicles stops, so account for that when starting late */
   133 	/* Aging of vehicles stops, so account for that when starting late */
   325 	e->player_avail = (byte)-1;
   335 	e->player_avail = (byte)-1;
   326 
   336 
   327 	/* Do not introduce new rail wagons */
   337 	/* Do not introduce new rail wagons */
   328 	if (IsWagon(index)) return;
   338 	if (IsWagon(index)) return;
   329 
   339 
   330 	if (index < NUM_TRAIN_ENGINES) {
   340 	if (e->type == VEH_TRAIN) {
   331 		/* maybe make another rail type available */
   341 		/* maybe make another rail type available */
   332 		RailType railtype = RailVehInfo(index)->railtype;
   342 		RailType railtype = RailVehInfo(index)->railtype;
   333 		assert(railtype < RAILTYPE_END);
   343 		assert(railtype < RAILTYPE_END);
   334 		FOR_ALL_PLAYERS(p) {
   344 		FOR_ALL_PLAYERS(p) {
   335 			if (p->is_active) SetBit(p->avail_railtypes, railtype);
   345 			if (p->is_active) SetBit(p->avail_railtypes, railtype);
   336 		}
   346 		}
   337 	}
   347 	} else if (e->type == VEH_ROAD) {
   338 	if ((index - NUM_TRAIN_ENGINES) < NUM_ROAD_ENGINES) {
       
   339 		/* maybe make another road type available */
   348 		/* maybe make another road type available */
   340 		FOR_ALL_PLAYERS(p) {
   349 		FOR_ALL_PLAYERS(p) {
   341 			if (p->is_active) SetBit(p->avail_roadtypes, HasBit(EngInfo(index)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
   350 			if (p->is_active) SetBit(p->avail_roadtypes, HasBit(EngInfo(index)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
   342 		}
   351 		}
   343 	}
   352 	}