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"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "engine.h"
|
2008-01-12 14:10:35 +00:00
|
|
|
#include "player_base.h"
|
|
|
|
#include "player_func.h"
|
2007-12-21 21:50:46 +00:00
|
|
|
#include "command_func.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#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"
|
2007-05-19 09:40:18 +00:00
|
|
|
#include "group.h"
|
2007-08-02 22:32:47 +00:00
|
|
|
#include "misc/autoptr.hpp"
|
2007-12-21 19:49:27 +00:00
|
|
|
#include "strings_func.h"
|
2008-01-09 09:57:48 +00:00
|
|
|
#include "gfx_func.h"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "functions.h"
|
|
|
|
#include "window_func.h"
|
2007-12-26 13:50:40 +00:00
|
|
|
#include "date_func.h"
|
2008-01-07 09:19:53 +00:00
|
|
|
#include "autoreplace_base.h"
|
|
|
|
#include "autoreplace_gui.h"
|
2008-01-07 14:23:25 +00:00
|
|
|
#include "string_func.h"
|
2008-01-13 14:37:30 +00:00
|
|
|
#include "settings_type.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
#include "table/engines.h"
|
|
|
|
|
2008-01-13 13:36:01 +00:00
|
|
|
Engine _engines[TOTAL_NUM_ENGINES];
|
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
|
|
|
|
2008-01-08 18:25:51 +00:00
|
|
|
void SetupEngines()
|
|
|
|
{
|
|
|
|
/* Copy original static engine data */
|
2008-01-09 10:15:20 +00:00
|
|
|
memcpy(&_engine_info, &_orig_engine_info, sizeof(_orig_engine_info));
|
|
|
|
memcpy(&_rail_vehicle_info, &_orig_rail_vehicle_info, sizeof(_orig_rail_vehicle_info));
|
|
|
|
memcpy(&_ship_vehicle_info, &_orig_ship_vehicle_info, sizeof(_orig_ship_vehicle_info));
|
|
|
|
memcpy(&_aircraft_vehicle_info, &_orig_aircraft_vehicle_info, sizeof(_orig_aircraft_vehicle_info));
|
|
|
|
memcpy(&_road_vehicle_info, &_orig_road_vehicle_info, sizeof(_orig_road_vehicle_info));
|
2008-01-08 18:25:51 +00:00
|
|
|
|
|
|
|
/* Add type to engines */
|
|
|
|
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]);
|
2008-01-12 19:58:06 +00:00
|
|
|
|
|
|
|
/* Set up default engine names */
|
|
|
|
for (EngineID engine = 0; engine < TOTAL_NUM_ENGINES; engine++) {
|
|
|
|
EngineInfo *ei = &_engine_info[engine];
|
|
|
|
ei->string_id = STR_8000_KIRBY_PAUL_TANK_STEAM + engine;
|
|
|
|
}
|
2008-01-08 18:25:51 +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
|
|
|
{
|
2008-01-12 19:58:06 +00:00
|
|
|
Engine *e;
|
|
|
|
FOR_ALL_ENGINES(e) {
|
|
|
|
free(e->name);
|
|
|
|
e->name = NULL;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_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
|
|
|
}
|
|
|
|
|
|
|
|
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 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
|
|
|
|
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. */
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(ei->climates, _opt.landscape)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
e->flags |= ENGINE_AVAILABLE;
|
|
|
|
e->player_avail = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2007-11-20 13:35:54 +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);
|
2007-11-20 13:35:54 +00:00
|
|
|
SetBit(p->avail_railtypes, rvi->railtype);
|
2007-05-25 08:13:01 +00:00
|
|
|
} else if (e->type == VEH_ROAD) {
|
2007-11-20 13:35:54 +00:00
|
|
|
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) {
|
2007-11-19 21:02:30 +00:00
|
|
|
if (p->is_active && p->block_preview == 0 && !HasBit(mask, p->index) &&
|
2005-05-11 00:00:27 +00:00
|
|
|
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
|
|
|
|
2007-11-20 13:35:54 +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
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost 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
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2007-11-19 21:02:30 +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
|
|
|
|
2008-01-08 18:16:26 +00:00
|
|
|
if (e->type == VEH_TRAIN) {
|
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) {
|
2007-11-20 13:35:54 +00:00
|
|
|
if (p->is_active) SetBit(p->avail_railtypes, railtype);
|
2005-07-20 22:02:58 +00:00
|
|
|
}
|
2008-01-08 18:16:26 +00:00
|
|
|
} else if (e->type == VEH_ROAD) {
|
2007-05-25 08:47:40 +00:00
|
|
|
/* maybe make another road type available */
|
|
|
|
FOR_ALL_PLAYERS(p) {
|
2007-11-20 13:35:54 +00:00
|
|
|
if (p->is_active) SetBit(p->avail_roadtypes, HasBit(EngInfo(index)->misc_flags, EF_ROAD_TRAM) ? ROADTYPE_TRAM : ROADTYPE_ROAD);
|
2007-05-25 08:47:40 +00:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
{
|
(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) {
|
2008-01-24 10:47:44 +00:00
|
|
|
Engine *e;
|
|
|
|
FOR_ALL_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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-27 20:53:25 +00:00
|
|
|
static bool IsUniqueEngineName(const char *name)
|
|
|
|
{
|
|
|
|
char buf[512];
|
|
|
|
|
|
|
|
for (EngineID i = 0; i < TOTAL_NUM_ENGINES; i++) {
|
|
|
|
SetDParam(0, i);
|
|
|
|
GetString(buf, STR_ENGINE_NAME, lastof(buf));
|
|
|
|
if (strcmp(buf, name) == 0) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*/
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost CmdRenameEngine(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-06-27 20:53:25 +00:00
|
|
|
if (!IsEngineIndex(p1) || StrEmpty(_cmd_text)) return CMD_ERROR;
|
|
|
|
|
|
|
|
if (!IsUniqueEngineName(_cmd_text)) return_cmd_error(STR_NAME_MUST_BE_UNIQUE);
|
2005-05-11 00:00:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (flags & DC_EXEC) {
|
2008-01-12 19:58:06 +00:00
|
|
|
Engine *e = GetEngine(p1);
|
|
|
|
free(e->name);
|
|
|
|
e->name = strdup(_cmd_text);
|
2004-08-09 17:04:08 +00:00
|
|
|
_vehicle_design_names |= 3;
|
|
|
|
MarkWholeScreenDirty();
|
|
|
|
}
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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 */
|
2007-11-19 21:02:30 +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);
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(p->avail_railtypes, RailVehInfo(engine)->railtype)) return false;
|
2007-04-26 07:24:19 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
************************************************************************/
|
|
|
|
|
2007-08-02 22:32:47 +00:00
|
|
|
DEFINE_OLD_POOL_GENERIC(EngineRenew, EngineRenew)
|
2006-01-12 15:52:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
2007-08-02 22:32:47 +00:00
|
|
|
while (er != NULL) {
|
2006-08-26 14:22:54 +00:00
|
|
|
next = er->next;
|
2007-08-02 22:32:47 +00:00
|
|
|
delete er;
|
2006-08-26 14:22:54 +00:00
|
|
|
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);
|
2008-01-16 01:27:24 +00:00
|
|
|
if (er == NULL && (group == DEFAULT_GROUP || (IsValidGroupID(group) && !GetGroup(group)->replace_protection))) {
|
|
|
|
/* We didn't find anything useful in the vehicle's own group so we will try ALL_GROUP */
|
|
|
|
er = GetEngineReplacement(erl, engine, ALL_GROUP);
|
|
|
|
}
|
2006-01-12 15:52:18 +00:00
|
|
|
return er == NULL ? INVALID_ENGINE : er->to;
|
|
|
|
}
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost 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;
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
|
|
|
|
2007-08-02 22:32:47 +00:00
|
|
|
er = new EngineRenew(old_engine, new_engine);
|
2006-01-12 15:52:18 +00:00
|
|
|
if (er == NULL) return CMD_ERROR;
|
2007-08-02 22:32:47 +00:00
|
|
|
AutoPtrT<EngineRenew> er_auto_delete = er;
|
|
|
|
|
2006-01-12 15:52:18 +00:00
|
|
|
|
|
|
|
if (flags & DC_EXEC) {
|
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;
|
2007-08-02 22:32:47 +00:00
|
|
|
|
|
|
|
er_auto_delete.Detach();
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
|
|
|
|
2007-06-18 10:48:15 +00:00
|
|
|
CommandCost 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
|
|
|
}
|
2007-08-02 22:32:47 +00:00
|
|
|
delete er;
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
2007-06-18 19:53:50 +00:00
|
|
|
return CommandCost();
|
2006-01-12 15:52:18 +00:00
|
|
|
}
|
|
|
|
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) {
|
2007-08-02 22:32:47 +00:00
|
|
|
EngineRenew *er = new (index) EngineRenew();
|
2006-01-12 15:52:18 +00:00
|
|
|
SlObject(er, _engine_renew_desc);
|
2007-05-19 09:40:18 +00:00
|
|
|
|
2007-07-14 23:10:27 +00:00
|
|
|
/* Advanced vehicle lists, ungrouped vehicles got added */
|
|
|
|
if (CheckSavegameVersion(60)) {
|
|
|
|
er->group_id = ALL_GROUP;
|
|
|
|
} else if (CheckSavegameVersion(71)) {
|
|
|
|
if (er->group_id == DEFAULT_GROUP) er->group_id = ALL_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),
|
2008-01-12 19:58:06 +00:00
|
|
|
SLE_CONDSTR(Engine, name, SLE_STR, 0, 84, SL_MAX_VERSION),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-12 19:58:06 +00:00
|
|
|
static void Load_ENGS()
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2008-01-12 19:58:06 +00:00
|
|
|
StringID names[TOTAL_NUM_ENGINES];
|
|
|
|
|
|
|
|
SlArray(names, lengthof(names), SLE_STRINGID);
|
|
|
|
|
|
|
|
for (EngineID engine = 0; engine < lengthof(names); engine++) {
|
|
|
|
Engine *e = GetEngine(engine);
|
|
|
|
e->name = CopyFromOldName(names[engine]);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
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 },
|
2008-01-12 19:58:06 +00:00
|
|
|
{ 'ENGS', NULL, Load_ENGS, CH_RIFF },
|
2006-01-12 15:52:18 +00:00
|
|
|
{ '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 */
|
2007-08-02 22:32:47 +00:00
|
|
|
_EngineRenew_pool.CleanPool();
|
|
|
|
_EngineRenew_pool.AddBlockToPool();
|
2008-01-12 19:58:06 +00:00
|
|
|
|
|
|
|
Engine *e;
|
|
|
|
FOR_ALL_ENGINES(e) {
|
|
|
|
free(e->name);
|
|
|
|
e->name = NULL;
|
|
|
|
}
|
2005-01-27 21:00:05 +00:00
|
|
|
}
|