#include "StdInc.h" #include "CBattleHero.h" #include "CBattleInterface.h" #include "../CGameInfo.h" #include "../CDefHandler.h" #include "../CCursorHandler.h" #include "../CPlayerInterface.h" #include "../../CCallback.h" #include "../SDL_Extensions.h" #include "../CSpellWindow.h" #include "../Graphics.h" #include "../CConfigHandler.h" void CBattleHero::show(SDL_Surface *to) { //animation of flag if(flip) { SDL_Rect 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( 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(); } //animation of hero int tick=-1; for(size_t i = 0; i < dh->ourImages.size(); ++i) { 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; } } } void CBattleHero::activate() { activateLClick(); } void CBattleHero::deactivate() { deactivateLClick(); } void CBattleHero::setPhase(int newPhase) { if(phase != 4) { phase = newPhase; image = 0; } else { nextPhase = newPhase; } } void CBattleHero::clickLeft(tribool down, bool previousState) { if(myOwner->spellDestSelectMode) //we are casting a spell return; if(!down && myHero != NULL && myOwner->myTurn && myOwner->curInt->cb->battleCanCastSpell()) //check conditions { for(int it=0; itbfield[it].hovered && myOwner->bfield[it].strictHovered) return; } CCS->curh->changeGraphic(0,0); CSpellWindow * spellWindow = new CSpellWindow(genRect(595, 620, (conf.cc.resx - 620)/2, (conf.cc.resy - 595)/2), myHero, myOwner->curInt); GH.pushInt(spellWindow); } } 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) { dh = CDefHandler::giveDef( defName ); for(size_t i = 0; i < dh->ourImages.size(); ++i) //transforming images { if(flip) { SDL_Surface * hlp = CSDL_Ext::rotate01(dh->ourImages[i].bitmap); SDL_FreeSurface(dh->ourImages[i].bitmap); dh->ourImages[i].bitmap = hlp; } CSDL_Ext::alphaTransform(dh->ourImages[i].bitmap); } if(flip) flag = CDefHandler::giveDef("CMFLAGR.DEF"); else flag = CDefHandler::giveDef("CMFLAGL.DEF"); //coloring flag and adding transparency for(size_t i = 0; i < flag->ourImages.size(); ++i) { CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap); graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player); } } CBattleHero::~CBattleHero() { delete dh; delete flag; }