signs_cmd.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013 #include "landscape.h"
00014 #include "company_func.h"
00015 #include "signs_base.h"
00016 #include "signs_func.h"
00017 #include "command_func.h"
00018 #include "tilehighlight_func.h"
00019 #include "window_func.h"
00020 #include "string_func.h"
00021
00022 #include "table/strings.h"
00023
00024 SignID _new_sign_id;
00025
00037 CommandCost CmdPlaceSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
00038 {
00039
00040 if (!Sign::CanAllocateItem()) return_cmd_error(STR_ERROR_TOO_MANY_SIGNS);
00041
00042
00043 if (!StrEmpty(text) && Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return CMD_ERROR;
00044
00045
00046 if (flags & DC_EXEC) {
00047 Sign *si = new Sign(_current_company);
00048 int x = TileX(tile) * TILE_SIZE;
00049 int y = TileY(tile) * TILE_SIZE;
00050
00051 si->x = x;
00052 si->y = y;
00053 si->z = GetSlopeZ(x, y);
00054 if (!StrEmpty(text)) {
00055 si->name = strdup(text);
00056 }
00057 si->UpdateVirtCoord();
00058 InvalidateWindowData(WC_SIGN_LIST, 0, 0);
00059 _new_sign_id = si->index;
00060 }
00061
00062 return CommandCost();
00063 }
00064
00076 CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
00077 {
00078 Sign *si = Sign::GetIfValid(p1);
00079 if (si == NULL) return CMD_ERROR;
00080
00081
00082 if (!StrEmpty(text)) {
00083 if (Utf8StringLength(text) >= MAX_LENGTH_SIGN_NAME_CHARS) return CMD_ERROR;
00084
00085 if (flags & DC_EXEC) {
00086
00087 free(si->name);
00088
00089 si->name = strdup(text);
00090 si->owner = _current_company;
00091
00092 si->UpdateVirtCoord();
00093 InvalidateWindowData(WC_SIGN_LIST, 0, 1);
00094 }
00095 } else {
00096 if (flags & DC_EXEC) {
00097 si->sign.MarkDirty();
00098 delete si;
00099
00100 InvalidateWindowData(WC_SIGN_LIST, 0, 0);
00101 }
00102 }
00103
00104 return CommandCost();
00105 }
00106
00114 void CcPlaceSign(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2)
00115 {
00116 if (result.Failed()) return;
00117
00118 ShowRenameSignWindow(Sign::Get(_new_sign_id));
00119 ResetObjectToPlace();
00120 }
00121
00128 void PlaceProc_Sign(TileIndex tile)
00129 {
00130 DoCommandP(tile, 0, 0, CMD_PLACE_SIGN | CMD_MSG(STR_ERROR_CAN_T_PLACE_SIGN_HERE), CcPlaceSign);
00131 }