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