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

Function VerifyElementContentParameters

src/story.cpp:59–96  ·  view source on GitHub ↗

* This helper for Create/Update PageElement Cmd procedure verifies if the page * element parameters are correct for the given page element type. * @param page_id The page id of the page which the page element (will) belong to * @param type The type of the page element to create/update * @param tile The tile parameter of the DoCommand proc * @param reference The reference parameter of the DoCo

Source from the content-addressed store, hash-verified

57 * @return true, if and only if the given parameters are valid for the given page element type and page id.
58 */
59static bool VerifyElementContentParameters(StoryPageID page_id, StoryPageElementType type, TileIndex tile, uint32_t reference, const EncodedString &text)
60{
61 StoryPageButtonData button_data{ reference };
62
63 switch (type) {
64 case SPET_TEXT:
65 if (text.empty()) return false;
66 break;
67 case SPET_LOCATION:
68 if (text.empty()) return false;
69 if (!IsValidTile(tile)) return false;
70 break;
71 case SPET_GOAL:
72 if (!Goal::IsValidID((GoalID)reference)) return false;
73 /* Reject company specific goals on global pages */
74 if (StoryPage::Get(page_id)->company == CompanyID::Invalid() && Goal::Get((GoalID)reference)->company != CompanyID::Invalid()) return false;
75 break;
76 case SPET_BUTTON_PUSH:
77 if (!button_data.ValidateColour()) return false;
78 if (!button_data.ValidateFlags()) return false;
79 return true;
80 case SPET_BUTTON_TILE:
81 if (!button_data.ValidateColour()) return false;
82 if (!button_data.ValidateFlags()) return false;
83 if (!button_data.ValidateCursor()) return false;
84 return true;
85 case SPET_BUTTON_VEHICLE:
86 if (!button_data.ValidateColour()) return false;
87 if (!button_data.ValidateFlags()) return false;
88 if (!button_data.ValidateCursor()) return false;
89 if (!button_data.ValidateVehicleType()) return false;
90 return true;
91 default:
92 return false;
93 }
94
95 return true;
96}
97
98/**
99 * This helper for Create/Update PageElement Cmd procedure updates a page

Callers 2

Calls 7

IsValidTileFunction · 0.85
InvalidFunction · 0.85
ValidateColourMethod · 0.80
ValidateFlagsMethod · 0.80
ValidateCursorMethod · 0.80
ValidateVehicleTypeMethod · 0.80
emptyMethod · 0.45

Tested by

no test coverage detected