* 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
| 685 | * @return Command error that occurred, if any |
| 686 | */ |
| 687 | static 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. |
no test coverage detected