src/water_cmd.cpp
branchgamebalance
changeset 9913 e79cd19772dd
parent 9912 1ac8aac92385
equal deleted inserted replaced
9912:1ac8aac92385 9913:e79cd19772dd
    54  * @param tile tile where ship depot is built
    54  * @param tile tile where ship depot is built
    55  * @param flags type of operation
    55  * @param flags type of operation
    56  * @param p1 bit 0 depot orientation (Axis)
    56  * @param p1 bit 0 depot orientation (Axis)
    57  * @param p2 unused
    57  * @param p2 unused
    58  */
    58  */
    59 int32 CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
    59 CommandCost CmdBuildShipDepot(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
    60 {
    60 {
    61 	TileIndex tile2;
    61 	TileIndex tile2;
    62 
    62 
    63 	int32 cost, ret;
    63 	CommandCost cost, ret;
    64 	Depot *depot;
    64 	Depot *depot;
    65 
    65 
    66 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
    66 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
    67 
    67 
    68 	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
    68 	if (!EnsureNoVehicle(tile)) return CMD_ERROR;
    99 	}
    99 	}
   100 
   100 
   101 	return cost + _eco->GetPrice(CEconomy::BUILD_SHIP_DEPOT);
   101 	return cost + _eco->GetPrice(CEconomy::BUILD_SHIP_DEPOT);
   102 }
   102 }
   103 
   103 
   104 static int32 RemoveShipDepot(TileIndex tile, uint32 flags)
   104 static CommandCost RemoveShipDepot(TileIndex tile, uint32 flags)
   105 {
   105 {
   106 	TileIndex tile2;
   106 	TileIndex tile2;
   107 
   107 
   108 	if (!IsShipDepot(tile)) return CMD_ERROR;
   108 	if (!IsShipDepot(tile)) return CMD_ERROR;
   109 	if (!CheckTileOwnership(tile)) return CMD_ERROR;
   109 	if (!CheckTileOwnership(tile)) return CMD_ERROR;
   125 
   125 
   126 	return _eco->GetPrice(CEconomy::REMOVE_SHIP_DEPOT);
   126 	return _eco->GetPrice(CEconomy::REMOVE_SHIP_DEPOT);
   127 }
   127 }
   128 
   128 
   129 /** build a shiplift */
   129 /** build a shiplift */
   130 static int32 DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags)
   130 static CommandCost DoBuildShiplift(TileIndex tile, DiagDirection dir, uint32 flags)
   131 {
   131 {
   132 	int32 ret;
   132 	CommandCost ret;
   133 	int delta;
   133 	int delta;
   134 
   134 
   135 	/* middle tile */
   135 	/* middle tile */
   136 	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   136 	ret = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
   137 	if (CmdFailed(ret)) return CMD_ERROR;
   137 	if (CmdFailed(ret)) return CMD_ERROR;
   165 	}
   165 	}
   166 
   166 
   167 	return _eco->GetPrice(CEconomy::CLEAR_WATER) * 22 >> 3;
   167 	return _eco->GetPrice(CEconomy::CLEAR_WATER) * 22 >> 3;
   168 }
   168 }
   169 
   169 
   170 static int32 RemoveShiplift(TileIndex tile, uint32 flags)
   170 static CommandCost RemoveShiplift(TileIndex tile, uint32 flags)
   171 {
   171 {
   172 	TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
   172 	TileIndexDiff delta = TileOffsByDiagDir(GetLockDirection(tile));
   173 
   173 
   174 	if (!CheckTileOwnership(tile)) return CMD_ERROR;
   174 	if (!CheckTileOwnership(tile)) return CMD_ERROR;
   175 
   175 
   198  * @param tile tile where to place the lock
   198  * @param tile tile where to place the lock
   199  * @param flags type of operation
   199  * @param flags type of operation
   200  * @param p1 unused
   200  * @param p1 unused
   201  * @param p2 unused
   201  * @param p2 unused
   202  */
   202  */
   203 int32 CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   203 CommandCost CmdBuildLock(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   204 {
   204 {
   205 	DiagDirection dir;
   205 	DiagDirection dir;
   206 
   206 
   207 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   207 	SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION);
   208 
   208 
   220  * @param tile end tile of stretch-dragging
   220  * @param tile end tile of stretch-dragging
   221  * @param flags type of operation
   221  * @param flags type of operation
   222  * @param p1 start tile of stretch-dragging
   222  * @param p1 start tile of stretch-dragging
   223  * @param p2 ctrl pressed - toggles ocean / canals at sealevel (ocean only allowed in the scenario editor)
   223  * @param p2 ctrl pressed - toggles ocean / canals at sealevel (ocean only allowed in the scenario editor)
   224  */
   224  */
   225 int32 CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   225 CommandCost CmdBuildCanal(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   226 {
   226 {
   227 	int32 cost;
   227 	CommandCost cost;
   228 	int size_x, size_y;
   228 	int size_x, size_y;
   229 	int x;
   229 	int x;
   230 	int y;
   230 	int y;
   231 	int sx, sy;
   231 	int sx, sy;
   232 
   232 
   249 	/* Outside the editor you can only drag canals, and not areas */
   249 	/* Outside the editor you can only drag canals, and not areas */
   250 	if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR;
   250 	if (_game_mode != GM_EDITOR && (sx != x && sy != y)) return CMD_ERROR;
   251 
   251 
   252 	cost = 0;
   252 	cost = 0;
   253 	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
   253 	BEGIN_TILE_LOOP(tile, size_x, size_y, TileXY(sx, sy)) {
   254 		int32 ret;
   254 		CommandCost ret;
   255 
   255 
   256 		if (GetTileSlope(tile, NULL) != SLOPE_FLAT) {
   256 		if (GetTileSlope(tile, NULL) != SLOPE_FLAT) {
   257 			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
   257 			return_cmd_error(STR_0007_FLAT_LAND_REQUIRED);
   258 		}
   258 		}
   259 
   259 
   282 	} else {
   282 	} else {
   283 		return cost;
   283 		return cost;
   284 	}
   284 	}
   285 }
   285 }
   286 
   286 
   287 static int32 ClearTile_Water(TileIndex tile, byte flags)
   287 static CommandCost ClearTile_Water(TileIndex tile, byte flags)
   288 {
   288 {
   289 	switch (GetWaterTileType(tile)) {
   289 	switch (GetWaterTileType(tile)) {
   290 		case WATER_TILE_CLEAR:
   290 		case WATER_TILE_CLEAR:
   291 			if (flags & DC_NO_WATER) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
   291 			if (flags & DC_NO_WATER) return_cmd_error(STR_3807_CAN_T_BUILD_ON_WATER);
   292 
   292 
   586 			/* FALLTHROUGH */
   586 			/* FALLTHROUGH */
   587 
   587 
   588 			case MP_CLEAR:
   588 			case MP_CLEAR:
   589 			case MP_TREES:
   589 			case MP_TREES:
   590 				_current_player = OWNER_WATER;
   590 				_current_player = OWNER_WATER;
   591 				if (!CmdFailed(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
   591 				if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
   592 					MakeShore(target);
   592 					MakeShore(target);
   593 					MarkTileDirtyByTile(target);
   593 					MarkTileDirtyByTile(target);
   594 				}
   594 				}
   595 				break;
   595 				break;
   596 
   596 
   601 		_current_player = OWNER_WATER;
   601 		_current_player = OWNER_WATER;
   602 
   602 
   603 		Vehicle *v = FindFloodableVehicleOnTile(target);
   603 		Vehicle *v = FindFloodableVehicleOnTile(target);
   604 		if (v != NULL) FloodVehicle(v);
   604 		if (v != NULL) FloodVehicle(v);
   605 
   605 
   606 		if (!CmdFailed(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
   606 		if (CmdSucceeded(DoCommand(target, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR))) {
   607 			MakeWater(target);
   607 			MakeWater(target);
   608 			MarkTileDirtyByTile(target);
   608 			MarkTileDirtyByTile(target);
   609 		}
   609 		}
   610 	}
   610 	}
   611 }
   611 }
   616  * @param tile the tile where to find a vehicle to flood
   616  * @param tile the tile where to find a vehicle to flood
   617  * @return a vehicle too flood or NULL when there is no vehicle too flood.
   617  * @return a vehicle too flood or NULL when there is no vehicle too flood.
   618  */
   618  */
   619 static Vehicle *FindFloodableVehicleOnTile(TileIndex tile)
   619 static Vehicle *FindFloodableVehicleOnTile(TileIndex tile)
   620 {
   620 {
       
   621 	if (IsTileType(tile, MP_STATION) && IsAirport(tile)) {
       
   622 		const Station *st = GetStationByTile(tile);
       
   623 		const AirportFTAClass *airport = st->Airport();
       
   624 		for (uint x = 0; x < airport->size_x; x++) {
       
   625 			for (uint y = 0; y < airport->size_y; y++) {
       
   626 				tile = TILE_ADDXY(st->airport_tile, x, y);
       
   627 				Vehicle *v = FindVehicleOnTileZ(tile, 1 + airport->delta_z);
       
   628 				if (v != NULL && (v->vehstatus & VS_CRASHED) == 0) return v;
       
   629 			}
       
   630 		}
       
   631 
       
   632 		/* No vehicle could be flooded on this airport anymore */
       
   633 		return NULL;
       
   634 	}
       
   635 
   621 	if (!IsBridgeTile(tile)) return FindVehicleOnTileZ(tile, 0);
   636 	if (!IsBridgeTile(tile)) return FindVehicleOnTileZ(tile, 0);
   622 
   637 
   623 	TileIndex end = GetOtherBridgeEnd(tile);
   638 	TileIndex end = GetOtherBridgeEnd(tile);
   624 	byte z = GetBridgeHeight(tile);
   639 	byte z = GetBridgeHeight(tile);
   625 	Vehicle *v;
   640 	Vehicle *v;
   640 static void FloodVehicle(Vehicle *v)
   655 static void FloodVehicle(Vehicle *v)
   641 {
   656 {
   642 	if (!(v->vehstatus & VS_CRASHED)) {
   657 	if (!(v->vehstatus & VS_CRASHED)) {
   643 		uint16 pass = 0;
   658 		uint16 pass = 0;
   644 
   659 
   645 		if (v->type == VEH_TRAIN || v->type == VEH_ROAD) {
   660 		if (v->type == VEH_TRAIN || v->type == VEH_ROAD || v->type == VEH_AIRCRAFT) {
       
   661 			if (v->type == VEH_AIRCRAFT) {
       
   662 				/* Crashing aircraft are always at z_pos == 1, never on z_pos == 0,
       
   663 				 * because that's always the shadow. Except for the heliport, because
       
   664 				 * that station has a big z_offset for the aircraft. */
       
   665 				if (!IsTileType(v->tile, MP_STATION) || !IsAirport(v->tile) || GetTileMaxZ(v->tile) != 0) return;
       
   666 				const Station *st = GetStationByTile(v->tile);
       
   667 				const AirportFTAClass *airport = st->Airport();
       
   668 
       
   669 				if (v->z_pos != airport->delta_z + 1) return;
       
   670 			}
   646 			Vehicle *u;
   671 			Vehicle *u;
   647 
   672 
   648 			v = GetFirstVehicleInChain(v);
   673 			if (v->type != VEH_AIRCRAFT) v = GetFirstVehicleInChain(v);
   649 			u = v;
   674 			u = v;
   650 
   675 
   651 			/* crash all wagons, and count passengers */
   676 			/* crash all wagons, and count passengers */
   652 			BEGIN_ENUM_WAGONS(v)
   677 			BEGIN_ENUM_WAGONS(v)
   653 				if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo_count;
   678 				if (IsCargoInClass(v->cargo_type, CC_PASSENGERS)) pass += v->cargo_count;
   655 				MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
   680 				MarkAllViewportsDirty(v->left_coord, v->top_coord, v->right_coord + 1, v->bottom_coord + 1);
   656 			END_ENUM_WAGONS(v)
   681 			END_ENUM_WAGONS(v)
   657 
   682 
   658 			v = u;
   683 			v = u;
   659 
   684 
   660 			if (v->type == VEH_TRAIN) {
   685 			switch (v->type) {
   661 				if (IsFrontEngine(v)) pass += 4; // driver
   686 				default: NOT_REACHED();
   662 				v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
   687 				case VEH_TRAIN:
   663 			} else {
   688 					if (IsFrontEngine(v)) pass += 4; // driver
   664 				if (IsRoadVehFront(v)) pass += 1; // driver
   689 					v->u.rail.crash_anim_pos = 4000; // max 4440, disappear pretty fast
   665 				v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
   690 					break;
       
   691 
       
   692 				case VEH_ROAD:
       
   693 					if (IsRoadVehFront(v)) pass += 1; // driver
       
   694 					v->u.road.crashed_ctr = 2000; // max 2220, disappear pretty fast
       
   695 					break;
       
   696 
       
   697 				case VEH_AIRCRAFT:
       
   698 					pass += 2; // driver
       
   699 					v->u.air.crashed_counter = 9000; // max 10000, disappear pretty fast
       
   700 					break;
   666 			}
   701 			}
   667 
   702 
   668 			RebuildVehicleLists();
   703 			RebuildVehicleLists();
   669 		} else {
   704 		} else {
   670 			return;
   705 			return;