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

Function paintBuilding

src/OpenLoco/src/Paint/PaintBuilding.cpp:166–232  ·  view source on GitHub ↗

0x0042C6C4

Source from the content-addressed store, hash-verified

164
165 // 0x0042C6C4
166 void paintBuilding(PaintSession& session, const World::BuildingElement& elBuilding)
167 {
168 session.setItemType(Ui::ViewportInteraction::InteractionItem::building);
169 auto* buildingObj = elBuilding.getObject();
170 if (buildingObj->hasFlags(BuildingObjectFlags::isHeadquarters))
171 {
172 session.setItemType(Ui::ViewportInteraction::InteractionItem::headquarterBuilding);
173 }
174
175 ImageId baseColour(0, elBuilding.colour());
176 if (elBuilding.isGhost())
177 {
178 session.setItemType(Ui::ViewportInteraction::InteractionItem::noInteraction);
179 baseColour = Gfx::applyGhostToImage(0);
180 }
181 // Combine this with any imageId
182 const uint8_t rotation = (session.getRotation() + elBuilding.rotation()) & 0x3;
183
184 // 0x00525D4E
185 const int16_t bbLengthZ = std::min(elBuilding.clearHeight() - elBuilding.baseHeight(), 128) - 2;
186
187 // 0x00525D18
188 const auto variation = elBuilding.variation();
189
190 const auto baseHeight = elBuilding.baseHeight();
191
192 bool isMultiTile = buildingObj->hasFlags(BuildingObjectFlags::largeTile);
193
194 // Note: Image offsets will change as you move up the building but bboffset/size does not
195 const World::Pos3 imageOffset = (isMultiTile ? kImageOffsetBase2x2 : kImageOffsetBase1x1) + World::Pos3{ 0, 0, baseHeight };
196 const World::Pos3 bbOffset = (isMultiTile ? kBBOffsetBase2x2 : kBBOffsetBase1x1) + World::Pos3{ 0, 0, baseHeight };
197 const World::Pos3 bbSize = (isMultiTile ? kBBSizeBase2x2 : kBBSizeBase1x1) + World::Pos3{ 0, 0, bbLengthZ };
198
199 session.resetLastPS(); // Odd...
200 if (buildingObj->hasFlags(BuildingObjectFlags::hasShadows))
201 {
202 if (session.getRenderTarget()->zoomLevel <= 1)
203 {
204 const auto shadowImageOffset = (buildingObj->numParts + buildingObj->numElevatorSequences + variation) * 4 + buildingObj->image + rotation;
205 const ImageId shadowImage = ImageId(shadowImageOffset).withTranslucency(Colours::getShadow(Colour::orange));
206 if (isMultiTile)
207 {
208 session.addToPlotListAsChild(shadowImage, imageOffset, bbOffset, bbSize);
209 }
210 else
211 {
212 session.addToPlotListAsChild(shadowImage, imageOffset, bbOffset, bbSize);
213 }
214 }
215 }
216
217 if (isMultiTile)
218 {
219 const auto sequenceIndex = elBuilding.sequenceIndex();
220 // Only the front of the 2x2 area will draw. Images are sized to overlap into the other tiles.
221 if ((sequenceIndex ^ (1 << 1)) == ((-session.getRotation()) & 0x3))
222 {
223 paintBuildingBuilding(session, elBuilding, *buildingObj, imageOffset, bbOffset, bbSize, baseColour, rotation, isMultiTile);

Callers 2

paintTileElementsFunction · 0.85
paintTileElements2Function · 0.85

Calls 15

applyGhostToImageFunction · 0.85
ImageIdClass · 0.85
getShadowFunction · 0.85
paintBuildingBuildingFunction · 0.85
setItemTypeMethod · 0.80
clearHeightMethod · 0.80
baseHeightMethod · 0.80
resetLastPSMethod · 0.80
getRenderTargetMethod · 0.80
withTranslucencyMethod · 0.80
addToPlotListAsChildMethod · 0.80

Tested by

no test coverage detected