summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2006-06-24 08:08:28 +0000
committertron <tron@openttd.org>2006-06-24 08:08:28 +0000
commit5fad8a1829248c450e54d3bf1838868c953fce3b (patch)
tree0d4d3366f1da5e2b8d4bef16e47f6e6c563c0eb6
parenta832ca51feb61319cccd8501bbb9020df2135a9f (diff)
downloadopenttd-5fad8a1829248c450e54d3bf1838868c953fce3b.tar.xz
(svn r5348) -Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to water
-rw-r--r--unmovable_cmd.c51
1 files changed, 19 insertions, 32 deletions
diff --git a/unmovable_cmd.c b/unmovable_cmd.c
index eaded26d7..2bfdbe5d7 100644
--- a/unmovable_cmd.c
+++ b/unmovable_cmd.c
@@ -25,39 +25,25 @@
* @param tile tile coordinates where HQ is located to destroy
* @param flags docommand flags of calling function
*/
-static int32 DestroyCompanyHQ(TileIndex tile, uint32 flags)
+static int32 DestroyCompanyHQ(PlayerID pid, uint32 flags)
{
- Player *p;
+ Player* p = GetPlayer(pid);
SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
- /* Find player that has HQ flooded, and reset their location_of_house */
- if (_current_player == OWNER_WATER) {
- bool dodelete = false;
-
- FOR_ALL_PLAYERS(p) {
- if (p->location_of_house == tile) {
- dodelete = true;
- break;
- }
- }
- if (!dodelete) return CMD_ERROR;
- } else /* Destruction was initiated by player */
- p = GetPlayer(_current_player);
-
- if (p->location_of_house == 0) return CMD_ERROR;
-
- if (flags & DC_EXEC) {
- DoClearSquare(p->location_of_house + TileDiffXY(0, 0));
- DoClearSquare(p->location_of_house + TileDiffXY(0, 1));
- DoClearSquare(p->location_of_house + TileDiffXY(1, 0));
- DoClearSquare(p->location_of_house + TileDiffXY(1, 1));
- p->location_of_house = 0; // reset HQ position
- InvalidateWindow(WC_COMPANY, p->index);
- }
+ if (flags & DC_EXEC) {
+ TileIndex t = p->location_of_house;
+
+ DoClearSquare(t + TileDiffXY(0, 0));
+ DoClearSquare(t + TileDiffXY(0, 1));
+ DoClearSquare(t + TileDiffXY(1, 0));
+ DoClearSquare(t + TileDiffXY(1, 1));
+ p->location_of_house = 0; // reset HQ position
+ InvalidateWindow(WC_COMPANY, pid);
+ }
// cost of relocating company is 1% of company value
- return CalculateCompanyValue(p) / 100;
+ return CalculateCompanyValue(p) / 100;
}
void UpdateCompanyHQ(Player *p, uint score)
@@ -101,9 +87,7 @@ int32 CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
cost = ret;
if (p->location_of_house != 0) { /* Moving HQ */
- ret = DestroyCompanyHQ(p->location_of_house, flags);
- if (CmdFailed(ret)) return CMD_ERROR;
- cost += ret;
+ cost += DestroyCompanyHQ(_current_player, flags);
}
if (flags & DC_EXEC) {
@@ -202,8 +186,11 @@ static Slope GetSlopeTileh_Unmovable(TileIndex tile, Slope tileh)
static int32 ClearTile_Unmovable(TileIndex tile, byte flags)
{
if (IsCompanyHQ(tile)) {
- if (_current_player == OWNER_WATER) return DestroyCompanyHQ(tile, DC_EXEC);
- return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN);
+ if (_current_player == OWNER_WATER) {
+ return DestroyCompanyHQ(GetTileOwner(tile), DC_EXEC);
+ } else {
+ return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN);
+ }
}
if (IsOwnedLand(tile)) {