OpenTTD
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 <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "landscape.h"
12 #include "command_func.h"
13 #include "viewport_func.h"
14 #include "company_base.h"
15 #include "town.h"
16 #include "bridge_map.h"
17 #include "genworld.h"
18 #include "autoslope.h"
19 #include "clear_func.h"
20 #include "water.h"
21 #include "window_func.h"
22 #include "company_gui.h"
23 #include "cheat_type.h"
24 #include "object.h"
25 #include "cargopacket.h"
26 #include "core/random_func.hpp"
27 #include "core/pool_func.hpp"
28 #include "object_map.h"
29 #include "object_base.h"
30 #include "newgrf_config.h"
31 #include "newgrf_object.h"
32 #include "date_func.h"
33 #include "newgrf_debug.h"
34 #include "vehicle_func.h"
35 
36 #include "table/strings.h"
37 #include "table/object_land.h"
38 
39 #include "safeguards.h"
40 
41 ObjectPool _object_pool("Object");
44 
50 /* static */ Object *Object::GetByTile(TileIndex tile)
51 {
52  return Object::Get(GetObjectIndex(tile));
53 }
54 
62 {
63  assert(IsTileType(t, MP_OBJECT));
64  return Object::GetByTile(t)->type;
65 }
66 
69 {
71 }
72 
84 {
85  const ObjectSpec *spec = ObjectSpec::Get(type);
86 
87  TileArea ta(tile, GB(spec->size, HasBit(view, 0) ? 4 : 0, 4), GB(spec->size, HasBit(view, 0) ? 0 : 4, 4));
88  Object *o = new Object();
89  o->type = type;
90  o->location = ta;
91  o->town = town == nullptr ? CalcClosestTownFromTile(tile) : town;
92  o->build_date = _date;
93  o->view = 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  const Livery *l = Company::Get(owner)->livery;
101  o->colour = l->colour1 + l->colour2 * 16;
102  }
103 
104  /* If the object wants only one colour, then give it that colour. */
105  if ((spec->flags & OBJECT_FLAG_2CC_COLOUR) == 0) o->colour &= 0xF;
106 
107  if (HasBit(spec->callback_mask, CBM_OBJ_COLOUR)) {
108  uint16 res = GetObjectCallback(CBID_OBJECT_COLOUR, o->colour, 0, spec, o, tile);
109  if (res != CALLBACK_FAILED) {
110  if (res >= 0x100) ErrorUnknownCallbackResult(spec->grf_prop.grffile->grfid, CBID_OBJECT_COLOUR, res);
111  o->colour = GB(res, 0, 8);
112  }
113  }
114 
115  assert(o->town != nullptr);
116 
117  TILE_AREA_LOOP(t, ta) {
119  /* Update company infrastructure counts for objects build on canals owned by nobody. */
120  if (wc == WATER_CLASS_CANAL && owner != OWNER_NONE && (IsTileOwner(tile, OWNER_NONE) || IsTileOwner(tile, OWNER_WATER))) {
121  Company::Get(owner)->infrastructure.water++;
123  }
124  MakeObject(t, owner, o->index, wc, Random());
126  }
127 
128  Object::IncTypeCount(type);
130 }
131 
137 {
138  TileArea ta = Object::GetByTile(tile)->location;
139  TILE_AREA_LOOP(t, ta) {
142  }
143 }
144 
146 #define GetCompanyHQSize GetAnimationFrame
147 
148 #define IncreaseCompanyHQSize IncreaseAnimationStage
149 
155 void UpdateCompanyHQ(TileIndex tile, uint score)
156 {
157  if (tile == INVALID_TILE) return;
158 
159  byte val = 0;
160  if (score >= 170) val++;
161  if (score >= 350) val++;
162  if (score >= 520) val++;
163  if (score >= 720) val++;
164 
165  while (GetCompanyHQSize(tile) < val) {
166  IncreaseCompanyHQSize(tile);
167  }
168 }
169 
175 {
176  for (Object *obj : Object::Iterate()) {
177  Owner owner = GetTileOwner(obj->location.tile);
178  /* Not the current owner, so colour doesn't change. */
179  if (owner != c->index) continue;
180 
181  const ObjectSpec *spec = ObjectSpec::GetByTile(obj->location.tile);
182  /* Using the object colour callback, so not using company colour. */
183  if (HasBit(spec->callback_mask, CBM_OBJ_COLOUR)) continue;
184 
185  const Livery *l = c->livery;
186  obj->colour = ((spec->flags & OBJECT_FLAG_2CC_COLOUR) ? (l->colour2 * 16) : 0) + l->colour1;
187  }
188 }
189 
190 extern CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z, bool allow_steep, bool check_bridge);
191 static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags);
192 
202 CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
203 {
205 
206  ObjectType type = (ObjectType)GB(p1, 0, 16);
207  if (type >= NUM_OBJECTS) return CMD_ERROR;
208  uint8 view = GB(p2, 0, 2);
209  const ObjectSpec *spec = ObjectSpec::Get(type);
210  if (_game_mode == GM_NORMAL && !spec->IsAvailable() && !_generating_world) return CMD_ERROR;
211  if ((_game_mode == GM_EDITOR || _generating_world) && !spec->WasEverAvailable()) return CMD_ERROR;
212 
213  if ((spec->flags & OBJECT_FLAG_ONLY_IN_SCENEDIT) != 0 && ((!_generating_world && _game_mode != GM_EDITOR) || _current_company != OWNER_NONE)) return CMD_ERROR;
214  if ((spec->flags & OBJECT_FLAG_ONLY_IN_GAME) != 0 && (_generating_world || _game_mode != GM_NORMAL || _current_company > MAX_COMPANIES)) return CMD_ERROR;
215  if (view >= spec->views) return CMD_ERROR;
216 
217  if (!Object::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_OBJECTS);
218  if (Town::GetNumItems() == 0) return_cmd_error(STR_ERROR_MUST_FOUND_TOWN_FIRST);
219 
220  int size_x = GB(spec->size, HasBit(view, 0) ? 4 : 0, 4);
221  int size_y = GB(spec->size, HasBit(view, 0) ? 0 : 4, 4);
222  TileArea ta(tile, size_x, size_y);
223 
224  if (type == OBJECT_OWNED_LAND) {
225  /* Owned land is special as it can be placed on any slope. */
226  cost.AddCost(DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR));
227  } else {
228  /* Check the surface to build on. At this time we can't actually execute the
229  * the CLEAR_TILE commands since the newgrf callback later on can check
230  * some information about the tiles. */
231  bool allow_water = (spec->flags & (OBJECT_FLAG_BUILT_ON_WATER | OBJECT_FLAG_NOT_ON_LAND)) != 0;
232  bool allow_ground = (spec->flags & OBJECT_FLAG_NOT_ON_LAND) == 0;
233  TILE_AREA_LOOP(t, ta) {
234  if (HasTileWaterGround(t)) {
235  if (!allow_water) return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
236  if (!IsWaterTile(t)) {
237  /* Normal water tiles don't have to be cleared. For all other tile types clear
238  * the tile but leave the water. */
239  cost.AddCost(DoCommand(t, 0, 0, flags & ~DC_NO_WATER & ~DC_EXEC, CMD_LANDSCAPE_CLEAR));
240  } else {
241  /* Can't build on water owned by another company. */
242  Owner o = GetTileOwner(t);
243  if (o != OWNER_NONE && o != OWNER_WATER) cost.AddCost(CheckOwnership(o, t));
244 
245  /* However, the tile has to be clear of vehicles. */
247  }
248  } else {
249  if (!allow_ground) return_cmd_error(STR_ERROR_MUST_BE_BUILT_ON_WATER);
250  /* For non-water tiles, we'll have to clear it before building. */
251  cost.AddCost(DoCommand(t, 0, 0, flags & ~DC_EXEC, CMD_LANDSCAPE_CLEAR));
252  }
253  }
254 
255  /* So, now the surface is checked... check the slope of said surface. */
256  int allowed_z;
257  if (GetTileSlope(tile, &allowed_z) != SLOPE_FLAT) allowed_z++;
258 
259  TILE_AREA_LOOP(t, ta) {
260  uint16 callback = CALLBACK_FAILED;
262  TileIndex diff = t - tile;
263  callback = GetObjectCallback(CBID_OBJECT_LAND_SLOPE_CHECK, GetTileSlope(t), TileY(diff) << 4 | TileX(diff), spec, nullptr, t, view);
264  }
265 
266  if (callback == CALLBACK_FAILED) {
267  cost.AddCost(CheckBuildableTile(t, 0, allowed_z, false, false));
268  } else {
269  /* The meaning of bit 10 is inverted for a grf version < 8. */
270  if (spec->grf_prop.grffile->grf_version < 8) ToggleBit(callback, 10);
271  CommandCost ret = GetErrorMessageFromLocationCallbackResult(callback, spec->grf_prop.grffile, STR_ERROR_LAND_SLOPED_IN_WRONG_DIRECTION);
272  if (ret.Failed()) return ret;
273  }
274  }
275 
276  if (flags & DC_EXEC) {
277  /* This is basically a copy of the loop above with the exception that we now
278  * execute the commands and don't check for errors, since that's already done. */
279  TILE_AREA_LOOP(t, ta) {
280  if (HasTileWaterGround(t)) {
281  if (!IsWaterTile(t)) {
283  }
284  } else {
286  }
287  }
288  }
289  }
290  if (cost.Failed()) return cost;
291 
292  /* Finally do a check for bridges. */
293  TILE_AREA_LOOP(t, ta) {
294  if (IsBridgeAbove(t) && (
297  return_cmd_error(STR_ERROR_MUST_DEMOLISH_BRIDGE_FIRST);
298  }
299  }
300 
301  int hq_score = 0;
302  switch (type) {
303  case OBJECT_TRANSMITTER:
304  case OBJECT_LIGHTHOUSE:
305  if (!IsTileFlat(tile)) return_cmd_error(STR_ERROR_FLAT_LAND_REQUIRED);
306  break;
307 
308  case OBJECT_OWNED_LAND:
309  if (IsTileType(tile, MP_OBJECT) &&
310  IsTileOwner(tile, _current_company) &&
312  return_cmd_error(STR_ERROR_YOU_ALREADY_OWN_IT);
313  }
314  break;
315 
316  case OBJECT_HQ: {
318  if (c->location_of_HQ != INVALID_TILE) {
319  /* We need to persuade a bit harder to remove the old HQ. */
321  cost.AddCost(ClearTile_Object(c->location_of_HQ, flags));
322  _current_company = c->index;
323  }
324 
325  if (flags & DC_EXEC) {
326  hq_score = UpdateCompanyRatingAndValue(c, false);
327  c->location_of_HQ = tile;
329  }
330  break;
331  }
332 
333  case OBJECT_STATUE:
334  /* This may never be constructed using this method. */
335  return CMD_ERROR;
336 
337  default: // i.e. NewGRF provided.
338  break;
339  }
340 
341  if (flags & DC_EXEC) {
342  BuildObject(type, tile, _current_company, nullptr, view);
343 
344  /* Make sure the HQ starts at the right size. */
345  if (type == OBJECT_HQ) UpdateCompanyHQ(tile, hq_score);
346  }
347 
348  cost.AddCost(ObjectSpec::Get(type)->GetBuildCost() * size_x * size_y);
349  return cost;
350 }
351 
352 
353 static Foundation GetFoundation_Object(TileIndex tile, Slope tileh);
354 
355 static void DrawTile_Object(TileInfo *ti)
356 {
358  const ObjectSpec *spec = ObjectSpec::Get(type);
359 
360  /* Fall back for when the object doesn't exist anymore. */
361  if (!spec->enabled) type = OBJECT_TRANSMITTER;
362 
363  if ((spec->flags & OBJECT_FLAG_HAS_NO_FOUNDATION) == 0) DrawFoundation(ti, GetFoundation_Object(ti->tile, ti->tileh));
364 
365  if (type < NEW_OBJECT_OFFSET) {
366  const DrawTileSprites *dts = nullptr;
367  Owner to = GetTileOwner(ti->tile);
368  PaletteID palette = to == OWNER_NONE ? PAL_NONE : COMPANY_SPRITE_COLOUR(to);
369 
370  if (type == OBJECT_HQ) {
371  TileIndex diff = ti->tile - Object::GetByTile(ti->tile)->location.tile;
372  dts = &_object_hq[GetCompanyHQSize(ti->tile) << 2 | TileY(diff) << 1 | TileX(diff)];
373  } else {
374  dts = &_objects[type];
375  }
376 
377  if (spec->flags & OBJECT_FLAG_HAS_NO_FOUNDATION) {
378  /* If an object has no foundation, but tries to draw a (flat) ground
379  * type... we have to be nice and convert that for them. */
380  switch (dts->ground.sprite) {
381  case SPR_FLAT_BARE_LAND: DrawClearLandTile(ti, 0); break;
382  case SPR_FLAT_1_THIRD_GRASS_TILE: DrawClearLandTile(ti, 1); break;
383  case SPR_FLAT_2_THIRD_GRASS_TILE: DrawClearLandTile(ti, 2); break;
384  case SPR_FLAT_GRASS_TILE: DrawClearLandTile(ti, 3); break;
385  default: DrawGroundSprite(dts->ground.sprite, palette); break;
386  }
387  } else {
388  DrawGroundSprite(dts->ground.sprite, palette);
389  }
390 
392  const DrawTileSeqStruct *dtss;
393  foreach_draw_tile_seq(dtss, dts->seq) {
395  dtss->image.sprite, palette,
396  ti->x + dtss->delta_x, ti->y + dtss->delta_y,
397  dtss->size_x, dtss->size_y,
398  dtss->size_z, ti->z + dtss->delta_z,
400  );
401  }
402  }
403  } else {
404  DrawNewObjectTile(ti, spec);
405  }
406 
407  DrawBridgeMiddle(ti);
408 }
409 
410 static int GetSlopePixelZ_Object(TileIndex tile, uint x, uint y)
411 {
412  if (IsObjectType(tile, OBJECT_OWNED_LAND)) {
413  int z;
414  Slope tileh = GetTilePixelSlope(tile, &z);
415 
416  return z + GetPartialPixelZ(x & 0xF, y & 0xF, tileh);
417  } else {
418  return GetTileMaxPixelZ(tile);
419  }
420 }
421 
422 static Foundation GetFoundation_Object(TileIndex tile, Slope tileh)
423 {
425 }
426 
432 {
434  TILE_AREA_LOOP(tile_cur, o->location) {
435  DeleteNewGRFInspectWindow(GSF_OBJECTS, tile_cur);
436 
437  MakeWaterKeepingClass(tile_cur, GetTileOwner(tile_cur));
438  }
439  delete o;
440 }
441 
442 std::vector<ClearedObjectArea> _cleared_object_areas;
443 
450 {
451  TileArea ta = TileArea(tile, 1, 1);
452 
453  for (ClearedObjectArea &coa : _cleared_object_areas) {
454  if (coa.area.Intersects(ta)) return &coa;
455  }
456 
457  return nullptr;
458 }
459 
460 static CommandCost ClearTile_Object(TileIndex tile, DoCommandFlag flags)
461 {
462  /* Get to the northern most tile. */
463  Object *o = Object::GetByTile(tile);
464  TileArea ta = o->location;
465 
466  ObjectType type = o->type;
467  const ObjectSpec *spec = ObjectSpec::Get(type);
468 
469  CommandCost cost(EXPENSES_CONSTRUCTION, spec->GetClearCost() * ta.w * ta.h / 5);
470  if (spec->flags & OBJECT_FLAG_CLEAR_INCOME) cost.MultiplyCost(-1); // They get an income!
471 
472  /* Towns can't remove any objects. */
473  if (_current_company == OWNER_TOWN) return CMD_ERROR;
474 
475  /* Water can remove everything! */
476  if (_current_company != OWNER_WATER) {
477  if ((flags & DC_NO_WATER) && IsTileOnWater(tile)) {
478  /* There is water under the object, treat it as water tile. */
479  return_cmd_error(STR_ERROR_CAN_T_BUILD_ON_WATER);
480  } else if (!(spec->flags & OBJECT_FLAG_AUTOREMOVE) && (flags & DC_AUTO)) {
481  /* No automatic removal by overbuilding stuff. */
482  return_cmd_error(type == OBJECT_HQ ? STR_ERROR_COMPANY_HEADQUARTERS_IN : STR_ERROR_OBJECT_IN_THE_WAY);
483  } else if (_game_mode == GM_EDITOR) {
484  /* No further limitations for the editor. */
485  } else if (GetTileOwner(tile) == OWNER_NONE) {
486  /* Owned by nobody and unremovable, so we can only remove it with brute force! */
487  if (!_cheats.magic_bulldozer.value && (spec->flags & OBJECT_FLAG_CANNOT_REMOVE) != 0) return CMD_ERROR;
488  } else if (CheckTileOwnership(tile).Failed()) {
489  /* We don't own it!. */
490  return_cmd_error(STR_ERROR_OWNED_BY);
491  } else if ((spec->flags & OBJECT_FLAG_CANNOT_REMOVE) != 0 && (spec->flags & OBJECT_FLAG_AUTOREMOVE) == 0) {
492  /* In the game editor or with cheats we can remove, otherwise we can't. */
493  if (!_cheats.magic_bulldozer.value) return CMD_ERROR;
494 
495  /* Removing with the cheat costs more in TTDPatch / the specs. */
496  cost.MultiplyCost(25);
497  }
498  } else if ((spec->flags & (OBJECT_FLAG_BUILT_ON_WATER | OBJECT_FLAG_NOT_ON_LAND)) != 0) {
499  /* Water can't remove objects that are buildable on water. */
500  return CMD_ERROR;
501  }
502 
503  switch (type) {
504  case OBJECT_HQ: {
505  Company *c = Company::Get(GetTileOwner(tile));
506  if (flags & DC_EXEC) {
507  c->location_of_HQ = INVALID_TILE; // reset HQ position
510  }
511 
512  /* cost of relocating company is 1% of company value */
514  break;
515  }
516 
517  case OBJECT_STATUE:
518  if (flags & DC_EXEC) {
519  Town *town = o->town;
520  ClrBit(town->statues, GetTileOwner(tile));
522  }
523  break;
524 
525  default:
526  break;
527  }
528 
529  _cleared_object_areas.push_back({tile, ta});
530 
531  if (flags & DC_EXEC) ReallyClearObjectTile(o);
532 
533  return cost;
534 }
535 
536 static void AddAcceptedCargo_Object(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted)
537 {
538  if (!IsObjectType(tile, OBJECT_HQ)) return;
539 
540  /* HQ accepts passenger and mail; but we have to divide the values
541  * between 4 tiles it occupies! */
542 
543  /* HQ level (depends on company performance) in the range 1..5. */
544  uint level = GetCompanyHQSize(tile) + 1;
545 
546  /* Top town building generates 10, so to make HQ interesting, the top
547  * type makes 20. */
548  acceptance[CT_PASSENGERS] += max(1U, level);
549  SetBit(*always_accepted, CT_PASSENGERS);
550 
551  /* Top town building generates 4, HQ can make up to 8. The
552  * proportion passengers:mail is different because such a huge
553  * commercial building generates unusually high amount of mail
554  * correspondence per physical visitor. */
555  acceptance[CT_MAIL] += max(1U, level / 2);
556  SetBit(*always_accepted, CT_MAIL);
557 }
558 
559 static void AddProducedCargo_Object(TileIndex tile, CargoArray &produced)
560 {
561  if (!IsObjectType(tile, OBJECT_HQ)) return;
562 
563  produced[CT_PASSENGERS]++;
564  produced[CT_MAIL]++;
565 }
566 
567 
568 static void GetTileDesc_Object(TileIndex tile, TileDesc *td)
569 {
570  const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
571  td->str = spec->name;
572  td->owner[0] = GetTileOwner(tile);
574 
575  if (spec->grf_prop.grffile != nullptr) {
576  td->grf = GetGRFConfig(spec->grf_prop.grffile->grfid)->GetName();
577  }
578 }
579 
580 static void TileLoop_Object(TileIndex tile)
581 {
582  const ObjectSpec *spec = ObjectSpec::GetByTile(tile);
583  if (spec->flags & OBJECT_FLAG_ANIMATION) {
584  Object *o = Object::GetByTile(tile);
586  if (o->location.tile == tile) TriggerObjectAnimation(o, OAT_256_TICKS, spec);
587  }
588 
589  if (IsTileOnWater(tile)) TileLoop_Water(tile);
590 
591  if (!IsObjectType(tile, OBJECT_HQ)) return;
592 
593  /* HQ accepts passenger and mail; but we have to divide the values
594  * between 4 tiles it occupies! */
595 
596  /* HQ level (depends on company performance) in the range 1..5. */
597  uint level = GetCompanyHQSize(tile) + 1;
598  assert(level < 6);
599 
600  StationFinder stations(TileArea(tile, 2, 2));
601 
602  uint r = Random();
603  /* Top town buildings generate 250, so the top HQ type makes 256. */
604  if (GB(r, 0, 8) < (256 / 4 / (6 - level))) {
605  uint amt = GB(r, 0, 8) / 8 / 4 + 1;
606  if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
607  MoveGoodsToStation(CT_PASSENGERS, amt, ST_HEADQUARTERS, GetTileOwner(tile), stations.GetStations());
608  }
609 
610  /* Top town building generates 90, HQ can make up to 196. The
611  * proportion passengers:mail is about the same as in the acceptance
612  * equations. */
613  if (GB(r, 8, 8) < (196 / 4 / (6 - level))) {
614  uint amt = GB(r, 8, 8) / 8 / 4 + 1;
615  if (EconomyIsInRecession()) amt = (amt + 1) >> 1;
616  MoveGoodsToStation(CT_MAIL, amt, ST_HEADQUARTERS, GetTileOwner(tile), stations.GetStations());
617  }
618 }
619 
620 
621 static TrackStatus GetTileTrackStatus_Object(TileIndex tile, TransportType mode, uint sub_mode, DiagDirection side)
622 {
623  return 0;
624 }
625 
626 static bool ClickTile_Object(TileIndex tile)
627 {
628  if (!IsObjectType(tile, OBJECT_HQ)) return false;
629 
630  ShowCompany(GetTileOwner(tile));
631  return true;
632 }
633 
634 static void AnimateTile_Object(TileIndex tile)
635 {
636  AnimateNewObjectTile(tile);
637 }
638 
645 static bool HasTransmitter(TileIndex tile, void *user)
646 {
647  return IsObjectTypeTile(tile, OBJECT_TRANSMITTER);
648 }
649 
654 static bool TryBuildLightHouse()
655 {
656  uint maxx = MapMaxX();
657  uint maxy = MapMaxY();
658  uint r = Random();
659 
660  /* Scatter the lighthouses more evenly around the perimeter */
661  int perimeter = (GB(r, 16, 16) % (2 * (maxx + maxy))) - maxy;
662  DiagDirection dir;
663  for (dir = DIAGDIR_NE; perimeter > 0; dir++) {
664  perimeter -= (DiagDirToAxis(dir) == AXIS_X) ? maxx : maxy;
665  }
666 
667  TileIndex tile;
668  switch (dir) {
669  default:
670  case DIAGDIR_NE: tile = TileXY(maxx - 1, r % maxy); break;
671  case DIAGDIR_SE: tile = TileXY(r % maxx, 1); break;
672  case DIAGDIR_SW: tile = TileXY(1, r % maxy); break;
673  case DIAGDIR_NW: tile = TileXY(r % maxx, maxy - 1); break;
674  }
675 
676  /* Only build lighthouses at tiles where the border is sea. */
677  if (!IsTileType(tile, MP_WATER)) return false;
678 
679  for (int j = 0; j < 19; j++) {
680  int h;
681  if (IsTileType(tile, MP_CLEAR) && IsTileFlat(tile, &h) && h <= 2 && !IsBridgeAbove(tile)) {
683  assert(tile < MapSize());
684  return true;
685  }
686  tile += TileOffsByDiagDir(dir);
687  if (!IsValidTile(tile)) return false;
688  }
689  return false;
690 }
691 
696 static bool TryBuildTransmitter()
697 {
698  TileIndex tile = RandomTile();
699  int h;
700  if (IsTileType(tile, MP_CLEAR) && IsTileFlat(tile, &h) && h >= 4 && !IsBridgeAbove(tile)) {
701  TileIndex t = tile;
702  if (CircularTileSearch(&t, 9, HasTransmitter, nullptr)) return false;
703 
705  return true;
706  }
707  return false;
708 }
709 
710 void GenerateObjects()
711 {
712  /* Set a guestimate on how much we progress */
714 
715  /* Determine number of water tiles at map border needed for freeform_edges */
716  uint num_water_tiles = 0;
718  for (uint x = 0; x < MapMaxX(); x++) {
719  if (IsTileType(TileXY(x, 1), MP_WATER)) num_water_tiles++;
720  if (IsTileType(TileXY(x, MapMaxY() - 1), MP_WATER)) num_water_tiles++;
721  }
722  for (uint y = 1; y < MapMaxY() - 1; y++) {
723  if (IsTileType(TileXY(1, y), MP_WATER)) num_water_tiles++;
724  if (IsTileType(TileXY(MapMaxX() - 1, y), MP_WATER)) num_water_tiles++;
725  }
726  }
727 
728  /* Iterate over all possible object types */
729  for (uint i = 0; i < NUM_OBJECTS; i++) {
730  const ObjectSpec *spec = ObjectSpec::Get(i);
731 
732  /* Continue, if the object was never available till now or shall not be placed */
733  if (!spec->WasEverAvailable() || spec->generate_amount == 0) continue;
734 
735  uint16 amount = spec->generate_amount;
736 
737  /* Scale by map size */
739  /* Scale the amount of lighthouses with the amount of land at the borders.
740  * The -6 is because the top borders are MP_VOID (-2) and all corners
741  * are counted twice (-4). */
742  amount = ScaleByMapSize1D(amount * num_water_tiles) / (2 * MapMaxY() + 2 * MapMaxX() - 6);
743  } else if (spec->flags & OBJECT_FLAG_SCALE_BY_WATER) {
744  amount = ScaleByMapSize1D(amount);
745  } else {
746  amount = ScaleByMapSize(amount);
747  }
748 
749  /* Now try to place the requested amount of this object */
750  for (uint j = ScaleByMapSize(1000); j != 0 && amount != 0 && Object::CanAllocateItem(); j--) {
751  switch (i) {
752  case OBJECT_TRANSMITTER:
753  if (TryBuildTransmitter()) amount--;
754  break;
755 
756  case OBJECT_LIGHTHOUSE:
757  if (TryBuildLightHouse()) amount--;
758  break;
759 
760  default:
761  uint8 view = RandomRange(spec->views);
762  if (CmdBuildObject(RandomTile(), DC_EXEC | DC_AUTO | DC_NO_TEST_TOWN_RATING | DC_NO_MODIFY_TOWN_RATING, i, view, nullptr).Succeeded()) amount--;
763  break;
764  }
765  }
767  }
768 }
769 
770 static void ChangeTileOwner_Object(TileIndex tile, Owner old_owner, Owner new_owner)
771 {
772  if (!IsTileOwner(tile, old_owner)) return;
773 
774  bool do_clear = false;
775 
776  ObjectType type = GetObjectType(tile);
777  if ((type == OBJECT_OWNED_LAND || type >= NEW_OBJECT_OFFSET) && new_owner != INVALID_OWNER) {
778  SetTileOwner(tile, new_owner);
779  } else if (type == OBJECT_STATUE) {
780  Town *t = Object::GetByTile(tile)->town;
781  ClrBit(t->statues, old_owner);
782  if (new_owner != INVALID_OWNER && !HasBit(t->statues, new_owner)) {
783  /* Transfer ownership to the new company */
784  SetBit(t->statues, new_owner);
785  SetTileOwner(tile, new_owner);
786  } else {
787  do_clear = true;
788  }
789 
791  } else {
792  do_clear = true;
793  }
794 
795  if (do_clear) {
797  /* When clearing objects, they may turn into canal, which may require transferring ownership. */
798  ChangeTileOwner(tile, old_owner, new_owner);
799  }
800 }
801 
802 static CommandCost TerraformTile_Object(TileIndex tile, DoCommandFlag flags, int z_new, Slope tileh_new)
803 {
804  ObjectType type = GetObjectType(tile);
805 
806  if (type == OBJECT_OWNED_LAND) {
807  /* Owned land remains unsold */
808  CommandCost ret = CheckTileOwnership(tile);
809  if (ret.Succeeded()) return CommandCost();
810  } else if (AutoslopeEnabled() && type != OBJECT_TRANSMITTER && type != OBJECT_LIGHTHOUSE) {
811  /* Behaviour:
812  * - Both new and old slope must not be steep.
813  * - TileMaxZ must not be changed.
814  * - Allow autoslope by default.
815  * - Disallow autoslope if callback succeeds and returns non-zero.
816  */
817  Slope tileh_old = GetTileSlope(tile);
818  /* TileMaxZ must not be changed. Slopes must not be steep. */
819  if (!IsSteepSlope(tileh_old) && !IsSteepSlope(tileh_new) && (GetTileMaxZ(tile) == z_new + GetSlopeMaxZ(tileh_new))) {
820  const ObjectSpec *spec = ObjectSpec::Get(type);
821 
822  /* Call callback 'disable autosloping for objects'. */
823  if (HasBit(spec->callback_mask, CBM_OBJ_AUTOSLOPE)) {
824  /* If the callback fails, allow autoslope. */
825  uint16 res = GetObjectCallback(CBID_OBJECT_AUTOSLOPE, 0, 0, spec, Object::GetByTile(tile), tile);
826  if (res == CALLBACK_FAILED || !ConvertBooleanCallback(spec->grf_prop.grffile, CBID_OBJECT_AUTOSLOPE, res)) return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
827  } else if (spec->enabled) {
828  /* allow autoslope */
829  return CommandCost(EXPENSES_CONSTRUCTION, _price[PR_BUILD_FOUNDATION]);
830  }
831  }
832  }
833 
834  return DoCommand(tile, 0, 0, flags, CMD_LANDSCAPE_CLEAR);
835 }
836 
837 extern const TileTypeProcs _tile_type_object_procs = {
838  DrawTile_Object, // draw_tile_proc
839  GetSlopePixelZ_Object, // get_slope_z_proc
840  ClearTile_Object, // clear_tile_proc
841  AddAcceptedCargo_Object, // add_accepted_cargo_proc
842  GetTileDesc_Object, // get_tile_desc_proc
843  GetTileTrackStatus_Object, // get_tile_track_status_proc
844  ClickTile_Object, // click_tile_proc
845  AnimateTile_Object, // animate_tile_proc
846  TileLoop_Object, // tile_loop_proc
847  ChangeTileOwner_Object, // change_tile_owner_proc
848  AddProducedCargo_Object, // add_produced_cargo_proc
849  nullptr, // vehicle_enter_tile_proc
850  GetFoundation_Object, // get_foundation_proc
851  TerraformTile_Object, // terraform_tile_proc
852 };
Owner
Enum for all companies/owners.
Definition: company_type.h:18
don&#39;t allow building on structures
Definition: command_type.h:345
void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner)
Change the owner of a tile.
Definition: landscape.cpp:600
Functions/types related to NewGRF debugging.
do not change town rating
Definition: command_type.h:354
ClearedObjectArea * FindClearedObject(TileIndex tile)
Find the entry in _cleared_object_areas which occupies a certain tile.
Definition: object_cmd.cpp:449
uint32 PaletteID
The number of the palette.
Definition: gfx_type.h:18
#define RandomTile()
Get a valid random tile.
Definition: map_func.h:435
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:79
Definition of stuff that is very close to a company, like the company struct itself.
Object wants 2CC colour mapping.
Definition: newgrf_object.h:34
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
static void SetAnimationFrame(TileIndex t, byte frame)
Set a new animation frame.
Definition: tile_map.h:262
ObjectFlags flags
Flags/settings related to the object.
Definition: newgrf_object.h:70
void DrawNewObjectTile(TileInfo *ti, const ObjectSpec *spec)
Draw an object on the map.
static const ObjectType NUM_OBJECTS
Number of supported objects overall.
Definition: object_type.h:25
static void SetTileOwner(TileIndex tile, Owner owner)
Sets the owner of a tile.
Definition: tile_map.h:198
Tile information, used while rendering the tile.
Definition: tile_cmd.h:42
CompanyMask statues
which companies have a statue?
Definition: town.h:68
static const ObjectType OBJECT_TRANSMITTER
The large antenna.
Definition: object_type.h:16
bool IsAvailable() const
Check whether the object is available at this time.
void TileLoop_Water(TileIndex tile)
Let a water tile floods its diagonal adjoining tiles called from tunnelbridge_cmd, and by TileLoop_Industry() and TileLoop_Track()
Definition: water_cmd.cpp:1206
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3215
An invalid owner.
Definition: company_type.h:29
uint GetPartialPixelZ(int x, int y, Slope corners)
Determines height at given coordinate of a slope.
Definition: landscape.cpp:215
CommandCost EnsureNoVehicleOnGround(TileIndex tile)
Ensure there is no vehicle at the ground at the given position.
Definition: vehicle.cpp:537
Generate objects (radio tower, light houses)
Definition: genworld.h:74
void TriggerObjectTileAnimation(Object *o, TileIndex tile, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a single tile.
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:291
Functions related to dates.
static WaterClass GetWaterClass(TileIndex t)
Get the water class at a tile.
Definition: water_map.h:106
const char * grf
newGRF used for the tile contents
Definition: tile_cmd.h:61
Town * town
Town the object is built in.
Definition: object_base.h:25
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
Northwest.
static byte GetAnimationFrame(TileIndex t)
Get the current animation frame.
Definition: tile_map.h:250
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
static const CommandCost CMD_ERROR
Define a default return value for a failed command.
Definition: command_func.h:23
Slope tileh
Slope of the tile.
Definition: tile_cmd.h:45
static const ObjectType OBJECT_STATUE
Statue in towns.
Definition: object_type.h:18
GRFFilePropsBase< 2 > grf_prop
Properties related the the grf file.
Definition: newgrf_object.h:60
static uint ScaleByMapSize(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:122
A town owns the tile, or a town is expanding.
Definition: company_type.h:24
Functions related to vehicles.
static bool HasTileWaterGround(TileIndex t)
Checks whether the tile has water at the ground.
Definition: water_map.h:344
Date build_date
Date of construction.
Definition: object_base.h:27
static uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:205
byte colour
Colour of the object, for display purpose.
Definition: object_base.h:28
Object can not be removed.
Definition: newgrf_object.h:27
static int GetSlopeMaxZ(Slope s)
Returns the height of the highest corner of a slope relative to TileZ (= minimal height) ...
Definition: slope_func.h:160
Object()
Make sure the object isn&#39;t zeroed.
Definition: object_base.h:32
Tile description for the &#39;land area information&#39; tool.
Definition: tile_cmd.h:51
demolish a tile
Definition: command_type.h:180
CommandCost CheckTileOwnership(TileIndex tile)
Check whether the current owner owns the stuff on the given tile.
Tindex index
Index of this pool item.
Definition: pool_type.hpp:189
#define GetCompanyHQSize
We encode the company HQ size in the animation stage.
Definition: object_cmd.cpp:146
static bool IsSteepSlope(Slope s)
Checks if a slope is steep.
Definition: slope_func.h:36
Allow incrementing of ObjectClassID variables.
Definition: newgrf_object.h:58
Object get automatically removed (like "owned land").
Definition: newgrf_object.h:28
int GetBridgeHeight(TileIndex t)
Get the height (&#39;z&#39;) of a bridge.
Definition: bridge_map.cpp:70
static bool TryBuildLightHouse()
Try to build a lighthouse.
Definition: object_cmd.cpp:654
#define IncreaseCompanyHQSize
We encode the company HQ size in the animation stage.
Definition: object_cmd.cpp:148
bool WasEverAvailable() const
Check whether the object was available at some point in the past or present in this game with the cur...
Functions related to world/map generation.
Contains objects such as transmitters and owned land.
Definition: tile_type.h:51
static void ReallyClearObjectTile(Object *o)
Perform the actual removal of the object from the map.
Definition: object_cmd.cpp:431
Construction costs.
Definition: economy_type.h:149
Common return value for all commands.
Definition: command_type.h:23
static void IncreaseAnimationStage(TileIndex tile)
Increase the animation stage of a whole structure.
Definition: object_cmd.cpp:136
Callback done for each tile of an object to check the slope.
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:24
static void InvalidateAllFrom(SourceType src_type, SourceID src)
Invalidates (sets source_id to INVALID_SOURCE) all cargo packets from given source.
void MultiplyCost(int factor)
Multiplies the cost of the command by the given factor.
Definition: command_type.h:73
uint16 w
The width of the area.
Definition: tilearea_type.h:18
bool IsTileFlat(TileIndex tile, int *h)
Check if a given tile is flat.
Definition: tile_map.cpp:100
a flat tile
Definition: slope_type.h:49
CommandCost GetErrorMessageFromLocationCallbackResult(uint16 cb_res, const GRFFile *grffile, StringID default_error)
Get the error message from a shape/location/slope check callback result.
int z
Height.
Definition: tile_cmd.h:47
static uint32 RandomRange(uint32 limit)
Pick a random number between 0 and limit - 1, inclusive.
Definition: random_func.hpp:81
void DrawFoundation(TileInfo *ti, Foundation f)
Draw foundation f at tile ti.
Definition: landscape.cpp:470
void AddCost(const Money &cost)
Adds the given cost to the cost of the command.
Definition: command_type.h:62
Owner owner[4]
Name of the owner(s)
Definition: tile_cmd.h:53
const DrawTileSeqStruct * seq
Array of child sprites. Terminated with a terminator entry.
Definition: sprite.h:60
static const ObjectSpec * Get(ObjectType index)
Get the specification associated with a specific ObjectType.
static bool IsObjectType(TileIndex t, ObjectType type)
Check whether the object on a tile is of a specific type.
Definition: object_map.h:25
Functions related to (drawing on) viewports.
Pseudo random number generator.
uint8 size
The size of this objects; low nibble for X, high nibble for Y.
Definition: newgrf_object.h:65
Functions related to NewGRF objects.
bool freeform_edges
allow terraforming the tiles at the map edges
Slope GetTileSlope(TileIndex tile, int *h)
Return the slope of a given tile inside the map.
Definition: tile_map.cpp:59
Base class for cargo packets.
static bool IsValidTile(TileIndex tile)
Checks if a tile is valid.
Definition: tile_map.h:161
static bool IsBridgeAbove(TileIndex t)
checks if a bridge is set above the ground of this tile
Definition: bridge_map.h:45
static bool IsTileOwner(TileIndex tile, Owner owner)
Checks if a tile belongs to the given owner.
Definition: tile_map.h:214
Base for all objects.
uint8 height
The height of this structure, in heightlevels; max MAX_TILE_HEIGHT.
Definition: newgrf_object.h:73
Some methods of Pool are placed here in order to reduce compilation time and binary size...
Sprites to use and how to display them for object tiles.
uint x
X position of the tile in unit coordinates.
Definition: tile_cmd.h:43
The tile has no ownership.
Definition: company_type.h:25
static TileIndexDiff TileOffsByDiagDir(DiagDirection dir)
Convert a DiagDirection to a TileIndexDiff.
Definition: map_func.h:341
bool enabled
Is this spec enabled?
Definition: newgrf_object.h:76
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Definition: tilearea_type.h:96
Foundation
Enumeration for Foundations.
Definition: slope_type.h:93
Types related to cheating.
Source/destination are company headquarters.
Definition: cargo_type.h:149
static bool IsTileType(TileIndex tile, TileType type)
Checks if a tile is a given tiletype.
Definition: tile_map.h:150
void AnimateNewObjectTile(TileIndex tile)
Handle the animation of the object tile.
Southeast.
TileIndex tile
Tile index.
Definition: tile_cmd.h:46
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
Object can only be built in game.
Definition: newgrf_object.h:33
CommandCost DoCommand(const CommandContainer *container, DoCommandFlag flags)
Shorthand for calling the long DoCommand with a container.
Definition: command.cpp:441
static uint16 counts[NUM_OBJECTS]
Number of objects per type ingame.
Definition: object_base.h:78
Ground palette sprite of a tile, together with its sprite layout.
Definition: sprite.h:58
Money GetClearCost() const
Get the cost for clearing a structure of this type.
Definition: newgrf_object.h:88
void DirtyCompanyInfrastructureWindows(CompanyID company)
Redraw all windows with company infrastructure counts.
WaterClass
classes of water (for WATER_TILE_CLEAR water tile type).
Definition: water_map.h:47
const StationList * GetStations()
Run a tile loop to find stations around a tile, on demand.
static Owner GetTileOwner(TileIndex tile)
Returns the owner of a tile.
Definition: tile_map.h:178
bool ConvertBooleanCallback(const GRFFile *grffile, uint16 cbid, uint16 cb_res)
Converts a callback result into a boolean.
DoCommandFlag
List of flags for a command.
Definition: command_type.h:342
Object can only be constructed in the scenario editor.
Definition: newgrf_object.h:26
#define foreach_draw_tile_seq(idx, list)
Iterate through all DrawTileSeqStructs in DrawTileSprites.
Definition: sprite.h:79
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:150
Keeps track of removed objects during execution/testruns of commands.
Definition: object_base.h:84
Triggered when the object is built (for all tiles at the same time).
TileIndex location_of_HQ
Northern tile of HQ; INVALID_TILE when there is none.
Definition: company_base.h:73
#define TILE_AREA_LOOP(var, ta)
A loop which iterates over the tiles of a TileArea.
Definition of base types and functions in a cross-platform compatible way.
Map accessors for object tiles.
A number of safeguards to prevent using unsafe methods.
bool value
tells if the bool cheat is active or not
Definition: cheat_type.h:18
bool CircularTileSearch(TileIndex *tile, uint size, TestTileOnSearchProc proc, void *user_data)
Function performing a search around a center tile and going outward, thus in circle.
Definition: map.cpp:258
uint16 callback_mask
Bitmask of requested/allowed callbacks.
Definition: newgrf_object.h:72
uint16 GetObjectCallback(CallbackID callback, uint32 param1, uint32 param2, const ObjectSpec *spec, Object *o, TileIndex tile, uint8 view)
Perform a callback for an object.
Water tile.
Definition: tile_type.h:47
uint y
Y position of the tile in unit coordinates.
Definition: tile_cmd.h:44
An object, such as transmitter, on the map.
Definition: object_base.h:23
uint8 views
The number of views.
Definition: newgrf_object.h:74
static Slope GetTilePixelSlope(TileIndex tile, int *h)
Return the slope of a given tile.
Definition: tile_map.h:280
static const ObjectType NEW_OBJECT_OFFSET
Offset for new objects.
Definition: object_type.h:24
Information about a particular livery.
Definition: livery.h:78
Represents the covered area of e.g.
Definition: tilearea_type.h:16
GUI Functions related to companies.
void BuildObject(ObjectType type, TileIndex tile, CompanyID owner, Town *town, uint8 view)
Actually build the object.
Definition: object_cmd.cpp:83
When object is cleared a positive income is generated instead of a cost.
Definition: newgrf_object.h:30
Money CalculateCompanyValue(const Company *c, bool including_loan=true)
Calculate the value of the company.
Definition: economy.cpp:111
don&#39;t allow building on water
Definition: command_type.h:347
Map accessor functions for bridges.
CommandCost CheckOwnership(Owner owner, TileIndex tile)
Check whether the current owner owns something.
static const ObjectType OBJECT_OWNED_LAND
Owned land &#39;flag&#39;.
Definition: object_type.h:19
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:1938
void TriggerObjectAnimation(Object *o, ObjectAnimationTrigger trigger, const ObjectSpec *spec)
Trigger the update of animation on a whole object.
CommandCost CmdBuildObject(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
Build an object object.
Definition: object_cmd.cpp:202
Object can not be on land, implicitly sets OBJECT_FLAG_BUILT_ON_WATER.
Definition: newgrf_object.h:35
static bool IsWaterTile(TileIndex t)
Is it a water tile with plain water?
Definition: water_map.h:184
static Foundation FlatteningFoundation(Slope s)
Returns the foundation needed to flatten a slope.
Definition: slope_func.h:369
static bool EconomyIsInRecession()
Is the economy in recession?
Definition: economy_func.h:47
decide the colour of the building
uint16 ObjectType
Types of objects.
Definition: object_type.h:14
TileIndex GetSouthernBridgeEnd(TileIndex t)
Finds the southern end of a bridge starting at a middle tile.
Definition: bridge_map.cpp:49
Functions related to autoslope.
static bool AutoslopeEnabled()
Tests if autoslope is enabled for _current_company.
Definition: autoslope.h:44
decides slope suitability
bool Failed() const
Did this command fail?
Definition: command_type.h:159
byte colour2
Second colour, for vehicles with 2CC support.
Definition: livery.h:81
Object has animated tiles.
Definition: newgrf_object.h:32
Functions to find and configure NewGRFs.
void AddSortableSpriteToDraw(SpriteID image, PaletteID pal, int x, int y, int w, int h, int dz, int z, bool transparent, int bb_offset_x, int bb_offset_y, int bb_offset_z, const SubSprite *sub)
Draw a (transparent) sprite at given coordinates with a given bounding box.
Definition: viewport.cpp:659
#define return_cmd_error(errcode)
Returns from a function with a specific StringID as error.
Definition: command_func.h:33
Triggered every 256 ticks (for all tiles at the same time).
Base class for all pools.
Definition: pool_type.hpp:82
StringID name
The name for this object.
Definition: newgrf_object.h:62
Functions related to clear (MP_CLEAR) land.
TileIndex tile
The base tile of the area.
Definition: tilearea_type.h:17
static uint ScaleByMapSize1D(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:136
#define INSTANTIATE_POOL_METHODS(name)
Force instantiation of pool methods so we don&#39;t get linker errors.
Definition: pool_func.hpp:224
The X axis.
static bool TryBuildTransmitter()
Try to build a transmitter.
Definition: object_cmd.cpp:696
static Axis DiagDirToAxis(DiagDirection d)
Convert a DiagDirection to the axis.
Town * CalcClosestTownFromTile(TileIndex tile, uint threshold=UINT_MAX)
Return the town closest to the given tile within threshold.
Definition: town_cmd.cpp:3470
CommandCost CheckBuildableTile(TileIndex tile, uint invalid_dirs, int &allowed_z, bool allow_steep, bool check_bridge)
Checks if the given tile is buildable, flat and has a certain height.
execute the given command
Definition: command_type.h:344
The tile/execution is done by "water".
Definition: company_type.h:26
PalSpriteID ground
Palette and sprite for the ground.
Definition: sprite.h:59
GRFConfig * GetGRFConfig(uint32 grfid, uint32 mask)
Retrieve a NewGRF from the current config by its grfid.
static uint MapSize()
Get the size of the map.
Definition: map_func.h:92
void ErrorUnknownCallbackResult(uint32 grfid, uint16 cbid, uint16 cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Class for storing amounts of cargo.
Definition: cargo_type.h:81
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:60
Object count is roughly scaled by water amount at edges.
Definition: newgrf_object.h:39
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
Town authority; Window numbers:
Definition: window_type.h:187
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:340
int GetTileMaxZ(TileIndex t)
Get top height of the tile inside the map.
Definition: tile_map.cpp:141
Set of callback functions for performing tile operations of a given tile type.
Definition: tile_cmd.h:145
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
Functions related to objects.
static void ResetTypeCounts()
Resets object counts.
Definition: object_base.h:72
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:321
static void IncTypeCount(ObjectType type)
Increment the count of objects for this type.
Definition: object_base.h:43
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:149
void UpdateCompanyHQ(TileIndex tile, uint score)
Update the CompanyHQ to the state associated with the given score.
Definition: object_cmd.cpp:155
Property costs.
Definition: economy_type.h:155
static uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:215
Cheat magic_bulldozer
dynamite industries, objects
Definition: cheat_type.h:27
int8 delta_z
0x80 identifies child sprites
Definition: sprite.h:28
The tile has no foundation, the slope remains unchanged.
Definition: slope_type.h:94
TileArea location
Location of the object.
Definition: object_base.h:26
TransportType
Available types of transport.
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
ObjectType type
Type of the object.
Definition: object_base.h:24
Slope
Enumeration for the slope-type.
Definition: slope_type.h:48
static uint MapMaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
Definition: map_func.h:111
Maximum number of companies.
Definition: company_type.h:23
Town data structure.
Definition: town.h:53
uint8 generate_amount
Number of objects which are attempted to be generated per 256^2 map during world generation.
Definition: newgrf_object.h:75
static bool CanAllocateItem(size_t n=1)
Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() ...
Definition: pool_type.hpp:261
static ObjectID GetObjectIndex(TileIndex t)
Get the index of which object this tile is attached to.
Definition: object_map.h:47
Functions related to OTTD&#39;s landscape.
other objects such as transmitters and lighthouses
Definition: transparency.h:29
void InitializeObjects()
Initialize/reset the objects.
Definition: object_cmd.cpp:68
Functions related to commands.
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:45
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:575
Date build_date
Date of construction of tile contents.
Definition: tile_cmd.h:55
static Object * GetByTile(TileIndex tile)
Get the object associated with a tile.
Definition: object_cmd.cpp:50
ConstructionSettings construction
construction of things in-game
const char * GetName() const
Get the name of this grf.
static void DecTypeCount(ObjectType type)
Decrement the count of objects for this type.
Definition: object_base.h:54
const struct GRFFile * grffile
grf file that introduced this entity
StringID str
Description of the tile.
Definition: tile_cmd.h:52
Object can be built on water (not required).
Definition: newgrf_object.h:29
decides allowance of autosloping
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
DiagDirection
Enumeration for diagonal directions.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:83
Object can built under a bridge.
Definition: newgrf_object.h:37
Base of the town class.
byte colour1
First colour, for all vehicles.
Definition: livery.h:80
Northeast, upper right on your monitor.
Called to determine the colour of a town building.
static bool HasTransmitter(TileIndex tile, void *user)
Helper function for CircularTileSearch.
Definition: object_cmd.cpp:645
Triggered in the periodic tile loop.
A tile without any structures, i.e. grass, rocks, farm fields etc.
Definition: tile_type.h:41
static const ObjectSpec * GetByTile(TileIndex tile)
Get the specification associated with a tile.
static uint MapMaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
Definition: map_func.h:102
static bool IsInvisibilitySet(TransparencyOption to)
Check if the invisibility option bit is set and if we aren&#39;t in the game menu (there&#39;s never transpar...
Definition: transparency.h:59
int8 delta_x
0x80 is sequence terminator
Definition: sprite.h:26
Window functions not directly related to making/drawing windows.
Called to determine if one can alter the ground below an object tile.
byte view
The view setting for this object.
Definition: object_base.h:29
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
Functions related to water (management)
void UpdateObjectColours(const Company *c)
Updates the colour of the object whenever a company changes.
Definition: object_cmd.cpp:174
town rating does not disallow you from building
Definition: command_type.h:349
static bool IsTileOnWater(TileIndex t)
Tests if the tile was built on water.
Definition: water_map.h:130
SpriteID sprite
The &#39;real&#39; sprite.
Definition: gfx_type.h:23
Structure contains cached list of stations nearby.
Definition: station_type.h:100
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
Date _date
Current date in days (day counter)
Definition: date.cpp:26
A tile child sprite and palette to draw for stations etc, with 3D bounding box.
Definition: sprite.h:25
uint16 h
The height of the area.
Definition: tilearea_type.h:19
Company view; Window numbers:
Definition: window_type.h:362
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
Delete inspect window for a given feature and index.
static void MakeObject(TileIndex t, Owner o, ObjectID index, WaterClass wc, byte random)
Make an Object tile.
Definition: object_map.h:74
void DrawBridgeMiddle(const TileInfo *ti)
Draw the middle bits of a bridge.
static bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren&#39;t in the game menu (there&#39;s never transpar...
Definition: transparency.h:48
static const ObjectType OBJECT_HQ
HeadQuarter of a player.
Definition: object_type.h:20
Used for industry tiles on land (also for oilrig if newgrf says so).
Definition: water_map.h:51
static const ObjectType OBJECT_LIGHTHOUSE
The nice lighthouse.
Definition: object_type.h:17
static TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
Definition: map_func.h:163
Do not display foundations when on a slope.
Definition: newgrf_object.h:31
ObjectType GetObjectType(TileIndex t)
Gets the ObjectType of the given object tile.
Definition: object_cmd.cpp:61
Southwest.
Cheats _cheats
All the cheats.
Definition: cheat.cpp:16
static bool IsObjectTypeTile(TileIndex t, ObjectType type)
Check whether a tile is a object tile of a specific type.
Definition: object_map.h:36
static int GetTileMaxPixelZ(TileIndex tile)
Get top height of the tile.
Definition: tile_map.h:304