1
0
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:
DjWarmonger 2009-08-16 15:39:18 +00:00
parent 4fc25c7b98
commit dd91e7e406
13 changed files with 105 additions and 67 deletions

View File

@ -181,7 +181,7 @@ public:
virtual void heroKilled(const CGHeroInstance *); virtual void heroKilled(const CGHeroInstance *);
virtual void heroCreated(const CGHeroInstance *); virtual void heroCreated(const CGHeroInstance *);
virtual void heroMoved(const TryMoveHero &); 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 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 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); virtual void tileRevealed(int3 pos);

View File

@ -78,7 +78,7 @@ public:
virtual void heroInGarrisonChange(const CGTownInstance *town){}; virtual void heroInGarrisonChange(const CGTownInstance *town){};
//virtual void heroKilled(const CGHeroInstance*){}; //virtual void heroKilled(const CGHeroInstance*){};
virtual void heroMoved(const TryMoveHero & details){}; 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 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 heroMovePointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after movement
virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){}; virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){};

View File

@ -804,7 +804,7 @@ int3 CPlayerInterface::repairScreenPos(int3 pos)
pos.y = CGI->mh->map->height - this->adventureInt->terrain.tilesh + CGI->mh->frameH; pos.y = CGI->mh->map->height - this->adventureInt->terrain.tilesh + CGI->mh->frameH;
return pos; 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) if(which >= PRIMARY_SKILLS) //no need to redraw infowin if this is experience (exp is treated as prim skill with id==4)
return; return;

View File

@ -139,7 +139,7 @@ public:
void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback); void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback);
void heroInGarrisonChange(const CGTownInstance *town); void heroInGarrisonChange(const CGTownInstance *town);
void heroMoved(const TryMoveHero & details); 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 heroManaPointsChanged(const CGHeroInstance * hero);
void heroMovePointsChanged(const CGHeroInstance * hero); void heroMovePointsChanged(const CGHeroInstance * hero);
void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town); void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town);

View File

@ -89,7 +89,7 @@ public:
void setOwner(int objid, ui8 owner){}; void setOwner(int objid, ui8 owner){};
void setHoverName(int objid, MetaString * name){}; void setHoverName(int objid, MetaString * name){};
void setObjProperty(int objid, int prop, int val){}; 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 changeSecSkill(int ID, int which, int val, bool abs=false){};
void showInfoDialog(InfoWindow *iw){}; void showInfoDialog(InfoWindow *iw){};
void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback){}; void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback){};

View File

@ -378,27 +378,30 @@ void CHeroHandler::initHeroClasses()
loadNativeTerrains(); loadNativeTerrains();
} }
unsigned int CHeroHandler::level(ui64 experience) unsigned int CHeroHandler::level (ui64 experience)
{ {
int i; int i;
if(experience <= expPerLevel.back()) if (experience <= expPerLevel.back())
{ {
for(i = expPerLevel.size()-1; experience < expPerLevel[i]; i--); for(i = expPerLevel.size()-1; experience < expPerLevel[i]; i--);
return i + 1; return i + 1;
} }
else else
{ {
for(i = expPerLevel.size(); experience > reqExp(i); i++); //for(i = expPerLevel.size(); experience > reqExp(i); i++);
return i - 1; i = expPerLevel.size();
while (experience > reqExp (i))
i++;
return i;
} }
} }
ui64 CHeroHandler::reqExp(unsigned int level) ui64 CHeroHandler::reqExp (unsigned int level)
{ {
if(!level) if(!level)
return 0; return 0;
if(level<=expPerLevel.size()) if(level <= expPerLevel.size())
{ {
return expPerLevel[level - 1]; return expPerLevel[level - 1];
} }
@ -412,7 +415,13 @@ ui64 CHeroHandler::reqExp(unsigned int level)
// exp*=1.2; // exp*=1.2;
//} //}
//return exp; //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
} }
} }

View File

@ -1373,7 +1373,7 @@ void CGVisitableOPH::initObj()
ttype = -1; 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 if(result) //player agreed to give res for exp
{ {
@ -2781,7 +2781,7 @@ void CGEvent::onHeroVisit( const CGHeroInstance * h ) const
activated(h); activated(h);
} }
void CGEvent::endBattle( const CGHeroInstance *h, BattleResult *result ) const void CGPandoraBox::endBattle( const CGHeroInstance *h, BattleResult *result ) const
{ {
if(result->winner) if(result->winner)
return; 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; InfoWindow iw;
iw.player = h->getOwner(); iw.player = h->getOwner();
@ -3011,12 +3053,7 @@ void CGEvent::giveContents( const CGHeroInstance *h, bool afterBattle ) const
SetGarrisons sg; SetGarrisons sg;
sg.garrs[id] = creatures; sg.garrs[id] = creatures;
cb->sendAndApply(&sg); cb->sendAndApply(&sg);
cb->showGarrisonDialog(id,h->id,boost::bind(&IGameCallback::removeObject,cb,id));
if(removeAfterVisit)
cb->showGarrisonDialog(id,h->id,boost::bind(&IGameCallback::removeObject,cb,id));
else
cb->showGarrisonDialog(id,h->id,0);
return;
} }
if(!afterBattle && message.size()) if(!afterBattle && message.size())
@ -3024,12 +3061,10 @@ void CGEvent::giveContents( const CGHeroInstance *h, bool afterBattle ) const
iw.text << message; iw.text << message;
cb->showInfoDialog(&iw); cb->showInfoDialog(&iw);
} }
cb->removeObject(id);
if(removeAfterVisit)
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()) 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.components.clear();
iw.text.clear(); iw.text.clear();

View File

@ -413,7 +413,7 @@ public:
void onHeroVisit(const CGHeroInstance * h) const; void onHeroVisit(const CGHeroInstance * h) const;
void onNAHeroVisit(int heroID, bool alreadyVisited) const; void onNAHeroVisit(int heroID, bool alreadyVisited) const;
void initObj(); 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 schoolSelected(int heroID, ui32 which) const;
void arenaSelected(int heroID, int primSkill) 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: public:
std::string message; std::string message;
ui8 removeAfterVisit; //true if event is removed after occurring
//gained things:
ui32 gainedExp; ui32 gainedExp;
si32 manaDiff; //amount of gained / lost mana si32 manaDiff; //amount of gained / lost mana
si32 moraleDiff; //morale modifier si32 moraleDiff; //morale modifier
@ -439,26 +442,42 @@ public:
std::vector<si32> artifacts; //gained artifacts std::vector<si32> artifacts; //gained artifacts
std::vector<si32> spells; //gained spells std::vector<si32> spells; //gained spells
CCreatureSet creatures; //gained creatures 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 availableFor; //players whom this event is available for
ui8 computerActivate; //true if computre player can activate this event ui8 computerActivate; //true if computre player can activate this event
ui8 humanActivate; //true if human 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) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & static_cast<CArmedInstance&>(*this); h & static_cast<CArmedInstance&>(*this);
h & message & gainedExp & manaDiff & moraleDiff & luckDiff & resources & primskills h & message & gainedExp & manaDiff & moraleDiff & luckDiff & resources & primskills
& abilities & abilityLevels & artifacts & spells & creatures & availableFor & abilities & abilityLevels & artifacts & spells & creatures & availableFor
& computerActivate & humanActivate; & computerActivate & humanActivate & army;
} }
void activated(const CGHeroInstance * h) const;
void onHeroVisit(const CGHeroInstance * h) const; void onHeroVisit(const CGHeroInstance * h) const;
void endBattle(const CGHeroInstance *h, BattleResult *result) const; void activated(const CGHeroInstance * h) 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;
}; };
class DLL_EXPORT CGCreature : public CArmedInstance //creatures on map 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 class DLL_EXPORT CGQuestGuard : public CGObjectInstance, public CQuest
{ {
public: public:

View File

@ -65,7 +65,7 @@ public:
virtual void setOwner(int objid, ui8 owner)=0; virtual void setOwner(int objid, ui8 owner)=0;
virtual void setHoverName(int objid, MetaString * name)=0; virtual void setHoverName(int objid, MetaString * name)=0;
virtual void setObjProperty(int objid, int prop, int val)=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 changeSecSkill(int ID, int which, int val, bool abs=false)=0;
virtual void showInfoDialog(InfoWindow *iw)=0; virtual void showInfoDialog(InfoWindow *iw)=0;
virtual void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback)=0; virtual void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback)=0;

View File

@ -237,7 +237,8 @@ struct SetPrimSkill : public CPackForClient //105
ui8 abs; //0 - changes by value; 1 - sets to value ui8 abs; //0 - changes by value; 1 - sets to value
si32 id; si32 id;
ui16 which, val; ui16 which;
si64 val;
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {

View File

@ -22,6 +22,7 @@ void registerTypes1(Serializer &s)
{ {
s.template registerType<CGHeroInstance>(); s.template registerType<CGHeroInstance>();
s.template registerType<CGTownInstance>(); s.template registerType<CGTownInstance>();
s.template registerType<CGPandoraBox>();
s.template registerType<CGEvent>(); s.template registerType<CGEvent>();
s.template registerType<CGVisitableOPH>(); s.template registerType<CGVisitableOPH>();
s.template registerType<CGVisitableOPW>(); s.template registerType<CGVisitableOPW>();
@ -37,7 +38,6 @@ void registerTypes1(Serializer &s)
s.template registerType<CGResource>(); s.template registerType<CGResource>();
s.template registerType<CGMine>(); s.template registerType<CGMine>();
s.template registerType<CGShrine>(); s.template registerType<CGShrine>();
s.template registerType<CGPandoraBox>();
s.template registerType<CGQuestGuard>(); s.template registerType<CGQuestGuard>();
s.template registerType<CGBonusingObject>(); s.template registerType<CGBonusingObject>();
s.template registerType<CGMagicWell>(); s.template registerType<CGMagicWell>();

View File

@ -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; SetPrimSkill sps;
sps.id = ID; sps.id = ID;

View File

@ -108,7 +108,7 @@ public:
void setOwner(int objid, ui8 owner); void setOwner(int objid, ui8 owner);
void setHoverName(int objid, MetaString * name); void setHoverName(int objid, MetaString * name);
void setObjProperty(int objid, int prop, int val); 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 changeSecSkill(int ID, int which, int val, bool abs=false);
void showInfoDialog(InfoWindow *iw); void showInfoDialog(InfoWindow *iw);
void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback); void showBlockingDialog(BlockingDialog *iw, const CFunctionList<void(ui32)> &callback);