From a7d8ad0004e00e1d917d636f4d69fd58f5edbfa3 Mon Sep 17 00:00:00 2001 From: celestar Date: Wed, 29 Mar 2006 16:30:26 +0000 Subject: (svn r4150) -Feature: Merged elrails into trunk. Thanks to Tron for lots of code and proofreading, thanks to peter1138 for another lot of code and ideas. --- BUGS | 7 + Makefile | 1 + ai/default/default.c | 45 +- bridge.h | 2 + bridge_map.h | 1 + data/elrailsw.grf | Bin 0 -> 7699 bytes docs/elrail.svg | 1091 +++++++++++++++++++++++++++++++++++++++++++++++ docs/elrail_tile.png | Bin 0 -> 64028 bytes docs/elrail_track.png | Bin 0 -> 62629 bytes docs/landscape.html | 2 +- elrail.c | 352 +++++++++++++++ engine_gui.c | 7 +- gfxinit.c | 3 + lang/english.txt | 4 + misc.c | 3 - newgrf.c | 11 +- npf.c | 24 +- npf.h | 12 +- openttd.c | 69 +++ openttd.dsp | 4 + openttd.vcproj | 3 + pathfind.c | 13 +- pathfind.h | 2 +- player.h | 1 + rail.h | 22 +- rail_cmd.c | 15 +- rail_map.h | 9 +- railtypes.h | 65 ++- road_cmd.c | 1 + saveload.c | 2 +- station_cmd.c | 2 + table/elrail_data.h | 362 ++++++++++++++++ table/engines.h | 15 +- table/landscape_const.h | 29 -- table/sprites.h | 64 ++- train_cmd.c | 87 +++- train_gui.c | 4 +- tunnelbridge_cmd.c | 13 +- variables.h | 1 - vehicle.c | 4 + vehicle.h | 2 + vehicle_gui.c | 26 +- 42 files changed, 2258 insertions(+), 122 deletions(-) create mode 100644 BUGS create mode 100644 data/elrailsw.grf create mode 100644 docs/elrail.svg create mode 100644 docs/elrail_tile.png create mode 100644 docs/elrail_track.png create mode 100644 elrail.c create mode 100644 table/elrail_data.h diff --git a/BUGS b/BUGS new file mode 100644 index 000000000..bcdcee6f2 --- /dev/null +++ b/BUGS @@ -0,0 +1,7 @@ +/* $Id */ + +KNOWN BUGS / PROBLEMS: + +Normal and elrail depots look the same. Use 'X' (transparent buildings) + to distinguish between them +Missing curors / icons for construction (currently using the conventional ones) diff --git a/Makefile b/Makefile index 5fb9a1eb7..4de699a2a 100644 --- a/Makefile +++ b/Makefile @@ -630,6 +630,7 @@ SRCS += dock_gui.c SRCS += driver.c SRCS += dummy_land.c SRCS += economy.c +SRCS += elrail.c SRCS += engine.c SRCS += engine_gui.c SRCS += fileio.c diff --git a/ai/default/default.c b/ai/default/default.c index 2a638e3e9..8c4d2569e 100644 --- a/ai/default/default.c +++ b/ai/default/default.c @@ -126,7 +126,7 @@ static void AiStateVehLoop(Player *p) p->ai.state_counter = 0; } -static EngineID AiChooseTrainToBuild(byte railtype, int32 money, byte flag, TileIndex tile) +static EngineID AiChooseTrainToBuild(RailType railtype, int32 money, byte flag, TileIndex tile) { EngineID best_veh_index = INVALID_ENGINE; byte best_veh_score = 0; @@ -137,7 +137,7 @@ static EngineID AiChooseTrainToBuild(byte railtype, int32 money, byte flag, Tile const RailVehicleInfo *rvi = RailVehInfo(i); const Engine* e = GetEngine(i); - if (e->railtype != railtype || + if (!IsCompatibleRail(e->railtype, railtype) || rvi->flags & RVI_WAGON || (rvi->flags & RVI_MULTIHEAD && flag & 1) || !HASBIT(e->player_avail, _current_player) || @@ -2321,6 +2321,41 @@ static StationID AiGetStationIdByDef(TileIndex tile, int id) return GetStationIndex(TILE_ADD(tile, ToTileIndexDiff(p->tileoffs))); } +static EngineID AiFindBestWagon(CargoID cargo, RailType railtype) +{ + EngineID best_veh_index = INVALID_ENGINE; + EngineID i; + uint16 best_capacity = 0; + uint16 best_speed = 0; + uint speed; + + for (i = 0; i < NUM_TRAIN_ENGINES; i++) { + const RailVehicleInfo *rvi = RailVehInfo(i); + const Engine* e = GetEngine(i); + + if (!IsCompatibleRail(e->railtype, railtype) || + !(rvi->flags & RVI_WAGON) || + !HASBIT(e->player_avail, _current_player)) { + continue; + } + + if (rvi->cargo_type != cargo) { + continue; + } + + /* max_speed of 0 indicates no speed limit */ + speed = rvi->max_speed == 0 ? 0xFFFF : rvi->max_speed; + + if (rvi->capacity >= best_capacity && speed >= best_speed) { + best_capacity = rvi->capacity; + best_speed = best_speed; + best_veh_index = i; + } + } + + return best_veh_index; +} + static void AiStateBuildRailVeh(Player *p) { const AiDefaultBlockData *ptr; @@ -2337,10 +2372,14 @@ static void AiStateBuildRailVeh(Player *p) tile = TILE_ADD(p->ai.src.use_tile, ToTileIndexDiff(ptr->tileoffs)); + cargo = p->ai.cargo_type; for (i = 0;;) { if (p->ai.wagon_list[i] == INVALID_VEHICLE) { - veh = _cargoc.ai_railwagon[p->ai.railtype_to_use][cargo]; + veh = AiFindBestWagon(cargo, p->ai.railtype_to_use); + /* veh will return INVALID_ENGINE if no suitable wagon is available. + * We shall treat this in the same way as having no money */ + if (veh == INVALID_ENGINE) goto handle_nocash; cost = DoCommandByTile(tile, veh, 0, DC_EXEC, CMD_BUILD_RAIL_VEHICLE); if (CmdFailed(cost)) goto handle_nocash; p->ai.wagon_list[i] = _new_wagon_id; diff --git a/bridge.h b/bridge.h index 79ea4fbde..18fcf81de 100644 --- a/bridge.h +++ b/bridge.h @@ -22,4 +22,6 @@ typedef struct Bridge { extern const Bridge orig_bridge[MAX_BRIDGES]; extern Bridge _bridge[MAX_BRIDGES]; +uint GetBridgeFoundation(uint tileh, Axis axis); + #endif /* BRIDGE_H */ diff --git a/bridge_map.h b/bridge_map.h index f799077b3..014a3671c 100644 --- a/bridge_map.h +++ b/bridge_map.h @@ -127,6 +127,7 @@ TileIndex GetSouthernBridgeEnd(TileIndex t); */ TileIndex GetOtherBridgeEnd(TileIndex); +uint GetBridgeHeight(TileIndex t); static inline void SetClearUnderBridge(TileIndex t) { diff --git a/data/elrailsw.grf b/data/elrailsw.grf new file mode 100644 index 000000000..f722d1e3a Binary files /dev/null and b/data/elrailsw.grf differ diff --git a/docs/elrail.svg b/docs/elrail.svg new file mode 100644 index 000000000..39098a388 --- /dev/null +++ b/docs/elrail.svg @@ -0,0 +1,1091 @@ + + + + + + + + + image/svg+xml + + + + + + + + N + + Pylon Control Point (PCP) + + + + + + + + + + + + + + + + not allowed, not owned + not allowed, owned + allowed, owned + allowed, not owned + Pylon Position Point (PPP) + + + + + + + + + + + + + + + + + + + + + + + + + + + + not allowed, but preferred (end of line marker) + not allowed + preferred, allowed + allowed + Pylon Position Point (PPP) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + preferred, allowed andcan be ignored to createlong wires (which span2 tiles) + + diff --git a/docs/elrail_tile.png b/docs/elrail_tile.png new file mode 100644 index 000000000..82407de48 Binary files /dev/null and b/docs/elrail_tile.png differ diff --git a/docs/elrail_track.png b/docs/elrail_track.png new file mode 100644 index 000000000..af88bd331 Binary files /dev/null and b/docs/elrail_track.png differ diff --git a/docs/landscape.html b/docs/landscape.html index 92fed219e..b28a8932f 100644 --- a/docs/landscape.html +++ b/docs/landscape.html @@ -129,7 +129,7 @@ m5 bit 7 clear: railway track B  fence on the N side (track in the S corner) C  on snow or desert -
  • m3 bits 0..3 = track type: 0 - conventional railway, 1 - monorail, 2 - maglev +
  • m3 bits 0..3 = track type: 0 - conventional railway, 1 - electrified railway, 2 - monorail, 3 - maglev m5 bits 7 and 6 set: railway depot / checkpoints