(svn r1667) - Feature: Signs are now shown in the color of the player who created them

(Note: The player information is currently not stored in savegames. Upon loading a game the signs will all be gray again)
This commit is contained in:
dominik 2005-01-25 15:38:36 +00:00
parent 03ba24dd65
commit d439221c62
6 changed files with 29 additions and 7 deletions

View File

@ -70,7 +70,7 @@ void HandleOnEditText(WindowEvent *e) {
switch(_rename_what) {
case 0:
// for empty string send "remove sign" parameter
DoCommandP(0, id, (*b==0)?1:0, NULL, CMD_RENAME_SIGN | CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME));
DoCommandP(0, id, (*b==0)?OWNER_NONE:_current_player, NULL, CMD_RENAME_SIGN | CMD_MSG(STR_280C_CAN_T_CHANGE_SIGN_NAME));
break;
case 1:
if(*b == 0)

View File

@ -6,6 +6,9 @@
#include "player.h"
#include "saveload.h"
/* TODO when upgrading to version 6.0:
* - uncomment "SLE_CONDVAR(SignStruct,owner..." in _sign_desc (signs.c) */
enum {
SAVEGAME_MAJOR_VERSION = 5,
SAVEGAME_MINOR_VERSION = 2,

13
signs.c
View File

@ -67,7 +67,7 @@ static SignStruct *AllocateSign(void)
*
* Place a sign at the given x/y
*
* @param p1 not used
* @param p1 player number
* @param p2 not used
*/
int32 CmdPlaceSign(int x, int y, uint32 flags, uint32 p1, uint32 p2)
@ -84,6 +84,7 @@ int32 CmdPlaceSign(int x, int y, uint32 flags, uint32 p1, uint32 p2)
ss->str = STR_280A_SIGN;
ss->x = x;
ss->y = y;
ss->owner = p1;
ss->z = GetSlopeZ(x,y);
UpdateSignVirtCoords(ss);
MarkSignDirty(ss);
@ -97,15 +98,15 @@ int32 CmdPlaceSign(int x, int y, uint32 flags, uint32 p1, uint32 p2)
* Rename a sign
*
* @param sign_id Index of the sign
* @param remove If 1, sign will be removed
* @param new owner, if OWNER_NONE, sign will be removed
*/
int32 CmdRenameSign(int x, int y, uint32 flags, uint32 sign_id, uint32 remove)
int32 CmdRenameSign(int x, int y, uint32 flags, uint32 sign_id, uint32 owner)
{
StringID str;
SignStruct *ss;
/* If GetDParam(0) == nothing, we delete the sign */
if (GetDParam(0) != 0 && remove != 1) {
if (GetDParam(0) != 0 && owner != OWNER_NONE) {
/* Create the name */
str = AllocateName((byte*)_decode_parameters, 0);
if (str == 0)
@ -120,6 +121,7 @@ int32 CmdRenameSign(int x, int y, uint32 flags, uint32 sign_id, uint32 remove)
DeleteName(ss->str);
/* Assign the new one */
ss->str = str;
ss->owner = owner;
/* Update */
UpdateSignVirtCoords(ss);
@ -165,7 +167,7 @@ void CcPlaceSign(bool success, uint tile, uint32 p1, uint32 p2)
*/
void PlaceProc_Sign(uint tile)
{
DoCommandP(tile, 0, 0, CcPlaceSign, CMD_PLACE_SIGN | CMD_MSG(STR_2809_CAN_T_PLACE_SIGN_HERE));
DoCommandP(tile, _current_player, 0, CcPlaceSign, CMD_PLACE_SIGN | CMD_MSG(STR_2809_CAN_T_PLACE_SIGN_HERE));
}
/**
@ -191,6 +193,7 @@ static const byte _sign_desc[] = {
SLE_CONDVAR(SignStruct,y, SLE_FILE_I16 | SLE_VAR_I32, 0, 4),
SLE_CONDVAR(SignStruct,x, SLE_INT32, 5, 255),
SLE_CONDVAR(SignStruct,y, SLE_INT32, 5, 255),
// SLE_CONDVAR(SignStruct,owner, SLE_INT32, 6, 255), // TODO: uncomment this after the savegame bump to version 6.0
SLE_VAR(SignStruct,z, SLE_UINT8),
SLE_END()
};

View File

@ -7,6 +7,8 @@ typedef struct SignStruct {
int32 x;
int32 y;
byte z;
byte owner; // placed by this player. Anyone can delete them though.
// OWNER_NONE for gray signs from old games.
uint16 index;
} SignStruct;

14
ttd.c
View File

@ -1269,6 +1269,15 @@ static void UpdateVoidTiles(void)
memset(_map_type_and_height + MapMaxY() * MapSizeX(), MP_VOID << 4, MapSizeX());
}
// since savegame version 6.0 each sign has an "owner", signs without owner (from old games are set to 255)
static void UpdateSignOwner(void)
{
SignStruct *ss;
FOR_ALL_SIGNS(ss) {
ss->owner = OWNER_NONE; // no owner
}
}
extern void UpdateOldAircraft( void );
extern void UpdateOilRig( void );
@ -1292,6 +1301,11 @@ bool AfterLoadGame(uint version)
UpdateCurrencies();
}
// from version 6.0 of the savegame, signs have an "owner"
if (version <= 0x600) {
UpdateSignOwner();
}
/* In old version there seems to be a problem that water is owned by
OWNER_NONE, not OWNER_WATER.. I can't replicate it for the current
(0x402) version, so I just check when versions are older, and then

View File

@ -930,7 +930,7 @@ static void ViewportAddSigns(DrawPixelInfo *dpi)
sstd=AddStringToDraw(ss->sign.left + 1, ss->sign.top + 1, STR_2806, ss->str, 0, 0);
if (sstd != NULL) {
sstd->width = ss->sign.width_1;
sstd->color = 14;
sstd->color = (ss->owner==OWNER_NONE)?14:_player_colors[ss->owner];
}
}
}