engine.cpp File Reference

#include "stdafx.h"
#include "openttd.h"
#include "debug.h"
#include "engine.h"
#include "player_base.h"
#include "player_func.h"
#include "command_func.h"
#include "news.h"
#include "saveload.h"
#include "variables.h"
#include "train.h"
#include "aircraft.h"
#include "newgrf_cargo.h"
#include "group.h"
#include "strings_func.h"
#include "gfx_func.h"
#include "functions.h"
#include "window_func.h"
#include "date_func.h"
#include "autoreplace_base.h"
#include "autoreplace_gui.h"
#include "string_func.h"
#include "settings_type.h"
#include "table/strings.h"
#include "table/engines.h"

Go to the source code of this file.

Enumerations

enum  { YEAR_ENGINE_AGING_STOPS = 2050 }

Functions

void SetupEngines ()
void ShowEnginePreviewWindow (EngineID engine)
void DeleteCustomEngineNames ()
void LoadCustomEngineNames ()
static void CalcEngineReliability (Engine *e)
void StartupEngines ()
static void AcceptEnginePreview (EngineID eid, PlayerID player)
static PlayerID GetBestPlayer (uint8 pp)
void EnginesDailyLoop ()
CommandCost CmdWantEnginePreview (TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 Accept an engine prototype.
static bool IsWagon (EngineID index)
static void NewVehicleAvailable (Engine *e)
void EnginesMonthlyLoop ()
static bool IsUniqueEngineName (const char *name)
CommandCost CmdRenameEngine (TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 Rename an engine.
bool IsEngineBuildable (EngineID engine, VehicleType type, PlayerID player)
 Check if an engine is buildable.
CargoID GetEngineCargoType (EngineID engine)
 Get the default cargo type for a certain engine type.
static EngineRenewGetEngineReplacement (EngineRenewList erl, EngineID engine, GroupID group)
 Retrieves the EngineRenew that specifies the replacement of the given engine type from the given renewlist.
void RemoveAllEngineReplacement (EngineRenewList *erl)
 Remove all engine replacement settings for the player.
EngineID EngineReplacement (EngineRenewList erl, EngineID engine, GroupID group)
 Retrieve the engine replacement in a given renewlist for an original engine type.
CommandCost AddEngineReplacement (EngineRenewList *erl, EngineID old_engine, EngineID new_engine, GroupID group, uint32 flags)
 Add an engine replacement to the given renewlist.
CommandCost RemoveEngineReplacement (EngineRenewList *erl, EngineID engine, GroupID group, uint32 flags)
 Remove an engine replacement from a given renewlist.
static void Save_ERNW ()
static void Load_ERNW ()
static void Save_ENGN ()
static void Load_ENGN ()
static void Load_ENGS ()
void InitializeEngines ()

Variables

Engine _engines [TOTAL_NUM_ENGINES]
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]
static const SaveLoad _engine_renew_desc []
static const SaveLoad _engine_desc []
const ChunkHandler _engine_chunk_handlers []


Detailed Description

Definition in file engine.cpp.


Function Documentation

CommandCost AddEngineReplacement ( EngineRenewList erl,
EngineID  old_engine,
EngineID  new_engine,
GroupID  group,
uint32  flags 
)

Add an engine replacement to the given renewlist.

Parameters:
erl The renewlist to add to.
old_engine The original engine type.
new_engine The replacement engine type.
flags The calling command flags.
Returns:
0 on success, CMD_ERROR on failure.

Definition at line 514 of file engine.cpp.

References PoolItem< T, Tid, Tpool >::CanAllocateItem(), CMD_ERROR, DC_EXEC, GetEngineReplacement(), EngineRenew::group_id, EngineRenew::next, and EngineRenew::to.

Referenced by AddEngineReplacementForPlayer().

CommandCost CmdRenameEngine ( TileIndex  tile,
uint32  flags,
uint32  p1,
uint32  p2 
)

Rename an engine.

Parameters:
tile unused
flags operation to perfom
p1 engine ID to rename
p2 unused

Definition at line 395 of file engine.cpp.

References _cmd_text, CMD_ERROR, DC_EXEC, MarkWholeScreenDirty(), and return_cmd_error.

CommandCost CmdWantEnginePreview ( TileIndex  tile,
uint32  flags,
uint32  p1,
uint32  p2 
)

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

Parameters:
tile unused
flags operation to perfom
p1 engine-prototype offered
p2 unused

Definition at line 276 of file engine.cpp.

References CMD_ERROR, and DC_EXEC.

EngineID EngineReplacement ( EngineRenewList  erl,
EngineID  engine,
GroupID  group 
)

Retrieve the engine replacement in a given renewlist for an original engine type.

Parameters:
erl The renewlist to search in.
engine Engine type to be replaced.
Returns:
The engine type to replace with, or INVALID_ENGINE if no replacement is in the list.

Definition at line 504 of file engine.cpp.

References DEFAULT_GROUP, GetEngineReplacement(), and EngineRenew::to.

Referenced by EngineReplacementForPlayer().

CargoID GetEngineCargoType ( EngineID  engine  ) 

Get the default cargo type for a certain engine type.

Parameters:
engine The ID to get the cargo for
Returns:
The cargo type. CT_INVALID means no cargo capacity

Definition at line 446 of file engine.cpp.

Referenced by CmdCloneVehicle().

bool IsEngineBuildable ( EngineID  engine,
VehicleType  type,
PlayerID  player 
)

Check if an engine is buildable.

Parameters:
engine index of the engine to check.
type the type the engine should be.
player index of the player.
Returns:
True if an engine is valid, of the specified type, and buildable by the given player.

Definition at line 420 of file engine.cpp.

References HasBit().

Referenced by CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRoadVeh(), CmdBuildShip(), and GenerateReplaceVehList().

void RemoveAllEngineReplacement ( EngineRenewList erl  ) 

Remove all engine replacement settings for the player.

Parameters:
erl The renewlist for a given player.
Returns:
The new renewlist for the player.

Definition at line 491 of file engine.cpp.

References EngineRenew::next.

Referenced by RemoveAllEngineReplacementForPlayer().

CommandCost RemoveEngineReplacement ( EngineRenewList erl,
EngineID  engine,
GroupID  group,
uint32  flags 
)

Remove an engine replacement from a given renewlist.

Parameters:
erl The renewlist from which to remove the replacement
engine The original engine type.
flags The calling command flags.
Returns:
0 on success, CMD_ERROR on failure.

Definition at line 539 of file engine.cpp.

References CMD_ERROR, DC_EXEC, EngineRenew::from, EngineRenew::group_id, and EngineRenew::next.

Referenced by RemoveEngineReplacementForPlayer().


Variable Documentation

const ChunkHandler _engine_chunk_handlers[]

Initial value:

 {
  { 'ENGN', Save_ENGN,     Load_ENGN,     CH_ARRAY          },
  { 'ENGS', NULL,          Load_ENGS,     CH_RIFF           },
  { 'ERNW', Save_ERNW,     Load_ERNW,     CH_ARRAY | CH_LAST},
}

const SaveLoad _engine_desc[] [static]

Initial value:

 {
  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_rank, SLE_UINT8),
      SLE_VAR(Engine, preview_wait,        SLE_UINT8),
  SLE_CONDNULL(1, 0, 44),
      SLE_VAR(Engine, player_avail,        SLE_UINT8),
  SLE_CONDSTR(Engine, name,                SLE_STR, 0,                 84, SL_MAX_VERSION),

  
  SLE_CONDNULL(16, 2, SL_MAX_VERSION),


}

Definition at line 602 of file engine.cpp.

const SaveLoad _engine_renew_desc[] [static]

Initial value:

 {
      SLE_VAR(EngineRenew, from,     SLE_UINT16),
      SLE_VAR(EngineRenew, to,       SLE_UINT16),

      SLE_REF(EngineRenew, next,     REF_ENGINE_RENEWS),
  SLE_CONDVAR(EngineRenew, group_id, SLE_UINT16, 60, SL_MAX_VERSION),

}

Definition at line 566 of file engine.cpp.


Generated on Mon Sep 22 20:34:22 2008 for openttd by  doxygen 1.5.6