summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordominik <dominik@openttd.org>2004-08-13 18:27:33 +0000
committerdominik <dominik@openttd.org>2004-08-13 18:27:33 +0000
commitca120eedad11f826b63bb5505a0f1f61aad740d4 (patch)
tree5791137b0f2b6552ea4bc03afa5cadaf28cf52de
parentecb6f670b0dc4b522fd712657db125162689cf4f (diff)
downloadopenttd-ca120eedad11f826b63bb5505a0f1f61aad740d4.tar.xz
(svn r40) Final slope graphics fix
-rw-r--r--clear_cmd.c6
-rw-r--r--dummy_land.c5
-rw-r--r--industry_cmd.c5
-rw-r--r--landscape.c26
-rw-r--r--rail_cmd.c23
-rw-r--r--road_cmd.c25
-rw-r--r--station_cmd.c6
-rw-r--r--town_cmd.c6
-rw-r--r--tree_cmd.c5
-rw-r--r--ttd.h2
-rw-r--r--tunnelbridge_cmd.c7
-rw-r--r--unmovable_cmd.c6
-rw-r--r--water_cmd.c6
13 files changed, 120 insertions, 8 deletions
diff --git a/clear_cmd.c b/clear_cmd.c
index 6645b5f9c..0308485e8 100644
--- a/clear_cmd.c
+++ b/clear_cmd.c
@@ -514,6 +514,11 @@ static void DrawTile_Clear(TileInfo *ti)
uint GetSlopeZ_Clear(TileInfo *ti) { return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z; }
+uint GetSlopeTileh_Clear(TileInfo *ti)
+{
+ return ti->tileh;
+}
+
static void GetAcceptedCargo_Clear(uint tile, AcceptedCargo *ac)
{
/* unused */
@@ -803,4 +808,5 @@ const TileTypeProcs _tile_type_clear_procs = {
NULL, /* get_produced_cargo_proc */
NULL, /* vehicle_enter_tile_proc */
NULL, /* vehicle_leave_tile_proc */
+ GetSlopeTileh_Clear, /* get_slope_tileh_proc */
};
diff --git a/dummy_land.c b/dummy_land.c
index 48acc8165..e9399d468 100644
--- a/dummy_land.c
+++ b/dummy_land.c
@@ -13,6 +13,10 @@ static uint GetSlopeZ_Dummy(TileInfo *ti) {
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z;
}
+static uint GetSlopeZ_Dummy(TileInfo *ti) {
+ return ti->tileh;
+}
+
static int32 ClearTile_Dummy(uint tile, byte flags) {
return_cmd_error(STR_0001_OFF_EDGE_OF_MAP);
}
@@ -68,5 +72,6 @@ const TileTypeProcs _tile_type_dummy_procs = {
NULL, /* get_produced_cargo_proc */
NULL, /* vehicle_enter_tile_proc */
NULL, /* vehicle_leave_tile_proc */
+ GetSlopeTileh_Dummy, /* get_slope_tileh_proc */
};
diff --git a/industry_cmd.c b/industry_cmd.c
index 895ca0442..17fa7bcd2 100644
--- a/industry_cmd.c
+++ b/industry_cmd.c
@@ -334,6 +334,10 @@ static uint GetSlopeZ_Industry(TileInfo *ti) {
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z;
}
+static uint GetSlopeTileh_Industry(TileInfo *ti) {
+ return 0;
+}
+
static void GetAcceptedCargo_Industry(uint tile, AcceptedCargo *ac)
{
int m5 = _map5[tile];
@@ -1819,6 +1823,7 @@ const TileTypeProcs _tile_type_industry_procs = {
GetProducedCargo_Industry, /* get_produced_cargo_proc */
NULL, /* vehicle_enter_tile_proc */
NULL, /* vehicle_leave_tile_proc */
+ GetSlopeTileh_Industry, /* get_slope_tileh_proc */
};
static const byte _industry_desc[] = {
diff --git a/landscape.c b/landscape.c
index 7863b0e1f..1932d29e2 100644
--- a/landscape.c
+++ b/landscape.c
@@ -237,22 +237,34 @@ uint GetSlopeZ(int x, int y)
assert(z < 256);
*/
-
return _tile_type_procs[ti.type]->get_slope_z_proc(&ti);
}
-/* TODO: add check if this tile has a foundation or not. Since this can't be done easily with the
- current landscape arrays, we might have to add a new TileTypeProc. */
-bool hasFoundation(uint tile)
+// direction=true: check for foundation in east and south corner
+// direction=false: check for foundation in west and south corner
+bool hasFoundation(TileInfo *ti, bool direction)
{
- return true;
+ bool south, other; // southern corner and east/west corner
+ uint slope = _tile_type_procs[ti->type]->get_slope_tileh_proc(ti);
+ south = ((ti->tileh) & 2) != (slope & 2);
+
+ if(direction)
+ other = ((ti->tileh) & 4) != (slope & 4);
+ else
+ other = ((ti->tileh) & 1) != (slope & 1);
+
+ return south || other;
}
void DrawFoundation(TileInfo *ti, uint f)
{
uint32 sprite_base = SPR_SLOPES_BASE-14;
- if(hasFoundation( TILE_FROM_XY(ti->x, ti->y-1) )) sprite_base += 22; // foundation in NW direction
- if(hasFoundation( TILE_FROM_XY(ti->x-1, ti->y) )) sprite_base += 22*2; // foundation in NE direction
+
+ TileInfo ti2;
+ FindLandscapeHeight(&ti2, ti->x, ti->y-1);
+ if(hasFoundation( &ti2, true )) sprite_base += 22; // foundation in NW direction
+ FindLandscapeHeight(&ti2, ti->x-1, ti->y);
+ if(hasFoundation( &ti2, false )) sprite_base += 22*2; // foundation in NE direction
if (f < 15) {
// leveled foundation
diff --git a/rail_cmd.c b/rail_cmd.c
index 66200d307..dd6fd90a9 100644
--- a/rail_cmd.c
+++ b/rail_cmd.c
@@ -1694,6 +1694,28 @@ uint GetSlopeZ_Track(TileInfo *ti)
return z;
}
+uint GetSlopeTileh_Track(TileInfo *ti)
+{
+ // check if it's a foundation
+ if (ti->tileh != 0) {
+ if ((ti->map5 & 0x80) == 0) {
+ uint f = GetRailFoundation(ti->tileh, ti->map5 & 0x3F);
+ if (f != 0) {
+ if (f < 15) {
+ // leveled foundation
+ return 0;
+ }
+ // inclined foundation
+ return _inclined_tileh[f - 15];
+ }
+ } else if ((ti->map5 & 0xC0) == 0xC0) {
+ // depot or checkpoint
+ return 0;
+ }
+ }
+ return ti->tileh;
+}
+
static void GetAcceptedCargo_Track(uint tile, AcceptedCargo *ac)
{
/* not used */
@@ -1949,4 +1971,5 @@ const TileTypeProcs _tile_type_rail_procs = {
NULL, /* get_produced_cargo_proc */
VehicleEnter_Track, /* vehicle_enter_tile_proc */
NULL, /* vehicle_leave_tile_proc */
+ GetSlopeTileh_Track, /* get_slope_tileh_proc */
};
diff --git a/road_cmd.c b/road_cmd.c
index 29e259734..07692c33d 100644
--- a/road_cmd.c
+++ b/road_cmd.c
@@ -875,7 +875,29 @@ uint GetSlopeZ_Road(TileInfo *ti)
}
return GetPartialZ(ti->x&0xF, ti->y&0xF, th) + z;
}
- return z;
+ return z; // normal Z if no slope
+}
+
+uint GetSlopeTileh_Road(TileInfo *ti)
+{
+ // check if it's a foundation
+ if (ti->tileh != 0) {
+ if ((ti->map5 & 0xE0) == 0) { /* road or crossing */
+ uint f = GetRoadFoundation(ti->tileh, ti->map5 & 0x3F);
+ if (f != 0) {
+ if (f < 15) {
+ // leveled foundation
+ return 0;
+ }
+ // inclined foundation
+ return _inclined_tileh[f - 15];
+ }
+ } else if ((ti->map5 & 0xF0) == 0x20) {
+ // depot
+ return 0;
+ }
+ }
+ return ti->tileh;
}
static void GetAcceptedCargo_Road(uint tile, AcceptedCargo *ac)
@@ -1129,4 +1151,5 @@ const TileTypeProcs _tile_type_road_procs = {
NULL, /* get_produced_cargo_proc */
VehicleEnter_Road, /* vehicle_enter_tile_proc */
VehicleLeave_Road, /* vehicle_leave_tile_proc */
+ GetSlopeTileh_Road, /* get_slope_tileh_proc */
};
diff --git a/station_cmd.c b/station_cmd.c
index b54f81b39..74a3308c2 100644
--- a/station_cmd.c
+++ b/station_cmd.c
@@ -1778,6 +1778,11 @@ static uint GetSlopeZ_Station(TileInfo *ti)
return z;
}
+static uint GetSlopeTileh_Station(TileInfo *ti)
+{
+ return 0;
+}
+
static void GetAcceptedCargo_Station(uint tile, AcceptedCargo *ac)
{
/* not used */
@@ -2451,6 +2456,7 @@ const TileTypeProcs _tile_type_station_procs = {
NULL, /* get_produced_cargo_proc */
VehicleEnter_Station, /* vehicle_enter_tile_proc */
NULL, /* vehicle_leave_tile_proc */
+ GetSlopeTileh_Station, /* get_slope_tileh_proc */
};
diff --git a/town_cmd.c b/town_cmd.c
index e889022e1..e68fd9dd2 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -103,6 +103,11 @@ static uint GetSlopeZ_Town(TileInfo *ti)
return (uint16) z;
}
+static uint GetSlopeTileh_Town(TileInfo *ti)
+{
+ return ti->tileh;
+}
+
static void AnimateTile_Town(uint tile)
{
int old;
@@ -1772,6 +1777,7 @@ const TileTypeProcs _tile_type_town_procs = {
NULL, /* get_produced_cargo_proc */
NULL, /* vehicle_enter_tile_proc */
NULL, /* vehicle_leave_tile_proc */
+ GetSlopeTileh_Town, /* get_slope_tileh_proc */
};
diff --git a/tree_cmd.c b/tree_cmd.c
index da1bbe3d2..62761a472 100644
--- a/tree_cmd.c
+++ b/tree_cmd.c
@@ -332,6 +332,10 @@ static uint GetSlopeZ_Trees(TileInfo *ti) {
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z;
}
+static uint GetSlopeTileh_Trees(TileInfo *ti) {
+ return ti->tileh;
+}
+
static int32 ClearTile_Trees(uint tile, byte flags) {
int num;
@@ -644,4 +648,5 @@ const TileTypeProcs _tile_type_trees_procs = {
NULL, /* get_produced_cargo_proc */
NULL, /* vehicle_enter_tile_proc */
NULL, /* vehicle_leave_tile_proc */
+ GetSlopeTileh_Trees, /* get_slope_tileh_proc */
};
diff --git a/ttd.h b/ttd.h
index 6395c5c8c..77f8cb039 100644
--- a/ttd.h
+++ b/ttd.h
@@ -242,6 +242,7 @@ typedef void ChangeTileOwnerProc(uint tile, byte old_player, byte new_player);
* other bits that can be set? */
typedef uint32 VehicleEnterTileProc(Vehicle *v, uint tile, int x, int y);
typedef void VehicleLeaveTileProc(Vehicle *v, uint tile, int x, int y);
+typedef uint GetSlopeTilehProc(TileInfo *ti);
typedef struct {
DrawTileProc *draw_tile_proc;
@@ -257,6 +258,7 @@ typedef struct {
GetProducedCargoProc *get_produced_cargo_proc;
VehicleEnterTileProc *vehicle_enter_tile_proc;
VehicleLeaveTileProc *vehicle_leave_tile_proc;
+ GetSlopeTilehProc *get_slope_tileh_proc;
} TileTypeProcs;
diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c
index 4761c6013..92bafbe65 100644
--- a/tunnelbridge_cmd.c
+++ b/tunnelbridge_cmd.c
@@ -1198,6 +1198,12 @@ static uint GetSlopeZ_TunnelBridge(TileInfo *ti) {
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + z;
}
+static uint GetSlopeTileh_TunnelBridge(TileInfo *ti) {
+ // not accurate, but good enough for slope graphics drawing
+ return 0;
+}
+
+
static void GetAcceptedCargo_TunnelBridge(uint tile, AcceptedCargo *ac)
{
/* not used */
@@ -1478,4 +1484,5 @@ const TileTypeProcs _tile_type_tunnelbridge_procs = {
NULL, /* get_produced_cargo_proc */
VehicleEnter_TunnelBridge, /* vehicle_enter_tile_proc */
NULL, /* vehicle_leave_tile_proc */
+ GetSlopeTileh_TunnelBridge, /* get_slope_tileh_proc */
};
diff --git a/unmovable_cmd.c b/unmovable_cmd.c
index ac72f6f3e..85afec5f1 100644
--- a/unmovable_cmd.c
+++ b/unmovable_cmd.c
@@ -106,6 +106,11 @@ static uint GetSlopeZ_Unmovable(TileInfo *ti)
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z;
}
+static uint GetSlopeTileh_Unmovable(TileInfo *ti)
+{
+ return 0;
+}
+
static int32 ClearTile_Unmovable(uint tile, byte flags)
{
byte m5 = _map5[tile];
@@ -386,4 +391,5 @@ const TileTypeProcs _tile_type_unmovable_procs = {
NULL, /* get_produced_cargo_proc */
NULL, /* vehicle_enter_tile_proc */
NULL, /* vehicle_leave_tile_proc */
+ GetSlopeTileh_Unmovable, /* get_slope_tileh_proc */
};
diff --git a/water_cmd.c b/water_cmd.c
index 14d99d716..2a1ccc111 100644
--- a/water_cmd.c
+++ b/water_cmd.c
@@ -441,6 +441,11 @@ uint GetSlopeZ_Water(TileInfo *ti)
return GetPartialZ(ti->x&0xF, ti->y&0xF, ti->tileh) + ti->z;
}
+uint GetSlopeTileh_Water(TileInfo *ti)
+{
+ return ti->tileh;
+}
+
static void GetAcceptedCargo_Water(uint tile, AcceptedCargo *ac)
{
/* not used */
@@ -608,5 +613,6 @@ const TileTypeProcs _tile_type_water_procs = {
NULL, /* get_produced_cargo_proc */
VehicleEnter_Water, /* vehicle_enter_tile_proc */
NULL, /* vehicle_leave_tile_proc */
+ GetSlopeTileh_Water, /* get_slope_tileh_proc */
};