Skip to content

Commit

Permalink
NWN2: Load the creature's skill ranks
Browse files Browse the repository at this point in the history
  • Loading branch information
rjshae authored and DrMcCoy committed Feb 2, 2019
1 parent 35509ba commit 886a680
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
43 changes: 24 additions & 19 deletions src/engines/nwn2/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,25 +474,12 @@ void Creature::loadProperties(const Aurora::GFF3Struct &gff) {
loadLevelStats(gff, _levels);
}

// Skills
// TODO: Process multiple "SkillList" blocks
if (gff.hasField("SkillList")) {
_skills.clear();

const Aurora::GFF3List &skills = gff.getList("SkillList");
for (Aurora::GFF3List::const_iterator s = skills.begin(); s != skills.end(); ++s) {
const Aurora::GFF3Struct &skill = **s;

_skills.push_back(skill.getSint("Rank"));
}
}

// Get total skill ranks
uint32 skill = 0;
for (std::vector<int8>::iterator it = _skills.begin(); it != _skills.end(); ++it) {
_ranks[skill] += *it;
skill = (skill + 1) % kSkillMAX;
}
/**
* The 'SkillsList' under the top level is a cumulative list of
* skill ranks for the creature. The 'LvlStatList' has 'SkillsList'
* arrays for the individual levels and those are stored separately.
*/
loadSkills(gff, _ranks);

// Feats
// TODO: Process multiple "FeatList" blocks
Expand Down Expand Up @@ -599,6 +586,24 @@ void Creature::loadLevelStats(const Aurora::GFF3Struct &gff,
} else {
levelStats.back().ability = kAbilityMAX; // Set to an invalid ability
}

// Skill ranks
loadSkills(cLevelStats, levelStats.back().ranks);
}
}

void Creature::loadSkills(const Aurora::GFF3Struct &gff,
uint8 ranks[]) {

if (!gff.hasField("SkillList"))
return;

uint32 i = 0;
const Aurora::GFF3List &skills = gff.getList("SkillList");
for (Aurora::GFF3List::const_iterator s = skills.begin(); s != skills.end(); ++s) {
const Aurora::GFF3Struct &skill = **s;

ranks[i++] = skill.getSint("Rank");
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/engines/nwn2/creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ class Creature : public Object {

std::vector<Class> _classes; ///< The creature's classes.
std::vector<LevelStats> _levels; ///< Level data for the creature.
std::vector<int8> _skills; ///< The creature's skills.
Common::ScopedPtr<Feats> _feats; ///< The creature's feats.

uint8 _ranks[kSkillMAX]; ///< Total skill ranks across levels.
Expand Down Expand Up @@ -244,6 +243,10 @@ class Creature : public Object {
static void loadLevelStats(const Aurora::GFF3Struct &gff,
std::vector<LevelStats> &levelStats);

/** Load the creature's skill ranks. */
static void loadSkills(const Aurora::GFF3Struct &gff,
uint8 ranks[]);

// Model loaders

Common::UString getBaseModel(const Common::UString &base);
Expand Down

0 comments on commit 886a680

Please sign in to comment.