(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
authordarkvater
Fri, 03 Sep 2004 17:57:27 +0000
changeset 149 5f7d4b21df01
parent 148 6a72b12f5588
child 150 636c31df729f
(svn r150) -Fix: [1010833] Turning on the magic bulldozer removes oil rigs
-Fix: [993493] Buildings on water
-Feature: Water floods everything, including vehicles.
clear_cmd.c
industry_cmd.c
lang/english.txt
rail_cmd.c
road_cmd.c
station_cmd.c
unmovable_cmd.c
water_cmd.c
--- a/clear_cmd.c	Fri Sep 03 16:03:17 2004 +0000
+++ b/clear_cmd.c	Fri Sep 03 17:57:27 2004 +0000
@@ -431,7 +431,7 @@
 
 	tile = TILE_FROM_XY(x,y);
 
-	if (!CheckTileOwnership(tile))
+	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
 		return CMD_ERROR;
 
 	if (!EnsureNoVehicle(tile))
--- a/industry_cmd.c	Fri Sep 03 16:03:17 2004 +0000
+++ b/industry_cmd.c	Fri Sep 03 17:57:27 2004 +0000
@@ -378,7 +378,14 @@
 {
 	Industry *i = DEREF_INDUSTRY(_map2[tile]);
 
- if ((_current_player == OWNER_WATER || _game_mode != GM_EDITOR) && !_cheats.magic_bulldozer.value) {
+	/*	* water can destroy industries
+			* in editor you can bulldoze industries
+			* with magic_bulldozer cheat you can destroy industries
+			* (area around OILRIG is water, so water shouldn't flood it
+	*/
+	if ((_current_player != OWNER_WATER && _game_mode != GM_EDITOR &&
+			!_cheats.magic_bulldozer.value) ||
+			(_current_player == OWNER_WATER && i->type == IT_OIL_RIG) ) {
  		SET_DPARAM16(0, STR_4802_COAL_MINE + i->type);
 		return_cmd_error(STR_4800_IN_THE_WAY);
 	}
--- a/lang/english.txt	Fri Sep 03 16:03:17 2004 +0000
+++ b/lang/english.txt	Fri Sep 03 17:57:27 2004 +0000
@@ -2520,6 +2520,7 @@
 STR_B003_FACTORY_DESTROYED_IN_SUSPICIOUS:{BLACK}{BIGFONT}Factory destroyed in suspicious circumstances near {TOWN}!
 STR_B004_UFO_LANDS_NEAR					:{BLACK}{BIGFONT}'UFO' lands near {TOWN}!
 STR_B005_COAL_MINE_SUBSIDENCE_LEAVES	:{BLACK}{BIGFONT}Coal mine subsidence leaves trail of destruction near {TOWN}!
+STR_B006_FLOOD_VEHICLE_DESTROYED		:{BLACK}{BIGFONT}Floods!{}At least {COMMA16} presumed missing or dead after deadly floods!
 
 STR_BRIBE_FAILED					:{WHITE}Your attempted bribery has been
 STR_BRIBE_FAILED_2				:{WHITE}discovered by a regional investigator
--- a/rail_cmd.c	Fri Sep 03 16:03:17 2004 +0000
+++ b/rail_cmd.c	Fri Sep 03 17:57:27 2004 +0000
@@ -1151,7 +1151,7 @@
 
 static int32 RemoveTrainDepot(uint tile, uint32 flags)
 {
-	if (!CheckTileOwnership(tile) && !(_current_player==17))
+	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
 		return CMD_ERROR;
 
 	if (!EnsureNoVehicle(tile))
--- a/road_cmd.c	Fri Sep 03 16:03:17 2004 +0000
+++ b/road_cmd.c	Fri Sep 03 17:57:27 2004 +0000
@@ -630,7 +630,7 @@
 
 static int32 RemoveRoadDepot(uint tile, uint32 flags)
 {
-	if (!CheckTileOwnership(tile))
+	if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER)
 		return CMD_ERROR;
 
 	if (!EnsureNoVehicle(tile))
--- a/station_cmd.c	Fri Sep 03 16:03:17 2004 +0000
+++ b/station_cmd.c	Fri Sep 03 17:57:27 2004 +0000
@@ -905,7 +905,7 @@
 	// make sure the specified tile belongs to the current player, and that it is a railroad station.
 	if (!IS_TILETYPE(tile, MP_STATION) || _map5[tile] >= 8 || !_patches.nonuniform_stations) return CMD_ERROR;
 	st = DEREF_STATION(_map2[tile]);
-	if (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile)) return CMD_ERROR;
+	if (_current_player != OWNER_WATER && (!CheckOwnership(st->owner) || !EnsureNoVehicle(tile))) return CMD_ERROR;
 
 	// if we reached here, it means we can actually delete it. do that.
 	if (flags & DC_EXEC) {
@@ -948,12 +948,15 @@
 }
 
 
-static int32 RemoveRailroadStation(Station *st, uint32 flags)
+static int32 RemoveRailroadStation(Station *st, TileIndex tile, uint32 flags)
 {
-	uint tile;
 	int w,h;
 	int32 cost;
 
+	/* if there is flooding and non-uniform stations are enabled, remove platforms tile by tile */
+	if (_current_player == OWNER_WATER && _patches.nonuniform_stations)
+		return DoCommandByTile(tile, 0, 0, DC_EXEC, CMD_REMOVE_FROM_RAILROAD_STATION);
+
 	/* Current player owns the station? */
 	if (_current_player != OWNER_WATER && !CheckOwnership(st->owner))
 		return CMD_ERROR;
@@ -2434,7 +2437,7 @@
 	st = DEREF_STATION(_map2[tile]);
 
 	if (m5 < 8)
-		return RemoveRailroadStation(st, flags);
+		return RemoveRailroadStation(st, tile, flags);
 
 	// original airports < 67, new airports between 83 - 114
 	if (m5 < 0x43 || ( m5 >= 83 && m5 <= 114) )
--- a/unmovable_cmd.c	Fri Sep 03 16:03:17 2004 +0000
+++ b/unmovable_cmd.c	Fri Sep 03 17:57:27 2004 +0000
@@ -114,39 +114,24 @@
 static int32 ClearTile_Unmovable(uint tile, byte flags)
 {
 	byte m5 = _map5[tile];
-	//Town *t;
 		
 	if (m5 & 0x80) {
 		if (_current_player == OWNER_WATER) 
-			return DoCommandByTile(tile, OWNER_WATER, 0, flags, CMD_DESTROY_COMPANY_HQ);
+			return DoCommandByTile(tile, OWNER_WATER, 0, DC_EXEC, CMD_DESTROY_COMPANY_HQ);
 		return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN);
 	}	
 
 	if (m5 == 3)	// company owned land
 		return DoCommandByTile(tile, 0, 0, flags, CMD_SELL_LAND_AREA);
 
-	//t = ClosestTownFromTile(tile, _patches.dist_local_authority + 20); 	// needed for town penalty
-
-	// checks if you're allowed to remove unmovable things. no remove under rating "%difficulty setting"
-	if (_game_mode != GM_EDITOR) {	
-		if (flags & DC_AUTO || !_cheats.magic_bulldozer.value)
-			return_cmd_error(STR_5800_OBJECT_IN_THE_WAY);
-
-		/*if (!CheckforTownRating(tile, flags, t, UNMOVEABLE_REMOVE)) 
-			return CMD_ERROR;
-		*/
-
-	}
+	// checks if you're allowed to remove unmovable things
+	if (_game_mode != GM_EDITOR && _current_player != OWNER_WATER && ((flags & DC_AUTO || !_cheats.magic_bulldozer.value)) )
+		return_cmd_error(STR_5800_OBJECT_IN_THE_WAY);
 	
 	if (flags & DC_EXEC) {	
 		DoClearSquare(tile);
-		// decreases the town rating by 250;
-		/*if (_game_mode != GM_EDITOR) 
-			ChangeTownRating(t, -250, -100);
-		*/
 	}
 
-	// return _price.build_industry*0.34; 
 	return 0;
 }
 
--- a/water_cmd.c	Fri Sep 03 16:03:17 2004 +0000
+++ b/water_cmd.c	Fri Sep 03 17:57:27 2004 +0000
@@ -4,6 +4,9 @@
 #include "viewport.h"
 #include "command.h"
 #include "town.h"
+#include "news.h"
+
+static void FloodVehicle(Vehicle *v);
 
 bool IsShipDepotTile(TileIndex tile)
 {
@@ -506,11 +509,60 @@
 		}
 
 		_current_player = OWNER_WATER;
+		{
+			Vehicle *v = FindVehicleBetween(tile, tile, 0);
+			if (v != NULL) {FloodVehicle(v);}
+		}
 		if (DoCommandByTile(tile,0,0,DC_EXEC, CMD_LANDSCAPE_CLEAR) != CMD_ERROR)
 			ModifyTile(tile, MP_SETTYPE(MP_WATER) | MP_MAPOWNER | MP_MAP5 | MP_MAP2_CLEAR | MP_MAP3LO_CLEAR | MP_MAP3HI_CLEAR,OWNER_WATER,0);
 	}
 }
 
+static void FloodVehicle(Vehicle *v)
+{
+	Vehicle *u;
+	uint16 pass;
+	if (!(v->vehstatus & VS_CRASHED)) {
+
+		if (v->type == VEH_Road) {	// flood bus/truck
+			pass = 1;	// driver
+			if (v->cargo_type == CT_PASSENGERS)
+				pass += v->cargo_count;
+
+			v->vehstatus |= VS_CRASHED;
+			v->u.road.crashed_ctr = 2000;	// max 2220, disappear pretty fast
+			InvalidateWindow(WC_ROADVEH_LIST, v->owner);
+		}
+		
+		else if (v->type == VEH_Train) {
+			v = GetFirstVehicleInChain(v);
+			u = v;
+			pass = 4;	// driver
+
+			// crash all wagons, and count passangers
+			BEGIN_ENUM_WAGONS(v)
+				if (v->cargo_type == CT_PASSENGERS) pass += v->cargo_count;
+				v->vehstatus |= VS_CRASHED;
+			END_ENUM_WAGONS(v)
+
+			v = u;
+			v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
+			InvalidateWindow(WC_TRAINS_LIST, v->owner);						
+		}
+
+		InvalidateWindowWidget(WC_VEHICLE_VIEW, v->index, 4);
+		InvalidateWindow(WC_VEHICLE_DEPOT, v->tile);
+		
+		SET_DPARAM16(0, pass);
+		AddNewsItem(STR_B006_FLOOD_VEHICLE_DESTROYED,
+			NEWS_FLAGS(NM_THIN, NF_VIEWPORT|NF_VEHICLE, NT_ACCIDENT, 0),
+			v->index,
+			0);
+	}
+	CreateEffectVehicleRel(v,4,4,8,EV_CRASHED_SMOKE);	// show cool destruction effects
+	SndPlayVehicleFx(16, v); // create sound
+}
+
 // called from tunnelbridge_cmd
 void TileLoop_Water(uint tile)
 {