Skip to content

Commit

Permalink
Fix lives going to 0 when replaying first mission
Browse files Browse the repository at this point in the history
  • Loading branch information
cxong committed Dec 9, 2023
1 parent 8164233 commit ad639e1
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/prep_equip.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
C-Dogs SDL
A port of the legendary (and fun) action/arcade cdogs.
Copyright (c) 2013-2018, 2020-2022 Cong Xu
Copyright (c) 2013-2018, 2020-2023 Cong Xu
All rights reserved.
Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -31,6 +31,7 @@
#include <cdogs/net_server.h>
#include <cdogs/player.h>

#include "autosave.h"
#include "prep.h"
#include "equip_menu.h"

Expand All @@ -51,6 +52,12 @@ GameLoopData *PlayerEquip(void)
{
PlayerEquipData *data;
CCALLOC(data, sizeof *data);
const CampaignSave *save = AutosaveGetCampaign(&gAutosave, gCampaign.Entry.Path);
const Mission *m = CampaignGetCurrentMission(&gCampaign);
if (save != NULL && gCampaign.MissionIndex > 0)
{
PlayerSavesApply(&save->Players, m->WeaponPersist);
}
data->waitResult = EVENT_WAIT_CONTINUE;
for (int i = 0, idx = 0; i < (int)gPlayerDatas.size; i++, idx++)
{
Expand Down Expand Up @@ -90,6 +97,14 @@ GameLoopData *PlayerEquip(void)
&gCampaign.Setting.Missions, gCampaign.MissionIndex - 1);
prevWeapons = &prevMission->Weapons;
}

// Special case: reset player lives
// Player.Lives is modified dynamically in game, so if we
// are replaying, we need to reset if we have no player save
if (save == NULL || gCampaign.MissionIndex == 0)
{
p->Lives = CampaignGetLives(&gCampaign);
}

EquipMenuCreate(
&data->menus[idx], &weapons, prevWeapons,
Expand Down

0 comments on commit ad639e1

Please sign in to comment.