Skip to content

Commit

Permalink
NWN2: Check if the creature satisfies the feat requirements
Browse files Browse the repository at this point in the history
The initial version only checks the creature's ability score ranges
and feat prerequisites.
  • Loading branch information
rjshae authored and DrMcCoy committed Feb 4, 2019
1 parent 5753254 commit d724e0b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/engines/nwn2/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,8 @@ bool Creature::hasFeat(uint32 feat) const {

bool Creature::featAdd(uint32 feat, bool checkRequirements) {
if (checkRequirements) {
// TODO: Check feat requirements
if (!_feats->meetsRequirements(*this, feat))
return false;
}

// Add feat at the current hit dice
Expand Down
53 changes: 52 additions & 1 deletion src/engines/nwn2/feats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,14 @@
* Feats for a Neverwinter Nights 2 creature.
*/

#include "src/aurora/2dafile.h"
#include "src/aurora/2dareg.h"

#include "src/common/debug.h"

#include "src/engines/nwn2/types.h"
#include "src/engines/nwn2/feats.h"
#include "src/engines/nwn2/creature.h"

namespace Engines {

Expand Down Expand Up @@ -132,6 +136,53 @@ bool Feats::getHasCustomFeat(Custom feat) const {
return _hasCustomFeat[feat];
}

/** Return true only if the creature satisfies the feat requirements */
bool Feats::meetsRequirements(const Creature &creature, uint32 id) const {
static const Common::UString kFeatMinCols[] = {"MINSTR", "MINDEX", "MINCON", "MININT", "MINWIS", "MINCHA"};
static const Common::UString kFeatMaxCols[] = {"MAXSTR", "MAXDEX", "MAXCON", "MAXINT", "MAXWIS", "MAXCHA"};
static const Common::UString kFeatPrereq1 = "PREREQFEAT1", kFeatPrereq2 = "PREREQFEAT2";

// Ready the feat.2da file
const Aurora::TwoDAFile &twoDA = TwoDAReg.get2DA("feat");
const size_t count = twoDA.getRowCount();
if (id >= count)
return false;

// Load the feats row
const Aurora::TwoDARow &row = twoDA.getRow(id);

// Check the ability range
for (uint i = (uint)kAbilityStrength; i < (uint)kAbilityMAX; i++) {
// Check minimum ability
const uint16 min = row.getInt(kFeatMinCols[i]);
if (min != 0) {
const uint16 ability = creature.getAbility((Ability)i);
if (ability < min)
return false;
}

// Check maximum ability
const uint16 max = row.getInt(kFeatMaxCols[i]);
if (max != 0) {
const uint16 ability = creature.getAbility((Ability)i);
if (ability > min)
return false;
}
}

// Check feat prerequisites
const uint32 prereq1 = row.getInt(kFeatPrereq1);
if (prereq1 != 0 && !getHasFeat(prereq1))
return false;

const uint32 prereq2 = row.getInt(kFeatPrereq2);
if (prereq2 != 0 && !getHasFeat(prereq2))
return false;

// TODO: Check other feat requirements
return true;
}

/** Initialize the data */
void Feats::initParameters() {
uint i;
Expand Down Expand Up @@ -417,7 +468,7 @@ void Feats::applyFeat(const uint32 id) {
break;

case kFeatBkgdThug:
// +2 bonus on Appraise, Initiative, and Intimidate checks
// +2 bonus on Appraise, Initiative, and Intimidate checks
_skillBonus[kSkillAppraise] += 2;
_skillBonus[kSkillIntimidate] += 2;
_initBonus += 2;
Expand Down
4 changes: 4 additions & 0 deletions src/engines/nwn2/feats.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ namespace Engines {

namespace NWN2 {

class Creature;

class Feats {
public:
// Feats that need custom code
Expand Down Expand Up @@ -62,6 +64,8 @@ class Feats {

bool getHasCustomFeat(Custom feat) const;

bool meetsRequirements(const Creature &creature, uint32 id) const;

private:
struct Feat {
uint32 id;
Expand Down

0 comments on commit d724e0b

Please sign in to comment.