diff options
author | darkvater <darkvater@openttd.org> | 2004-09-01 21:54:12 +0000 |
---|---|---|
committer | darkvater <darkvater@openttd.org> | 2004-09-01 21:54:12 +0000 |
commit | 3b96ad994c43581918c3a5fa060f184d2c730f71 (patch) | |
tree | 70c7281080f4c25e80d32f9e7c77816a506ca463 /unmovable_cmd.c | |
parent | 6f3c862a242bb69cbad434dea4f8b1123728f04f (diff) | |
download | openttd-3b96ad994c43581918c3a5fa060f184d2c730f71.tar.xz |
(svn r148) -Feature: Company HQ can now be moved somewhere else (cost 1% of company value). Water floods HQ.
-Some layout fixes for command.c
-Tileinfo debug window in console now shows Tile in decimal numbers
Diffstat (limited to 'unmovable_cmd.c')
-rw-r--r-- | unmovable_cmd.c | 58 |
1 files changed, 54 insertions, 4 deletions
diff --git a/unmovable_cmd.c b/unmovable_cmd.c index 85afec5f1..1c6d26f5b 100644 --- a/unmovable_cmd.c +++ b/unmovable_cmd.c @@ -116,8 +116,11 @@ static int32 ClearTile_Unmovable(uint tile, byte flags) byte m5 = _map5[tile]; //Town *t; - if (m5 & 0x80) + if (m5 & 0x80) { + if (_current_player == OWNER_WATER) + return DoCommandByTile(tile, OWNER_WATER, 0, flags, 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); @@ -331,15 +334,26 @@ restart: extern int32 CheckFlatLandBelow(uint tile, uint w, uint h, uint flags, uint invalid_dirs, int *); +/* p1 = relocate HQ + p1&0xFF = player whose HQ is up for relocation +*/ int32 CmdBuildCompanyHQ(int x, int y, uint32 flags, uint32 p1, uint32 p2) { uint tile = TILE_FROM_XY(x,y); - + Player *p = DEREF_PLAYER(_current_player); + int score; + int32 cost = 0; + if (CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL) == CMD_ERROR) return CMD_ERROR; + if (p1) + cost = DoCommand(GET_TILE_X(p->location_of_house)*16, GET_TILE_Y(p->location_of_house)*16, p1&0xFF, 0, flags, CMD_DESTROY_COMPANY_HQ); + if (flags & DC_EXEC) { - DEREF_PLAYER(_current_player)->location_of_house = tile; + score = UpdateCompanyRatingAndValue(p, false); + + p->location_of_house = tile; ModifyTile(tile + TILE_XY(0,0), MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, @@ -360,11 +374,47 @@ int32 CmdBuildCompanyHQ(int x, int y, uint32 flags, uint32 p1, uint32 p2) MP_SETTYPE(MP_UNMOVABLE) | MP_MAPOWNER_CURRENT | MP_MAP5, 0x83 ); + UpdatePlayerHouse(p, score); + InvalidateWindow(WC_COMPANY, (int)p->index); } - return 0; + return cost; } +/* p1 = owner of the HQ */ +int32 CmdDestroyCompanyHQ(int x, int y, uint32 flags, uint32 p1, uint32 p2) +{ + uint tile = TILE_FROM_XY(x,y); + Player *p; + + if ((int)p1 != OWNER_WATER) // destruction was initiated by player + p = DEREF_PLAYER((byte)p1); + else { // find player that has HQ flooded, and reset their location_of_house + bool dodelete = false; + FOR_ALL_PLAYERS(p) { + if (p->location_of_house == tile) { + dodelete = true; + break; + } + } + if (!dodelete) + return CMD_ERROR; + } + + if (flags & DC_EXEC) { + p->location_of_house = 0; // reset HQ position + DoClearSquare(tile + TILE_XY(0,0)); + DoClearSquare(tile + TILE_XY(0,1)); + DoClearSquare(tile + TILE_XY(1,0)); + DoClearSquare(tile + TILE_XY(1,1)); + InvalidateWindow(WC_COMPANY, (int)p->index); + } + + // cost of relocating company is 1% of company value + return CalculateCompanyValue(p) / 100; +} + + static void ChangeTileOwner_Unmovable(uint tile, byte old_player, byte new_player) { if (_map_owner[tile] != old_player) |