42 DoClearSquare(t + TileDiffXY(1, 1)); |
44 DoClearSquare(t + TileDiffXY(1, 1)); |
43 p->location_of_house = 0; // reset HQ position |
45 p->location_of_house = 0; // reset HQ position |
44 InvalidateWindow(WC_COMPANY, pid); |
46 InvalidateWindow(WC_COMPANY, pid); |
45 } |
47 } |
46 |
48 |
47 // cost of relocating company is 1% of company value |
49 /* cost of relocating company is 1% of company value */ |
48 return CalculateCompanyValue(p) / 100; |
50 return CalculateCompanyValue(p) / 100; |
49 } |
51 } |
50 |
52 |
51 void UpdateCompanyHQ(Player *p, uint score) |
53 void UpdateCompanyHQ(Player *p, uint score) |
52 { |
54 { |
67 MarkTileDirtyByTile(tile + TileDiffXY(0, 1)); |
69 MarkTileDirtyByTile(tile + TileDiffXY(0, 1)); |
68 MarkTileDirtyByTile(tile + TileDiffXY(1, 0)); |
70 MarkTileDirtyByTile(tile + TileDiffXY(1, 0)); |
69 MarkTileDirtyByTile(tile + TileDiffXY(1, 1)); |
71 MarkTileDirtyByTile(tile + TileDiffXY(1, 1)); |
70 } |
72 } |
71 |
73 |
|
74 extern int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station); |
|
75 |
72 /** Build or relocate the HQ. This depends if the HQ is already built or not |
76 /** Build or relocate the HQ. This depends if the HQ is already built or not |
73 * @param tile tile where the HQ will be built or relocated to |
77 * @param tile tile where the HQ will be built or relocated to |
|
78 * @param flags type of operation |
74 * @param p1 unused |
79 * @param p1 unused |
75 * @param p2 unused |
80 * @param p2 unused |
76 */ |
81 */ |
77 extern int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station); |
|
78 int32 CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
82 int32 CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
79 { |
83 { |
80 Player *p = GetPlayer(_current_player); |
84 Player *p = GetPlayer(_current_player); |
81 int cost; |
85 int cost; |
82 int32 ret; |
86 int32 ret; |
85 |
89 |
86 ret = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL); |
90 ret = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL); |
87 if (CmdFailed(ret)) return ret; |
91 if (CmdFailed(ret)) return ret; |
88 cost = ret; |
92 cost = ret; |
89 |
93 |
90 if (p->location_of_house != 0) { /* Moving HQ */ |
94 if (p->location_of_house != 0) { // Moving HQ |
91 cost += DestroyCompanyHQ(_current_player, flags); |
95 cost += DestroyCompanyHQ(_current_player, flags); |
92 } |
96 } |
93 |
97 |
94 if (flags & DC_EXEC) { |
98 if (flags & DC_EXEC) { |
95 int score = UpdateCompanyRatingAndValue(p, false); |
99 int score = UpdateCompanyRatingAndValue(p, false); |
222 |
226 |
223 if (IsOwnedLand(tile)) { |
227 if (IsOwnedLand(tile)) { |
224 return DoCommand(tile, 0, 0, flags, CMD_SELL_LAND_AREA); |
228 return DoCommand(tile, 0, 0, flags, CMD_SELL_LAND_AREA); |
225 } |
229 } |
226 |
230 |
227 // checks if you're allowed to remove unmovable things |
231 /* checks if you're allowed to remove unmovable things */ |
228 if (_game_mode != GM_EDITOR && _current_player != OWNER_WATER && ((flags & DC_AUTO || !_cheats.magic_bulldozer.value)) ) |
232 if (_game_mode != GM_EDITOR && _current_player != OWNER_WATER && ((flags & DC_AUTO || !_cheats.magic_bulldozer.value)) ) |
229 return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); |
233 return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); |
230 |
234 |
231 if (IsStatue(tile)) { |
235 if (IsStatue(tile)) { |
232 TownID town = GetStatueTownID(tile); |
236 TownID town = GetStatueTownID(tile); |
250 /* HQ accepts passenger and mail; but we have to divide the values |
254 /* HQ accepts passenger and mail; but we have to divide the values |
251 * between 4 tiles it occupies! */ |
255 * between 4 tiles it occupies! */ |
252 |
256 |
253 level = GetCompanyHQSize(tile) + 1; |
257 level = GetCompanyHQSize(tile) + 1; |
254 |
258 |
255 // Top town building generates 10, so to make HQ interesting, the top |
259 /* Top town building generates 10, so to make HQ interesting, the top |
256 // type makes 20. |
260 * type makes 20. */ |
257 ac[CT_PASSENGERS] = max(1U, level); |
261 ac[CT_PASSENGERS] = max(1U, level); |
258 |
262 |
259 // Top town building generates 4, HQ can make up to 8. The |
263 /* Top town building generates 4, HQ can make up to 8. The |
260 // proportion passengers:mail is different because such a huge |
264 * proportion passengers:mail is different because such a huge |
261 // commercial building generates unusually high amount of mail |
265 * commercial building generates unusually high amount of mail |
262 // correspondence per physical visitor. |
266 * correspondence per physical visitor. */ |
263 ac[CT_MAIL] = max(1U, level / 2); |
267 ac[CT_MAIL] = max(1U, level / 2); |
264 } |
268 } |
265 |
269 |
266 |
270 |
267 static void GetTileDesc_Unmovable(TileIndex tile, TileDesc *td) |
271 static void GetTileDesc_Unmovable(TileIndex tile, TileDesc *td) |
293 |
297 |
294 level = GetCompanyHQSize(tile) + 1; |
298 level = GetCompanyHQSize(tile) + 1; |
295 assert(level < 6); |
299 assert(level < 6); |
296 |
300 |
297 r = Random(); |
301 r = Random(); |
298 // Top town buildings generate 250, so the top HQ type makes 256. |
302 /* Top town buildings generate 250, so the top HQ type makes 256. */ |
299 if (GB(r, 0, 8) < (256 / 4 / (6 - level))) { |
303 if (GB(r, 0, 8) < (256 / 4 / (6 - level))) { |
300 uint amt = GB(r, 0, 8) / 8 / 4 + 1; |
304 uint amt = GB(r, 0, 8) / 8 / 4 + 1; |
301 if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
305 if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
302 MoveGoodsToStation(tile, 2, 2, CT_PASSENGERS, amt); |
306 MoveGoodsToStation(tile, 2, 2, CT_PASSENGERS, amt); |
303 } |
307 } |
304 |
308 |
305 // Top town building generates 90, HQ can make up to 196. The |
309 /* Top town building generates 90, HQ can make up to 196. The |
306 // proportion passengers:mail is about the same as in the acceptance |
310 * proportion passengers:mail is about the same as in the acceptance |
307 // equations. |
311 * equations. */ |
308 if (GB(r, 8, 8) < (196 / 4 / (6 - level))) { |
312 if (GB(r, 8, 8) < (196 / 4 / (6 - level))) { |
309 uint amt = GB(r, 8, 8) / 8 / 4 + 1; |
313 uint amt = GB(r, 8, 8) / 8 / 4 + 1; |
310 if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
314 if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
311 MoveGoodsToStation(tile, 2, 2, CT_MAIL, amt); |
315 MoveGoodsToStation(tile, 2, 2, CT_MAIL, amt); |
312 } |
316 } |