mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
1. Support for Pandora Box
2. Improved functions handling experience. Now it works with values over 65K, but still didn't with event giving 99M exp I have no idea what it has to do with AI though
This commit is contained in:
parent
4fc25c7b98
commit
dd91e7e406
@ -181,7 +181,7 @@ public:
|
||||
virtual void heroKilled(const CGHeroInstance *);
|
||||
virtual void heroCreated(const CGHeroInstance *);
|
||||
virtual void heroMoved(const TryMoveHero &);
|
||||
virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) {};
|
||||
virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val) {};
|
||||
virtual void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID){};
|
||||
virtual void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, const int soundID, bool selection, bool cancel); //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID.
|
||||
virtual void tileRevealed(int3 pos);
|
||||
|
@ -78,7 +78,7 @@ public:
|
||||
virtual void heroInGarrisonChange(const CGTownInstance *town){};
|
||||
//virtual void heroKilled(const CGHeroInstance*){};
|
||||
virtual void heroMoved(const TryMoveHero & details){};
|
||||
virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val){};
|
||||
virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val){};
|
||||
virtual void heroManaPointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after spell casts
|
||||
virtual void heroMovePointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after movement
|
||||
virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){};
|
||||
|
@ -804,7 +804,7 @@ int3 CPlayerInterface::repairScreenPos(int3 pos)
|
||||
pos.y = CGI->mh->map->height - this->adventureInt->terrain.tilesh + CGI->mh->frameH;
|
||||
return pos;
|
||||
}
|
||||
void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)
|
||||
void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val)
|
||||
{
|
||||
if(which >= PRIMARY_SKILLS) //no need to redraw infowin if this is experience (exp is treated as prim skill with id==4)
|
||||
return;
|
||||
|
@ -139,7 +139,7 @@ public:
|
||||
void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
|
||||
void heroInGarrisonChange(const CGTownInstance *town);
|
||||
void heroMoved(const TryMoveHero & details);
|
||||
void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
|
||||
void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val);
|
||||
void heroManaPointsChanged(const CGHeroInstance * hero);
|
||||
void heroMovePointsChanged(const CGHeroInstance * hero);
|
||||
void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);
|
||||
|
@ -89,7 +89,7 @@ public:
|
||||
void setOwner(int objid, ui8 owner){};
|
||||
void setHoverName(int objid, MetaString * name){};
|
||||
void setObjProperty(int objid, int prop, int val){};
|
||||
void changePrimSkill(int ID, int which, int val, bool abs=false){};
|
||||
void changePrimSkill(int ID, int which, si64 val, bool abs=false){};
|
||||
void changeSecSkill(int ID, int which, int val, bool abs=false){};
|
||||
void showInfoDialog(InfoWindow *iw){};
|
||||
void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback){};
|
||||
|
@ -378,27 +378,30 @@ void CHeroHandler::initHeroClasses()
|
||||
loadNativeTerrains();
|
||||
}
|
||||
|
||||
unsigned int CHeroHandler::level(ui64 experience)
|
||||
unsigned int CHeroHandler::level (ui64 experience)
|
||||
{
|
||||
int i;
|
||||
if(experience <= expPerLevel.back())
|
||||
if (experience <= expPerLevel.back())
|
||||
{
|
||||
for(i = expPerLevel.size()-1; experience < expPerLevel[i]; i--);
|
||||
return i + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for(i = expPerLevel.size(); experience > reqExp(i); i++);
|
||||
return i - 1;
|
||||
//for(i = expPerLevel.size(); experience > reqExp(i); i++);
|
||||
i = expPerLevel.size();
|
||||
while (experience > reqExp (i))
|
||||
i++;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
ui64 CHeroHandler::reqExp(unsigned int level)
|
||||
ui64 CHeroHandler::reqExp (unsigned int level)
|
||||
{
|
||||
if(!level)
|
||||
return 0;
|
||||
|
||||
if(level<=expPerLevel.size())
|
||||
if(level <= expPerLevel.size())
|
||||
{
|
||||
return expPerLevel[level - 1];
|
||||
}
|
||||
@ -412,7 +415,13 @@ ui64 CHeroHandler::reqExp(unsigned int level)
|
||||
// exp*=1.2;
|
||||
//}
|
||||
//return exp;
|
||||
return (ui64)(reqExp(level - 1) + (reqExp(level - 1) - reqExp(level - 2)) * 1.2); //inefficient but follows exactly H3 values
|
||||
while (level > expPerLevel.size())
|
||||
{
|
||||
int i = expPerLevel.size() - 1;
|
||||
expPerLevel.push_back ((ui64)(expPerLevel[i] + (expPerLevel[i] - expPerLevel[i-1]) * 1.2));
|
||||
}
|
||||
return expPerLevel[level-1];
|
||||
//return (ui64)(reqExp(level - 1) + (reqExp(level - 1) - reqExp(level - 2)) * 1.2); //inefficient but follows exactly H3 values
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1373,7 +1373,7 @@ void CGVisitableOPH::initObj()
|
||||
ttype = -1;
|
||||
}
|
||||
|
||||
void CGVisitableOPH::treeSelected( int heroID, int resType, int resVal, int expVal, ui32 result ) const
|
||||
void CGVisitableOPH::treeSelected( int heroID, int resType, int resVal, ui64 expVal, ui32 result ) const
|
||||
{
|
||||
if(result) //player agreed to give res for exp
|
||||
{
|
||||
@ -2781,7 +2781,7 @@ void CGEvent::onHeroVisit( const CGHeroInstance * h ) const
|
||||
activated(h);
|
||||
}
|
||||
|
||||
void CGEvent::endBattle( const CGHeroInstance *h, BattleResult *result ) const
|
||||
void CGPandoraBox::endBattle( const CGHeroInstance *h, BattleResult *result ) const
|
||||
{
|
||||
if(result->winner)
|
||||
return;
|
||||
@ -2808,7 +2808,49 @@ void CGEvent::activated( const CGHeroInstance * h ) const
|
||||
}
|
||||
}
|
||||
|
||||
void CGEvent::giveContents( const CGHeroInstance *h, bool afterBattle ) const
|
||||
void CGPandoraBox::initObj()
|
||||
{
|
||||
blockVisit = true;
|
||||
}
|
||||
void CGPandoraBox::onHeroVisit(const CGHeroInstance * h) const
|
||||
{
|
||||
BlockingDialog bd (true, false);
|
||||
bd.player = h->getOwner();
|
||||
bd.soundID = soundBase::QUEST;
|
||||
bd.text.addTxt (MetaString::ADVOB_TXT, 14);
|
||||
cb->showBlockingDialog (&bd, boost::bind (&CGPandoraBox::open, this, h, _1));
|
||||
}
|
||||
void CGPandoraBox::open( const CGHeroInstance * h, ui32 accept ) const
|
||||
{
|
||||
if (accept)
|
||||
{
|
||||
if (army)
|
||||
{
|
||||
InfoWindow iw;
|
||||
iw.player = h->tempOwner;
|
||||
iw.text.addTxt(MetaString::ADVOB_TXT, 16);
|
||||
cb->showInfoDialog(&iw);
|
||||
cb->startBattleI(h, this, boost::bind(&CGPandoraBox::endBattle, this, h,_1));
|
||||
}
|
||||
else if (message.size() == resources.size() ==
|
||||
primskills.size() == abilities.size() ==
|
||||
abilityLevels.size() == artifacts.size() ==
|
||||
spells.size() == creatures ==
|
||||
gainedExp == manaDiff == moraleDiff == luckDiff == 0) //yeaha!
|
||||
{
|
||||
InfoWindow iw;
|
||||
iw.player = h->tempOwner;
|
||||
iw.text.addTxt(MetaString::ADVOB_TXT, 15);
|
||||
cb->showInfoDialog(&iw);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
giveContents (h, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
void CGPandoraBox::giveContents( const CGHeroInstance *h, bool afterBattle ) const
|
||||
{
|
||||
InfoWindow iw;
|
||||
iw.player = h->getOwner();
|
||||
@ -3011,12 +3053,7 @@ void CGEvent::giveContents( const CGHeroInstance *h, bool afterBattle ) const
|
||||
SetGarrisons sg;
|
||||
sg.garrs[id] = creatures;
|
||||
cb->sendAndApply(&sg);
|
||||
|
||||
if(removeAfterVisit)
|
||||
cb->showGarrisonDialog(id,h->id,boost::bind(&IGameCallback::removeObject,cb,id));
|
||||
else
|
||||
cb->showGarrisonDialog(id,h->id,0);
|
||||
return;
|
||||
cb->showGarrisonDialog(id,h->id,boost::bind(&IGameCallback::removeObject,cb,id));
|
||||
}
|
||||
|
||||
if(!afterBattle && message.size())
|
||||
@ -3024,12 +3061,10 @@ void CGEvent::giveContents( const CGHeroInstance *h, bool afterBattle ) const
|
||||
iw.text << message;
|
||||
cb->showInfoDialog(&iw);
|
||||
}
|
||||
|
||||
if(removeAfterVisit)
|
||||
cb->removeObject(id);
|
||||
cb->removeObject(id);
|
||||
}
|
||||
|
||||
void CGEvent::getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const
|
||||
void CGPandoraBox::getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const
|
||||
{
|
||||
if(afterBattle || !message.size())
|
||||
{
|
||||
@ -3043,7 +3078,7 @@ void CGEvent::getText( InfoWindow &iw, bool &afterBattle, int text, const CGHero
|
||||
}
|
||||
}
|
||||
|
||||
void CGEvent::getText( InfoWindow &iw, bool &afterBattle, int val, int negative, int positive, const CGHeroInstance * h ) const
|
||||
void CGPandoraBox::getText( InfoWindow &iw, bool &afterBattle, int val, int negative, int positive, const CGHeroInstance * h ) const
|
||||
{
|
||||
iw.components.clear();
|
||||
iw.text.clear();
|
||||
|
@ -413,7 +413,7 @@ public:
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
void onNAHeroVisit(int heroID, bool alreadyVisited) const;
|
||||
void initObj();
|
||||
void treeSelected(int heroID, int resType, int resVal, int expVal, ui32 result) const; //handle player's anwer to the Tree of Knowledge dialog
|
||||
void treeSelected(int heroID, int resType, int resVal, ui64 expVal, ui32 result) const; //handle player's anwer to the Tree of Knowledge dialog
|
||||
void schoolSelected(int heroID, ui32 which) const;
|
||||
void arenaSelected(int heroID, int primSkill) const;
|
||||
|
||||
@ -424,10 +424,13 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGEvent : public CArmedInstance //event objects
|
||||
class DLL_EXPORT CGPandoraBox : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
std::string message;
|
||||
ui8 removeAfterVisit; //true if event is removed after occurring
|
||||
|
||||
//gained things:
|
||||
ui32 gainedExp;
|
||||
si32 manaDiff; //amount of gained / lost mana
|
||||
si32 moraleDiff; //morale modifier
|
||||
@ -439,26 +442,42 @@ public:
|
||||
std::vector<si32> artifacts; //gained artifacts
|
||||
std::vector<si32> spells; //gained spells
|
||||
CCreatureSet creatures; //gained creatures
|
||||
|
||||
void CGPandoraBox::initObj();
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
void open (const CGHeroInstance * h, ui32 accept) const;
|
||||
void endBattle(const CGHeroInstance *h, BattleResult *result) const;
|
||||
void giveContents(const CGHeroInstance *h, bool afterBattle) const;
|
||||
void getText( InfoWindow &iw, bool &afterBattle, int val, int negative, int positive, const CGHeroInstance * h ) const;
|
||||
void getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & static_cast<CArmedInstance&>(*this);
|
||||
h & message & gainedExp & manaDiff & moraleDiff & luckDiff & resources & primskills
|
||||
& abilities & abilityLevels & artifacts & spells & creatures & army;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGEvent : public CGPandoraBox //event objects
|
||||
{
|
||||
public:
|
||||
|
||||
ui8 availableFor; //players whom this event is available for
|
||||
ui8 computerActivate; //true if computre player can activate this event
|
||||
ui8 humanActivate; //true if human player can activate this event
|
||||
ui8 removeAfterVisit; //true if event is removed after occurring
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & static_cast<CArmedInstance&>(*this);
|
||||
h & message & gainedExp & manaDiff & moraleDiff & luckDiff & resources & primskills
|
||||
& abilities & abilityLevels & artifacts & spells & creatures & availableFor
|
||||
& computerActivate & humanActivate;
|
||||
& computerActivate & humanActivate & army;
|
||||
}
|
||||
|
||||
void activated(const CGHeroInstance * h) const;
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
void endBattle(const CGHeroInstance *h, BattleResult *result) const;
|
||||
void giveContents(const CGHeroInstance *h, bool afterBattle) const;
|
||||
void activated(const CGHeroInstance * h) const;
|
||||
|
||||
void getText( InfoWindow &iw, bool &afterBattle, int val, int negative, int positive, const CGHeroInstance * h ) const;
|
||||
void getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGCreature : public CArmedInstance //creatures on map
|
||||
@ -634,32 +653,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGPandoraBox : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
std::string message;
|
||||
|
||||
//gained things:
|
||||
ui32 gainedExp;
|
||||
si32 manaDiff; //amount of gained / lost mana
|
||||
si32 moraleDiff; //morale modifier
|
||||
si32 luckDiff; //luck modifier
|
||||
std::vector<si32> resources;//gained / lost resources
|
||||
std::vector<si32> primskills;//gained / lost resources
|
||||
std::vector<si32> abilities; //gained abilities
|
||||
std::vector<si32> abilityLevels; //levels of gained abilities
|
||||
std::vector<si32> artifacts; //gained artifacts
|
||||
std::vector<si32> spells; //gained spells
|
||||
CCreatureSet creatures; //gained creatures
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & static_cast<CArmedInstance&>(*this);
|
||||
h & message & gainedExp & manaDiff & moraleDiff & luckDiff & resources & primskills
|
||||
& abilities & abilityLevels & artifacts & spells & creatures;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGQuestGuard : public CGObjectInstance, public CQuest
|
||||
{
|
||||
public:
|
||||
|
@ -65,7 +65,7 @@ public:
|
||||
virtual void setOwner(int objid, ui8 owner)=0;
|
||||
virtual void setHoverName(int objid, MetaString * name)=0;
|
||||
virtual void setObjProperty(int objid, int prop, int val)=0;
|
||||
virtual void changePrimSkill(int ID, int which, int val, bool abs=false)=0;
|
||||
virtual void changePrimSkill(int ID, int which, si64 val, bool abs=false)=0;
|
||||
virtual void changeSecSkill(int ID, int which, int val, bool abs=false)=0;
|
||||
virtual void showInfoDialog(InfoWindow *iw)=0;
|
||||
virtual void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback)=0;
|
||||
|
@ -237,7 +237,8 @@ struct SetPrimSkill : public CPackForClient //105
|
||||
|
||||
ui8 abs; //0 - changes by value; 1 - sets to value
|
||||
si32 id;
|
||||
ui16 which, val;
|
||||
ui16 which;
|
||||
si64 val;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
|
@ -22,6 +22,7 @@ void registerTypes1(Serializer &s)
|
||||
{
|
||||
s.template registerType<CGHeroInstance>();
|
||||
s.template registerType<CGTownInstance>();
|
||||
s.template registerType<CGPandoraBox>();
|
||||
s.template registerType<CGEvent>();
|
||||
s.template registerType<CGVisitableOPH>();
|
||||
s.template registerType<CGVisitableOPW>();
|
||||
@ -37,7 +38,6 @@ void registerTypes1(Serializer &s)
|
||||
s.template registerType<CGResource>();
|
||||
s.template registerType<CGMine>();
|
||||
s.template registerType<CGShrine>();
|
||||
s.template registerType<CGPandoraBox>();
|
||||
s.template registerType<CGQuestGuard>();
|
||||
s.template registerType<CGBonusingObject>();
|
||||
s.template registerType<CGMagicWell>();
|
||||
|
@ -211,7 +211,7 @@ void CGameHandler::changeSecSkill( int ID, int which, int val, bool abs/*=false*
|
||||
}
|
||||
}
|
||||
|
||||
void CGameHandler::changePrimSkill(int ID, int which, int val, bool abs)
|
||||
void CGameHandler::changePrimSkill(int ID, int which, si64 val, bool abs)
|
||||
{
|
||||
SetPrimSkill sps;
|
||||
sps.id = ID;
|
||||
|
@ -108,7 +108,7 @@ public:
|
||||
void setOwner(int objid, ui8 owner);
|
||||
void setHoverName(int objid, MetaString * name);
|
||||
void setObjProperty(int objid, int prop, int val);
|
||||
void changePrimSkill(int ID, int which, int val, bool abs=false);
|
||||
void changePrimSkill(int ID, int which, si64 val, bool abs=false);
|
||||
void changeSecSkill(int ID, int which, int val, bool abs=false);
|
||||
void showInfoDialog(InfoWindow *iw);
|
||||
void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback);
|
||||
|
Loading…
Reference in New Issue
Block a user