tunnelbridge_cmd.c
changeset 3187 6f83f483fed0
parent 3184 118a520164e4
child 3188 d1316a266fa8
equal deleted inserted replaced
3186:4317b5b295c4 3187:6f83f483fed0
     5  * @todo seperate this file into two
     5  * @todo seperate this file into two
     6  */
     6  */
     7 
     7 
     8 #include "stdafx.h"
     8 #include "stdafx.h"
     9 #include "openttd.h"
     9 #include "openttd.h"
       
    10 #include "rail_map.h"
    10 #include "road_map.h"
    11 #include "road_map.h"
    11 #include "table/sprites.h"
    12 #include "table/sprites.h"
    12 #include "table/strings.h"
    13 #include "table/strings.h"
    13 #include "functions.h"
    14 #include "functions.h"
    14 #include "map.h"
    15 #include "map.h"
    21 #include "town.h"
    22 #include "town.h"
    22 #include "sound.h"
    23 #include "sound.h"
    23 #include "variables.h"
    24 #include "variables.h"
    24 #include "bridge.h"
    25 #include "bridge.h"
    25 #include "train.h"
    26 #include "train.h"
       
    27 #include "water_map.h"
    26 
    28 
    27 #include "table/bridge_land.h"
    29 #include "table/bridge_land.h"
    28 
    30 
    29 extern const byte _track_sloped_sprites[14];
    31 extern const byte _track_sloped_sprites[14];
    30 extern const SpriteID _water_shore_sprites[15];
    32 extern const SpriteID _water_shore_sprites[15];
   689 	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
   691 	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
   690 		if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) return CMD_ERROR;
   692 		if (!CheckforTownRating(flags, t, TUNNELBRIDGE_REMOVE)) return CMD_ERROR;
   691 	}
   693 	}
   692 
   694 
   693 	if (flags & DC_EXEC) {
   695 	if (flags & DC_EXEC) {
   694 		byte m5;
   696 		TileIndex c = tile;
   695 		uint c = tile;
       
   696 		uint16 new_data;
       
   697 
   697 
   698 		//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
   698 		//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
   699 		// you have a "Poor" (0) town rating
   699 		// you have a "Poor" (0) town rating
   700 		if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
   700 		if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
   701 			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
   701 			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
   702 
   702 
   703 		do {
   703 		do {
   704 			m5 = _m[c].m5;
   704 			if (!(_m[c].m5 & 0x40)) {
   705 
   705 				// bridge ramp
   706 			if (m5 & 0x40) {
   706 				DoClearSquare(c);
   707 				if (m5 & 0x20) {
       
   708 					static const uint16 _new_data_table[] = {0x1002, 0x1001, 0x2005, 0x200A, 0, 0, 0, 0};
       
   709 					new_data = _new_data_table[((m5 & 0x18) >> 2) | (m5 & 1)];
       
   710 				}	else {
       
   711 					if (GB(m5, 3, 2) == 0) goto clear_it;
       
   712 					new_data = (GetTileSlope(c, NULL) == 0) ? 0x6000 : 0x6001;
       
   713 				}
       
   714 
       
   715 				SetTileType(c, new_data >> 12);
       
   716 				_m[c].m5 = (byte)new_data;
       
   717 				_m[c].m2 = 0;
       
   718 				_m[c].m4 &= 0x0F;
       
   719 
       
   720 				MarkTileDirtyByTile(c);
       
   721 
       
   722 			} else {
   707 			} else {
   723 clear_it:;
   708 				// bridge middle part
   724 				DoClearSquare(c);
   709 				if (_m[c].m5 & 0x20) {
       
   710 					// transport under bridge
       
   711 					if (GB(_m[c].m5, 3, 2) == TRANSPORT_RAIL) {
       
   712 						MakeRailNormal(c, GetTileOwner(c), _m[c].m5 & 1 ? TRACK_BIT_X : TRACK_BIT_Y, GB(_m[c].m3, 0, 3));
       
   713 					} else {
       
   714 						MakeRoadNormal(c, GetTileOwner(c), _m[c].m5 & 1 ? ROAD_X : ROAD_Y, 0); // XXX Determine town, missing till now
       
   715 					}
       
   716 					MarkTileDirtyByTile(c);
       
   717 				} else {
       
   718 					// clear under bridge
       
   719 					if (GB(_m[c].m5, 3, 2) == 0) {
       
   720 						// grass under bridge
       
   721 						DoClearSquare(c);
       
   722 					} else {
       
   723 						// water under bridge
       
   724 						if (GetTileSlope(c, NULL) == 0) {
       
   725 							MakeWater(c);
       
   726 						} else {
       
   727 							MakeShore(c);
       
   728 						}
       
   729 						MarkTileDirtyByTile(c);
       
   730 					}
       
   731 				}
   725 			}
   732 			}
   726 			c += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
   733 			c += (direction == AXIS_X ? TileDiffXY(1, 0) : TileDiffXY(0, 1));
   727 		} while (c <= endtile);
   734 		} while (c <= endtile);
   728 
   735 
   729 		SetSignalsOnBothDir(tile,    direction == AXIS_X ? TRACK_X : TRACK_Y);
   736 		SetSignalsOnBothDir(tile,    direction == AXIS_X ? TRACK_X : TRACK_Y);