Files
@ r26102:502baaa2877d
Branch filter:
Location: cpp/openttd-patchpack/source/src/signs_cmd.cpp - annotation
r26102:502baaa2877d
4.1 KiB
text/x-c
Codechange: Template DoCommand to automagically reflect the parameters of the command proc.
When finished, this will allow each command handler to take individually
different parameters, obliviating the need for bit-packing.
When finished, this will allow each command handler to take individually
different parameters, obliviating the need for bit-packing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r23437:6ce81d75a8ed r11345:85f52e96797f r11345:85f52e96797f r26094:7572e88decb3 r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r21383:942c32fb8b0e r21383:942c32fb8b0e r17625:366001a31c88 r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r13057:58af81fcdcf8 r13057:58af81fcdcf8 r11345:85f52e96797f r26095:00c14d52e378 r11345:85f52e96797f r11345:85f52e96797f r11725:57bc99fdc1bc r11345:85f52e96797f r11345:85f52e96797f r25562:30716ba6a396 r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r18969:91e591a12593 r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r18245:fb370bf5a3c0 r25562:30716ba6a396 r25428:48f543d34f61 r11345:85f52e96797f r23512:89adada9c9f0 r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r15610:623a23fb6560 r15610:623a23fb6560 r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r13057:58af81fcdcf8 r13057:58af81fcdcf8 r11345:85f52e96797f r26095:00c14d52e378 r11345:85f52e96797f r11944:3b8f9f948e8d r23607:36c15679007d r26082:ed4b80b7fdde r11345:85f52e96797f r11345:85f52e96797f r25562:30716ba6a396 r16672:c10913372b81 r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r24214:a65c412aafcc r18969:91e591a12593 r11345:85f52e96797f r12381:5e06b887e97b r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r23514:44f7e602e9c5 r23942:2580b984b22e r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r14220:2b66d13ca715 r26097:38be59df2287 r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r26097:38be59df2287 r11345:85f52e96797f r26097:38be59df2287 r11345:85f52e96797f r14220:2b66d13ca715 r14220:2b66d13ca715 r14220:2b66d13ca715 r14220:2b66d13ca715 r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r11345:85f52e96797f r26092:d96f469449f6 r11345:85f52e96797f | /*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file signs_cmd.cpp Handling of sign related commands. */
#include "stdafx.h"
#include "landscape.h"
#include "company_func.h"
#include "signs_base.h"
#include "signs_func.h"
#include "command_func.h"
#include "tilehighlight_func.h"
#include "viewport_kdtree.h"
#include "window_func.h"
#include "string_func.h"
#include "signs_cmd.h"
#include "table/strings.h"
#include "safeguards.h"
/** The last built sign. */
SignID _new_sign_id;
/**
* 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 p1 unused
* @param p2 unused
* @param text unused
* @return the cost of this operation or an error
*/
CommandCost CmdPlaceSign(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
{
/* Try to locate a new sign */
if (!Sign::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_SIGNS);
/* Check sign text length if any */
if (Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return CMD_ERROR;
/* When we execute, really make the sign */
if (flags & DC_EXEC) {
Sign *si = new Sign(_game_mode == GM_EDITOR ? OWNER_DEITY : _current_company);
int x = TileX(tile) * TILE_SIZE;
int y = TileY(tile) * TILE_SIZE;
si->x = x;
si->y = y;
si->z = GetSlopePixelZ(x, y);
if (!text.empty()) {
si->name = text;
}
si->UpdateVirtCoord();
InvalidateWindowData(WC_SIGN_LIST, 0, 0);
_new_sign_id = si->index;
}
return CommandCost();
}
/**
* Rename a sign. If the new name of the sign is empty, we assume
* the user wanted to delete it. So delete it. Ownership of signs
* has no meaning/effect whatsoever except for eyecandy
* @param tile unused
* @param flags type of operation
* @param p1 index of the sign to be renamed/removed
* @param p2 unused
* @param text the new name or an empty string when resetting to the default
* @return the cost of this operation or an error
*/
CommandCost CmdRenameSign(DoCommandFlag flags, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
{
Sign *si = Sign::GetIfValid(p1);
if (si == nullptr) return CMD_ERROR;
if (!CompanyCanRenameSign(si)) return CMD_ERROR;
/* Rename the signs when empty, otherwise remove it */
if (!text.empty()) {
if (Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return CMD_ERROR;
if (flags & DC_EXEC) {
/* Assign the new one */
si->name = text;
if (_game_mode != GM_EDITOR) si->owner = _current_company;
si->UpdateVirtCoord();
InvalidateWindowData(WC_SIGN_LIST, 0, 1);
}
} else { // Delete sign
if (flags & DC_EXEC) {
si->sign.MarkDirty();
if (si->sign.kdtree_valid) _viewport_sign_kdtree.Remove(ViewportSignKdtreeItem::MakeSign(si->index));
delete si;
InvalidateWindowData(WC_SIGN_LIST, 0, 0);
}
}
return CommandCost();
}
/**
* Callback function that is called after a sign is placed
* @param result of the operation
* @param cmd unused
* @param tile unused
* @param p1 unused
* @param p2 unused
* @param text unused
*/
void CcPlaceSign(const CommandCost &result, Commands cmd, TileIndex tile, uint32 p1, uint32 p2, const std::string &text)
{
if (result.Failed()) return;
ShowRenameSignWindow(Sign::Get(_new_sign_id));
ResetObjectToPlace();
}
/**
*
* PlaceProc function, called when someone pressed the button if the
* sign-tool is selected
* @param tile on which to place the sign
*/
void PlaceProc_Sign(TileIndex tile)
{
DoCommandP(CMD_PLACE_SIGN, STR_ERROR_CAN_T_PLACE_SIGN_HERE, CcPlaceSign, tile, 0, 0);
}
|