Skip to content

Commit

Permalink
Add critical hits improvements (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbatalov committed Aug 2, 2022
1 parent df5bcea commit 63bcb2d
Show file tree
Hide file tree
Showing 7 changed files with 342 additions and 17 deletions.
295 changes: 293 additions & 2 deletions src/combat.cc

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions src/combat.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ int _combat_explode_scenery(Object* a1, Object* a2);
void _combat_delete_critter(Object* obj);
void _combatKillCritterOutsideCombat(Object* critter_obj, char* msg);

int criticalsGetValue(int killType, int hitLocation, int effect, int dataMember);
void criticalsSetValue(int killType, int hitLocation, int effect, int dataMember, int value);
void criticalsResetValue(int killType, int hitLocation, int effect, int dataMember);

static inline bool isInCombat()
{
return (gCombatState & COMBAT_STATE_0x01) != 0;
Expand Down
42 changes: 29 additions & 13 deletions src/combat_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,41 @@ typedef struct Attack {
int extrasKnockback[EXPLOSION_TARGET_COUNT];
} Attack;

typedef enum CriticalHitDescriptionDataMember {
CRIT_DATA_MEMBER_DAMAGE_MULTIPLIER,
CRIT_DATA_MEMBER_FLAGS,
CRIT_DATA_MEMBER_MASSIVE_CRITICAL_STAT,
CRIT_DATA_MEMBER_MASSIVE_CRITICAL_STAT_MODIFIER,
CRIT_DATA_MEMBER_MASSIVE_CRITICAL_FLAGS,
CRIT_DATA_MEMBER_MESSAGE_ID,
CRIT_DATA_MEMBER_MASSIVE_CRITICAL_MESSAGE_ID,
CRIT_DATA_MEMBER_COUNT,
} CriticalHitDescriptionDataMember;

// Provides metadata about critical hit effect.
typedef struct CriticalHitDescription {
int damageMultiplier;
typedef union CriticalHitDescription {
struct {
int damageMultiplier;

// Damage flags that will be applied to defender.
int flags;

// Damage flags that will be applied to defender.
int flags;
// Stat to check to upgrade this critical hit to massive critical hit or
// -1 if there is no massive critical hit.
int massiveCriticalStat;

// Stat to check to upgrade this critical hit to massive critical hit or
// -1 if there is no massive critical hit.
int massiveCriticalStat;
// Bonus/penalty to massive critical stat.
int massiveCriticalStatModifier;

// Bonus/penalty to massive critical stat.
int massiveCriticalStatModifier;
// Additional damage flags if this critical hit become massive critical.
int massiveCriticalFlags;

// Additional damage flags if this critical hit become massive critical.
int massiveCriticalFlags;
int messageId;
int massiveCriticalMessageId;
};

int messageId;
int massiveCriticalMessageId;
// SFALL: Allow indexed access to the data above.
int values[CRIT_DATA_MEMBER_COUNT];
} CriticalHitDescription;

#endif /* COMBAT_DEFS_H */
5 changes: 5 additions & 0 deletions src/proto_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ enum {
KILL_TYPE_GIANT_ANT,
KILL_TYPE_BIG_BAD_BOSS,
KILL_TYPE_COUNT,

// Sfall has the option to treat kill type numbers as shorts, thus doubling
// number of kill types it can deal with without breaking backwards
// compatibility.
SFALL_KILL_TYPE_COUNT = KILL_TYPE_COUNT * 2,
};

enum {
Expand Down
9 changes: 7 additions & 2 deletions src/random.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "debug.h"
#include "platform_compat.h"
#include "scripts.h"
#include "sfall_config.h"

#include <limits.h>
#include <stdlib.h>
Expand Down Expand Up @@ -97,11 +98,15 @@ static int randomTranslateRoll(int delta, int criticalSuccessModifier)
{
int gameTime = gameTimeGetTime();

// SFALL: Remove criticals time limits.
bool criticalsTimeLimitsRemoved = false;
configGetBool(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_REMOVE_CRITICALS_TIME_LIMITS_KEY, &criticalsTimeLimitsRemoved);

int roll;
if (delta < 0) {
roll = ROLL_FAILURE;

if ((gameTime / GAME_TIME_TICKS_PER_DAY) >= 1) {
if (criticalsTimeLimitsRemoved || (gameTime / GAME_TIME_TICKS_PER_DAY) >= 1) {
// 10% to become critical failure.
if (randomBetween(1, 100) <= -delta / 10) {
roll = ROLL_CRITICAL_FAILURE;
Expand All @@ -110,7 +115,7 @@ static int randomTranslateRoll(int delta, int criticalSuccessModifier)
} else {
roll = ROLL_SUCCESS;

if ((gameTime / GAME_TIME_TICKS_PER_DAY) >= 1) {
if (criticalsTimeLimitsRemoved || (gameTime / GAME_TIME_TICKS_PER_DAY) >= 1) {
// 10% + modifier to become critical success.
if (randomBetween(1, 100) <= delta / 10 + criticalSuccessModifier) {
roll = ROLL_CRITICAL_SUCCESS;
Expand Down
1 change: 1 addition & 0 deletions src/sfall_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ bool sfallConfigInit(int argc, char** argv)
configSetInt(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_SKIP_OPENING_MOVIES_KEY, 0);
configSetString(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_STARTING_MAP_KEY, "");
configSetBool(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_DISPLAY_KARMA_CHANGES_KEY, false);
configSetBool(&gSfallConfig, SFALL_CONFIG_MISC_KEY, SFALL_CONFIG_REMOVE_CRITICALS_TIME_LIMITS_KEY, false);

char path[COMPAT_MAX_PATH];
char* executable = argv[0];
Expand Down
3 changes: 3 additions & 0 deletions src/sfall_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#define SFALL_CONFIG_KARMA_FRMS_KEY "KarmaFRMs"
#define SFALL_CONFIG_KARMA_POINTS_KEY "KarmaPoints"
#define SFALL_CONFIG_DISPLAY_KARMA_CHANGES_KEY "DisplayKarmaChanges"
#define SFALL_CONFIG_OVERRIDE_CRITICALS_MODE_KEY "OverrideCriticalTable"
#define SFALL_CONFIG_OVERRIDE_CRITICALS_FILE_KEY "OverrideCriticalFile"
#define SFALL_CONFIG_REMOVE_CRITICALS_TIME_LIMITS_KEY "RemoveCriticalTimelimits"

extern bool gSfallConfigInitialized;
extern Config gSfallConfig;
Expand Down

0 comments on commit 63bcb2d

Please sign in to comment.