|
|
@@ -396,138 +396,206 @@ void CCallback::unregisterBattleInterface(shared_ptr<IBattleEventsReceiver> batt
|
|
|
cl->additionalBattleInts[*player] -= battleEvents;
|
|
|
}
|
|
|
|
|
|
-CBattleCallback::CBattleCallback(CGameState *GS, boost::optional<PlayerColor> Player, CClient *C )
|
|
|
-{
|
|
|
- gs = GS;
|
|
|
- player = Player;
|
|
|
- cl = C;
|
|
|
-}
|
|
|
-
|
|
|
-bool CBattleCallback::battleMakeTacticAction( BattleAction * action )
|
|
|
-{
|
|
|
- assert(cl->gs->curB->tacticDistance);
|
|
|
- MakeAction ma;
|
|
|
- ma.ba = *action;
|
|
|
- sendRequest(&ma);
|
|
|
- return true;
|
|
|
-}
|
|
|
-
|
|
|
-bool CAutomationCallback::moveHero(const CGHeroInstance *h, int3 dst)
|
|
|
-{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
-}
|
|
|
-
|
|
|
-bool CAutomationCallback::dismissHero(const CGHeroInstance * hero)
|
|
|
-{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
-}
|
|
|
-
|
|
|
-void CAutomationCallback::dig(const CGObjectInstance *hero)
|
|
|
-{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
-}
|
|
|
-
|
|
|
-void CAutomationCallback::castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos /*= int3(-1, -1, -1) */)
|
|
|
-{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
-}
|
|
|
-
|
|
|
-void CAutomationCallback::recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero)
|
|
|
+shared_ptr<CAutomationModule> CCallback::createAutomationModule(const std::string &moduleName, const ObjectsCeded &objects, const boost::any &initialMessage /*= boost::none*/)
|
|
|
{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
+ auto module = CDynLibHandler::getNewAutomationModule(moduleName);
|
|
|
+ installAutomationModule(module, objects);
|
|
|
+ module->receivedMessage(initialMessage);
|
|
|
+ return module;
|
|
|
}
|
|
|
|
|
|
-bool CAutomationCallback::buildBuilding(const CGTownInstance *town, BuildingID buildingID)
|
|
|
+void CCallback::installAutomationModule(shared_ptr<CAutomationModule> module, const ObjectsCeded &objects)
|
|
|
{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
+ auto cb = make_shared<CAutomationCallback>(gs, player, cl, module);
|
|
|
+ module->automationInit(cb, objects);
|
|
|
+ registerGameInterface(module);
|
|
|
+ cb->waitTillRealize = module->needsWaitingForRealize();
|
|
|
+ cb->unlockGsWhenWaiting = module->needsUnlockingGs();
|
|
|
+ module->modulePrepared();
|
|
|
}
|
|
|
|
|
|
-void CAutomationCallback::recruitCreatures(const CGObjectInstance *obj, CreatureID ID, ui32 amount, si32 level/*=-1*/)
|
|
|
+void CCallback::removeAutomationModule(shared_ptr<CAutomationModule> module)
|
|
|
{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
+ unregisterGameInterface(module);
|
|
|
}
|
|
|
|
|
|
-bool CAutomationCallback::upgradeCreature(const CArmedInstance *obj, SlotID stackPos, CreatureID newID/*=CreatureID::NONE*/)
|
|
|
+void CCallback::giveObjectToModule(const CGObjectInstance *obj, shared_ptr<CAutomationModule> module)
|
|
|
{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
-}
|
|
|
-
|
|
|
-void CAutomationCallback::swapGarrisonHero(const CGTownInstance *town)
|
|
|
-{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
-}
|
|
|
-
|
|
|
-void CAutomationCallback::trade(const CGObjectInstance *market, EMarketMode::EMarketMode mode, int id1, int id2, int val1, const CGHeroInstance *hero /*= NULL*/)
|
|
|
-{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
-}
|
|
|
-
|
|
|
-int CAutomationCallback::selectionMade(int selection, QueryID queryID)
|
|
|
-{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
-}
|
|
|
-
|
|
|
-int CAutomationCallback::swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2)
|
|
|
-{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
-}
|
|
|
-
|
|
|
-int CAutomationCallback::mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2)
|
|
|
-{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
-}
|
|
|
+ if(module->receivedObjects.hasObject(obj))
|
|
|
+ return;
|
|
|
|
|
|
-int CAutomationCallback::mergeOrSwapStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2)
|
|
|
-{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
+ module->receivedObjects.add(obj);
|
|
|
+ module->newObjectReceived(obj);
|
|
|
}
|
|
|
|
|
|
-int CAutomationCallback::splitStack(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2, int val)
|
|
|
+void CCallback::takeObjectFromModule(const CGObjectInstance *obj, shared_ptr<CAutomationModule> module)
|
|
|
{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
-}
|
|
|
+ if(!module->receivedObjects.hasObject(obj))
|
|
|
+ return;
|
|
|
|
|
|
-bool CAutomationCallback::swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation &l2)
|
|
|
-{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
+ module->receivedObjects.remove(obj);
|
|
|
+ module->objectTakenAway(obj);
|
|
|
}
|
|
|
|
|
|
-bool CAutomationCallback::assembleArtifacts(const CGHeroInstance * hero, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo)
|
|
|
+void CCallback::sendMessageToModule(shared_ptr<CAutomationModule> module, const boost::any &message)
|
|
|
{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
+ module->receivedMessage(message);
|
|
|
}
|
|
|
|
|
|
-bool CAutomationCallback::dismissCreature(const CArmedInstance *obj, SlotID stackPos)
|
|
|
+std::vector<shared_ptr<CAutomationModule>> CCallback::getAutomationInterfaces()
|
|
|
{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
-}
|
|
|
+ std::vector<shared_ptr<CAutomationModule>> ret;
|
|
|
+ BOOST_FOREACH(auto &interfacePtr, cl->additionalPlayerInts[*player])
|
|
|
+ if(auto automationModule = std::dynamic_pointer_cast<CAutomationModule>(interfacePtr))
|
|
|
+ ret.push_back(automationModule);
|
|
|
|
|
|
-void CAutomationCallback::endTurn()
|
|
|
-{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
-void CAutomationCallback::buyArtifact(const CGHeroInstance *hero, ArtifactID aid)
|
|
|
+void CCallback::executeAutomation()
|
|
|
{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
+ BOOST_FOREACH(auto module, getAutomationInterfaces())
|
|
|
+ module->execute();
|
|
|
}
|
|
|
|
|
|
-void CAutomationCallback::setFormation(const CGHeroInstance * hero, bool tight)
|
|
|
+CBattleCallback::CBattleCallback(CGameState *GS, boost::optional<PlayerColor> Player, CClient *C )
|
|
|
{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
+ gs = GS;
|
|
|
+ player = Player;
|
|
|
+ cl = C;
|
|
|
}
|
|
|
|
|
|
-void CAutomationCallback::setSelection(const CArmedInstance * obj)
|
|
|
+bool CBattleCallback::battleMakeTacticAction( BattleAction * action )
|
|
|
{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
+ assert(cl->gs->curB->tacticDistance);
|
|
|
+ MakeAction ma;
|
|
|
+ ma.ba = *action;
|
|
|
+ sendRequest(&ma);
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
-void CAutomationCallback::buildBoat(const IShipyard *obj)
|
|
|
-{
|
|
|
- throw std::exception("The method or operation is not implemented.");
|
|
|
-}
|
|
|
+// bool CAutomationCallback::moveHero(const CGHeroInstance *h, int3 dst)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// bool CAutomationCallback::dismissHero(const CGHeroInstance * hero)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// void CAutomationCallback::dig(const CGObjectInstance *hero)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// void CAutomationCallback::castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos /*= int3(-1, -1, -1) */)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// void CAutomationCallback::recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// bool CAutomationCallback::buildBuilding(const CGTownInstance *town, BuildingID buildingID)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// void CAutomationCallback::recruitCreatures(const CGObjectInstance *obj, CreatureID ID, ui32 amount, si32 level/*=-1*/)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// bool CAutomationCallback::upgradeCreature(const CArmedInstance *obj, SlotID stackPos, CreatureID newID/*=CreatureID::NONE*/)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// void CAutomationCallback::swapGarrisonHero(const CGTownInstance *town)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// void CAutomationCallback::trade(const CGObjectInstance *market, EMarketMode::EMarketMode mode, int id1, int id2, int val1, const CGHeroInstance *hero /*= NULL*/)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// int CAutomationCallback::selectionMade(int selection, QueryID queryID)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// int CAutomationCallback::swapCreatures(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// int CAutomationCallback::mergeStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// int CAutomationCallback::mergeOrSwapStacks(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// int CAutomationCallback::splitStack(const CArmedInstance *s1, const CArmedInstance *s2, SlotID p1, SlotID p2, int val)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// bool CAutomationCallback::swapArtifacts(const ArtifactLocation &l1, const ArtifactLocation &l2)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// bool CAutomationCallback::assembleArtifacts(const CGHeroInstance * hero, ArtifactPosition artifactSlot, bool assemble, ArtifactID assembleTo)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// bool CAutomationCallback::dismissCreature(const CArmedInstance *obj, SlotID stackPos)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// void CAutomationCallback::endTurn()
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// void CAutomationCallback::buyArtifact(const CGHeroInstance *hero, ArtifactID aid)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// void CAutomationCallback::setFormation(const CGHeroInstance * hero, bool tight)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// void CAutomationCallback::setSelection(const CArmedInstance * obj)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// void CAutomationCallback::buildBoat(const IShipyard *obj)
|
|
|
+// {
|
|
|
+// throw std::exception("The method or operation is not implemented.");
|
|
|
+// }
|
|
|
+//
|
|
|
+// shared_ptr<CAutomationModule> CAutomationCallback::getModule()
|
|
|
+// {
|
|
|
+// return automationModule.lock();
|
|
|
+// }
|
|
|
|
|
|
-shared_ptr<CAutomationInterface> CAutomationCallback::getModule()
|
|
|
+CAutomationCallback::CAutomationCallback(CGameState * GS, boost::optional<PlayerColor> Player, CClient *C, shared_ptr<CAutomationModule> module)
|
|
|
+ : CCallback(GS, Player, C)
|
|
|
{
|
|
|
- return automationModule.lock();
|
|
|
-}
|
|
|
+ automationModule = module;
|
|
|
+}
|