mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
- Framework of new battle interface
- Minor fixes for AI
This commit is contained in:
parent
c61f536d8b
commit
2193f8912e
@ -2628,9 +2628,11 @@ bool shouldVisit (const CGHeroInstance * h, const CGObjectInstance * obj)
|
||||
if (myRes[Res::GOLD] - GOLD_RESERVE < 1000)
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case Obj::LIBRARY_OF_ENLIGHTENMENT:
|
||||
if (h->level < 12)
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (obj->wasVisited(h))
|
||||
|
@ -41,6 +41,8 @@ const double M_PI = 3.14159265358979323846;
|
||||
#endif
|
||||
#include "../../lib/UnlockGuard.h"
|
||||
|
||||
using namespace boost::assign;
|
||||
|
||||
const time_t CBattleInterface::HOVER_ANIM_DELTA = 1;
|
||||
|
||||
/*
|
||||
@ -363,6 +365,9 @@ CBattleInterface::CBattleInterface(const CCreatureSet * army1, const CCreatureSe
|
||||
int channel = CCS->soundh->playSoundFromSet(CCS->soundh->battleIntroSounds);
|
||||
CCS->soundh->setCallback(channel, boost::bind(&CMusicHandler::playMusicFromSet, CCS->musich, CCS->musich->battleMusics, -1));
|
||||
memset(stackCountOutsideHexes, 1, GameConstants::BFIELD_SIZE * sizeof(bool)); //initialize array with trues
|
||||
|
||||
currentAction = INVALID;
|
||||
selectedAction = INVALID;
|
||||
}
|
||||
|
||||
CBattleInterface::~CBattleInterface()
|
||||
@ -1967,6 +1972,44 @@ void CBattleInterface::endCastingSpell()
|
||||
spellToCast = NULL;
|
||||
spellDestSelectMode = false;
|
||||
CCS->curh->changeGraphic(1, 6);
|
||||
|
||||
//restore actions for current stack
|
||||
possibleActions.clear();
|
||||
getPossibleActionsForStack (activeStack);
|
||||
}
|
||||
|
||||
void CBattleInterface::getPossibleActionsForStack(const CStack * stack)
|
||||
{
|
||||
//first action will be prioritized over later ones
|
||||
if (stack->casts) //TODO: check for battlefield effects that prevent casting?
|
||||
{
|
||||
if (stack->hasBonusOfType (Bonus::SPELLCASTER))
|
||||
{
|
||||
//TODO: poll possible spells
|
||||
possibleActions.push_back (OFFENSIVE_SPELL);
|
||||
possibleActions.push_back (FRIENDLY_SPELL);
|
||||
possibleActions.push_back (RISING_SPELL);
|
||||
//TODO: stacks casting remove obstacle?
|
||||
//possibleActions.push_back (OTHER_SPELL);
|
||||
}
|
||||
if (stack->hasBonusOfType (Bonus::RANDOM_SPELLCASTER))
|
||||
possibleActions.push_back (RANDOM_GENIE_SPELL);
|
||||
if (stack->hasBonusOfType (Bonus::DAEMON_SUMMONING))
|
||||
possibleActions.push_back (RISE_DEMONS);
|
||||
}
|
||||
if (stack->shots && stack->hasBonusOfType (Bonus::SHOOTER))
|
||||
possibleActions.push_back (SHOOT);
|
||||
if (stack->hasBonusOfType (Bonus::RETURN_AFTER_STRIKE));
|
||||
possibleActions.push_back (ATTACK_AND_RETURN);
|
||||
|
||||
possibleActions.push_back(ATTACK); //all active stacks can attack
|
||||
possibleActions.push_back(WALK_AND_ATTACK); //not all stacks can always walk, but we will check this elsewhere
|
||||
|
||||
if (siegeH && stack->hasBonusOfType (Bonus::CATAPULT)) //TODO: check shots
|
||||
possibleActions.push_back (CATAPULT);
|
||||
if (stack->hasBonusOfType (Bonus::HEALER))
|
||||
possibleActions.push_back (HEAL);
|
||||
|
||||
}
|
||||
|
||||
void CBattleInterface::showAliveStack(const CStack *stack, SDL_Surface * to)
|
||||
@ -2509,6 +2552,9 @@ void CBattleInterface::bTacticNextStack(const CStack *current /*= NULL*/)
|
||||
stackActivated(*it);
|
||||
else
|
||||
stackActivated(stacksOfMine.front());
|
||||
|
||||
possibleActions.clear();
|
||||
possibleActions += MOVE_TACTICS, CHOOSE_TACTICS_STACK;
|
||||
}
|
||||
|
||||
CBattleInterface::SpellSelectionType CBattleInterface::selectionTypeByPositiveness(const CSpell & spell)
|
||||
@ -2582,6 +2628,12 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType)
|
||||
|
||||
bool noStackIsHovered = true; //will cause removing a blue glow
|
||||
|
||||
localActions.clear();
|
||||
BOOST_FOREACH (int action, localActions)
|
||||
{
|
||||
//TODO: copy actions avaliable to perform at this hex to localActions. set currentAction
|
||||
}
|
||||
|
||||
//handle spellcasting (by hero or creature)
|
||||
if(!tacticsMode && (spellDestSelectMode || creatureCasting))
|
||||
{
|
||||
@ -2822,6 +2874,13 @@ pastCastingSpells:
|
||||
}
|
||||
}
|
||||
|
||||
if (vstd::contains(localActions, selectedAction))
|
||||
currentAction = selectedAction;
|
||||
else if (localActions.size())
|
||||
currentAction = localActions.front();
|
||||
else
|
||||
currentAction = INVALID;
|
||||
|
||||
realizeThingsToDo();
|
||||
if(noStackIsHovered)
|
||||
mouseHoveredStack = -1;
|
||||
|
@ -95,6 +95,14 @@ class CBattleInterface : public CIntObject
|
||||
{
|
||||
ANY_LOCATION = 0, FRIENDLY_CREATURE, HOSTILE_CREATURE, ANY_CREATURE, OBSTACLE, TELEPORT, NO_LOCATION = -1, STACK_SPELL_CANCELLED = -2
|
||||
};
|
||||
enum PossibleActions // actions performed at l-click
|
||||
{
|
||||
INVALID = -1,
|
||||
MOVE_TACTICS, CHOOSE_TACTICS_STACK,
|
||||
MOVE_STACK, ATTACK, WALK_AND_ATTACK, ATTACK_AND_RETURN, SHOOT, //OPEN_GATE, //we can open castle gate during siege
|
||||
OFFENSIVE_SPELL, FRIENDLY_SPELL, RISING_SPELL, RANDOM_GENIE_SPELL, OTHER_SPELL, //use SpellSelectionType for non-standard spells - should we merge it?
|
||||
CATAPULT, HEAL, RISE_DEMONS
|
||||
};
|
||||
private:
|
||||
SDL_Surface * background, * menu, * amountNormal, * amountNegative, * amountPositive, * amountEffNeutral, * cellBorders, * backgroundWithHexes;
|
||||
CAdventureMapButton * bOptions, * bSurrender, * bFlee, * bAutofight, * bSpell,
|
||||
@ -131,6 +139,12 @@ private:
|
||||
SpellSelectionType spellSelMode;
|
||||
BattleAction * spellToCast; //spell for which player is choosing destination
|
||||
si32 creatureSpellToCast;
|
||||
std::vector<int> possibleActions; //all actions possible to call at the moment by player
|
||||
std::vector<int> localActions; //actions possible to take on hovered hex
|
||||
int currentAction; //action that will be performed on l-click
|
||||
int selectedAction; //last action chosen (and saved) by player
|
||||
|
||||
void getPossibleActionsForStack (const CStack * stack); //called when stack gets its turn
|
||||
void endCastingSpell(); //ends casting spell (eg. when spell has been cast or canceled)
|
||||
|
||||
void showAliveStack(const CStack *stack, SDL_Surface * to); //helper function for function show
|
||||
|
Loading…
Reference in New Issue
Block a user