src/water_cmd.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
--- a/src/water_cmd.cpp	Wed Jun 13 12:05:56 2007 +0000
+++ b/src/water_cmd.cpp	Tue Jun 19 07:21:01 2007 +0000
@@ -56,11 +56,11 @@
  * @param p1 bit 0 depot orientation (Axis)
  * @param p2 unused
  */
-int32 CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	TileIndex tile2;
 
-	int32 cost, ret;
+	CommandCost cost, ret;
 	Depot *depot;
 
 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
@@ -101,7 +101,7 @@
 	return cost + _eco->GetPrice(CEconomy::BUILD_SHIP_DEPOT);
 }
 
-static int32 RemoveShipDepot(TileIndex tile, uint32 flags)
+static CommandCost RemoveShipDepot(TileIndex tile, uint32 flags)
 {
 	TileIndex tile2;
 
@@ -127,9 +127,9 @@
 }
 
 /** build a shiplift */
-static int32 DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags)
+static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags)
 {
-	int32 ret;
+	CommandCost ret;
 	int delta;
 
 	/* middle tile */
@@ -167,7 +167,7 @@
 	return _eco->GetPrice(CEconomy::CLEAR_WATER) * 22 >> 3;
 }
 
-static int32 RemoveShiplift(TileIndex tile, uint32 flags)
+static CommandCost RemoveShiplift(TileIndex tile, uint32 flags)
 {
 	TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
 
@@ -200,7 +200,7 @@
  * @param p1 unused
  * @param p2 unused
  */
-int32 CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
 	DiagDirection dir;
 
@@ -222,9 +222,9 @@
  * @param p1 start tile of stretch-dragging
  * @param p2 ctrl pressed - toggles ocean / canals at sealevel (ocean only allowed in the scenario editor)
  */
-int32 CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
+CommandCost CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
 {
-	int32 cost;
+	CommandCost cost;
 	int size_x, size_y;
 	int x;
 	int y;
@@ -251,7 +251,7 @@
 
 	cost = 0;
 	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
-		int32 ret;
+		CommandCost ret;
 
 		if (GetTileSlope(tile, NULL) != SLOPE_FLAT) {
 			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
@@ -284,7 +284,7 @@
 	}
 }
 
-static int32 ClearTile_Water(TileIndex tile, byte flags)
+static CommandCost ClearTile_Water(TileIndex tile, byte flags)
 {
 	switch (GetWaterTileType(tile)) {
 		case WATER_TILE_CLEAR:
@@ -588,7 +588,7 @@
 			case MP_CLEAR:
 			case MP_TREES:
 				_current_player = OWNER_WATER;
-				if (!CmdFailed(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
+				if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
 					MakeShore(target);
 					MarkTileDirtyByTile(target);
 				}
@@ -603,7 +603,7 @@
 		Vehicle *v = FindFloodableVehicleOnTile(target);
 		if (v != NULL) FloodVehicle(v);
 
-		if (!CmdFailed(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
+		if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
 			MakeWater(target);
 			MarkTileDirtyByTile(target);
 		}
@@ -618,6 +618,21 @@
  */
 static Vehicle *FindFloodableVehicleOnTile(TileIndex tile)
 {
+	if (IsTileType(tile, MP_STATION) && IsAirport(tile)) {
+		const Station *st = GetStationByTile(tile);
+		const AirportFTAClass *airport = st->Airport();
+		for (uint x = 0; x < airport->size_x; x++) {
+			for (uint y = 0; y < airport->size_y; y++) {
+				tile = TILE_ADDXY(st->airport_tile, x, y);
+				Vehicle *v = FindVehicleOnTileZ(tile, 1 + airport->delta_z);
+				if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v;
+			}
+		}
+
+		/* No vehicle could be flooded on this airport anymore */
+		return NULL;
+	}
+
 	if (!IsBridgeTile(tile)) return FindVehicleOnTileZ(tile, 0);
 
 	TileIndex end = GetOtherBridgeEnd(tile);
@@ -642,10 +657,20 @@
 	if (!(v->vehstatus & VS_CRASHED)) {
 		uint16 pass = 0;
 
-		if (v->type == VEH_TRAIN || v->type == VEH_ROAD) {
+		if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_AIRCRAFT) {
+			if (v->type == VEH_AIRCRAFT) {
+				/* Crashing aircraft are always at z_pos == 1, never on z_pos == 0,
+				 * because that's always the shadow. Except for the heliport, because
+				 * that station has a big z_offset for the aircraft. */
+				if (!IsTileType(v->tile, MP_STATION) || !IsAirport(v->tile) || GetTileMaxZ(v->tile) != 0) return;
+				const Station *st = GetStationByTile(v->tile);
+				const AirportFTAClass *airport = st->Airport();
+
+				if (v->z_pos != airport->delta_z + 1) return;
+			}
 			Vehicle *u;
 
-			v = GetFirstVehicleInChain(v);
+			if (v->type != VEH_AIRCRAFT) v = GetFirstVehicleInChain(v);
 			u = v;
 
 			/* crash all wagons, and count passengers */
@@ -657,12 +682,22 @@
 
 			v = u;
 
-			if (v->type == VEH_TRAIN) {
-				if (IsFrontEngine(v)) pass += 4; // driver
-				v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
-			} else {
-				if (IsRoadVehFront(v)) pass += 1; // driver
-				v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
+			switch (v->type) {
+				default: NOT_REACHED();
+				case VEH_TRAIN:
+					if (IsFrontEngine(v)) pass += 4; // driver
+					v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
+					break;
+
+				case VEH_ROAD:
+					if (IsRoadVehFront(v)) pass += 1; // driver
+					v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
+					break;
+
+				case VEH_AIRCRAFT:
+					pass += 2; // driver
+					v->u.air.crashed_counter = 9000; // max 10000, disappear pretty fast
+					break;
 			}
 
 			RebuildVehicleLists();