2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-02-23 18:55:07 +00:00
|
|
|
/** @file engine.cpp */
|
|
|
|
|
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"
|
2007-01-27 12:29:55 +00:00
|
|
|
#include "aircraft.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"
|
2007-05-19 09:40:18 +00:00
|
|
|
#include "group.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];
|
|
|
|
|
(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,
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void DeleteCustomEngineNames()
|
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;
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void LoadCustomEngineNames()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-28 10:14:37 +00:00
|
|
|
/* XXX: not done */
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG(misc, 1, "LoadCustomEngineNames: not done");
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void SetupEngineNames()
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void CalcEngineReliability(Engine *e)
|
|
|
|
{
|
|
|
|
uint age = e->age;
|
|
|
|
|
2007-05-10 23:10:23 +00:00
|
|
|
/* 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (age < e->duration_phase_1) {
|
|
|
|
uint start = e->reliability_start;
|
|
|
|
e->reliability = age * (e->reliability_max - start) / e->duration_phase_1 + start;
|
2006-10-07 15:04:22 +00:00
|
|
|
} 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 */
|
2004-08-09 17:04:08 +00:00
|
|
|
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 {
|
2006-10-07 15:04:22 +00:00
|
|
|
/* time's up for this engine.
|
|
|
|
* We will now completely retire this design */
|
|
|
|
e->player_avail = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
e->reliability = e->reliability_final;
|
2007-02-06 11:11:12 +00:00
|
|
|
/* Kick this engine out of the lists */
|
|
|
|
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-10-07 15:04:22 +00:00
|
|
|
InvalidateWindowClasses(WC_BUILD_VEHICLE); // Update to show the new reliability
|
2007-02-06 11:11:12 +00:00
|
|
|
InvalidateWindowClasses(WC_REPLACE_VEHICLE);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void AddTypeToEngines()
|
2005-01-02 17:23:04 +00:00
|
|
|
{
|
2005-07-30 18:04:49 +00:00
|
|
|
Engine* e = _engines;
|
|
|
|
|
2007-03-08 16:27:54 +00:00
|
|
|
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]);
|
2005-01-02 17:23:04 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void StartupEngines()
|
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;
|
|
|
|
e->flags = 0;
|
|
|
|
e->player_avail = 0;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-02-23 18:55:07 +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;
|
|
|
|
|
2007-02-23 18:55:07 +00:00
|
|
|
/* 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
|
2006-09-04 20:40:33 +00:00
|
|
|
* 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-01-24 07:14:09 +00:00
|
|
|
static void AcceptEnginePreview(EngineID eid, PlayerID player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-01-24 07:14:09 +00:00
|
|
|
Engine *e = GetEngine(eid);
|
2007-05-25 08:13:01 +00:00
|
|
|
Player *p = GetPlayer(player);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SETBIT(e->player_avail, player);
|
2007-03-08 16:27:54 +00:00
|
|
|
if (e->type == VEH_TRAIN) {
|
2007-01-24 07:14:09 +00:00
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(eid);
|
|
|
|
|
|
|
|
assert(rvi->railtype < RAILTYPE_END);
|
|
|
|
SETBIT(p->avail_railtypes, rvi->railtype);
|
2007-05-25 08:13:01 +00:00
|
|
|
} else if (e->type == VEH_ROAD) {
|
|
|
|
SETBIT(p->avail_roadtypes, HASBIT(EngInfo(eid)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
|
2007-01-24 07:14:09 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
e->preview_player = INVALID_PLAYER;
|
2006-10-07 14:30:13 +00:00
|
|
|
if (player == _local_player) {
|
2007-02-06 11:11:12 +00:00
|
|
|
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
|
2006-10-07 14:30:13 +00:00
|
|
|
}
|
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;
|
2006-10-14 15:49:43 +00:00
|
|
|
best_player = PLAYER_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-14 15:49:43 +00:00
|
|
|
if (best_player == PLAYER_SPECTATOR) return PLAYER_SPECTATOR;
|
2005-05-11 00:00:27 +00:00
|
|
|
|
|
|
|
SETBIT(mask, best_player);
|
2007-01-10 18:56:51 +00:00
|
|
|
} while (pp--, pp != 0);
|
2005-05-11 00:00:27 +00:00
|
|
|
|
|
|
|
return best_player;
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void EnginesDailyLoop()
|
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
|
|
|
|
2007-02-28 17:06:22 +00:00
|
|
|
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
|
|
|
|
if (e->flags & ENGINE_OFFER_WINDOW_OPEN) {
|
2004-12-21 14:42:06 +00:00
|
|
|
if (e->preview_player != 0xFF && !--e->preview_wait) {
|
2007-02-28 17:06:22 +00:00
|
|
|
e->flags &= ~ENGINE_OFFER_WINDOW_OPEN;
|
2004-08-09 17:04:08 +00:00
|
|
|
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);
|
|
|
|
|
2006-10-14 15:49:43 +00:00
|
|
|
if (best_player == PLAYER_SPECTATOR) {
|
2007-01-10 18:56:51 +00:00
|
|
|
e->preview_player = INVALID_PLAYER;
|
2005-05-11 00:00:27 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-10-14 15:15:56 +00:00
|
|
|
if (!IsHumanPlayer(best_player)) {
|
2005-05-11 00:00:27 +00:00
|
|
|
/* XXX - TTDBUG: TTD has a bug here ???? */
|
2007-01-24 07:14:09 +00:00
|
|
|
AcceptEnginePreview(i, best_player);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
2007-02-28 17:06:22 +00:00
|
|
|
e->flags |= ENGINE_OFFER_WINDOW_OPEN;
|
2004-08-09 17:04:08 +00:00
|
|
|
e->preview_wait = 20;
|
2006-10-14 15:15:56 +00:00
|
|
|
if (IsInteractivePlayer(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
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perfom
|
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;
|
|
|
|
|
2007-01-24 07:14:09 +00:00
|
|
|
if (flags & DC_EXEC) AcceptEnginePreview(p1, _current_player);
|
2005-05-11 00:00:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-02-23 18:55:07 +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
|
|
|
{
|
2007-01-30 11:53:35 +00:00
|
|
|
return index < NUM_TRAIN_ENGINES && RailVehInfo(index)->railveh_type == RAILVEH_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
|
|
|
|
2007-02-23 18:55:07 +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. */
|
2007-02-28 17:06:22 +00:00
|
|
|
if (e->flags & ENGINE_EXCLUSIVE_PREVIEW) {
|
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) {
|
2007-03-08 16:27:54 +00:00
|
|
|
if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_SHIP ||
|
|
|
|
(v->type == VEH_AIRCRAFT && IsNormalAircraft(v))) {
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-28 17:06:22 +00:00
|
|
|
e->flags = (e->flags & ~ENGINE_EXCLUSIVE_PREVIEW) | ENGINE_AVAILABLE;
|
2007-02-06 11:11:12 +00:00
|
|
|
AddRemoveEngineFromAutoreplaceAndBuildWindows(e->type);
|
2004-08-23 07:50:01 +00:00
|
|
|
|
2007-02-23 18:55:07 +00:00
|
|
|
/* Now available for all players */
|
2004-08-09 17:04:08 +00:00
|
|
|
e->player_avail = (byte)-1;
|
2004-08-23 07:50:01 +00:00
|
|
|
|
2007-02-23 18:55:07 +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
|
|
|
|
2007-01-24 07:14:09 +00:00
|
|
|
if (index < NUM_TRAIN_ENGINES) {
|
2007-02-23 18:55:07 +00:00
|
|
|
/* maybe make another rail type available */
|
2007-01-24 07:14:09 +00:00
|
|
|
RailType railtype = RailVehInfo(index)->railtype;
|
|
|
|
assert(railtype < RAILTYPE_END);
|
|
|
|
FOR_ALL_PLAYERS(p) {
|
|
|
|
if (p->is_active) SETBIT(p->avail_railtypes, railtype);
|
2005-07-20 22:02:58 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2007-05-25 08:47:40 +00:00
|
|
|
if ((index - NUM_TRAIN_ENGINES) < NUM_ROAD_ENGINES) {
|
|
|
|
/* maybe make another road type available */
|
|
|
|
FOR_ALL_PLAYERS(p) {
|
|
|
|
if (p->is_active) SETBIT(p->avail_roadtypes, HASBIT(EngInfo(index)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
|
|
|
|
}
|
|
|
|
}
|
2007-03-03 22:03:15 +00:00
|
|
|
AddNewsItem(index, NEWS_FLAGS(NM_CALLBACK, 0, NT_NEW_VEHICLES, DNC_VEHICLEAVAIL), 0, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void EnginesMonthlyLoop()
|
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++) {
|
2007-02-23 18:55:07 +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)) {
|
2007-02-23 18:55:07 +00:00
|
|
|
/* Introduce it to all players */
|
2004-08-09 17:04:08 +00:00
|
|
|
NewVehicleAvailable(e);
|
2007-02-28 17:06:22 +00:00
|
|
|
} else if (!(e->flags & (ENGINE_AVAILABLE|ENGINE_EXCLUSIVE_PREVIEW)) && _date >= e->intro_date) {
|
2007-02-23 18:55:07 +00:00
|
|
|
/* Introduction date has passed.. show introducing dialog to one player. */
|
2007-02-28 17:06:22 +00:00
|
|
|
e->flags |= ENGINE_EXCLUSIVE_PREVIEW;
|
2004-09-15 06:51:23 +00:00
|
|
|
|
2007-02-23 18:55:07 +00:00
|
|
|
/* Do not introduce new rail wagons */
|
2005-01-10 08:25:43 +00:00
|
|
|
if (!IsWagon(e - _engines))
|
2007-01-10 18:56:51 +00:00
|
|
|
e->preview_player = (PlayerID)1; // Give to the player with the highest rating.
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-11 00:00:27 +00:00
|
|
|
/** Rename an engine.
|
2006-04-10 07:15:58 +00:00
|
|
|
* @param tile unused
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param flags operation to perfom
|
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
|
2006-12-03 15:48:21 +00:00
|
|
|
* the given player, false otherwise
|
2006-01-12 15:52:18 +00:00
|
|
|
*
|
|
|
|
* engine = index of the engine to check
|
|
|
|
* type = the type the engine should be of (VEH_xxx)
|
2006-12-03 15:48:21 +00:00
|
|
|
* player = index of the player
|
2006-01-12 15:52:18 +00:00
|
|
|
*/
|
2006-12-03 15:48:21 +00:00
|
|
|
bool IsEngineBuildable(EngineID engine, byte type, PlayerID player)
|
2006-01-12 15:52:18 +00:00
|
|
|
{
|
|
|
|
const Engine *e;
|
|
|
|
|
2007-02-23 18:55:07 +00:00
|
|
|
/* check if it's an engine that is in the engine array */
|
2006-01-12 15:52:18 +00:00
|
|
|
if (!IsEngineIndex(engine)) return false;
|
|
|
|
|
|
|
|
e = GetEngine(engine);
|
|
|
|
|
2007-02-23 18:55:07 +00:00
|
|
|
/* check if it's an engine of specified type */
|
2006-01-12 15:52:18 +00:00
|
|
|
if (e->type != type) return false;
|
|
|
|
|
2007-02-23 18:55:07 +00:00
|
|
|
/* check if it's available */
|
2006-12-03 15:48:21 +00:00
|
|
|
if (!HASBIT(e->player_avail, player)) return false;
|
2006-01-12 15:52:18 +00:00
|
|
|
|
2007-04-26 07:24:19 +00:00
|
|
|
if (type == VEH_TRAIN) {
|
|
|
|
/* Check if the rail type is available to this player */
|
|
|
|
const Player *p = GetPlayer(player);
|
|
|
|
if (!HASBIT(p->avail_railtypes, RailVehInfo(engine)->railtype)) return false;
|
|
|
|
}
|
|
|
|
|
2006-01-12 15:52:18 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-04-20 16:56:55 +00:00
|
|
|
/** Get the default cargo type for a certain engine type
|
|
|
|
* @param engine The ID to get the cargo for
|
|
|
|
* @return The cargo type. CT_INVALID means no cargo capacity
|
|
|
|
*/
|
|
|
|
CargoID GetEngineCargoType(EngineID engine)
|
|
|
|
{
|
|
|
|
assert(IsEngineIndex(engine));
|
|
|
|
|
|
|
|
switch (GetEngine(engine)->type) {
|
|
|
|
case VEH_TRAIN:
|
|
|
|
if (RailVehInfo(engine)->capacity == 0) return CT_INVALID;
|
|
|
|
return RailVehInfo(engine)->cargo_type;
|
|
|
|
|
|
|
|
case VEH_ROAD:
|
|
|
|
if (RoadVehInfo(engine)->capacity == 0) return CT_INVALID;
|
|
|
|
return RoadVehInfo(engine)->cargo_type;
|
|
|
|
|
|
|
|
case VEH_SHIP:
|
|
|
|
if (ShipVehInfo(engine)->capacity == 0) return CT_INVALID;
|
|
|
|
return ShipVehInfo(engine)->cargo_type;
|
|
|
|
|
|
|
|
case VEH_AIRCRAFT:
|
|
|
|
/* all aircraft starts as passenger planes with cargo capacity */
|
|
|
|
return CT_PASSENGERS;
|
|
|
|
|
|
|
|
default: NOT_REACHED(); return CT_INVALID;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-12 15:52:18 +00:00
|
|
|
/************************************************************************
|
|
|
|
* Engine Replacement stuff
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-10-28 11:08:52 +00:00
|
|
|
static void EngineRenewPoolNewBlock(uint start_item);
|
2006-01-12 15:52:18 +00:00
|
|
|
|
2006-12-03 17:27:43 +00:00
|
|
|
DEFINE_OLD_POOL(EngineRenew, EngineRenew, EngineRenewPoolNewBlock, 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-10-28 11:08:52 +00:00
|
|
|
for (er = GetEngineRenew(start_item); er != NULL; er = (er->index + 1U < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1U) : NULL) {
|
2006-01-12 15:52:18 +00:00
|
|
|
er->index = start_item++;
|
|
|
|
er->from = INVALID_ENGINE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static EngineRenew *AllocateEngineRenew()
|
2006-01-12 15:52:18 +00:00
|
|
|
{
|
|
|
|
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-10-28 11:08:52 +00:00
|
|
|
for (er = GetEngineRenew(0); er != NULL; er = (er->index + 1U < GetEngineRenewPoolSize()) ? GetEngineRenew(er->index + 1U) : NULL) {
|
2006-08-22 16:22:07 +00:00
|
|
|
if (IsValidEngineRenew(er)) continue;
|
|
|
|
|
|
|
|
er->to = INVALID_ENGINE;
|
|
|
|
er->next = NULL;
|
2007-05-19 09:40:18 +00:00
|
|
|
er->group_id = DEFAULT_GROUP;
|
2006-08-22 16:22:07 +00:00
|
|
|
return er;
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we can add a block to the pool */
|
2006-10-28 11:08:52 +00:00
|
|
|
if (AddBlockToPool(&_EngineRenew_pool)) return AllocateEngineRenew();
|
2006-01-12 15:52:18 +00:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieves the EngineRenew that specifies the replacement of the given
|
|
|
|
* engine type from the given renewlist */
|
2007-05-19 09:40:18 +00:00
|
|
|
static EngineRenew *GetEngineReplacement(EngineRenewList erl, EngineID engine, GroupID group)
|
2006-01-12 15:52:18 +00:00
|
|
|
{
|
2006-08-22 16:22:07 +00:00
|
|
|
EngineRenew *er = (EngineRenew *)erl;
|
|
|
|
|
2006-01-12 15:52:18 +00:00
|
|
|
while (er) {
|
2007-05-19 09:40:18 +00:00
|
|
|
if (er->from == engine && er->group_id == group) return er;
|
2006-01-12 15:52:18 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
EngineID EngineReplacement(EngineRenewList erl, EngineID engine, GroupID group)
|
2006-01-12 15:52:18 +00:00
|
|
|
{
|
2007-05-19 09:40:18 +00:00
|
|
|
const EngineRenew *er = GetEngineReplacement(erl, engine, group);
|
2006-01-12 15:52:18 +00:00
|
|
|
return er == NULL ? INVALID_ENGINE : er->to;
|
|
|
|
}
|
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
int32 AddEngineReplacement(EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, 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 */
|
2007-05-19 09:40:18 +00:00
|
|
|
er = GetEngineReplacement(*erl, old_engine, group);
|
2006-01-12 15:52:18 +00:00
|
|
|
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;
|
2007-05-19 09:40:18 +00:00
|
|
|
er->group_id = group;
|
2006-01-12 15:52:18 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
int32 RemoveEngineReplacement(EngineRenewList *erl, EngineID engine, GroupID group, 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)
|
|
|
|
{
|
2007-05-19 09:40:18 +00:00
|
|
|
if (er->from == engine && er->group_id == group) {
|
2006-01-12 15:52:18 +00:00
|
|
|
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[] = {
|
2007-05-19 09:40:18 +00:00
|
|
|
SLE_VAR(EngineRenew, from, SLE_UINT16),
|
|
|
|
SLE_VAR(EngineRenew, to, SLE_UINT16),
|
2006-01-12 15:52:18 +00:00
|
|
|
|
2007-05-19 09:40:18 +00:00
|
|
|
SLE_REF(EngineRenew, next, REF_ENGINE_RENEWS),
|
|
|
|
SLE_CONDVAR(EngineRenew, group_id, SLE_UINT16, 60, SL_MAX_VERSION),
|
2006-01-12 15:52:18 +00:00
|
|
|
SLE_END()
|
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Save_ERNW()
|
2006-01-12 15:52:18 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_ERNW()
|
2006-01-12 15:52:18 +00:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
|
|
|
|
while ((index = SlIterateArray()) != -1) {
|
|
|
|
EngineRenew *er;
|
|
|
|
|
2006-10-28 11:08:52 +00:00
|
|
|
if (!AddBlockIfNeeded(&_EngineRenew_pool, index))
|
2006-01-12 15:52:18 +00:00
|
|
|
error("EngineRenews: failed loading savegame: too many EngineRenews");
|
|
|
|
|
|
|
|
er = GetEngineRenew(index);
|
|
|
|
SlObject(er, _engine_renew_desc);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
|
|
|
/* Advanced vehicle lists got added */
|
|
|
|
if (CheckSavegameVersion(60)) er->group_id = DEFAULT_GROUP;
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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),
|
2007-01-24 07:14:09 +00:00
|
|
|
SLE_CONDNULL(1, 0, 44),
|
2006-08-22 14:38:37 +00:00
|
|
|
SLE_VAR(Engine, player_avail, SLE_UINT8),
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-02-23 18:55:07 +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()
|
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Save_ENGN()
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void Load_ENGN()
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
static void LoadSave_ENGS()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
SlArray(_engine_name_strings, lengthof(_engine_name_strings), SLE_STRINGID);
|
|
|
|
}
|
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
extern 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
|
|
|
};
|
|
|
|
|
2007-03-07 11:47:46 +00:00
|
|
|
void InitializeEngines()
|
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 */
|
2006-10-28 11:08:52 +00:00
|
|
|
CleanPool(&_EngineRenew_pool);
|
|
|
|
AddBlockToPool(&_EngineRenew_pool);
|
2005-01-27 21:00:05 +00:00
|
|
|
}
|