From d439221c62fb6dc95192c68659fd68e4a85f60a2 Mon Sep 17 00:00:00 2001 From: dominik Date: Tue, 25 Jan 2005 15:38:36 +0000 Subject: (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) --- main_gui.c | 2 +- saveload.c | 3 +++ signs.c | 13 ++++++++----- signs.h | 2 ++ ttd.c | 14 ++++++++++++++ viewport.c | 2 +- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/main_gui.c b/main_gui.c index c5ba8073c..6deba6f1e 100644 --- a/main_gui.c +++ b/main_gui.c @@ -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) diff --git a/saveload.c b/saveload.c index deeedbb8c..a37b40724 100644 --- a/saveload.c +++ b/saveload.c @@ -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, diff --git a/signs.c b/signs.c index c21e99c7b..a8f65ca51 100644 --- a/signs.c +++ b/signs.c @@ -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() }; diff --git a/signs.h b/signs.h index fd8ba206c..98934ef78 100644 --- a/signs.h +++ b/signs.h @@ -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; diff --git a/ttd.c b/ttd.c index 70e8e6722..f86c00e27 100644 --- a/ttd.c +++ b/ttd.c @@ -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 diff --git a/viewport.c b/viewport.c index 78ac0fda3..b4e86d0e5 100644 --- a/viewport.c +++ b/viewport.c @@ -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]; } } } -- cgit v1.2.3-70-g09d2