mirror of
https://github.com/cxong/cdogs-sdl.git
synced 2025-07-23 07:23:01 +02:00
Load weapons/ammo from autosave
This commit is contained in:
@@ -47,12 +47,6 @@
|
||||
|
||||
Autosave gAutosave;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *Guns[MAX_WEAPONS];
|
||||
CArray ammo; // of int
|
||||
} PlayerSave;
|
||||
static void PlayerSaveInit(PlayerSave *ps)
|
||||
{
|
||||
memset(ps, 0, sizeof *ps);
|
||||
@@ -172,16 +166,7 @@ static void AddPlayersNode(CArray *players, json_t *root)
|
||||
json_insert_child(gunsNode, json_new_string(ps->Guns[i] != NULL ? ps->Guns[i] : ""));
|
||||
}
|
||||
json_insert_pair_into_object(playerNode, "Guns", gunsNode);
|
||||
|
||||
json_t *ammoNode = json_new_array();
|
||||
for (int i = 0; i < (int)ps->ammo.size; i++)
|
||||
{
|
||||
const int *ammop = CArrayGet(&ps->ammo, i);
|
||||
char buf[256];
|
||||
sprintf(buf, "%d", *ammop);
|
||||
json_insert_child(ammoNode, json_new_string(buf));
|
||||
}
|
||||
json_insert_pair_into_object(playerNode, "Ammo", ammoNode);
|
||||
AddIntArray(playerNode, "Ammo", &ps->ammo);
|
||||
|
||||
json_insert_child(playersNode, playerNode);
|
||||
CA_FOREACH_END()
|
||||
|
@@ -36,6 +36,11 @@
|
||||
|
||||
#define AUTOSAVE_FILE "autosave.json"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char *Guns[MAX_WEAPONS];
|
||||
CArray ammo; // of int
|
||||
} PlayerSave;
|
||||
typedef struct
|
||||
{
|
||||
CampaignEntry Campaign;
|
||||
|
15
src/prep.c
15
src/prep.c
@@ -325,6 +325,8 @@ GameLoopData *PlayerSelection(void)
|
||||
GetDataFilePath(data->suffixes, "data/suffixes.txt");
|
||||
GetDataFilePath(data->suffixnames, "data/suffixnames.txt");
|
||||
NameGenInit(&data->g, data->prefixes, data->suffixes, data->suffixnames);
|
||||
|
||||
const CampaignSave *cs = AutosaveGetCampaign(&gAutosave, gCampaign.Entry.Path);
|
||||
|
||||
// Create selection menus for each local player
|
||||
for (int i = 0, idx = 0; i < (int)gPlayerDatas.size; i++, idx++)
|
||||
@@ -335,6 +337,19 @@ GameLoopData *PlayerSelection(void)
|
||||
idx--;
|
||||
continue;
|
||||
}
|
||||
// Load autosaved player guns/ammo at this point
|
||||
if (cs != NULL && gCampaign.Setting.WeaponPersist && idx < (int)cs->Players.size)
|
||||
{
|
||||
const PlayerSave *ps = CArrayGet(&cs->Players, idx);
|
||||
for (int j = 0; j < MAX_WEAPONS; j++)
|
||||
{
|
||||
if (ps->Guns[j] != NULL)
|
||||
{
|
||||
p->guns[j] = StrWeaponClass(ps->Guns[j]);
|
||||
}
|
||||
}
|
||||
CArrayCopy(&p->ammo, &ps->ammo);
|
||||
}
|
||||
PlayerSelectMenusCreate(
|
||||
&data->menus[idx], GetNumPlayers(PLAYER_ANY, false, true), idx,
|
||||
p->UID, &gEventHandlers, &gGraphicsDevice, &data->g);
|
||||
|
Reference in New Issue
Block a user