From 7da3b3b92d7e4e9b25c4b0d419a4dfb3ea6a3fff Mon Sep 17 00:00:00 2001 From: Darkvater Date: Fri, 25 Mar 2005 17:30:54 +0000 Subject: (svn r2066) - Fix: [ 1164248 ] game crash while AI builds bridge. Also protect bridge building against invalid bridges and some safeguards when drawing. --- tunnelbridge_cmd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'tunnelbridge_cmd.c') diff --git a/tunnelbridge_cmd.c b/tunnelbridge_cmd.c index 4b98be103..df2191dec 100644 --- a/tunnelbridge_cmd.c +++ b/tunnelbridge_cmd.c @@ -197,6 +197,9 @@ int32 CmdBuildBridge(int x, int y, uint32 flags, uint32 p1, uint32 p2) direction = 0; + if (bridge_type >= MAX_BRIDGES) // out of bounds bridge + return_cmd_error(STR_5015_CAN_T_BUILD_BRIDGE_HERE); + /* check if valid, and make sure that (x,y) are smaller than (sx,sy) */ if (x == sx) { if (y == sy) @@ -1046,7 +1049,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti) } // bridge ending. - b = _bridge_sprite_table[_map2[ti->tile]>>4][6]; + b = _bridge_sprite_table[(_map2[ti->tile] >> 4) & 0xF][6]; b += (tmp&(3<<1))*4; /* actually ((tmp>>2)&3)*8 */ b += (tmp&1); // direction if (ti->tileh == 0) b += 4; // sloped "entrance" ? @@ -1106,7 +1109,7 @@ static void DrawTile_TunnelBridge(TileInfo *ti) DrawGroundSprite(image); } // get bridge sprites - b = _bridge_sprite_table[_map2[ti->tile]>>4][_map2[ti->tile]&0xF] + tmp * 4; + b = _bridge_sprite_table[(_map2[ti->tile] >> 4) & 0xF][_map2[ti->tile]&0xF] + tmp * 4; z = GetBridgeHeight(ti) + 5; -- cgit v1.2.3-54-g00ecf