MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / BeforeAddTile

Method BeforeAddTile

src/station.cpp:575–607  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

573}
574
575CommandCost StationRect::BeforeAddTile(TileIndex tile, StationRectMode mode)
576{
577 int x = TileX(tile);
578 int y = TileY(tile);
579 if (this->IsEmpty()) {
580 /* we are adding the first station tile */
581 if (mode != ADD_TEST) {
582 this->left = this->right = x;
583 this->top = this->bottom = y;
584 }
585 } else if (!this->PtInExtendedRect(x, y)) {
586 /* current rect is not empty and new point is outside this rect
587 * make new spread-out rectangle */
588 Rect new_rect = {std::min(x, this->left), std::min(y, this->top), std::max(x, this->right), std::max(y, this->bottom)};
589
590 /* check new rect dimensions against preset max */
591 int w = new_rect.Width();
592 int h = new_rect.Height();
593 if (mode != ADD_FORCE && (w > _settings_game.station.station_spread || h > _settings_game.station.station_spread)) {
594 assert(mode != ADD_TRY);
595 return CommandCost(STR_ERROR_STATION_TOO_SPREAD_OUT);
596 }
597
598 /* spread-out ok, return true */
599 if (mode != ADD_TEST) {
600 /* we should update the station rect */
601 *this = new_rect;
602 }
603 } else {
604 ; // new point is inside the rect, we don't need to do anything
605 }
606 return CommandCost();
607}
608
609CommandCost StationRect::BeforeAddRect(TileIndex tile, int w, int h, StationRectMode mode)
610{

Callers 8

BeforeAddRectMethod · 0.95
CmdBuildRoadWaypointFunction · 0.80
CmdBuildBuoyFunction · 0.80
CmdBuildRoadStopFunction · 0.80
BuildOilRigFunction · 0.80
AfterLoadGameFunction · 0.80
MoveBuoysToWaypointsFunction · 0.80

Calls 7

IsEmptyMethod · 0.95
PtInExtendedRectMethod · 0.95
TileXFunction · 0.85
TileYFunction · 0.85
CommandCostClass · 0.85
WidthMethod · 0.45
HeightMethod · 0.45

Tested by

no test coverage detected