42 DoClearSquare(t + TileDiffXY(1, 1)); |
45 DoClearSquare(t + TileDiffXY(1, 1)); |
43 p->location_of_house = 0; // reset HQ position |
46 p->location_of_house = 0; // reset HQ position |
44 InvalidateWindow(WC_COMPANY, pid); |
47 InvalidateWindow(WC_COMPANY, pid); |
45 } |
48 } |
46 |
49 |
47 // cost of relocating company is 1% of company value |
50 /* cost of relocating company is 1% of company value */ |
48 return CalculateCompanyValue(p) / 100; |
51 return CalculateCompanyValue(p) / 100; |
49 } |
52 } |
50 |
53 |
51 void UpdateCompanyHQ(Player *p, uint score) |
54 void UpdateCompanyHQ(Player *p, uint score) |
52 { |
55 { |
67 MarkTileDirtyByTile(tile + TileDiffXY(0, 1)); |
70 MarkTileDirtyByTile(tile + TileDiffXY(0, 1)); |
68 MarkTileDirtyByTile(tile + TileDiffXY(1, 0)); |
71 MarkTileDirtyByTile(tile + TileDiffXY(1, 0)); |
69 MarkTileDirtyByTile(tile + TileDiffXY(1, 1)); |
72 MarkTileDirtyByTile(tile + TileDiffXY(1, 1)); |
70 } |
73 } |
71 |
74 |
|
75 extern int32 CheckFlatLandBelow(TileIndex tile, uint w, uint h, uint flags, uint invalid_dirs, StationID* station); |
|
76 |
72 /** Build or relocate the HQ. This depends if the HQ is already built or not |
77 /** 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 |
78 * @param tile tile where the HQ will be built or relocated to |
|
79 * @param flags type of operation |
74 * @param p1 unused |
80 * @param p1 unused |
75 * @param p2 unused |
81 * @param p2 unused |
76 */ |
82 */ |
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) |
83 int32 CmdBuildCompanyHQ(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) |
79 { |
84 { |
80 Player *p = GetPlayer(_current_player); |
85 Player *p = GetPlayer(_current_player); |
81 int cost; |
86 int cost; |
82 int32 ret; |
87 int32 ret; |
85 |
90 |
86 ret = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL); |
91 ret = CheckFlatLandBelow(tile, 2, 2, flags, 0, NULL); |
87 if (CmdFailed(ret)) return ret; |
92 if (CmdFailed(ret)) return ret; |
88 cost = ret; |
93 cost = ret; |
89 |
94 |
90 if (p->location_of_house != 0) { /* Moving HQ */ |
95 if (p->location_of_house != 0) { // Moving HQ |
91 cost += DestroyCompanyHQ(_current_player, flags); |
96 cost += DestroyCompanyHQ(_current_player, flags); |
92 } |
97 } |
93 |
98 |
94 if (flags & DC_EXEC) { |
99 if (flags & DC_EXEC) { |
95 int score = UpdateCompanyRatingAndValue(p, false); |
100 int score = UpdateCompanyRatingAndValue(p, false); |
119 DrawClearLandTile(ti, 2); |
124 DrawClearLandTile(ti, 2); |
120 |
125 |
121 dtus = &_draw_tile_unmovable_data[GetUnmovableType(ti->tile)]; |
126 dtus = &_draw_tile_unmovable_data[GetUnmovableType(ti->tile)]; |
122 |
127 |
123 image = dtus->image; |
128 image = dtus->image; |
124 if (_display_opt & DO_TRANS_BUILDINGS) { |
129 if (HASBIT(_transparent_opt, TO_STRUCTURES)) { |
125 SETBIT(image, PALETTE_MODIFIER_TRANSPARENT); |
130 SETBIT(image, PALETTE_MODIFIER_TRANSPARENT); |
126 pal = PALETTE_TO_TRANSPARENT; |
131 pal = PALETTE_TO_TRANSPARENT; |
127 } else { |
132 } else { |
128 pal = PAL_NONE; |
133 pal = PAL_NONE; |
129 } |
134 } |
137 |
142 |
138 case UNMOVABLE_STATUE: |
143 case UNMOVABLE_STATUE: |
139 DrawGroundSprite(SPR_CONCRETE_GROUND, PAL_NONE); |
144 DrawGroundSprite(SPR_CONCRETE_GROUND, PAL_NONE); |
140 |
145 |
141 image = SPR_STATUE_COMPANY; |
146 image = SPR_STATUE_COMPANY; |
142 if (_display_opt & DO_TRANS_BUILDINGS) { |
147 if (HASBIT(_transparent_opt, TO_STRUCTURES)) { |
143 SETBIT(image, PALETTE_MODIFIER_TRANSPARENT); |
148 SETBIT(image, PALETTE_MODIFIER_TRANSPARENT); |
144 pal = PALETTE_TO_TRANSPARENT; |
149 pal = PALETTE_TO_TRANSPARENT; |
145 } else { |
150 } else { |
146 pal = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)); |
151 pal = PLAYER_SPRITE_COLOR(GetTileOwner(ti->tile)); |
147 } |
152 } |
173 t = &_unmovable_display_datas[GetCompanyHQSection(ti->tile)]; |
178 t = &_unmovable_display_datas[GetCompanyHQSection(ti->tile)]; |
174 DrawGroundSprite(t->ground_sprite, palette); |
179 DrawGroundSprite(t->ground_sprite, palette); |
175 |
180 |
176 foreach_draw_tile_seq(dtss, t->seq) { |
181 foreach_draw_tile_seq(dtss, t->seq) { |
177 image = dtss->image; |
182 image = dtss->image; |
178 if (_display_opt & DO_TRANS_BUILDINGS) { |
183 if (HASBIT(_transparent_opt, TO_STRUCTURES)) { |
179 SETBIT(image, PALETTE_MODIFIER_TRANSPARENT); |
184 SETBIT(image, PALETTE_MODIFIER_TRANSPARENT); |
180 pal = PALETTE_TO_TRANSPARENT; |
185 pal = PALETTE_TO_TRANSPARENT; |
181 } else { |
186 } else { |
182 pal = palette; |
187 pal = palette; |
183 } |
188 } |
223 if (IsOwnedLand(tile)) { |
228 if (IsOwnedLand(tile)) { |
224 if (flags & DC_AUTO) return CMD_ERROR; |
229 if (flags & DC_AUTO) return CMD_ERROR; |
225 return DoCommand(tile, 0, 0, flags, CMD_SELL_LAND_AREA); |
230 return DoCommand(tile, 0, 0, flags, CMD_SELL_LAND_AREA); |
226 } |
231 } |
227 |
232 |
228 // checks if you're allowed to remove unmovable things |
233 /* checks if you're allowed to remove unmovable things */ |
229 if (_game_mode != GM_EDITOR && _current_player != OWNER_WATER && ((flags & DC_AUTO || !_cheats.magic_bulldozer.value)) ) |
234 if (_game_mode != GM_EDITOR && _current_player != OWNER_WATER && ((flags & DC_AUTO || !_cheats.magic_bulldozer.value)) ) |
230 return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); |
235 return_cmd_error(STR_5800_OBJECT_IN_THE_WAY); |
231 |
236 |
232 if (IsStatue(tile)) { |
237 if (IsStatue(tile)) { |
233 TownID town = GetStatueTownID(tile); |
238 TownID town = GetStatueTownID(tile); |
251 /* HQ accepts passenger and mail; but we have to divide the values |
256 /* HQ accepts passenger and mail; but we have to divide the values |
252 * between 4 tiles it occupies! */ |
257 * between 4 tiles it occupies! */ |
253 |
258 |
254 level = GetCompanyHQSize(tile) + 1; |
259 level = GetCompanyHQSize(tile) + 1; |
255 |
260 |
256 // Top town building generates 10, so to make HQ interesting, the top |
261 /* Top town building generates 10, so to make HQ interesting, the top |
257 // type makes 20. |
262 * type makes 20. */ |
258 ac[CT_PASSENGERS] = max(1U, level); |
263 ac[CT_PASSENGERS] = max(1U, level); |
259 |
264 |
260 // Top town building generates 4, HQ can make up to 8. The |
265 /* Top town building generates 4, HQ can make up to 8. The |
261 // proportion passengers:mail is different because such a huge |
266 * proportion passengers:mail is different because such a huge |
262 // commercial building generates unusually high amount of mail |
267 * commercial building generates unusually high amount of mail |
263 // correspondence per physical visitor. |
268 * correspondence per physical visitor. */ |
264 ac[CT_MAIL] = max(1U, level / 2); |
269 ac[CT_MAIL] = max(1U, level / 2); |
265 } |
270 } |
266 |
271 |
267 |
272 |
268 static void GetTileDesc_Unmovable(TileIndex tile, TileDesc *td) |
273 static void GetTileDesc_Unmovable(TileIndex tile, TileDesc *td) |
294 |
299 |
295 level = GetCompanyHQSize(tile) + 1; |
300 level = GetCompanyHQSize(tile) + 1; |
296 assert(level < 6); |
301 assert(level < 6); |
297 |
302 |
298 r = Random(); |
303 r = Random(); |
299 // Top town buildings generate 250, so the top HQ type makes 256. |
304 /* Top town buildings generate 250, so the top HQ type makes 256. */ |
300 if (GB(r, 0, 8) < (256 / 4 / (6 - level))) { |
305 if (GB(r, 0, 8) < (256 / 4 / (6 - level))) { |
301 uint amt = GB(r, 0, 8) / 8 / 4 + 1; |
306 uint amt = GB(r, 0, 8) / 8 / 4 + 1; |
302 if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
307 if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
303 MoveGoodsToStation(tile, 2, 2, CT_PASSENGERS, amt); |
308 MoveGoodsToStation(tile, 2, 2, CT_PASSENGERS, amt); |
304 } |
309 } |
305 |
310 |
306 // Top town building generates 90, HQ can make up to 196. The |
311 /* Top town building generates 90, HQ can make up to 196. The |
307 // proportion passengers:mail is about the same as in the acceptance |
312 * proportion passengers:mail is about the same as in the acceptance |
308 // equations. |
313 * equations. */ |
309 if (GB(r, 8, 8) < (196 / 4 / (6 - level))) { |
314 if (GB(r, 8, 8) < (196 / 4 / (6 - level))) { |
310 uint amt = GB(r, 8, 8) / 8 / 4 + 1; |
315 uint amt = GB(r, 8, 8) / 8 / 4 + 1; |
311 if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
316 if (_economy.fluct <= 0) amt = (amt + 1) >> 1; |
312 MoveGoodsToStation(tile, 2, 2, CT_MAIL, amt); |
317 MoveGoodsToStation(tile, 2, 2, CT_MAIL, amt); |
313 } |
318 } |