1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-02-09 13:14:02 +02:00

* fixed 1085

* fixed starting hero is granted in normal scenarios
* introduced TArtifactInstanceID
This commit is contained in:
mateuszb 2012-09-25 14:40:39 +00:00
parent 8e78c86fe9
commit f3f4a7633d
8 changed files with 51 additions and 38 deletions

View File

@ -448,7 +448,7 @@ void CArtHandler::sortArts()
// } // }
//} //}
} }
void CArtHandler::erasePickedArt (TArtifactID id) void CArtHandler::erasePickedArt( TArtifactInstanceID id )
{ {
std::vector<CArtifact*>* ptr; std::vector<CArtifact*>* ptr;
CArtifact *art = artifacts[id]; CArtifact *art = artifacts[id];
@ -566,7 +566,7 @@ void CArtHandler::giveArtBonus(TArtifactID aid, Bonus *bonus)
artifacts[aid]->addNewBonus(bonus); artifacts[aid]->addNewBonus(bonus);
} }
void CArtHandler::makeItCreatureArt (TArtifactID aid, bool onlyCreature /*=true*/) void CArtHandler::makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature /*=true*/)
{ {
CArtifact *a = artifacts[aid]; CArtifact *a = artifacts[aid];
if (onlyCreature) if (onlyCreature)
@ -577,7 +577,7 @@ void CArtHandler::makeItCreatureArt (TArtifactID aid, bool onlyCreature /*=true*
a->possibleSlots[ArtBearer::CREATURE].push_back(ArtifactPosition::CREATURE_SLOT); a->possibleSlots[ArtBearer::CREATURE].push_back(ArtifactPosition::CREATURE_SLOT);
} }
void CArtHandler::makeItCommanderArt (TArtifactID aid, bool onlyCommander /*=true*/) void CArtHandler::makeItCommanderArt( TArtifactInstanceID aid, bool onlyCommander /*= true*/ )
{ {
CArtifact *a = artifacts[aid]; CArtifact *a = artifacts[aid];
if (onlyCommander) if (onlyCommander)
@ -1456,7 +1456,7 @@ si32 CArtifactSet::getArtPos(const CArtifactInstance *art) const
return -1; return -1;
} }
const CArtifactInstance * CArtifactSet::getArtByInstanceId( TArtifactID artInstId ) const const CArtifactInstance * CArtifactSet::getArtByInstanceId( TArtifactInstanceID artInstId ) const
{ {
for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++) for(std::map<ui16, ArtSlotInfo>::const_iterator i = artifactsWorn.begin(); i != artifactsWorn.end(); i++)
if(i->second.artifact->id == artInstId) if(i->second.artifact->id == artInstId)

View File

@ -34,11 +34,20 @@ namespace ArtifactPosition
}; };
} }
namespace ArtifactPos namespace ArtifactID
{ {
enum ArtifactPos enum ArtifactID
{ {
SPELLBOOK = 17 SPELLBOOK = 0,
SPELL_SCROLL = 1,
GRAIL = 2,
CATAPULT = 3,
BALLISTA = 4,
AMMO_CART = 5,
FIRST_AID_TENT = 6,
CENTAUR_AXE = 7,
BLACKSHARD_OF_THE_DEAD_KNIGHT = 8,
CORNUCOPIA = 140
}; };
} }
@ -110,7 +119,7 @@ public:
CArtifactInstance(); CArtifactInstance();
ConstTransitivePtr<CArtifact> artType; ConstTransitivePtr<CArtifact> artType;
TArtifactID id; //id of the instance TArtifactInstanceID id;
//CArtifactInstance(int aid); //CArtifactInstance(int aid);
@ -208,14 +217,14 @@ public:
ui16 getArtSync (ui32 rand, int flags); ui16 getArtSync (ui32 rand, int flags);
void getAllowedArts(std::vector<ConstTransitivePtr<CArtifact> > &out, std::vector<CArtifact*> *arts, int flag); void getAllowedArts(std::vector<ConstTransitivePtr<CArtifact> > &out, std::vector<CArtifact*> *arts, int flag);
void getAllowed(std::vector<ConstTransitivePtr<CArtifact> > &out, int flags); void getAllowed(std::vector<ConstTransitivePtr<CArtifact> > &out, int flags);
void erasePickedArt (TArtifactID id); void erasePickedArt (TArtifactInstanceID id);
bool isBigArtifact (TArtifactID artID) const {return bigArtifacts.find(artID) != bigArtifacts.end();} bool isBigArtifact (TArtifactID artID) const {return bigArtifacts.find(artID) != bigArtifacts.end();}
// void equipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art) const; // void equipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID, const CArtifact* art) const;
// void unequipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID) const; // void unequipArtifact (std::map<ui16, const CArtifact*> &artifWorn, ui16 slotID) const;
void initAllowedArtifactsList(const std::vector<ui8> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed void initAllowedArtifactsList(const std::vector<ui8> &allowed); //allowed[art_id] -> 0 if not allowed, 1 if allowed
static int convertMachineID(int id, bool creToArt); static int convertMachineID(int id, bool creToArt);
void makeItCreatureArt (TArtifactID aid, bool onlyCreature = true); void makeItCreatureArt (TArtifactInstanceID aid, bool onlyCreature = true);
void makeItCommanderArt (TArtifactID aid, bool onlyCommander = true); void makeItCommanderArt (TArtifactInstanceID aid, bool onlyCommander = true);
CArtHandler(); CArtHandler();
~CArtHandler(); ~CArtHandler();
@ -257,7 +266,7 @@ public:
CArtifactInstance* getArt(ui16 pos, bool excludeLocked = true); //NULL - no artifact CArtifactInstance* getArt(ui16 pos, bool excludeLocked = true); //NULL - no artifact
si32 getArtPos(int aid, bool onlyWorn = true) const; //looks for equipped artifact with given ID and returns its slot ID or -1 if none(if more than one such artifact lower ID is returned) si32 getArtPos(int aid, bool onlyWorn = true) const; //looks for equipped artifact with given ID and returns its slot ID or -1 if none(if more than one such artifact lower ID is returned)
si32 getArtPos(const CArtifactInstance *art) const; si32 getArtPos(const CArtifactInstance *art) const;
const CArtifactInstance *getArtByInstanceId(TArtifactID artInstId) const; const CArtifactInstance *getArtByInstanceId(TArtifactInstanceID artInstId) const;
bool hasArt(ui32 aid, bool onlyWorn = false) const; //checks if hero possess artifact of given id (either in backack or worn) bool hasArt(ui32 aid, bool onlyWorn = false) const; //checks if hero possess artifact of given id (either in backack or worn)
bool isPositionFree(ui16 pos, bool onlyLockCheck = false) const; bool isPositionFree(ui16 pos, bool onlyLockCheck = false) const;
si32 getArtTypeId(ui16 pos) const; si32 getArtTypeId(ui16 pos) const;

View File

@ -980,34 +980,37 @@ void CGameState::init(StartInfo * si)
/*********give starting hero****************************************/ /*********give starting hero****************************************/
tlog4 << "\tGiving starting hero"; tlog4 << "\tGiving starting hero";
{ {
bool campaignGiveHero = false;
if(scenarioOps->campState) if(scenarioOps->campState)
{ {
auto bonus = scenarioOps->campState->getBonusForCurrentMap(); auto bonus = scenarioOps->campState->getBonusForCurrentMap();
if(bonus.is_initialized()) if(bonus.is_initialized())
{ {
for(auto it = scenarioOps->playerInfos.begin(); it != scenarioOps->playerInfos.end(); ++it) campaignGiveHero = scenarioOps->mode == StartInfo::CAMPAIGN &&
{ bonus.get().type == CScenarioTravel::STravelBonus::HERO;
const PlayerInfo &p = map->players[it->first]; }
bool campaignGiveHero = it->second.human && scenarioOps->mode == StartInfo::CAMPAIGN && }
bonus.get().type == CScenarioTravel::STravelBonus::HERO;
bool generateHero = (p.generateHeroAtMainTown || campaignGiveHero) && p.hasMainTown;
if(generateHero && vstd::contains(scenarioOps->playerInfos, it->first))
{
int3 hpos = p.posOfMainTown;
hpos.x+=1;
int h = pickHero(it->first);
if(it->second.hero == -1)
it->second.hero = h;
CGHeroInstance * nnn = static_cast<CGHeroInstance*>(createObject(Obj::HERO,h,hpos,it->first)); for(auto it = scenarioOps->playerInfos.begin(); it != scenarioOps->playerInfos.end(); ++it)
nnn->id = map->objects.size(); {
nnn->initHero(); const PlayerInfo &p = map->players[it->first];
map->heroes.push_back(nnn); bool generateHero = (p.generateHeroAtMainTown || (it->second.human && campaignGiveHero)) && p.hasMainTown;
map->objects.push_back(nnn); if(generateHero && vstd::contains(scenarioOps->playerInfos, it->first))
map->addBlockVisTiles(nnn); {
} int3 hpos = p.posOfMainTown;
} hpos.x+=1;
int h = pickHero(it->first);
if(it->second.hero == -1)
it->second.hero = h;
CGHeroInstance * nnn = static_cast<CGHeroInstance*>(createObject(Obj::HERO,h,hpos,it->first));
nnn->id = map->objects.size();
nnn->initHero();
map->heroes.push_back(nnn);
map->objects.push_back(nnn);
map->addBlockVisTiles(nnn);
} }
} }
} }

View File

@ -5438,7 +5438,7 @@ void CGShrine::onHeroVisit( const CGHeroInstance * h ) const
iw.text.addTxt(MetaString::SPELL_NAME,spell); iw.text.addTxt(MetaString::SPELL_NAME,spell);
iw.text << "."; iw.text << ".";
if(!h->getArt(ArtifactPos::SPELLBOOK)) if(!h->getArt(ArtifactPosition::SPELLBOOK))
{ {
iw.text.addTxt(MetaString::ADVOB_TXT,131); iw.text.addTxt(MetaString::ADVOB_TXT,131);
} }

View File

@ -405,5 +405,6 @@ typedef si32 TBonusSubtype;
typedef si32 TSlot; typedef si32 TSlot;
typedef si32 TQuantity; typedef si32 TQuantity;
typedef si32 TArtifactID; typedef si32 TArtifactID;
typedef si32 TArtifactInstanceID;
typedef ui32 TCreature; //creature id typedef ui32 TCreature; //creature id
typedef si8 TPlayerColor; typedef ui8 TPlayerColor;

View File

@ -1323,7 +1323,7 @@ struct BattleResult : public CPackForClient//3003
ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)] ui8 winner; //0 - attacker, 1 - defender, [2 - draw (should be possible?)]
std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number std::map<ui32,si32> casualties[2]; //first => casualties of attackers - map crid => number
TExpType exp[2]; //exp for attacker and defender TExpType exp[2]; //exp for attacker and defender
std::set<TArtifactID> artifacts; //artifacts taken from loser to winner - currently unused std::set<TArtifactInstanceID> artifacts; //artifacts taken from loser to winner - currently unused
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {

View File

@ -2967,7 +2967,7 @@ bool CGameHandler::buyArtifact(const IMarket *m, const CGHeroInstance *h, int ri
return true; return true;
} }
bool CGameHandler::sellArtifact(const IMarket *m, const CGHeroInstance *h, TArtifactID aid, int rid) bool CGameHandler::sellArtifact( const IMarket *m, const CGHeroInstance *h, TArtifactInstanceID aid, TResource rid )
{ {
const CArtifactInstance *art = h->getArtByInstanceId(aid); const CArtifactInstance *art = h->getArtByInstanceId(aid);
if(!art) if(!art)

View File

@ -216,7 +216,7 @@ public:
bool assembleArtifacts (si32 heroID, ui16 artifactSlot, bool assemble, ui32 assembleTo); bool assembleArtifacts (si32 heroID, ui16 artifactSlot, bool assemble, ui32 assembleTo);
bool buyArtifact( ui32 hid, TArtifactID aid ); //for blacksmith and mage guild only -> buying for gold in common buildings bool buyArtifact( ui32 hid, TArtifactID aid ); //for blacksmith and mage guild only -> buying for gold in common buildings
bool buyArtifact( const IMarket *m, const CGHeroInstance *h, TArtifactID rid, TArtifactID aid); //for artifact merchant and black market -> buying for any resource in special building / advobject bool buyArtifact( const IMarket *m, const CGHeroInstance *h, TArtifactID rid, TArtifactID aid); //for artifact merchant and black market -> buying for any resource in special building / advobject
bool sellArtifact( const IMarket *m, const CGHeroInstance *h, TArtifactID aid, TArtifactID rid); //for artifact merchant selling bool sellArtifact( const IMarket *m, const CGHeroInstance *h, TArtifactInstanceID aid, TResource rid); //for artifact merchant selling
//void lootArtifacts (TArtHolder source, TArtHolder dest, std::vector<ui32> &arts); //after battle - move al arts to winer //void lootArtifacts (TArtHolder source, TArtHolder dest, std::vector<ui32> &arts); //after battle - move al arts to winer
bool buySecSkill( const IMarket *m, const CGHeroInstance *h, int skill); bool buySecSkill( const IMarket *m, const CGHeroInstance *h, int skill);
bool garrisonSwap(si32 tid); bool garrisonSwap(si32 tid);