mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	- fix for hero flags along with battlehero cleanup
- removed unused code
This commit is contained in:
		| @@ -241,7 +241,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe | ||||
| 		int type = hero1->type->heroType; | ||||
| 		if ( type % 2 )   type--; | ||||
| 		if ( hero1->sex ) type++; | ||||
| 		attackingHero = new CBattleHero(graphics->battleHeroes[type], 0, 0, false, hero1->tempOwner, hero1->tempOwner == curInt->playerID ? hero1 : NULL, this); | ||||
| 		attackingHero = new CBattleHero(graphics->battleHeroes[type], false, hero1->tempOwner, hero1->tempOwner == curInt->playerID ? hero1 : NULL, this); | ||||
| 		attackingHero->pos = genRect(attackingHero->dh->ourImages[0].bitmap->h, attackingHero->dh->ourImages[0].bitmap->w, pos.x - 43, pos.y - 19); | ||||
| 	} | ||||
| 	else | ||||
| @@ -253,7 +253,7 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe | ||||
| 		int type = hero2->type->heroType; | ||||
| 		if ( type % 2 )   type--; | ||||
| 		if ( hero2->sex ) type++; | ||||
| 		defendingHero = new CBattleHero(graphics->battleHeroes[type ], 0, 0, true, hero2->tempOwner, hero2->tempOwner == curInt->playerID ? hero2 : NULL, this); | ||||
| 		defendingHero = new CBattleHero(graphics->battleHeroes[type ], true, hero2->tempOwner, hero2->tempOwner == curInt->playerID ? hero2 : NULL, this); | ||||
| 		defendingHero->pos = genRect(defendingHero->dh->ourImages[0].bitmap->h, defendingHero->dh->ourImages[0].bitmap->w, pos.x + 693, pos.y - 19); | ||||
| 	} | ||||
| 	else | ||||
|   | ||||
| @@ -112,81 +112,50 @@ void CBattleConsole::scrollDown(ui32 by) | ||||
| void CBattleHero::show(SDL_Surface * to) | ||||
| { | ||||
| 	//animation of flag | ||||
| 	SDL_Rect temp_rect; | ||||
| 	if(flip) | ||||
| 	{ | ||||
| 		SDL_Rect temp_rect = genRect( | ||||
| 		temp_rect = genRect( | ||||
| 			flag->ourImages[flagAnim].bitmap->h, | ||||
| 			flag->ourImages[flagAnim].bitmap->w, | ||||
| 			pos.x + 61, | ||||
| 			pos.y + 39); | ||||
| 		CSDL_Ext::blit8bppAlphaTo24bpp( | ||||
| 			flag->ourImages[flagAnim].bitmap, | ||||
| 			NULL, | ||||
| 			screen, | ||||
| 			&temp_rect); | ||||
|  | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		SDL_Rect temp_rect = genRect( | ||||
| 		temp_rect = genRect( | ||||
| 			flag->ourImages[flagAnim].bitmap->h, | ||||
| 			flag->ourImages[flagAnim].bitmap->w, | ||||
| 			pos.x + 72, | ||||
| 			pos.y + 39); | ||||
| 		CSDL_Ext::blit8bppAlphaTo24bpp( | ||||
| 			flag->ourImages[flagAnim].bitmap, | ||||
| 			NULL, | ||||
| 			screen, | ||||
| 			&temp_rect); | ||||
| 	} | ||||
| 	++flagAnimCount; | ||||
| 	if(flagAnimCount%4==0) | ||||
| 	{ | ||||
| 		++flagAnim; | ||||
| 		flagAnim %= flag->ourImages.size(); | ||||
| 	} | ||||
| 	CSDL_Ext::blit8bppAlphaTo24bpp( | ||||
| 		flag->ourImages[flagAnim].bitmap, | ||||
| 		NULL, | ||||
| 		screen, | ||||
| 		&temp_rect); | ||||
|  | ||||
| 	//animation of hero | ||||
| 	int tick=-1; | ||||
| 	for(size_t i = 0; i < dh->ourImages.size(); ++i) | ||||
| 	SDL_Rect rect = pos; | ||||
| 	CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[currentFrame].bitmap, NULL, to, &rect); | ||||
|  | ||||
| 	if ( ++animCount == 4 ) | ||||
| 	{ | ||||
| 		if(dh->ourImages[i].groupNumber==phase) | ||||
| 			++tick; | ||||
| 		if(tick==image) | ||||
| 		{ | ||||
| 			SDL_Rect posb = pos; | ||||
| 			CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb); | ||||
| 			if(phase != 4 || nextPhase != -1 || image < 4) | ||||
| 			{ | ||||
| 				if(flagAnimCount%2==0) | ||||
| 				{ | ||||
| 					++image; | ||||
| 				} | ||||
| 				if(dh->ourImages[(i+1)%dh->ourImages.size()].groupNumber!=phase) //back to appropriate frame | ||||
| 				{ | ||||
| 					image = 0; | ||||
| 				} | ||||
| 			} | ||||
| 			if(phase == 4 && nextPhase != -1 && image == 7) | ||||
| 			{ | ||||
| 				phase = nextPhase; | ||||
| 				nextPhase = -1; | ||||
| 				image = 0; | ||||
| 			} | ||||
| 			break; | ||||
| 		} | ||||
| 		animCount = 0; | ||||
| 		if ( ++flagAnim >= flag->ourImages.size()) | ||||
| 			flagAnim = 0; | ||||
|  | ||||
| 		if ( ++currentFrame >= lastFrame) | ||||
| 			switchToNextPhase(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| void CBattleHero::setPhase(int newPhase) | ||||
| { | ||||
| 	if(phase != 4) | ||||
| 	{ | ||||
| 		phase = newPhase; | ||||
| 		image = 0; | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		nextPhase = newPhase; | ||||
| 	} | ||||
| 	nextPhase = newPhase; | ||||
| 	switchToNextPhase(); //immediately switch to next phase and then restore idling phase | ||||
| 	nextPhase = 0; | ||||
| } | ||||
|  | ||||
| void CBattleHero::clickLeft(tribool down, bool previousState) | ||||
| @@ -208,7 +177,33 @@ void CBattleHero::clickLeft(tribool down, bool previousState) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| CBattleHero::CBattleHero(const std::string & defName, int phaseG, int imageG, bool flipG, ui8 player, const CGHeroInstance * hero, const CBattleInterface * owner): flip(flipG), myHero(hero), myOwner(owner), phase(phaseG), nextPhase(-1), image(imageG), flagAnim(0), flagAnimCount(0) | ||||
| void CBattleHero::switchToNextPhase() | ||||
| { | ||||
| 	if (phase != nextPhase) | ||||
| 	{ | ||||
| 		phase = nextPhase; | ||||
|  | ||||
| 		//find first and last frames of our animation | ||||
| 		for (firstFrame = 0; | ||||
| 		     firstFrame < dh->ourImages.size() && dh->ourImages[firstFrame].groupNumber != phase; | ||||
| 		     firstFrame++); | ||||
|  | ||||
| 		for (lastFrame = firstFrame; | ||||
| 			 lastFrame < dh->ourImages.size() && dh->ourImages[lastFrame].groupNumber == phase; | ||||
| 			 lastFrame++); | ||||
| 	} | ||||
|  | ||||
| 	currentFrame = firstFrame; | ||||
| } | ||||
|  | ||||
| CBattleHero::CBattleHero(const std::string & defName, bool flipG, ui8 player, const CGHeroInstance * hero, const CBattleInterface * owner): | ||||
|     flip(flipG), | ||||
|     myHero(hero), | ||||
|     myOwner(owner), | ||||
|     phase(1), | ||||
|     nextPhase(0), | ||||
|     flagAnim(0), | ||||
|     animCount(0) | ||||
| { | ||||
| 	dh = CDefHandler::giveDef( defName ); | ||||
| 	for(size_t i = 0; i < dh->ourImages.size(); ++i) //transforming images | ||||
| @@ -234,6 +229,8 @@ CBattleHero::CBattleHero(const std::string & defName, int phaseG, int imageG, bo | ||||
| 		graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player); | ||||
| 	} | ||||
| 	addUsedEvents(LCLICK); | ||||
|  | ||||
| 	switchToNextPhase(); | ||||
| } | ||||
|  | ||||
| CBattleHero::~CBattleHero() | ||||
|   | ||||
| @@ -49,6 +49,7 @@ public: | ||||
| /// Hero battle animation | ||||
| class CBattleHero : public CIntObject | ||||
| { | ||||
| 	void switchToNextPhase(); | ||||
| public: | ||||
| 	bool flip; //false if it's attacking hero, true otherwise | ||||
| 	CDefHandler *dh, *flag; //animation and flag | ||||
| @@ -56,12 +57,12 @@ public: | ||||
| 	const CBattleInterface * myOwner; //battle interface to which this animation is assigned | ||||
| 	int phase; //stage of animation | ||||
| 	int nextPhase; //stage of animation to be set after current phase is fully displayed | ||||
| 	int image; //frame of animation | ||||
| 	ui8 flagAnim, flagAnimCount; //for flag animation | ||||
| 	int currentFrame, firstFrame, lastFrame; //frame of animation | ||||
| 	ui8 flagAnim, animCount; //for flag animation | ||||
| 	void show(SDL_Surface * to); //prints next frame of animation to to | ||||
| 	void setPhase(int newPhase); //sets phase of hero animation | ||||
| 	void clickLeft(tribool down, bool previousState); //call-in | ||||
| 	CBattleHero(const std::string &defName, int phaseG, int imageG, bool filpG, ui8 player, const CGHeroInstance *hero, const CBattleInterface *owner); //c-tor | ||||
| 	CBattleHero(const std::string &defName, bool filpG, ui8 player, const CGHeroInstance *hero, const CBattleInterface *owner); //c-tor | ||||
| 	~CBattleHero(); //d-tor | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -58,7 +58,8 @@ void Graphics::loadPaletteAndColors() | ||||
| 		col.r = pals[startPoint++]; | ||||
| 		col.g = pals[startPoint++]; | ||||
| 		col.b = pals[startPoint++]; | ||||
| 		col.unused = pals[startPoint++]; | ||||
| 		col.unused = 255; | ||||
| 		startPoint++; | ||||
| 		playerColorPalette[i] = col; | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -1657,19 +1657,6 @@ int CGameState::battleGetBattlefieldType(int3 tile) const | ||||
| 	} | ||||
| } | ||||
|  | ||||
|  | ||||
| std::set<std::pair<int, int> > costDiff(const std::vector<ui32> &a, const std::vector<ui32> &b, const int modifier = 100) //modifer % | ||||
| { | ||||
| 	std::set<std::pair<int, int> > ret; | ||||
| 	for(int j=0;j<GameConstants::RESOURCE_QUANTITY;j++) | ||||
| 	{ | ||||
| 		assert(a[j] >= b[j]); | ||||
| 		if(int dif = modifier * (a[j] - b[j]) / 100) | ||||
| 			ret.insert(std::make_pair(j,dif)); | ||||
| 	} | ||||
| 	return ret; | ||||
| } | ||||
|  | ||||
| UpgradeInfo CGameState::getUpgradeInfo(const CStackInstance &stack) | ||||
| { | ||||
| 	UpgradeInfo ret; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user