1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

- Second part of battle interface.

- Testing for Stack Artifacts feature.
This commit is contained in:
DjWarmonger 2012-04-17 08:46:09 +00:00
parent aeb9cf9460
commit 294276ea13
4 changed files with 142 additions and 74 deletions

View File

@ -1859,11 +1859,8 @@ void CBattleInterface::battleTriggerEffect(const BattleTriggerEffect & bte)
switch (bte.effect) switch (bte.effect)
{ {
case Bonus::HP_REGENERATION: case Bonus::HP_REGENERATION:
if( stack->hasBonusOfType(Bonus::HP_REGENERATION) || stack->hasBonusOfType(Bonus::FULL_HP_REGENERATION)) displayEffect(74, stack->position);
{ CCS->soundh->playSound(soundBase::REGENER);
displayEffect(74, stack->position);
CCS->soundh->playSound(soundBase::REGENER);
}
break; break;
case Bonus::MANA_DRAIN: case Bonus::MANA_DRAIN:
displayEffect(77, stack->position); displayEffect(77, stack->position);
@ -1935,7 +1932,7 @@ void CBattleInterface::activateStack()
creatureSpellToCast = spellcaster->subtype; creatureSpellToCast = spellcaster->subtype;
if(creatureSpellToCast < 0) //TODO proper way of detecting casters of positive spells if(creatureSpellToCast < 0) //TODO proper way of detecting casters of positive spells
spellSelMode = FRIENDLY_CREATURE; spellSelMode = FRIENDLY_CREATURE_SPELL;
else else
spellSelMode = selectionTypeByPositiveness(*CGI->spellh->spells[creatureSpellToCast]); spellSelMode = selectionTypeByPositiveness(*CGI->spellh->spells[creatureSpellToCast]);
} }
@ -1988,17 +1985,31 @@ void CBattleInterface::getPossibleActionsForStack(const CStack * stack)
if (stack->hasBonusOfType (Bonus::SPELLCASTER)) if (stack->hasBonusOfType (Bonus::SPELLCASTER))
{ {
//TODO: poll possible spells //TODO: poll possible spells
const CSpell * spell;
BOOST_FOREACH (Bonus * spellBonus, *stack->getBonuses (Selector::type(Bonus::SPELLCASTER))) BOOST_FOREACH (Bonus * spellBonus, *stack->getBonuses (Selector::type(Bonus::SPELLCASTER)))
{ {
possibleActions.push_back (selectionTypeByPositiveness (*CGI->spellh->spells[spellBonus->subtype])); spell = CGI->spellh->spells[spellBonus->subtype];
if (spell->isRisingSpell())
{
possibleActions.push_back (RISING_SPELL);
}
//possibleActions.push_back (NO_LOCATION);
//possibleActions.push_back (ANY_LOCATION);
//possibleActions.push_back (OTHER_SPELL);
else
{
switch (spellBonus->subtype)
{
case Spells::REMOVE_OBSTACLE:
possibleActions.push_back (OBSTACLE);
break;
default:
possibleActions.push_back (selectionTypeByPositiveness (*spell));
break;
}
}
} }
//TODO: determine whether spell is rising
//possibleActions.push_back (RISING_SPELL);
//possibleActions.push_back (OBSTACLE);
//possibleActions.push_back (SACRIFICE);
//possibleActions.push_back (NO_LOCATION);
//possibleActions.push_back (ANY_LOCATION);
//possibleActions.push_back (OTHER_SPELL);
} }
if (stack->hasBonusOfType (Bonus::RANDOM_SPELLCASTER)) if (stack->hasBonusOfType (Bonus::RANDOM_SPELLCASTER))
possibleActions.push_back (RANDOM_GENIE_SPELL); possibleActions.push_back (RANDOM_GENIE_SPELL);
@ -2570,11 +2581,11 @@ CBattleInterface::PossibleActions CBattleInterface::selectionTypeByPositiveness(
switch(spell.positiveness) switch(spell.positiveness)
{ {
case CSpell::NEGATIVE : case CSpell::NEGATIVE :
return HOSTILE_CREATURE; return HOSTILE_CREATURE_SPELL;
case CSpell::NEUTRAL: case CSpell::NEUTRAL:
return ANY_CREATURE; return ANY_CREATURE;
case CSpell::POSITIVE: case CSpell::POSITIVE:
return FRIENDLY_CREATURE; return FRIENDLY_CREATURE_SPELL;
} }
assert(0); assert(0);
return NO_LOCATION; //should never happen return NO_LOCATION; //should never happen
@ -2608,7 +2619,6 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
std::function<void()> realizeAction; std::function<void()> realizeAction;
//helper lambda that appropriately realizes action / sets cursor and tooltip //helper lambda that appropriately realizes action / sets cursor and tooltip
//TODO: separate action at mouse move and clicking
auto realizeThingsToDo = [&]() auto realizeThingsToDo = [&]()
{ {
if(eventType == MOVE) if(eventType == MOVE)
@ -2636,14 +2646,15 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
if (shere) if (shere)
ourStack = shere->owner == curInt->playerID; ourStack = shere->owner == curInt->playerID;
//TODO: handle
bool noStackIsHovered = true; //will cause removing a blue glow bool noStackIsHovered = true; //will cause removing a blue glow
localActions.clear(); localActions.clear();
BOOST_FOREACH (PossibleActions action, possibleActions) BOOST_FOREACH (PossibleActions action, possibleActions)
{ {
bool legalAction = false; bool legalAction = false; //this action is legal and can't be performed
bool illegalAction = false; bool illegalAction = false; //this action is not legal and should display message
//TODO: copy actions avaliable to perform at this hex to localActions. set currentAction
switch (action) switch (action)
{ {
case MOVE_TACTICS: case MOVE_TACTICS:
@ -2672,11 +2683,11 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
if(curInt->cb->battleCanShoot (activeStack, myNumber)) if(curInt->cb->battleCanShoot (activeStack, myNumber))
legalAction = true; legalAction = true;
break; break;
case HOSTILE_CREATURE: //TODO: check spell immunity case HOSTILE_CREATURE_SPELL: //TODO: check spell immunity
if (shere && !ourStack && isCastingPossibleHere (sactive, shere, myNumber)) if (shere && !ourStack && isCastingPossibleHere (sactive, shere, myNumber))
legalAction = true; legalAction = true;
break; break;
case FRIENDLY_CREATURE: case FRIENDLY_CREATURE_SPELL:
if (shere && ourStack && isCastingPossibleHere (sactive, shere, myNumber)) if (shere && ourStack && isCastingPossibleHere (sactive, shere, myNumber))
legalAction = true; legalAction = true;
break; break;
@ -2704,14 +2715,14 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
{ {
const ui8 skill = spellToCast ? getActiveHero()->getSpellSchoolLevel(CGI->spellh->spells[spellToCast->additionalInfo]) : 0; //skill level const ui8 skill = spellToCast ? getActiveHero()->getSpellSchoolLevel(CGI->spellh->spells[spellToCast->additionalInfo]) : 0; //skill level
//TODO: creature can cast a spell with some skill / spellpower as well //TODO: creature can cast a spell with some skill / spellpower as well
//TODO: explicitely save spell_to_cast * CSpell, power, skill //TODO: explicitely save power, skill
if (curInt->cb->battleCanTeleportTo(activeStack, myNumber, skill)) if (curInt->cb->battleCanTeleportTo(activeStack, myNumber, skill))
legalAction = true; legalAction = true;
else else
illegalAction = true; illegalAction = true;
} }
break; break;
case OTHER_SPELL: //TODO case SACRIFICE: //TODO
break; break;
case CATAPULT: case CATAPULT:
if (isCatapultAttackable(myNumber)) if (isCatapultAttackable(myNumber))
@ -2744,6 +2755,10 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
illegalAction = selectedAction; illegalAction = selectedAction;
else if (illegalActions.size()) else if (illegalActions.size())
illegalAction = illegalActions.front(); illegalAction = illegalActions.front();
else if (shere && ourStack && shere->alive()) //last possibility - display info about our creature
{
currentAction = CREATURE_INFO;
}
else else
illegalAction = INVALID; //we should never be here illegalAction = INVALID; //we should never be here
} }
@ -2819,8 +2834,8 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
consoleMsg = (boost::format(CGI->generaltexth->allTexts[296]) % shere->getName() % sactive->shots % estDmgText).str(); consoleMsg = (boost::format(CGI->generaltexth->allTexts[296]) % shere->getName() % sactive->shots % estDmgText).str();
} }
break; break;
case HOSTILE_CREATURE: case HOSTILE_CREATURE_SPELL:
case FRIENDLY_CREATURE: case FRIENDLY_CREATURE_SPELL:
case RISING_SPELL: case RISING_SPELL:
case RANDOM_GENIE_SPELL: case RANDOM_GENIE_SPELL:
if (spellToCast) //TODO: merge hero spell and creature spell into it if (spellToCast) //TODO: merge hero spell and creature spell into it
@ -2839,9 +2854,7 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
case OBSTACLE: case OBSTACLE:
consoleMsg = CGI->generaltexth->allTexts[550]; consoleMsg = CGI->generaltexth->allTexts[550];
isCastingPossible = true; isCastingPossible = true;
break; break;;
case OTHER_SPELL:
break;
case HEAL: case HEAL:
cursorFrame = ECursor::COMBAT_HEAL; cursorFrame = ECursor::COMBAT_HEAL;
consoleMsg = (boost::format(CGI->generaltexth->allTexts[419]) % shere->getName()).str(); //Apply first aid to the %s consoleMsg = (boost::format(CGI->generaltexth->allTexts[419]) % shere->getName()).str(); //Apply first aid to the %s
@ -2854,15 +2867,36 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
case CATAPULT: case CATAPULT:
cursorFrame = ECursor::COMBAT_SHOOT_CATAPULT; cursorFrame = ECursor::COMBAT_SHOOT_CATAPULT;
realizeAction = [=]{ giveCommand(BattleAction::CATAPULT, myNumber, activeStack->ID); }; realizeAction = [=]{ giveCommand(BattleAction::CATAPULT, myNumber, activeStack->ID); };
case CREATURE_INFO:
{
cursorFrame = ECursor::COMBAT_QUERY;
consoleMsg = (boost::format(CGI->generaltexth->allTexts[297]) % shere->getName()).str();
realizeAction = [=]{ GH.pushInt(createCreWindow(shere, true)); };
//setting console text
const time_t curTime = time(NULL);
CCreatureAnimation *hoveredStackAnim = creAnims[shere->ID];
if (shere->ID != mouseHoveredStack
&& curTime > lastMouseHoveredStackAnimationTime + HOVER_ANIM_DELTA
&& hoveredStackAnim->getType() == CCreatureAnim::HOLDING
&& hoveredStackAnim->framesInGroup(CCreatureAnim::MOUSEON) > 0)
{
hoveredStackAnim->playOnce(CCreatureAnim::MOUSEON);
lastMouseHoveredStackAnimationTime = curTime;
}
noStackIsHovered = false;
mouseHoveredStack = shere->ID;
}
break; break;
} }
} }
else else //no possible valid action, display message
{ {
switch (illegalAction) switch (illegalAction)
{ {
case HOSTILE_CREATURE: case HOSTILE_CREATURE_SPELL:
case FRIENDLY_CREATURE: case FRIENDLY_CREATURE_SPELL:
case RISING_SPELL: case RISING_SPELL:
case RANDOM_GENIE_SPELL: case RANDOM_GENIE_SPELL:
cursorFrame = ECursor::COMBAT_BLOCKED; cursorFrame = ECursor::COMBAT_BLOCKED;
@ -2886,16 +2920,30 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
realizeAction = [=] realizeAction = [=]
{ {
if(creatureCasting) switch (sp->id)
{ {
giveCommand(BattleAction::MONSTER_SPELL, myNumber, sactive->ID, creatureSpellToCast); case TELEPORT: //TODO: choose second target for Teleport or Sacrifice
} possibleActions.clear();
else possibleActions.push_back (TELEPORT);
{ break;
spellToCast->destinationTile = myNumber; case SACRIFICE:
curInt->cb->battleMakeAction(spellToCast); possibleActions.clear();
endCastingSpell(); possibleActions.push_back (SACRIFICE);
break;
default:
if(creatureCasting)
{
giveCommand(BattleAction::MONSTER_SPELL, myNumber, sactive->ID, creatureSpellToCast);
}
else
{
spellToCast->destinationTile = myNumber;
curInt->cb->battleMakeAction(spellToCast);
endCastingSpell();
}
break;
} }
}; };
} }
@ -2903,32 +2951,11 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
if(noStackIsHovered) if(noStackIsHovered)
mouseHoveredStack = -1; mouseHoveredStack = -1;
if (shere && ourStack && shere->alive()) //TODO: handle hover properly
{
cursorFrame = ECursor::COMBAT_QUERY;
consoleMsg = (boost::format(CGI->generaltexth->allTexts[297]) % shere->getName()).str();
realizeAction = [=]{ GH.pushInt(createCreWindow(shere, true)); };
//setting console text
const time_t curTime = time(NULL);
CCreatureAnimation *hoveredStackAnim = creAnims[shere->ID];
if (shere->ID != mouseHoveredStack
&& curTime > lastMouseHoveredStackAnimationTime + HOVER_ANIM_DELTA
&& hoveredStackAnim->getType() == CCreatureAnim::HOLDING
&& hoveredStackAnim->framesInGroup(CCreatureAnim::MOUSEON) > 0)
{
hoveredStackAnim->playOnce(CCreatureAnim::MOUSEON);
lastMouseHoveredStackAnimationTime = curTime;
}
noStackIsHovered = false;
mouseHoveredStack = shere->ID;
}
} }
bool CBattleInterface::isCastingPossibleHere (const CStack * sactive, const CStack * shere, BattleHex myNumber) bool CBattleInterface::isCastingPossibleHere (const CStack * sactive, const CStack * shere, BattleHex myNumber)
{ {
creatureCasting = (spellDestSelectMode >= NO_LOCATION && spellDestSelectMode <= OTHER_SPELL) && //what does it really check? creatureCasting = (spellDestSelectMode >= NO_LOCATION && spellDestSelectMode <= RANDOM_GENIE_SPELL) && //what does it really check?
stackCanCastSpell && shere != sactive; stackCanCastSpell && shere != sactive;
//TODO: use currentAction //TODO: use currentAction

View File

@ -93,10 +93,10 @@ class CBattleInterface : public CIntObject
{ {
enum PossibleActions // actions performed at l-click enum PossibleActions // actions performed at l-click
{ {
INVALID = -1, INVALID = -1, CREATURE_INFO,
MOVE_TACTICS, CHOOSE_TACTICS_STACK, MOVE_TACTICS, CHOOSE_TACTICS_STACK,
MOVE_STACK, ATTACK, WALK_AND_ATTACK, ATTACK_AND_RETURN, SHOOT, //OPEN_GATE, //we can open castle gate during siege MOVE_STACK, ATTACK, WALK_AND_ATTACK, ATTACK_AND_RETURN, SHOOT, //OPEN_GATE, //we can open castle gate during siege
NO_LOCATION, ANY_LOCATION, FRIENDLY_CREATURE, HOSTILE_CREATURE, RISING_SPELL, ANY_CREATURE, OBSTACLE, TELEPORT, SACRIFICE, RANDOM_GENIE_SPELL, OTHER_SPELL, NO_LOCATION, ANY_LOCATION, FRIENDLY_CREATURE_SPELL, HOSTILE_CREATURE_SPELL, RISING_SPELL, ANY_CREATURE, OBSTACLE, TELEPORT, SACRIFICE, RANDOM_GENIE_SPELL,
CATAPULT, HEAL, RISE_DEMONS CATAPULT, HEAL, RISE_DEMONS
}; };
private: private:

View File

@ -188,6 +188,11 @@ std::string CArtifact::nodeName() const
// // //boost::algorithm::replace_first(description, "[spell name]", VLC->spellh->spells[spellid].name); // // //boost::algorithm::replace_first(description, "[spell name]", VLC->spellh->spells[spellid].name);
// } // }
void CArtifact::setDescription (std::string desc)
{
description = desc;
}
CArtHandler::CArtHandler() CArtHandler::CArtHandler()
{ {
VLC->arth = this; VLC->arth = this;
@ -475,9 +480,10 @@ void CArtHandler::getAllowedArts(std::vector<ConstTransitivePtr<CArtifact> > &ou
out.push_back(art); out.push_back(art);
} }
} }
void CArtHandler::giveArtBonus( int aid, Bonus::BonusType type, int val, int subtype, int valType, ILimiter * limiter ) void CArtHandler::giveArtBonus( int aid, Bonus::BonusType type, int val, int subtype, int valType, ILimiter * limiter, int additionalInfo)
{ {
Bonus *added = new Bonus(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,aid,subtype); Bonus *added = new Bonus(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,aid,subtype);
added->additionalInfo = additionalInfo;
added->valType = valType; added->valType = valType;
added->limiter.reset(limiter); added->limiter.reset(limiter);
if(type == Bonus::MORALE || type == Bonus::LUCK) if(type == Bonus::MORALE || type == Bonus::LUCK)
@ -487,9 +493,10 @@ void CArtHandler::giveArtBonus( int aid, Bonus::BonusType type, int val, int sub
artifacts[aid]->addNewBonus(added); artifacts[aid]->addNewBonus(added);
} }
void CArtHandler::giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype, IPropagator* propagator /*= NULL*/) void CArtHandler::giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype, IPropagator* propagator /*= NULL*/, int additionalInfo)
{ {
Bonus *added = new Bonus(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,aid,subtype); Bonus *added = new Bonus(Bonus::PERMANENT,type,Bonus::ARTIFACT,val,aid,subtype);
added->additionalInfo = additionalInfo;
added->valType = Bonus::BASE_NUMBER; added->valType = Bonus::BASE_NUMBER;
added->propagator.reset(propagator); added->propagator.reset(propagator);
if(type == Bonus::MORALE || type == Bonus::LUCK) if(type == Bonus::MORALE || type == Bonus::LUCK)
@ -752,10 +759,43 @@ void CArtHandler::addBonuses()
makeItCreatureArt(142); makeItCreatureArt(142);
makeItCreatureArt(143); makeItCreatureArt(143);
makeItCreatureArt(156); makeItCreatureArt(156);
giveArtBonus(141, Bonus::STACK_HEALTH, +400, -1, Bonus::PERCENT_TO_BASE); //Magic Wans //Magic Wand
giveArtBonus(142, Bonus::STACK_HEALTH, +400, -1, Bonus::PERCENT_TO_BASE); //Tower Arrow giveArtBonus(141, Bonus::CASTS, 10);
giveArtBonus(143, Bonus::STACK_HEALTH, +400, -1, Bonus::PERCENT_TO_BASE); //Monster's Power giveArtBonus(141, Bonus::SPELLCASTER, 0, Spells::IMPLOSION);
giveArtBonus(156, Bonus::STACK_HEALTH, +2); //Warlord's banner giveArtBonus(141, Bonus::SPELLCASTER, 0, Spells::FIREBALL);
giveArtBonus(141, Bonus::RANDOM_SPELLCASTER, 0);
giveArtBonus(141, Bonus::DAEMON_SUMMONING, 10, 63); //rise vampire lords
giveArtBonus(141, Bonus::ENCHANTER, 0, Spells::LIGHTNING_BOLT, NULL, 2);
giveArtBonus(141, Bonus::REBIRTH, 1, 1);
giveArtBonus(141, Bonus::MANA_DRAIN, 10);
giveArtBonus(141, Bonus::HEALER, 25);
artifacts[141].get()->setDescription ("Casts Implosion / Fireball, random Genie spell, summons Vampire Lords from corpses, casts Lighthning Bolt every 2 turns, rebirths at least one creature, drains enemy mana and heals");
//Tower Arrow
giveArtBonus(142, Bonus::NO_DISTANCE_PENALTY, 0);
giveArtBonus(142, Bonus::ADDITIONAL_ATTACK, 2);
giveArtBonus(142, Bonus::SPELL_LIKE_ATTACK, 1, Spells::INFERNO);
giveArtBonus(142, Bonus::CATAPULT, 0);
giveArtBonus(142, Bonus::ACID_BREATH, 20);
giveArtBonus(142, Bonus::SHOTS, 200, 0, Bonus::PERCENT_TO_BASE);
giveArtBonus(142, Bonus::SPELL_BEFORE_ATTACK, 1, Spells::AGE, NULL, 50);
giveArtBonus(142, Bonus::SPELL_AFTER_ATTACK, 1, Spells::BERSERK, NULL, 50);
giveArtBonus(142, Bonus::SPELL_AFTER_ATTACK, 1, Spells::POISON, NULL, 50);
giveArtBonus(142, Bonus::SPELL_AFTER_ATTACK, 1, Spells::DISRUPTING_RAY, NULL, 50);
artifacts[142].get()->setDescription ("Tripple shots, tripple attack, casts various spells during attack, attacks have range of Inferno, no distance penalty, catapult");
//Monster's Power
giveArtBonus(143, Bonus::STACK_HEALTH, +100, -1, Bonus::PERCENT_TO_BASE);
giveArtBonus(143, Bonus::CREATURE_DAMAGE, +100, 2, Bonus::PERCENT_TO_ALL);
giveArtBonus(143, Bonus::HP_REGENERATION, 50);
giveArtBonus(143, Bonus::NO_RETALIATION, 0);
giveArtBonus(143, Bonus::RETURN_AFTER_STRIKE, 0);
giveArtBonus(143, Bonus::ATTACKS_ALL_ADJACENT, 0);
giveArtBonus(143, Bonus::SPELL_RESISTANCE_AURA, 100);
giveArtBonus(143, Bonus::DIRECT_DAMAGE_IMMUNITY, 0);
artifacts[143].get()->setDescription ("Double health, double max damage, hp regeneration, can't retaliate, return after strike, attack all around, 100% spell reisstance aura, immune to direct damage spells");
//Warlord's banner
giveArtBonus(156, Bonus::STACK_HEALTH, +2);
artifacts[156].get()->setDescription ("+2 stack HP");
} }
} }

View File

@ -49,6 +49,7 @@ public:
const std::string &Name() const; //getter const std::string &Name() const; //getter
const std::string &Description() const; //getter const std::string &Description() const; //getter
bool isBig () const; bool isBig () const;
void setDescription (std::string desc);
int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other int getArtClassSerial() const; //0 - treasure, 1 - minor, 2 - major, 3 - relic, 4 - spell scroll, 5 - other
std::string nodeName() const OVERRIDE; std::string nodeName() const OVERRIDE;
@ -217,8 +218,8 @@ public:
class DLL_LINKAGE CArtHandler //handles artifacts class DLL_LINKAGE CArtHandler //handles artifacts
{ {
void giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype = -1, int valType = Bonus::BASE_NUMBER, ILimiter * limiter = NULL); void giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype = -1, int valType = Bonus::BASE_NUMBER, ILimiter * limiter = NULL, int additionalinfo = 0);
void giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype, IPropagator* propagator); void giveArtBonus(int aid, Bonus::BonusType type, int val, int subtype, IPropagator* propagator, int additionalinfo = 0);
public: public:
std::vector<CArtifact*> treasures, minors, majors, relics; std::vector<CArtifact*> treasures, minors, majors, relics;
std::vector< ConstTransitivePtr<CArtifact> > artifacts; std::vector< ConstTransitivePtr<CArtifact> > artifacts;