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

Path for #773 from Yupsi

+ some refactorings
This commit is contained in:
DjWarmonger 2011-09-15 05:41:47 +00:00
parent 0cfb2deeaf
commit 1e4a08529c
2 changed files with 26 additions and 18 deletions

View File

@ -1185,7 +1185,7 @@ void CBattleInterface::addNewAnim(CBattleAnimation * anim)
CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSet * army2, CGHeroInstance *hero1, CGHeroInstance *hero2, const SDL_Rect & myRect, CPlayerInterface * att, CPlayerInterface * defen)
: queue(NULL), attackingHeroInstance(hero1), defendingHeroInstance(hero2), animCount(0),
activeStack(NULL), stackToActivate(NULL), mouseHoveredStack(-1), lastMouseHoveredStackAnimationTime(-1), previouslyHoveredHex(-1),
currentlyHoveredHex(-1), attackingHex(-1), tacticianInterface(NULL), spellDestSelectMode(false), spellToCast(NULL),
currentlyHoveredHex(-1), attackingHex(-1), tacticianInterface(NULL), spellDestSelectMode(false), stackCanCastSpell(false), spellToCast(NULL),
siegeH(NULL), attackerInt(att), defenderInt(defen), curInt(att), animIDhelper(0), givenCommand(NULL),
myTurn(false), resWindow(NULL), moveStarted(false), moveSh(-1), bresult(NULL)
@ -3361,19 +3361,19 @@ void CBattleInterface::castThisSpell(int spellID)
//choosing possible tragets
const CGHeroInstance * castingHero = (attackingHeroInstance->tempOwner == curInt->playerID) ? attackingHeroInstance : defendingHeroInstance;
const CSpell & spell = *CGI->spellh->spells[spellID];
spellSelMode = 0;
spellSelMode = ANY_LOCATION;
if(spell.getTargetType() == CSpell::CREATURE)
{
switch(spell.positiveness)
{
case -1 :
spellSelMode = 2;
spellSelMode = HOSTILE_CREATURE;
break;
case 0:
spellSelMode = 3;
spellSelMode = ANY_CREATURE;
break;
case 1:
spellSelMode = 1;
spellSelMode = FRIENDLY_CREATURE;
break;
}
}
@ -3384,41 +3384,41 @@ void CBattleInterface::castThisSpell(int spellID)
switch(spell.positiveness)
{
case -1 :
spellSelMode = 2;
spellSelMode = HOSTILE_CREATURE;
break;
case 0:
spellSelMode = 3;
spellSelMode = ANY_CREATURE;
break;
case 1:
spellSelMode = 1;
spellSelMode = FRIENDLY_CREATURE;
break;
}
}
else
{
spellSelMode = -1;
spellSelMode = NO_LOCATION;
}
}
if(spell.getTargetType() == CSpell::OBSTACLE)
{
spellSelMode = 4;
spellSelMode = OBSTACLE;
}
if(spell.range[ castingHero->getSpellSchoolLevel(&spell) ] == "X") //spell has no range
{
spellSelMode = -1;
spellSelMode = NO_LOCATION;
}
if(spell.id == 63) //teleport
{
spellSelMode = 5;
spellSelMode = TELEPORT;
}
if(spell.range[ castingHero->getSpellSchoolLevel(&spell) ].size() > 1) //spell has many-hex range
{
spellSelMode = 0;
spellSelMode = ANY_LOCATION;
}
if(spellSelMode == -1) //user does not have to select location
if(spellSelMode == NO_LOCATION) //user does not have to select location
{
spellToCast->destinationTile = -1;
curInt->cb->battleMakeAction(spellToCast);
@ -3466,6 +3466,10 @@ void CBattleInterface::activateStack()
bFlee->block(!curInt->cb->battleCanFlee());
bSurrender->block(curInt->cb->battleGetSurrenderCost() < 0);
//set casting flag to true if creature can use it to not check it every time
if (s->casts && s->hasBonus(Selector::type(Bonus::SPELLCASTER) || Selector::type(Bonus::DAEMON_SUMMONING)))
stackCanCastSpell = true;
GH.fakeMouseMove();
if(!pendingAnims.size() && !active)
@ -4115,7 +4119,7 @@ void CBattleHero::clickLeft(tribool down, bool previousState)
if(myOwner->spellDestSelectMode) //we are casting a spell
return;
if(!down && myHero && myOwner->curInt->cb->battleCanCastSpell()) //check conditions
if(!down && myHero && myOwner->myTurn && myOwner->curInt->cb->battleCanCastSpell()) //check conditions
{
for(int it=0; it<BFIELD_SIZE; ++it) //do nothing when any hex is hovered - hero's animation overlaps battlefield
{

View File

@ -417,6 +417,10 @@ struct CatapultProjectileInfo
/// drawing everything correctly.
class CBattleInterface : public CIntObject
{
enum SpellSelectionType
{
ANY_LOCATION = 0, FRIENDLY_CREATURE, HOSTILE_CREATURE, ANY_CREATURE, OBSTACLE, TELEPORT, NO_LOCATION = -1
};
private:
SDL_Surface * background, * menu, * amountNormal, * amountNegative, * amountPositive, * amountEffNeutral, * cellBorders, * backgroundWithHexes;
AdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
@ -448,9 +452,9 @@ private:
CPlayerInterface *tacticianInterface; //used during tactics mode, points to the interface of player with higher tactics (can be either attacker or defender in hot-seat), valid onloy for human players
bool tacticsMode;
bool stackCanCastSpell; //if true, active stack could possibly cats some target spell
bool spellDestSelectMode; //if true, player is choosing destination for his spell
int spellSelMode; //0 - any location, 1 - any friendly creature, 2 - any hostile creature, 3 - any creature,
//4 - obstacle, 5 - teleport -1 - no location
SpellSelectionType spellSelMode;
BattleAction * spellToCast; //spell for which player is choosing destination
void endCastingSpell(); //ends casting spell (eg. when spell has been cast or canceled)
@ -514,7 +518,7 @@ public:
//std::vector< CBattleObstacle * > obstacles; //vector of obstacles on the battlefield
SDL_Surface * cellBorder, * cellShade;
CondSh<BattleAction *> *givenCommand; //data != NULL if we have i.e. moved current unit
bool myTurn; //if true, interface is active (commands can be ordered
bool myTurn; //if true, interface is active (commands can be ordered)
CBattleResultWindow * resWindow; //window of end of battle
bool moveStarted; //if true, the creature that is already moving is going to make its first step