From 18ec0d3e656be71d7e563c1cfe9761a80d0efab3 Mon Sep 17 00:00:00 2001 From: cc9cii Date: Wed, 24 Jun 2015 21:21:35 +1000 Subject: [PATCH] Add missing files for autocalc. --- apps/opencs/model/world/npcstats.cpp | 138 +++++++++++++++++++++++++++ apps/opencs/model/world/npcstats.hpp | 74 ++++++++++++++ 2 files changed, 212 insertions(+) create mode 100644 apps/opencs/model/world/npcstats.cpp create mode 100644 apps/opencs/model/world/npcstats.hpp diff --git a/apps/opencs/model/world/npcstats.cpp b/apps/opencs/model/world/npcstats.cpp new file mode 100644 index 0000000000..da14b473e1 --- /dev/null +++ b/apps/opencs/model/world/npcstats.cpp @@ -0,0 +1,138 @@ +#include "npcstats.hpp" + +#include +#include + +namespace CSMWorld +{ + NpcStats::NpcStats() : mHealth(0), mMana(0), mFatigue(0) + { + for (int i = 0; i < ESM::Skill::Length; ++i) + mSkill[i] = 0; + } + + NpcStats::NpcStats(const NpcStats &other) + { + for (int i = 0; i < ESM::Attribute::Length; ++i) + mAttr[i] = other.mAttr[i]; + + mSpells = other.mSpells; + + for (int i = 0; i < ESM::Skill::Length; ++i) + mSkill[i] = 0; + + mHealth = other.mHealth; + mMana = other.mMana; + mFatigue = other.mFatigue; + } + + NpcStats::~NpcStats() + {} + + unsigned char NpcStats::getBaseAttribute(int index) const + { + if (index < 0 || index >= ESM::Attribute::Length) + throw std::runtime_error("attrib index out of bounds"); + + return mAttr[index]; + } + + void NpcStats::setAttribute(int index, unsigned char value) + { + if (index < 0 || index >= ESM::Attribute::Length) + throw std::runtime_error("attrib index out of bounds"); + + mAttr[index] = value; + } + + void NpcStats::addSpells(std::string id) + { + struct SpellInfo info; + info.mName = id; + info.mType = ESM::Spell::ST_Spell; // default type from autocalc + info.mFromRace = false; + info.mCost = 0; + info.mChance = 0; + + mSpells.insert(mSpells.begin(), info); + } + + void NpcStats::addPowers(const std::string& id, int type) + { + struct SpellInfo info; + info.mName = id; + info.mType = type; + info.mFromRace = true; + info.mCost = 0; + info.mChance = 0; + + mSpells.push_back(info); + } + + void NpcStats::addCostAndChance(const std::string& id, int cost, int chance) + { + // usually only a few spells, so simply iterate through rather than keeping a separate + // lookup index or map + for (std::vector::iterator it = mSpells.begin(); it != mSpells.end(); ++it) + { + if ((*it).mName == id) + { + (*it).mCost = cost; + (*it).mChance = chance; + return; + } + } + } + + const std::vector& NpcStats::spells() const + { + return mSpells; + } + + unsigned char NpcStats::getBaseSkill(int index) const + { + if (index < 0 || index >= ESM::Skill::Length) + throw std::runtime_error("skill index out of bounds"); + + return mSkill[index]; + } + + void NpcStats::setBaseSkill(int index, unsigned char value) + { + if (index < 0 || index >= ESM::Skill::Length) + throw std::runtime_error("skill index out of bounds"); + + mSkill[index] = value; + } + + unsigned short NpcStats::getHealth() + { + return mHealth; + } + + void NpcStats::setHealth(unsigned short health) + { + mHealth = health; + } + + unsigned short NpcStats::getMana() + { + return mMana; + } + + void NpcStats::setMana(unsigned short mana) + { + mMana = mana; + } + + unsigned short NpcStats::getFatigue() + { + return mFatigue; + } + + void NpcStats::setFatigue(unsigned short fatigue) + { + mFatigue = fatigue; + } +} + diff --git a/apps/opencs/model/world/npcstats.hpp b/apps/opencs/model/world/npcstats.hpp new file mode 100644 index 0000000000..a020e04998 --- /dev/null +++ b/apps/opencs/model/world/npcstats.hpp @@ -0,0 +1,74 @@ +#ifndef CSM_WORLD_NPCSTATS_H +#define CSM_WORLD_NPCSTATS_H + +#include + +#include + +#include +#include +#include + +namespace CSMWorld +{ + struct SpellInfo + { + std::string mName; + int mType; + bool mFromRace; + int mCost; + int mChance; + }; + + class NpcStats : public GamePlay::StatsBase + { + + int mAttr[ESM::Attribute::Length]; + std::vector mSpells; + int mSkill[ESM::Skill::Length]; + + unsigned short mHealth; + unsigned short mMana; + unsigned short mFatigue; + + public: + + NpcStats(); + + NpcStats(const NpcStats &other); + + ~NpcStats(); + + virtual unsigned char getBaseAttribute(int index) const; + + virtual void setAttribute(int index, unsigned char value); + + virtual void addSpells(std::string id); + + void addPowers(const std::string& id, int type); + + void addCostAndChance(const std::string& id, int cost, int chance); + + const std::vector& spells() const; + + virtual unsigned char getBaseSkill(int index) const; + + virtual void setBaseSkill(int index, unsigned char value); + + unsigned short getHealth(); + + void setHealth(unsigned short health); + + unsigned short getMana(); + + void setMana(unsigned short mana); + + unsigned short getFatigue(); + + void setFatigue(unsigned short fatigue); + }; +} + +Q_DECLARE_METATYPE(CSMWorld::NpcStats*); + +#endif // CSM_WORLD_NPCSTATS_H