summaryrefslogtreecommitdiff
path: root/station_cmd.c
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2006-05-04 20:00:50 +0000
committerpeter1138 <peter1138@openttd.org>2006-05-04 20:00:50 +0000
commit86b57907824d3bb80b6524d6f221ba4b43f94bf4 (patch)
treec64a76e8f58754388af773e8a9fb32010a359ef7 /station_cmd.c
parent27e7fbaaa0afd3cabcf1289e2fedb48867a33506 (diff)
downloadopenttd-86b57907824d3bb80b6524d6f221ba4b43f94bf4.tar.xz
(svn r4742) - Newstations: Add callbacks for building and drawing custom stations.
Diffstat (limited to 'station_cmd.c')
-rw-r--r--station_cmd.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/station_cmd.c b/station_cmd.c
index b488fa212..e523e491b 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)];
+ }
}
}