mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-22 22:13:35 +02:00
invite hero backend
This commit is contained in:
parent
1fb2a026ec
commit
346beea49c
@ -260,12 +260,12 @@ void CCallback::setFormation(const CGHeroInstance * hero, EArmyFormation mode)
|
|||||||
sendRequest(&pack);
|
sendRequest(&pack);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCallback::recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero)
|
void CCallback::recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero, const HeroTypeID & nextHero)
|
||||||
{
|
{
|
||||||
assert(townOrTavern);
|
assert(townOrTavern);
|
||||||
assert(hero);
|
assert(hero);
|
||||||
|
|
||||||
HireHero pack(hero->getHeroType(), townOrTavern->id);
|
HireHero pack(hero->getHeroType(), townOrTavern->id, nextHero);
|
||||||
pack.player = *player;
|
pack.player = *player;
|
||||||
sendRequest(&pack);
|
sendRequest(&pack);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ public:
|
|||||||
virtual void castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos = int3(-1, -1, -1))=0; //cast adventure map spell
|
virtual void castSpell(const CGHeroInstance *hero, SpellID spellID, const int3 &pos = int3(-1, -1, -1))=0; //cast adventure map spell
|
||||||
|
|
||||||
//town
|
//town
|
||||||
virtual void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero)=0;
|
virtual void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero, const HeroTypeID & nextHero=HeroTypeID::NONE)=0;
|
||||||
virtual bool buildBuilding(const CGTownInstance *town, BuildingID buildingID)=0;
|
virtual bool buildBuilding(const CGTownInstance *town, BuildingID buildingID)=0;
|
||||||
virtual void recruitCreatures(const CGDwelling *obj, const CArmedInstance * dst, CreatureID ID, ui32 amount, si32 level=-1)=0;
|
virtual void recruitCreatures(const CGDwelling *obj, const CArmedInstance * dst, CreatureID ID, ui32 amount, si32 level=-1)=0;
|
||||||
virtual bool upgradeCreature(const CArmedInstance *obj, SlotID stackPos, CreatureID newID=CreatureID::NONE)=0; //if newID==-1 then best possible upgrade will be made
|
virtual bool upgradeCreature(const CArmedInstance *obj, SlotID stackPos, CreatureID newID=CreatureID::NONE)=0; //if newID==-1 then best possible upgrade will be made
|
||||||
@ -185,7 +185,7 @@ public:
|
|||||||
void trade(const IMarket * market, EMarketMode mode, TradeItemSell id1, TradeItemBuy id2, ui32 val1, const CGHeroInstance * hero = nullptr) override;
|
void trade(const IMarket * market, EMarketMode mode, TradeItemSell id1, TradeItemBuy id2, ui32 val1, const CGHeroInstance * hero = nullptr) override;
|
||||||
void trade(const IMarket * market, EMarketMode mode, const std::vector<TradeItemSell> & id1, const std::vector<TradeItemBuy> & id2, const std::vector<ui32> & val1, const CGHeroInstance * hero = nullptr) override;
|
void trade(const IMarket * market, EMarketMode mode, const std::vector<TradeItemSell> & id1, const std::vector<TradeItemBuy> & id2, const std::vector<ui32> & val1, const CGHeroInstance * hero = nullptr) override;
|
||||||
void setFormation(const CGHeroInstance * hero, EArmyFormation mode) override;
|
void setFormation(const CGHeroInstance * hero, EArmyFormation mode) override;
|
||||||
void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero) override;
|
void recruitHero(const CGObjectInstance *townOrTavern, const CGHeroInstance *hero, const HeroTypeID & nextHero=HeroTypeID::NONE) override;
|
||||||
void save(const std::string &fname) override;
|
void save(const std::string &fname) override;
|
||||||
void sendMessage(const std::string &mess, const CGObjectInstance * currentObject = nullptr) override;
|
void sendMessage(const std::string &mess, const CGObjectInstance * currentObject = nullptr) override;
|
||||||
void gamePause(bool pause) override;
|
void gamePause(bool pause) override;
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#include "InfoWindows.h"
|
#include "InfoWindows.h"
|
||||||
|
|
||||||
#include "../CGameInfo.h"
|
#include "../CGameInfo.h"
|
||||||
|
#include "../CServerHandler.h"
|
||||||
|
#include "../Client.h"
|
||||||
#include "../CMusicHandler.h"
|
#include "../CMusicHandler.h"
|
||||||
#include "../CPlayerInterface.h"
|
#include "../CPlayerInterface.h"
|
||||||
#include "../CVideoHandler.h"
|
#include "../CVideoHandler.h"
|
||||||
@ -48,6 +50,7 @@
|
|||||||
#include "../lib/mapObjects/ObjectTemplate.h"
|
#include "../lib/mapObjects/ObjectTemplate.h"
|
||||||
#include "../lib/gameState/CGameState.h"
|
#include "../lib/gameState/CGameState.h"
|
||||||
#include "../lib/gameState/SThievesGuildInfo.h"
|
#include "../lib/gameState/SThievesGuildInfo.h"
|
||||||
|
#include "../lib/gameState/TavernHeroesPool.h"
|
||||||
#include "../lib/CGeneralTextHandler.h"
|
#include "../lib/CGeneralTextHandler.h"
|
||||||
#include "../lib/CHeroHandler.h"
|
#include "../lib/CHeroHandler.h"
|
||||||
#include "../lib/GameSettings.h"
|
#include "../lib/GameSettings.h"
|
||||||
@ -514,7 +517,17 @@ void CTavernWindow::recruitb()
|
|||||||
const CGHeroInstance *toBuy = (selected ? h2 : h1)->h;
|
const CGHeroInstance *toBuy = (selected ? h2 : h1)->h;
|
||||||
const CGObjectInstance *obj = tavernObj;
|
const CGObjectInstance *obj = tavernObj;
|
||||||
|
|
||||||
LOCPLINT->cb->recruitHero(obj, toBuy);
|
const auto & heroesPool = CSH->client->gameState()->heroesPool;
|
||||||
|
HeroTypeID nextHero = HeroTypeID::NONE;
|
||||||
|
|
||||||
|
for(auto & elem : heroesPool->unusedHeroesFromPool())
|
||||||
|
{
|
||||||
|
bool heroAvailable = heroesPool->isHeroAvailableFor(elem.first, tavernObj->getOwner());
|
||||||
|
if(heroAvailable && elem.second->getNameTranslated() == "Sir Mullich")
|
||||||
|
nextHero = elem.first;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOCPLINT->cb->recruitHero(obj, toBuy, nextHero);
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -516,12 +516,14 @@ struct DLL_LINKAGE SetFormation : public CPackForServer
|
|||||||
struct DLL_LINKAGE HireHero : public CPackForServer
|
struct DLL_LINKAGE HireHero : public CPackForServer
|
||||||
{
|
{
|
||||||
HireHero() = default;
|
HireHero() = default;
|
||||||
HireHero(HeroTypeID HID, const ObjectInstanceID & TID)
|
HireHero(HeroTypeID HID, const ObjectInstanceID & TID, const HeroTypeID & NHID)
|
||||||
: hid(HID)
|
: hid(HID)
|
||||||
, tid(TID)
|
, tid(TID)
|
||||||
|
, nhid(NHID)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
HeroTypeID hid; //available hero serial
|
HeroTypeID hid; //available hero serial
|
||||||
|
HeroTypeID nhid; //next hero
|
||||||
ObjectInstanceID tid; //town (tavern) id
|
ObjectInstanceID tid; //town (tavern) id
|
||||||
PlayerColor player;
|
PlayerColor player;
|
||||||
|
|
||||||
@ -531,6 +533,7 @@ struct DLL_LINKAGE HireHero : public CPackForServer
|
|||||||
{
|
{
|
||||||
h & static_cast<CPackForServer &>(*this);
|
h & static_cast<CPackForServer &>(*this);
|
||||||
h & hid;
|
h & hid;
|
||||||
|
h & nhid;
|
||||||
h & tid;
|
h & tid;
|
||||||
h & player;
|
h & player;
|
||||||
}
|
}
|
||||||
|
@ -282,7 +282,7 @@ void ApplyGhNetPackVisitor::visitHireHero(HireHero & pack)
|
|||||||
{
|
{
|
||||||
gh.throwIfWrongPlayer(&pack);
|
gh.throwIfWrongPlayer(&pack);
|
||||||
|
|
||||||
result = gh.heroPool->hireHero(pack.tid, pack.hid, pack.player);
|
result = gh.heroPool->hireHero(pack.tid, pack.hid, pack.player, pack.nhid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyGhNetPackVisitor::visitBuildBoat(BuildBoat & pack)
|
void ApplyGhNetPackVisitor::visitBuildBoat(BuildBoat & pack)
|
||||||
|
@ -104,7 +104,7 @@ void HeroPoolProcessor::clearHeroFromSlot(const PlayerColor & color, TavernHeroS
|
|||||||
gameHandler->sendAndApply(&sah);
|
gameHandler->sendAndApply(&sah);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HeroPoolProcessor::selectNewHeroForSlot(const PlayerColor & color, TavernHeroSlot slot, bool needNativeHero, bool giveArmy)
|
void HeroPoolProcessor::selectNewHeroForSlot(const PlayerColor & color, TavernHeroSlot slot, bool needNativeHero, bool giveArmy, const HeroTypeID & nextHero)
|
||||||
{
|
{
|
||||||
SetAvailableHero sah;
|
SetAvailableHero sah;
|
||||||
sah.player = color;
|
sah.player = color;
|
||||||
@ -113,6 +113,10 @@ void HeroPoolProcessor::selectNewHeroForSlot(const PlayerColor & color, TavernHe
|
|||||||
|
|
||||||
CGHeroInstance *newHero = pickHeroFor(needNativeHero, color);
|
CGHeroInstance *newHero = pickHeroFor(needNativeHero, color);
|
||||||
|
|
||||||
|
const auto & heroesPool = gameHandler->gameState()->heroesPool;
|
||||||
|
if(gameHandler->getStartInfo()->extraOptionsInfo.unlimitedReplay && heroesPool->unusedHeroesFromPool().count(nextHero) && heroesPool->isHeroAvailableFor(nextHero, color))
|
||||||
|
newHero = heroesPool->unusedHeroesFromPool()[nextHero];
|
||||||
|
|
||||||
if (newHero)
|
if (newHero)
|
||||||
{
|
{
|
||||||
sah.hid = newHero->getHeroType();
|
sah.hid = newHero->getHeroType();
|
||||||
@ -145,7 +149,7 @@ void HeroPoolProcessor::onNewWeek(const PlayerColor & color)
|
|||||||
selectNewHeroForSlot(color, TavernHeroSlot::RANDOM, false, true);
|
selectNewHeroForSlot(color, TavernHeroSlot::RANDOM, false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HeroPoolProcessor::hireHero(const ObjectInstanceID & objectID, const HeroTypeID & heroToRecruit, const PlayerColor & player)
|
bool HeroPoolProcessor::hireHero(const ObjectInstanceID & objectID, const HeroTypeID & heroToRecruit, const PlayerColor & player, const HeroTypeID & nextHero)
|
||||||
{
|
{
|
||||||
const PlayerState * playerState = gameHandler->getPlayerState(player);
|
const PlayerState * playerState = gameHandler->getPlayerState(player);
|
||||||
const CGObjectInstance * mapObject = gameHandler->getObj(objectID);
|
const CGObjectInstance * mapObject = gameHandler->getObj(objectID);
|
||||||
@ -226,9 +230,9 @@ bool HeroPoolProcessor::hireHero(const ObjectInstanceID & objectID, const HeroTy
|
|||||||
gameHandler->sendAndApply(&hr);
|
gameHandler->sendAndApply(&hr);
|
||||||
|
|
||||||
if(recruitableHeroes[0] == recruitedHero)
|
if(recruitableHeroes[0] == recruitedHero)
|
||||||
selectNewHeroForSlot(player, TavernHeroSlot::NATIVE, false, false);
|
selectNewHeroForSlot(player, TavernHeroSlot::NATIVE, false, false, nextHero);
|
||||||
else
|
else
|
||||||
selectNewHeroForSlot(player, TavernHeroSlot::RANDOM, false, false);
|
selectNewHeroForSlot(player, TavernHeroSlot::RANDOM, false, false, nextHero);
|
||||||
|
|
||||||
gameHandler->giveResource(player, EGameResID::GOLD, -GameConstants::HERO_GOLD_COST);
|
gameHandler->giveResource(player, EGameResID::GOLD, -GameConstants::HERO_GOLD_COST);
|
||||||
|
|
||||||
|
@ -9,6 +9,8 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "../../lib/constants/EntityIdentifiers.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
|
|
||||||
enum class TavernHeroSlot : int8_t;
|
enum class TavernHeroSlot : int8_t;
|
||||||
@ -33,7 +35,7 @@ class HeroPoolProcessor : boost::noncopyable
|
|||||||
std::map<HeroTypeID, std::unique_ptr<CRandomGenerator>> heroSeed;
|
std::map<HeroTypeID, std::unique_ptr<CRandomGenerator>> heroSeed;
|
||||||
|
|
||||||
void clearHeroFromSlot(const PlayerColor & color, TavernHeroSlot slot);
|
void clearHeroFromSlot(const PlayerColor & color, TavernHeroSlot slot);
|
||||||
void selectNewHeroForSlot(const PlayerColor & color, TavernHeroSlot slot, bool needNativeHero, bool giveStartingArmy);
|
void selectNewHeroForSlot(const PlayerColor & color, TavernHeroSlot slot, bool needNativeHero, bool giveStartingArmy, const HeroTypeID & nextHero = HeroTypeID::NONE);
|
||||||
|
|
||||||
std::vector<const CHeroClass *> findAvailableClassesFor(const PlayerColor & player) const;
|
std::vector<const CHeroClass *> findAvailableClassesFor(const PlayerColor & player) const;
|
||||||
std::vector<CGHeroInstance *> findAvailableHeroesFor(const PlayerColor & player, const CHeroClass * heroClass) const;
|
std::vector<CGHeroInstance *> findAvailableHeroesFor(const PlayerColor & player, const CHeroClass * heroClass) const;
|
||||||
@ -60,7 +62,7 @@ public:
|
|||||||
CRandomGenerator & getHeroSkillsRandomGenerator(const HeroTypeID & hero);
|
CRandomGenerator & getHeroSkillsRandomGenerator(const HeroTypeID & hero);
|
||||||
|
|
||||||
/// Incoming net pack handling
|
/// Incoming net pack handling
|
||||||
bool hireHero(const ObjectInstanceID & objectID, const HeroTypeID & hid, const PlayerColor & player);
|
bool hireHero(const ObjectInstanceID & objectID, const HeroTypeID & hid, const PlayerColor & player, const HeroTypeID & nextHero);
|
||||||
|
|
||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user