* 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 */
| 33 | * @return the cost of this operation + the ID of the new sign or an error |
| 34 | */ |
| 35 | std::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 |
nothing calls this directly
no test coverage detected