1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-15 11:46:56 +02:00

Drafts for hero serialization

This commit is contained in:
AlexVinS 2016-01-24 02:27:14 +03:00
parent 3eb9de0c0b
commit 408f346541
6 changed files with 76 additions and 33 deletions

View File

@ -19,6 +19,7 @@
#include "mapObjects/MapObjects.h" #include "mapObjects/MapObjects.h"
#include "NetPacksBase.h" #include "NetPacksBase.h"
#include "GameConstants.h" #include "GameConstants.h"
#include "StringConstants.h"
#include "CRandomGenerator.h" #include "CRandomGenerator.h"
#include "mapObjects/CObjectClassesHandler.h" #include "mapObjects/CObjectClassesHandler.h"
@ -1258,3 +1259,13 @@ void CArtifactSet::artDeserializationFix(CBonusSystemNode *node)
if(elem.second.artifact && !elem.second.locked) if(elem.second.artifact && !elem.second.locked)
node->attachTo(elem.second.artifact); node->attachTo(elem.second.artifact);
} }
void CArtifactSet::writeJson(JsonNode& json) const
{
}
void CArtifactSet::readJson(const JsonNode& json)
{
}

View File

@ -48,7 +48,7 @@ protected:
std::string eventText; //short story displayed upon picking std::string eventText; //short story displayed upon picking
public: public:
enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes
std::string identifier; std::string identifier;
std::string image; std::string image;
std::string large; // big image for cutom artifacts, used in drag & drop std::string large; // big image for cutom artifacts, used in drag & drop
@ -309,4 +309,8 @@ public:
} }
void artDeserializationFix(CBonusSystemNode *node); void artDeserializationFix(CBonusSystemNode *node);
protected:
void writeJson(JsonNode & json) const;
void readJson(const JsonNode & json);
}; };

View File

@ -21,7 +21,7 @@ namespace GameConstants
const std::string TERRAIN_NAMES [TERRAIN_TYPES] = { const std::string TERRAIN_NAMES [TERRAIN_TYPES] = {
"dirt", "sand", "grass", "snow", "swamp", "rough", "subterra", "lava", "water", "rock" "dirt", "sand", "grass", "snow", "swamp", "rough", "subterra", "lava", "water", "rock"
}; };
const std::string RESOURCE_NAMES [RESOURCE_QUANTITY] = { const std::string RESOURCE_NAMES [RESOURCE_QUANTITY] = {
"wood", "mercury", "ore", "sulfur", "crystal", "gems", "gold", "mithril" "wood", "mercury", "ore", "sulfur", "crystal", "gems", "gold", "mithril"
}; };
@ -84,3 +84,17 @@ namespace ETownType
"stronghold", "fortress", "conflux" "stronghold", "fortress", "conflux"
}; };
} }
namespace NArtifactPosition
{
const std::string names [19] =
{
"head", "shoulders", "neck", "rightHand", "leftHand", "torso", //5
"rightRing", "leftRing", "feet", //8
"misc1", "misc2", "misc3", "misc4", //12
"mach1", "mach2", "mach3", "mach4", //16
"spellbook", "misc5" //18
};
const std::string backpack = "backpack";
}

View File

@ -868,18 +868,18 @@ TExpType CGHeroInstance::calculateXp(TExpType exp) const
ui8 CGHeroInstance::getSpellSchoolLevel(const CSpell * spell, int *outSelectedSchool) const ui8 CGHeroInstance::getSpellSchoolLevel(const CSpell * spell, int *outSelectedSchool) const
{ {
si16 skill = -1; //skill level si16 skill = -1; //skill level
spell->forEachSchool([&, this](const SpellSchoolInfo & cnf, bool & stop) spell->forEachSchool([&, this](const SpellSchoolInfo & cnf, bool & stop)
{ {
int thisSchool = std::max<int>(getSecSkillLevel(cnf.skill), valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 1 << ((ui8)cnf.id))); //FIXME: Bonus shouldn't be additive (Witchking Artifacts : Crown of Skies) int thisSchool = std::max<int>(getSecSkillLevel(cnf.skill), valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 1 << ((ui8)cnf.id))); //FIXME: Bonus shouldn't be additive (Witchking Artifacts : Crown of Skies)
if(thisSchool > skill) if(thisSchool > skill)
{ {
skill = thisSchool; skill = thisSchool;
if(outSelectedSchool) if(outSelectedSchool)
*outSelectedSchool = (ui8)cnf.id; *outSelectedSchool = (ui8)cnf.id;
} }
}); });
vstd::amax(skill, valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 0)); //any school bonus vstd::amax(skill, valOfBonuses(Bonus::MAGIC_SCHOOL_SKILL, 0)); //any school bonus
vstd::amax(skill, valOfBonuses(Bonus::SPELL, spell->id.toEnum())); //given by artifact or other effect vstd::amax(skill, valOfBonuses(Bonus::SPELL, spell->id.toEnum())); //given by artifact or other effect
@ -904,7 +904,7 @@ ui32 CGHeroInstance::getSpellBonus(const CSpell * spell, ui32 base, const CStack
if (affectedStack && affectedStack->getCreature()->level) //Hero specials like Solmyr, Deemer if (affectedStack && affectedStack->getCreature()->level) //Hero specials like Solmyr, Deemer
base *= (100. + ((valOfBonuses(Bonus::SPECIAL_SPELL_LEV, spell->id.toEnum()) * level) / affectedStack->getCreature()->level)) / 100.0; base *= (100. + ((valOfBonuses(Bonus::SPECIAL_SPELL_LEV, spell->id.toEnum()) * level) / affectedStack->getCreature()->level)) / 100.0;
return base; return base;
} }
int CGHeroInstance::getEffectLevel(const CSpell * spell) const int CGHeroInstance::getEffectLevel(const CSpell * spell) const
@ -912,7 +912,7 @@ int CGHeroInstance::getEffectLevel(const CSpell * spell) const
if(hasBonusOfType(Bonus::MAXED_SPELL, spell->id)) if(hasBonusOfType(Bonus::MAXED_SPELL, spell->id))
return 3;//todo: recheck specialty from where this bonus is. possible bug return 3;//todo: recheck specialty from where this bonus is. possible bug
else else
return getSpellSchoolLevel(spell); return getSpellSchoolLevel(spell);
} }
int CGHeroInstance::getEffectPower(const CSpell * spell) const int CGHeroInstance::getEffectPower(const CSpell * spell) const
@ -922,7 +922,7 @@ int CGHeroInstance::getEffectPower(const CSpell * spell) const
int CGHeroInstance::getEnchantPower(const CSpell * spell) const int CGHeroInstance::getEnchantPower(const CSpell * spell) const
{ {
return getPrimSkillLevel(PrimarySkill::SPELL_POWER) + valOfBonuses(Bonus::SPELL_DURATION); return getPrimSkillLevel(PrimarySkill::SPELL_POWER) + valOfBonuses(Bonus::SPELL_DURATION);
} }
int CGHeroInstance::getEffectValue(const CSpell * spell) const int CGHeroInstance::getEffectValue(const CSpell * spell) const
@ -1107,8 +1107,8 @@ void CGHeroInstance::getOutOffsets(std::vector<int3> &offsets) const
{ {
// FIXME: Offsets need to be fixed once we get rid of convertPosition // FIXME: Offsets need to be fixed once we get rid of convertPosition
// Check issue 515 for details // Check issue 515 for details
offsets = offsets =
{ {
int3(-1,1,0), int3(-1,-1,0), int3(-2,0,0), int3(0,0,0), int3(0,1,0), int3(-2,1,0), int3(0,-1,0), int3(-2,-1,0) int3(-1,1,0), int3(-1,-1,0), int3(-2,0,0), int3(0,0,0), int3(0,1,0), int3(-2,1,0), int3(0,-1,0), int3(-2,-1,0)
}; };
} }
@ -1436,20 +1436,33 @@ void CGHeroInstance::levelUpAutomatically()
bool CGHeroInstance::hasVisions(const CGObjectInstance * target, const int subtype) const bool CGHeroInstance::hasVisions(const CGObjectInstance * target, const int subtype) const
{ {
//VISIONS spell support //VISIONS spell support
const std::string cached = boost::to_string((boost::format("type_%d__subtype_%d") % Bonus::VISIONS % subtype)); const std::string cached = boost::to_string((boost::format("type_%d__subtype_%d") % Bonus::VISIONS % subtype));
const int visionsMultiplier = valOfBonuses(Selector::typeSubtype(Bonus::VISIONS,subtype), cached); const int visionsMultiplier = valOfBonuses(Selector::typeSubtype(Bonus::VISIONS,subtype), cached);
int visionsRange = visionsMultiplier * getPrimSkillLevel(PrimarySkill::SPELL_POWER); int visionsRange = visionsMultiplier * getPrimSkillLevel(PrimarySkill::SPELL_POWER);
if (visionsMultiplier > 0) if (visionsMultiplier > 0)
vstd::amax(visionsRange, 3); //minimum range is 3 tiles, but only if VISIONS bonus present vstd::amax(visionsRange, 3); //minimum range is 3 tiles, but only if VISIONS bonus present
const int distance = target->pos.dist2d(getPosition(false)); const int distance = target->pos.dist2d(getPosition(false));
//logGlobal->debug(boost::to_string(boost::format("Visions: dist %d, mult %d, range %d") % distance % visionsMultiplier % visionsRange)); //logGlobal->debug(boost::to_string(boost::format("Visions: dist %d, mult %d, range %d") % distance % visionsMultiplier % visionsRange));
return (distance < visionsRange) && (target->pos.z == pos.z); return (distance < visionsRange) && (target->pos.z == pos.z);
} }
void CGHeroInstance::writeJsonOptions(JsonNode& json) const
{
CArmedInstance::writeJsonOptions(json);
CGObjectInstance::writeOwner(json);
CArtifactSet::writeJson(json["artifacts"]);
}
void CGHeroInstance::readJsonOptions(const JsonNode& json)
{
CArmedInstance::readJsonOptions(json);
CGObjectInstance::readOwner(json);
CArtifactSet::readJson(json["artifacts"]);
}

View File

@ -177,7 +177,7 @@ public:
double getHeroStrength() const; // includes fighting and magic strength double getHeroStrength() const; // includes fighting and magic strength
ui64 getTotalStrength() const; // includes fighting strength and army strength ui64 getTotalStrength() const; // includes fighting strength and army strength
TExpType calculateXp(TExpType exp) const; //apply learning skill TExpType calculateXp(TExpType exp) const; //apply learning skill
bool canCastThisSpell(const CSpell * spell) const; //determines if this hero can cast given spell; takes into account existing spell in spellbook, existing spellbook and artifact bonuses bool canCastThisSpell(const CSpell * spell) const; //determines if this hero can cast given spell; takes into account existing spell in spellbook, existing spellbook and artifact bonuses
CStackBasicDescriptor calculateNecromancy (const BattleResult &battleResult) const; CStackBasicDescriptor calculateNecromancy (const BattleResult &battleResult) const;
void showNecromancyDialog(const CStackBasicDescriptor &raisedStack) const; void showNecromancyDialog(const CStackBasicDescriptor &raisedStack) const;
@ -201,23 +201,23 @@ public:
void Updatespecialty(); void Updatespecialty();
void recreateSecondarySkillsBonuses(); void recreateSecondarySkillsBonuses();
void updateSkill(SecondarySkill which, int val); void updateSkill(SecondarySkill which, int val);
bool hasVisions(const CGObjectInstance * target, const int subtype) const; bool hasVisions(const CGObjectInstance * target, const int subtype) const;
CGHeroInstance(); CGHeroInstance();
virtual ~CGHeroInstance(); virtual ~CGHeroInstance();
///ArtBearer ///ArtBearer
ArtBearer::ArtBearer bearerType() const override; ArtBearer::ArtBearer bearerType() const override;
///IBonusBearer ///IBonusBearer
CBonusSystemNode *whereShouldBeAttached(CGameState *gs) override; CBonusSystemNode *whereShouldBeAttached(CGameState *gs) override;
std::string nodeName() const override; std::string nodeName() const override;
///ISpellCaster ///ISpellCaster
ui8 getSpellSchoolLevel(const CSpell * spell, int *outSelectedSchool = nullptr) const override; ui8 getSpellSchoolLevel(const CSpell * spell, int *outSelectedSchool = nullptr) const override;
ui32 getSpellBonus(const CSpell * spell, ui32 base, const CStack * affectedStack) const override; ui32 getSpellBonus(const CSpell * spell, ui32 base, const CStack * affectedStack) const override;
///default spell school level for effect calculation ///default spell school level for effect calculation
int getEffectLevel(const CSpell * spell) const override; int getEffectLevel(const CSpell * spell) const override;
@ -229,9 +229,9 @@ public:
///damage/heal override(ignores spell configuration, effect level and effect power) ///damage/heal override(ignores spell configuration, effect level and effect power)
int getEffectValue(const CSpell * spell) const override; int getEffectValue(const CSpell * spell) const override;
const PlayerColor getOwner() const override; const PlayerColor getOwner() const override;
void deserializationFix(); void deserializationFix();
void initObj() override; void initObj() override;
@ -239,6 +239,8 @@ public:
std::string getObjectName() const override; std::string getObjectName() const override;
protected: protected:
void setPropertyDer(ui8 what, ui32 val) override;//synchr void setPropertyDer(ui8 what, ui32 val) override;//synchr
void writeJsonOptions(JsonNode & json) const override;
void readJsonOptions(const JsonNode & json) override;
private: private:
void levelUpAutomatically(); void levelUpAutomatically();

View File

@ -683,7 +683,6 @@ void CMapSaverJson::addToArchive(const JsonNode& data, const std::string& filena
void CMapSaverJson::saveMap(const std::unique_ptr<CMap>& map) void CMapSaverJson::saveMap(const std::unique_ptr<CMap>& map)
{ {
//TODO: saveMap
this->map = map.get(); this->map = map.get();
writeHeader(); writeHeader();
writeTerrain(); writeTerrain();