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

Function BuildStationPart

src/station_cmd.cpp:687–716  ·  view source on GitHub ↗

* Common part of building various station parts and possibly attaching them to an existing one. * @param[in,out] st Station to attach to * @param flags Command flags * @param reuse Whether to try to reuse a deleted station (gray sign) if possible * @param area Area occupied by the new part * @param name_class Station naming class to use to generate the new station's name * @return Command er

Source from the content-addressed store, hash-verified

685 * @return Command error that occurred, if any
686 */
687static CommandCost BuildStationPart(Station **st, DoCommandFlags flags, bool reuse, TileArea area, StationNaming name_class)
688{
689 /* Find a deleted station close to us */
690 if (*st == nullptr && reuse) *st = GetClosestDeletedStation(area.tile);
691
692 if (*st != nullptr) {
693 if ((*st)->owner != _current_company) {
694 return CommandCost(CMD_ERROR);
695 }
696
697 CommandCost ret = (*st)->rect.BeforeAddRect(area.tile, area.w, area.h, StationRect::ADD_TEST);
698 if (ret.Failed()) return ret;
699 } else {
700 /* allocate and initialize new station */
701 if (!Station::CanAllocateItem()) return CommandCost(STR_ERROR_TOO_MANY_STATIONS_LOADING);
702
703 if (flags.Test(DoCommandFlag::Execute)) {
704 *st = new Station(area.tile);
705 _station_kdtree.Insert((*st)->index);
706
707 (*st)->town = ClosestTownFromTile(area.tile, UINT_MAX);
708 (*st)->string_id = GenerateStationName(*st, area.tile, name_class);
709
710 if (Company::IsValidID(_current_company)) {
711 (*st)->town->have_ratings.Set(_current_company);
712 }
713 }
714 }
715 return CommandCost();
716}
717
718/**
719 * This is called right after a station was deleted.

Callers 4

CmdBuildRailStationFunction · 0.85
CmdBuildRoadStopFunction · 0.85
CmdBuildAirportFunction · 0.85
CmdBuildDockFunction · 0.85

Calls 9

GetClosestDeletedStationFunction · 0.85
CommandCostClass · 0.85
ClosestTownFromTileFunction · 0.85
GenerateStationNameFunction · 0.85
BeforeAddRectMethod · 0.80
FailedMethod · 0.80
TestMethod · 0.80
InsertMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected