mirror of
https://github.com/yquake2/rogue.git
synced 2024-11-22 12:21:44 +00:00
Save gclient_t::resp.coop_respawn.*weapon to fix coop savegames
This fixed bug #357 - the problem was that client->resp.coop_respawn.weapon and .lastweapon (pointers to gitem) were not properly initialized when loading a savegame. Now those fields are saved (=> we had to bump the savegame version) and for old savegames client->resp.coop_rewspawn is initialized from client->pers, as a hack for backwards-compatibility.
This commit is contained in:
parent
1f82ad2154
commit
063776d504
4 changed files with 41 additions and 5 deletions
|
@ -663,6 +663,7 @@ typedef struct
|
|||
int ofs;
|
||||
fieldtype_t type;
|
||||
int flags;
|
||||
short save_ver;
|
||||
} field_t;
|
||||
|
||||
extern field_t fields[];
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
* load older savegames. This should be bumped if the files
|
||||
* in tables/ are changed, otherwise strange things may happen.
|
||||
*/
|
||||
#define SAVEGAMEVER "YQ2-3"
|
||||
#define SAVEGAMEVER "YQ2-4"
|
||||
|
||||
/*
|
||||
* This macros are used to prohibit loading of savegames
|
||||
|
@ -722,16 +722,24 @@ WriteClient(FILE *f, gclient_t *client)
|
|||
* Read the client struct from a file
|
||||
*/
|
||||
void
|
||||
ReadClient(FILE *f, gclient_t *client)
|
||||
ReadClient(FILE *f, gclient_t *client, short save_ver)
|
||||
{
|
||||
field_t *field;
|
||||
|
||||
fread(client, sizeof(*client), 1, f);
|
||||
|
||||
for (field = clientfields; field->name; field++)
|
||||
{
|
||||
if (field->save_ver <= save_ver)
|
||||
{
|
||||
ReadField(f, field, (byte *)client);
|
||||
}
|
||||
}
|
||||
|
||||
if (save_ver < 3)
|
||||
{
|
||||
InitClientResp(client);
|
||||
}
|
||||
}
|
||||
|
||||
/* ========================================================= */
|
||||
|
@ -810,6 +818,7 @@ ReadGame(const char *filename)
|
|||
char str_game[32];
|
||||
char str_os[32];
|
||||
char str_arch[32];
|
||||
short save_ver;
|
||||
|
||||
gi.FreeTags(TAG_GAME);
|
||||
|
||||
|
@ -828,6 +837,28 @@ ReadGame(const char *filename)
|
|||
|
||||
if (!strcmp(str_ver, SAVEGAMEVER))
|
||||
{
|
||||
save_ver = 4;
|
||||
|
||||
if (strcmp(str_game, GAMEVERSION))
|
||||
{
|
||||
fclose(f);
|
||||
gi.error("Savegame from an other game.so.\n");
|
||||
}
|
||||
else if (strcmp(str_os, OSTYPE))
|
||||
{
|
||||
fclose(f);
|
||||
gi.error("Savegame from an other os.\n");
|
||||
}
|
||||
else if (strcmp(str_arch, ARCH))
|
||||
{
|
||||
fclose(f);
|
||||
gi.error("Savegame from an other architecure.\n");
|
||||
}
|
||||
}
|
||||
else if (!strcmp(str_ver, "YQ2-3"))
|
||||
{
|
||||
save_ver = 3;
|
||||
|
||||
if (strcmp(str_game, GAMEVERSION))
|
||||
{
|
||||
fclose(f);
|
||||
|
@ -846,6 +877,8 @@ ReadGame(const char *filename)
|
|||
}
|
||||
else if (!strcmp(str_ver, "YQ2-2"))
|
||||
{
|
||||
save_ver = 2;
|
||||
|
||||
if (strcmp(str_game, GAMEVERSION))
|
||||
{
|
||||
fclose(f);
|
||||
|
@ -890,7 +923,7 @@ ReadGame(const char *filename)
|
|||
|
||||
for (i = 0; i < game.maxclients; i++)
|
||||
{
|
||||
ReadClient(f, &game.clients[i]);
|
||||
ReadClient(f, &game.clients[i], save_ver);
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
|
|
@ -10,4 +10,6 @@
|
|||
{"pers.lastweapon", CLOFS(pers.lastweapon), F_ITEM},
|
||||
{"newweapon", CLOFS(newweapon), F_ITEM},
|
||||
{"owned_sphere", CLOFS(owned_sphere), F_EDICT},
|
||||
{"resp.coop_respawn.weapon", CLOFS(resp.coop_respawn.weapon), F_ITEM, 0, 4},
|
||||
{"resp.coop_respawn.lastweapon", CLOFS(resp.coop_respawn.lastweapon), F_ITEM, 0, 4},
|
||||
{NULL, 0, F_INT}
|
||||
|
|
|
@ -14,7 +14,7 @@ extern void WriteLevelLocals ( FILE * f ) ;
|
|||
extern void WriteEdict ( FILE * f , edict_t * ent ) ;
|
||||
extern void ReadGame ( const char * filename ) ;
|
||||
extern void WriteGame ( const char * filename , qboolean autosave ) ;
|
||||
extern void ReadClient ( FILE * f , gclient_t * client ) ;
|
||||
extern void ReadClient ( FILE * f , gclient_t * client , short save_ver ) ;
|
||||
extern void WriteClient ( FILE * f , gclient_t * client ) ;
|
||||
extern void ReadField ( FILE * f , field_t * field , byte * base ) ;
|
||||
extern void WriteField2 ( FILE * f , field_t * field , byte * base ) ;
|
||||
|
|
Loading…
Reference in a new issue