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

Function removeSignal

src/OpenLoco/src/GameCommands/Track/RemoveSignal.cpp:84–182  ·  view source on GitHub ↗

0x004891E4

Source from the content-addressed store, hash-verified

82
83 // 0x004891E4
84 static currency32_t removeSignal(const SignalRemovalArgs& args, uint8_t flags)
85 {
86 setExpenditureType(ExpenditureType::Construction);
87 setPosition(args.pos + World::Pos3{ 16, 16, 0 });
88
89 auto* elTrack = getElTrackAt(args, args.pos, args.index);
90
91 if (elTrack == nullptr)
92 {
93 return kFailure;
94 }
95
96 if (!sub_431E6A(elTrack->owner(), reinterpret_cast<World::TileElement*>(elTrack)))
97 {
98 return kFailure;
99 }
100
101 const auto trackPieces = World::TrackData::getTrackPiece(args.trackId);
102 auto& trackPiece = trackPieces[args.index];
103
104 const auto trackStart = args.pos - World::Pos3{ Math::Vector::rotate(World::Pos2{ trackPiece.x, trackPiece.y }, args.rotation), trackPiece.z };
105
106 currency32_t cost = signalRemoveCost(args, trackPieces[0], trackStart);
107
108 if (static_cast<uint32_t>(cost) == kFailure)
109 {
110 return kFailure;
111 }
112
113 for (auto& piece : trackPieces)
114 {
115 const auto trackLoc = trackStart + World::Pos3{ Math::Vector::rotate(World::Pos2{ piece.x, piece.y }, args.rotation), piece.z };
116 auto* pieceElTrack = getElTrackAt(args, trackLoc, piece.index);
117 if (pieceElTrack == nullptr)
118 {
119 return kFailure;
120 }
121
122 if (!(flags & Flags::apply))
123 {
124 continue;
125 }
126
127 if (!pieceElTrack->hasSignal())
128 {
129 return 0;
130 }
131
132 auto* elSignal = pieceElTrack->next()->as<World::SignalElement>();
133 if (elSignal == nullptr)
134 {
135 return kFailure;
136 }
137
138 if (args.flags & (1U << 15))
139 {
140 if (!(flags & Flags::ghost) || elSignal->isLeftGhost())
141 {

Callers

nothing calls this directly

Calls 15

setExpenditureTypeFunction · 0.85
setPositionFunction · 0.85
sub_431E6AFunction · 0.85
getTrackPieceFunction · 0.85
signalRemoveCostFunction · 0.85
sub_4A2AD7Function · 0.85
getUpdatingCompanyIdFunction · 0.85
SignalRemovalArgsClass · 0.85
isLeftGhostMethod · 0.80
setAllLightsMethod · 0.80
setFrameMethod · 0.80
setLeftGhostMethod · 0.80

Tested by

no test coverage detected