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

Function CmdPlaceSign

src/signs_cmd.cpp:35–56  ·  view source on GitHub ↗

* Place a sign at the given coordinates. Ownership of sign has * no effect whatsoever except for the colour the sign gets for easy recognition, * but everybody is able to rename/remove it. * @param tile tile to place sign at * @param flags type of operation * @param text contents of the sign * @return the cost of this operation + the ID of the new sign or an error */

Source from the content-addressed store, hash-verified

33 * @return the cost of this operation + the ID of the new sign or an error
34 */
35std::tuple<CommandCost, SignID> CmdPlaceSign(DoCommandFlags flags, TileIndex tile, const std::string &text)
36{
37 /* Try to locate a new sign */
38 if (!Sign::CanAllocateItem()) return { CommandCost(STR_ERROR_TOO_MANY_SIGNS), SignID::Invalid() };
39
40 /* Check sign text length if any */
41 if (Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return { CMD_ERROR, SignID::Invalid() };
42
43 /* When we execute, really make the sign */
44 if (flags.Test(DoCommandFlag::Execute)) {
45 int x = TileX(tile) * TILE_SIZE;
46 int y = TileY(tile) * TILE_SIZE;
47
48 Sign *si = new Sign(_game_mode == GM_EDITOR ? OWNER_DEITY : _current_company, x, y, GetSlopePixelZ(x, y), text);
49
50 si->UpdateVirtCoord();
51 InvalidateWindowData(WC_SIGN_LIST, 0, 0);
52 return { CommandCost(), si->index };
53 }
54
55 return { CommandCost(), SignID::Invalid() };
56}
57
58/**
59 * Rename a sign. If the new name of the sign is empty, we assume

Callers

nothing calls this directly

Calls 9

CommandCostClass · 0.85
InvalidFunction · 0.85
Utf8StringLengthFunction · 0.85
TileXFunction · 0.85
TileYFunction · 0.85
GetSlopePixelZFunction · 0.85
TestMethod · 0.80
InvalidateWindowDataFunction · 0.70
UpdateVirtCoordMethod · 0.45

Tested by

no test coverage detected