From 2193f8912e572aacf36ea43affd47ed02d44de84 Mon Sep 17 00:00:00 2001 From: DjWarmonger Date: Wed, 4 Apr 2012 08:03:52 +0000 Subject: [PATCH] - Framework of new battle interface - Minor fixes for AI --- AI/VCAI/VCAI.cpp | 2 + client/BattleInterface/CBattleInterface.cpp | 61 ++++++++++++++++++++- client/BattleInterface/CBattleInterface.h | 14 +++++ 3 files changed, 76 insertions(+), 1 deletion(-) diff --git a/AI/VCAI/VCAI.cpp b/AI/VCAI/VCAI.cpp index 453db3444..e5dba384d 100644 --- a/AI/VCAI/VCAI.cpp +++ b/AI/VCAI/VCAI.cpp @@ -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)) diff --git a/client/BattleInterface/CBattleInterface.cpp b/client/BattleInterface/CBattleInterface.cpp index 9b0b15345..38abbd383 100644 --- a/client/BattleInterface/CBattleInterface.cpp +++ b/client/BattleInterface/CBattleInterface.cpp @@ -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) @@ -2537,7 +2583,7 @@ std::string formatDmgRange(std::pair dmgRange) void CBattleInterface::handleHex(BattleHex myNumber, int eventType) { if(!myTurn) //we are not permit to do anything - return; + return; // This function handles mouse move over hexes and l-clicking on them. // First we decide what happens if player clicks on this hex and set appropriately @@ -2581,6 +2627,12 @@ void CBattleInterface::handleHex(BattleHex myNumber, int eventType) && shere != sactive; 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; diff --git a/client/BattleInterface/CBattleInterface.h b/client/BattleInterface/CBattleInterface.h index 6c97be2c7..a51b5b248 100644 --- a/client/BattleInterface/CBattleInterface.h +++ b/client/BattleInterface/CBattleInterface.h @@ -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 possibleActions; //all actions possible to call at the moment by player + std::vector 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