signs_cmd.cpp
Go to the documentation of this file.00001
00002
00005 #include "stdafx.h"
00006 #include "landscape.h"
00007 #include "company_func.h"
00008 #include "signs_base.h"
00009 #include "signs_func.h"
00010 #include "command_func.h"
00011 #include "tilehighlight_func.h"
00012 #include "window_func.h"
00013 #include "map_func.h"
00014 #include "string_func.h"
00015
00016 #include "table/strings.h"
00017
00018 SignID _new_sign_id;
00019
00029 CommandCost CmdPlaceSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
00030 {
00031
00032 if (!Sign::CanAllocateItem()) return_cmd_error(STR_2808_TOO_MANY_SIGNS);
00033
00034
00035 if (!StrEmpty(text) && strlen(text) >= MAX_LENGTH_SIGN_NAME_BYTES) return CMD_ERROR;
00036
00037
00038 if (flags & DC_EXEC) {
00039 Sign *si = new Sign(_current_company);
00040 int x = TileX(tile) * TILE_SIZE;
00041 int y = TileY(tile) * TILE_SIZE;
00042
00043 si->x = x;
00044 si->y = y;
00045 si->z = GetSlopeZ(x, y);
00046 if (!StrEmpty(text)) {
00047 si->name = strdup(text);
00048 }
00049 UpdateSignVirtCoords(si);
00050 MarkSignDirty(si);
00051 InvalidateWindowData(WC_SIGN_LIST, 0, 0);
00052 _new_sign_id = si->index;
00053 }
00054
00055 return CommandCost();
00056 }
00057
00067 CommandCost CmdRenameSign(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
00068 {
00069 if (!IsValidSignID(p1)) return CMD_ERROR;
00070
00071
00072 if (!StrEmpty(text)) {
00073 if (strlen(text) >= MAX_LENGTH_SIGN_NAME_BYTES) return CMD_ERROR;
00074
00075 if (flags & DC_EXEC) {
00076 Sign *si = GetSign(p1);
00077
00078
00079 free(si->name);
00080
00081 si->name = strdup(text);
00082 si->owner = _current_company;
00083
00084
00085 MarkSignDirty(si);
00086 UpdateSignVirtCoords(si);
00087 MarkSignDirty(si);
00088 InvalidateWindowData(WC_SIGN_LIST, 0, 1);
00089 }
00090 } else {
00091 if (flags & DC_EXEC) {
00092 Sign *si = GetSign(p1);
00093
00094 MarkSignDirty(si);
00095 delete si;
00096
00097 InvalidateWindowData(WC_SIGN_LIST, 0, 0);
00098 }
00099 }
00100
00101 return CommandCost();
00102 }
00103
00111 void CcPlaceSign(bool success, TileIndex tile, uint32 p1, uint32 p2)
00112 {
00113 if (success) {
00114 ShowRenameSignWindow(GetSign(_new_sign_id));
00115 ResetObjectToPlace();
00116 }
00117 }
00118
00125 void PlaceProc_Sign(TileIndex tile)
00126 {
00127 DoCommandP(tile, 0, 0, CMD_PLACE_SIGN | CMD_MSG(STR_2809_CAN_T_PLACE_SIGN_HERE), CcPlaceSign);
00128 }