tunnelbridge_cmd.c
changeset 1901 03bf9bf99319
parent 1891 862800791170
child 1902 86b7fb11f938
equal deleted inserted replaced
1900:1f3309a61546 1901:03bf9bf99319
   626 
   626 
   627 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   627 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   628 
   628 
   629 	// in scenario editor you can always destroy tunnels
   629 	// in scenario editor you can always destroy tunnels
   630 	if (_game_mode != GM_EDITOR && !CheckTileOwnership(tile)) {
   630 	if (_game_mode != GM_EDITOR && !CheckTileOwnership(tile)) {
   631 		if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || _map_owner[tile] != OWNER_TOWN)
   631 		if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN))
   632 			return CMD_ERROR;
   632 			return CMD_ERROR;
   633 	}
   633 	}
   634 
   634 
   635 	endtile = CheckTunnelBusy(tile, &length);
   635 	endtile = CheckTunnelBusy(tile, &length);
   636 	if (endtile == INVALID_TILE) return CMD_ERROR;
   636 	if (endtile == INVALID_TILE) return CMD_ERROR;
   638 	_build_tunnel_endtile = endtile;
   638 	_build_tunnel_endtile = endtile;
   639 
   639 
   640 	t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
   640 	t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
   641 	// check if you're allowed to remove the tunnel owned by a town
   641 	// check if you're allowed to remove the tunnel owned by a town
   642 	// removal allowal depends on difficulty settings
   642 	// removal allowal depends on difficulty settings
   643 	if(_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR ) {
   643 	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
   644 		if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE)) {
   644 		if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE)) {
   645 			SetDParam(0, t->index);
   645 			SetDParam(0, t->index);
   646 			return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
   646 			return_cmd_error(STR_2009_LOCAL_AUTHORITY_REFUSES);
   647 		}
   647 		}
   648 	}
   648 	}
   654 		byte endtile_dir = _map5[endtile]&3;
   654 		byte endtile_dir = _map5[endtile]&3;
   655 		DoClearSquare(tile);
   655 		DoClearSquare(tile);
   656 		DoClearSquare(endtile);
   656 		DoClearSquare(endtile);
   657 		UpdateSignalsOnSegment(tile, _updsignals_tunnel_dir[tile_dir]);
   657 		UpdateSignalsOnSegment(tile, _updsignals_tunnel_dir[tile_dir]);
   658 		UpdateSignalsOnSegment(endtile, _updsignals_tunnel_dir[endtile_dir]);
   658 		UpdateSignalsOnSegment(endtile, _updsignals_tunnel_dir[endtile_dir]);
   659 		if (_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR)
   659 		if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
   660 			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
   660 			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
   661 	}
   661 	}
   662 	return  _price.clear_tunnel * (length + 1);
   662 	return  _price.clear_tunnel * (length + 1);
   663 }
   663 }
   664 
   664 
   734 
   734 
   735 	tile = FindEdgesOfBridge(tile, &endtile);
   735 	tile = FindEdgesOfBridge(tile, &endtile);
   736 
   736 
   737 	// floods, scenario editor can always destroy bridges
   737 	// floods, scenario editor can always destroy bridges
   738 	if (_current_player != OWNER_WATER && _game_mode != GM_EDITOR && !CheckTileOwnership(tile)) {
   738 	if (_current_player != OWNER_WATER && _game_mode != GM_EDITOR && !CheckTileOwnership(tile)) {
   739 		if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || _map_owner[tile] != OWNER_TOWN)
   739 		if (!(_patches.extra_dynamite || _cheats.magic_bulldozer.value) || !IsTileOwner(tile, OWNER_TOWN))
   740 			return CMD_ERROR;
   740 			return CMD_ERROR;
   741 	}
   741 	}
   742 
   742 
   743 	if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile))
   743 	if (!EnsureNoVehicle(tile) || !EnsureNoVehicle(endtile))
   744 		return CMD_ERROR;
   744 		return CMD_ERROR;
   761 
   761 
   762 
   762 
   763 	t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
   763 	t = ClosestTownFromTile(tile, (uint)-1); //needed for town rating penalty
   764 	// check if you're allowed to remove the bridge owned by a town.
   764 	// check if you're allowed to remove the bridge owned by a town.
   765 	// removal allowal depends on difficulty settings
   765 	// removal allowal depends on difficulty settings
   766 	if(_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR) {
   766 	if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR) {
   767 		if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE))
   767 		if (!CheckforTownRating(tile, flags, t, TUNNELBRIDGE_REMOVE))
   768 			return CMD_ERROR;
   768 			return CMD_ERROR;
   769 	}
   769 	}
   770 
   770 
   771 	if (flags & DC_EXEC) {
   771 	if (flags & DC_EXEC) {
   773 		uint c = tile;
   773 		uint c = tile;
   774 		uint16 new_data;
   774 		uint16 new_data;
   775 
   775 
   776 		//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
   776 		//checks if the owner is town then decrease town rating by RATING_TUNNEL_BRIDGE_DOWN_STEP until
   777 		// you have a "Poor" (0) town rating
   777 		// you have a "Poor" (0) town rating
   778 		if (_map_owner[tile] == OWNER_TOWN && _game_mode != GM_EDITOR)
   778 		if (IsTileOwner(tile, OWNER_TOWN) && _game_mode != GM_EDITOR)
   779 			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
   779 			ChangeTownRating(t, RATING_TUNNEL_BRIDGE_DOWN_STEP, RATING_TUNNEL_BRIDGE_MINIMUM);
   780 
   780 
   781 		do {
   781 		do {
   782 			m5 = _map5[c];
   782 			m5 = _map5[c];
   783 
   783 
  1279 		if (_map5[tile] & 0x40) {
  1279 		if (_map5[tile] & 0x40) {
  1280 			delta = _map5[tile] & 1 ? TILE_XY(0,-1) : TILE_XY(-1,0);
  1280 			delta = _map5[tile] & 1 ? TILE_XY(0,-1) : TILE_XY(-1,0);
  1281 			do tile += delta; while (_map5[tile] & 0x40);
  1281 			do tile += delta; while (_map5[tile] & 0x40);
  1282 		}
  1282 		}
  1283 	}
  1283 	}
  1284 	td->owner = _map_owner[tile];
  1284 	td->owner = GetTileOwner(tile);
  1285 }
  1285 }
  1286 
  1286 
  1287 
  1287 
  1288 static void AnimateTile_TunnelBridge(uint tile)
  1288 static void AnimateTile_TunnelBridge(uint tile)
  1289 {
  1289 {
  1368 	return 0;
  1368 	return 0;
  1369 }
  1369 }
  1370 
  1370 
  1371 static void ChangeTileOwner_TunnelBridge(uint tile, byte old_player, byte new_player)
  1371 static void ChangeTileOwner_TunnelBridge(uint tile, byte old_player, byte new_player)
  1372 {
  1372 {
  1373 	if (_map_owner[tile] != old_player)
  1373 	if (!IsTileOwner(tile, old_player)) return;
  1374 		return;
       
  1375 
  1374 
  1376 	if (new_player != 255) {
  1375 	if (new_player != 255) {
  1377 		_map_owner[tile] = new_player;
  1376 		_map_owner[tile] = new_player;
  1378 	}	else {
  1377 	}	else {
  1379 		if((_map5[tile] & 0xC0)==0xC0) {
  1378 		if((_map5[tile] & 0xC0)==0xC0) {