src/signs.cpp
branchNewGRF_ports
changeset 6719 4cc327ad39d5
parent 6573 7624f942237f
child 6720 35756db7e577
equal deleted inserted replaced
6718:5a8b295aa345 6719:4cc327ad39d5
     1 /* $Id$ */
     1 /* $Id$ */
       
     2 
       
     3 /** @file signs.cpp */
     2 
     4 
     3 #include "stdafx.h"
     5 #include "stdafx.h"
     4 #include "openttd.h"
     6 #include "openttd.h"
     5 #include "table/strings.h"
     7 #include "table/strings.h"
     6 #include "functions.h"
     8 #include "functions.h"
       
     9 #include "landscape.h"
     7 #include "player.h"
    10 #include "player.h"
     8 #include "signs.h"
    11 #include "signs.h"
     9 #include "saveload.h"
    12 #include "saveload.h"
    10 #include "command.h"
    13 #include "command.h"
    11 #include "variables.h"
    14 #include "variables.h"
    28 DEFINE_OLD_POOL(Sign, Sign, SignPoolNewBlock, NULL)
    31 DEFINE_OLD_POOL(Sign, Sign, SignPoolNewBlock, NULL)
    29 
    32 
    30 /**
    33 /**
    31  *
    34  *
    32  * Update the coordinate of one sign
    35  * Update the coordinate of one sign
       
    36  * @param si Pointer to the Sign
    33  *
    37  *
    34  */
    38  */
    35 static void UpdateSignVirtCoords(Sign *si)
    39 static void UpdateSignVirtCoords(Sign *si)
    36 {
    40 {
    37 	Point pt = RemapCoords(si->x, si->y, si->z);
    41 	Point pt = RemapCoords(si->x, si->y, si->z);
    58  *
    62  *
    59  * @param si Pointer to the Sign
    63  * @param si Pointer to the Sign
    60  */
    64  */
    61 static void MarkSignDirty(Sign *si)
    65 static void MarkSignDirty(Sign *si)
    62 {
    66 {
       
    67 	/* We use ZOOM_LVL_MAX here, as every viewport can have an other zoom,
       
    68 		*  and there is no way for us to know which is the biggest. So make the
       
    69 		*  biggest area dirty, and we are safe for sure. */
    63 	MarkAllViewportsDirty(
    70 	MarkAllViewportsDirty(
    64 		si->sign.left - 6,
    71 		si->sign.left - 6,
    65 		si->sign.top  - 3,
    72 		si->sign.top  - 3,
    66 		si->sign.left + si->sign.width_1 * 4 + 12,
    73 		si->sign.left + ScaleByZoom(si->sign.width_1 + 12, ZOOM_LVL_MAX),
    67 		si->sign.top  + 45);
    74 		si->sign.top  + ScaleByZoom(12, ZOOM_LVL_MAX));
    68 }
    75 }
    69 
    76 
    70 /**
    77 /**
    71  *
    78  *
    72  * Allocates a new sign
    79  * Allocates a new sign
    95 		return AllocateSign();
   102 		return AllocateSign();
    96 
   103 
    97 	return NULL;
   104 	return NULL;
    98 }
   105 }
    99 
   106 
       
   107 /**
       
   108  * Destroy a sign placed on the map
       
   109  * @param si Pointer to the Sign to remove
       
   110  */
   100 void DestroySign(Sign *si)
   111 void DestroySign(Sign *si)
   101 {
   112 {
   102 	DeleteName(si->str);
   113 	DeleteName(si->str);
   103 }
   114 }
   104 
   115 
   105 /**
   116 /**
   106  * Place a sign at the given coordinates. Ownership of sign has
   117  * Place a sign at the given coordinates. Ownership of sign has
   107  * no effect whatsoever except for the colour the sign gets for easy recognition,
   118  * no effect whatsoever except for the colour the sign gets for easy recognition,
   108  * but everybody is able to rename/remove it.
   119  * but everybody is able to rename/remove it.
   109  * @param tile tile to place sign at
   120  * @param tile tile to place sign at
       
   121  * @param flags type of operation
   110  * @param p1 unused
   122  * @param p1 unused
   111  * @param p2 unused
   123  * @param p2 unused
   112  */
   124  */
   113 int32 CmdPlaceSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   125 int32 CmdPlaceSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   114 {
   126 {
   125 
   137 
   126 		si->str = STR_280A_SIGN;
   138 		si->str = STR_280A_SIGN;
   127 		si->x = x;
   139 		si->x = x;
   128 		si->y = y;
   140 		si->y = y;
   129 		si->owner = _current_player; // owner of the sign; just eyecandy
   141 		si->owner = _current_player; // owner of the sign; just eyecandy
   130 		si->z = GetSlopeZ(x,y);
   142 		si->z = GetSlopeZ(x, y);
   131 		UpdateSignVirtCoords(si);
   143 		UpdateSignVirtCoords(si);
   132 		MarkSignDirty(si);
   144 		MarkSignDirty(si);
   133 		InvalidateWindow(WC_SIGN_LIST, 0);
   145 		InvalidateWindow(WC_SIGN_LIST, 0);
   134 		_sign_sort_dirty = true;
   146 		_sign_sort_dirty = true;
   135 		_new_sign = si;
   147 		_new_sign = si;
   140 
   152 
   141 /** Rename a sign. If the new name of the sign is empty, we assume
   153 /** Rename a sign. If the new name of the sign is empty, we assume
   142  * the user wanted to delete it. So delete it. Ownership of signs
   154  * the user wanted to delete it. So delete it. Ownership of signs
   143  * has no meaning/effect whatsoever except for eyecandy
   155  * has no meaning/effect whatsoever except for eyecandy
   144  * @param tile unused
   156  * @param tile unused
       
   157  * @param flags type of operation
   145  * @param p1 index of the sign to be renamed/removed
   158  * @param p1 index of the sign to be renamed/removed
   146  * @param p2 unused
   159  * @param p2 unused
       
   160  * @return 0 if succesfull, otherwise CMD_ERROR
   147  */
   161  */
   148 int32 CmdRenameSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   162 int32 CmdRenameSign(TileIndex tile, uint32 flags, uint32 p1, uint32 p2)
   149 {
   163 {
   150 	if (!IsValidSignID(p1)) return CMD_ERROR;
   164 	if (!IsValidSignID(p1)) return CMD_ERROR;
   151 
   165 
   173 			_sign_sort_dirty = true;
   187 			_sign_sort_dirty = true;
   174 		} else {
   188 		} else {
   175 			/* Free the name, because we did not assign it yet */
   189 			/* Free the name, because we did not assign it yet */
   176 			DeleteName(str);
   190 			DeleteName(str);
   177 		}
   191 		}
   178 	} else { /* Delete sign */
   192 	} else { // Delete sign
   179 		if (flags & DC_EXEC) {
   193 		if (flags & DC_EXEC) {
   180 			Sign *si = GetSign(p1);
   194 			Sign *si = GetSign(p1);
   181 
   195 
   182 			MarkSignDirty(si);
   196 			MarkSignDirty(si);
   183 			DeleteSign(si);
   197 			DeleteSign(si);
   189 
   203 
   190 	return 0;
   204 	return 0;
   191 }
   205 }
   192 
   206 
   193 /**
   207 /**
   194  *
       
   195  * Callback function that is called after a sign is placed
   208  * Callback function that is called after a sign is placed
   196  *
   209  * @param success of the operation
       
   210  * @param tile unused
       
   211  * @param p1 unused
       
   212  * @param p2 unused
   197  */
   213  */
   198 void CcPlaceSign(bool success, TileIndex tile, uint32 p1, uint32 p2)
   214 void CcPlaceSign(bool success, TileIndex tile, uint32 p1, uint32 p2)
   199 {
   215 {
   200 	if (success) {
   216 	if (success) {
   201 		ShowRenameSignWindow(_new_sign);
   217 		ShowRenameSignWindow(_new_sign);
   205 
   221 
   206 /**
   222 /**
   207  *
   223  *
   208  * PlaceProc function, called when someone pressed the button if the
   224  * PlaceProc function, called when someone pressed the button if the
   209  *  sign-tool is selected
   225  *  sign-tool is selected
   210  *
   226  * @param tile on which to place the sign
   211  */
   227  */
   212 void PlaceProc_Sign(TileIndex tile)
   228 void PlaceProc_Sign(TileIndex tile)
   213 {
   229 {
   214 	DoCommandP(tile, 0, 0, CcPlaceSign, CMD_PLACE_SIGN | CMD_MSG(STR_2809_CAN_T_PLACE_SIGN_HERE));
   230 	DoCommandP(tile, 0, 0, CcPlaceSign, CMD_PLACE_SIGN | CMD_MSG(STR_2809_CAN_T_PLACE_SIGN_HERE));
   215 }
   231 }