From 86b57907824d3bb80b6524d6f221ba4b43f94bf4 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Thu, 4 May 2006 20:00:50 +0000 Subject: [PATCH] (svn r4742) - Newstations: Add callbacks for building and drawing custom stations. --- newgrf_callbacks.h | 11 +++++++++++ station_cmd.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/newgrf_callbacks.h b/newgrf_callbacks.h index 24a697395c..62ce8ac965 100644 --- a/newgrf_callbacks.h +++ b/newgrf_callbacks.h @@ -19,6 +19,14 @@ enum CallbackID { // only for train vehicles CBID_TRAIN_VEHICLE_LENGTH = 0x11, + /* Called (if appropriate bit in callback mask is set) to determine if a + * newstation should be made available to build */ + CBID_STATION_AVAILABILITY = 0x13, + + /* Called (if appropriate bit in callback mask is set) when drawing a tile + * to choose a sprite layout to draw, instead of the standard 0-7 range */ + CBID_STATION_SPRITE_LAYOUT = 0x14, + // Refit capacity, the passed vehicle needs to have its ->cargo_type set to // the cargo we are refitting to, returns the new cargo capacity CBID_VEHICLE_REFIT_CAPACITY = 0x15, @@ -30,6 +38,9 @@ enum CallbackID { /* This callback is called from vehicle purchase lists. It returns a value to be * used as a custom string ID in the 0xD000 range. */ CBID_VEHICLE_ADDITIONAL_TEXT = 0x23, + + /* Called when building a station to customize the tile layout */ + CBID_STATION_TILE_LAYOUT = 0x24, }; /** diff --git a/station_cmd.c b/station_cmd.c index b488fa2126..e523e491be 100644 --- a/station_cmd.c +++ b/station_cmd.c @@ -29,6 +29,8 @@ #include "train.h" #include "water_map.h" #include "industry_map.h" +#include "newgrf_callbacks.h" +#include "newgrf_station.h" enum { /* Max stations: 64000 (64 * 1000) */ @@ -1049,6 +1051,20 @@ int32 CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint3 specindex = AllocateSpecToStation(statspec, st, flags & DC_EXEC); if (specindex == -1) return CMD_ERROR; + if (statspec != NULL) { + /* Perform NewStation checks */ + + /* Check if the station size is permitted */ + if (HASBIT(statspec->disallowed_platforms, numtracks - 1) || HASBIT(statspec->disallowed_lengths, plat_len - 1)) { + return CMD_ERROR; + } + + /* Check if the station is buildable */ + if (HASBIT(statspec->callbackmask, CBM_STATION_AVAIL) && GetStationCallback(CBID_STATION_AVAILABILITY, 0, 0, statspec, NULL, INVALID_TILE) == 0) { + return CMD_ERROR; + } + } + if (flags & DC_EXEC) { TileIndexDiff tile_delta; byte *layout_ptr; @@ -1085,6 +1101,11 @@ int32 CmdBuildRailroadStation(TileIndex tile_org, uint32 flags, uint32 p1, uint3 SetCustomStationSpecIndex(tile, specindex); SetStationTileRandomBits(tile, GB(Random(), 0, 4)); + if (statspec != NULL) { + uint16 callback = GetStationCallback(CBID_STATION_TILE_LAYOUT, 0, 0, statspec, st, tile); + if (callback != CALLBACK_FAILED && callback < 8) SetStationGfx(tile, callback); + } + tile += tile_delta; } while (--w); SetSignalsOnBothDir(tile_org, track); @@ -1992,8 +2013,15 @@ static void DrawTile_Station(TileInfo *ti) relocation = GetCustomStationRelocation(statspec, st, ti->tile); + if (HASBIT(statspec->callbackmask, CBM_CUSTOM_LAYOUT)) { + uint16 callback = GetStationCallback(CBID_STATION_SPRITE_LAYOUT, 0, 0, statspec, st, ti->tile); + if (callback != CALLBACK_FAILED) tile = callback + GetRailStationAxis(ti->tile); + } + /* Ensure the chosen tile layout is valid for this custom station */ - t = &statspec->renderdata[tile < statspec->tiles ? tile : GetRailStationAxis(ti->tile)]; + if (statspec->renderdata != NULL) { + t = &statspec->renderdata[tile < statspec->tiles ? tile : GetRailStationAxis(ti->tile)]; + } } }