34 #include "table/unmovable_land.h" |
34 #include "table/unmovable_land.h" |
35 |
35 |
36 /** Destroy a HQ. |
36 /** Destroy a HQ. |
37 * During normal gameplay you can only implicitely destroy a HQ when you are |
37 * During normal gameplay you can only implicitely destroy a HQ when you are |
38 * rebuilding it. Otherwise, only water can destroy it. |
38 * rebuilding it. Otherwise, only water can destroy it. |
39 * @param pid Player requesting the destruction of his HQ |
39 * @param cid Company requesting the destruction of his HQ |
40 * @param flags docommand flags of calling function |
40 * @param flags docommand flags of calling function |
41 * @return cost of the operation |
41 * @return cost of the operation |
42 */ |
42 */ |
43 static CommandCost DestroyCompanyHQ(PlayerID pid, uint32 flags) |
43 static CommandCost DestroyCompanyHQ(CompanyID cid, uint32 flags) |
44 { |
44 { |
45 Player *p = GetPlayer(pid); |
45 Company *c = GetCompany(cid); |
46 |
46 |
47 if (flags & DC_EXEC) { |
47 if (flags & DC_EXEC) { |
48 TileIndex t = p->location_of_HQ; |
48 TileIndex t = c->location_of_HQ; |
49 |
49 |
50 DoClearSquare(t + TileDiffXY(0, 0)); |
50 DoClearSquare(t + TileDiffXY(0, 0)); |
51 DoClearSquare(t + TileDiffXY(0, 1)); |
51 DoClearSquare(t + TileDiffXY(0, 1)); |
52 DoClearSquare(t + TileDiffXY(1, 0)); |
52 DoClearSquare(t + TileDiffXY(1, 0)); |
53 DoClearSquare(t + TileDiffXY(1, 1)); |
53 DoClearSquare(t + TileDiffXY(1, 1)); |
54 p->location_of_HQ = 0; // reset HQ position |
54 c->location_of_HQ = 0; // reset HQ position |
55 InvalidateWindow(WC_COMPANY, pid); |
55 InvalidateWindow(WC_COMPANY, cid); |
56 } |
56 } |
57 |
57 |
58 /* cost of relocating company is 1% of company value */ |
58 /* cost of relocating company is 1% of company value */ |
59 return CommandCost(EXPENSES_PROPERTY, CalculateCompanyValue(p) / 100); |
59 return CommandCost(EXPENSES_PROPERTY, CalculateCompanyValue(c) / 100); |
60 } |
60 } |
61 |
61 |
62 void UpdateCompanyHQ(Player *p, uint score) |
62 void UpdateCompanyHQ(Company *c, uint score) |
63 { |
63 { |
64 byte val; |
64 byte val; |
65 TileIndex tile = p->location_of_HQ; |
65 TileIndex tile = c->location_of_HQ; |
66 |
66 |
67 if (tile == 0) return; |
67 if (tile == 0) return; |
68 |
68 |
69 (val = 0, score < 170) || |
69 (val = 0, score < 170) || |
70 (val++, score < 350) || |
70 (val++, score < 350) || |
88 * @param p1 unused |
88 * @param p1 unused |
89 * @param p2 unused |
89 * @param p2 unused |
90 */ |
90 */ |
91 CommandCost CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
91 CommandCost CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
92 { |
92 { |
93 Player *p = GetPlayer(_current_player); |
93 Company *c = GetCompany(_current_company); |
94 CommandCost cost(EXPENSES_PROPERTY); |
94 CommandCost cost(EXPENSES_PROPERTY); |
95 |
95 |
96 cost = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL); |
96 cost = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL); |
97 if (CmdFailed(cost)) return cost; |
97 if (CmdFailed(cost)) return cost; |
98 |
98 |
99 if (p->location_of_HQ != 0) { // Moving HQ |
99 if (c->location_of_HQ != 0) { // Moving HQ |
100 cost.AddCost(DestroyCompanyHQ(_current_player, flags)); |
100 cost.AddCost(DestroyCompanyHQ(_current_company, flags)); |
101 } |
101 } |
102 |
102 |
103 if (flags & DC_EXEC) { |
103 if (flags & DC_EXEC) { |
104 int score = UpdateCompanyRatingAndValue(p, false); |
104 int score = UpdateCompanyRatingAndValue(c, false); |
105 |
105 |
106 p->location_of_HQ = tile; |
106 c->location_of_HQ = tile; |
107 |
107 |
108 MakeCompanyHQ(tile, _current_player); |
108 MakeCompanyHQ(tile, _current_company); |
109 |
109 |
110 UpdateCompanyHQ(p, score); |
110 UpdateCompanyHQ(c, score); |
111 InvalidateWindow(WC_COMPANY, p->index); |
111 InvalidateWindow(WC_COMPANY, c->index); |
112 } |
112 } |
113 |
113 |
114 return cost; |
114 return cost; |
115 } |
115 } |
116 |
116 |
117 /** Purchase a land area. Actually you only purchase one tile, so |
117 /** Purchase a land area. Actually you only purchase one tile, so |
118 * the name is a bit confusing ;p |
118 * the name is a bit confusing ;p |
119 * @param tile the tile the player is purchasing |
119 * @param tile the tile the company is purchasing |
120 * @param flags for this command type |
120 * @param flags for this command type |
121 * @param p1 unused |
121 * @param p1 unused |
122 * @param p2 unused |
122 * @param p2 unused |
123 * @return error of cost of operation |
123 * @return error of cost of operation |
124 */ |
124 */ |
125 CommandCost CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
125 CommandCost CmdPurchaseLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
126 { |
126 { |
127 CommandCost cost(EXPENSES_CONSTRUCTION); |
127 CommandCost cost(EXPENSES_CONSTRUCTION); |
128 |
128 |
129 if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_player)) { |
129 if (IsOwnedLandTile(tile) && IsTileOwner(tile, _current_company)) { |
130 return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT); |
130 return_cmd_error(STR_5807_YOU_ALREADY_OWN_IT); |
131 } |
131 } |
132 |
132 |
133 cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
133 cost = DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR); |
134 if (CmdFailed(cost)) return CMD_ERROR; |
134 if (CmdFailed(cost)) return CMD_ERROR; |
135 |
135 |
136 if (flags & DC_EXEC) { |
136 if (flags & DC_EXEC) { |
137 MakeOwnedLand(tile, _current_player); |
137 MakeOwnedLand(tile, _current_company); |
138 MarkTileDirtyByTile(tile); |
138 MarkTileDirtyByTile(tile); |
139 } |
139 } |
140 |
140 |
141 return cost.AddCost(_price.clear_roughland * 10); |
141 return cost.AddCost(_price.clear_roughland * 10); |
142 } |
142 } |
143 |
143 |
144 /** Sell a land area. Actually you only sell one tile, so |
144 /** Sell a land area. Actually you only sell one tile, so |
145 * the name is a bit confusing ;p |
145 * the name is a bit confusing ;p |
146 * @param tile the tile the player is selling |
146 * @param tile the tile the company is selling |
147 * @param flags for this command type |
147 * @param flags for this command type |
148 * @param p1 unused |
148 * @param p1 unused |
149 * @param p2 unused |
149 * @param p2 unused |
150 * @return error or cost of operation |
150 * @return error or cost of operation |
151 */ |
151 */ |
152 CommandCost CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
152 CommandCost CmdSellLandArea(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
153 { |
153 { |
154 if (!IsOwnedLandTile(tile)) return CMD_ERROR; |
154 if (!IsOwnedLandTile(tile)) return CMD_ERROR; |
155 if (!CheckTileOwnership(tile) && _current_player != OWNER_WATER) return CMD_ERROR; |
155 if (!CheckTileOwnership(tile) && _current_company != OWNER_WATER) return CMD_ERROR; |
156 |
156 |
157 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
157 if (!EnsureNoVehicleOnGround(tile)) return CMD_ERROR; |
158 |
158 |
159 if (flags & DC_EXEC) DoClearSquare(tile); |
159 if (flags & DC_EXEC) DoClearSquare(tile); |
160 |
160 |
190 |
190 |
191 DrawGroundSprite(SPR_CONCRETE_GROUND, PAL_NONE); |
191 DrawGroundSprite(SPR_CONCRETE_GROUND, PAL_NONE); |
192 |
192 |
193 if (IsInvisibilitySet(TO_STRUCTURES)) break; |
193 if (IsInvisibilitySet(TO_STRUCTURES)) break; |
194 |
194 |
195 AddSortableSpriteToDraw(SPR_STATUE_COMPANY, PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), ti->x, ti->y, 16, 16, 25, ti->z, IsTransparencySet(TO_STRUCTURES)); |
195 AddSortableSpriteToDraw(SPR_STATUE_COMPANY, COMPANY_SPRITE_COLOR(GetTileOwner(ti->tile)), ti->x, ti->y, 16, 16, 25, ti->z, IsTransparencySet(TO_STRUCTURES)); |
196 break; |
196 break; |
197 |
197 |
198 case UNMOVABLE_OWNED_LAND: |
198 case UNMOVABLE_OWNED_LAND: |
199 DrawClearLandTile(ti, 0); |
199 DrawClearLandTile(ti, 0); |
200 |
200 |
201 AddSortableSpriteToDraw( |
201 AddSortableSpriteToDraw( |
202 SPR_BOUGHT_LAND, PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)), |
202 SPR_BOUGHT_LAND, COMPANY_SPRITE_COLOR(GetTileOwner(ti->tile)), |
203 ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, BB_HEIGHT_UNDER_BRIDGE, GetSlopeZ(ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2) |
203 ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2, 1, 1, BB_HEIGHT_UNDER_BRIDGE, GetSlopeZ(ti->x + TILE_SIZE / 2, ti->y + TILE_SIZE / 2) |
204 ); |
204 ); |
205 DrawBridgeMiddle(ti); |
205 DrawBridgeMiddle(ti); |
206 break; |
206 break; |
207 |
207 |
208 default: { |
208 default: { |
209 assert(IsCompanyHQ(ti->tile)); |
209 assert(IsCompanyHQ(ti->tile)); |
210 if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); |
210 if (ti->tileh != SLOPE_FLAT) DrawFoundation(ti, FOUNDATION_LEVELED); |
211 |
211 |
212 SpriteID palette = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)); |
212 SpriteID palette = COMPANY_SPRITE_COLOR(GetTileOwner(ti->tile)); |
213 |
213 |
214 const DrawTileSprites *t = &_unmovable_display_datas[GetCompanyHQSection(ti->tile)]; |
214 const DrawTileSprites *t = &_unmovable_display_datas[GetCompanyHQSection(ti->tile)]; |
215 DrawGroundSprite(t->ground.sprite, palette); |
215 DrawGroundSprite(t->ground.sprite, palette); |
216 |
216 |
217 if (IsInvisibilitySet(TO_STRUCTURES)) break; |
217 if (IsInvisibilitySet(TO_STRUCTURES)) break; |
431 tile = TILE_MASK(tile + TileOffsByDiagDir(dir)); |
431 tile = TILE_MASK(tile + TileOffsByDiagDir(dir)); |
432 } |
432 } |
433 } |
433 } |
434 } |
434 } |
435 |
435 |
436 static void ChangeTileOwner_Unmovable(TileIndex tile, PlayerID old_player, PlayerID new_player) |
436 static void ChangeTileOwner_Unmovable(TileIndex tile, Owner old_owner, Owner new_owner) |
437 { |
437 { |
438 if (!IsTileOwner(tile, old_player)) return; |
438 if (!IsTileOwner(tile, old_owner)) return; |
439 |
439 |
440 if (IsOwnedLand(tile) && new_player != PLAYER_SPECTATOR) { |
440 if (IsOwnedLand(tile) && new_owner != INVALID_OWNER) { |
441 SetTileOwner(tile, new_player); |
441 SetTileOwner(tile, new_owner); |
442 } else if (IsStatueTile(tile)) { |
442 } else if (IsStatueTile(tile)) { |
443 TownID town = GetStatueTownID(tile); |
443 TownID town = GetStatueTownID(tile); |
444 Town *t = GetTown(town); |
444 Town *t = GetTown(town); |
445 ClrBit(t->statues, old_player); |
445 ClrBit(t->statues, old_owner); |
446 if (new_player != PLAYER_SPECTATOR && !HasBit(t->statues, new_player)) { |
446 if (new_owner != INVALID_OWNER && !HasBit(t->statues, new_owner)) { |
447 /* Transfer ownership to the new company */ |
447 /* Transfer ownership to the new company */ |
448 SetBit(t->statues, new_player); |
448 SetBit(t->statues, new_owner); |
449 SetTileOwner(tile, new_player); |
449 SetTileOwner(tile, new_owner); |
450 } else { |
450 } else { |
451 DoClearSquare(tile); |
451 DoClearSquare(tile); |
452 } |
452 } |
453 |
453 |
454 InvalidateWindow(WC_TOWN_AUTHORITY, town); |
454 InvalidateWindow(WC_TOWN_AUTHORITY, town); |