mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Hero speciality in creatures (growing with level) is now ready.
Fixed Tree of Knowledge giving only 2^31 XP.
This commit is contained in:
		
							
								
								
									
										1
									
								
								global.h
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								global.h
									
									
									
									
									
								
							| @@ -14,6 +14,7 @@ typedef boost::int64_t si64; //signed int 64 bits (8 bytes) | |||||||
| typedef boost::int32_t si32; //signed int 32 bits (4 bytes) | typedef boost::int32_t si32; //signed int 32 bits (4 bytes) | ||||||
| typedef boost::int16_t si16; //signed int 16 bits (2 bytes) | typedef boost::int16_t si16; //signed int 16 bits (2 bytes) | ||||||
| typedef boost::int8_t si8; //signed int 8 bits (1 byte) | typedef boost::int8_t si8; //signed int 8 bits (1 byte) | ||||||
|  | typedef si64 expType; | ||||||
| #include "int3.h" | #include "int3.h" | ||||||
| #include <map> | #include <map> | ||||||
| #include <vector> | #include <vector> | ||||||
|   | |||||||
| @@ -14,7 +14,6 @@ | |||||||
|  * Full text of license available in license.txt file, in main folder |  * Full text of license available in license.txt file, in main folder | ||||||
|  * |  * | ||||||
|  */ |  */ | ||||||
|  |  | ||||||
| class CHeroClass; | class CHeroClass; | ||||||
| class CDefHandler; | class CDefHandler; | ||||||
| class CGameInfo; | class CGameInfo; | ||||||
|   | |||||||
| @@ -975,10 +975,6 @@ void CGHeroInstance::initObj() | |||||||
| 				{ | 				{ | ||||||
| 					speciality.growthsWithLevel = true; | 					speciality.growthsWithLevel = true; | ||||||
|  |  | ||||||
| 					bonus.type = Bonus::SPECIAL_CREATURE_LEV; // general info to indicate type of growing bonus |  | ||||||
| 					bonus.additionalInfo = it->additionalinfo; //base creature ID |  | ||||||
| 					speciality.bonuses.push_back (bonus); |  | ||||||
|  |  | ||||||
| 					const CCreature &specCreature = *VLC->creh->creatures[it->additionalinfo]; //creature in which we have specialty | 					const CCreature &specCreature = *VLC->creh->creatures[it->additionalinfo]; //creature in which we have specialty | ||||||
|  |  | ||||||
| 					int creLevel = specCreature.level; | 					int creLevel = specCreature.level; | ||||||
| @@ -993,40 +989,21 @@ void CGHeroInstance::initObj() | |||||||
| 						} | 						} | ||||||
| 					} | 					} | ||||||
|  |  | ||||||
| 					int levelFactor = level / creLevel; //round down | 					bonus.limiter = new CCreatureTypeLimiter (specCreature, true); //with upgrades | ||||||
| 					double primSkillModifier = levelFactor / 20.0; |  | ||||||
|  |  | ||||||
| 					bonus.limiter = new CCreatureTypeLimiter(specCreature); |  | ||||||
| 					bonus.type = Bonus::PRIMARY_SKILL;  | 					bonus.type = Bonus::PRIMARY_SKILL;  | ||||||
|  | 					bonus.additionalInfo = it->additionalinfo; | ||||||
| 					bonus.valType = Bonus::ADDITIVE_VALUE; | 					bonus.valType = Bonus::ADDITIVE_VALUE; | ||||||
|  |  | ||||||
| 					bonus.subtype = PrimarySkill::ATTACK; | 					bonus.subtype = PrimarySkill::ATTACK; | ||||||
| 					bonus.val = std::ceil(primSkillModifier * specCreature.attack); |  | ||||||
| 					speciality.bonuses.push_back (bonus); | 					speciality.bonuses.push_back (bonus); | ||||||
|  |  | ||||||
| 					bonus.subtype = PrimarySkill::DEFENSE; | 					bonus.subtype = PrimarySkill::DEFENSE; | ||||||
| 					bonus.val = std::ceil(primSkillModifier * specCreature.defence); |  | ||||||
| 					speciality.bonuses.push_back (bonus); | 					speciality.bonuses.push_back (bonus); | ||||||
|  | 					//values will be calculated later | ||||||
|  |  | ||||||
| 					bonus.type = Bonus::STACKS_SPEED; | 					bonus.type = Bonus::STACKS_SPEED; | ||||||
| 					bonus.val = 1; //+1 speed | 					bonus.val = 1; //+1 speed | ||||||
| 					speciality.bonuses.push_back (bonus); | 					speciality.bonuses.push_back (bonus); | ||||||
|  |  | ||||||
| // 					for (std::set<ui32>::iterator i = (*creatures)[it->additionalinfo]->upgrades.begin(); |  | ||||||
| // 						i != VLC->creh->creatures[it->additionalinfo]->upgrades.end(); i++) |  | ||||||
| // 					{ |  | ||||||
| // 						bonus.val = (*i); // for all direct upgrades of that creature |  | ||||||
| // 						bonus.type = Bonus::PRIMARY_SKILL; |  | ||||||
| // 						bonus.subtype = 1; //attack |  | ||||||
| // 						bonus.val = level * (*creatures)[*i]->attack / (*creatures)[*i]->level /20; |  | ||||||
| // 						speciality.bonuses.push_back (bonus); |  | ||||||
| // 						bonus.subtype = 2; //defense |  | ||||||
| // 						bonus.val = level * (*creatures)[*i]->defence / (*creatures)[*i]->level /20; |  | ||||||
| // 						speciality.bonuses.push_back (bonus); |  | ||||||
| // 						bonus.type = Bonus::STACKS_SPEED; |  | ||||||
| // 						bonus.val = 1; //+1 speed |  | ||||||
| // 						speciality.bonuses.push_back (bonus); |  | ||||||
| // 					} |  | ||||||
| 				} | 				} | ||||||
| 				break; | 				break; | ||||||
| 			case 2://secondary skill | 			case 2://secondary skill | ||||||
| @@ -1137,6 +1114,49 @@ void CGHeroInstance::initObj() | |||||||
| 				tlog2 << "Unexpected hero speciality " << type <<'\n'; | 				tlog2 << "Unexpected hero speciality " << type <<'\n'; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  | 	UpdateSpeciality(); | ||||||
|  | } | ||||||
|  | void CGHeroInstance::UpdateSpeciality() | ||||||
|  | { | ||||||
|  | 	if (speciality.growthsWithLevel) | ||||||
|  | 	{ | ||||||
|  | 		std::vector<CCreature*>* creatures = &VLC->creh->creatures; | ||||||
|  | 		for (std::list<Bonus>::iterator it = speciality.bonuses.begin(); it != speciality.bonuses.end(); it++) | ||||||
|  | 		{ | ||||||
|  | 			switch (it->type) | ||||||
|  | 			{ | ||||||
|  | 				case Bonus::SECONDARY_SKILL_PREMY: | ||||||
|  | 					it->val = (speciality.valOfBonuses(Bonus::SPECIAL_SECONDARY_SKILL, it->subtype) * | ||||||
|  | 						valOfBonuses(Bonus::SECONDARY_SKILL_PREMY, it->subtype) * level)/100; | ||||||
|  | 					break; | ||||||
|  | 				case Bonus::PRIMARY_SKILL: //for crearures, that is | ||||||
|  | 					int creLevel = (*creatures)[it->additionalInfo]->level; | ||||||
|  | 					if(!creLevel) | ||||||
|  | 					{ | ||||||
|  | 						if(it->additionalInfo == 146) | ||||||
|  | 							creLevel = 5; //treat ballista as 5-level | ||||||
|  | 						else | ||||||
|  | 						{ | ||||||
|  | 							tlog2 << "Warning: unknown level of " << (*creatures)[it->additionalInfo]->namePl << std::endl; | ||||||
|  | 							continue; | ||||||
|  | 						} | ||||||
|  | 					} | ||||||
|  |  | ||||||
|  | 					double primSkillModifier = (int)(level / creLevel) / 20.0; | ||||||
|  |  | ||||||
|  | 					switch (it->subtype) | ||||||
|  | 					{ | ||||||
|  | 						case PrimarySkill::ATTACK: | ||||||
|  | 							it->val = (*creatures)[it->additionalInfo]->attack * primSkillModifier; | ||||||
|  | 						break; | ||||||
|  | 						case PrimarySkill::DEFENSE: | ||||||
|  | 							it->val = (*creatures)[it->additionalInfo]->defence * primSkillModifier; | ||||||
|  | 							break; | ||||||
|  | 					} | ||||||
|  | 					break; | ||||||
|  | 			} | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| } | } | ||||||
| void CGHeroInstance::setPropertyDer( ui8 what, ui32 val ) | void CGHeroInstance::setPropertyDer( ui8 what, ui32 val ) | ||||||
| { | { | ||||||
| @@ -2232,7 +2252,7 @@ void CGVisitableOPH::initObj() | |||||||
| 		ttype = -1; | 		ttype = -1; | ||||||
| } | } | ||||||
|  |  | ||||||
| void CGVisitableOPH::treeSelected( int heroID, int resType, int resVal, ui64 expVal, ui32 result ) const | void CGVisitableOPH::treeSelected( int heroID, int resType, int resVal, expType expVal, ui32 result ) const | ||||||
| { | { | ||||||
| 	if(result) //player agreed to give res for exp | 	if(result) //player agreed to give res for exp | ||||||
| 	{ | 	{ | ||||||
| @@ -2243,7 +2263,8 @@ void CGVisitableOPH::treeSelected( int heroID, int resType, int resVal, ui64 exp | |||||||
| } | } | ||||||
| void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const | void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const | ||||||
| { | { | ||||||
| 	int id=0, subid=0, ot=0, val=1, sound = 0; | 	int id=0, subid=0, ot=0, sound = 0; | ||||||
|  | 	expType val=1; | ||||||
| 	switch(ID) | 	switch(ID) | ||||||
| 	{ | 	{ | ||||||
| 	case 4: //arena | 	case 4: //arena | ||||||
| @@ -2355,7 +2376,8 @@ void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const | |||||||
| 				} | 				} | ||||||
| 				else | 				else | ||||||
| 				{ | 				{ | ||||||
| 					int res, resval; | 					ui32 res; | ||||||
|  | 					expType resval; | ||||||
| 					if(ttype==1) | 					if(ttype==1) | ||||||
| 					{ | 					{ | ||||||
| 						res = 6; | 						res = 6; | ||||||
|   | |||||||
| @@ -381,6 +381,7 @@ public: | |||||||
| 	void giveArtifact (ui32 aid); | 	void giveArtifact (ui32 aid); | ||||||
| 	void initHeroDefInfo(); | 	void initHeroDefInfo(); | ||||||
| 	void pushPrimSkill(int which, int val); | 	void pushPrimSkill(int which, int val); | ||||||
|  | 	void UpdateSpeciality(); | ||||||
|  |  | ||||||
| 	CGHeroInstance(); | 	CGHeroInstance(); | ||||||
| 	virtual ~CGHeroInstance(); | 	virtual ~CGHeroInstance(); | ||||||
| @@ -424,7 +425,7 @@ public: | |||||||
| 	void onHeroVisit(const CGHeroInstance * h) const; | 	void onHeroVisit(const CGHeroInstance * h) const; | ||||||
| 	void onNAHeroVisit(int heroID, bool alreadyVisited) const; | 	void onNAHeroVisit(int heroID, bool alreadyVisited) const; | ||||||
| 	void initObj(); | 	void initObj(); | ||||||
| 	void treeSelected(int heroID, int resType, int resVal, ui64 expVal, ui32 result) const; //handle player's anwer to the Tree of Knowledge dialog | 	void treeSelected(int heroID, int resType, int resVal, expType expVal, ui32 result) const; //handle player's anwer to the Tree of Knowledge dialog | ||||||
| 	void schoolSelected(int heroID, ui32 which) const; | 	void schoolSelected(int heroID, ui32 which) const; | ||||||
| 	void arenaSelected(int heroID, int primSkill) const; | 	void arenaSelected(int heroID, int primSkill) const; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -148,7 +148,6 @@ namespace PrimarySkill | |||||||
| 	BONUS_NAME(NO_LUCK) /*eg. when fighting on cursed ground*/	\ | 	BONUS_NAME(NO_LUCK) /*eg. when fighting on cursed ground*/	\ | ||||||
| 	BONUS_NAME(NO_MORALE) /*eg. when fighting on cursed ground*/ \ | 	BONUS_NAME(NO_MORALE) /*eg. when fighting on cursed ground*/ \ | ||||||
| 	BONUS_NAME(DARKNESS) /*val = radius */ \ | 	BONUS_NAME(DARKNESS) /*val = radius */ \ | ||||||
| 	BONUS_NAME(SPECIAL_CREATURE_LEV) /*val = base id*/ \ |  | ||||||
| 	BONUS_NAME(SPECIAL_SECONDARY_SKILL) /*val = id, additionalInfo = value per level in percent*/ \ | 	BONUS_NAME(SPECIAL_SECONDARY_SKILL) /*val = id, additionalInfo = value per level in percent*/ \ | ||||||
| 	BONUS_NAME(SPECIAL_SPELL_LEV) /*val = id, additionalInfo = value per level in percent*/\ | 	BONUS_NAME(SPECIAL_SPELL_LEV) /*val = id, additionalInfo = value per level in percent*/\ | ||||||
| 	BONUS_NAME(SPECIFIC_SPELL_DAMAGE) /*val = id of spell, additionalInfo = value*/\ | 	BONUS_NAME(SPECIFIC_SPELL_DAMAGE) /*val = id of spell, additionalInfo = value*/\ | ||||||
|   | |||||||
| @@ -707,42 +707,7 @@ DLL_EXPORT void HeroLevelUp::applyGs( CGameState *gs ) | |||||||
| 	CGHeroInstance* h = gs->getHero(heroid); | 	CGHeroInstance* h = gs->getHero(heroid); | ||||||
| 	h->level = level; | 	h->level = level; | ||||||
| 	//speciality | 	//speciality | ||||||
| 	if (h->speciality.growthsWithLevel) | 	h->UpdateSpeciality(); | ||||||
| 	{ |  | ||||||
| 		std::vector<CCreature*>* creatures = &VLC->creh->creatures; |  | ||||||
| 		for (std::list<Bonus>::iterator it = h->speciality.bonuses.begin(); it != h->speciality.bonuses.end(); it++) |  | ||||||
| 		{ |  | ||||||
| 			switch (it->type) |  | ||||||
| 			{ |  | ||||||
| 				case Bonus::SECONDARY_SKILL_PREMY: |  | ||||||
| 					it->val = (h->speciality.valOfBonuses(Bonus::SPECIAL_SECONDARY_SKILL, it->subtype) * |  | ||||||
| 						h->valOfBonuses(Bonus::SECONDARY_SKILL_PREMY,it->subtype) * h->level)/100; |  | ||||||
| 				break; |  | ||||||
| 				case Bonus::PRIMARY_SKILL: |  | ||||||
| 					int creLevel = (*creatures)[it->additionalInfo]->level; |  | ||||||
| 					if(!creLevel) |  | ||||||
| 					{ |  | ||||||
| 						if(it->additionalInfo == 146) |  | ||||||
| 							creLevel = 5; //treat ballista as 5-level |  | ||||||
| 						else |  | ||||||
| 						{ |  | ||||||
| 							tlog2 << "Warning: unknown level of " << (*creatures)[it->val]->namePl << std::endl; |  | ||||||
| 							continue; |  | ||||||
| 						} |  | ||||||
| 					} |  | ||||||
| 					switch (it->subtype) |  | ||||||
| 					{ |  | ||||||
| 					case 1: |  | ||||||
| 						it->val = (level * (*creatures)[it->additionalInfo]->attack)/creLevel /20; |  | ||||||
| 						break; |  | ||||||
| 					case 2: |  | ||||||
| 							it->val = (level * (*creatures)[it->additionalInfo]->defence)/creLevel /20; |  | ||||||
| 							break; |  | ||||||
| 					} |  | ||||||
| 					break; |  | ||||||
| 			} |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| } | } | ||||||
|  |  | ||||||
| DLL_EXPORT void BattleStart::applyGs( CGameState *gs ) | DLL_EXPORT void BattleStart::applyGs( CGameState *gs ) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user