Changeset - r3189:4e602cf0aaa8
[Not reviewed]
master
0 4 1
tron - 19 years ago 2006-03-13 12:55:20
tron@openttd.org
(svn r3846) Add functions to set the type of stuff (clear, water, rail, road) under bridges
5 files changed with 67 insertions and 33 deletions:
0 comments (0 inline, 0 general)
bridge_map.h
Show inline comments
 
new file 100644
 
/* $Id$ */
 

	
 
#ifndef BRIDGE_MAP_H
 
#define BRIDGE_MAP_H
 

	
 
#include "macros.h"
 
#include "map.h"
 
#include "rail.h"
 
#include "tile.h"
 

	
 

	
 
static inline void SetClearUnderBridge(TileIndex t)
 
{
 
	SetTileOwner(t, OWNER_NONE);
 
	SB(_m[t].m5, 3, 3, 0 << 2 | 0);
 
}
 

	
 
static inline void SetWaterUnderBridge(TileIndex t)
 
{
 
	SetTileOwner(t, OWNER_WATER);
 
	SB(_m[t].m5, 3, 3, 0 << 2 | 1);
 
}
 

	
 
static inline void SetRailUnderBridge(TileIndex t, Owner o, RailType r)
 
{
 
	SetTileOwner(t, o);
 
	SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_RAIL);
 
	SB(_m[t].m3, 0, 4, r);
 
}
 

	
 
static inline void SetRoadUnderBridge(TileIndex t, Owner o)
 
{
 
	SetTileOwner(t, o);
 
	SB(_m[t].m5, 3, 3, 1 << 2 | TRANSPORT_ROAD);
 
}
 

	
 
#endif
rail_cmd.c
Show inline comments
 
@@ -2,6 +2,7 @@
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "bridge_map.h"
 
#include "debug.h"
 
#include "functions.h"
 
#include "rail_map.h"
 
@@ -299,11 +300,7 @@ int32 CmdBuildSingleRail(int x, int y, u
 
					if (CmdFailed(ret)) return ret;
 
					cost += ret;
 

	
 
					if (flags & DC_EXEC) {
 
						SetTileOwner(tile, _current_player);
 
						SB(_m[tile].m3, 0, 4, p1);
 
						_m[tile].m5 = (m5 & 0xC7) | 0x20; // railroad under bridge
 
					}
 
					if (flags & DC_EXEC) SetRailUnderBridge(tile, _current_player, p1);
 
					break;
 

	
 
				case 0x20: // rail already there
 
@@ -426,8 +423,7 @@ int32 CmdRemoveSingleRail(int x, int y, 
 
			if (!(flags & DC_EXEC))
 
				return _price.remove_rail;
 

	
 
			SetTileOwner(tile, OWNER_NONE);
 
			_m[tile].m5 = _m[tile].m5 & 0xC7;
 
			SetClearUnderBridge(tile);
 
			break;
 

	
 
		case MP_STREET: {
road_cmd.c
Show inline comments
 
@@ -2,6 +2,7 @@
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "bridge_map.h"
 
#include "rail_map.h"
 
#include "road_map.h"
 
#include "table/sprites.h"
 
@@ -140,8 +141,7 @@ int32 CmdRemoveRoad(int x, int y, uint32
 

	
 
			if (flags & DC_EXEC) {
 
				ChangeTownRating(t, -road_remove_cost[(byte)edge_road], RATING_ROAD_MINIMUM);
 
				_m[tile].m5 = ti.map5 & 0xC7;
 
				SetTileOwner(tile, OWNER_NONE);
 
				SetClearUnderBridge(tile);
 
				MarkTileDirtyByTile(tile);
 
			}
 
			return cost;
 
@@ -375,10 +375,8 @@ int32 CmdBuildRoad(int x, int y, uint32 
 
			/* all checked, can build road now! */
 
			cost = _price.build_road * 2;
 
			if (flags & DC_EXEC) {
 
				ModifyTile(tile,
 
					MP_MAPOWNER_CURRENT | MP_MAP5,
 
					(ti.map5 & 0xC7) | 0x28 // map5
 
				);
 
				SetRoadUnderBridge(tile, _current_player);
 
				MarkTileDirtyByTile(tile);
 
			}
 
			return cost;
 

	
tunnelbridge_cmd.c
Show inline comments
 
@@ -7,6 +7,7 @@
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "bridge_map.h"
 
#include "rail_map.h"
 
#include "road_map.h"
 
#include "table/sprites.h"
 
@@ -334,6 +335,8 @@ int32 CmdBuildBridge(int x, int y, uint3
 
	delta = (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
 
	for (i = 0; i != bridge_len; i++) {
 
		TransportType transport_under;
 
		Owner owner_under = OWNER_NONE;
 
		RailType rail_under = INVALID_RAILTYPE;
 
		uint z;
 

	
 
		tile += delta;
 
@@ -354,6 +357,8 @@ int32 CmdBuildBridge(int x, int y, uint3
 
					goto not_valid_below;
 
				}
 
				transport_under = TRANSPORT_RAIL;
 
				owner_under = GetTileOwner(tile);
 
				rail_under = GB(_m[tile].m3, 0, 4);
 
				break;
 

	
 
			case MP_STREET:
 
@@ -362,6 +367,7 @@ int32 CmdBuildBridge(int x, int y, uint3
 
					goto not_valid_below;
 
				}
 
				transport_under = TRANSPORT_ROAD;
 
				owner_under = GetTileOwner(tile);
 
				break;
 

	
 
			default:
 
@@ -408,10 +414,10 @@ not_valid_below:;
 
			_m[tile].m2 = (bridge_type << 4) | piece;
 
			SB(_m[tile].m3, 4, 4, railtype);
 
			switch (transport_under) {
 
				case TRANSPORT_RAIL:  _m[tile].m5 = 0xE0 | TRANSPORT_RAIL << 3 | transport << 1 | direction; break; // rail
 
				case TRANSPORT_ROAD:  _m[tile].m5 = 0xE0 | TRANSPORT_ROAD << 3 | transport << 1 | direction; break; // road
 
				case TRANSPORT_WATER: _m[tile].m5 = 0xC0 |              1 << 3 | transport << 1 | direction; break; // water
 
				default:              _m[tile].m5 = 0xC0 |              0 << 3 | transport << 1 | direction; break; // grass
 
				case TRANSPORT_RAIL:  SetRailUnderBridge(tile, owner_under, rail_under); break;
 
				case TRANSPORT_ROAD:  SetRoadUnderBridge(tile, owner_under); break;
 
				case TRANSPORT_WATER: SetWaterUnderBridge(tile); break;
 
				default:              SetClearUnderBridge(tile); break;
 
			}
 

	
 
			MarkTileDirtyByTile(tile);
 
@@ -644,8 +650,7 @@ static int32 DoClearBridge(TileIndex til
 
		cost = (_m[tile].m5 & 8) ? _price.remove_road * 2 : _price.remove_rail;
 

	
 
		if (flags & DC_EXEC) {
 
			_m[tile].m5 = _m[tile].m5 & ~0x38;
 
			SetTileOwner(tile, OWNER_NONE);
 
			SetClearUnderBridge(tile);
 
			MarkTileDirtyByTile(tile);
 
		}
 
		return cost;
 
@@ -658,8 +663,7 @@ static int32 DoClearBridge(TileIndex til
 
		if (!EnsureNoVehicleZ(tile, TilePixelHeight(tile))) return CMD_ERROR;
 
		cost = _price.clear_water;
 
		if (flags & DC_EXEC) {
 
			_m[tile].m5 = _m[tile].m5 & ~0x38;
 
			SetTileOwner(tile, OWNER_NONE);
 
			SetClearUnderBridge(tile);
 
			MarkTileDirtyByTile(tile);
 
		}
 
		return cost;
 
@@ -1355,7 +1359,7 @@ static void ChangeTileOwner_TunnelBridge
 
			// the stuff BELOW the middle part is owned by the deleted player.
 
			if (!(_m[tile].m5 & (1 << 4 | 1 << 3))) {
 
				// convert railway into grass.
 
				_m[tile].m5 &= ~(1 << 5 | 1 << 4 | 1 << 3); // no transport route under bridge anymore..
 
				SetClearUnderBridge(tile);
 
			} else {
 
				// for road, change the owner of the road to local authority
 
				SetTileOwner(tile, OWNER_NONE);
water_cmd.c
Show inline comments
 
@@ -2,6 +2,7 @@
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "bridge_map.h"
 
#include "table/sprites.h"
 
#include "table/strings.h"
 
#include "functions.h"
 
@@ -248,10 +249,7 @@ int32 CmdBuildCanal(int x, int y, uint32
 
				return_cmd_error(STR_1007_ALREADY_BUILT);
 
			}
 

	
 
			if (flags & DC_EXEC) {
 
				// change owner to OWNER_WATER and set land under bridge bit to water
 
				ModifyTile(tile, MP_MAP5 | MP_MAPOWNER, OWNER_WATER, _m[tile].m5 | 0x08);
 
			}
 
			if (flags & DC_EXEC) SetWaterUnderBridge(tile);
 
		} else {
 
			/* no bridge, try to clear it. */
 
			int32 ret = DoCommandByTile(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
 
@@ -259,13 +257,13 @@ int32 CmdBuildCanal(int x, int y, uint32
 
			if (CmdFailed(ret)) return ret;
 
			cost += ret;
 

	
 
			if (flags & DC_EXEC) {
 
				MakeWater(tile);
 
				MarkTileDirtyByTile(tile);
 
			}
 
			if (flags & DC_EXEC) MakeWater(tile);
 
		}
 

	
 
		if (flags & DC_EXEC) MarkTilesAroundDirty(tile);
 
		if (flags & DC_EXEC) {
 
			MarkTileDirtyByTile(tile);
 
			MarkTilesAroundDirty(tile);
 
		}
 

	
 
		cost += _price.clear_water;
 
	} END_TILE_LOOP(tile, size_x, size_y, 0);
 
@@ -546,7 +544,7 @@ static void TileLoopWaterHelper(TileInde
 
			case MP_TUNNELBRIDGE:
 
				// Middle part of bridge with clear land below?
 
				if ((_m[target].m5 & 0xF8) == 0xC0) {
 
					_m[target].m5 |= 0x08;
 
					SetWaterUnderBridge(target);
 
					MarkTileDirtyByTile(target);
 
				}
 
				break;
 
@@ -560,7 +558,8 @@ static void TileLoopWaterHelper(TileInde
 
			if ((m5 & 0xF8) == 0xC8 || (m5 & 0xF8) == 0xF0) return;
 

	
 
			if ((m5 & 0xC0) == 0xC0) {
 
				ModifyTile(target, MP_MAPOWNER | MP_MAP5, OWNER_WATER, (m5 & ~0x38) | 0x8);
 
				SetWaterUnderBridge(target);
 
				MarkTileDirtyByTile(target);
 
				return;
 
			}
 
		}
0 comments (0 inline, 0 general)