1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-14 02:33:51 +02:00

Various fixes and improvements, mostly for r1093

This commit is contained in:
Michał W. Urbańczyk 2009-08-13 01:03:11 +00:00
parent 69217ff217
commit 2af6d85c23
11 changed files with 116 additions and 111 deletions

View File

@ -76,7 +76,7 @@ public:
virtual void heroCreated(const CGHeroInstance*){}; virtual void heroCreated(const CGHeroInstance*){};
virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback)=0; //pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback)=0; //pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id
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, int 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
@ -93,7 +93,7 @@ public:
virtual void tileRevealed(const std::set<int3> &pos){}; virtual void tileRevealed(const std::set<int3> &pos){};
virtual void newObject(const CGObjectInstance * obj){}; //eg. ship built in shipyard virtual void newObject(const CGObjectInstance * obj){}; //eg. ship built in shipyard
virtual void yourTurn(){}; virtual void yourTurn(){};
virtual void centerView (int3 pos){}; virtual void centerView (int3 pos, int focusTime){};
virtual void availableCreaturesChanged(const CGDwelling *town){}; virtual void availableCreaturesChanged(const CGDwelling *town){};
virtual void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain){};//if gain hero received bonus, else he lost it virtual void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain){};//if gain hero received bonus, else he lost it
virtual void requestRealized(PackageApplied *pa){}; virtual void requestRealized(PackageApplied *pa){};

View File

@ -1463,6 +1463,8 @@ void CAdvMapInt::activate()
} }
screenBuf = screen; screenBuf = screen;
LOCPLINT->statusbar = &statusbar; LOCPLINT->statusbar = &statusbar;
activateMouseMove();
kingOverview.activate(); kingOverview.activate();
underground.activate(); underground.activate();
questlog.activate(); questlog.activate();
@ -1483,7 +1485,9 @@ void CAdvMapInt::activate()
} }
void CAdvMapInt::deactivate() void CAdvMapInt::deactivate()
{ {
deactivateMouseMove();
scrollingDir = 0; scrollingDir = 0;
CGI->curh->changeGraphic(0,0); CGI->curh->changeGraphic(0,0);
kingOverview.deactivate(); kingOverview.deactivate();
underground.deactivate(); underground.deactivate();

View File

@ -1545,9 +1545,20 @@ void CPlayerInterface::newObject( const CGObjectInstance * obj )
} }
} }
void CPlayerInterface::centerView (int3 pos) void CPlayerInterface::centerView (int3 pos, int focusTime)
{ {
LOCPLINT->adventureInt->centerOn (pos); LOCPLINT->adventureInt->centerOn (pos);
if(focusTime)
{
bool activeAdv = (GH.topInt() == adventureInt && adventureInt->active);
if(activeAdv)
adventureInt->deactivate();
SDL_Delay(focusTime);
if(activeAdv)
adventureInt->activate();
}
} }
void CPlayerInterface::objectRemoved( const CGObjectInstance *obj ) void CPlayerInterface::objectRemoved( const CGObjectInstance *obj )

View File

@ -157,7 +157,7 @@ public:
void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain);//if gain hero received bonus, else he lost it void heroBonusChanged(const CGHeroInstance *hero, const HeroBonus &bonus, bool gain);//if gain hero received bonus, else he lost it
void requestRealized(PackageApplied *pa); void requestRealized(PackageApplied *pa);
void heroExchangeStarted(si32 hero1, si32 hero2); void heroExchangeStarted(si32 hero1, si32 hero2);
void centerView (int3 pos); void centerView (int3 pos, int focusTime);
void objectPropertyChanged(const SetObjectProperty * sop); void objectPropertyChanged(const SetObjectProperty * sop);
void objectRemoved(const CGObjectInstance *obj); void objectRemoved(const CGObjectInstance *obj);
void serialize(COSer<CSaveFile> &h, const int version); //saving void serialize(COSer<CSaveFile> &h, const int version); //saving

View File

@ -552,13 +552,7 @@ void OpenWindow::applyCl(CClient *cl)
void CenterView::applyCl(CClient *cl) void CenterView::applyCl(CClient *cl)
{ {
int3 pos = (cl->getObj(id))->pos; INTERFACE_CALL_IF_PRESENT (player, centerView, pos, focusTime);
INTERFACE_CALL_IF_PRESENT (player, centerView, pos);
}
void TakeYourTime::applyCl(CClient *cl)
{
SDL_Delay(time);
} }
void NewObject::applyCl(CClient *cl) void NewObject::applyCl(CClient *cl)

View File

@ -404,14 +404,14 @@ ui64 CHeroHandler::reqExp(unsigned int level)
} }
else else
{ {
ui64 exp = expPerLevel[expPerLevel.size()-1]; //ui64 exp = expPerLevel[expPerLevel.size()-1];
level-=(expPerLevel.size()-1); //level-=(expPerLevel.size()-1);
while(level>0) //while(level>0)
{ //{
--level; // --level;
exp*=1.2; // exp*=1.2;
} //}
return exp; //return exp;
return reqExp(level - 1) + (reqExp(level - 1) - reqExp(level - 2)) * 1.2; //inefficient but follows exactly H3 values return reqExp(level - 1) + (reqExp(level - 1) - reqExp(level - 2)) * 1.2; //inefficient but follows exactly H3 values
} }
} }

View File

@ -39,24 +39,8 @@ DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mod
extern CLodHandler * bitmaph; extern CLodHandler * bitmaph;
extern boost::rand48 ran; extern boost::rand48 ran;
std::map <ui8, std::set <ui8> > CGKeys::playerKeyMap; std::map <ui8, std::set <ui8> > CGKeys::playerKeyMap;
std::map <si32, std::vector<CGMagi> > CGMagi::eyelist; std::map <si32, std::vector<si32> > CGMagi::eyelist;
std::map <ui32, std::vector <BankConfig> > banksInfo; //[index][preset], TODO: load it
struct BankConfig
{
BankConfig() {chance = upgradeChance = combatValue = value = rewardDifficulty = easiest = 0; };
//std::string name;
ui8 chance;
ui8 upgradeChance;
std::vector< std::pair <ui16, ui32> > guards;
ui32 combatValue;
std::map<ui8, si32> resources;
std::vector< std::pair <ui16, ui32> > creatures;
std::map<ui8, ui16> artifacts;
ui32 value;
ui32 rewardDifficulty; //?
ui16 easiest; //?
};
void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const
{}; {};
@ -91,6 +75,7 @@ bool CPlayersVisited::hasVisited( ui8 player ) const
} }
void CObjectHandler::loadObjects() void CObjectHandler::loadObjects()
{
{ {
tlog5 << "\t\tReading cregens \n"; tlog5 << "\t\tReading cregens \n";
cregens.resize(110); //TODO: hardcoded value - change cregens.resize(110); //TODO: hardcoded value - change
@ -105,10 +90,12 @@ void CObjectHandler::loadObjects()
ifs >> dw >> cr; ifs >> dw >> cr;
cregens[dw]=cr; cregens[dw]=cr;
} }
ifs.close();
ifs.clear();
tlog5 << "\t\tDone loading objects!\n"; tlog5 << "\t\tDone loading objects!\n";
} }
std::string banksConfig = bitmaph->getTextFile("ZCRBANK.TXT");
//TODO: parse to banksInfo
}
int CGObjectInstance::getOwner() const int CGObjectInstance::getOwner() const
{ {
//if (state) //if (state)
@ -3430,6 +3417,16 @@ void CGOnceVisitable::searchTomb(const CGHeroInstance *h, ui32 accept) const
cb->giveHeroArtifact(bonusType,h->id,-2); cb->giveHeroArtifact(bonusType,h->id,-2);
} }
if(!h->getBonus(HeroBonus::OBJECT,ID)) //we don't have modifier from this object yet
{
//ruin morale
GiveBonus gb;
gb.hid = h->id;
gb.bonus = HeroBonus(HeroBonus::ONE_BATTLE,HeroBonus::MORALE,HeroBonus::OBJECT,-3,id,"");
gb.bdescr.addTxt(MetaString::ARRAY_TXT,104); //Warrior Tomb Visited -3
cb->giveHeroBonus(&gb);
}
} }
} }
@ -3458,9 +3455,9 @@ void CBank::reset()
int val1 = ran()%100; int val1 = ran()%100;
int chance = 0; int chance = 0;
for (ui8 i = 1; i <= banksInfo[index].size(); i++) for (ui8 i = 1; i <= VLC->objh->banksInfo[index].size(); i++)
{ {
if (val1 < (chance += banksInfo[index][i].chance)) if (val1 < (chance += VLC->objh->banksInfo[index][i].chance))
cb->setObjProperty (id, 13, i); cb->setObjProperty (id, 13, i);
} }
artifacts.clear(); artifacts.clear();
@ -3482,7 +3479,7 @@ void CBank::setPropertyDer (ui8 what, ui32 val)
multiplier *= ((float)val)/100; multiplier *= ((float)val)/100;
break; break;
case 13: //bank preset case 13: //bank preset
bc = &banksInfo[index][val]; bc = &VLC->objh->banksInfo[index][val];
break; break;
case 18: //Artifacts case 18: //Artifacts
{ {
@ -3752,7 +3749,7 @@ void CGMagi::initObj()
if (ID == 27) if (ID == 27)
{ {
blockVisit = true; blockVisit = true;
eyelist[subID].push_back (*this); eyelist[subID].push_back(id);
} }
} }
void CGMagi::onHeroVisit(const CGHeroInstance * h) const void CGMagi::onHeroVisit(const CGHeroInstance * h) const
@ -3770,18 +3767,18 @@ void CGMagi::onHeroVisit(const CGHeroInstance * h) const
cb->showInfoDialog(&iw); cb->showInfoDialog(&iw);
fw.mode = 1; fw.mode = 1;
TakeYourTime tyt; std::vector<si32>::iterator it;
std::vector<CGMagi>::iterator it;
for (it = eyelist[subID].begin(); it < eyelist[subID].end(); it++) for (it = eyelist[subID].begin(); it < eyelist[subID].end(); it++)
{ {
cb->getTilesInRange (fw.tiles, it->pos, 5, h->tempOwner, 1); const CGObjectInstance *eye = cb->getObj(*it);
cb->getTilesInRange (fw.tiles, eye->pos, 5, h->tempOwner, 1);
cb->sendAndApply(&fw); cb->sendAndApply(&fw);
cv.id = it->id; cv.pos = eye->pos;
cv.focusTime = 2000;
cb->sendAndApply(&cv); cb->sendAndApply(&cv);
tyt.time = 2000;
cb->sendAndApply(&tyt);
} }
cv.id = h->id; cv.pos = h->getPosition(false);
cb->sendAndApply(&cv); cb->sendAndApply(&cv);
} }
else if (ID == 27) else if (ID == 27)

View File

@ -879,24 +879,10 @@ public:
void onHeroVisit(const CGHeroInstance * h) const; void onHeroVisit(const CGHeroInstance * h) const;
}; };
class DLL_EXPORT CObjectHandler
{
public:
std::vector<si32> cregens; //type 17. dwelling subid -> creature ID
void loadObjects();
template <typename Handler> void serialize(Handler &h, const int version)
{
h & cregens;
}
};
class DLL_EXPORT CGMagi : public CGObjectInstance class DLL_EXPORT CGMagi : public CGObjectInstance
{ {
public: public:
static std::map <si32, std::vector<CGMagi> > eyelist; //[subID][id], supports multiple sets as in H5 static std::map <si32, std::vector<si32> > eyelist; //[subID][id], supports multiple sets as in H5
void initObj(); void initObj();
void onHeroVisit(const CGHeroInstance * h) const; void onHeroVisit(const CGHeroInstance * h) const;
@ -906,4 +892,44 @@ public:
h & static_cast<CGObjectInstance&>(*this); h & static_cast<CGObjectInstance&>(*this);
} }
}; };
struct BankConfig
{
BankConfig() {chance = upgradeChance = combatValue = value = rewardDifficulty = easiest = 0; };
//std::string name;
ui8 chance;
ui8 upgradeChance;
std::vector< std::pair <ui16, ui32> > guards;
ui32 combatValue;
std::map<ui8, si32> resources;
std::vector< std::pair <ui16, ui32> > creatures;
std::map<ui8, ui16> artifacts;
ui32 value;
ui32 rewardDifficulty; //?
ui16 easiest; //?
template <typename Handler> void serialize(Handler &h, const int version)
{
h & chance & upgradeChance & guards & combatValue & resources & creatures & artifacts
& value & rewardDifficulty & easiest;
}
};
class DLL_EXPORT CObjectHandler
{
public:
std::vector<si32> cregens; //type 17. dwelling subid -> creature ID
std::map <ui32, std::vector <BankConfig> > banksInfo; //[index][preset], TODO: load it
void loadObjects();
template <typename Handler> void serialize(Handler &h, const int version)
{
h & cregens & banksInfo;
}
};
#endif // __COBJECTHANDLER_H__ #endif // __COBJECTHANDLER_H__

View File

@ -1296,35 +1296,18 @@ struct SetSelection : public CPackForClient, public CPackForServer //514
} }
}; };
struct TakeYourTime : public CPackForClient//515 struct CenterView : public CPackForClient//515
{ {
TakeYourTime(){CPackForClient::type = 515;}; CenterView(){CPackForClient::type = 515;};
DLL_EXPORT void applyGs(CGameState *gs);
void applyCl(CClient *cl); void applyCl(CClient *cl);
bool applyGh(CGameHandler *gh);
ui8 player; ui8 player;
ui32 time; int3 pos;
ui32 focusTime; //ms
template <typename Handler> void serialize(Handler &h, const int version) template <typename Handler> void serialize(Handler &h, const int version)
{ {
h & time & player; h & pos & player & focusTime;
}
};
struct CenterView : public CPackForClient//516
{
CenterView(){CPackForClient::type = 516;};
DLL_EXPORT void applyGs(CGameState *gs);
void applyCl(CClient *cl);
bool applyGh(CGameHandler *gh);
ui8 player;
si32 id;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & id & player;
} }
}; };

View File

@ -1005,12 +1005,3 @@ DLL_EXPORT void SetSelection::applyGs( CGameState *gs )
{ {
gs->getPlayer(player)->currentSelection = id; gs->getPlayer(player)->currentSelection = id;
} }
DLL_EXPORT void CenterView::applyGs( CGameState *gs )
{
gs->getPlayer(player)->currentSelection = id;
}
DLL_EXPORT void TakeYourTime::applyGs( CGameState *gs )
{
}

View File

@ -110,7 +110,6 @@ void registerTypes2(Serializer &s)
s.template registerType<SaveGame>(); s.template registerType<SaveGame>();
s.template registerType<SetSelection>(); s.template registerType<SetSelection>();
s.template registerType<PlayerMessage>(); s.template registerType<PlayerMessage>();
s.template registerType<TakeYourTime>();
s.template registerType<CenterView>(); s.template registerType<CenterView>();
} }