1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

* displaying spell effects (currently only arrow magic effect is shown)

* minor fixes
This commit is contained in:
mateuszb 2008-10-19 15:41:18 +00:00
parent c431577a5e
commit 45204d8beb
6 changed files with 194 additions and 10 deletions

View File

@ -405,6 +405,23 @@ void CBattleInterface::show(SDL_Surface * to)
//units shown
projectileShowHelper(to);//showing projectiles
//showing spell effects
std::vector< std::list<SBattleEffect>::iterator > toErase;
for(std::list<SBattleEffect>::iterator it = battleEffects.begin(); it!=battleEffects.end(); ++it)
{
blitAt(it->anim->ourImages[it->frame].bitmap, it->x, it->y, to);
++(it->frame);
if(it->frame == it->maxFrame)
toErase.push_back(it);
}
for(int b=0; b<toErase.size(); ++b)
{
delete toErase[b]->anim;
battleEffects.erase(toErase[b]);
}
//showing queue of stacks
if(showStackQueue)
{
@ -666,7 +683,7 @@ void CBattleInterface::stackRemoved(CStack stack)
creAnims.erase(stack.ID);
}
void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting, ui32 effects)
void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting)
{
if(creAnims[ID]->getType() != 2)
{
@ -711,7 +728,7 @@ void CBattleInterface::stackKilled(int ID, int dmg, int killed, int IDby, bool b
SDL_framerateDelay(LOCPLINT->mainFPSmng);
}
if(effects == 0)
if(IDby!=-1)
printConsoleAttacked(ID, dmg, killed, IDby);
}
@ -838,7 +855,7 @@ void CBattleInterface::stackMoved(int number, int destHex, bool endMoving)
creAnims[number]->pos.y = coords.second;
}
void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting, ui32 effects)
void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting)
{
while(creAnims[ID]->getType() != 2 || (attackingInfo && attackingInfo->IDby == IDby))
{
@ -882,7 +899,7 @@ void CBattleInterface::stackIsAttacked(int ID, int dmg, int killed, int IDby, bo
}
creAnims[ID]->setType(2);
if(effects == 0)
if(IDby!=-1)
printConsoleAttacked(ID, dmg, killed, IDby);
}
@ -1269,6 +1286,25 @@ void CBattleInterface::castThisSpell(int spellID)
CGI->curh->changeGraphic(3, 0);
}
void CBattleInterface::displayEffect(ui32 effect, int destTile, bool affected)
{
if(graphics->battleACToDef[effect].size() != 0)
{
SBattleEffect be;
be.anim = CDefHandler::giveDef(graphics->battleACToDef[effect][0]);
be.frame = 0;
be.maxFrame = be.anim->ourImages.size();
std::pair<int, int> coords = CBattleHex::getXYUnitAnim(destTile, affected, NULL);
coords.first += 250; coords.second += 240;
coords.first -= be.anim->ourImages[0].bitmap->w/2;
coords.second -= be.anim->ourImages[0].bitmap->h/2;
be.x = coords.first; be.y = coords.second;
battleEffects.push_back(be);
}
//battleEffects
}
void CBattleInterface::setAnimSpeed(int set)
{
animSpeed = set;
@ -1587,7 +1623,7 @@ void CBattleHero::show(SDL_Surface *to)
SDL_Rect posb = pos;
CSDL_Ext::blit8bppAlphaTo24bpp(dh->ourImages[i].bitmap, NULL, to, &posb);
++image;
if(dh->ourImages[i+1].groupNumber!=phase) //back to appropriate frame
if(dh->ourImages[(i+1)%dh->ourImages.size()].groupNumber!=phase) //back to appropriate frame
{
image = 0;
}
@ -1604,6 +1640,13 @@ void CBattleHero::deactivate()
{
ClickableL::deactivate();
}
void CBattleHero::setPhase(int newPhase)
{
phase = newPhase;
image = 0;
}
void CBattleHero::clickLeft(boost::logic::tribool down)
{
if(!down && myHero)
@ -1670,7 +1713,7 @@ std::pair<int, int> CBattleHex::getXYUnitAnim(const int & hexNum, const bool & a
ret.first = -219 + 22 * ( ((hexNum/17) + 1)%2 ) + 44 * (hexNum % 17);
}
//shifting position for double - hex creatures
if(creature->isDoubleWide())
if(creature && creature->isDoubleWide())
{
if(attacker)
{

View File

@ -30,6 +30,7 @@ public:
void show(SDL_Surface * to); //prints next frame of animation to to
void activate();
void deactivate();
void setPhase(int newPhase);
void clickLeft(boost::logic::tribool down);
CBattleHero(const std::string & defName, int phaseG, int imageG, bool filpG, unsigned char player, const CGHeroInstance * hero, const CBattleInterface * owner); //c-tor
~CBattleHero(); //d-tor
@ -166,6 +167,14 @@ private:
void projectileShowHelper(SDL_Surface * to=NULL); //prints projectiles present on the battlefield
void giveCommand(ui8 action, ui16 tile, ui32 stack, si32 additional=-1);
bool isTileAttackable(int number); //returns true if tile 'number' is neighbouring any tile from active stack's range or is one of these tiles
struct SBattleEffect
{
int x, y; //position on the screen
int frame, maxFrame;
CDefHandler * anim; //animation to display
};
std::list<SBattleEffect> battleEffects; //different animations to display on the screen like spell effects
public:
CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2); //c-tor
~CBattleInterface(); //d-tor
@ -211,10 +220,10 @@ public:
//call-ins
void newStack(CStack stack); //new stack appeared on battlefield
void stackRemoved(CStack stack); //stack disappeared from batlefiled
void stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting, ui32 effects = 0); //stack has been killed (but corpses remain); effects - additional optional spell effect (AC format)
void stackKilled(int ID, int dmg, int killed, int IDby, bool byShooting); //stack has been killed (but corpses remain)
void stackActivated(int number); //active stack has been changed
void stackMoved(int number, int destHex, bool endMoving); //stack with id number moved to destHex
void stackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting, ui32 effects = 0); //called when stack id attacked by stack with id IDby; effects - additional optional spell effect (AC format)
void stackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting); //called when stack id attacked by stack with id IDby
void stackAttacking(int ID, int dest); //called when stack with id ID is attacking something on hex dest
void newRound(int number); //caled when round is ended; number is the number of round
void hexLclicked(int whichOne); //hex only call-in
@ -222,6 +231,7 @@ public:
void battleFinished(const BattleResult& br); //called when battle is finished - battleresult window should be printed
void spellCasted(SpellCasted * sc); //called when a hero casts a spell
void castThisSpell(int spellID); //called when player has chosen a spell from spellbook
void displayEffect(ui32 effect, int destTile, bool affected); //displays effect of a spell on the battlefield; affected: true - attacker. false - defender
friend class CBattleHex;
friend class CBattleReslutWindow;

View File

@ -1998,6 +1998,13 @@ void CPlayerInterface::actionStarted(const BattleAction* action)
{
battleInt->deactivate();
}
if(action->actionType == 1)
{
if(action->side)
battleInt->defendingHero->setPhase(4);
else
battleInt->attackingHero->setPhase(4);
}
}
void CPlayerInterface::actionFinished(const BattleAction* action)
@ -2008,6 +2015,13 @@ void CPlayerInterface::actionFinished(const BattleAction* action)
{
battleInt->activate();
}
if(action->actionType == 1)
{
if(action->side)
battleInt->defendingHero->setPhase(0);
else
battleInt->attackingHero->setPhase(0);
}
}
BattleAction CPlayerInterface::activeStack(int stackID) //called when it's turn of that stack
@ -2061,11 +2075,12 @@ void CPlayerInterface::battleSpellCasted(SpellCasted *sc)
}
void CPlayerInterface::battleStackAttacked(BattleStackAttacked * bsa)
{
battleInt->displayEffect(bsa->effect, cb->battleGetStackByID(bsa->stackAttacked)->position, cb->battleGetStackByID(bsa->stackAttacked)->attackerOwned);
boost::unique_lock<boost::recursive_mutex> un(*pim);
if(bsa->killed())
battleInt->stackKilled(bsa->stackAttacked, bsa->damageAmount, bsa->killedAmount, -1, false, bsa->effect);
battleInt->stackKilled(bsa->stackAttacked, bsa->damageAmount, bsa->killedAmount, -1, false);
else
battleInt->stackIsAttacked(bsa->stackAttacked, bsa->damageAmount, bsa->killedAmount, -1, false, bsa->effect);
battleInt->stackIsAttacked(bsa->stackAttacked, bsa->damageAmount, bsa->killedAmount, -1, false);
}
void CPlayerInterface::battleAttack(BattleAttack *ba)
{

View File

@ -148,6 +148,34 @@ void Graphics::initializeBattleGraphics()
{
bher>>battleHeroes[i];
}
//initialization of AC->def name mapping
std::ifstream acd;
acd.open("config/AC_desc.txt", std::ios::binary);
if(!acd.is_open())
{
tlog1<<"lack of config/AC_desc.txt file!"<<std::endl;
}
else
{
std::string buf;
acd>>buf;
int ACid, numberOfDefs;
while(true)
{
std::vector< std::string > toAdd;
acd>>ACid;
if(ACid == -1)
break;
acd>>numberOfDefs;
for(int g=0; g<numberOfDefs; ++g)
{
acd>>buf;
toAdd.push_back(buf);
}
battleACToDef[ACid] = toAdd;
}
}
}
Graphics::Graphics()
{

View File

@ -39,6 +39,7 @@ public:
//for battles
std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type
std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle
std::map< int, std::vector < std::string > > battleACToDef; //maps AC format to vector of appropriate def names
std::vector<std::string> guildBgs;// name of bitmaps with imgs for mage guild screen
//functions
Graphics();

87
config/AC_desc.txt Normal file
View File

@ -0,0 +1,87 @@
//WoG_Ac_format_to_def_names_mapping
0 1 C10SPW.DEF
1 1 C03SPA.DEF
2 1 C01SPA0.DEF
3 1 C02SPA0.DEF
4 1 SP12_.DEF
5 1 C02SPE0.DEF
6 1 C02SPF0.DEF
7 1 C04SPA0.DEF
8 1 C04SPE0.DEF
9 1 C04SPF0.DEF
10 0
11 1 C05SPF0.DEF
12 1 C06SPF0.DEF
13 1 C07SPA0.DEF
14 1 C07SPA1.DEF
15 1 C0FEAR.DEF
16 1 C08SPE0.DEF
17 1 C08SPF0.DEF
18 1 C09SPA0.DEF
19 3 C17SPE0.DEF C17SPE1.DEF C17SPE2.DEF
20 1 C09SPW0.DEF
21 1 C10SPA0.DEF
22 1 C11SPE0.DEF
23 1 C11SPF0.DEF
24 1 C11SPW0.DEF
25 1 C12SPA0.DEF
26 1 C13SPA0.DEF
27 1 C13SPE0.DEF
28 1 C13SPW0.DEF
29 1 C04SPE0.DEF
30 1 C14SPE0.DEF
31 1 C15SPA0.DEF
32 3 C15SPE0.DEF C15SPE1.DEF C15SPE2.DEF
33 7 C15SPE3.DEF C15SPE6.DEF C15SPE7.DEF C15SPE8.DEF C15SPE9.DEF C15SPE10.DEF C15SPE11.DEF
34 0
35 2 C01SPF.DEF C01SPF0.DEF
36 2 C01SPW.DEF C01SPW0.DEF
37 0
38 0
39 2 C03SPW.DEF C03SPW0.DEF
40 2 C04SPW.DEF C04SPW0.DEF
41 2 C05SPW.DEF C05SPW0.DEF
42 2 C06SPW.DEF C06SPW0.DEF
43 6 C07SPF0.DEF C07SPF1.DEF C07SPF2.DEF C07SPF6.DEF C07SPF7.DEF C07SPF8.DEF
44 6 C07SPF0.DEF C07SPF4.DEF C07SPF5.DEF C07SPF9.DEF C07SPF10.DEF C07SPF11.DEF
45 2 C07SPW.DEF C07SPW0.DEF
46 1 C08SPW5.DEF
47 1 C09SPF0.DEF
48 1 C10SPF0.DEF
49 1 C11SPA1.DEF
50 1 C12SPE0.DEF
51 1 C12SPF0.DEF
52 1 C12SPE0.DEF
53 2 C13SPF.DEF C13SPF0.DEF
54 2 C16SPE.DEF C16SPE0.DEF
55 1 C09SPE0.DEF
56 1 C0ACID.DEF
57 2 C09SPF1.DEF C09SPF2.DEF
58 0
59 1 C09SPF0.DEF
60 0
61 0
62 3 C07SPF60.DEF C07SPF61.DEF C07SPF62.DEF
63 0
64 1 C20SPX.DEF
65 0
66 0
67 0
68 0
69 1 C05SPE0.DEF
70 2 SP02_.DEF SP10_.DEF
71 1 SP01_.DEF
72 1 SP04_.DEF
73 1 SP03_.DEF
74 1 SP06_.DEF
75 1 SP07_A.DEF
76 1 SP07_B.DEF
77 1 SP08_.DEF
78 1 SP09_.DEF
79 1 C01SPE0.DEF
80 1 C07SPE0.DEF
81 1 C17SPW0.DEF
82 1 C09SPF3.DEF
83 0
84 1 ZMGC02.DEF
-1