mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Lots of fixes and improvements for Commander interface.
This commit is contained in:
		| @@ -159,6 +159,10 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * | ||||
|  | ||||
| 	//Basic graphics - need to calculate size | ||||
|  | ||||
| 	int commanderOffset = 0; | ||||
| 	if (type >= COMMANDER) | ||||
| 		commanderOffset = 74; | ||||
|  | ||||
| 	BonusList bl, blTemp; | ||||
| 	blTemp = (*(stackNode->getBonuses(Selector::durationType(Bonus::PERMANENT)))); | ||||
|  | ||||
| @@ -237,11 +241,12 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * | ||||
| 	new CAnimImage("PSKIL42", 4, 0, 387, 51); //exp icon - Print it always? | ||||
| 	if (type) //not in fort window | ||||
| 	{ | ||||
| 		if (GameConstants::STACK_EXP) | ||||
| 		if (GameConstants::STACK_EXP && type < COMMANDER) | ||||
| 		{ | ||||
| 			int rank = std::min(stack->getExpRank(), 10); //hopefully nobody adds more | ||||
| 			printAtMiddle(CGI->generaltexth->zcrexp[rank] + " [" + boost::lexical_cast<std::string>(rank) + "]", 488, 62, FONT_MEDIUM, Colors::Jasmine,*bitmap); | ||||
| 			printAtMiddle(boost::lexical_cast<std::string>(stack->experience), 488, 82, FONT_SMALL, Colors::Cornsilk,*bitmap); | ||||
| 			printAtMiddle(CGI->generaltexth->zcrexp[rank] + " [" + boost::lexical_cast<std::string>(rank) + "]", 488, 62, FONT_MEDIUM, Colors::Jasmine,*bitmap); | ||||
|  | ||||
| 			if (type > BATTLE) //we need it only on adv. map | ||||
| 			{ | ||||
| 				int tier = stack->type->level; | ||||
| @@ -335,14 +340,12 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * | ||||
| 				} | ||||
| 				file += sufix += ".bmp"; | ||||
|  | ||||
| 				//bonusGraphics = new CPicture(graphicsName, 26, 232); | ||||
| 				//blitAtLoc(bonusGraphics->bg, 12, 2, bitmap->bg); | ||||
|  | ||||
| 				auto skillGraphics = new CPicture(file, 39 + i * 82, 223); | ||||
| 				//if (skillGraphics->bg) | ||||
| 				//	blitAtLoc(skillGraphics->bg, 0, 0, bitmap->bg); | ||||
| 				auto skillGraphics = new CPicture(file, 38 + i * 84, 223); | ||||
| 			} | ||||
| 		} | ||||
| 		//print commander level | ||||
| 		printAtMiddle(boost::lexical_cast<std::string>((ui16)(commander->level)), 488, 62, FONT_MEDIUM, Colors::Jasmine,*bitmap); | ||||
| 		printAtMiddle(boost::lexical_cast<std::string>(stack->experience), 488, 82, FONT_SMALL, Colors::Cornsilk,*bitmap); | ||||
| 	} | ||||
|  | ||||
| 	if (battleStack) //only during battle | ||||
| @@ -371,7 +374,7 @@ void CCreatureWindow::init(const CStackInstance *Stack, const CBonusSystemNode * | ||||
|  | ||||
| 	if (bonusItems.size() > (bonusRows << 1)) //only after graphics are created | ||||
| 	{ | ||||
| 		slider = new CSlider(528, 231, bonusRows*60, boost::bind (&CCreatureWindow::sliderMoved, this, _1), | ||||
| 		slider = new CSlider(528, 231 + commanderOffset, bonusRows*60, boost::bind (&CCreatureWindow::sliderMoved, this, _1), | ||||
| 		bonusRows, (bonusItems.size() + 1) >> 1, 0, false, 0); | ||||
| 	} | ||||
| 	else //slider automatically places bonus Items | ||||
|   | ||||
| @@ -34,7 +34,7 @@ public: | ||||
| 	int idRand; //hlp variable used during loading game -> "id" placeholder for randomization | ||||
|  | ||||
| 	const CArmedInstance * const & armyObj; //stack must be part of some army, army must be part of some object | ||||
| 	ui32 experience; | ||||
| 	expType experience;//commander needs same amount of exp as hero | ||||
|  | ||||
| 	template <typename Handler> void serialize(Handler &h, const int version) | ||||
| 	{ | ||||
| @@ -83,6 +83,7 @@ public: | ||||
| 	ui8 level; //required only to count callbacks | ||||
| 	std::string name; // each Commander has different name | ||||
| 	std::vector <ui8> secondarySkills; //ID -> level | ||||
| 	std::set <ui8> specialSKills; | ||||
| 	//std::vector <CArtifactInstance *> arts; | ||||
| 	void init() OVERRIDE; | ||||
| 	CCommanderInstance(); | ||||
| @@ -99,7 +100,7 @@ public: | ||||
| 	template <typename Handler> void serialize(Handler &h, const int version) | ||||
| 	{ | ||||
| 		h & static_cast<CStackInstance&>(*this); | ||||
| 		h & alive & level & name & secondarySkills; | ||||
| 		h & alive & level & name & secondarySkills & specialSKills; | ||||
| 	} | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -524,7 +524,7 @@ struct UpdateCampaignState : public CPackForClient //119 | ||||
| }; | ||||
| struct SetCommanderProperty : public CPackForClient //120 | ||||
| { | ||||
| 	enum ECommanderProperty {ALIVE, BONUS, SECONDARY_SKILL}; | ||||
| 	enum ECommanderProperty {ALIVE, BONUS, SECONDARY_SKILL, EXPERIENCE, SPECIAL_SKILL}; | ||||
|  | ||||
| 	SetCommanderProperty(){type = 120;}; | ||||
| 	void applyCl(CClient *cl){}; | ||||
| @@ -534,7 +534,7 @@ struct SetCommanderProperty : public CPackForClient //120 | ||||
| 	StackLocation sl; //for commander not on the hero? | ||||
|  | ||||
| 	ui8 which; // use ECommanderProperty | ||||
| 	ui8 amount; //0 for dead, >0 for alive | ||||
| 	expType amount; //0 for dead, >0 for alive | ||||
| 	si32 additionalInfo; //for secondary skills choice | ||||
| 	Bonus accumulatedBonus; | ||||
|  | ||||
|   | ||||
| @@ -86,6 +86,10 @@ DLL_LINKAGE void SetCommanderProperty::applyGs(CGameState *gs) | ||||
| 		case BONUS: | ||||
| 			commander->accumulateBonus (accumulatedBonus); | ||||
| 			break; | ||||
| 		case SPECIAL_SKILL: | ||||
| 			commander->accumulateBonus (accumulatedBonus); | ||||
| 			commander->specialSKills.insert (additionalInfo); | ||||
| 			break; | ||||
| 		case SECONDARY_SKILL: | ||||
| 			commander->secondarySkills[additionalInfo] = amount; | ||||
| 			break; | ||||
| @@ -95,6 +99,9 @@ DLL_LINKAGE void SetCommanderProperty::applyGs(CGameState *gs) | ||||
| 			else | ||||
| 				commander->setAlive(false); | ||||
| 			break; | ||||
| 		case EXPERIENCE: | ||||
| 			commander->giveStackExp (amount); //TODO: allow setting exp for stacks via netpacks | ||||
| 			break; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -1031,11 +1038,6 @@ void BattleResult::applyGs( CGameState *gs ) | ||||
| 		if (h) | ||||
| 		{ | ||||
| 			h->getBonusList().remove_if(Bonus::OneBattle); | ||||
| 			if (h->commander && h->commander->alive) | ||||
| 			{ | ||||
| 				h->commander->giveStackExp(exp[i]); | ||||
| 				CBonusSystemNode::treeHasChanged(); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -298,7 +298,6 @@ void CGameHandler::levelUpCommander (const CCommanderInstance * c, int skill) | ||||
| 		return; | ||||
| 	} | ||||
|  | ||||
| 	scp.which = SetCommanderProperty::BONUS; | ||||
| 	scp.accumulatedBonus.additionalInfo = 0; | ||||
| 	scp.accumulatedBonus.duration = Bonus::PERMANENT; | ||||
| 	scp.accumulatedBonus.turnsRemain = 0; | ||||
| @@ -306,10 +305,13 @@ void CGameHandler::levelUpCommander (const CCommanderInstance * c, int skill) | ||||
| 	scp.accumulatedBonus.valType = Bonus::BASE_NUMBER; | ||||
| 	if (skill <= ECommander::SPELL_POWER) | ||||
| 	{ | ||||
| 		scp.which = SetCommanderProperty::BONUS; | ||||
|  | ||||
| 		auto difference = [](std::vector< std::vector <ui8> > skillLevels, std::vector <ui8> secondarySkills, int skill)->int | ||||
| 		{ | ||||
| 			return skillLevels[skill][secondarySkills[skill]] - (secondarySkills[skill] ? skillLevels[skill][secondarySkills[skill]-1] : 0); | ||||
| 		}; | ||||
|  | ||||
| 		switch (skill) | ||||
| 		{ | ||||
| 			case ECommander::ATTACK: | ||||
| @@ -353,7 +355,9 @@ void CGameHandler::levelUpCommander (const CCommanderInstance * c, int skill) | ||||
| 	} | ||||
| 	else if (skill >= 100) | ||||
| 	{ | ||||
| 		scp.which = SetCommanderProperty::SPECIAL_SKILL; | ||||
| 		scp.accumulatedBonus = VLC->creh->skillRequirements[skill-100].first; | ||||
| 		scp.additionalInfo = skill; //unnormalized | ||||
| 		sendAndApply (&scp); | ||||
| 	} | ||||
| 	levelUpCommander (c); | ||||
| @@ -387,7 +391,8 @@ void CGameHandler::levelUpCommander(const CCommanderInstance * c) | ||||
| 	BOOST_FOREACH (auto specialSkill, VLC->creh->skillRequirements) | ||||
| 	{ | ||||
| 		if (c->secondarySkills[specialSkill.second.first] == ECommander::MAX_SKILL_LEVEL && | ||||
| 			c->secondarySkills[specialSkill.second.second] == ECommander::MAX_SKILL_LEVEL) | ||||
| 			c->secondarySkills[specialSkill.second.second] == ECommander::MAX_SKILL_LEVEL && | ||||
| 			!vstd::contains (c->specialSKills, i)) | ||||
| 			clu.skills.push_back (i); | ||||
| 		++i; | ||||
| 	} | ||||
| @@ -420,12 +425,20 @@ void CGameHandler::changePrimSkill(int ID, int which, si64 val, bool abs) | ||||
| 	sendAndApply(&sps); | ||||
| 	 | ||||
| 	//only for exp - hero may level up | ||||
| 	if(which==4) | ||||
| 	if (which == 4) | ||||
| 	{ | ||||
| 		levelUpHero(ID); | ||||
| 		CGHeroInstance *h = static_cast<CGHeroInstance *>(gs->map->objects[ID].get()); | ||||
| 		if (h->commander) | ||||
| 		if (h->commander && h->commander->alive) | ||||
| 		{ | ||||
| 			SetCommanderProperty scp; | ||||
| 			scp.heroid = h->id; | ||||
| 			scp.which = SetCommanderProperty::EXPERIENCE; | ||||
| 			scp.amount = val; | ||||
| 			sendAndApply (&scp); | ||||
| 			levelUpCommander (h->commander); | ||||
| 			CBonusSystemNode::treeHasChanged(); | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user