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

Function DrawRoadStopTile

src/newgrf_roadstop.cpp:282–340  ·  view source on GitHub ↗

* Draw representation of a road stop tile for GUI purposes. * @param x position x of image. * @param y position y of image. * @param image an int offset for the sprite. * @param roadtype the RoadType of the underlying road. * @param spec the RoadStop's spec. * @return true of the tile was drawn (allows for fallback to default graphics) */

Source from the content-addressed store, hash-verified

280 * @return true of the tile was drawn (allows for fallback to default graphics)
281 */
282void DrawRoadStopTile(int x, int y, RoadType roadtype, const RoadStopSpec *spec, StationType type, int view)
283{
284 assert(roadtype != INVALID_ROADTYPE);
285 assert(spec != nullptr);
286
287 const RoadTypeInfo *rti = GetRoadTypeInfo(roadtype);
288 RoadStopResolverObject object(spec, nullptr, INVALID_TILE, roadtype, type, view);
289 const auto *group = object.Resolve<TileLayoutSpriteGroup>();
290 if (group == nullptr) return;
291 auto processor = group->ProcessRegisters(object, nullptr);
292 auto dts = processor.GetLayout();
293
294 PaletteID palette = GetCompanyPalette(_local_company);
295
296 SpriteID image = dts.ground.sprite;
297 PaletteID pal = dts.ground.pal;
298
299 RoadStopDrawModes draw_mode;
300 if (spec->flags.Test(RoadStopSpecFlag::DrawModeRegister)) {
301 draw_mode = static_cast<RoadStopDrawModes>(object.GetRegister(0x100));
302 } else {
303 draw_mode = spec->draw_mode;
304 }
305
306 if (type == StationType::RoadWaypoint) {
307 DrawSprite(SPR_ROAD_PAVED_STRAIGHT_X, PAL_NONE, x, y);
308 if (draw_mode.Test(RoadStopDrawMode::WaypGround) && GB(image, 0, SPRITE_WIDTH) != 0) {
309 DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
310 }
311 } else if (GB(image, 0, SPRITE_WIDTH) != 0) {
312 DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
313 }
314
315 if (view >= 4) {
316 /* Drive-through stop */
317 uint sprite_offset = 5 - view;
318
319 /* Road underlay takes precedence over tram */
320 if (type == StationType::RoadWaypoint || draw_mode.Test(RoadStopDrawMode::Overlay)) {
321 if (rti->UsesOverlay()) {
322 SpriteID ground = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_GROUND);
323 DrawSprite(ground + sprite_offset, PAL_NONE, x, y);
324
325 SpriteID overlay = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_OVERLAY);
326 if (overlay) DrawSprite(overlay + sprite_offset, PAL_NONE, x, y);
327 } else if (RoadTypeIsTram(roadtype)) {
328 DrawSprite(SPR_TRAMWAY_TRAM + sprite_offset, PAL_NONE, x, y);
329 }
330 }
331 } else {
332 /* Bay stop */
333 if (draw_mode.Test(RoadStopDrawMode::Road) && rti->UsesOverlay()) {
334 SpriteID ground = GetCustomRoadSprite(rti, INVALID_TILE, ROTSG_ROADSTOP);
335 DrawSprite(ground + view, PAL_NONE, x, y);
336 }
337 }
338
339 DrawCommonTileSeqInGUI(x, y, &dts, 0, 0, palette, true);

Callers 3

DrawTypeMethod · 0.85
DrawWidgetMethod · 0.85
DrawTypeMethod · 0.85

Calls 13

GetRoadTypeInfoFunction · 0.85
GetCompanyPaletteFunction · 0.85
DrawSpriteFunction · 0.85
GBFunction · 0.85
GetCustomRoadSpriteFunction · 0.85
RoadTypeIsTramFunction · 0.85
DrawCommonTileSeqInGUIFunction · 0.85
GetLayoutMethod · 0.80
TestMethod · 0.80
GetRegisterMethod · 0.80
ProcessRegistersMethod · 0.45

Tested by

no test coverage detected