1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +02:00

* improved Events handling

* fixed saving town available creatures info
* minor improvements
This commit is contained in:
Michał W. Urbańczyk
2009-07-15 22:46:00 +00:00
parent 48661bd714
commit 23803c9f17
8 changed files with 34 additions and 27 deletions

View File

@ -309,12 +309,14 @@ void CBattleInterface::setPrintCellBorders(bool set)
{ {
settings.printCellBorders = set; settings.printCellBorders = set;
redrawBackgroundWithHexes(activeStack); redrawBackgroundWithHexes(activeStack);
LOCPLINT->totalRedraw();
} }
void CBattleInterface::setPrintStackRange(bool set) void CBattleInterface::setPrintStackRange(bool set)
{ {
settings.printStackRange = set; settings.printStackRange = set;
redrawBackgroundWithHexes(activeStack); redrawBackgroundWithHexes(activeStack);
LOCPLINT->totalRedraw();
} }
void CBattleInterface::setPrintMouseShadow(bool set) void CBattleInterface::setPrintMouseShadow(bool set)

View File

@ -91,17 +91,17 @@ void CGarrisonSlot::hover (bool on)
{ {
if(owner->highlighted == this) if(owner->highlighted == this)
{ {
temp = CGI->generaltexth->tcommands[4]; temp = CGI->generaltexth->tcommands[4]; //View %s
boost::algorithm::replace_first(temp,"%s",creature->nameSing); boost::algorithm::replace_first(temp,"%s",creature->nameSing);
} }
else if (owner->highlighted->creature == creature) else if (owner->highlighted->creature == creature)
{ {
temp = CGI->generaltexth->tcommands[2]; temp = CGI->generaltexth->tcommands[2]; //Combine %s armies
boost::algorithm::replace_first(temp,"%s",creature->nameSing); boost::algorithm::replace_first(temp,"%s",creature->nameSing);
} }
else if (owner->highlighted->creature) else if (owner->highlighted->creature)
{ {
temp = CGI->generaltexth->tcommands[7]; temp = CGI->generaltexth->tcommands[7]; //Exchange %s with %s
boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing); boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
boost::algorithm::replace_first(temp,"%s",creature->nameSing); boost::algorithm::replace_first(temp,"%s",creature->nameSing);
} }
@ -116,11 +116,15 @@ void CGarrisonSlot::hover (bool on)
{ {
if(upg) if(upg)
{ {
temp = CGI->generaltexth->tcommands[32]; temp = CGI->generaltexth->tcommands[32]; //Select %s (visiting)
}
else if(owner->oup && owner->oup->ID == TOWNI_TYPE)
{
temp = CGI->generaltexth->tcommands[12]; //Select %s (in garrison)
} }
else else
{ {
temp = CGI->generaltexth->tcommands[12]; temp = CGI->generaltexth->allTexts[481]; //Select %s
} }
boost::algorithm::replace_first(temp,"%s",creature->nameSing); boost::algorithm::replace_first(temp,"%s",creature->nameSing);
}; };
@ -135,17 +139,17 @@ void CGarrisonSlot::hover (bool on)
&& owner->highlighted->upg != upg //we're moving it to the other garrison && owner->highlighted->upg != upg //we're moving it to the other garrison
) )
{ {
temp = CGI->generaltexth->tcommands[5]; //cannot move last stack! temp = CGI->generaltexth->tcommands[5]; //Cannot move last army to garrison
} }
else else
{ {
temp = CGI->generaltexth->tcommands[6]; temp = CGI->generaltexth->tcommands[6]; //Move %s
boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing); boost::algorithm::replace_first(temp,"%s",owner->highlighted->creature->nameSing);
} }
} }
else else
{ {
temp = CGI->generaltexth->tcommands[11]; temp = CGI->generaltexth->tcommands[11]; //Empty
} }
} }
LOCPLINT->statusbar->print(temp); LOCPLINT->statusbar->print(temp);
@ -532,7 +536,7 @@ void CGarrisonInt::splitStacks(int am2)
} }
CGarrisonInt::CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *&pomsur, const Point& SurOffset, CGarrisonInt::CGarrisonInt(int x, int y, int inx, const Point &garsOffset, SDL_Surface *&pomsur, const Point& SurOffset,
const CArmedInstance *s1, const CArmedInstance *s2, bool smallImgs) const CArmedInstance *s1, const CArmedInstance *s2, bool smallImgs)
:interx(inx),garOffset(garsOffset),highlighted(NULL),sur(pomsur),surOffset(surOffset),sup(NULL), :interx(inx),garOffset(garsOffset),highlighted(NULL),sur(pomsur),surOffset(SurOffset),sup(NULL),
sdown(NULL),oup(s1),odown(s2), smallIcons(smallImgs) sdown(NULL),oup(s1),odown(s2), smallIcons(smallImgs)
{ {
active = false; active = false;
@ -694,7 +698,7 @@ void SComponent::init(Etype Type, int Subtype, int Val)
subtitle = CGI->arth->artifacts[Subtype].Name(); subtitle = CGI->arth->artifacts[Subtype].Name();
break; break;
case primskill: case primskill:
oss << ((Val>0)?("+"):("-")) << Val << " "; oss << std::showpos << Val << " ";
if(Subtype < 4) if(Subtype < 4)
{ {
description = CGI->generaltexth->arraytxt[2+Subtype]; description = CGI->generaltexth->arraytxt[2+Subtype];

View File

@ -462,10 +462,6 @@ void ShowInInfobox::applyCl(CClient *cl)
} }
} }
void OpenWindow::applyFirstCl(CClient *cl)
{
}
void OpenWindow::applyCl(CClient *cl) void OpenWindow::applyCl(CClient *cl)
{ {
switch(window) switch(window)

View File

@ -2553,7 +2553,10 @@ void CGEvent::activated( const CGHeroInstance * h ) const
{ {
InfoWindow iw; InfoWindow iw;
iw.player = h->tempOwner; iw.player = h->tempOwner;
if(message.size())
iw.text << message; iw.text << message;
else
iw.text.addTxt(MetaString::ADVOB_TXT, 16);
cb->showInfoDialog(&iw); cb->showInfoDialog(&iw);
cb->startBattleI(h->id,army,pos,boost::bind(&CGEvent::endBattle,this,h,_1)); cb->startBattleI(h->id,army,pos,boost::bind(&CGEvent::endBattle,this,h,_1));
} }
@ -2688,9 +2691,15 @@ void CGEvent::giveContents( const CGHeroInstance *h, bool afterBattle ) const
} }
iw.components.clear(); iw.components.clear();
getText(iw,afterBattle,183,h);
for(int i=0; i<artifacts.size(); i++) for(int i=0; i<artifacts.size(); i++)
{ {
iw.components.push_back(Component(Component::ARTIFACT,artifacts[i],0,0)); iw.components.push_back(Component(Component::ARTIFACT,artifacts[i],0,0));
if(iw.components.size() >= 14)
{
cb->showInfoDialog(&iw);
iw.components.clear();
}
} }
if(iw.components.size()) if(iw.components.size())
{ {
@ -2768,7 +2777,7 @@ void CGEvent::giveContents( const CGHeroInstance *h, bool afterBattle ) const
return; return;
} }
if(!afterBattle) if(!afterBattle && message.size())
{ {
iw.text << message; iw.text << message;
cb->showInfoDialog(&iw); cb->showInfoDialog(&iw);
@ -2780,7 +2789,7 @@ void CGEvent::giveContents( const CGHeroInstance *h, bool afterBattle ) const
void CGEvent::getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const void CGEvent::getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const
{ {
if(afterBattle) if(afterBattle || !message.size())
{ {
iw.text.addTxt(MetaString::ADVOB_TXT,text);//%s has lost treasure. iw.text.addTxt(MetaString::ADVOB_TXT,text);//%s has lost treasure.
iw.text.addReplacement(h->name); iw.text.addReplacement(h->name);
@ -2796,7 +2805,7 @@ void CGEvent::getText( InfoWindow &iw, bool &afterBattle, int val, int negative,
{ {
iw.components.clear(); iw.components.clear();
iw.text.clear(); iw.text.clear();
if(afterBattle) if(afterBattle || !message.size())
{ {
iw.text.addTxt(MetaString::ADVOB_TXT,val < 0 ? negative : positive); //%s's luck takes a turn for the worse / %s's luck increases iw.text.addTxt(MetaString::ADVOB_TXT,val < 0 ? negative : positive); //%s's luck takes a turn for the worse / %s's luck increases
iw.text.addReplacement(h->name); iw.text.addReplacement(h->name);
@ -2952,7 +2961,7 @@ void CGScholar::onHeroVisit( const CGHeroInstance * h ) const
{ {
case 0: case 0:
cb->changePrimSkill(h->id,bid,+1); cb->changePrimSkill(h->id,bid,+1);
iw.components.push_back(Component(Component::PRIM_SKILL,bid,ssl+1,0)); iw.components.push_back(Component(Component::PRIM_SKILL,bid,+1,0));
break; break;
case 1: case 1:
cb->changeSecSkill(h->id,bid,+1); cb->changeSecSkill(h->id,bid,+1);

View File

@ -334,7 +334,7 @@ public:
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<CGDwelling&>(*this);
h & name & builded & destroyed & identifier & alignment & forbiddenBuildings & builtBuildings h & name & builded & destroyed & identifier & alignment & forbiddenBuildings & builtBuildings
& possibleSpells & obligatorySpells & spells & /*strInfo & */events; & possibleSpells & obligatorySpells & spells & /*strInfo & */events;

View File

@ -516,9 +516,7 @@ struct GiveHero : public CPackForClient //516
struct OpenWindow : public CPackForClient //517 struct OpenWindow : public CPackForClient //517
{ {
OpenWindow(){type = 517;}; OpenWindow(){type = 517;};
void applyFirstCl(CClient *cl);
void applyCl(CClient *cl); void applyCl(CClient *cl);
DLL_EXPORT void applyGs(CGameState *gs);
enum EWindow {EXCHANGE_WINDOW, RECRUITMENT_FIRST, RECRUITMENT_ALL}; enum EWindow {EXCHANGE_WINDOW, RECRUITMENT_FIRST, RECRUITMENT_ALL};
ui8 window; ui8 window;

View File

@ -34,6 +34,7 @@
DLL_EXPORT void SetResource::applyGs( CGameState *gs ) DLL_EXPORT void SetResource::applyGs( CGameState *gs )
{ {
amax(val, 0); //new value must be >= 0
gs->getPlayer(player)->resources[resid] = val; gs->getPlayer(player)->resources[resid] = val;
} }
@ -141,6 +142,7 @@ DLL_EXPORT void ChangeSpells::applyGs( CGameState *gs )
DLL_EXPORT void SetMana::applyGs( CGameState *gs ) DLL_EXPORT void SetMana::applyGs( CGameState *gs )
{ {
CGHeroInstance *hero = gs->getHero(hid); CGHeroInstance *hero = gs->getHero(hid);
amax(val, 0); //not less than 0
hero->mana = val; hero->mana = val;
} }
@ -424,10 +426,6 @@ DLL_EXPORT void GiveHero::applyGs( CGameState *gs )
h->inTownGarrison = false; h->inTownGarrison = false;
} }
DLL_EXPORT void OpenWindow::applyGs(CGameState *gs)
{
}
DLL_EXPORT void NewTurn::applyGs( CGameState *gs ) DLL_EXPORT void NewTurn::applyGs( CGameState *gs )
{ {
gs->day = day; gs->day = day;

View File

@ -1296,7 +1296,7 @@ void CGameHandler::giveResource(int player, int which, int val)
SetResource sr; SetResource sr;
sr.player = player; sr.player = player;
sr.resid = which; sr.resid = which;
sr.val = (gs->players.find(player)->second.resources[which]+val); sr.val = gs->players.find(player)->second.resources[which]+val;
sendAndApply(&sr); sendAndApply(&sr);
} }
void CGameHandler::showCompInfo(ShowInInfobox * comp) void CGameHandler::showCompInfo(ShowInInfobox * comp)