MCPcopy Create free account
hub / github.com/OpenRCT2/OpenRCT2 / QueryExecute

Method QueryExecute

src/openrct2/actions/scenery/BannerSetColourAction.cpp:57–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55 }
56
57 Result BannerSetColourAction::QueryExecute(bool isExecuting) const
58 {
59 auto res = Result();
60 res.expenditure = ExpenditureType::landscaping;
61 res.position.x = _loc.x + 16;
62 res.position.y = _loc.y + 16;
63 res.position.z = _loc.z;
64 res.errorTitle = STR_CANT_REPAINT_THIS;
65
66 if (!LocationValid(_loc))
67 {
68 LOG_ERROR("Invalid x / y coordinates: x = %d, y = %d", _loc.x, _loc.y);
69 return Result(Status::invalidParameters, STR_CANT_REPAINT_THIS, STR_OFF_EDGE_OF_MAP);
70 }
71
72 if (!Drawing::colourIsValid(_primaryColour))
73 {
74 LOG_ERROR("Invalid primary colour %u", _primaryColour);
75 return Result(Status::invalidParameters, STR_CANT_REPAINT_THIS, STR_ERR_INVALID_COLOUR);
76 }
77
78 if (!MapCanBuildAt({ _loc.x, _loc.y, _loc.z - 16 }))
79 {
80 return Result(Status::notOwned, STR_CANT_REPAINT_THIS, STR_LAND_NOT_OWNED_BY_PARK);
81 }
82
83 auto bannerElement = MapGetBannerElementAt(_loc, _loc.direction);
84
85 if (bannerElement == nullptr)
86 {
87 LOG_ERROR("No banner at x = %d, y = %d, z = %d, direction = %u", _loc.x, _loc.y, _loc.z, _loc.direction);
88 return Result(Status::unknown, STR_CANT_REPAINT_THIS, STR_ERR_BANNER_ELEMENT_NOT_FOUND);
89 }
90
91 auto index = bannerElement->GetIndex();
92 auto banner = GetBanner(index);
93 if (banner == nullptr)
94 {
95 LOG_ERROR("Invalid banner index %u", index);
96 return Result(Status::invalidParameters, STR_CANT_REPAINT_THIS, kStringIdNone);
97 }
98
99 if (isExecuting)
100 {
101 auto intent = Intent(INTENT_ACTION_UPDATE_BANNER);
102 intent.PutExtra(INTENT_EXTRA_BANNER_INDEX, index);
103 ContextBroadcastIntent(&intent);
104
105 banner->colour = _primaryColour;
106 MapInvalidateTileZoom1({ _loc, _loc.z, _loc.z + 32 });
107 }
108
109 return res;
110 }
111} // namespace OpenRCT2::GameActions

Callers

nothing calls this directly

Calls 10

colourIsValidFunction · 0.85
MapCanBuildAtFunction · 0.85
MapGetBannerElementAtFunction · 0.85
GetBannerFunction · 0.85
ContextBroadcastIntentFunction · 0.85
MapInvalidateTileZoom1Function · 0.85
ResultClass · 0.50
IntentClass · 0.50
GetIndexMethod · 0.45
PutExtraMethod · 0.45

Tested by

no test coverage detected