summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorpeter1138 <peter1138@openttd.org>2010-01-03 22:44:57 +0000
committerpeter1138 <peter1138@openttd.org>2010-01-03 22:44:57 +0000
commit5ab64809fe72c38d373bdbed6ffa9b6660dd69d6 (patch)
tree49b0a7ac404ffab434ecb124ee9931f0e11d8c7e /src
parent9e2ccca327b309da98217e92f133619a30cc4038 (diff)
downloadopenttd-5ab64809fe72c38d373bdbed6ffa9b6660dd69d6.tar.xz
(svn r18708) -Feature: [NewGRF] Add support for custom station foundation graphics.
Diffstat (limited to 'src')
-rw-r--r--src/landscape.cpp4
-rw-r--r--src/landscape.h2
-rw-r--r--src/newgrf_station.cpp14
-rw-r--r--src/newgrf_station.h1
-rw-r--r--src/station_cmd.cpp59
5 files changed, 74 insertions, 6 deletions
diff --git a/src/landscape.cpp b/src/landscape.cpp
index d42d23c8f..3cc7a6fc8 100644
--- a/src/landscape.cpp
+++ b/src/landscape.cpp
@@ -338,7 +338,7 @@ Slope GetFoundationSlope(TileIndex tile, uint *z)
}
-static bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
+bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
{
uint z;
@@ -355,7 +355,7 @@ static bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here)
}
-static bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
+bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here)
{
uint z;
diff --git a/src/landscape.h b/src/landscape.h
index eef353942..46d263ae5 100644
--- a/src/landscape.h
+++ b/src/landscape.h
@@ -58,6 +58,8 @@ static inline Point RemapCoords2(int x, int y)
uint ApplyFoundationToSlope(Foundation f, Slope *s);
void DrawFoundation(TileInfo *ti, Foundation f);
+bool HasFoundationNW(TileIndex tile, Slope slope_here, uint z_here);
+bool HasFoundationNE(TileIndex tile, Slope slope_here, uint z_here);
void DoClearSquare(TileIndex tile);
void RunTileLoop();
diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp
index 0a0c711f5..5aa42d022 100644
--- a/src/newgrf_station.cpp
+++ b/src/newgrf_station.cpp
@@ -742,6 +742,20 @@ SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const Bas
}
+SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, const BaseStation *st, TileIndex tile)
+{
+ const SpriteGroup *group;
+ ResolverObject object;
+
+ NewStationResolver(&object, statspec, st, tile);
+ object.callback_param1 = 2; // Indicate we are resolving the foundation sprites
+
+ group = ResolveStation(&object);
+ if (group == NULL || group->type != SGT_RESULT) return 0;
+ return group->GetResult() + GetRegister(0x100);
+}
+
+
uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, const BaseStation *st, TileIndex tile)
{
const SpriteGroup *group;
diff --git a/src/newgrf_station.h b/src/newgrf_station.h
index 25d5831c7..b7cab7db9 100644
--- a/src/newgrf_station.h
+++ b/src/newgrf_station.h
@@ -139,6 +139,7 @@ uint32 GetPlatformInfo(Axis axis, byte tile, int platforms, int length, int x, i
* for variational sprite groups. */
SpriteID GetCustomStationRelocation(const StationSpec *statspec, const BaseStation *st, TileIndex tile);
SpriteID GetCustomStationGroundRelocation(const StationSpec *statspec, const BaseStation *st, TileIndex tile);
+SpriteID GetCustomStationFoundationRelocation(const StationSpec *statspec, const BaseStation *st, TileIndex tile);
uint16 GetStationCallback(CallbackID callback, uint32 param1, uint32 param2, const StationSpec *statspec, const BaseStation *st, TileIndex tile);
/* Allocate a StationSpec to a Station. This is called once per build operation. */
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp
index df57900f4..f51a32def 100644
--- a/src/station_cmd.cpp
+++ b/src/station_cmd.cpp
@@ -2316,10 +2316,6 @@ static void DrawTile_Station(TileInfo *ti)
palette = PALETTE_TO_GREY;
}
- /* don't show foundation for docks */
- if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile))
- DrawFoundation(ti, FOUNDATION_LEVELED);
-
if (IsCustomStationSpecIndex(ti->tile)) {
/* look for customization */
st = BaseStation::GetByTile(ti->tile);
@@ -2344,6 +2340,61 @@ static void DrawTile_Station(TileInfo *ti)
if (t == NULL || t->seq == NULL) t = &_station_display_datas[GetStationType(ti->tile)][GetStationGfx(ti->tile)];
+ /* don't show foundation for docks */
+ if (ti->tileh != SLOPE_FLAT && !IsDock(ti->tile)) {
+ if (statspec != NULL && HasBit(statspec->flags, SSF_CUSTOM_FOUNDATIONS)) {
+ /* Station has custom foundations. */
+ SpriteID image = GetCustomStationFoundationRelocation(statspec, st, ti->tile);
+
+ if (HasBit(statspec->flags, SSF_EXTENDED_FOUNDATIONS)) {
+ /* Station provides extended foundations. */
+
+ static const uint8 foundation_parts[] = {
+ 0, 0, 0, 0, // Invalid, Invalid, Invalid, SLOPE_SW
+ 0, 1, 2, 3, // Invalid, SLOPE_EW, SLOPE_SE, SLOPE_WSE
+ 0, 4, 5, 6, // Invalid, SLOPE_NW, SLOPE_NS, SLOPE_NWS
+ 7, 8, 9 // SLOPE_NE, SLOPE_ENW, SLOPE_SEN
+ };
+
+ AddSortableSpriteToDraw(image + foundation_parts[ti->tileh], PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
+ } else {
+ /* Draw simple foundations, built up from 8 possible foundation sprites. */
+
+ /* Each set bit represents one of the eight composite sprites to be drawn.
+ * 'Invalid' entries will not drawn but are included for completeness. */
+ static const uint8 composite_foundation_parts[] = {
+ /* Invalid (00000000), Invalid (11010001), Invalid (11100100), SLOPE_SW (11100000) */
+ 0x00, 0xD1, 0xE4, 0xE0,
+ /* Invalid (11001010), SLOPE_EW (11001001), SLOPE_SE (11000100), SLOPE_WSE (11000000) */
+ 0xCA, 0xC9, 0xC4, 0xC0,
+ /* Invalid (11010010), SLOPE_NW (10010001), SLOPE_NS (11100100), SLOPE_NWS (10100000) */
+ 0xD2, 0x91, 0xE4, 0xA0,
+ /* SLOPE_NE (01001010), SLOPE_ENW (00001001), SLOPE_SEN (01000100) */
+ 0x4A, 0x09, 0x44
+ };
+
+ uint8 parts = composite_foundation_parts[ti->tileh];
+
+ /* If foundations continue beyond the tile's upper sides then
+ * mask out the last two pieces. */
+ uint z;
+ Slope slope = GetFoundationSlope(ti->tile, &z);
+ if (!HasFoundationNW(ti->tile, slope, z)) ClrBit(parts, 6);
+ if (!HasFoundationNE(ti->tile, slope, z)) ClrBit(parts, 7);
+
+ for (int i = 0; i < 8; i++) {
+ if (HasBit(parts, i)) {
+ AddSortableSpriteToDraw(image + i, PAL_NONE, ti->x, ti->y, 16, 16, 7, ti->z);
+ }
+ }
+ }
+
+ OffsetGroundSprite(31, 1);
+ ti->z += ApplyFoundationToSlope(FOUNDATION_LEVELED, &ti->tileh);
+ } else {
+ DrawFoundation(ti, FOUNDATION_LEVELED);
+ }
+ }
if (IsBuoy(ti->tile) || IsDock(ti->tile) || (IsOilRig(ti->tile) && GetWaterClass(ti->tile) != WATER_CLASS_INVALID)) {
if (ti->tileh == SLOPE_FLAT) {