OpenTTD Source: src/object_cmd.cpp Source File

OpenTTD Source 15.0-RC2

object_cmd.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11#include "landscape.h"
12#include "command_func.h"
13#include "company_func.h"
14#include "viewport_func.h"
15#include "company_base.h"
16#include "town.h"
17#include "bridge_map.h"
18#include "genworld.h"
19#include "autoslope.h"
20#include "clear_func.h"
21#include "water.h"
22#include "window_func.h"
23#include "company_gui.h"
24#include "cheat_type.h"
25#include "object.h"
26#include "cargopacket.h"
27#include "core/random_func.hpp"
28#include "core/pool_func.hpp"
29#include "object_map.h"
30#include "object_base.h"
31#include "newgrf_config.h"
32#include "newgrf_object.h"
33#include "timer/timer_game_calendar.h"
34#include "newgrf_debug.h"
35#include "vehicle_func.h"
36#include "station_func.h"
37#include "object_cmd.h"
38#include "landscape_cmd.h"
39#include "pathfinder/water_regions.h"
40
41#include "table/strings.h"
42#include "table/object_land.h"
43
44#include "safeguards.h"
45
46 ObjectPool _object_pool("Object");
47 INSTANTIATE_POOL_METHODS(Object)
48/* static */ std::array<uint16_t, NUM_OBJECTS> Object::counts;
49
55/* static */ Object *Object::GetByTile(TileIndex tile)
56{
57 return Object::Get(GetObjectIndex(tile));
58}
59
66 ObjectType GetObjectType(Tile t)
67{
68 assert(IsTileType(t, MP_OBJECT));
69 return Object::GetByTile(t)->type;
70}
71
73 void InitializeObjects()
74{
75 Object::ResetTypeCounts();
76}
77
88 void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, uint8_t view)
89{
90 const ObjectSpec *spec = ObjectSpec::Get(type);
91
92 TileArea ta(tile, GB(spec->size, HasBit(view, 0) ? 4 : 0, 4), GB(spec->size, HasBit(view, 0) ? 0 : 4, 4));
93 Object *o = new Object(type, town == nullptr ? CalcClosestTownFromTile(tile) : town, ta, TimerGameCalendar::date, view);
94
95 /* If nothing owns the object, the colour will be random. Otherwise
96 * get the colour from the company's livery settings. */
97 if (owner == OWNER_NONE) {
98 o->colour = Random();
99 } else {
100 o->colour = Company::Get(owner)->GetCompanyRecolourOffset(LS_DEFAULT);
101 }
102
103 /* If the object wants only one colour, then give it that colour. */
104 if (!spec->flags.Test(ObjectFlag::Uses2CC)) o->colour &= 0xF;
105
106 if (spec->callback_mask.Test(ObjectCallbackMask::Colour)) {
107 uint16_t res = GetObjectCallback(CBID_OBJECT_COLOUR, o->colour, 0, spec, o, tile);
108 if (res != CALLBACK_FAILED) {
109 if (res >= 0x100) ErrorUnknownCallbackResult(spec->grf_prop.grfid, CBID_OBJECT_COLOUR, res);
110 o->colour = GB(res, 0, 8);
111 }
112 }
113
114 assert(o->town != nullptr);
115
116 for (TileIndex t : ta) {
117 if (IsWaterTile(t)) ClearNeighbourNonFloodingStates(t);
118 if (HasTileWaterGround(t)) InvalidateWaterRegion(t);
119 WaterClass wc = (IsWaterTile(t) ? GetWaterClass(t) : WaterClass::Invalid);
120 /* Update company infrastructure counts for objects build on canals owned by nobody. */
121 if (wc == WaterClass::Canal && owner != OWNER_NONE && (IsTileOwner(t, OWNER_NONE) || IsTileOwner(t, OWNER_WATER))) {
122 Company::Get(owner)->infrastructure.water++;
123 DirtyCompanyInfrastructureWindows(owner);
124 }
125 bool remove = IsDockingTile(t);
126 MakeObject(t, owner, o->index, wc, Random());
127 if (remove) RemoveDockingTile(t);
128 MarkTileDirtyByTile(t);
129 }
130
131 Object::IncTypeCount(type);
132 if (spec->flags.Test(ObjectFlag::Animation)) TriggerObjectAnimation(o, ObjectAnimationTrigger::Built, spec);
133}
134
139 static void IncreaseCompanyHQSize(TileIndex tile)
140{
141 TileArea ta = Object::GetByTile(tile)->location;
142 for (TileIndex t : ta) {
143 /* We encode the company HQ size in the animation state. */
144 SetAnimationFrame(t, GetAnimationFrame(t) + 1);
145 MarkTileDirtyByTile(t);
146 }
147}
148
154 static uint8_t GetCompanyHQSize(TileIndex tile)
155{
156 /* We encode the company HQ size in the animation state. */
157 return GetAnimationFrame(tile);
158}
159
165 void UpdateCompanyHQ(TileIndex tile, uint score)
166{
167 if (tile == INVALID_TILE) return;
168
169 uint8_t val = 0;
170 if (score >= 170) val++;
171 if (score >= 350) val++;
172 if (score >= 520) val++;
173 if (score >= 720) val++;
174
175 while (GetCompanyHQSize(tile) < val) {
176 IncreaseCompanyHQSize(tile);
177 }
178}
179
184 void UpdateObjectColours(const Company *c)
185{
186 for (Object *obj : Object::Iterate()) {
187 Owner owner = GetTileOwner(obj->location.tile);
188 /* Not the current owner, so colour doesn't change. */
189 if (owner != c->index) continue;
190
191 const ObjectSpec *spec = ObjectSpec::GetByTile(obj->location.tile);
192 /* Using the object colour callback, so not using company colour. */
193 if (spec->callback_mask.Test(ObjectCallbackMask::Colour)) continue;
194
195 obj->colour = c->GetCompanyRecolourOffset(LS_DEFAULT, spec->flags.Test(ObjectFlag::Uses2CC));
196 }
197}
198
199extern CommandCost CheckBuildableTile(TileIndex tile, DiagDirections invalid_dirs, int &allowed_z, bool allow_steep, bool check_bridge);
200static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlags flags);
201
210 CommandCost CmdBuildObject(DoCommandFlags flags, TileIndex tile, ObjectType type, uint8_t view)
211{
212 CommandCost cost(EXPENSES_CONSTRUCTION);
213
214 if (type >= ObjectSpec::Count()) return CMD_ERROR;
215 const ObjectSpec *spec = ObjectSpec::Get(type);
216 if (_game_mode == GM_NORMAL && !spec->IsAvailable() && !_generating_world) return CMD_ERROR;
217 if ((_game_mode == GM_EDITOR || _generating_world) && !spec->WasEverAvailable()) return CMD_ERROR;
218
219 if (spec->flags.Test(ObjectFlag::OnlyInScenedit) && ((!_generating_world && _game_mode != GM_EDITOR) || _current_company != OWNER_NONE)) return CMD_ERROR;
220 if (spec->flags.Test(ObjectFlag::OnlyInGame) && (_generating_world || _game_mode != GM_NORMAL || _current_company > MAX_COMPANIES)) return CMD_ERROR;
221 if (view >= spec->views) return CMD_ERROR;
222
223 if (!Object::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_OBJECTS);
224 if (Town::GetNumItems() == 0) return CommandCost(STR_ERROR_MUST_FOUND_TOWN_FIRST);
225
226 int size_x = GB(spec->size, HasBit(view, 0) ? 4 : 0, 4);
227 int size_y = GB(spec->size, HasBit(view, 0) ? 0 : 4, 4);
228 TileArea ta(tile, size_x, size_y);
229 for (TileIndex t : ta) {
230 if (!IsValidTile(t)) return CommandCost(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP_SUB); // Might be off the map
231 }
232
233 if (type == OBJECT_OWNED_LAND) {
234 /* Owned land is special as it can be placed on any slope. */
235 cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile));
236 } else {
237 /* Check the surface to build on. At this time we can't actually execute the
238 * the CLEAR_TILE commands since the newgrf callback later on can check
239 * some information about the tiles. */
240 bool allow_water = spec->flags.Any({ObjectFlag::BuiltOnWater, ObjectFlag::NotOnLand});
241 bool allow_ground = !spec->flags.Test(ObjectFlag::NotOnLand);
242 for (TileIndex t : ta) {
243 if (HasTileWaterGround(t)) {
244 if (!allow_water) return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER);
245 if (!IsWaterTile(t)) {
246 /* Normal water tiles don't have to be cleared. For all other tile types clear
247 * the tile but leave the water. */
248 cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(DoCommandFlags{flags}.Reset({DoCommandFlag::NoWater, DoCommandFlag::Execute}), t));
249 } else {
250 /* Can't build on water owned by another company. */
251 Owner o = GetTileOwner(t);
252 if (o != OWNER_NONE && o != OWNER_WATER) cost.AddCost(CheckOwnership(o, t));
253
254 /* If freeform edges are disabled, don't allow building on edge tiles. */
255 if (!_settings_game.construction.freeform_edges && (!IsInsideMM(TileX(t), 1, Map::MaxX() - 1) || !IsInsideMM(TileY(t), 1, Map::MaxY() - 1))) {
256 return CommandCost(STR_ERROR_TOO_CLOSE_TO_EDGE_OF_MAP);
257 }
258
259 /* However, the tile has to be clear of vehicles. */
260 cost.AddCost(EnsureNoVehicleOnGround(t));
261 }
262 } else {
263 if (!allow_ground) return CommandCost(STR_ERROR_MUST_BE_BUILT_ON_WATER);
264 /* For non-water tiles, we'll have to clear it before building. */
265
266 /* When relocating HQ, allow it to be relocated (partial) on itself. */
267 if (!(type == OBJECT_HQ &&
268 IsTileType(t, MP_OBJECT) &&
269 IsTileOwner(t, _current_company) &&
270 IsObjectType(t, OBJECT_HQ))) {
271 cost.AddCost(Command<CMD_LANDSCAPE_CLEAR>::Do(DoCommandFlags{flags}.Reset(DoCommandFlag::Execute), t));
272 }
273 }
274 }
275
276 /* So, now the surface is checked... check the slope of said surface. */
277 auto [slope, allowed_z] = GetTileSlopeZ(tile);
278 if (slope != SLOPE_FLAT) allowed_z++;
279
280 for (TileIndex t : ta) {
281 uint16_t callback = CALLBACK_FAILED;
282 std::array<int32_t, 16> regs100;
283 if (spec->callback_mask.Test(ObjectCallbackMask::SlopeCheck)) {
284 TileIndex diff = t - tile;
285 callback = GetObjectCallback(CBID_OBJECT_LAND_SLOPE_CHECK, GetTileSlope(t), TileY(diff) << 4 | TileX(diff), spec, nullptr, t, regs100, view);
286 }
287
288 if (callback == CALLBACK_FAILED) {
289 cost.AddCost(CheckBuildableTile(t, {}, allowed_z, false, false));
290 } else {
291 /* The meaning of bit 10 is inverted for a grf version < 8. */
292 if (spec->grf_prop.grffile->grf_version < 8) ToggleBit(callback, 10);
293 CommandCost ret = GetErrorMessageFromLocationCallbackResult(callback, regs100, spec->grf_prop.grffile, STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
294 if (ret.Failed()) return ret;
295 }
296 }
297
298 if (flags.Test(DoCommandFlag::Execute)) {
299 /* This is basically a copy of the loop above with the exception that we now
300 * execute the commands and don't check for errors, since that's already done. */
301 for (TileIndex t : ta) {
302 if (HasTileWaterGround(t)) {
303 if (!IsWaterTile(t)) {
304 Command<CMD_LANDSCAPE_CLEAR>::Do(DoCommandFlags{flags}.Reset(DoCommandFlag::NoWater), t);
305 }
306 } else {
307 Command<CMD_LANDSCAPE_CLEAR>::Do(flags, t);
308 }
309 }
310 }
311 }
312 if (cost.Failed()) return cost;
313
314 /* Finally do a check for bridges. */
315 for (TileIndex t : ta) {
316 if (IsBridgeAbove(t) && (
317 !spec->flags.Test(ObjectFlag::AllowUnderBridge) ||
318 (GetTileMaxZ(t) + spec->height >= GetBridgeHeight(GetSouthernBridgeEnd(t))))) {
319 return CommandCost(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
320 }
321 }
322
323 int hq_score = 0;
324 uint build_object_size = 1;
325 switch (type) {
326 case OBJECT_TRANSMITTER:
327 case OBJECT_LIGHTHOUSE:
328 if (!IsTileFlat(tile)) return CommandCost(STR_ERROR_FLAT_LAND_REQUIRED);
329 break;
330
331 case OBJECT_OWNED_LAND:
332 if (IsTileType(tile, MP_OBJECT) &&
333 IsTileOwner(tile, _current_company) &&
334 IsObjectType(tile, OBJECT_OWNED_LAND)) {
335 return CommandCost(STR_ERROR_YOU_ALREADY_OWN_IT);
336 }
337 break;
338
339 case OBJECT_HQ: {
340 Company *c = Company::Get(_current_company);
341 if (c->location_of_HQ != INVALID_TILE) {
342 /* Don't relocate HQ on the same location. */
343 if (c->location_of_HQ == tile) return CommandCost(STR_ERROR_ALREADY_BUILT);
344 /* We need to persuade a bit harder to remove the old HQ. */
345 _current_company = OWNER_WATER;
346 cost.AddCost(ClearTile_Object(c->location_of_HQ, flags));
347 _current_company = c->index;
348 }
349
350 if (flags.Test(DoCommandFlag::Execute)) {
351 hq_score = UpdateCompanyRatingAndValue(c, false);
352 c->location_of_HQ = tile;
353 SetWindowDirty(WC_COMPANY, c->index);
354 }
355 break;
356 }
357
358 case OBJECT_STATUE:
359 /* This may never be constructed using this method. */
360 return CMD_ERROR;
361
362 default: // i.e. NewGRF provided.
363 build_object_size = size_x * size_y;
364 break;
365 }
366
367 /* Don't allow building more objects if the company has reached its limit. */
368 Company *c = Company::GetIfValid(_current_company);
369 if (c != nullptr && GB(c->build_object_limit, 16, 16) < build_object_size) {
370 return CommandCost(STR_ERROR_BUILD_OBJECT_LIMIT_REACHED);
371 }
372
373 if (flags.Test(DoCommandFlag::Execute)) {
374 BuildObject(type, tile, _current_company == OWNER_DEITY ? OWNER_NONE : _current_company, nullptr, view);
375
376 /* Make sure the HQ starts at the right size. */
377 if (type == OBJECT_HQ) UpdateCompanyHQ(tile, hq_score);
378
379 /* Subtract the tile from the build limit. */
380 if (c != nullptr) c->build_object_limit -= build_object_size << 16;
381 }
382
383 cost.AddCost(spec->GetBuildCost() * build_object_size);
384 return cost;
385}
386
397 CommandCost CmdBuildObjectArea(DoCommandFlags flags, TileIndex tile, TileIndex start_tile, ObjectType type, uint8_t view, bool diagonal)
398{
399 if (start_tile >= Map::Size()) return CMD_ERROR;
400
401 if (type >= ObjectSpec::Count()) return CMD_ERROR;
402 const ObjectSpec *spec = ObjectSpec::Get(type);
403 if (view >= spec->views) return CMD_ERROR;
404
405 if (spec->size != OBJECT_SIZE_1X1) return CMD_ERROR;
406
407 Money money = GetAvailableMoneyForCommand();
408 CommandCost cost(EXPENSES_CONSTRUCTION);
409 CommandCost last_error = CMD_ERROR;
410 bool had_success = false;
411
412 const Company *c = Company::GetIfValid(_current_company);
413 int limit = (c == nullptr ? INT32_MAX : GB(c->build_object_limit, 16, 16));
414
415 std::unique_ptr<TileIterator> iter = TileIterator::Create(tile, start_tile, diagonal);
416 for (; *iter != INVALID_TILE; ++(*iter)) {
417 TileIndex t = *iter;
418 CommandCost ret = Command<CMD_BUILD_OBJECT>::Do(DoCommandFlags{flags}.Reset(DoCommandFlag::Execute), t, type, view);
419
420 /* If we've reached the limit, stop building (or testing). */
421 if (c != nullptr && limit-- <= 0) break;
422
423 if (ret.Failed()) {
424 last_error = std::move(ret);
425 continue;
426 }
427
428 had_success = true;
429 if (flags.Test(DoCommandFlag::Execute)) {
430 money -= ret.GetCost();
431
432 /* If we run out of money, stop building. */
433 if (ret.GetCost() > 0 && money < 0) break;
434 Command<CMD_BUILD_OBJECT>::Do(flags, t, type, view);
435 }
436 cost.AddCost(ret.GetCost());
437 }
438
439 return had_success ? cost : last_error;
440}
441
442static Foundation GetFoundation_Object(TileIndex tile, Slope tileh);
443
444static void DrawTile_Object(TileInfo *ti)
445{
446 ObjectType type = GetObjectType(ti->tile);
447 const ObjectSpec *spec = ObjectSpec::Get(type);
448
449 /* Fall back for when the object doesn't exist anymore. */
450 if (!spec->IsEnabled()) type = OBJECT_TRANSMITTER;
451
452 if (!spec->flags.Test(ObjectFlag::HasNoFoundation)) DrawFoundation(ti, GetFoundation_Object(ti->tile, ti->tileh));
453
454 if (type < NEW_OBJECT_OFFSET) {
455 const DrawTileSprites *dts = nullptr;
456 Owner to = GetTileOwner(ti->tile);
457 PaletteID palette = to == OWNER_NONE ? PAL_NONE : GetCompanyPalette(to);
458
459 if (type == OBJECT_HQ) {
460 TileIndex diff = ti->tile - Object::GetByTile(ti->tile)->location.tile;
461 dts = &_object_hq[GetCompanyHQSize(ti->tile) << 2 | TileY(diff) << 1 | TileX(diff)];
462 } else {
463 dts = &_objects[type];
464 }
465
466 if (spec->flags.Test(ObjectFlag::HasNoFoundation)) {
467 /* If an object has no foundation, but tries to draw a (flat) ground
468 * type... we have to be nice and convert that for them. */
469 switch (dts->ground.sprite) {
470 case SPR_FLAT_BARE_LAND: DrawClearLandTile(ti, 0); break;
471 case SPR_FLAT_1_THIRD_GRASS_TILE: DrawClearLandTile(ti, 1); break;
472 case SPR_FLAT_2_THIRD_GRASS_TILE: DrawClearLandTile(ti, 2); break;
473 case SPR_FLAT_GRASS_TILE: DrawClearLandTile(ti, 3); break;
474 default: DrawGroundSprite(dts->ground.sprite, palette); break;
475 }
476 } else {
477 DrawGroundSprite(dts->ground.sprite, palette);
478 }
479
480 if (!IsInvisibilitySet(TO_STRUCTURES)) {
481 for (const DrawTileSeqStruct &dtss : dts->GetSequence()) {
482 AddSortableSpriteToDraw(dtss.image.sprite, palette, *ti, dtss, IsTransparencySet(TO_STRUCTURES));
483 }
484 }
485 } else {
486 DrawNewObjectTile(ti, spec);
487 }
488
489 DrawBridgeMiddle(ti, {});
490}
491
492static int GetSlopePixelZ_Object(TileIndex tile, uint x, uint y, bool)
493{
494 if (IsObjectType(tile, OBJECT_OWNED_LAND)) {
495 auto [tileh, z] = GetTilePixelSlope(tile);
496
497 return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
498 } else {
499 return GetTileMaxPixelZ(tile);
500 }
501}
502
503static Foundation GetFoundation_Object(TileIndex tile, Slope tileh)
504{
505 return IsObjectType(tile, OBJECT_OWNED_LAND) ? FOUNDATION_NONE : FlatteningFoundation(tileh);
506}
507
512 static void ReallyClearObjectTile(Object *o)
513{
514 Object::DecTypeCount(o->type);
515 for (TileIndex tile_cur : o->location) {
516 DeleteNewGRFInspectWindow(GSF_OBJECTS, tile_cur.base());
517
518 MakeWaterKeepingClass(tile_cur, GetTileOwner(tile_cur));
519 }
520 delete o;
521}
522
523std::vector<ClearedObjectArea> _cleared_object_areas;
524
530 ClearedObjectArea *FindClearedObject(TileIndex tile)
531{
532 TileArea ta = TileArea(tile, 1, 1);
533
534 for (ClearedObjectArea &coa : _cleared_object_areas) {
535 if (coa.area.Intersects(ta)) return &coa;
536 }
537
538 return nullptr;
539}
540
541static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlags flags)
542{
543 /* Get to the northern most tile. */
544 Object *o = Object::GetByTile(tile);
545 TileArea ta = o->location;
546
547 ObjectType type = o->type;
548 const ObjectSpec *spec = ObjectSpec::Get(type);
549
550 CommandCost cost(EXPENSES_CONSTRUCTION, spec->GetClearCost() * ta.w * ta.h / 5);
551 if (spec->flags.Test(ObjectFlag::ClearIncome)) cost.MultiplyCost(-1); // They get an income!
552
553 /* Towns can't remove any objects. */
554 if (_current_company == OWNER_TOWN) return CMD_ERROR;
555
556 /* Water can remove everything! */
557 if (_current_company != OWNER_WATER) {
558 if (flags.Test(DoCommandFlag::NoWater) && IsTileOnWater(tile)) {
559 /* There is water under the object, treat it as water tile. */
560 return CommandCost(STR_ERROR_CAN_T_BUILD_ON_WATER);
561 } else if (!spec->flags.Test(ObjectFlag::Autoremove) && flags.Test(DoCommandFlag::Auto)) {
562 /* No automatic removal by overbuilding stuff. */
563 return CommandCost(type == OBJECT_HQ ? STR_ERROR_COMPANY_HEADQUARTERS_IN : STR_ERROR_OBJECT_IN_THE_WAY);
564 } else if (_game_mode == GM_EDITOR) {
565 /* No further limitations for the editor. */
566 } else if (GetTileOwner(tile) == OWNER_NONE) {
567 /* Owned by nobody and unremovable, so we can only remove it with brute force! */
568 if (!_cheats.magic_bulldozer.value && spec->flags.Test(ObjectFlag::CannotRemove)) return CMD_ERROR;
569 } else if (CheckTileOwnership(tile).Failed()) {
570 /* We don't own it!. */
571 return CommandCost(STR_ERROR_OWNED_BY);
572 } else if (spec->flags.Test(ObjectFlag::CannotRemove) && !spec->flags.Test(ObjectFlag::Autoremove)) {
573 /* In the game editor or with cheats we can remove, otherwise we can't. */
574 if (!_cheats.magic_bulldozer.value) {
575 if (type == OBJECT_HQ) return CommandCost(STR_ERROR_COMPANY_HEADQUARTERS_IN);
576 return CMD_ERROR;
577 }
578
579 /* Removing with the cheat costs more in TTDPatch / the specs. */
580 cost.MultiplyCost(25);
581 }
582 } else if (spec->flags.Any({ObjectFlag::BuiltOnWater, ObjectFlag::NotOnLand})) {
583 /* Water can't remove objects that are buildable on water. */
584 return CMD_ERROR;
585 }
586
587 switch (type) {
588 case OBJECT_HQ: {
589 Company *c = Company::Get(GetTileOwner(tile));
590 if (flags.Test(DoCommandFlag::Execute)) {
591 c->location_of_HQ = INVALID_TILE; // reset HQ position
592 SetWindowDirty(WC_COMPANY, c->index);
593 CargoPacket::InvalidateAllFrom({c->index, SourceType::Headquarters});
594 }
595
596 /* cost of relocating company is 1% of company value */
597 cost = CommandCost(EXPENSES_CONSTRUCTION, CalculateCompanyValue(c) / 100);
598 break;
599 }
600
601 case OBJECT_STATUE:
602 if (flags.Test(DoCommandFlag::Execute)) {
603 Town *town = o->town;
604 town->statues.Reset(GetTileOwner(tile));
605 SetWindowDirty(WC_TOWN_AUTHORITY, town->index);
606 }
607 break;
608
609 default:
610 break;
611 }
612
613 _cleared_object_areas.emplace_back(tile, ta);
614
615 if (flags.Test(DoCommandFlag::Execute)) ReallyClearObjectTile(o);
616
617 return cost;
618}
619
620static void AddAcceptedCargo_Object(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted)
621{
622 if (!IsObjectType(tile, OBJECT_HQ)) return;
623
624 /* HQ accepts passenger and mail; but we have to divide the values
625 * between 4 tiles it occupies! */
626
627 /* HQ level (depends on company performance) in the range 1..5. */
628 uint level = GetCompanyHQSize(tile) + 1;
629
630 /* Top town building generates 10, so to make HQ interesting, the top
631 * type makes 20. */
632 CargoType pass = GetCargoTypeByLabel(CT_PASSENGERS);
633 if (IsValidCargoType(pass)) {
634 acceptance[pass] += std::max(1U, level);
635 SetBit(always_accepted, pass);
636 }
637
638 /* Top town building generates 4, HQ can make up to 8. The
639 * proportion passengers:mail is different because such a huge
640 * commercial building generates unusually high amount of mail
641 * correspondence per physical visitor. */
642 CargoType mail = GetCargoTypeByLabel(CT_MAIL);
643 if (IsValidCargoType(mail)) {
644 acceptance[mail] += std::max(1U, level / 2);
645 SetBit(always_accepted, mail);
646 }
647}
648
649static void AddProducedCargo_Object(TileIndex tile, CargoArray &produced)
650{
651 if (!IsObjectType(tile, OBJECT_HQ)) return;
652
653 CargoType pass = GetCargoTypeByLabel(CT_PASSENGERS);
654 if (IsValidCargoType(pass)) produced[pass]++;
655 CargoType mail = GetCargoTypeByLabel(CT_MAIL);
656 if (IsValidCargoType(mail)) produced[mail]++;
657}
658
659
660static void GetTileDesc_Object(TileIndex tile, TileDesc &td)
661{
662 const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
663 td.str = spec->name;
664 td.owner[0] = GetTileOwner(tile);
665 td.build_date = Object::GetByTile(tile)->build_date;
666
667 if (spec->grf_prop.HasGrfFile()) {
668 td.grf = GetGRFConfig(spec->grf_prop.grfid)->GetName();
669 }
670}
671
672static void TileLoop_Object(TileIndex tile)
673{
674 const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
675 if (spec->flags.Test(ObjectFlag::Animation)) {
676 Object *o = Object::GetByTile(tile);
677 TriggerObjectTileAnimation(o, tile, ObjectAnimationTrigger::TileLoop, spec);
678 if (o->location.tile == tile) TriggerObjectAnimation(o, ObjectAnimationTrigger::TileLoopNorth, spec);
679 }
680
681 if (IsTileOnWater(tile)) TileLoop_Water(tile);
682
683 if (!IsObjectType(tile, OBJECT_HQ)) return;
684
685 /* HQ accepts passenger and mail; but we have to divide the values
686 * between 4 tiles it occupies! */
687
688 /* HQ level (depends on company performance) in the range 1..5. */
689 uint level = GetCompanyHQSize(tile) + 1;
690 assert(level < 6);
691
692 StationFinder stations(TileArea(tile, 2, 2));
693
694 uint r = Random();
695 /* Top town buildings generate 250, so the top HQ type makes 256. */
696 CargoType pass = GetCargoTypeByLabel(CT_PASSENGERS);
697 if (IsValidCargoType(pass) && GB(r, 0, 8) < (256 / 4 / (6 - level))) {
698 uint amt = GB(r, 0, 8) / 8 / 4 + 1;
699
700 /* Production is halved during recessions. */
701 if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
702
703 /* Scale by cargo scale setting. */
704 amt = ScaleByCargoScale(amt, true);
705
706 MoveGoodsToStation(pass, amt, {GetTileOwner(tile), SourceType::Headquarters}, stations.GetStations());
707 }
708
709 /* Top town building generates 90, HQ can make up to 196. The
710 * proportion passengers:mail is about the same as in the acceptance
711 * equations. */
712 CargoType mail = GetCargoTypeByLabel(CT_MAIL);
713 if (IsValidCargoType(mail) && GB(r, 8, 8) < (196 / 4 / (6 - level))) {
714 uint amt = GB(r, 8, 8) / 8 / 4 + 1;
715
716 /* Production is halved during recessions. */
717 if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
718
719 /* Scale by cargo scale setting. */
720 amt = ScaleByCargoScale(amt, true);
721
722 MoveGoodsToStation(mail, amt, {GetTileOwner(tile), SourceType::Headquarters}, stations.GetStations());
723 }
724}
725
726
727static TrackStatus GetTileTrackStatus_Object(TileIndex, TransportType, uint, DiagDirection)
728{
729 return 0;
730}
731
732static bool ClickTile_Object(TileIndex tile)
733{
734 if (!IsObjectType(tile, OBJECT_HQ)) return false;
735
736 ShowCompany(GetTileOwner(tile));
737 return true;
738}
739
740static void AnimateTile_Object(TileIndex tile)
741{
742 AnimateNewObjectTile(tile);
743}
744
749 static bool TryBuildLightHouse()
750{
751 uint maxx = Map::MaxX();
752 uint maxy = Map::MaxY();
753 uint r = Random();
754
755 /* Scatter the lighthouses more evenly around the perimeter */
756 int perimeter = (GB(r, 16, 16) % (2 * (maxx + maxy))) - maxy;
757 DiagDirection dir;
758 for (dir = DIAGDIR_NE; perimeter > 0; dir++) {
759 perimeter -= (DiagDirToAxis(dir) == AXIS_X) ? maxx : maxy;
760 }
761
762 TileIndex tile;
763 switch (dir) {
764 default:
765 case DIAGDIR_NE: tile = TileXY(maxx - 1, r % maxy); break;
766 case DIAGDIR_SE: tile = TileXY(r % maxx, 1); break;
767 case DIAGDIR_SW: tile = TileXY(1, r % maxy); break;
768 case DIAGDIR_NW: tile = TileXY(r % maxx, maxy - 1); break;
769 }
770
771 /* Only build lighthouses at tiles where the border is sea. */
772 if (!IsTileType(tile, MP_WATER) || GetWaterClass(tile) != WaterClass::Sea) return false;
773
774 for (int j = 0; j < 19; j++) {
775 int h;
776 if (IsTileType(tile, MP_CLEAR) && IsTileFlat(tile, &h) && h <= 2 && !IsBridgeAbove(tile)) {
777 for (auto t : SpiralTileSequence(tile, 9)) {
778 if (IsObjectTypeTile(t, OBJECT_LIGHTHOUSE)) return false;
779 }
780 BuildObject(OBJECT_LIGHTHOUSE, tile);
781 assert(tile < Map::Size());
782 return true;
783 }
784 tile += TileOffsByDiagDir(dir);
785 if (!IsValidTile(tile)) return false;
786 }
787 return false;
788}
789
794 static bool TryBuildTransmitter()
795{
796 TileIndex tile = RandomTile();
797 int h;
798 if (IsTileType(tile, MP_CLEAR) && IsTileFlat(tile, &h) && h >= 4 && !IsBridgeAbove(tile)) {
799 for (auto t : SpiralTileSequence(tile, 9)) {
800 if (IsObjectTypeTile(t, OBJECT_TRANSMITTER)) return false;
801 }
802 BuildObject(OBJECT_TRANSMITTER, tile);
803 return true;
804 }
805 return false;
806}
807
808void GenerateObjects()
809{
810 /* Set a guestimate on how much we progress */
811 SetGeneratingWorldProgress(GWP_OBJECT, (uint)ObjectSpec::Count());
812
813 /* Determine number of water tiles at map border needed for freeform_edges */
814 uint num_water_tiles = 0;
815 if (_settings_game.construction.freeform_edges) {
816 for (uint x = 0; x < Map::MaxX(); x++) {
817 if (IsTileType(TileXY(x, 1), MP_WATER)) num_water_tiles++;
818 if (IsTileType(TileXY(x, Map::MaxY() - 1), MP_WATER)) num_water_tiles++;
819 }
820 for (uint y = 1; y < Map::MaxY() - 1; y++) {
821 if (IsTileType(TileXY(1, y), MP_WATER)) num_water_tiles++;
822 if (IsTileType(TileXY(Map::MaxX() - 1, y), MP_WATER)) num_water_tiles++;
823 }
824 }
825
826 /* Iterate over all possible object types */
827 for (const auto &spec : ObjectSpec::Specs()) {
828
829 /* Continue, if the object was never available till now or shall not be placed */
830 if (!spec.WasEverAvailable() || spec.generate_amount == 0) continue;
831
832 uint16_t amount = spec.generate_amount;
833
834 /* Scale by map size */
835 if (spec.flags.Test(ObjectFlag::ScaleByWater) && _settings_game.construction.freeform_edges) {
836 /* Scale the amount of lighthouses with the amount of land at the borders.
837 * The -6 is because the top borders are MP_VOID (-2) and all corners
838 * are counted twice (-4). */
839 amount = Map::ScaleBySize1D(amount * num_water_tiles) / (2 * Map::MaxY() + 2 * Map::MaxX() - 6);
840 } else if (spec.flags.Test(ObjectFlag::ScaleByWater)) {
841 amount = Map::ScaleBySize1D(amount);
842 } else {
843 amount = Map::ScaleBySize(amount);
844 }
845
846 /* Now try to place the requested amount of this object */
847 for (uint j = Map::ScaleBySize(1000); j != 0 && amount != 0 && Object::CanAllocateItem(); j--) {
848 switch (spec.Index()) {
849 case OBJECT_TRANSMITTER:
850 if (TryBuildTransmitter()) amount--;
851 break;
852
853 case OBJECT_LIGHTHOUSE:
854 if (TryBuildLightHouse()) amount--;
855 break;
856
857 default:
858 uint8_t view = RandomRange(spec.views);
859 if (CmdBuildObject({DoCommandFlag::Execute, DoCommandFlag::Auto, DoCommandFlag::NoTestTownRating, DoCommandFlag::NoModifyTownRating}, RandomTile(), spec.Index(), view).Succeeded()) amount--;
860 break;
861 }
862 }
863 IncreaseGeneratingWorldProgress(GWP_OBJECT);
864 }
865}
866
867static void ChangeTileOwner_Object(TileIndex tile, Owner old_owner, Owner new_owner)
868{
869 if (!IsTileOwner(tile, old_owner)) return;
870
871 bool do_clear = false;
872
873 ObjectType type = GetObjectType(tile);
874 if ((type == OBJECT_OWNED_LAND || type >= NEW_OBJECT_OFFSET) && new_owner != INVALID_OWNER) {
875 SetTileOwner(tile, new_owner);
876 if (GetWaterClass(tile) == WaterClass::Canal) {
877 Company::Get(old_owner)->infrastructure.water--;
878 Company::Get(new_owner)->infrastructure.water++;
879 }
880 } else if (type == OBJECT_STATUE) {
881 Town *t = Object::GetByTile(tile)->town;
882 t->statues.Reset(old_owner);
883 if (new_owner != INVALID_OWNER && !t->statues.Test(new_owner)) {
884 /* Transfer ownership to the new company */
885 t->statues.Set(new_owner);
886 SetTileOwner(tile, new_owner);
887 } else {
888 do_clear = true;
889 }
890
891 SetWindowDirty(WC_TOWN_AUTHORITY, t->index);
892 } else {
893 do_clear = true;
894 }
895
896 if (do_clear) {
897 ReallyClearObjectTile(Object::GetByTile(tile));
898 /* When clearing objects, they may turn into canal, which may require transferring ownership. */
899 ChangeTileOwner(tile, old_owner, new_owner);
900 }
901}
902
903static CommandCost TerraformTile_Object(TileIndex tile, DoCommandFlags flags, int z_new, Slope tileh_new)
904{
905 ObjectType type = GetObjectType(tile);
906
907 if (type == OBJECT_OWNED_LAND) {
908 /* Owned land remains unsold */
909 CommandCost ret = CheckTileOwnership(tile);
910 if (ret.Succeeded()) return CommandCost();
911 } else if (AutoslopeEnabled() && type != OBJECT_TRANSMITTER && type != OBJECT_LIGHTHOUSE) {
912 /* Behaviour:
913 * - Both new and old slope must not be steep.
914 * - TileMaxZ must not be changed.
915 * - Allow autoslope by default.
916 * - Disallow autoslope if callback succeeds and returns non-zero.
917 */
918 Slope tileh_old = GetTileSlope(tile);
919 /* TileMaxZ must not be changed. Slopes must not be steep. */
920 if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
921 const ObjectSpec *spec = ObjectSpec::Get(type);
922
923 /* Call callback 'disable autosloping for objects'. */
924 if (spec->callback_mask.Test(ObjectCallbackMask::Autoslope)) {
925 /* If the callback fails, allow autoslope. */
926 uint16_t res = GetObjectCallback(CBID_OBJECT_AUTOSLOPE, 0, 0, spec, Object::GetByTile(tile), tile);
927 if (res == CALLBACK_FAILED || !ConvertBooleanCallback(spec->grf_prop.grffile, CBID_OBJECT_AUTOSLOPE, res)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
928 } else if (spec->IsEnabled()) {
929 /* allow autoslope */
930 return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
931 }
932 }
933 }
934
935 return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
936}
937
938static CommandCost CheckBuildAbove_Object(TileIndex tile, DoCommandFlags flags, Axis, int height)
939{
940 const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
941 if (spec->flags.Test(ObjectFlag::AllowUnderBridge) && GetTileMaxZ(tile) + spec->height <= height) {
942 return CommandCost();
943 }
944
945 return Command<CMD_LANDSCAPE_CLEAR>::Do(flags, tile);
946}
947
948extern const TileTypeProcs _tile_type_object_procs = {
949 DrawTile_Object, // draw_tile_proc
950 GetSlopePixelZ_Object, // get_slope_z_proc
951 ClearTile_Object, // clear_tile_proc
952 AddAcceptedCargo_Object, // add_accepted_cargo_proc
953 GetTileDesc_Object, // get_tile_desc_proc
954 GetTileTrackStatus_Object, // get_tile_track_status_proc
955 ClickTile_Object, // click_tile_proc
956 AnimateTile_Object, // animate_tile_proc
957 TileLoop_Object, // tile_loop_proc
958 ChangeTileOwner_Object, // change_tile_owner_proc
959 AddProducedCargo_Object, // add_produced_cargo_proc
960 nullptr, // vehicle_enter_tile_proc
961 GetFoundation_Object, // get_foundation_proc
962 TerraformTile_Object, // terraform_tile_proc
963 CheckBuildAbove_Object, // check_build_above_proc
964};
autoslope.h
Functions related to autoslope.
AutoslopeEnabled
bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
Definition autoslope.h:65
GB
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
Definition bitmath_func.hpp:32
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
HasBit
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
ToggleBit
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
Definition bitmath_func.hpp:157
DrawBridgeMiddle
void DrawBridgeMiddle(const TileInfo *ti, BridgePillarFlags blocked_pillars)
Draw the middle bits of a bridge.
Definition tunnelbridge_cmd.cpp:1607
GetSouthernBridgeEnd
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
Definition bridge_map.cpp:49
GetBridgeHeight
int GetBridgeHeight(TileIndex t)
Get the height ('z') of a bridge.
Definition bridge_map.cpp:70
bridge_map.h
Map accessor functions for bridges.
IsBridgeAbove
bool IsBridgeAbove(Tile t)
checks if a bridge is set above the ground of this tile
Definition bridge_map.h:45
CargoType
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:21
IsValidCargoType
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
Definition cargo_type.h:104
CT_PASSENGERS
static constexpr CargoLabel CT_PASSENGERS
Available types of cargo Labels may be re-used between different climates.
Definition cargo_type.h:29
cargopacket.h
Base class for cargo packets.
_cheats
Cheats _cheats
All the cheats.
Definition cheat.cpp:16
cheat_type.h
Types related to cheating.
BaseBitSet::Test
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition base_bitset_type.hpp:141
BaseBitSet::Reset
constexpr Timpl & Reset()
Reset all bits.
Definition base_bitset_type.hpp:83
BaseBitSet::Set
constexpr Timpl & Set()
Set all bits.
Definition base_bitset_type.hpp:40
BaseBitSet::Any
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Definition base_bitset_type.hpp:170
CommandCost
Common return value for all commands.
Definition command_type.h:24
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition command_type.h:168
CommandCost::AddCost
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition command_type.h:98
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition command_type.h:118
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition command_type.h:177
CommandCost::MultiplyCost
void MultiplyCost(int factor)
Multiplies the cost of the command by the given factor.
Definition command_type.h:109
EnumBitSet
Enum-as-bit-set wrapper.
Definition enum_type.hpp:177
OverflowSafeInt< int64_t >
SpiralTileSequence
Generate TileIndices around a center tile or tile area, with increasing distance.
Definition tilearea_type.h:316
StationFinder
Structure contains cached list of stations nearby.
Definition station_type.h:137
TileIterator::Create
static std::unique_ptr< TileIterator > Create(TileIndex corner1, TileIndex corner2, bool diagonal)
Create either an OrthogonalTileIterator or DiagonalTileIterator given the diagonal parameter.
Definition tilearea.cpp:291
Tile
Wrapper class to abstract away the way the tiles are stored.
Definition map_func.h:25
TimerGameCalendar::date
static Date date
Current date in days (day counter).
Definition timer_game_calendar.h:33
clear_func.h
Functions related to clear (MP_CLEAR) land.
command_func.h
Functions related to commands.
CMD_ERROR
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition command_func.h:28
DoCommandFlag::Auto
@ Auto
don't allow building on structures
DoCommandFlag::NoModifyTownRating
@ NoModifyTownRating
do not change town rating
DoCommandFlag::NoWater
@ NoWater
don't allow building on water
DoCommandFlag::Execute
@ Execute
execute the given command
DoCommandFlag::NoTestTownRating
@ NoTestTownRating
town rating does not disallow you from building
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
CalculateCompanyValue
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
Definition economy.cpp:150
CheckTileOwnership
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
Definition company_cmd.cpp:404
GetCompanyPalette
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
Definition company_cmd.cpp:164
GetAvailableMoneyForCommand
Money GetAvailableMoneyForCommand()
This functions returns the money which can be used to execute a command.
Definition company_cmd.cpp:252
CheckOwnership
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
Definition company_cmd.cpp:381
_current_company
CompanyID _current_company
Company currently doing an action.
Definition company_cmd.cpp:56
company_func.h
Functions related to companies.
ShowCompany
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
Definition company_gui.cpp:2307
DirtyCompanyInfrastructureWindows
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
Definition company_gui.cpp:2318
company_gui.h
GUI Functions related to companies.
OWNER_DEITY
static constexpr Owner OWNER_DEITY
The object is owned by a superuser / goal script.
Definition company_type.h:28
OWNER_TOWN
static constexpr Owner OWNER_TOWN
A town owns the tile, or a town is expanding.
Definition company_type.h:25
OWNER_NONE
static constexpr Owner OWNER_NONE
The tile has no ownership.
Definition company_type.h:26
INVALID_OWNER
static constexpr Owner INVALID_OWNER
An invalid owner.
Definition company_type.h:30
OWNER_WATER
static constexpr Owner OWNER_WATER
The tile/execution is done by "water".
Definition company_type.h:27
DiagDirToAxis
Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Definition direction_func.h:214
Axis
Axis
Allow incrementing of DiagDirDiff variables.
Definition direction_type.h:123
AXIS_X
@ AXIS_X
The X axis.
Definition direction_type.h:124
DiagDirection
DiagDirection
Enumeration for diagonal directions.
Definition direction_type.h:78
DIAGDIR_NE
@ DIAGDIR_NE
Northeast, upper right on your monitor.
Definition direction_type.h:80
DIAGDIR_NW
@ DIAGDIR_NW
Northwest.
Definition direction_type.h:83
DIAGDIR_SE
@ DIAGDIR_SE
Southeast.
Definition direction_type.h:81
DIAGDIR_SW
@ DIAGDIR_SW
Southwest.
Definition direction_type.h:82
UpdateCompanyRatingAndValue
int UpdateCompanyRatingAndValue(Company *c, bool update)
if update is set to true, the economy is updated with this score (also the house is updated,...
Definition economy.cpp:202
EconomyIsInRecession
bool EconomyIsInRecession()
Is the economy in recession?
Definition economy_func.h:50
ScaleByCargoScale
uint ScaleByCargoScale(uint num, bool town)
Scale a number by the cargo scale setting.
Definition economy_func.h:78
EXPENSES_CONSTRUCTION
@ EXPENSES_CONSTRUCTION
Construction costs.
Definition economy_type.h:179
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition genworld.cpp:74
genworld.h
Functions related to world/map generation.
IncreaseGeneratingWorldProgress
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
Definition genworld_gui.cpp:1534
GWP_OBJECT
@ GWP_OBJECT
Generate objects (radio tower, light houses)
Definition genworld.h:69
SetGeneratingWorldProgress
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
Definition genworld_gui.cpp:1520
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:18
MarkTileDirtyByTile
void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset, int tile_height_override)
Mark a tile given by its index dirty for repaint.
Definition viewport.cpp:2128
GetPartialPixelZ
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition landscape.cpp:231
ChangeTileOwner
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
Definition landscape.cpp:570
DrawFoundation
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition landscape.cpp:428
landscape.h
Functions related to OTTD's landscape.
landscape_cmd.h
Command definitions related to landscape (slopes etc.).
BorderFlag::Random
@ Random
Randomise borders.
TileXY
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition map_func.h:385
TileY
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition map_func.h:437
TileX
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition map_func.h:427
RandomTile
#define RandomTile()
Get a valid random tile.
Definition map_func.h:664
TileOffsByDiagDir
TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition map_func.h:582
IsInsideMM
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition math_func.hpp:267
CBID_OBJECT_LAND_SLOPE_CHECK
@ CBID_OBJECT_LAND_SLOPE_CHECK
Callback done for each tile of an object to check the slope.
Definition newgrf_callbacks.h:256
CBID_OBJECT_AUTOSLOPE
@ CBID_OBJECT_AUTOSLOPE
Called to determine if one can alter the ground below an object tile.
Definition newgrf_callbacks.h:274
CBID_OBJECT_COLOUR
@ CBID_OBJECT_COLOUR
Called to determine the colour of a town building.
Definition newgrf_callbacks.h:268
ObjectCallbackMask::Autoslope
@ Autoslope
decides allowance of autosloping
ObjectCallbackMask::Colour
@ Colour
decide the colour of the building
ObjectCallbackMask::SlopeCheck
@ SlopeCheck
decides slope suitability
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition newgrf_callbacks.h:439
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition newgrf_commons.cpp:517
GetErrorMessageFromLocationCallbackResult
CommandCost GetErrorMessageFromLocationCallbackResult(uint16_t cb_res, std::span< const int32_t > textstack, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
Definition newgrf_commons.cpp:471
ConvertBooleanCallback
bool ConvertBooleanCallback(const GRFFile *grffile, uint16_t cbid, uint16_t cb_res)
Converts a callback result into a boolean.
Definition newgrf_commons.cpp:543
GetGRFConfig
GRFConfig * GetGRFConfig(uint32_t grfid, uint32_t mask)
Retrieve a NewGRF from the current config by its grfid.
Definition newgrf_config.cpp:622
newgrf_config.h
Functions to find and configure NewGRFs.
newgrf_debug.h
Functions/types related to NewGRF debugging.
DeleteNewGRFInspectWindow
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
Definition newgrf_debug_gui.cpp:726
DrawNewObjectTile
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Draw an object on the map.
Definition newgrf_object.cpp:472
TriggerObjectAnimation
bool TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a whole object.
Definition newgrf_object.cpp:587
TriggerObjectTileAnimation
bool TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a single tile.
Definition newgrf_object.cpp:576
AnimateNewObjectTile
void AnimateNewObjectTile(TileIndex tile)
Handle the animation of the object tile.
Definition newgrf_object.cpp:553
GetObjectCallback
uint16_t GetObjectCallback(CallbackID callback, uint32_t param1, uint32_t param2, const ObjectSpec *spec, Object *o, TileIndex tile, std::span< int32_t > regs100, uint8_t view)
Perform a callback for an object.
Definition newgrf_object.cpp:435
newgrf_object.h
Functions related to NewGRF objects.
OBJECT_SIZE_1X1
static const uint8_t OBJECT_SIZE_1X1
The value of a NewGRF's size property when the object is 1x1 tiles: low nibble for X,...
Definition newgrf_object.h:43
ObjectFlag::Autoremove
@ Autoremove
Object get automatically removed (like "owned land").
ObjectFlag::CannotRemove
@ CannotRemove
Object can not be removed.
ObjectFlag::AllowUnderBridge
@ AllowUnderBridge
Object can built under a bridge.
ObjectFlag::OnlyInScenedit
@ OnlyInScenedit
Object can only be constructed in the scenario editor.
ObjectFlag::BuiltOnWater
@ BuiltOnWater
Object can be built on water (not required).
ObjectFlag::OnlyInGame
@ OnlyInGame
Object can only be built in game.
ObjectFlag::HasNoFoundation
@ HasNoFoundation
Do not display foundations when on a slope.
ObjectFlag::Uses2CC
@ Uses2CC
Object wants 2CC colour mapping.
ObjectFlag::NotOnLand
@ NotOnLand
Object can not be on land, implicitly sets ObjectFlag::BuiltOnWater.
ObjectFlag::ScaleByWater
@ ScaleByWater
Object count is roughly scaled by water amount at edges.
ObjectFlag::Animation
@ Animation
Object has animated tiles.
ObjectFlag::ClearIncome
@ ClearIncome
When object is cleared a positive income is generated instead of a cost.
object.h
Functions related to objects.
object_base.h
Base for all objects.
UpdateObjectColours
void UpdateObjectColours(const Company *c)
Updates the colour of the object whenever a company changes.
Definition object_cmd.cpp:184
BuildObject
void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, uint8_t view)
Actually build the object.
Definition object_cmd.cpp:88
ReallyClearObjectTile
static void ReallyClearObjectTile(Object *o)
Perform the actual removal of the object from the map.
Definition object_cmd.cpp:512
CheckBuildableTile
CommandCost CheckBuildableTile(TileIndex tile, DiagDirections invalid_dirs, int &allowed_z, bool allow_steep, bool check_bridge)
Checks if the given tile is buildable, flat and has a certain height.
Definition station_cmd.cpp:789
InitializeObjects
void InitializeObjects()
Initialize/reset the objects.
Definition object_cmd.cpp:73
GetCompanyHQSize
static uint8_t GetCompanyHQSize(TileIndex tile)
Get the size of the HQ.
Definition object_cmd.cpp:154
TryBuildTransmitter
static bool TryBuildTransmitter()
Try to build a transmitter.
Definition object_cmd.cpp:794
CmdBuildObjectArea
CommandCost CmdBuildObjectArea(DoCommandFlags flags, TileIndex tile, TileIndex start_tile, ObjectType type, uint8_t view, bool diagonal)
Construct multiple objects in an area.
Definition object_cmd.cpp:397
TryBuildLightHouse
static bool TryBuildLightHouse()
Try to build a lighthouse.
Definition object_cmd.cpp:749
GetObjectType
ObjectType GetObjectType(Tile t)
Gets the ObjectType of the given object tile.
Definition object_cmd.cpp:66
UpdateCompanyHQ
void UpdateCompanyHQ(TileIndex tile, uint score)
Update the CompanyHQ to the state associated with the given score.
Definition object_cmd.cpp:165
FindClearedObject
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
Definition object_cmd.cpp:530
IncreaseCompanyHQSize
static void IncreaseCompanyHQSize(TileIndex tile)
Increase the HQ size.
Definition object_cmd.cpp:139
CmdBuildObject
CommandCost CmdBuildObject(DoCommandFlags flags, TileIndex tile, ObjectType type, uint8_t view)
Build an object object.
Definition object_cmd.cpp:210
object_cmd.h
Command definitions related to objects.
object_land.h
Sprites to use and how to display them for object tiles.
object_map.h
Map accessors for object tiles.
MakeObject
void MakeObject(Tile t, Owner o, ObjectID index, WaterClass wc, uint8_t random)
Make an Object tile.
Definition object_map.h:74
IsObjectTypeTile
bool IsObjectTypeTile(Tile t, ObjectType type)
Check whether a tile is a object tile of a specific type.
Definition object_map.h:36
IsObjectType
bool IsObjectType(Tile t, ObjectType type)
Check whether the object on a tile is of a specific type.
Definition object_map.h:25
GetObjectIndex
ObjectID GetObjectIndex(Tile t)
Get the index of which object this tile is attached to.
Definition object_map.h:47
OBJECT_LIGHTHOUSE
static const ObjectType OBJECT_LIGHTHOUSE
The nice lighthouse.
Definition object_type.h:19
ObjectType
uint16_t ObjectType
Types of objects.
Definition object_type.h:16
OBJECT_STATUE
static const ObjectType OBJECT_STATUE
Statue in towns.
Definition object_type.h:20
OBJECT_HQ
static const ObjectType OBJECT_HQ
HeadQuarter of a player.
Definition object_type.h:22
OBJECT_TRANSMITTER
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
Definition object_type.h:18
ObjectAnimationTrigger::Built
@ Built
Triggered when the object is built (for all tiles at the same time).
ObjectAnimationTrigger::TileLoop
@ TileLoop
Triggered in the periodic tile loop.
ObjectAnimationTrigger::TileLoopNorth
@ TileLoopNorth
Triggered every 256 ticks (for all tiles at the same time).
NEW_OBJECT_OFFSET
static const ObjectType NEW_OBJECT_OFFSET
Offset for new objects.
Definition object_type.h:24
OBJECT_OWNED_LAND
static const ObjectType OBJECT_OWNED_LAND
Owned land 'flag'.
Definition object_type.h:21
pool_func.hpp
Some methods of Pool are placed here in order to reduce compilation time and binary size.
INSTANTIATE_POOL_METHODS
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don't get linker errors.
Definition pool_func.hpp:210
random_func.hpp
Pseudo random number generator.
RandomRange
uint32_t RandomRange(uint32_t limit, const std::source_location location=std::source_location::current())
Pick a random number between 0 and limit - 1, inclusive.
Definition random_func.hpp:88
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
GetSlopeMaxZ
static constexpr int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height)
Definition slope_func.h:160
IsSteepSlope
static constexpr bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition slope_func.h:36
FlatteningFoundation
Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
Definition slope_func.h:369
Slope
Slope
Enumeration for the slope-type.
Definition slope_type.h:48
SLOPE_FLAT
@ SLOPE_FLAT
a flat tile
Definition slope_type.h:49
Foundation
Foundation
Enumeration for Foundations.
Definition slope_type.h:93
FOUNDATION_NONE
@ FOUNDATION_NONE
The tile has no foundation, the slope remains unchanged.
Definition slope_type.h:94
SourceType::Headquarters
@ Headquarters
Source/destination are company headquarters.
station_func.h
Functions related to stations.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
CargoArray
Class for storing amounts of cargo.
Definition cargo_type.h:111
CargoPacket::InvalidateAllFrom
static void InvalidateAllFrom(Source src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
Definition cargopacket.cpp:132
Cheat::value
bool value
tells if the bool cheat is active or not
Definition cheat_type.h:18
Cheats::magic_bulldozer
Cheat magic_bulldozer
dynamite industries, objects
Definition cheat_type.h:27
ClearedObjectArea
Keeps track of removed objects during execution/testruns of commands.
Definition object_base.h:86
CommandHelper
Definition command_func.h:83
CompanyProperties::location_of_HQ
TileIndex location_of_HQ
Northern tile of HQ; INVALID_TILE when there is none.
Definition company_base.h:93
CompanyProperties::build_object_limit
uint32_t build_object_limit
Amount of tiles we can (still) build objects on (times 65536). Also applies to buying land.
Definition company_base.h:108
Company
Definition company_base.h:127
Company::GetCompanyRecolourOffset
uint8_t GetCompanyRecolourOffset(LiveryScheme livery_scheme, bool use_secondary=true) const
Get offset for recolour palette of specific company.
Definition company_base.h:189
ConstructionSettings::freeform_edges
bool freeform_edges
allow terraforming the tiles at the map edges
Definition settings_type.h:423
DrawTileSeqStruct
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
Definition sprite.h:33
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:52
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:53
GRFConfig::GetName
std::string GetName() const
Get the name of this grf.
Definition newgrf_config.cpp:85
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition newgrf_commons.h:318
GRFFilePropsBase::grfid
uint32_t grfid
grfid that introduced this entity.
Definition newgrf_commons.h:317
GRFFilePropsBase::HasGrfFile
bool HasGrfFile() const
Test if this entity was introduced by NewGRF.
Definition newgrf_commons.h:326
GameSettings::construction
ConstructionSettings construction
construction of things in-game
Definition settings_type.h:635
Map::ScaleBySize
static uint ScaleBySize(uint n)
Scales the given value by the map size, where the given value is for a 256 by 256 map.
Definition map_func.h:340
Map::ScaleBySize1D
static uint ScaleBySize1D(uint n)
Scales the given value by the maps circumference, where the given value is for a 256 by 256 map.
Definition map_func.h:353
Map::MaxY
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition map_func.h:308
Map::MaxX
static uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition map_func.h:299
Map::Size
static uint Size()
Get the size of the map.
Definition map_func.h:290
ObjectSpec
Allow incrementing of ObjectClassID variables.
Definition newgrf_object.h:60
ObjectSpec::IsEnabled
bool IsEnabled() const
Test if this object is enabled.
Definition newgrf_object.h:83
ObjectSpec::grf_prop
StandardGRFFileProps grf_prop
Properties related the the grf file.
Definition newgrf_object.h:61
ObjectSpec::name
StringID name
The name for this object.
Definition newgrf_object.h:64
ObjectSpec::GetByTile
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
Definition newgrf_object.cpp:69
ObjectSpec::Get
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
Definition newgrf_object.cpp:54
ObjectSpec::IsAvailable
bool IsAvailable() const
Check whether the object is available at this time.
Definition newgrf_object.cpp:97
ObjectSpec::GetClearCost
Money GetClearCost() const
Get the cost for clearing a structure of this type.
Definition newgrf_object.h:95
ObjectSpec::size
uint8_t size
The size of this objects; low nibble for X, high nibble for Y.
Definition newgrf_object.h:67
ObjectSpec::generate_amount
uint8_t generate_amount
Number of objects which are attempted to be generated per 256^2 map during world generation.
Definition newgrf_object.h:76
ObjectSpec::Index
uint Index() const
Gets the index of this spec.
Definition newgrf_object.cpp:107
ObjectSpec::callback_mask
ObjectCallbackMasks callback_mask
Bitmask of requested/allowed callbacks.
Definition newgrf_object.h:73
ObjectSpec::flags
ObjectFlags flags
Flags/settings related to the object.
Definition newgrf_object.h:72
ObjectSpec::height
uint8_t height
The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
Definition newgrf_object.h:74
ObjectSpec::WasEverAvailable
bool WasEverAvailable() const
Check whether the object was available at some point in the past or present in this game with the cur...
Definition newgrf_object.cpp:88
ObjectSpec::GetBuildCost
Money GetBuildCost() const
Get the cost for building a structure of this type.
Definition newgrf_object.h:89
ObjectSpec::views
uint8_t views
The number of views.
Definition newgrf_object.h:75
Object
An object, such as transmitter, on the map.
Definition object_base.h:23
Object::type
ObjectType type
Type of the object.
Definition object_base.h:24
Object::town
Town * town
Town the object is built in.
Definition object_base.h:25
Object::counts
static std::array< uint16_t, NUM_OBJECTS > counts
Number of objects per type ingame.
Definition object_base.h:80
Object::GetByTile
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
Definition object_cmd.cpp:55
Object::IncTypeCount
static void IncTypeCount(ObjectType type)
Increment the count of objects for this type.
Definition object_base.h:45
Object::build_date
TimerGameCalendar::Date build_date
Date of construction.
Definition object_base.h:27
Object::location
TileArea location
Location of the object.
Definition object_base.h:26
Object::colour
uint8_t colour
Colour of the object, for display purpose.
Definition object_base.h:28
Object::DecTypeCount
static void DecTypeCount(ObjectType type)
Decrement the count of objects for this type.
Definition object_base.h:56
Object::ResetTypeCounts
static void ResetTypeCounts()
Resets object counts.
Definition object_base.h:74
OrthogonalTileArea
Represents the covered area of e.g.
Definition tilearea_type.h:18
OrthogonalTileArea::w
uint16_t w
The width of the area.
Definition tilearea_type.h:20
OrthogonalTileArea::tile
TileIndex tile
The base tile of the area.
Definition tilearea_type.h:19
OrthogonalTileArea::h
uint16_t h
The height of the area.
Definition tilearea_type.h:21
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition gfx_type.h:23
PoolID< uint8_t, struct CompanyIDTag, 0xF, 0xFF >
Pool::PoolItem<&_object_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:436
Pool::PoolItem<&_object_pool >::Get
static Titem * Get(auto index)
Returns Titem with given index.
Definition pool_type.hpp:387
Pool::PoolItem<&_town_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition pool_type.hpp:417
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:286
Pool::PoolItem<&_object_pool >::CanAllocateItem
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function()
Definition pool_type.hpp:357
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(auto index)
Returns Titem with given index.
Definition pool_type.hpp:398
Pool
Base class for all pools.
Definition pool_type.hpp:133
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TileDesc
Tile description for the 'land area information' tool.
Definition tile_cmd.h:36
TileDesc::grf
std::optional< std::string > grf
newGRF used for the tile contents
Definition tile_cmd.h:47
TileDesc::str
StringID str
Description of the tile.
Definition tile_cmd.h:37
TileDesc::build_date
TimerGameCalendar::Date build_date
Date of construction of tile contents.
Definition tile_cmd.h:41
TileDesc::owner
std::array< Owner, 4 > owner
Name of the owner(s)
Definition tile_cmd.h:39
TileInfo
Tile information, used while rendering the tile.
Definition tile_cmd.h:30
TileInfo::tileh
Slope tileh
Slope of the tile.
Definition tile_cmd.h:31
TileInfo::tile
TileIndex tile
Tile index.
Definition tile_cmd.h:32
TileTypeProcs
Set of callback functions for performing tile operations of a given tile type.
Definition tile_cmd.h:152
Town
Town data structure.
Definition town.h:63
Town::statues
CompanyMask statues
which companies have a statue?
Definition town.h:79
IsTileFlat
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition tile_map.cpp:95
GetTileSlopeZ
std::tuple< Slope, int > GetTileSlopeZ(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.cpp:55
GetTileMaxZ
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition tile_map.cpp:136
IsTileType
static bool IsTileType(Tile tile, TileType type)
Checks if a tile is a given tiletype.
Definition tile_map.h:150
IsTileOwner
bool IsTileOwner(Tile tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition tile_map.h:214
GetTileOwner
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
Definition tile_map.h:178
SetTileOwner
void SetTileOwner(Tile tile, Owner owner)
Sets the owner of a tile.
Definition tile_map.h:198
GetTileMaxPixelZ
int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
Definition tile_map.h:312
GetAnimationFrame
uint8_t GetAnimationFrame(Tile t)
Get the current animation frame.
Definition tile_map.h:250
GetTilePixelSlope
std::tuple< Slope, int > GetTilePixelSlope(TileIndex tile)
Return the slope of a given tile.
Definition tile_map.h:289
IsValidTile
bool IsValidTile(Tile tile)
Checks if a tile is valid.
Definition tile_map.h:161
SetAnimationFrame
void SetAnimationFrame(Tile t, uint8_t frame)
Set a new animation frame.
Definition tile_map.h:262
GetTileSlope
Slope GetTileSlope(TileIndex tile)
Return the slope of a given tile inside the map.
Definition tile_map.h:279
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
MP_CLEAR
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition tile_type.h:48
MP_WATER
@ MP_WATER
Water tile.
Definition tile_type.h:54
MP_OBJECT
@ MP_OBJECT
Contains objects such as transmitters and owned land.
Definition tile_type.h:58
TileArea
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition tilearea_type.h:102
timer_game_calendar.h
Definition of the game-calendar-timer.
town.h
Base of the town class.
CalcClosestTownFromTile
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
Definition town_cmd.cpp:3934
IsTransparencySet
bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
Definition transparency.h:50
IsInvisibilitySet
bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren't in the game menu (there's never transpar...
Definition transparency.h:61
TO_STRUCTURES
@ TO_STRUCTURES
other objects such as transmitters and lighthouses
Definition transparency.h:30
TransportType
TransportType
Available types of transport.
Definition transport_type.h:17
EnsureNoVehicleOnGround
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition vehicle.cpp:527
vehicle_func.h
Functions related to vehicles.
AddSortableSpriteToDraw
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int z, const SpriteBounds &bounds, bool transparent, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition viewport.cpp:663
DrawGroundSprite
void DrawGroundSprite(SpriteID image, PaletteID pal, const SubSprite *sub, int extra_offs_x, int extra_offs_y)
Draws a ground sprite for the current tile.
Definition viewport.cpp:579
viewport_func.h
Functions related to (drawing on) viewports.
water.h
Functions related to water (management)
TileLoop_Water
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd,...
Definition water_cmd.cpp:1269
ClearNeighbourNonFloodingStates
void ClearNeighbourNonFloodingStates(TileIndex tile)
Clear non-flooding state of the tiles around a tile.
Definition water_cmd.cpp:97
HasTileWaterGround
bool HasTileWaterGround(Tile t)
Checks whether the tile has water at the ground.
Definition water_map.h:352
IsTileOnWater
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
Definition water_map.h:138
WaterClass
WaterClass
classes of water (for WaterTileType::Clear water tile type).
Definition water_map.h:39
WaterClass::Invalid
@ Invalid
Used for industry tiles on land (also for oilrig if newgrf says so).
WaterClass::Canal
@ Canal
Canal.
WaterClass::Sea
@ Sea
Sea.
GetWaterClass
WaterClass GetWaterClass(Tile t)
Get the water class at a tile.
Definition water_map.h:114
IsDockingTile
bool IsDockingTile(Tile t)
Checks whether the tile is marked as a dockling tile.
Definition water_map.h:373
IsWaterTile
bool IsWaterTile(Tile t)
Is it a water tile with plain water?
Definition water_map.h:192
InvalidateWaterRegion
void InvalidateWaterRegion(TileIndex tile)
Marks the water region that tile is part of as invalid.
Definition water_regions.cpp:313
water_regions.h
Handles dividing the water in the map into regions to assist pathfinding.
SetWindowDirty
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition window.cpp:3176
window_func.h
Window functions not directly related to making/drawing windows.
WC_TOWN_AUTHORITY
@ WC_TOWN_AUTHORITY
Town authority; Window numbers:
Definition window_type.h:199
WC_COMPANY
@ WC_COMPANY
Company view; Window numbers:
Definition window_type.h:374