mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Drafts for hero serialization
This commit is contained in:
parent
3eb9de0c0b
commit
408f346541
@ -19,6 +19,7 @@
|
||||
#include "mapObjects/MapObjects.h"
|
||||
#include "NetPacksBase.h"
|
||||
#include "GameConstants.h"
|
||||
#include "StringConstants.h"
|
||||
#include "CRandomGenerator.h"
|
||||
|
||||
#include "mapObjects/CObjectClassesHandler.h"
|
||||
@ -1258,3 +1259,13 @@ void CArtifactSet::artDeserializationFix(CBonusSystemNode *node)
|
||||
if(elem.second.artifact && !elem.second.locked)
|
||||
node->attachTo(elem.second.artifact);
|
||||
}
|
||||
|
||||
void CArtifactSet::writeJson(JsonNode& json) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CArtifactSet::readJson(const JsonNode& json)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ protected:
|
||||
std::string eventText; //short story displayed upon picking
|
||||
public:
|
||||
enum EartClass {ART_SPECIAL=1, ART_TREASURE=2, ART_MINOR=4, ART_MAJOR=8, ART_RELIC=16}; //artifact classes
|
||||
|
||||
|
||||
std::string identifier;
|
||||
std::string image;
|
||||
std::string large; // big image for cutom artifacts, used in drag & drop
|
||||
@ -309,4 +309,8 @@ public:
|
||||
}
|
||||
|
||||
void artDeserializationFix(CBonusSystemNode *node);
|
||||
|
||||
protected:
|
||||
void writeJson(JsonNode & json) const;
|
||||
void readJson(const JsonNode & json);
|
||||
};
|
||||
|
@ -21,7 +21,7 @@ namespace GameConstants
|
||||
const std::string TERRAIN_NAMES [TERRAIN_TYPES] = {
|
||||
"dirt", "sand", "grass", "snow", "swamp", "rough", "subterra", "lava", "water", "rock"
|
||||
};
|
||||
|
||||
|
||||
const std::string RESOURCE_NAMES [RESOURCE_QUANTITY] = {
|
||||
"wood", "mercury", "ore", "sulfur", "crystal", "gems", "gold", "mithril"
|
||||
};
|
||||
@ -84,3 +84,17 @@ namespace ETownType
|
||||
"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";
|
||||
}
|
||||
|
@ -868,18 +868,18 @@ TExpType CGHeroInstance::calculateXp(TExpType exp) const
|
||||
ui8 CGHeroInstance::getSpellSchoolLevel(const CSpell * spell, int *outSelectedSchool) const
|
||||
{
|
||||
si16 skill = -1; //skill level
|
||||
|
||||
|
||||
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)
|
||||
if(thisSchool > skill)
|
||||
{
|
||||
skill = thisSchool;
|
||||
if(outSelectedSchool)
|
||||
*outSelectedSchool = (ui8)cnf.id;
|
||||
}
|
||||
if(thisSchool > skill)
|
||||
{
|
||||
skill = thisSchool;
|
||||
if(outSelectedSchool)
|
||||
*outSelectedSchool = (ui8)cnf.id;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
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
|
||||
|
||||
@ -904,7 +904,7 @@ ui32 CGHeroInstance::getSpellBonus(const CSpell * spell, ui32 base, const CStack
|
||||
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;
|
||||
|
||||
return base;
|
||||
return base;
|
||||
}
|
||||
|
||||
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))
|
||||
return 3;//todo: recheck specialty from where this bonus is. possible bug
|
||||
else
|
||||
return getSpellSchoolLevel(spell);
|
||||
return getSpellSchoolLevel(spell);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
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
|
||||
@ -1107,8 +1107,8 @@ void CGHeroInstance::getOutOffsets(std::vector<int3> &offsets) const
|
||||
{
|
||||
// FIXME: Offsets need to be fixed once we get rid of convertPosition
|
||||
// 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)
|
||||
};
|
||||
}
|
||||
@ -1436,20 +1436,33 @@ void CGHeroInstance::levelUpAutomatically()
|
||||
bool CGHeroInstance::hasVisions(const CGObjectInstance * target, const int subtype) const
|
||||
{
|
||||
//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);
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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));
|
||||
|
||||
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"]);
|
||||
}
|
||||
|
@ -177,7 +177,7 @@ public:
|
||||
double getHeroStrength() const; // includes fighting and magic strength
|
||||
ui64 getTotalStrength() const; // includes fighting strength and army strength
|
||||
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
|
||||
CStackBasicDescriptor calculateNecromancy (const BattleResult &battleResult) const;
|
||||
void showNecromancyDialog(const CStackBasicDescriptor &raisedStack) const;
|
||||
@ -201,23 +201,23 @@ public:
|
||||
void Updatespecialty();
|
||||
void recreateSecondarySkillsBonuses();
|
||||
void updateSkill(SecondarySkill which, int val);
|
||||
|
||||
|
||||
bool hasVisions(const CGObjectInstance * target, const int subtype) const;
|
||||
|
||||
CGHeroInstance();
|
||||
virtual ~CGHeroInstance();
|
||||
|
||||
|
||||
///ArtBearer
|
||||
ArtBearer::ArtBearer bearerType() const override;
|
||||
|
||||
///IBonusBearer
|
||||
CBonusSystemNode *whereShouldBeAttached(CGameState *gs) override;
|
||||
std::string nodeName() const override;
|
||||
|
||||
|
||||
///ISpellCaster
|
||||
ui8 getSpellSchoolLevel(const CSpell * spell, int *outSelectedSchool = nullptr) const override;
|
||||
ui32 getSpellBonus(const CSpell * spell, ui32 base, const CStack * affectedStack) const override;
|
||||
|
||||
|
||||
///default spell school level for effect calculation
|
||||
int getEffectLevel(const CSpell * spell) const override;
|
||||
|
||||
@ -229,9 +229,9 @@ public:
|
||||
|
||||
///damage/heal override(ignores spell configuration, effect level and effect power)
|
||||
int getEffectValue(const CSpell * spell) const override;
|
||||
|
||||
|
||||
const PlayerColor getOwner() const override;
|
||||
|
||||
|
||||
void deserializationFix();
|
||||
|
||||
void initObj() override;
|
||||
@ -239,6 +239,8 @@ public:
|
||||
std::string getObjectName() const override;
|
||||
protected:
|
||||
void setPropertyDer(ui8 what, ui32 val) override;//synchr
|
||||
void writeJsonOptions(JsonNode & json) const override;
|
||||
void readJsonOptions(const JsonNode & json) override;
|
||||
|
||||
private:
|
||||
void levelUpAutomatically();
|
||||
|
@ -683,7 +683,6 @@ void CMapSaverJson::addToArchive(const JsonNode& data, const std::string& filena
|
||||
|
||||
void CMapSaverJson::saveMap(const std::unique_ptr<CMap>& map)
|
||||
{
|
||||
//TODO: saveMap
|
||||
this->map = map.get();
|
||||
writeHeader();
|
||||
writeTerrain();
|
||||
|
Loading…
Reference in New Issue
Block a user