MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / removePort

Function removePort

src/OpenLoco/src/GameCommands/Docks/RemovePort.cpp:78–131  ·  view source on GitHub ↗

0x00494570

Source from the content-addressed store, hash-verified

76
77 // 0x00494570
78 static currency32_t removePort(const PortRemovalArgs& args, const uint8_t flags)
79 {
80 setExpenditureType(ExpenditureType::Construction);
81 setPosition(args.pos + World::Pos3(16, 16, 0));
82
83 // Find station element on tile
84 auto* stationEl = getStationEl(args.pos);
85 if (stationEl == nullptr)
86 {
87 return kFailure;
88 }
89
90 StationId stationId = StationId::null;
91 const auto rotation = stationEl->rotation();
92
93 // Do we need to remove the port from a station?
94 if ((flags & Flags::ghost) == 0)
95 {
96 stationId = stationEl->stationId();
97 }
98
99 // Station in use by a vehicle?
100 if (stationEl->isFlag6())
101 {
102 GameCommands::setErrorText(StringIds::currently_in_use_by_at_least_one_vehicle);
103 return kFailure;
104 }
105
106 // Calculate base removal cost
107 auto* dockObj = ObjectManager::get<DockObject>(stationEl->objectId());
108 currency32_t totalCost = Economy::getInflationAdjustedCost(dockObj->sellCostFactor, dockObj->costIndex, 7);
109
110 // Remove the actual tile elements associated with the port
111 if (!removePortTileElements(args.pos, flags))
112 {
113 return kFailure;
114 }
115
116 // Should we update the station meta data?
117 if ((flags & Flags::ghost) == 0 && (flags & Flags::apply) != 0)
118 {
119 auto* station = StationManager::get(stationId);
120
121 removeTileFromStationAndRecalcCargo(stationId, args.pos, rotation);
122 station->invalidate();
123
124 recalculateStationModes(stationId);
125 recalculateStationCenter(stationId);
126 station->updateLabel();
127 station->invalidate();
128 }
129
130 return totalCost;
131 }
132
133 void removePort(registers& regs)
134 {

Callers

nothing calls this directly

Calls 15

setExpenditureTypeFunction · 0.85
setPositionFunction · 0.85
setErrorTextFunction · 0.85
getInflationAdjustedCostFunction · 0.85
removePortTileElementsFunction · 0.85
recalculateStationModesFunction · 0.85
recalculateStationCenterFunction · 0.85
PortRemovalArgsClass · 0.85
stationIdMethod · 0.80
isFlag6Method · 0.80
getStationElFunction · 0.70

Tested by

no test coverage detected