mirror of https://github.com/OpenTTD/OpenTTD
(svn r5367) -Backport: 5348
-Fix: A HQ could only be flooded at its northern tile, the other 3 were immune to waterrelease/0.4
parent
93713354a2
commit
339160760b
|
@ -23,39 +23,25 @@
|
||||||
* @param tile tile coordinates where HQ is located to destroy
|
* @param tile tile coordinates where HQ is located to destroy
|
||||||
* @param flags docommand flags of calling function
|
* @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);
|
SET_EXPENSES_TYPE(EXPENSES_PROPERTY);
|
||||||
|
|
||||||
/* Find player that has HQ flooded, and reset their location_of_house */
|
if (flags & DC_EXEC) {
|
||||||
if (_current_player == OWNER_WATER) {
|
TileIndex t = p->location_of_house;
|
||||||
bool dodelete = false;
|
|
||||||
|
|
||||||
FOR_ALL_PLAYERS(p) {
|
DoClearSquare(t + TileDiffXY(0, 0));
|
||||||
if (p->location_of_house == tile) {
|
DoClearSquare(t + TileDiffXY(0, 1));
|
||||||
dodelete = true;
|
DoClearSquare(t + TileDiffXY(1, 0));
|
||||||
break;
|
DoClearSquare(t + TileDiffXY(1, 1));
|
||||||
}
|
p->location_of_house = 0; // reset HQ position
|
||||||
}
|
InvalidateWindow(WC_COMPANY, pid);
|
||||||
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, (int)p->index);
|
|
||||||
}
|
|
||||||
|
|
||||||
// cost of relocating company is 1% of company value
|
// cost of relocating company is 1% of company value
|
||||||
return CalculateCompanyValue(p) / 100;
|
return CalculateCompanyValue(p) / 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Build or relocate the HQ. This depends if the HQ is already built or not
|
/** Build or relocate the HQ. This depends if the HQ is already built or not
|
||||||
|
@ -76,9 +62,7 @@ int32 CmdBuildCompanyHQ(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
||||||
if (CmdFailed(cost)) return CMD_ERROR;
|
if (CmdFailed(cost)) return CMD_ERROR;
|
||||||
|
|
||||||
if (p->location_of_house != 0) { /* Moving HQ */
|
if (p->location_of_house != 0) { /* Moving HQ */
|
||||||
int32 ret = DestroyCompanyHQ(p->location_of_house, flags);
|
cost += DestroyCompanyHQ(_current_player, flags);
|
||||||
if (CmdFailed(ret)) return CMD_ERROR;
|
|
||||||
cost += ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & DC_EXEC) {
|
if (flags & DC_EXEC) {
|
||||||
|
@ -199,8 +183,11 @@ static int32 ClearTile_Unmovable(TileIndex tile, byte flags)
|
||||||
byte m5 = _m[tile].m5;
|
byte m5 = _m[tile].m5;
|
||||||
|
|
||||||
if (m5 & 0x80) {
|
if (m5 & 0x80) {
|
||||||
if (_current_player == OWNER_WATER) return DestroyCompanyHQ(tile, DC_EXEC);
|
if (_current_player == OWNER_WATER) {
|
||||||
return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN);
|
return DestroyCompanyHQ(GetTileOwner(tile), DC_EXEC);
|
||||||
|
} else {
|
||||||
|
return_cmd_error(STR_5804_COMPANY_HEADQUARTERS_IN);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m5 == 3) // company owned land
|
if (m5 == 3) // company owned land
|
||||||
|
|
Loading…
Reference in New Issue