Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
captainurist committed Sep 19, 2023
1 parent 4936009 commit 0c35ec9
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 15 deletions.
7 changes: 6 additions & 1 deletion src/Application/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2000,8 +2000,13 @@ void Game::gameLoop() {
if (!pEventTimer->bPaused && uGameState == GAME_STATE_PLAYING) {
onTimer();

if (!pEventTimer->bTackGameTime)
if (!pEventTimer->bTackGameTime) {
_494035_timed_effects__water_walking_damage__etc();
} else {
// Need to process party death in turn-based mode.
maybeWakeSoloSurvivor();
updatePartyDeathState();
}

if (dword_6BE364_game_settings_1 & GAME_SETTINGS_SKIP_WORLD_UPDATE) {
dword_6BE364_game_settings_1 &= ~GAME_SETTINGS_SKIP_WORLD_UPDATE;
Expand Down
38 changes: 24 additions & 14 deletions src/Engine/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,20 +1444,8 @@ void _494035_timed_effects__water_walking_damage__etc() {
}
}

if (!numPlayersCouldAct) {
if (current_screen_type != SCREEN_REST) {
for (Character &character : pParty->pCharacters) {
// if someone is sleeping - wake them up
if (character.conditions.Has(CONDITION_SLEEP)) {
character.conditions.Reset(CONDITION_SLEEP);
numPlayersCouldAct = 1;
break;
}
}
if (!numPlayersCouldAct)
uGameState = GAME_STATE_PARTY_DIED;
}
}
maybeWakeSoloSurvivor();
updatePartyDeathState();

if (pParty->hasActiveCharacter()) {
if (current_screen_type != SCREEN_REST) {
Expand All @@ -1468,6 +1456,28 @@ void _494035_timed_effects__water_walking_damage__etc() {
}
}

void maybeWakeSoloSurvivor() {
if (current_screen_type == SCREEN_REST)
return;

if (pParty->canActCount() != 0)
return;

// Try waking up a single character.
for (Character &character : pParty->pCharacters) {
if (character.conditions.Has(CONDITION_SLEEP)) {
character.conditions.Reset(CONDITION_SLEEP);
pParty->setActiveToFirstCanAct();
break;
}
}
}

void updatePartyDeathState() {
if (current_screen_type != SCREEN_REST && pParty->canActCount() == 0)
uGameState = GAME_STATE_PARTY_DIED;
}

void RegeneratePartyHealthMana() {
constexpr int MINUTES_BETWEEN_REGEN = 5;
int cur_minutes = pParty->GetPlayingTime().GetMinutes();
Expand Down
2 changes: 2 additions & 0 deletions src/Engine/Engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ void setFacesBit(int sCogNumber, FaceAttribute bit, int on);
*/
void setDecorationSprite(uint16_t uCog, bool bHide, const std::string &pFileName); // idb
void _494035_timed_effects__water_walking_damage__etc();
void maybeWakeSoloSurvivor();
void updatePartyDeathState();

/**
* Modify party health or mana based on party or players conditions/buffs.
Expand Down
7 changes: 7 additions & 0 deletions src/Engine/Party.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,13 @@ bool Party::_497FC5_check_party_perception_against_level() {
return result;
}

int Party::canActCount() const {
int result = 0;
for (const Character &character : pCharacters)
result += character.CanAct();
return result;
}

void Party::setHoldingItem(ItemGen *pItem) {
placeHeldItemInInventoryOrDrop();
pPickedItem = *pItem;
Expand Down
5 changes: 5 additions & 0 deletions src/Engine/Party.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ struct Party {
void switchToNextActiveCharacter();
bool _497FC5_check_party_perception_against_level();

/**
* @return Total number of characters who can act.
*/
int canActCount() const;

/**
* @offset 0x48C6F6
*/
Expand Down

0 comments on commit 0c35ec9

Please sign in to comment.