1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 04:49:54 +00:00
openmw-tes3mp/apps/opencs/model/tools/referenceablecheck.cpp

989 lines
30 KiB
C++
Raw Normal View History

#include "referenceablecheck.hpp"
#include <sstream>
#include <map>
#include <cassert>
2013-12-27 21:13:55 +00:00
#include <boost/graph/graph_concepts.hpp>
#include "../world/record.hpp"
#include "../world/universalid.hpp"
2013-12-29 20:02:53 +00:00
CSMTools::ReferenceableCheckStage::ReferenceableCheckStage(const CSMWorld::RefIdData& referenceable, const CSMWorld::IdCollection<ESM::Race >& races, const CSMWorld::IdCollection<ESM::Class>& classes, const CSMWorld::IdCollection<ESM::Faction>& faction) :
mReferencables(referenceable),
mClasses(classes),
2013-12-29 20:02:53 +00:00
mRaces(races),
mFactions(faction)
{
2013-12-21 11:07:40 +00:00
}
void CSMTools::ReferenceableCheckStage::perform(int stage, std::vector< std::string >& messages)
{
//Checks for books, than, when stage is above mBooksSize goes to other checks, with (stage - PrevSum) as stage.
const int BookSize(mReferencables.getBooks().getSize());
if (stage < BookSize)
{
bookCheck(stage, mReferencables.getBooks(), messages);
return;
}
2013-12-21 10:15:46 +00:00
stage -= BookSize;
const int ActivatorSize(mReferencables.getActivators().getSize());
2013-12-21 10:15:46 +00:00
if (stage < ActivatorSize)
{
2013-12-21 10:01:40 +00:00
activatorCheck(stage, mReferencables.getActivators(), messages);
2013-12-21 10:15:46 +00:00
return;
}
stage -= ActivatorSize;
const int PotionSize(mReferencables.getActivators().getSize());
2013-12-21 10:15:46 +00:00
if (stage < PotionSize)
{
2013-12-21 11:07:40 +00:00
potionCheck(stage, mReferencables.getPotions(), messages);
return;
}
2013-12-21 10:15:46 +00:00
stage -= PotionSize;
2013-12-22 13:22:03 +00:00
const int ApparatusSize(mReferencables.getApparati().getSize());
if (stage < ApparatusSize)
2013-12-21 11:07:40 +00:00
{
2013-12-22 13:22:03 +00:00
apparatusCheck(stage, mReferencables.getApparati(), messages);
return;
2013-12-21 11:07:40 +00:00
}
2013-12-22 13:22:03 +00:00
stage -= ApparatusSize;
const int ArmorSize(mReferencables.getArmors().getSize());
2013-12-22 13:22:03 +00:00
if (stage < ArmorSize)
2013-12-22 13:22:03 +00:00
{
armorCheck(stage, mReferencables.getArmors(), messages);
return;
}
2013-12-22 13:32:42 +00:00
stage -= ArmorSize;
2013-12-22 13:32:42 +00:00
const int ClothingSize(mReferencables.getClothing().getSize());
if (stage < ClothingSize)
2013-12-22 13:32:42 +00:00
{
clothingCheck(stage, mReferencables.getClothing(), messages);
return;
}
stage -= ClothingSize;
const int ContainerSize(mReferencables.getContainers().getSize());
if (stage < ContainerSize)
2013-12-22 13:42:17 +00:00
{
containerCheck(stage, mReferencables.getContainers(), messages);
return;
2013-12-22 13:42:17 +00:00
}
stage -= ContainerSize;
2013-12-26 14:24:52 +00:00
const int DoorSize(mReferencables.getDoors().getSize());
if (stage < DoorSize)
2013-12-26 11:59:43 +00:00
{
2013-12-26 14:24:52 +00:00
doorCheck(stage, mReferencables.getDoors(), messages);
return;
2013-12-26 11:59:43 +00:00
}
2013-12-26 14:24:52 +00:00
stage -= DoorSize;
const int IngredientSize(mReferencables.getIngredients().getSize());
2013-12-26 17:16:54 +00:00
if (stage < IngredientSize)
2013-12-26 14:35:58 +00:00
{
2013-12-26 17:16:54 +00:00
ingredientCheck(stage, mReferencables.getIngredients(), messages);
return;
2013-12-26 14:35:58 +00:00
}
2013-12-26 17:16:54 +00:00
stage -= IngredientSize;
2013-12-26 17:16:54 +00:00
const int CreatureLevListSize(mReferencables.getCreatureLevelledLists().getSize());
if (stage < CreatureLevListSize)
2013-12-26 17:16:54 +00:00
{
creaturesLevListCheck(stage, mReferencables.getCreatureLevelledLists(), messages);
return;
}
stage -= CreatureLevListSize;
const int ItemLevelledListSize(mReferencables.getItemLevelledList().getSize());
if (stage < ItemLevelledListSize)
2013-12-26 17:28:24 +00:00
{
2013-12-27 21:13:55 +00:00
itemLevelledListCheck(stage, mReferencables.getItemLevelledList(), messages);
return;
2013-12-26 17:28:24 +00:00
}
stage -= ItemLevelledListSize;
const int LightSize(mReferencables.getLights().getSize());
2013-12-27 21:13:55 +00:00
if (stage < LightSize)
2013-12-27 21:13:55 +00:00
{
lightCheck(stage, mReferencables.getLights(), messages);
return;
}
stage -= LightSize;
2013-12-27 21:13:55 +00:00
const int LockpickSize(mReferencables.getLocpicks().getSize());
if (stage < LockpickSize)
2013-12-27 21:13:55 +00:00
{
lockpickCheck(stage, mReferencables.getLocpicks(), messages);
return;
}
stage -= LockpickSize;
const int MiscSize(mReferencables.getMiscellaneous().getSize());
2013-12-27 21:13:55 +00:00
if (stage < MiscSize)
2013-12-27 21:13:55 +00:00
{
miscCheck(stage, mReferencables.getMiscellaneous(), messages);
return;
}
stage -= MiscSize;
const int NPCSize(mReferencables.getNPCs().getSize());
if (stage < NPCSize)
2013-12-28 17:07:01 +00:00
{
npcCheck(stage, mReferencables.getNPCs(), messages);
return;
2013-12-28 17:07:01 +00:00
}
2014-01-03 10:31:54 +00:00
stage -= NPCSize;
const int WeaponSize(mReferencables.getWeapons().getSize());
if (stage < WeaponSize)
{
weaponCheck(stage, mReferencables.getWeapons(), messages);
return;
}
stage -= WeaponSize;
const int ProbeSize(mReferencables.getProbes().getSize());
if (stage < ProbeSize)
{
probeCheck(stage, mReferencables.getProbes(), messages);
return;
}
stage -= ProbeSize;
const int RepairSize(mReferencables.getRepairs().getSize());
if (stage < RepairSize)
{
repairCheck(stage, mReferencables.getRepairs(), messages);
return;
}
stage -= RepairSize;
const int StaticSize(mReferencables.getStatics().getSize());
if (stage < StaticSize)
{
staticCheck(stage, mReferencables.getStatics(), messages);
return;
}
}
int CSMTools::ReferenceableCheckStage::setup()
{
return mReferencables.getSize();
}
void CSMTools::ReferenceableCheckStage::bookCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Book >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Book& Book = (dynamic_cast<const CSMWorld::Record<ESM::Book>& >(baserecord)).get();
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Book, Book.mId);
2014-01-03 10:31:54 +00:00
inventoryItemCheck<ESM::Book>(Book, messages, id.toString(), true);
}
void CSMTools::ReferenceableCheckStage::activatorCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Activator >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Activator& Activator = (dynamic_cast<const CSMWorld::Record<ESM::Activator>& >(baserecord)).get();
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Activator, Activator.mId);
//Checking for model, IIRC all activators should have a model
if (Activator.mModel.empty())
{
messages.push_back(id.toString() + "|" + Activator.mId + " has no model");
}
}
2013-12-21 11:07:40 +00:00
void CSMTools::ReferenceableCheckStage::potionCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Potion >& records, std::vector< std::string >& messages)
2013-12-21 10:15:46 +00:00
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Potion& Potion = (dynamic_cast<const CSMWorld::Record<ESM::Potion>& >(baserecord)).get();
2013-12-21 10:15:46 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Potion, Potion.mId);
2014-01-03 10:31:54 +00:00
inventoryItemCheck<ESM::Potion>(Potion, messages, id.toString());
2013-12-21 10:15:46 +00:00
//IIRC potion can have empty effects list just fine.
}
2013-12-21 11:07:40 +00:00
void CSMTools::ReferenceableCheckStage::apparatusCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Apparatus >& records, std::vector< std::string >& messages)
{
2013-12-21 11:07:40 +00:00
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Apparatus& Apparatus = (dynamic_cast<const CSMWorld::Record<ESM::Apparatus>& >(baserecord)).get();
2013-12-21 11:07:40 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Apparatus, Apparatus.mId);
2014-01-03 10:31:54 +00:00
inventoryItemCheck<ESM::Apparatus>(Apparatus, messages, id.toString());
2013-12-22 13:22:03 +00:00
//checking for quality, 0 → apparatus is basicly useless, any negative → apparatus is harmfull instead of helpfull
2014-01-03 10:31:54 +00:00
toolCheck<ESM::Apparatus>(Apparatus, messages, id.toString());
2013-12-22 13:22:03 +00:00
}
void CSMTools::ReferenceableCheckStage::armorCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Armor >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Armor& Armor = (dynamic_cast<const CSMWorld::Record<ESM::Armor>& >(baserecord)).get();
2013-12-22 13:22:03 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Armor, Armor.mId);
2014-01-03 10:31:54 +00:00
inventoryItemCheck<ESM::Armor>(Armor, messages, id.toString(), true);
2013-12-22 13:32:42 +00:00
2013-12-22 13:22:03 +00:00
//checking for armor class, armor should have poistive armor class, but 0 is considered legal
if (Armor.mData.mArmor < 0)
{
2013-12-22 13:32:42 +00:00
messages.push_back(id.toString() + "|" + Armor.mId + " has negative armor class");
2013-12-22 13:22:03 +00:00
}
2013-12-22 13:32:42 +00:00
2014-01-03 10:31:54 +00:00
//checking for health. Only positive numbers are allowed, or 0 is illegal
2013-12-22 13:22:03 +00:00
if (Armor.mData.mHealth <= 0)
{
2013-12-22 13:32:42 +00:00
messages.push_back(id.toString() + "|" + Armor.mId + " has non positive health");
}
}
void CSMTools::ReferenceableCheckStage::clothingCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Clothing >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Clothing& Clothing = (dynamic_cast<const CSMWorld::Record<ESM::Clothing>& >(baserecord)).get();
2013-12-22 13:32:42 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Clothing, Clothing.mId);
2014-01-03 10:31:54 +00:00
inventoryItemCheck<ESM::Clothing>(Clothing, messages, id.toString(), true);
}
2013-12-22 13:42:17 +00:00
void CSMTools::ReferenceableCheckStage::containerCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Container >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Container& Container = (dynamic_cast<const CSMWorld::Record<ESM::Container>& >(baserecord)).get();
2013-12-22 13:42:17 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Container, Container.mId);
//Checking for model, IIRC all containers should have a model
if (Container.mModel.empty())
{
messages.push_back(id.toString() + "|" + Container.mId + " has no model");
}
//Checking for capacity (weight)
if (Container.mWeight < 0) //0 is allowed
{
messages.push_back(id.toString() + "|" + Container.mId + " has negative weight (capacity)");
}
//checking for name
if (Container.mName.empty())
{
messages.push_back(id.toString() + "|" + Container.mId + " has an empty name");
}
}
void CSMTools::ReferenceableCheckStage::creatureCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Creature >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Creature& Creature = (dynamic_cast<const CSMWorld::Record<ESM::Creature>&>(baserecord)).get();
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Creature, Creature.mId);
if (Creature.mModel.empty())
{
messages.push_back(id.toString() + "|" + Creature.mId + " has no model");
}
if (Creature.mName.empty())
{
messages.push_back(id.toString() + "|" + Creature.mId + " has an empty name");
}
//stats checks
if (Creature.mData.mLevel < 1)
{
messages.push_back(id.toString() + "|" + Creature.mId + " has non-postive level");
}
if (Creature.mData.mStrength < 0)
{
messages.push_back(id.toString() + "|" + Creature.mId + " has negative strength");
}
if (Creature.mData.mIntelligence < 0)
{
messages.push_back(id.toString() + "|" + Creature.mId + " has negative intelligence");
}
if (Creature.mData.mWillpower < 0)
{
messages.push_back(id.toString() + "|" + Creature.mId + " has negative willpower");
}
if (Creature.mData.mAgility < 0)
{
messages.push_back(id.toString() + "|" + Creature.mId + " has negative agility");
}
if (Creature.mData.mSpeed < 0)
{
messages.push_back(id.toString() + "|" + Creature.mId + " has negative speed");
}
if (Creature.mData.mEndurance < 0)
{
messages.push_back(id.toString() + "|" + Creature.mId + " has negative endurance");
}
if (Creature.mData.mPersonality < 0)
{
messages.push_back(id.toString() + "|" + Creature.mId + " has negative personality");
}
if (Creature.mData.mLuck < 0)
{
messages.push_back(id.toString() + "|" + Creature.mId + " has negative luck");
}
if (Creature.mData.mHealth < 0)
{
messages.push_back(id.toString() + "|" + Creature.mId + " has negative health");
}
if (Creature.mData.mSoul < 0)
{
messages.push_back(id.toString() + "|" + Creature.mId + " has negative soul value");
}
for (int i = 0; i < 6; ++i)
{
if (Creature.mData.mAttack[i] < 0)
{
messages.push_back(id.toString() + "|" + Creature.mId + " has negative attack strength");
break;
}
}
//TODO, find meaning of other values
2013-12-26 11:59:43 +00:00
if (Creature.mData.mGold < 0) //It seems that this is for gold in merchant creatures
{
messages.push_back(id.toString() + "|" + Creature.mId + " has negative gold ");
}
2013-12-26 11:59:43 +00:00
}
void CSMTools::ReferenceableCheckStage::doorCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Door >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Door& Door = (dynamic_cast<const CSMWorld::Record<ESM::Door>&>(baserecord)).get();
2013-12-26 11:59:43 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Door, Door.mId);
2013-12-26 14:24:52 +00:00
2014-01-03 10:31:54 +00:00
//usual, name or model
2013-12-26 11:59:43 +00:00
if (Door.mName.empty())
{
messages.push_back(id.toString() + "|" + Door.mId + " has an empty name");
}
if (Door.mModel.empty())
{
messages.push_back(id.toString() + "|" + Door.mId + " has no model");
}
2013-12-26 14:24:52 +00:00
//TODO, check what static unsigned int sRecordId; is for
}
void CSMTools::ReferenceableCheckStage::ingredientCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Ingredient >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Ingredient& Ingredient = (dynamic_cast<const CSMWorld::Record<ESM::Ingredient>& >(baserecord)).get();
2013-12-26 14:24:52 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Ingredient, Ingredient.mId);
2014-01-03 10:31:54 +00:00
inventoryItemCheck<ESM::Ingredient>(Ingredient, messages, id.toString());
}
2013-12-26 14:35:58 +00:00
void CSMTools::ReferenceableCheckStage::creaturesLevListCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::CreatureLevList >& records, std::vector< std::string >& messages)
{
2013-12-26 17:16:54 +00:00
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
2013-12-26 14:35:58 +00:00
if (baserecord.isDeleted())
{
return;
}
const ESM::CreatureLevList& CreatureLevList = (dynamic_cast<const CSMWorld::Record<ESM::CreatureLevList>& >(baserecord)).get();
2013-12-26 17:16:54 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_CreatureLevelledList, CreatureLevList.mId); //CreatureLevList but Type_CreatureLevelledList :/
2014-01-03 10:31:54 +00:00
listCheck<ESM::CreatureLevList>(CreatureLevList, messages, id.toString());
2013-12-26 17:28:24 +00:00
}
2013-12-27 21:13:55 +00:00
void CSMTools::ReferenceableCheckStage::itemLevelledListCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::ItemLevList >& records, std::vector< std::string >& messages)
2013-12-26 17:28:24 +00:00
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
2013-12-26 17:16:54 +00:00
const ESM::ItemLevList& ItemLevList = (dynamic_cast<const CSMWorld::Record<ESM::ItemLevList>& >(baserecord)).get();
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_ItemLevelledList, ItemLevList.mId);
2013-12-26 17:28:24 +00:00
2014-01-03 10:31:54 +00:00
listCheck<ESM::ItemLevList>(ItemLevList, messages, id.toString());
2013-12-27 21:13:55 +00:00
}
2013-12-26 17:28:24 +00:00
2013-12-27 21:13:55 +00:00
void CSMTools::ReferenceableCheckStage::lightCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Light >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Light& Light = (dynamic_cast<const CSMWorld::Record<ESM::Light>& >(baserecord)).get();
2013-12-27 21:13:55 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Light, Light.mId);
if (Light.mData.mRadius < 0)
2013-12-26 17:28:24 +00:00
{
2013-12-27 21:13:55 +00:00
messages.push_back(id.toString() + "|" + Light.mId + " has negative light radius");
2013-12-26 17:28:24 +00:00
}
2013-12-27 21:13:55 +00:00
if (Light.mData.mFlags & ESM::Light::Carry)
{
if (Light.mIcon.empty()) //Needs to be checked with carrable flag
{
2014-01-03 10:31:54 +00:00
inventoryItemCheck<ESM::Light>(Light, messages, id.toString());
2013-12-27 21:13:55 +00:00
2014-01-03 10:31:54 +00:00
if (Light.mData.mTime == 0)
{
messages.push_back(id.toString() + "|" + Light.mId + " has zero duration");
}
2013-12-27 21:13:55 +00:00
}
}
}
void CSMTools::ReferenceableCheckStage::lockpickCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Lockpick >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Lockpick& Lockpick = (dynamic_cast<const CSMWorld::Record<ESM::Lockpick>& >(baserecord)).get();
2013-12-27 21:13:55 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Lockpick, Lockpick.mId);
2014-01-03 10:31:54 +00:00
inventoryItemCheck<ESM::Lockpick>(Lockpick, messages, id.toString());
2013-12-27 21:13:55 +00:00
2014-01-03 10:31:54 +00:00
toolCheck<ESM::Lockpick>(Lockpick, messages, id.toString(), true);
2013-12-27 21:13:55 +00:00
}
void CSMTools::ReferenceableCheckStage::miscCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Miscellaneous >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Miscellaneous& Miscellaneous = (dynamic_cast<const CSMWorld::Record<ESM::Miscellaneous>& >(baserecord)).get();
2013-12-27 21:13:55 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Miscellaneous, Miscellaneous.mId);
2014-01-03 10:31:54 +00:00
inventoryItemCheck<ESM::Miscellaneous>(Miscellaneous, messages, id.toString());
2013-12-27 21:13:55 +00:00
}
void CSMTools::ReferenceableCheckStage::npcCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::NPC >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::NPC& NPC = (dynamic_cast<const CSMWorld::Record<ESM::NPC>& >(baserecord)).get();
2013-12-27 21:13:55 +00:00
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Npc, NPC.mId);
short level(NPC.mNpdt52.mLevel);
char Disposition(NPC.mNpdt52.mDisposition);
char Reputation(NPC.mNpdt52.mReputation);
char Rank(NPC.mNpdt52.mRank);
//Don't know what unknown is for
int Gold(NPC.mNpdt52.mGold);
2013-12-28 10:34:51 +00:00
if (NPC.mNpdtType == 12) //12 = autocalculated
2013-12-27 21:13:55 +00:00
{
if ((NPC.mFlags & 0x0008) == 0) //0x0008 = autocalculated flag
2013-12-27 21:13:55 +00:00
{
2014-01-03 10:31:54 +00:00
messages.push_back(id.toString() + "|" + NPC.mId + " mNpdtType or flags mismatch!"); //should not happend?
2013-12-27 21:13:55 +00:00
return;
}
level = NPC.mNpdt12.mLevel;
Disposition = NPC.mNpdt12.mDisposition;
Reputation = NPC.mNpdt12.mReputation;
Rank = NPC.mNpdt12.mRank;
Gold = NPC.mNpdt12.mGold;
}
else
{
if (NPC.mNpdt52.mMana < 0)
{
2013-12-28 10:34:51 +00:00
messages.push_back(id.toString() + "|" + NPC.mId + " mana has negative value");
2013-12-27 21:13:55 +00:00
}
if (NPC.mNpdt52.mFatigue < 0)
{
2013-12-28 10:34:51 +00:00
messages.push_back(id.toString() + "|" + NPC.mId + " fatigue has negative value");
2013-12-27 21:13:55 +00:00
}
2013-12-28 10:34:51 +00:00
2013-12-28 14:51:38 +00:00
if (NPC.mNpdt52.mAgility == 0)
2013-12-28 10:34:51 +00:00
{
2013-12-28 14:51:38 +00:00
messages.push_back(id.toString() + "|" + NPC.mId + " agility has zero value");
2013-12-28 10:34:51 +00:00
}
2013-12-28 14:51:38 +00:00
if (NPC.mNpdt52.mEndurance == 0)
2013-12-28 10:34:51 +00:00
{
2013-12-28 14:51:38 +00:00
messages.push_back(id.toString() + "|" + NPC.mId + " endurance has zero value");
2013-12-28 10:34:51 +00:00
}
2013-12-28 14:51:38 +00:00
if (NPC.mNpdt52.mIntelligence == 0)
2013-12-28 10:34:51 +00:00
{
2013-12-28 14:51:38 +00:00
messages.push_back(id.toString() + "|" + NPC.mId + " intelligence has zero value");
2013-12-28 10:34:51 +00:00
}
2013-12-28 14:51:38 +00:00
if (NPC.mNpdt52.mLuck == 0)
2013-12-28 10:34:51 +00:00
{
2013-12-28 14:51:38 +00:00
messages.push_back(id.toString() + "|" + NPC.mId + " luck has zero value");
2013-12-28 10:34:51 +00:00
}
2013-12-28 14:51:38 +00:00
if (NPC.mNpdt52.mPersonality == 0)
2013-12-28 10:34:51 +00:00
{
2013-12-28 14:51:38 +00:00
messages.push_back(id.toString() + "|" + NPC.mId + " personality has zero value");
2013-12-28 10:34:51 +00:00
}
2013-12-28 14:51:38 +00:00
if (NPC.mNpdt52.mStrength == 0)
2013-12-28 10:34:51 +00:00
{
2013-12-28 14:51:38 +00:00
messages.push_back(id.toString() + "|" + NPC.mId + " strength has zero value");
2013-12-28 10:34:51 +00:00
}
2013-12-28 14:51:38 +00:00
if (NPC.mNpdt52.mSpeed == 0)
2013-12-28 10:34:51 +00:00
{
2013-12-28 14:51:38 +00:00
messages.push_back(id.toString() + "|" + NPC.mId + " speed has zero value");
2013-12-28 10:34:51 +00:00
}
2013-12-28 14:51:38 +00:00
if (NPC.mNpdt52.mWillpower == 0)
2013-12-28 10:34:51 +00:00
{
2013-12-28 14:51:38 +00:00
messages.push_back(id.toString() + "|" + NPC.mId + " willpower has zero value");
2013-12-28 10:34:51 +00:00
}
2013-12-27 21:13:55 +00:00
}
if (level < 1)
{
messages.push_back(id.toString() + "|" + NPC.mId + " level is non positive");
}
if (Gold < 0)
{
messages.push_back(id.toString() + "|" + NPC.mId + " gold has negative value");
2013-12-27 21:13:55 +00:00
}
if (NPC.mName.empty())
{
messages.push_back(id.toString() + "|" + NPC.mId + " has any empty name");
}
if (NPC.mClass.empty())
{
messages.push_back(id.toString() + "|" + NPC.mId + " has any empty class");
}
2013-12-28 17:07:01 +00:00
else //checking if there is such class
{
2013-12-30 18:24:53 +00:00
if (mClasses.searchId(NPC.mClass) == -1)
2013-12-28 17:07:01 +00:00
{
messages.push_back(id.toString() + "|" + NPC.mId + " has invalid class");
}
}
2013-12-28 10:34:51 +00:00
if (NPC.mRace.empty())
{
messages.push_back(id.toString() + "|" + NPC.mId + " has any empty race");
}
2013-12-28 17:07:01 +00:00
else //checking if there is a such race
{
bool nosuchrace(true);
for (int i = 0; i < mRaces.getSize(); ++i)
{
2013-12-29 20:53:33 +00:00
if (dynamic_cast<const ESM::Race&>(mRaces.getRecord(i).get()).mName == NPC.mRace) //mId in class, mName for race. Stupid.
2013-12-28 17:07:01 +00:00
{
nosuchrace = false;
break;
}
}
2013-12-28 17:07:01 +00:00
if (nosuchrace)
{
messages.push_back(id.toString() + "|" + NPC.mId + " has invalid race");
}
}
2013-12-29 20:02:53 +00:00
if (Disposition < 0)
{
messages.push_back(id.toString() + "|" + NPC.mId + " has negative disposition");
}
2013-12-29 20:53:33 +00:00
if (Reputation < 0) //It seems that no character in Morrowind.esm have negative reputation. I'm assuming that negative reputation is invalid
2013-12-29 20:02:53 +00:00
{
messages.push_back(id.toString() + "|" + NPC.mId + " has negative reputation");
}
if (NPC.mFaction.empty() == false)
2013-12-29 20:02:53 +00:00
{
if (Rank < 0)
2013-12-29 20:02:53 +00:00
{
messages.push_back(id.toString() + "|" + NPC.mId + " has negative rank");
2013-12-29 20:02:53 +00:00
}
2013-12-30 17:41:16 +00:00
if (mFactions.searchId(NPC.mFaction) == -1)
{
messages.push_back(id.toString() + "|" + NPC.mId + " has invalid faction");
}
}
if (NPC.mHead.empty())
{
messages.push_back(id.toString() + "|" + NPC.mId + " has no head");
}
if (NPC.mHair.empty())
{
2013-12-30 17:41:16 +00:00
messages.push_back(id.toString() + "|" + NPC.mId + " has no hair");
2013-12-29 20:02:53 +00:00
}
2013-12-27 21:13:55 +00:00
//TODO: reputation, Disposition, rank, everything else
2013-12-26 17:16:54 +00:00
}
2014-01-02 19:20:18 +00:00
2014-01-03 10:31:54 +00:00
void CSMTools::ReferenceableCheckStage::weaponCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Weapon >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Weapon& Weapon = (dynamic_cast<const CSMWorld::Record<ESM::Weapon>& >(baserecord)).get();
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Weapon, Weapon.mId);
//TODO, It seems that this stuff for spellcasting is obligatory and In fact We should check if records are present
if
(
Weapon.mId.find("VFX_") == std::string::npos
and Weapon.mId != "magic_bolt"
and Weapon.mId != "shield_bolt"
and Weapon.mId != "shock_bolt"
)
{
inventoryItemCheck<ESM::Weapon>(Weapon, messages, id.toString(), true);
if (Weapon.mData.mType == ESM::Weapon::MarksmanBow or Weapon.mData.mType == ESM::Weapon::MarksmanCrossbow or Weapon.mData.mType == ESM::Weapon::MarksmanThrown or Weapon.mData.mType == ESM::Weapon::Arrow or Weapon.mData.mType == ESM::Weapon::Bolt)
{
if (Weapon.mData.mChop[0] > Weapon.mData.mChop[1])
{
messages.push_back(id.toString() + "|" + Weapon.mId + " has minimum chop damage higher than maximum");
}
}
else
{
if (Weapon.mData.mSlash[0] > Weapon.mData.mSlash[1])
{
messages.push_back(id.toString() + "|" + Weapon.mId + " has minimum slash damage higher than maximum");
}
if (Weapon.mData.mChop[0] > Weapon.mData.mChop[1])
{
messages.push_back(id.toString() + "|" + Weapon.mId + " has minimum chop damage higher than maximum");
}
if (Weapon.mData.mThrust[0] > Weapon.mData.mThrust[1])
{
messages.push_back(id.toString() + "|" + Weapon.mId + " has minimum thrust damage higher than maximum");
}
}
if (!(Weapon.mData.mType == ESM::Weapon::Arrow or Weapon.mData.mType == ESM::Weapon::Bolt or Weapon.mData.mType == ESM::Weapon::MarksmanThrown))
{
//checking of health
if (Weapon.mData.mHealth <= 0)
{
messages.push_back(id.toString() + "|" + Weapon.mId + " has non-positivie health");
}
if (Weapon.mData.mReach < 0)
{
messages.push_back(id.toString() + "|" + Weapon.mId + " has negative reach");
}
}
}
}
void CSMTools::ReferenceableCheckStage::probeCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Probe >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Probe& Probe = (dynamic_cast<const CSMWorld::Record<ESM::Probe>& >(baserecord)).get();
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Probe, Probe.mId);
inventoryItemCheck<ESM::Probe>(Probe, messages, id.toString());
toolCheck<ESM::Probe>(Probe, messages, id.toString(), true);
}
void CSMTools::ReferenceableCheckStage::repairCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Repair >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Repair& Repair = (dynamic_cast<const CSMWorld::Record<ESM::Repair>& >(baserecord)).get();
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Repair, Repair.mId);
inventoryItemCheck<ESM::Repair>(Repair, messages, id.toString());
toolCheck<ESM::Repair>(Repair, messages, id.toString(), true);
}
void CSMTools::ReferenceableCheckStage::staticCheck(int stage, const CSMWorld::RefIdDataContainer< ESM::Static >& records, std::vector< std::string >& messages)
{
const CSMWorld::RecordBase& baserecord = records.getRecord(stage);
if (baserecord.isDeleted())
{
return;
}
const ESM::Static& Static = (dynamic_cast<const CSMWorld::Record<ESM::Static>& >(baserecord)).get();
CSMWorld::UniversalId id(CSMWorld::UniversalId::Type_Static, Static.mId);
if (Static.mModel.empty())
{
messages.push_back(id.toString() + "|" + Static.mId + " has no model");
}
}
2014-01-02 19:20:18 +00:00
//Templates begins here
2014-01-03 10:31:54 +00:00
template<typename ITEM> void CSMTools::ReferenceableCheckStage::inventoryItemCheck(const ITEM& someitem, std::vector< std::string >& messages, const std::string& someid, bool enchantable)
{
if (someitem.mName.empty())
{
messages.push_back(someid + "|" + someitem.mId + " has an empty name");
}
//Checking for weight
if (someitem.mData.mWeight < 0)
{
messages.push_back(someid + "|" + someitem.mId + " has negative weight");
}
//Checking for value
if (someitem.mData.mValue < 0)
{
messages.push_back(someid + "|" + someitem.mId + " has negative value");
}
//checking for model
if (someitem.mModel.empty())
{
messages.push_back(someid + "|" + someitem.mId + " has no model");
}
//checking for icon
if (someitem.mIcon.empty())
{
messages.push_back(someid + "|" + someitem.mId + " has no icon");
}
if (enchantable)
{
if (someitem.mData.mEnchant < 0)
{
messages.push_back(someid + "|" + someitem.mId + " has negative enchantment");
}
}
}
template<typename ITEM> void CSMTools::ReferenceableCheckStage::inventoryItemCheck(const ITEM& someitem, std::vector< std::string >& messages, const std::string& someid)
2014-01-02 19:20:18 +00:00
{
2014-01-03 10:31:54 +00:00
if (someitem.mName.empty())
2014-01-02 19:20:18 +00:00
{
2014-01-03 10:31:54 +00:00
messages.push_back(someid + "|" + someitem.mId + " has an empty name");
2014-01-02 19:20:18 +00:00
}
//Checking for weight
2014-01-03 10:31:54 +00:00
if (someitem.mData.mWeight < 0)
2014-01-02 19:20:18 +00:00
{
2014-01-03 10:31:54 +00:00
messages.push_back(someid + "|" + someitem.mId + " has negative weight");
2014-01-02 19:20:18 +00:00
}
//Checking for value
2014-01-03 10:31:54 +00:00
if (someitem.mData.mValue < 0)
2014-01-02 19:20:18 +00:00
{
2014-01-03 10:31:54 +00:00
messages.push_back(someid + "|" + someitem.mId + " has negative value");
2014-01-02 19:20:18 +00:00
}
//checking for model
2014-01-03 10:31:54 +00:00
if (someitem.mModel.empty())
2014-01-02 19:20:18 +00:00
{
2014-01-03 10:31:54 +00:00
messages.push_back(someid + "|" + someitem.mId + " has no model");
2014-01-02 19:20:18 +00:00
}
//checking for icon
2014-01-03 10:31:54 +00:00
if (someitem.mIcon.empty())
{
messages.push_back(someid + "|" + someitem.mId + " has no icon");
}
}
template<typename TOOL> void CSMTools::ReferenceableCheckStage::toolCheck(const TOOL& sometool, std::vector< std::string >& messages, const std::string& someid, bool canbebroken)
{
if (sometool.mData.mQuality <= 0)
{
messages.push_back(someid + "|" + sometool.mId + " has non-positive quality");
}
if (canbebroken)
{
if (sometool.mData.mUses <= 0)
{
messages.push_back(someid + "|" + sometool.mId + " has non-positive uses count");
}
}
}
template<typename TOOL> void CSMTools::ReferenceableCheckStage::toolCheck(const TOOL& sometool, std::vector< std::string >& messages, const std::string& someid)
{
if (sometool.mData.mQuality <= 0)
{
messages.push_back(someid + "|" + sometool.mId + " has non-positive quality");
}
}
template<typename LIST> void CSMTools::ReferenceableCheckStage::listCheck(const LIST& somelist, std::vector< std::string >& messages, const std::string& someid)
{
for (unsigned i = 0; i < somelist.mList.size(); ++i)
2014-01-02 19:20:18 +00:00
{
2014-01-03 10:31:54 +00:00
if (somelist.mList[i].mId.empty())
{
messages.push_back(someid + "|" + somelist.mId + " contains item with empty Id");
}
if (somelist.mList[i].mLevel < 1)
{
messages.push_back(someid + "|" + somelist.mId + " contains item with non-positive level");
}
2014-01-02 19:20:18 +00:00
}
}
2014-01-03 10:31:54 +00:00