mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	* enum serialization/deserialization (si32 as basetype ought to be enough for anybody)
* some fields in classes refactored to use appropriate enums (not yet finished)
This commit is contained in:
		| @@ -2208,7 +2208,7 @@ void VCAI::striveToGoal(const CGoal &ultimateGoal) | ||||
|  | ||||
| void VCAI::striveToQuest (const QuestInfo &q) | ||||
| { | ||||
| 	if (q.quest->missionType && q.quest->progress < CQuest::COMPLETE) //FIXME: quests are never synchronized. Pointer handling needed | ||||
| 	if (q.quest->missionType && q.quest->progress != CQuest::COMPLETE) //FIXME: quests are never synchronized. Pointer handling needed | ||||
| 	{ | ||||
| 		MetaString ms; | ||||
| 		q.quest->getRolloverText(ms, false); | ||||
|   | ||||
| @@ -195,7 +195,7 @@ void updateStartInfo(std::string filename, StartInfo & sInfo, const CMapHeader * | ||||
| 			else | ||||
| 				pset.heroPortrait = pinfo.customHeroID; | ||||
| 		} | ||||
| 		pset.handicap = 0; | ||||
| 		pset.handicap = PlayerSettings::NO_HANDICAP; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -2355,7 +2355,7 @@ void OptionsTab::nextBonus( int player, int dir ) | ||||
| 	} | ||||
|  | ||||
| 	PlayerSettings &s = SEL->sInfo.playerInfos[player]; | ||||
| 	si8 &ret = s.bonus += dir; | ||||
| 	PlayerSettings::Ebonus &ret = s.bonus = static_cast<PlayerSettings::Ebonus>(static_cast<int>(s.bonus) + dir); | ||||
|  | ||||
| 	if (s.hero==PlayerSettings::NONE && | ||||
| 		!SEL->current->mapHeader->players[s.color].heroesNames.size() && | ||||
|   | ||||
| @@ -175,7 +175,7 @@ public: | ||||
| 	std::vector<si32> activeSpells() const; //returns vector of active spell IDs sorted by time of cast | ||||
| 	const CGHeroInstance *getMyHero() const; //if stack belongs to hero (directly or was by him summoned) returns hero, NULL otherwise | ||||
|  | ||||
| 	static inline Bonus featureGenerator(Bonus::BonusType type, si16 subtype, si32 value, ui16 turnsRemain, si32 additionalInfo = 0, si32 limit = Bonus::NO_LIMIT) | ||||
| 	static inline Bonus featureGenerator(Bonus::BonusType type, si16 subtype, si32 value, ui16 turnsRemain, si32 additionalInfo = 0, Bonus::LimitEffect limit = Bonus::NO_LIMIT) | ||||
| 	{ | ||||
| 		Bonus hb = makeFeatureVal(type, Bonus::N_TURNS, subtype, value, Bonus::SPELL_EFFECT, turnsRemain, additionalInfo); | ||||
| 		hb.effectRange = limit; | ||||
|   | ||||
| @@ -630,7 +630,7 @@ void CArtHandler::getAllowedArts(std::vector<ConstTransitivePtr<CArtifact> > &ou | ||||
| 	} | ||||
| } | ||||
|  | ||||
| Bonus *createBonus(Bonus::BonusType type, int val, int subtype, int valType, shared_ptr<ILimiter> limiter = shared_ptr<ILimiter>(), int additionalInfo = 0) | ||||
| Bonus *createBonus(Bonus::BonusType type, int val, int subtype, Bonus::ValueType valType, shared_ptr<ILimiter> limiter = shared_ptr<ILimiter>(), int additionalInfo = 0) | ||||
| { | ||||
| 	Bonus *added = new Bonus(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,-1,subtype); | ||||
| 	added->additionalInfo = additionalInfo; | ||||
| @@ -648,7 +648,7 @@ Bonus *createBonus(Bonus::BonusType type, int val, int subtype, shared_ptr<IProp | ||||
| 	return added; | ||||
| } | ||||
|  | ||||
| void CArtHandler::giveArtBonus( TArtifactID aid, Bonus::BonusType type, int val, int subtype, int valType, shared_ptr<ILimiter> limiter, int additionalInfo) | ||||
| void CArtHandler::giveArtBonus( TArtifactID aid, Bonus::BonusType type, int val, int subtype, Bonus::ValueType valType, shared_ptr<ILimiter> limiter, int additionalInfo) | ||||
| { | ||||
| 	giveArtBonus(aid, createBonus(type, val, subtype, valType, limiter, additionalInfo)); | ||||
| } | ||||
|   | ||||
| @@ -219,7 +219,7 @@ public: | ||||
|  | ||||
| class DLL_LINKAGE CArtHandler //handles artifacts | ||||
| { | ||||
| 	void giveArtBonus(TArtifactID aid, Bonus::BonusType type, int val, int subtype = -1, int valType = Bonus::BASE_NUMBER, shared_ptr<ILimiter> limiter = shared_ptr<ILimiter>(), int additionalinfo = 0); | ||||
| 	void giveArtBonus(TArtifactID aid, Bonus::BonusType type, int val, int subtype = -1, Bonus::ValueType valType = Bonus::BASE_NUMBER, shared_ptr<ILimiter> limiter = shared_ptr<ILimiter>(), int additionalinfo = 0); | ||||
| 	void giveArtBonus(TArtifactID aid, Bonus::BonusType type, int val, int subtype, shared_ptr<IPropagator> propagator, int additionalinfo = 0); | ||||
| 	void giveArtBonus(TArtifactID aid, Bonus *bonus); | ||||
| public: | ||||
|   | ||||
| @@ -1351,7 +1351,7 @@ void CGameState::init(StartInfo * si) | ||||
| 	{ | ||||
| 		//starting bonus | ||||
| 		if(scenarioOps->playerInfos[k->first].bonus==PlayerSettings::RANDOM) | ||||
| 			scenarioOps->playerInfos[k->first].bonus = ran()%3; | ||||
| 			scenarioOps->playerInfos[k->first].bonus = static_cast<PlayerSettings::Ebonus>(ran()%3); | ||||
| 		switch(scenarioOps->playerInfos[k->first].bonus) | ||||
| 		{ | ||||
| 		case PlayerSettings::GOLD: | ||||
|   | ||||
| @@ -15,6 +15,7 @@ | ||||
| #include "ResourceSet.h" | ||||
| #include "int3.h" | ||||
| #include "CObjectHandler.h" | ||||
| #include "IGameCallback.h" | ||||
|  | ||||
|  | ||||
| /* | ||||
| @@ -162,7 +163,7 @@ struct DLL_LINKAGE SThievesGuildInfo | ||||
| struct DLL_LINKAGE PlayerState : public CBonusSystemNode | ||||
| { | ||||
| public: | ||||
| 	enum EStatus {INGAME, LOSER, WINNER}; | ||||
| 	enum EStatus {WRONG = -1, INGAME, LOSER, WINNER}; | ||||
| 	TPlayerColor color; | ||||
| 	ui8 human; //true if human controlled player, false for AI | ||||
| 	ui32 currentSelection; //id of hero/town, 0xffffffff if none | ||||
| @@ -175,7 +176,7 @@ public: | ||||
| 	std::vector<QuestInfo> quests; //store info about all received quests | ||||
|  | ||||
| 	ui8 enteredWinningCheatCode, enteredLosingCheatCode; //if true, this player has entered cheat codes for loss / victory | ||||
| 	ui8 status; //0 - in game, 1 - loser, 2 - winner <- uses EStatus enum | ||||
| 	EStatus status; | ||||
| 	ui8 daysWithoutCastle; | ||||
|  | ||||
| 	PlayerState(); | ||||
|   | ||||
| @@ -1252,7 +1252,7 @@ void CGHeroInstance::updateSkill(SecondarySkill which, int val) | ||||
| 	} | ||||
|  | ||||
|  | ||||
| 	int skillValType = skillVal ? Bonus::BASE_NUMBER : Bonus::INDEPENDENT_MIN; | ||||
| 	Bonus::ValueType skillValType = skillVal ? Bonus::BASE_NUMBER : Bonus::INDEPENDENT_MIN; | ||||
| 	if(Bonus * b = getBonusList().getFirst(Selector::typeSubtype(Bonus::SECONDARY_SKILL_PREMY, which) && Selector::sourceType(Bonus::SECONDARY_SKILL))) //only local hero bonus | ||||
| 	{ | ||||
| 		b->val = skillVal; | ||||
| @@ -1260,7 +1260,7 @@ void CGHeroInstance::updateSkill(SecondarySkill which, int val) | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		Bonus *bonus = new Bonus(Bonus::PERMANENT, Bonus::SECONDARY_SKILL_PREMY, id, skillVal, ID, which, skillValType); | ||||
| 		Bonus *bonus = new Bonus(Bonus::PERMANENT, Bonus::SECONDARY_SKILL_PREMY, Bonus::SECONDARY_SKILL, skillVal, id, which, skillValType); | ||||
| 		bonus->source = Bonus::SECONDARY_SKILL; | ||||
| 		addNewBonus(bonus); | ||||
| 	} | ||||
| @@ -4444,7 +4444,7 @@ void CGSeerHut::initObj() | ||||
| { | ||||
| 	seerName = VLC->generaltexth->seerNames[ran()%VLC->generaltexth->seerNames.size()]; | ||||
| 	quest->textOption = ran()%3; | ||||
| 	quest->progress = 0; | ||||
| 	quest->progress = CQuest::NOT_ACTIVE; | ||||
| 	if (quest->missionType) | ||||
| 	{ | ||||
| 		if (!quest->isCustomFirst) | ||||
| @@ -4471,7 +4471,7 @@ const std::string & CGSeerHut::getHoverText() const | ||||
| 	switch (ID) | ||||
| 	{ | ||||
| 	case Obj::SEER_HUT: | ||||
| 		if (quest->progress) | ||||
| 		if (quest->progress != CQuest::NOT_ACTIVE) | ||||
| 		{ | ||||
| 			hoverName = VLC->generaltexth->allTexts[347]; | ||||
| 			boost::algorithm::replace_first(hoverName,"%s", seerName); | ||||
| @@ -4526,25 +4526,25 @@ void CGSeerHut::getCompletionText(MetaString &text, std::vector<Component> &comp | ||||
| 	quest->getCompletionText (text, components, isCustom, h); | ||||
| 	switch (rewardType) | ||||
| 	{ | ||||
| 		case 1: components.push_back(Component (Component::EXPERIENCE, 0, h->calculateXp(rVal), 0)); | ||||
| 		case EXPERIENCE: components.push_back(Component (Component::EXPERIENCE, 0, h->calculateXp(rVal), 0)); | ||||
| 			break; | ||||
| 		case 2: components.push_back(Component (Component::PRIM_SKILL, 5, rVal, 0)); | ||||
| 		case MANA_POINTS: components.push_back(Component (Component::PRIM_SKILL, 5, rVal, 0)); | ||||
| 			break; | ||||
| 		case 3: components.push_back(Component (Component::MORALE, 0, rVal, 0)); | ||||
| 		case MORALE_BONUS: components.push_back(Component (Component::MORALE, 0, rVal, 0)); | ||||
| 			break; | ||||
| 		case 4: components.push_back(Component (Component::LUCK, 0, rVal, 0)); | ||||
| 		case LUCK_BONUS: components.push_back(Component (Component::LUCK, 0, rVal, 0)); | ||||
| 			break; | ||||
| 		case 5: components.push_back(Component (Component::RESOURCE, rID, rVal, 0)); | ||||
| 		case RESOURCES: components.push_back(Component (Component::RESOURCE, rID, rVal, 0)); | ||||
| 			break; | ||||
| 		case 6: components.push_back(Component (Component::PRIM_SKILL, rID, rVal, 0)); | ||||
| 		case PRIMARY_SKILL: components.push_back(Component (Component::PRIM_SKILL, rID, rVal, 0)); | ||||
| 			break; | ||||
| 		case 7: components.push_back(Component (Component::SEC_SKILL, rID, rVal, 0)); | ||||
| 		case SECONDARY_SKILL: components.push_back(Component (Component::SEC_SKILL, rID, rVal, 0)); | ||||
| 			break; | ||||
| 		case 8: components.push_back(Component (Component::ARTIFACT, rID, 0, 0)); | ||||
| 		case ARTIFACT: components.push_back(Component (Component::ARTIFACT, rID, 0, 0)); | ||||
| 			break; | ||||
| 		case 9: components.push_back(Component (Component::SPELL, rID, 0, 0)); | ||||
| 		case SPELL: components.push_back(Component (Component::SPELL, rID, 0, 0)); | ||||
| 			break; | ||||
| 		case 10: components.push_back(Component (Component::CREATURE, rID, rVal, 0)); | ||||
| 		case CREATURE: components.push_back(Component (Component::CREATURE, rID, rVal, 0)); | ||||
| 			break; | ||||
| 	} | ||||
| } | ||||
| @@ -4554,7 +4554,7 @@ void CGSeerHut::setPropertyDer (ui8 what, ui32 val) | ||||
| 	switch (what) | ||||
| 	{ | ||||
| 		case 10: | ||||
| 			quest->progress = val; | ||||
| 			quest->progress = static_cast<CQuest::Eprogress>(val); | ||||
| 			break; | ||||
| 		case 11: | ||||
| 			quest->missionType = CQuest::MISSION_NONE; | ||||
| @@ -4685,18 +4685,18 @@ void CGSeerHut::completeQuest (const CGHeroInstance * h) const //reward | ||||
| { | ||||
| 	switch (rewardType) | ||||
| 	{ | ||||
| 		case 1: //experience | ||||
| 		case EXPERIENCE: | ||||
| 		{ | ||||
| 			TExpType expVal = h->calculateXp(rVal); | ||||
| 			cb->changePrimSkill(h->id, 4, expVal, false); | ||||
| 			break; | ||||
| 		} | ||||
| 		case 2: //mana points | ||||
| 		case MANA_POINTS: | ||||
| 		{ | ||||
| 			cb->setManaPoints(h->id, h->mana+rVal); | ||||
| 			break; | ||||
| 		} | ||||
| 		case 3: case 4: //morale /luck | ||||
| 		case MORALE_BONUS: case LUCK_BONUS: | ||||
| 		{ | ||||
| 			Bonus hb(Bonus::ONE_WEEK, (rewardType == 3 ? Bonus::MORALE : Bonus::LUCK), | ||||
| 				Bonus::OBJECT, rVal, h->id, "", -1); | ||||
| @@ -4706,26 +4706,26 @@ void CGSeerHut::completeQuest (const CGHeroInstance * h) const //reward | ||||
| 			cb->giveHeroBonus(&gb); | ||||
| 		} | ||||
| 			break; | ||||
| 		case 5: //resources | ||||
| 		case RESOURCES: | ||||
| 			cb->giveResource(h->getOwner(), rID, rVal); | ||||
| 			break; | ||||
| 		case 6: //main ability bonus (attak, defence etd.) | ||||
| 		case PRIMARY_SKILL: | ||||
| 			cb->changePrimSkill(h->id, rID, rVal, false); | ||||
| 			break; | ||||
| 		case 7: // secondary ability gain | ||||
| 		case SECONDARY_SKILL: | ||||
| 			cb->changeSecSkill(h->id, rID, rVal, false); | ||||
| 			break; | ||||
| 		case 8: // artifact | ||||
| 		case ARTIFACT: | ||||
| 			cb->giveHeroNewArtifact(h, VLC->arth->artifacts[rID],-2); | ||||
| 			break; | ||||
| 		case 9:// spell | ||||
| 		case SPELL: | ||||
| 		{ | ||||
| 			std::set<ui32> spell; | ||||
| 			spell.insert (rID); | ||||
| 			cb->changeSpells(h->id, true, spell); | ||||
| 		} | ||||
| 			break; | ||||
| 		case 10:// creature | ||||
| 		case CREATURE: | ||||
| 			{ | ||||
| 				CCreatureSet creatures; | ||||
| 				creatures.setCreature(0, rID, rVal); | ||||
| @@ -4758,7 +4758,7 @@ const CGCreature * CGSeerHut::getCreatureToKill(bool allowNull) const | ||||
| void CGQuestGuard::initObj() | ||||
| { | ||||
| 	blockVisit = true; | ||||
| 	quest->progress = 0; | ||||
| 	quest->progress = CQuest::NOT_ACTIVE; | ||||
| 	quest->textOption = ran()%3 + 3; //3-5 | ||||
| 	if (quest->missionType) | ||||
| 	{ | ||||
| @@ -5534,17 +5534,17 @@ void CGSignBottle::onHeroVisit( const CGHeroInstance * h ) const | ||||
| void CGScholar::onHeroVisit( const CGHeroInstance * h ) const | ||||
| { | ||||
|  | ||||
| 	int type = bonusType; | ||||
| 	EBonusType type = bonusType; | ||||
| 	int bid = bonusID; | ||||
| 	//check if the bonus if applicable, if not - give primary skill (always possible) | ||||
| 	int ssl = h->getSecSkillLevel(static_cast<CGHeroInstance::SecondarySkill>(bid)); //current sec skill level, used if bonusType == 1 | ||||
| 	if((type == 1 | ||||
| 	if((type == SECONDARY_SKILL | ||||
| 			&& ((ssl == 3)  ||  (!ssl  &&  !h->canLearnSkill()))) ////hero already has expert level in the skill or (don't know skill and doesn't have free slot) | ||||
| 		|| (type == 2  &&  (!h->getArt(17) || vstd::contains(h->spells, (ui32) bid) | ||||
| 		|| (type == SPELL  &&  (!h->getArt(17) || vstd::contains(h->spells, (ui32) bid) | ||||
| 		|| (VLC->spellh->spells[bid]->level > h->getSecSkillLevel(CGHeroInstance::WISDOM) + 2) | ||||
| 		))) //hero doesn't have a spellbook or already knows the spell or doesn't have Wisdom | ||||
| 	{ | ||||
| 		type = 0; | ||||
| 		type = PRIM_SKILL; | ||||
| 		bid = ran() % GameConstants::PRIMARY_SKILLS; | ||||
| 	} | ||||
|  | ||||
| @@ -5556,15 +5556,15 @@ void CGScholar::onHeroVisit( const CGHeroInstance * h ) const | ||||
|  | ||||
| 	switch (type) | ||||
| 	{ | ||||
| 	case 0: | ||||
| 	case PRIM_SKILL: | ||||
| 		cb->changePrimSkill(h->id,bid,+1); | ||||
| 		iw.components.push_back(Component(Component::PRIM_SKILL,bid,+1,0)); | ||||
| 		break; | ||||
| 	case 1: | ||||
| 	case SECONDARY_SKILL: | ||||
| 		cb->changeSecSkill(h->id,bid,+1); | ||||
| 		iw.components.push_back(Component(Component::SEC_SKILL,bid,ssl+1,0)); | ||||
| 		break; | ||||
| 	case 2: | ||||
| 	case SPELL: | ||||
| 		{ | ||||
| 			std::set<ui32> hlp; | ||||
| 			hlp.insert(bid); | ||||
| @@ -5584,18 +5584,18 @@ void CGScholar::onHeroVisit( const CGHeroInstance * h ) const | ||||
| void CGScholar::initObj() | ||||
| { | ||||
| 	blockVisit = true; | ||||
| 	if(bonusType == 255) | ||||
| 	if(bonusType == RANDOM) | ||||
| 	{ | ||||
| 		bonusType = ran()%3; | ||||
| 		bonusType = static_cast<EBonusType>(ran()%3); | ||||
| 		switch(bonusType) | ||||
| 		{ | ||||
| 		case 0: | ||||
| 		case PRIM_SKILL: | ||||
| 			bonusID = ran() % GameConstants::PRIMARY_SKILLS; | ||||
| 			break; | ||||
| 		case 1: | ||||
| 		case SECONDARY_SKILL: | ||||
| 			bonusID = ran() % GameConstants::SKILL_QUANTITY; | ||||
| 			break; | ||||
| 		case 2: | ||||
| 		case SPELL: | ||||
| 			std::vector<ui16> possibilities; | ||||
| 			for (int i = 1; i < 6; ++i) | ||||
| 				cb->getAllowedSpells (possibilities, i); | ||||
|   | ||||
| @@ -57,7 +57,8 @@ public: | ||||
|  | ||||
| 	si32 qid; //unique quets id for serialization / identification | ||||
|  | ||||
| 	ui8 missionType, progress; | ||||
| 	Emission missionType; | ||||
| 	Eprogress progress; | ||||
| 	si32 lastDay; //after this day (first day is 0) mission cannot be completed; if -1 - no limit | ||||
|  | ||||
| 	ui32 m13489val; | ||||
| @@ -76,7 +77,7 @@ public: | ||||
| 	std::string firstVisitText, nextVisitText, completedText; | ||||
| 	bool isCustomFirst, isCustomNext, isCustomComplete; | ||||
|  | ||||
| 	CQuest(){missionType = 0;}; //default constructor | ||||
| 	CQuest(){missionType = MISSION_NONE;}; //default constructor | ||||
|  | ||||
| 	virtual bool checkQuest (const CGHeroInstance * h) const; //determines whether the quest is complete or not | ||||
| 	virtual void getVisitText (MetaString &text, std::vector<Component> &components, bool isCustom, bool FirstVisit, const CGHeroInstance * h = NULL) const; | ||||
| @@ -737,7 +738,7 @@ public: | ||||
| 	si8 character; //character of this set of creatures (0 - the most friendly, 4 - the most hostile) => on init changed to -4 (compliant) ... 10 value (savage) | ||||
| 	std::string message; //message printed for attacking hero | ||||
| 	std::vector<ui32> resources; //[res_id], resources given to hero that has won with monsters | ||||
| 	si32 gainedArtifact; //ID of artifact gained to hero, -1 if none | ||||
| 	TArtifactID gainedArtifact; //ID of artifact gained to hero, -1 if none | ||||
| 	ui8 neverFlees; //if true, the troops will never flee | ||||
| 	ui8 notGrowingTeam; //if true, number of units won't grow | ||||
| 	ui64 temppower; //used to handle fractional stack growth for tiny stacks | ||||
| @@ -811,7 +812,8 @@ public: | ||||
| class DLL_LINKAGE CGSeerHut : public CArmedInstance, public IQuestObject //army is used when giving reward | ||||
| { | ||||
| public: | ||||
| 	ui8 rewardType; //type of reward: 0 - no reward; 1 - experience; 2 - mana points; 3 - morale bonus; 4 - luck bonus; 5 - resources; 6 - main ability bonus (attak, defence etd.); 7 - secondary ability gain; 8 - artifact; 9 - spell; 10 - creature | ||||
| 	enum ERewardType {NOTHING, EXPERIENCE, MANA_POINTS, MORALE_BONUS, LUCK_BONUS, RESOURCES, PRIMARY_SKILL, SECONDARY_SKILL, ARTIFACT, SPELL, CREATURE}; | ||||
| 	ERewardType rewardType; | ||||
| 	si32 rID; //reward ID | ||||
| 	si32 rVal; //reward value | ||||
| 	std::string seerName; | ||||
| @@ -873,7 +875,8 @@ public: | ||||
| class DLL_LINKAGE CGScholar : public CGObjectInstance | ||||
| { | ||||
| public: | ||||
| 	ui8 bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell | ||||
| 	enum EBonusType {PRIM_SKILL, SECONDARY_SKILL, SPELL, RANDOM = 255}; | ||||
| 	EBonusType bonusType; | ||||
| 	ui16 bonusID; //ID of skill/spell | ||||
|  | ||||
| //	void giveAnyBonus(const CGHeroInstance * h) const; //TODO: remove | ||||
|   | ||||
| @@ -75,6 +75,7 @@ enum SerializationLvl | ||||
| 	Primitive, | ||||
| 	Array, | ||||
| 	Pointer, | ||||
| 	Enum, | ||||
| 	Serializable | ||||
| }; | ||||
|  | ||||
| @@ -133,6 +134,23 @@ struct SaveSerializable | ||||
| 		s.saveSerializable(data); | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| template<typename Ser,typename T> | ||||
| struct SaveEnum | ||||
| { | ||||
| 	static void invoke(Ser &s, const T &data) | ||||
| 	{ | ||||
| 		s.saveEnum(data); | ||||
| 	} | ||||
| }; | ||||
| template<typename Ser,typename T> | ||||
| struct LoadEnum | ||||
| { | ||||
| 	static void invoke(Ser &s, T &data) | ||||
| 	{ | ||||
| 		s.loadEnum(data); | ||||
| 	} | ||||
| }; | ||||
| template<typename Ser,typename T> | ||||
| struct LoadPrimitive | ||||
| { | ||||
| @@ -208,6 +226,10 @@ struct SerializationLevel | ||||
| 			boost::is_fundamental<T>, | ||||
| 			mpl::int_<Primitive>, | ||||
| 		//else | ||||
| 		typename mpl::eval_if< | ||||
| 			boost::is_enum<T>, | ||||
| 			mpl::int_<Enum>, | ||||
| 		//else | ||||
| 		typename mpl::eval_if< | ||||
| 			boost::is_class<T>, | ||||
| 			mpl::int_<Serializable>, | ||||
| @@ -229,6 +251,7 @@ struct SerializationLevel | ||||
| 		> | ||||
| 		> | ||||
| 		> | ||||
| 		> | ||||
| 		>::type type; | ||||
| 	static const int value = SerializationLevel::type::value; | ||||
| }; | ||||
| @@ -562,6 +585,9 @@ public: | ||||
| 			typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Primitive> >, | ||||
| 			mpl::identity<SavePrimitive<Serializer,T> >, | ||||
| 			//else if | ||||
| 			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Enum> >, | ||||
| 			mpl::identity<SaveEnum<Serializer,T> >, | ||||
| 			//else if | ||||
| 			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Pointer> >, | ||||
| 			mpl::identity<SavePointer<Serializer,T> >, | ||||
| 			//else if | ||||
| @@ -575,6 +601,7 @@ public: | ||||
| 			> | ||||
| 			> | ||||
| 			> | ||||
| 			> | ||||
| 			>::type typex; | ||||
| 		typex::invoke(* this->This(), data); | ||||
| 	} | ||||
| @@ -656,6 +683,12 @@ public: | ||||
| 		VariantVisitorSaver<Serializer> visitor(*this->This()); | ||||
| 		boost::apply_visitor(visitor, data); | ||||
| 	} | ||||
| 	template <typename E> | ||||
| 	void saveEnum(const E &data) | ||||
| 	{ | ||||
| 		si32 writ = static_cast<si32>(data); | ||||
| 		*this << writ; | ||||
| 	} | ||||
| }; | ||||
|  | ||||
|  | ||||
| @@ -748,6 +781,9 @@ public: | ||||
| 			typename mpl::eval_if< mpl::equal_to<SerializationLevel<T>,mpl::int_<Primitive> >, | ||||
| 			mpl::identity<LoadPrimitive<Serializer,T> >, | ||||
| 			//else if | ||||
| 			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Enum> >, | ||||
| 			mpl::identity<LoadEnum<Serializer,T> >, | ||||
| 			//else if | ||||
| 			typename mpl::eval_if<mpl::equal_to<SerializationLevel<T>,mpl::int_<Pointer> >, | ||||
| 			mpl::identity<LoadPointer<Serializer,T> >, | ||||
| 			//else if | ||||
| @@ -761,6 +797,7 @@ public: | ||||
| 			> | ||||
| 			> | ||||
| 			> | ||||
| 			> | ||||
| 			>::type typex; | ||||
| 		typex::invoke(* this->This(), data); | ||||
| 	} | ||||
| @@ -1005,6 +1042,13 @@ public: | ||||
| 			loadSerializableBySerializeCall(s); | ||||
| 	} | ||||
|  | ||||
| 	template <typename E> | ||||
| 	void loadEnum(E &data) | ||||
| 	{ | ||||
| 		si32 read; | ||||
| 		*this >> read; | ||||
| 		data = static_cast<E>(read); | ||||
| 	} | ||||
| }; | ||||
|  | ||||
| class DLL_LINKAGE CSaveFile | ||||
|   | ||||
| @@ -359,7 +359,7 @@ void IBonusBearer::getModifiersWDescr(TModDescr &out, const CSelector &selector, | ||||
| { | ||||
| 	getBonuses(selector, cachingStr)->getModifiersWDescr(out); | ||||
| } | ||||
| int IBonusBearer::getBonusesCount(int from, int id) const | ||||
| int IBonusBearer::getBonusesCount(Bonus::BonusSource from, int id) const | ||||
| { | ||||
| 	std::stringstream cachingStr; | ||||
| 	cachingStr << "source_" << from << "id_" << id; | ||||
| @@ -381,7 +381,7 @@ const TBonusListPtr IBonusBearer::getBonuses(const CSelector &selector, const CS | ||||
| 	return getAllBonuses(selector, limit, NULL, cachingStr); | ||||
| } | ||||
|  | ||||
| bool IBonusBearer::hasBonusFrom(ui8 source, ui32 sourceID) const | ||||
| bool IBonusBearer::hasBonusFrom(Bonus::BonusSource source, ui32 sourceID) const | ||||
| { | ||||
| 	std::stringstream cachingStr; | ||||
| 	cachingStr << "source_" << source << "id_" << sourceID; | ||||
| @@ -1087,7 +1087,7 @@ void NBonus::getModifiersWDescr(const CBonusSystemNode *obj, TModDescr &out, Bon | ||||
| 		return obj->getModifiersWDescr(out, type, subtype); | ||||
| } | ||||
|  | ||||
| int NBonus::getCount(const CBonusSystemNode *obj, int from, int id) | ||||
| int NBonus::getCount(const CBonusSystemNode *obj, Bonus::BonusSource from, int id) | ||||
| { | ||||
| 	if(obj) | ||||
| 		return obj->getBonusesCount(from, id); | ||||
| @@ -1128,7 +1128,7 @@ std::string Bonus::Description() const | ||||
| 	return str.str(); | ||||
| } | ||||
|  | ||||
| Bonus::Bonus(ui16 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype/*=-1*/)  | ||||
| Bonus::Bonus(ui16 Dur, ui8 Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype/*=-1*/)  | ||||
| 	: duration(Dur), type(Type), subtype(Subtype), source(Src), val(Val), sid(ID), description(Desc) | ||||
| { | ||||
| 	additionalInfo = -1; | ||||
| @@ -1138,7 +1138,7 @@ Bonus::Bonus(ui16 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, std::string Desc, s | ||||
| 	boost::algorithm::trim(description); | ||||
| } | ||||
|  | ||||
| Bonus::Bonus(ui16 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, si32 Subtype/*=-1*/, ui8 ValType /*= ADDITIVE_VALUE*/)  | ||||
| Bonus::Bonus(ui16 Dur, ui8 Type, BonusSource Src, si32 Val, ui32 ID, si32 Subtype/*=-1*/, ValueType ValType /*= ADDITIVE_VALUE*/)  | ||||
| 	: duration(Dur), type(Type), subtype(Subtype), source(Src), val(Val), sid(ID), valType(ValType) | ||||
| { | ||||
| 	additionalInfo = -1; | ||||
| @@ -1180,8 +1180,8 @@ namespace Selector | ||||
| 	DLL_LINKAGE CSelectFieldEqual<TBonusSubtype> subtype(&Bonus::subtype, 0); | ||||
| 	DLL_LINKAGE CSelectFieldEqual<si32> info(&Bonus::additionalInfo, 0); | ||||
| 	DLL_LINKAGE CSelectFieldEqual<ui16> duration(&Bonus::duration, 0); | ||||
| 	DLL_LINKAGE CSelectFieldEqual<ui8> sourceType(&Bonus::source, 0); | ||||
| 	DLL_LINKAGE CSelectFieldEqual<ui8> effectRange(&Bonus::effectRange, Bonus::NO_LIMIT); | ||||
| 	DLL_LINKAGE CSelectFieldEqual<Bonus::BonusSource> sourceType(&Bonus::source, Bonus::OTHER); | ||||
| 	DLL_LINKAGE CSelectFieldEqual<Bonus::LimitEffect> effectRange(&Bonus::effectRange, Bonus::NO_LIMIT); | ||||
| 	DLL_LINKAGE CWillLastTurns turns; | ||||
|  | ||||
| 	CSelector DLL_LINKAGE typeSubtype(TBonusType Type, TBonusSubtype Subtype) | ||||
| @@ -1194,9 +1194,9 @@ namespace Selector | ||||
| 		return CSelectFieldEqual<TBonusType>(&Bonus::type, type) && CSelectFieldEqual<TBonusSubtype>(&Bonus::subtype, subtype) && CSelectFieldEqual<si32>(&Bonus::additionalInfo, info); | ||||
| 	} | ||||
|  | ||||
| 	CSelector DLL_LINKAGE source(ui8 source, ui32 sourceID) | ||||
| 	CSelector DLL_LINKAGE source(Bonus::BonusSource source, ui32 sourceID) | ||||
| 	{ | ||||
| 		return CSelectFieldEqual<ui8>(&Bonus::source, source) && CSelectFieldEqual<ui32>(&Bonus::sid, sourceID); | ||||
| 		return CSelectFieldEqual<Bonus::BonusSource>(&Bonus::source, source) && CSelectFieldEqual<ui32>(&Bonus::sid, sourceID); | ||||
| 	} | ||||
|  | ||||
| 	CSelector DLL_EXPORT durationType(ui16 duration) | ||||
| @@ -1204,9 +1204,9 @@ namespace Selector | ||||
| 		return CSelectFieldEqual<ui16>(&Bonus::duration, duration); | ||||
| 	} | ||||
|  | ||||
| 	CSelector DLL_LINKAGE sourceTypeSel(ui8 source) | ||||
| 	CSelector DLL_LINKAGE sourceTypeSel(Bonus::BonusSource source) | ||||
| 	{ | ||||
| 		return CSelectFieldEqual<ui8>(&Bonus::source, source); | ||||
| 		return CSelectFieldEqual<Bonus::BonusSource>(&Bonus::source, source); | ||||
| 	} | ||||
|  | ||||
| 	bool DLL_LINKAGE matchesType(const CSelector &sel, TBonusType type) | ||||
|   | ||||
| @@ -18,14 +18,11 @@ struct Bonus; | ||||
| class CBonusSystemNode; | ||||
| class ILimiter; | ||||
| class IPropagator; | ||||
| class ICalculator; | ||||
| class BonusList; | ||||
| struct BonusCalculationContext; | ||||
|  | ||||
| typedef shared_ptr<BonusList> TBonusListPtr; | ||||
| typedef shared_ptr<ILimiter> TLimiterPtr; | ||||
| typedef shared_ptr<IPropagator> TPropagatorPtr; | ||||
| typedef shared_ptr<ICalculator> TCalculatorPtr; | ||||
| typedef std::vector<std::pair<int,std::string> > TModDescr; //modifiers values and their descriptions | ||||
| typedef std::set<CBonusSystemNode*> TNodes; | ||||
| typedef std::set<const CBonusSystemNode*> TCNodes; | ||||
| @@ -258,22 +255,21 @@ struct DLL_LINKAGE Bonus | ||||
| 	TBonusType type; //uses BonusType values - says to what is this bonus - 1 byte | ||||
| 	TBonusSubtype subtype; //-1 if not applicable - 4 bytes | ||||
|  | ||||
| 	ui8 source;//source type" uses BonusSource values - what gave that bonus | ||||
| 	BonusSource source;//source type" uses BonusSource values - what gave that bonus | ||||
| 	si32 val; | ||||
| 	ui32 sid; //source id: id of object/artifact/spell | ||||
| 	ui8 valType; //by ValueType enum | ||||
| 	ValueType valType; | ||||
|  | ||||
| 	si32 additionalInfo; | ||||
| 	ui8 effectRange; //if not NO_LIMIT, bonus will be omitted by default | ||||
| 	LimitEffect effectRange; //if not NO_LIMIT, bonus will be omitted by default | ||||
|  | ||||
| 	TLimiterPtr limiter; | ||||
| 	TPropagatorPtr propagator; | ||||
| 	TCalculatorPtr calculator; | ||||
|  | ||||
| 	std::string description; | ||||
|  | ||||
| 	Bonus(ui16 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype=-1); | ||||
| 	Bonus(ui16 Dur, ui8 Type, ui8 Src, si32 Val, ui32 ID, si32 Subtype=-1, ui8 ValType = ADDITIVE_VALUE); | ||||
| 	Bonus(ui16 Dur, ui8 Type, BonusSource Src, si32 Val, ui32 ID, std::string Desc, si32 Subtype=-1); | ||||
| 	Bonus(ui16 Dur, ui8 Type, BonusSource Src, si32 Val, ui32 ID, si32 Subtype=-1, ValueType ValType = ADDITIVE_VALUE); | ||||
| 	Bonus(); | ||||
| 	~Bonus(); | ||||
|  | ||||
| @@ -292,7 +288,6 @@ struct DLL_LINKAGE Bonus | ||||
| 	template <typename Handler> void serialize(Handler &h, const int version) | ||||
| 	{ | ||||
| 		h & duration & type & subtype & source & val & sid & description & additionalInfo & turnsRemain & valType & effectRange & limiter & propagator; | ||||
| 		h & calculator; | ||||
| 	} | ||||
|  | ||||
| 	static bool compareByAdditionalInfo(const Bonus *a, const Bonus *b) | ||||
| @@ -528,9 +523,9 @@ public: | ||||
| 	int valOfBonuses(Bonus::BonusType type, const CSelector &selector) const; | ||||
| 	int valOfBonuses(Bonus::BonusType type, int subtype = -1) const; //subtype -> subtype of bonus, if -1 then anyt; | ||||
| 	bool hasBonusOfType(Bonus::BonusType type, int subtype = -1) const;//determines if hero has a bonus of given type (and optionally subtype) | ||||
| 	bool hasBonusFrom(ui8 source, ui32 sourceID) const; | ||||
| 	bool hasBonusFrom(Bonus::BonusSource source, ui32 sourceID) const; | ||||
| 	void getModifiersWDescr( TModDescr &out, Bonus::BonusType type, int subtype = -1 ) const;  //out: pairs<modifier value, modifier description> | ||||
| 	int getBonusesCount(int from, int id) const; | ||||
| 	int getBonusesCount(Bonus::BonusSource from, int id) const; | ||||
|  | ||||
| 	//various hlp functions for non-trivial values | ||||
| 	ui32 getMinDamage() const; //used for stacks and creatures only | ||||
| @@ -658,7 +653,7 @@ namespace NBonus | ||||
| 	DLL_LINKAGE bool hasOfType(const CBonusSystemNode *obj, Bonus::BonusType type, int subtype = -1);//determines if hero has a bonus of given type (and optionally subtype) | ||||
| 	//DLL_LINKAGE const HeroBonus * get(const CBonusSystemNode *obj, int from, int id ); | ||||
| 	DLL_LINKAGE void getModifiersWDescr(const CBonusSystemNode *obj, TModDescr &out, Bonus::BonusType type, int subtype = -1 );  //out: pairs<modifier value, modifier description> | ||||
| 	DLL_LINKAGE int getCount(const CBonusSystemNode *obj, int from, int id); | ||||
| 	DLL_LINKAGE int getCount(const CBonusSystemNode *obj, Bonus::BonusSource from, int id); | ||||
| } | ||||
|  | ||||
| /// generates HeroBonus from given data | ||||
| @@ -888,15 +883,15 @@ namespace Selector | ||||
| 	extern DLL_LINKAGE CSelectFieldEqual<TBonusSubtype> subtype; | ||||
| 	extern DLL_LINKAGE CSelectFieldEqual<si32> info; | ||||
| 	extern DLL_LINKAGE CSelectFieldEqual<ui16> duration; | ||||
| 	extern DLL_LINKAGE CSelectFieldEqual<ui8> sourceType; | ||||
| 	extern DLL_LINKAGE CSelectFieldEqual<ui8> effectRange; | ||||
| 	extern DLL_LINKAGE CSelectFieldEqual<Bonus::BonusSource> sourceType; | ||||
| 	extern DLL_LINKAGE CSelectFieldEqual<Bonus::LimitEffect> effectRange; | ||||
| 	extern DLL_LINKAGE CWillLastTurns turns; | ||||
|  | ||||
| 	CSelector DLL_LINKAGE typeSubtype(TBonusType Type, TBonusSubtype Subtype); | ||||
| 	CSelector DLL_LINKAGE typeSubtypeInfo(TBonusType type, TBonusSubtype subtype, si32 info); | ||||
| 	CSelector DLL_LINKAGE source(ui8 source, ui32 sourceID); | ||||
| 	CSelector DLL_LINKAGE source(Bonus::BonusSource source, ui32 sourceID); | ||||
| 	CSelector DLL_LINKAGE durationType(ui16 duration); | ||||
| 	CSelector DLL_LINKAGE sourceTypeSel(ui8 source); | ||||
| 	CSelector DLL_LINKAGE sourceTypeSel(Bonus::BonusSource source); | ||||
|  | ||||
| 	bool DLL_LINKAGE matchesType(const CSelector &sel, TBonusType type); | ||||
| 	bool DLL_LINKAGE matchesTypeSubtype(const CSelector &sel, TBonusType type, TBonusSubtype subtype); | ||||
| @@ -907,17 +902,6 @@ extern DLL_LINKAGE const std::map<std::string, int> bonusNameMap, bonusValueMap, | ||||
| extern DLL_LINKAGE const bmap<std::string, TLimiterPtr> bonusLimiterMap; | ||||
| extern DLL_LINKAGE const bmap<std::string, TPropagatorPtr> bonusPropagatorMap; | ||||
|  | ||||
| class DLL_LINKAGE ICalculator //calculate value of bonus on-the-fly | ||||
| { | ||||
| public: | ||||
| 	enum EDecision {ACCEPT, DISCARD, NOT_SURE}; | ||||
|  | ||||
| 	virtual si32 val(const BonusCalculationContext &context) const {return 0;}; | ||||
| 	virtual ~ICalculator(){}; | ||||
|  | ||||
| 	template <typename Handler> void serialize(Handler &h, const int version) | ||||
| 	{} | ||||
| }; | ||||
|  | ||||
| // BonusList template that requires full interface of CBonusSystemNode | ||||
| template <class InputIterator> | ||||
|   | ||||
| @@ -989,7 +989,7 @@ Bonus * JsonUtils::parseBonus (const JsonNode &ability) | ||||
|  | ||||
| 	value = &ability["valueType"]; | ||||
| 	if (!value->isNull()) | ||||
| 		b->valType = parseByMap(bonusValueMap, value, "value type "); | ||||
| 		b->valType = static_cast<Bonus::ValueType>(parseByMap(bonusValueMap, value, "value type ")); | ||||
|  | ||||
| 	resolveIdentifier (b->additionalInfo, ability, "addInfo"); | ||||
|  | ||||
| @@ -1007,7 +1007,7 @@ Bonus * JsonUtils::parseBonus (const JsonNode &ability) | ||||
|  | ||||
| 	value = &ability["effectRange"]; | ||||
| 	if (!value->isNull()) | ||||
| 		b->effectRange = parseByMap(bonusLimitEffect, value, "effect range "); | ||||
| 		b->effectRange = static_cast<Bonus::LimitEffect>(parseByMap(bonusLimitEffect, value, "effect range ")); | ||||
|  | ||||
| 	value = &ability["duration"]; | ||||
| 	if (!value->isNull()) | ||||
| @@ -1034,7 +1034,7 @@ Bonus * JsonUtils::parseBonus (const JsonNode &ability) | ||||
|  | ||||
| 	value = &ability["source"]; | ||||
| 	if (!value->isNull()) | ||||
| 		b->source = parseByMap(bonusSourceMap, value, "source type "); | ||||
| 		b->source = static_cast<Bonus::BonusSource>(parseByMap(bonusSourceMap, value, "source type ")); | ||||
|  | ||||
| 	value = &ability["limiters"]; | ||||
| 	if (!value->isNull()) | ||||
|   | ||||
| @@ -1312,7 +1312,7 @@ void CMapLoaderH3M::readObjects() | ||||
| 			{ | ||||
| 				CGScholar * sch = new CGScholar(); | ||||
| 				nobj = sch; | ||||
| 				sch->bonusType = buffer[pos++]; | ||||
| 				sch->bonusType = static_cast<CGScholar::EBonusType>(buffer[pos++]); | ||||
| 				sch->bonusID = buffer[pos++]; | ||||
| 				pos += 6; | ||||
| 				break; | ||||
| @@ -2046,7 +2046,7 @@ CGSeerHut * CMapLoaderH3M::readSeerHut() | ||||
| 	{ | ||||
| 		ui8 rewardType = buffer[pos]; | ||||
| 		++pos; | ||||
| 		hut->rewardType = rewardType; | ||||
| 		hut->rewardType = static_cast<CGSeerHut::ERewardType>(rewardType); | ||||
|  | ||||
| 		switch(rewardType) | ||||
| 		{ | ||||
| @@ -2151,7 +2151,7 @@ CGSeerHut * CMapLoaderH3M::readSeerHut() | ||||
|  | ||||
| void CMapLoaderH3M::readQuest(IQuestObject * guard) | ||||
| { | ||||
| 	guard->quest->missionType = buffer[pos]; | ||||
| 	guard->quest->missionType = static_cast<CQuest::Emission>(buffer[pos]); | ||||
| 	++pos; | ||||
|  | ||||
| 	switch(guard->quest->missionType) | ||||
|   | ||||
| @@ -248,7 +248,7 @@ DLL_LINKAGE void ChangeObjPos::applyGs( CGameState *gs ) | ||||
| DLL_LINKAGE void PlayerEndsGame::applyGs( CGameState *gs ) | ||||
| { | ||||
| 	PlayerState *p = gs->getPlayer(player); | ||||
| 	p->status = victory ? 2 : 1; | ||||
| 	p->status = victory ? PlayerState::WINNER : PlayerState::LOSER; | ||||
| } | ||||
|  | ||||
| DLL_LINKAGE void RemoveBonus::applyGs( CGameState *gs ) | ||||
|   | ||||
| @@ -29,15 +29,15 @@ struct PlayerSettings | ||||
| 		RESOURCE =  2 | ||||
| 	}; | ||||
|  | ||||
| 	//uses enum type Ebonus | ||||
| 	si8 bonus; | ||||
| 	Ebonus bonus; | ||||
| 	si16 castle; | ||||
| 	si32 hero, | ||||
| 	     heroPortrait; //-1 if default, else ID | ||||
|  | ||||
| 	std::string heroName; | ||||
| 	TPlayerColor color; //from 0 -  | ||||
| 	ui8 handicap;//0-no, 1-mild, 2-severe | ||||
| 	enum EHandicap {NO_HANDICAP, MILD, SEVERE}; | ||||
| 	EHandicap handicap;//0-no, 1-mild, 2-severe | ||||
| 	ui8 team; | ||||
|  | ||||
| 	std::string name; | ||||
| @@ -60,7 +60,7 @@ struct PlayerSettings | ||||
| 	} | ||||
|  | ||||
| 	PlayerSettings() : bonus(RANDOM), castle(NONE), hero(RANDOM), heroPortrait(RANDOM), | ||||
| 		color(0), handicap(0), team(0), playerID(PLAYER_AI), compOnly(false) | ||||
| 		color(0), handicap(NO_HANDICAP), team(0), playerID(PLAYER_AI), compOnly(false) | ||||
| 	{ | ||||
| 		 | ||||
| 	} | ||||
| @@ -71,7 +71,7 @@ struct StartInfo | ||||
| { | ||||
| 	enum EMode {NEW_GAME, LOAD_GAME, CAMPAIGN, DUEL, INVALID = 255}; | ||||
|  | ||||
| 	ui8 mode; //uses EMode enum | ||||
| 	EMode mode; | ||||
| 	ui8 difficulty; //0=easy; 4=impossible | ||||
|  | ||||
| 	typedef bmap<TPlayerColor, PlayerSettings> TPlayerInfos; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user