2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "debug.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "engine.h"
|
2005-01-14 19:41:24 +00:00
|
|
|
#include "gfx.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "player.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "vehicle.h"
|
|
|
|
#include "news.h"
|
|
|
|
#include "saveload.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
2005-12-02 14:55:23 +00:00
|
|
|
#include "train.h"
|
2006-05-18 02:43:23 +00:00
|
|
|
#include "newgrf_cargo.h"
|
2006-08-14 14:21:15 +00:00
|
|
|
#include "date.h"
|
2006-08-20 12:39:17 +00:00
|
|
|
#include "table/engines.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-12-15 17:55:59 +00:00
|
|
|
EngineInfo _engine_info[TOTAL_NUM_ENGINES];
|
|
|
|
RailVehicleInfo _rail_vehicle_info[NUM_TRAIN_ENGINES];
|
|
|
|
ShipVehicleInfo _ship_vehicle_info[NUM_SHIP_ENGINES];
|
|
|
|
AircraftVehicleInfo _aircraft_vehicle_info[NUM_AIRCRAFT_ENGINES];
|
|
|
|
RoadVehicleInfo _road_vehicle_info[NUM_ROAD_ENGINES];
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
enum {
|
2006-08-22 14:38:37 +00:00
|
|
|
ENGINE_AVAILABLE = 1,
|
2004-08-09 17:04:08 +00:00
|
|
|
ENGINE_INTRODUCING = 2,
|
2006-08-22 14:38:37 +00:00
|
|
|
ENGINE_PREVIEWING = 4,
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
enum {
|
|
|
|
YEAR_ENGINE_AGING_STOPS = 2050,
|
|
|
|
};
|
|
|
|
|
2005-05-14 12:36:16 +00:00
|
|
|
/** Bitmasked values of what type of cargo is refittable for the given vehicle-type.
|
|
|
|
* This coupled with the landscape information (_landscape_global_cargo_mask) gives
|
|
|
|
* us exactly what is refittable and what is not */
|
2006-05-18 02:43:23 +00:00
|
|
|
#define MC(cargo) (1 << cargo)
|
2005-05-14 12:36:16 +00:00
|
|
|
const uint32 _default_refitmasks[NUM_VEHICLE_TYPES] = {
|
|
|
|
/* Trains */
|
2006-08-22 14:38:37 +00:00
|
|
|
MC(GC_PASSENGERS) | MC(GC_COAL) | MC(GC_MAIL) | MC(GC_LIVESTOCK) | MC(GC_GOODS) | MC(GC_GRAIN) | MC(GC_WOOD) | MC(GC_IRON_ORE) |
|
|
|
|
MC(GC_STEEL) | MC(GC_VALUABLES) | MC(GC_PAPER) | MC(GC_FOOD) | MC(GC_FRUIT) | MC(GC_COPPER_ORE) | MC(GC_WATER) | MC(GC_SUGAR) |
|
|
|
|
MC(GC_TOYS) | MC(GC_CANDY) | MC(GC_TOFFEE) | MC(GC_COLA) | MC(GC_COTTON_CANDY) | MC(GC_BUBBLES) | MC(GC_PLASTIC) | MC(GC_FIZZY_DRINKS),
|
2005-05-14 12:36:16 +00:00
|
|
|
/* Road vehicles (not refittable by default) */
|
|
|
|
0,
|
|
|
|
/* Ships */
|
2006-08-22 14:38:37 +00:00
|
|
|
MC(GC_COAL) | MC(GC_MAIL) | MC(GC_LIVESTOCK) | MC(GC_GOODS) | MC(GC_GRAIN) | MC(GC_WOOD) | MC(GC_IRON_ORE) | MC(GC_STEEL) | MC(GC_VALUABLES) |
|
|
|
|
MC(GC_PAPER) | MC(GC_FOOD) | MC(GC_FRUIT) | MC(GC_COPPER_ORE) | MC(GC_WATER) | MC(GC_RUBBER) | MC(GC_SUGAR) | MC(GC_TOYS) | MC(GC_BATTERIES) |
|
|
|
|
MC(GC_CANDY) | MC(GC_TOFFEE) | MC(GC_COLA) | MC(GC_COTTON_CANDY) | MC(GC_BUBBLES) | MC(GC_PLASTIC) | MC(GC_FIZZY_DRINKS),
|
2005-05-14 12:36:16 +00:00
|
|
|
/* Aircraft */
|
2006-08-22 14:38:37 +00:00
|
|
|
MC(GC_PASSENGERS) | MC(GC_MAIL) | MC(GC_GOODS) | MC(GC_VALUABLES) | MC(GC_FOOD) | MC(GC_FRUIT) | MC(GC_SUGAR) | MC(GC_TOYS) |
|
|
|
|
MC(GC_BATTERIES) | MC(GC_CANDY) | MC(GC_TOFFEE) | MC(GC_COLA) | MC(GC_COTTON_CANDY) | MC(GC_BUBBLES) | MC(GC_PLASTIC) | MC(GC_FIZZY_DRINKS),
|
2005-05-14 12:36:16 +00:00
|
|
|
/* Special/Disaster */
|
|
|
|
0,0
|
|
|
|
};
|
|
|
|
#undef MC
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
void ShowEnginePreviewWindow(EngineID engine);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void DeleteCustomEngineNames(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
uint i;
|
|
|
|
StringID old;
|
|
|
|
|
2005-03-09 19:48:20 +00:00
|
|
|
for (i = 0; i != TOTAL_NUM_ENGINES; i++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
old = _engine_name_strings[i];
|
|
|
|
_engine_name_strings[i] = i + STR_8000_KIRBY_PAUL_TANK_STEAM;
|
|
|
|
DeleteName(old);
|
|
|
|
}
|
|
|
|
|
|
|
|
_vehicle_design_names &= ~1;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void LoadCustomEngineNames(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-28 10:14:37 +00:00
|
|
|
/* XXX: not done */
|
2004-08-09 17:04:08 +00:00
|
|
|
DEBUG(misc, 1) ("LoadCustomEngineNames: not done");
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void SetupEngineNames(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-03-09 19:48:20 +00:00
|
|
|
StringID *name;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-03-09 19:48:20 +00:00
|
|
|
for (name = _engine_name_strings; name != endof(_engine_name_strings); name++)
|
|
|
|
*name = STR_SV_EMPTY;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
DeleteCustomEngineNames();
|
|
|
|
LoadCustomEngineNames();
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void AdjustAvailAircraft(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
byte avail = 0;
|
2006-08-17 20:22:35 +00:00
|
|
|
if (_cur_year >= 1955) avail |= 2; // big airport
|
|
|
|
if (_cur_year < 1960 || _patches.always_small_airport) avail |= 1; // small airport
|
|
|
|
if (_cur_year >= 1963) avail |= 4; // enable heliport
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (avail != _avail_aircraft) {
|
|
|
|
_avail_aircraft = avail;
|
|
|
|
InvalidateWindow(WC_BUILD_STATION, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void CalcEngineReliability(Engine *e)
|
|
|
|
{
|
|
|
|
uint age = e->age;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
e->reliability = e->reliability_max;
|
|
|
|
} else if ((age -= e->duration_phase_2) < e->duration_phase_3) {
|
|
|
|
uint max = e->reliability_max;
|
|
|
|
e->reliability = (int)age * (int)(e->reliability_final - max) / e->duration_phase_3 + max;
|
|
|
|
} else {
|
2004-09-19 19:56:40 +00:00
|
|
|
// time's up for this engine
|
|
|
|
// make it either available to all players (if never_expire_vehicles is enabled and if it was available earlier)
|
|
|
|
// or disable this engine completely
|
|
|
|
e->player_avail = (_patches.never_expire_vehicles && e->player_avail)? -1 : 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
e->reliability = e->reliability_final;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void AddTypeToEngines(void)
|
2005-01-02 17:23:04 +00:00
|
|
|
{
|
2005-07-30 18:04:49 +00:00
|
|
|
Engine* e = _engines;
|
|
|
|
|
|
|
|
do e->type = VEH_Train; while (++e < &_engines[ROAD_ENGINES_INDEX]);
|
|
|
|
do e->type = VEH_Road; while (++e < &_engines[SHIP_ENGINES_INDEX]);
|
|
|
|
do e->type = VEH_Ship; while (++e < &_engines[AIRCRAFT_ENGINES_INDEX]);
|
|
|
|
do e->type = VEH_Aircraft; while (++e < &_engines[TOTAL_NUM_ENGINES]);
|
|
|
|
do e->type = VEH_Special; while (++e < endof(_engines));
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void StartupEngines(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Engine *e;
|
|
|
|
const EngineInfo *ei;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
/* Aging of vehicles stops, so account for that when starting late */
|
2006-08-20 12:39:17 +00:00
|
|
|
const Date aging_date = min(_date, ConvertYMDToDate(YEAR_ENGINE_AGING_STOPS, 0, 1));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SetupEngineNames();
|
|
|
|
|
2005-07-30 18:04:49 +00:00
|
|
|
for (e = _engines, ei = _engine_info; e != endof(_engines); e++, ei++) {
|
|
|
|
uint32 r;
|
2005-01-02 17:23:04 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
e->age = 0;
|
2005-10-18 11:23:58 +00:00
|
|
|
e->railtype = ei->railtype;
|
2004-08-09 17:04:08 +00:00
|
|
|
e->flags = 0;
|
|
|
|
e->player_avail = 0;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-01-24 07:41:28 +00:00
|
|
|
// The magic value of 729 days below comes from the NewGRF spec. If the
|
|
|
|
// base intro date is before 1922 then the random number of days is not
|
|
|
|
// added.
|
2004-08-09 17:04:08 +00:00
|
|
|
r = Random();
|
2006-08-17 20:22:35 +00:00
|
|
|
e->intro_date = ei->base_intro <= ConvertYMDToDate(1922, 0, 1) ? ei->base_intro : (Date)GB(r, 0, 9) + ei->base_intro;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (e->intro_date <= _date) {
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
e->age = (aging_date - e->intro_date) >> 5;
|
2004-08-09 17:04:08 +00:00
|
|
|
e->player_avail = (byte)-1;
|
|
|
|
e->flags |= ENGINE_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2005-07-20 15:29:28 +00:00
|
|
|
e->reliability_start = GB(r, 16, 14) + 0x7AE0;
|
2004-08-09 17:04:08 +00:00
|
|
|
r = Random();
|
2005-07-20 15:29:28 +00:00
|
|
|
e->reliability_max = GB(r, 0, 14) + 0xBFFF;
|
|
|
|
e->reliability_final = GB(r, 16, 14) + 0x3FFF;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
r = Random();
|
2005-07-20 15:29:28 +00:00
|
|
|
e->duration_phase_1 = GB(r, 0, 5) + 7;
|
|
|
|
e->duration_phase_2 = GB(r, 5, 4) + ei->base_life * 12 - 96;
|
|
|
|
e->duration_phase_3 = GB(r, 9, 7) + 120;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
e->reliability_spd_dec = (ei->unk2&0x7F) << 2;
|
|
|
|
|
|
|
|
/* my invented flag for something that is a wagon */
|
|
|
|
if (ei->unk2 & 0x80) {
|
|
|
|
e->age = 0xFFFF;
|
|
|
|
} else {
|
|
|
|
CalcEngineReliability(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
e->lifelength = ei->lifelength + _patches.extend_vehicle_life;
|
|
|
|
|
|
|
|
// prevent certain engines from ever appearing.
|
2005-10-18 11:23:58 +00:00
|
|
|
if (!HASBIT(ei->climates, _opt.landscape)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
e->flags |= ENGINE_AVAILABLE;
|
|
|
|
e->player_avail = 0;
|
|
|
|
}
|
2005-01-06 18:45:28 +00:00
|
|
|
|
2004-12-28 17:18:46 +00:00
|
|
|
/* This sets up type for the engine
|
|
|
|
It is needed if you want to ask the engine what type it is
|
|
|
|
It should hopefully be the same as when you ask a vehicle what it is
|
|
|
|
but using this, you can ask what type an engine number is
|
|
|
|
even if it is not a vehicle (yet)*/
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AdjustAvailAircraft();
|
|
|
|
}
|
|
|
|
|
2006-01-05 12:40:50 +00:00
|
|
|
static void AcceptEnginePreview(Engine *e, PlayerID player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-06-21 16:28:17 +00:00
|
|
|
Player *p = GetPlayer(player);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-20 22:02:58 +00:00
|
|
|
assert(e->railtype < RAILTYPE_END);
|
2004-08-09 17:04:08 +00:00
|
|
|
SETBIT(e->player_avail, player);
|
2005-07-20 22:02:58 +00:00
|
|
|
SETBIT(p->avail_railtypes, e->railtype);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
e->preview_player = 0xFF;
|
|
|
|
InvalidateWindowClasses(WC_BUILD_VEHICLE);
|
2005-01-22 23:11:25 +00:00
|
|
|
InvalidateWindowClasses(WC_REPLACE_VEHICLE);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
static PlayerID GetBestPlayer(PlayerID pp)
|
|
|
|
{
|
|
|
|
const Player *p;
|
|
|
|
int32 best_hist;
|
|
|
|
PlayerID best_player;
|
|
|
|
uint mask = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
best_hist = -1;
|
2005-09-28 19:35:36 +00:00
|
|
|
best_player = OWNER_SPECTATOR;
|
2005-05-11 00:00:27 +00:00
|
|
|
FOR_ALL_PLAYERS(p) {
|
|
|
|
if (p->is_active && p->block_preview == 0 && !HASBIT(mask, p->index) &&
|
|
|
|
p->old_economy[0].performance_history > best_hist) {
|
|
|
|
best_hist = p->old_economy[0].performance_history;
|
|
|
|
best_player = p->index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-28 19:35:36 +00:00
|
|
|
if (best_player == OWNER_SPECTATOR) return OWNER_SPECTATOR;
|
2005-05-11 00:00:27 +00:00
|
|
|
|
|
|
|
SETBIT(mask, best_player);
|
|
|
|
} while (--pp != 0);
|
|
|
|
|
|
|
|
return best_player;
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void EnginesDailyLoop(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID i;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
if (_cur_year >= YEAR_ENGINE_AGING_STOPS) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-30 18:04:49 +00:00
|
|
|
for (i = 0; i != lengthof(_engines); i++) {
|
2006-07-26 03:33:12 +00:00
|
|
|
Engine *e = &_engines[i];
|
2005-07-30 18:04:49 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (e->flags & ENGINE_INTRODUCING) {
|
|
|
|
if (e->flags & ENGINE_PREVIEWING) {
|
2004-12-21 14:42:06 +00:00
|
|
|
if (e->preview_player != 0xFF && !--e->preview_wait) {
|
2004-08-09 17:04:08 +00:00
|
|
|
e->flags &= ~ENGINE_PREVIEWING;
|
|
|
|
DeleteWindowById(WC_ENGINE_PREVIEW, i);
|
|
|
|
e->preview_player++;
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2006-06-27 21:25:53 +00:00
|
|
|
} else if (e->preview_player != 0xFF) {
|
2005-05-11 00:00:27 +00:00
|
|
|
PlayerID best_player = GetBestPlayer(e->preview_player);
|
|
|
|
|
2005-09-28 19:35:36 +00:00
|
|
|
if (best_player == OWNER_SPECTATOR) {
|
2005-05-11 00:00:27 +00:00
|
|
|
e->preview_player = 0xFF;
|
|
|
|
continue;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (!IS_HUMAN_PLAYER(best_player)) {
|
2005-05-11 00:00:27 +00:00
|
|
|
/* XXX - TTDBUG: TTD has a bug here ???? */
|
2004-08-09 17:04:08 +00:00
|
|
|
AcceptEnginePreview(e, best_player);
|
|
|
|
} else {
|
|
|
|
e->flags |= ENGINE_PREVIEWING;
|
|
|
|
e->preview_wait = 20;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (IS_INTERACTIVE_PLAYER(best_player)) ShowEnginePreviewWindow(i);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Accept an engine prototype. XXX - it is possible that the top-player
|
|
|
|
* changes while you are waiting to accept the offer? Then it becomes invalid
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p1 engine-prototype offered
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdWantEnginePreview(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-05-11 00:00:27 +00:00
|
|
|
Engine *e;
|
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
if (!IsEngineIndex(p1)) return CMD_ERROR;
|
2005-06-07 18:13:49 +00:00
|
|
|
e = GetEngine(p1);
|
2005-05-11 00:00:27 +00:00
|
|
|
if (GetBestPlayer(e->preview_player) != _current_player) return CMD_ERROR;
|
|
|
|
|
2006-02-01 06:32:03 +00:00
|
|
|
if (flags & DC_EXEC) AcceptEnginePreview(e, _current_player);
|
2005-05-11 00:00:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2004-09-15 06:51:23 +00:00
|
|
|
// Determine if an engine type is a wagon (and not a loco)
|
2005-10-01 12:43:34 +00:00
|
|
|
static bool IsWagon(EngineID index)
|
2004-09-15 06:51:23 +00:00
|
|
|
{
|
2005-01-10 08:25:43 +00:00
|
|
|
return index < NUM_TRAIN_ENGINES && RailVehInfo(index)->flags & RVI_WAGON;
|
2004-09-15 06:51:23 +00:00
|
|
|
}
|
|
|
|
|
2004-11-14 19:44:06 +00:00
|
|
|
static void NewVehicleAvailable(Engine *e)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Vehicle *v;
|
|
|
|
Player *p;
|
2005-10-01 12:43:34 +00:00
|
|
|
EngineID index = e - _engines;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// In case the player didn't build the vehicle during the intro period,
|
|
|
|
// prevent that player from getting future intro periods for a while.
|
2005-11-14 19:48:04 +00:00
|
|
|
if (e->flags & ENGINE_INTRODUCING) {
|
2004-08-09 17:04:08 +00:00
|
|
|
FOR_ALL_PLAYERS(p) {
|
2005-01-06 22:31:58 +00:00
|
|
|
uint block_preview = p->block_preview;
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (!HASBIT(e->player_avail, p->index)) continue;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
/* We assume the user did NOT build it.. prove me wrong ;) */
|
|
|
|
p->block_preview = 20;
|
|
|
|
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (v->type == VEH_Train || v->type == VEH_Road || v->type == VEH_Ship ||
|
|
|
|
(v->type == VEH_Aircraft && v->subtype <= 2)) {
|
2005-01-06 22:31:58 +00:00
|
|
|
if (v->owner == p->index && v->engine_type == index) {
|
|
|
|
/* The user did prove me wrong, so restore old value */
|
|
|
|
p->block_preview = block_preview;
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-23 07:50:01 +00:00
|
|
|
e->flags = (e->flags & ~ENGINE_INTRODUCING) | ENGINE_AVAILABLE;
|
|
|
|
InvalidateWindowClasses(WC_BUILD_VEHICLE);
|
2005-01-22 23:11:25 +00:00
|
|
|
InvalidateWindowClasses(WC_REPLACE_VEHICLE);
|
2004-08-23 07:50:01 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// Now available for all players
|
|
|
|
e->player_avail = (byte)-1;
|
2004-08-23 07:50:01 +00:00
|
|
|
|
|
|
|
// Do not introduce new rail wagons
|
2005-11-14 19:48:04 +00:00
|
|
|
if (IsWagon(index)) return;
|
2004-08-23 07:50:01 +00:00
|
|
|
|
|
|
|
// make maglev / monorail available
|
2004-08-09 17:04:08 +00:00
|
|
|
FOR_ALL_PLAYERS(p) {
|
2005-07-20 22:02:58 +00:00
|
|
|
if (p->is_active) {
|
|
|
|
assert(e->railtype < RAILTYPE_END);
|
|
|
|
SETBIT(p->avail_railtypes, e->railtype);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-10-01 12:43:34 +00:00
|
|
|
if (index < NUM_TRAIN_ENGINES) {
|
2004-08-09 17:04:08 +00:00
|
|
|
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_TRAINAVAIL), 0, 0);
|
2005-10-01 12:43:34 +00:00
|
|
|
} else if (index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES) {
|
2004-08-09 17:04:08 +00:00
|
|
|
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_ROADAVAIL), 0, 0);
|
2005-10-01 12:43:34 +00:00
|
|
|
} else if (index < NUM_TRAIN_ENGINES + NUM_ROAD_ENGINES + NUM_SHIP_ENGINES) {
|
2004-08-09 17:04:08 +00:00
|
|
|
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_SHIPAVAIL), 0, 0);
|
|
|
|
} else {
|
|
|
|
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_AIRCRAFTAVAIL), 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void EnginesMonthlyLoop(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Engine *e;
|
|
|
|
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
if (_cur_year < YEAR_ENGINE_AGING_STOPS) {
|
2005-07-30 18:04:49 +00:00
|
|
|
for (e = _engines; e != endof(_engines); e++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
// Age the vehicle
|
2005-07-30 18:04:49 +00:00
|
|
|
if (e->flags & ENGINE_AVAILABLE && e->age != 0xFFFF) {
|
2004-08-09 17:04:08 +00:00
|
|
|
e->age++;
|
|
|
|
CalcEngineReliability(e);
|
|
|
|
}
|
|
|
|
|
2006-02-06 10:05:41 +00:00
|
|
|
if (!(e->flags & ENGINE_AVAILABLE) && _date >= (e->intro_date + 365)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
// Introduce it to all players
|
|
|
|
NewVehicleAvailable(e);
|
|
|
|
} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_INTRODUCING)) && _date >= e->intro_date) {
|
|
|
|
// Introduction date has passed.. show introducing dialog to one player.
|
|
|
|
e->flags |= ENGINE_INTRODUCING;
|
2004-09-15 06:51:23 +00:00
|
|
|
|
|
|
|
// Do not introduce new rail wagons
|
2005-01-10 08:25:43 +00:00
|
|
|
if (!IsWagon(e - _engines))
|
2004-09-15 06:51:23 +00:00
|
|
|
e->preview_player = 1; // Give to the player with the highest rating.
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
AdjustAvailAircraft();
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Rename an engine.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2005-05-11 00:00:27 +00:00
|
|
|
* @param p1 engine ID to rename
|
|
|
|
* @param p2 unused
|
|
|
|
*/
|
2006-04-10 07:15:58 +00:00
|
|
|
int32 CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
StringID str;
|
|
|
|
|
2005-05-17 20:58:58 +00:00
|
|
|
if (!IsEngineIndex(p1) || _cmd_text[0] == '\0') return CMD_ERROR;
|
2005-05-11 00:00:27 +00:00
|
|
|
|
2005-05-15 18:50:55 +00:00
|
|
|
str = AllocateNameUnique(_cmd_text, 0);
|
2005-05-11 00:00:27 +00:00
|
|
|
if (str == 0) return CMD_ERROR;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
StringID old_str = _engine_name_strings[p1];
|
|
|
|
_engine_name_strings[p1] = str;
|
|
|
|
DeleteName(old_str);
|
|
|
|
_vehicle_design_names |= 3;
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
} else {
|
|
|
|
DeleteName(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-12 15:52:18 +00:00
|
|
|
/*
|
|
|
|
* returns true if an engine is valid, of the specified type, and buildable by
|
|
|
|
* the current player, false otherwise
|
|
|
|
*
|
|
|
|
* engine = index of the engine to check
|
|
|
|
* type = the type the engine should be of (VEH_xxx)
|
|
|
|
*/
|
|
|
|
bool IsEngineBuildable(uint engine, byte type)
|
|
|
|
{
|
|
|
|
const Engine *e;
|
|
|
|
|
|
|
|
// check if it's an engine that is in the engine array
|
|
|
|
if (!IsEngineIndex(engine)) return false;
|
|
|
|
|
|
|
|
e = GetEngine(engine);
|
|
|
|
|
|
|
|
// check if it's an engine of specified type
|
|
|
|
if (e->type != type) return false;
|
|
|
|
|
|
|
|
// check if it's available
|
|
|
|
if (!HASBIT(e->player_avail, _current_player)) return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* Engine Replacement stuff
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
static void EngineRenewPoolNewBlock(uint start_item); /* Forward declare for initializer of _engine_renew_pool */
|
|
|
|
enum {
|
|
|
|
ENGINE_RENEW_POOL_BLOCK_SIZE_BITS = 3,
|
|
|
|
ENGINE_RENEW_POOL_MAX_BLOCKS = 8000,
|
|
|
|
};
|
|
|
|
|
2006-04-18 18:48:50 +00:00
|
|
|
MemoryPool _engine_renew_pool = { "EngineRe", ENGINE_RENEW_POOL_MAX_BLOCKS, ENGINE_RENEW_POOL_BLOCK_SIZE_BITS, sizeof(EngineRenew), &EngineRenewPoolNewBlock, NULL, 0, 0, NULL };
|
2006-01-12 15:52:18 +00:00
|
|
|
|
|
|
|
static void EngineRenewPoolNewBlock(uint start_item)
|
|
|
|
{
|
|
|
|
EngineRenew *er;
|
|
|
|
|
2006-08-22 16:22:07 +00:00
|
|
|
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
|
|
|
* TODO - This is just a temporary stage, this will be removed. */
|
2006-08-22 22:59:42 +00:00
|
|
|
for (er = GetEngineRenew(start_item); er != NULL; er = (er->index + 1 < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1) : NULL) {
|
2006-01-12 15:52:18 +00:00
|
|
|
er->index = start_item++;
|
|
|
|
er->from = INVALID_ENGINE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static EngineRenew *AllocateEngineRenew(void)
|
|
|
|
{
|
|
|
|
EngineRenew *er;
|
|
|
|
|
2006-08-22 16:22:07 +00:00
|
|
|
/* We don't use FOR_ALL here, because FOR_ALL skips invalid items.
|
|
|
|
* TODO - This is just a temporary stage, this will be removed. */
|
2006-08-22 22:59:42 +00:00
|
|
|
for (er = GetEngineRenew(0); er != NULL; er = (er->index + 1 < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1) : NULL) {
|
2006-08-22 16:22:07 +00:00
|
|
|
if (IsValidEngineRenew(er)) continue;
|
|
|
|
|
|
|
|
er->to = INVALID_ENGINE;
|
|
|
|
er->next = NULL;
|
|
|
|
return er;
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we can add a block to the pool */
|
|
|
|
if (AddBlockToPool(&_engine_renew_pool)) return AllocateEngineRenew();
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the EngineRenew that specifies the replacement of the given
|
|
|
|
* engine type from the given renewlist */
|
|
|
|
static EngineRenew *GetEngineReplacement(EngineRenewList erl, EngineID engine)
|
|
|
|
{
|
2006-08-22 16:22:07 +00:00
|
|
|
EngineRenew *er = (EngineRenew *)erl;
|
|
|
|
|
2006-01-12 15:52:18 +00:00
|
|
|
while (er) {
|
|
|
|
if (er->from == engine) return er;
|
|
|
|
er = er->next;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
void RemoveAllEngineReplacement(EngineRenewList *erl)
|
2006-01-12 15:52:18 +00:00
|
|
|
{
|
2006-08-22 16:22:07 +00:00
|
|
|
EngineRenew *er = (EngineRenew *)(*erl);
|
2006-08-26 14:22:54 +00:00
|
|
|
EngineRenew *next;
|
2006-08-22 16:22:07 +00:00
|
|
|
|
2006-01-12 15:52:18 +00:00
|
|
|
while (er) {
|
2006-08-26 14:22:54 +00:00
|
|
|
next = er->next;
|
|
|
|
DeleteEngineRenew(er);
|
|
|
|
er = next;
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
2006-08-22 16:22:07 +00:00
|
|
|
*erl = NULL; // Empty list
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EngineID EngineReplacement(EngineRenewList erl, EngineID engine)
|
|
|
|
{
|
|
|
|
const EngineRenew *er = GetEngineReplacement(erl, engine);
|
|
|
|
return er == NULL ? INVALID_ENGINE : er->to;
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
int32 AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, uint32 flags)
|
2006-01-12 15:52:18 +00:00
|
|
|
{
|
|
|
|
EngineRenew *er;
|
|
|
|
|
2006-08-22 16:22:07 +00:00
|
|
|
/* Check if the old vehicle is already in the list */
|
2006-01-12 15:52:18 +00:00
|
|
|
er = GetEngineReplacement(*erl, old_engine);
|
|
|
|
if (er != NULL) {
|
|
|
|
if (flags & DC_EXEC) er->to = new_engine;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
er = AllocateEngineRenew();
|
|
|
|
if (er == NULL) return CMD_ERROR;
|
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
|
|
|
er->from = old_engine;
|
|
|
|
er->to = new_engine;
|
|
|
|
|
2006-08-22 16:22:07 +00:00
|
|
|
/* Insert before the first element */
|
|
|
|
er->next = (EngineRenew *)(*erl);
|
|
|
|
*erl = (EngineRenewList)er;
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-07-26 03:33:12 +00:00
|
|
|
int32 RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, uint32 flags)
|
2006-01-12 15:52:18 +00:00
|
|
|
{
|
2006-08-22 16:22:07 +00:00
|
|
|
EngineRenew *er = (EngineRenew *)(*erl);
|
2006-07-26 03:33:12 +00:00
|
|
|
EngineRenew *prev = NULL;
|
2006-01-12 15:52:18 +00:00
|
|
|
|
|
|
|
while (er)
|
|
|
|
{
|
|
|
|
if (er->from == engine) {
|
|
|
|
if (flags & DC_EXEC) {
|
2006-08-22 16:22:07 +00:00
|
|
|
if (prev == NULL) { // First element
|
|
|
|
/* The second becomes the new first element */
|
|
|
|
*erl = (EngineRenewList)er->next;
|
2006-01-12 15:52:18 +00:00
|
|
|
} else {
|
2006-08-22 16:22:07 +00:00
|
|
|
/* Cut this element out */
|
|
|
|
prev->next = er->next;
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
2006-08-26 14:22:54 +00:00
|
|
|
DeleteEngineRenew(er);
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
prev = er;
|
2006-08-22 16:22:07 +00:00
|
|
|
er = er->next;
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
|
|
|
|
2006-08-22 16:22:07 +00:00
|
|
|
return CMD_ERROR;
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const SaveLoad _engine_renew_desc[] = {
|
|
|
|
SLE_VAR(EngineRenew, from, SLE_UINT16),
|
|
|
|
SLE_VAR(EngineRenew, to, SLE_UINT16),
|
|
|
|
|
|
|
|
SLE_REF(EngineRenew, next, REF_ENGINE_RENEWS),
|
|
|
|
|
|
|
|
SLE_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
static void Save_ERNW(void)
|
|
|
|
{
|
|
|
|
EngineRenew *er;
|
|
|
|
|
|
|
|
FOR_ALL_ENGINE_RENEWS(er) {
|
2006-08-22 16:22:07 +00:00
|
|
|
SlSetArrayIndex(er->index);
|
|
|
|
SlObject(er, _engine_renew_desc);
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Load_ERNW(void)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
while ((index = SlIterateArray()) != -1) {
|
|
|
|
EngineRenew *er;
|
|
|
|
|
|
|
|
if (!AddBlockIfNeeded(&_engine_renew_pool, index))
|
|
|
|
error("EngineRenews: failed loading savegame: too many EngineRenews");
|
|
|
|
|
|
|
|
er = GetEngineRenew(index);
|
|
|
|
SlObject(er, _engine_renew_desc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-30 22:16:05 +00:00
|
|
|
static const SaveLoad _engine_desc[] = {
|
2006-08-22 14:38:37 +00:00
|
|
|
SLE_CONDVAR(Engine, intro_date, SLE_FILE_U16 | SLE_VAR_I32, 0, 30),
|
|
|
|
SLE_CONDVAR(Engine, intro_date, SLE_INT32, 31, SL_MAX_VERSION),
|
|
|
|
SLE_CONDVAR(Engine, age, SLE_FILE_U16 | SLE_VAR_I32, 0, 30),
|
|
|
|
SLE_CONDVAR(Engine, age, SLE_INT32, 31, SL_MAX_VERSION),
|
|
|
|
SLE_VAR(Engine, reliability, SLE_UINT16),
|
|
|
|
SLE_VAR(Engine, reliability_spd_dec, SLE_UINT16),
|
|
|
|
SLE_VAR(Engine, reliability_start, SLE_UINT16),
|
|
|
|
SLE_VAR(Engine, reliability_max, SLE_UINT16),
|
|
|
|
SLE_VAR(Engine, reliability_final, SLE_UINT16),
|
|
|
|
SLE_VAR(Engine, duration_phase_1, SLE_UINT16),
|
|
|
|
SLE_VAR(Engine, duration_phase_2, SLE_UINT16),
|
|
|
|
SLE_VAR(Engine, duration_phase_3, SLE_UINT16),
|
|
|
|
|
|
|
|
SLE_VAR(Engine, lifelength, SLE_UINT8),
|
|
|
|
SLE_VAR(Engine, flags, SLE_UINT8),
|
|
|
|
SLE_VAR(Engine, preview_player, SLE_UINT8),
|
|
|
|
SLE_VAR(Engine, preview_wait, SLE_UINT8),
|
|
|
|
SLE_VAR(Engine, railtype, SLE_UINT8),
|
|
|
|
SLE_VAR(Engine, player_avail, SLE_UINT8),
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
// reserve extra space in savegame here. (currently 16 bytes)
|
2006-03-16 00:20:33 +00:00
|
|
|
SLE_CONDNULL(16, 2, SL_MAX_VERSION),
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SLE_END()
|
|
|
|
};
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Save_ENGN(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2005-07-30 18:04:49 +00:00
|
|
|
uint i;
|
|
|
|
|
|
|
|
for (i = 0; i != lengthof(_engines); i++) {
|
2004-08-09 17:04:08 +00:00
|
|
|
SlSetArrayIndex(i);
|
2005-07-30 18:04:49 +00:00
|
|
|
SlObject(&_engines[i], _engine_desc);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void Load_ENGN(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
while ((index = SlIterateArray()) != -1) {
|
2005-06-07 18:13:49 +00:00
|
|
|
SlObject(GetEngine(index), _engine_desc);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
static void LoadSave_ENGS(void)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
SlArray(_engine_name_strings, lengthof(_engine_name_strings), SLE_STRINGID);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ChunkHandler _engine_chunk_handlers[] = {
|
2006-01-12 15:52:18 +00:00
|
|
|
{ 'ENGN', Save_ENGN, Load_ENGN, CH_ARRAY },
|
|
|
|
{ 'ENGS', LoadSave_ENGS, LoadSave_ENGS, CH_RIFF },
|
|
|
|
{ 'ERNW', Save_ERNW, Load_ERNW, CH_ARRAY | CH_LAST},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2006-01-12 15:52:18 +00:00
|
|
|
void InitializeEngines(void)
|
2005-01-27 21:18:03 +00:00
|
|
|
{
|
2006-01-12 15:52:18 +00:00
|
|
|
/* Clean the engine renew pool and create 1 block in it */
|
|
|
|
CleanPool(&_engine_renew_pool);
|
|
|
|
AddBlockToPool(&_engine_renew_pool);
|
2005-01-27 21:00:05 +00:00
|
|
|
}
|