1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-12 02:28:11 +02:00

Patch from Yupsi. Hero sleep/wake-up. Fixes #162 and #601.

This commit is contained in:
Frank Zago 2011-09-24 16:46:23 +00:00
parent 6dd9d416b4
commit 01566fcde1
5 changed files with 101 additions and 15 deletions

View File

@ -1092,7 +1092,16 @@ void CAdvMapInt::fshowQuestlog()
}
void CAdvMapInt::fsleepWake()
{
const CGHeroInstance *h = curHero();
if (!h)
return;
bool newSleep = !isHeroSleeping(h);
setHeroSleeping(h, newSleep);
updateSleepWake(h);
if (newSleep)
fnextHero();
}
void CAdvMapInt::fmoveHero()
{
const CGHeroInstance *h = curHero();
@ -1136,7 +1145,7 @@ void CAdvMapInt::fnextHero()
i++;
if(i >= LOCPLINT->wanderingHeroes.size())
i = 0;
} while (!LOCPLINT->wanderingHeroes[i]->movement && i!=start);
} while ((!LOCPLINT->wanderingHeroes[i]->movement || isHeroSleeping(LOCPLINT->wanderingHeroes[i])) && i!=start);
heroList.select(i);
}
@ -1144,10 +1153,26 @@ void CAdvMapInt::fendTurn()
{
if(!LOCPLINT->makingTurn)
return;
if(LOCPLINT->cingconsole->active)
LOCPLINT->cingconsole->deactivate();
LOCPLINT->makingTurn = false;
LOCPLINT->cb->endTurn();
for (int i = 0; i < LOCPLINT->wanderingHeroes.size(); i++)
if (!isHeroSleeping(LOCPLINT->wanderingHeroes[i]) && (LOCPLINT->wanderingHeroes[i]->movement > 0)) // some other minimal threshold probably?
{
LOCPLINT->showYesNoDialog(CGI->generaltexth->allTexts[55], std::vector<SComponent*>(), boost::bind(&CAdvMapInt::endingTurn, this), 0, false);
return;
}
endingTurn();
}
void CAdvMapInt::updateSleepWake(const CGHeroInstance *h)
{
sleepWake.block(!h);
if (!h)
return;
bool state = isHeroSleeping(h);
sleepWake.setIndex(state ? 1 : 0, true);
sleepWake.assignedKeys.clear();
sleepWake.assignedKeys.insert(state ? SDLK_w : SDLK_z);
sleepWake.update();
}
void CAdvMapInt::activate()
@ -1239,6 +1264,23 @@ void CAdvMapInt::showAll(SDL_Surface *to)
infoBar.showAll(to);
LOCPLINT->cingconsole->show(to);
}
bool CAdvMapInt::isHeroSleeping(const CGHeroInstance *hero)
{
if (!hero)
return false;
return vstd::contains(LOCPLINT->sleepingHeroes, hero);
}
void CAdvMapInt::setHeroSleeping(const CGHeroInstance *hero, bool sleep)
{
if (sleep)
LOCPLINT->sleepingHeroes += hero;
else
LOCPLINT->sleepingHeroes -= hero;
}
void CAdvMapInt::show(SDL_Surface *to)
{
if(state != INGAME)
@ -1506,6 +1548,8 @@ void CAdvMapInt::select(const CArmedInstance *sel, bool centerView /*= true*/)
terrain.currentPath = NULL;
if(sel->ID==TOWNI_TYPE)
{
updateSleepWake(NULL);
int pos = vstd::findPos(LOCPLINT->towns,sel);
townList.selected = pos;
townList.fixPos();
@ -1514,6 +1558,8 @@ void CAdvMapInt::select(const CArmedInstance *sel, bool centerView /*= true*/)
{
const CGHeroInstance *h = static_cast<const CGHeroInstance*>(sel);
updateSleepWake(h);
if(LOCPLINT->getWHero(heroList.selected) != h)
{
heroList.selected = heroList.getPosOfHero(h);
@ -1604,6 +1650,14 @@ void CAdvMapInt::startTurn()
state = INGAME;
}
void CAdvMapInt::endingTurn()
{
if(LOCPLINT->cingconsole->active)
LOCPLINT->cingconsole->deactivate();
LOCPLINT->makingTurn = false;
LOCPLINT->cb->endTurn();
}
void CAdvMapInt::tileLClicked(const int3 &mp)
{
if(!LOCPLINT->cb->isVisible(mp) || !LOCPLINT->makingTurn)

View File

@ -233,9 +233,13 @@ public:
void mouseMoved (const SDL_MouseMotionEvent & sEvent);
bool isActive();
bool isHeroSleeping(const CGHeroInstance *hero);
void setHeroSleeping(const CGHeroInstance *hero, bool sleep);
void setPlayer(int Player);
void startHotSeatWait(int Player);
void startTurn();
void endingTurn();
void tileLClicked(const int3 &mp);
void tileHovered(const int3 &tile);
void tileRClicked(const int3 &mp);
@ -244,6 +248,7 @@ public:
const CGHeroInstance * curHero() const;
const CGTownInstance * curTown() const;
const IShipyard * ourInaccessibleShipyard(const CGObjectInstance *obj) const; //checks if obj is our ashipyard and cursor is 0,0 -> returns shipyard or NULL else
void updateSleepWake(const CGHeroInstance *h); //button update
};
extern CAdvMapInt *adventureInt;

View File

@ -1094,6 +1094,23 @@ template <typename Handler> void CPlayerInterface::serializeTempl( Handler &h, c
h & playerID;
h & sysOpts;
h & spellbookSettings;
ui8 sleepingSize;
if(h.saving)
sleepingSize = sleepingHeroes.size();
h & sleepingSize;
for (int i = 0; i < sleepingSize; i++)
{
si32 hid;
if (h.saving)
hid = sleepingHeroes[i]->id;
h & hid;
if (!h.saving)
{
const CGHeroInstance *hero = cb->getHero(hid);
sleepingHeroes += hero;
}
}
}
void CPlayerInterface::serialize( COSer<CSaveFile> &h, const int version )
@ -1115,6 +1132,15 @@ bool CPlayerInterface::moveHero( const CGHeroInstance *h, CGPath path )
if (!h)
return false; //can't find hero
if (adventureInt && adventureInt->isHeroSleeping(h))
{
adventureInt->sleepWake.clickLeft(true, false);
adventureInt->sleepWake.clickLeft(false, true);
//could've just called
//adventureInt->fsleepWake();
//but no authentic button click/sound ;-)
}
//evil...
eventsM.unlock();
pim->unlock();

View File

@ -141,6 +141,7 @@ public:
std::vector<const CGHeroInstance *> wanderingHeroes; //our heroes on the adventure map (not the garrisoned ones)
std::vector<const CGTownInstance *> towns; //our heroes on the adventure map (not the garrisoned ones)
std::map<const CGHeroInstance *, CGPath> paths; //maps hero => selected path in adventure map
std::vector<const CGHeroInstance *> sleepingHeroes;
struct SpellbookLastSetting
{

View File

@ -20,7 +20,7 @@
"ButtonKingdomOv": { "x": 679, "y": 196, "graphic": "IAM002.DEF", "playerColoured": 1 },
"ButtonUnderground": { "x": 711, "y": 196, "graphic": "IAM010.DEF", "playerColoured": 1, "additionalDefs": [ "IAM003.DEF" ] },
"ButtonQuestLog": { "x": 679, "y": 228, "graphic": "IAM004.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 711, "y": 228, "graphic": "IAM005.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 711, "y": 228, "graphic": "IAM005.DEF", "playerColoured": 1, "additionalDefs":["IAM011.DEF"] },
"ButtonMoveHero": { "x": 679, "y": 260, "graphic": "IAM006.DEF", "playerColoured": 1 },
"ButtonSpellbook": { "x": 711, "y": 260, "graphic": "IAM007.DEF", "playerColoured": 1 },
"ButtonAdvOptions": { "x": 679, "y": 292, "graphic": "IAM008.DEF", "playerColoured": 1 },
@ -48,7 +48,7 @@
"ButtonKingdomOv": { "x": 903, "y": 196, "graphic": "IAM002.DEF", "playerColoured": 1 },
"ButtonUnderground": { "x": 935, "y": 196, "graphic": "IAM010.DEF", "playerColoured": 1, "additionalDefs": [ "IAM003.DEF" ] },
"ButtonQuestLog": { "x": 903, "y": 228, "graphic": "IAM004.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 935, "y": 228, "graphic": "IAM005.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 935, "y": 228, "graphic": "IAM005.DEF", "playerColoured": 1, "additionalDefs":["IAM011.DEF"] },
"ButtonMoveHero": { "x": 903, "y": 260, "graphic": "IAM006.DEF", "playerColoured": 1 },
"ButtonSpellbook": { "x": 935, "y": 260, "graphic": "IAM007.DEF", "playerColoured": 1 },
"ButtonAdvOptions": { "x": 903, "y": 292, "graphic": "IAM008.DEF", "playerColoured": 1 },
@ -76,7 +76,7 @@
"ButtonKingdomOv": { "x": 903, "y": 197, "graphic": "IAM002L.DEF", "playerColoured": 1 },
"ButtonUnderground": { "x": 903, "y": 229, "graphic": "IAM010L.DEF", "playerColoured": 1, "additionalDefs": ["IAM003L.DEF" ] },
"ButtonQuestLog": { "x": 903, "y": 261, "graphic": "IAM004L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 903, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 903, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1, "additionalDefs":["IAM011L.DEF"] },
"ButtonMoveHero": { "x": 903, "y": 326, "graphic": "IAM006L.DEF", "playerColoured": 1 },
"ButtonSpellbook": { "x": 903, "y": 359, "graphic": "IAM007L.DEF", "playerColoured": 1 },
"ButtonAdvOptions": { "x": 903, "y": 392, "graphic": "IAM008L.DEF", "playerColoured": 1 },
@ -103,7 +103,7 @@
"ButtonKingdomOv": { "x": 1159, "y": 197, "graphic": "IAM002L.DEF", "playerColoured": 1 },
"ButtonUnderground": { "x": 1159, "y": 229, "graphic": "IAM010L.DEF", "playerColoured": 1, "additionalDefs": ["IAM003L.DEF" ] },
"ButtonQuestLog": { "x": 1159, "y": 261, "graphic": "IAM004L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1159, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1159, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1, "additionalDefs":["IAM011L.DEF"] },
"ButtonMoveHero": { "x": 1159, "y": 326, "graphic": "IAM006L.DEF", "playerColoured": 1 },
"ButtonSpellbook": { "x": 1159, "y": 359, "graphic": "IAM007L.DEF", "playerColoured": 1 },
"ButtonAdvOptions": { "x": 1159, "y": 392, "graphic": "IAM008L.DEF", "playerColoured": 1 },
@ -131,7 +131,7 @@
"ButtonKingdomOv": { "x": 1159, "y": 196, "graphic": "IAM002L.DEF", "playerColoured": 1 },
"ButtonUnderground": { "x": 1159, "y": 228, "graphic": "IAM010L.DEF", "playerColoured": 1, "additionalDefs": ["IAM003L.DEF" ] },
"ButtonQuestLog": { "x": 1159, "y": 260, "graphic": "IAM004L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1159, "y": 292, "graphic": "IAM005L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1159, "y": 292, "graphic": "IAM005L.DEF", "playerColoured": 1, "additionalDefs":["IAM011L.DEF"] },
"ButtonMoveHero": { "x": 1159, "y": 324, "graphic": "IAM006L.DEF", "playerColoured": 1 },
"ButtonSpellbook": { "x": 1159, "y": 355, "graphic": "IAM007L.DEF", "playerColoured": 1 },
"ButtonAdvOptions": { "x": 1159, "y": 388, "graphic": "IAM008L.DEF", "playerColoured": 1 },
@ -159,7 +159,7 @@
"ButtonKingdomOv": { "x": 1245, "y": 197, "graphic": "IAM002L.DEF", "playerColoured": 1 },
"ButtonUnderground": { "x": 1245, "y": 229, "graphic": "IAM010L.DEF", "playerColoured": 1, "additionalDefs": ["IAM003L.DEF" ] },
"ButtonQuestLog": { "x": 1245, "y": 261, "graphic": "IAM004L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1245, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1245, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1, "additionalDefs":["IAM011L.DEF"] },
"ButtonMoveHero": { "x": 1245, "y": 326, "graphic": "IAM006L.DEF", "playerColoured": 1 },
"ButtonSpellbook": { "x": 1245, "y": 359, "graphic": "IAM007L.DEF", "playerColoured": 1 },
"ButtonAdvOptions": { "x": 1245, "y": 392, "graphic": "IAM008L.DEF", "playerColoured": 1 },
@ -187,7 +187,7 @@
"ButtonKingdomOv": { "x": 1319, "y": 197, "graphic": "IAM002L.DEF", "playerColoured": 1 },
"ButtonUnderground": { "x": 1319, "y": 229, "graphic": "IAM010L.DEF", "playerColoured": 1, "additionalDefs": ["IAM003L.DEF" ] },
"ButtonQuestLog": { "x": 1319, "y": 261, "graphic": "IAM004L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1319, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1319, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1, "additionalDefs":["IAM011L.DEF"] },
"ButtonMoveHero": { "x": 1319, "y": 326, "graphic": "IAM006L.DEF", "playerColoured": 1 },
"ButtonSpellbook": { "x": 1319, "y": 359, "graphic": "IAM007L.DEF", "playerColoured": 1 },
"ButtonAdvOptions": { "x": 1319, "y": 392, "graphic": "IAM008L.DEF", "playerColoured": 1 },
@ -215,7 +215,7 @@
"ButtonKingdomOv": { "x": 1479, "y": 197, "graphic": "IAM002L.DEF", "playerColoured": 1 },
"ButtonUnderground": { "x": 1479, "y": 229, "graphic": "IAM010L.DEF", "playerColoured": 1, "additionalDefs": ["IAM003L.DEF" ] },
"ButtonQuestLog": { "x": 1479, "y": 261, "graphic": "IAM004L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1479, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1479, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1, "additionalDefs":["IAM011L.DEF"] },
"ButtonMoveHero": { "x": 1479, "y": 326, "graphic": "IAM006L.DEF", "playerColoured": 1 },
"ButtonSpellbook": { "x": 1479, "y": 359, "graphic": "IAM007L.DEF", "playerColoured": 1 },
"ButtonAdvOptions": { "x": 1479, "y": 392, "graphic": "IAM008L.DEF", "playerColoured": 1 },
@ -243,7 +243,7 @@
"ButtonKingdomOv": { "x": 1559, "y": 197, "graphic": "IAM002L.DEF", "playerColoured": 1 },
"ButtonUnderground": { "x": 1559, "y": 229, "graphic": "IAM010L.DEF", "playerColoured": 1, "additionalDefs": ["IAM003L.DEF" ] },
"ButtonQuestLog": { "x": 1559, "y": 261, "graphic": "IAM004L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1559, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1559, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1, "additionalDefs":["IAM011L.DEF"] },
"ButtonMoveHero": { "x": 1559, "y": 326, "graphic": "IAM006L.DEF", "playerColoured": 1 },
"ButtonSpellbook": { "x": 1559, "y": 359, "graphic": "IAM007L.DEF", "playerColoured": 1 },
"ButtonAdvOptions": { "x": 1559, "y": 392, "graphic": "IAM008L.DEF", "playerColoured": 1 },
@ -271,7 +271,7 @@
"ButtonKingdomOv": { "x": 1799, "y": 197, "graphic": "IAM002L.DEF", "playerColoured": 1 },
"ButtonUnderground": { "x": 1799, "y": 229, "graphic": "IAM010L.DEF", "playerColoured": 1, "additionalDefs": [ "IAM003L.DEF" ] },
"ButtonQuestLog": { "x": 1799, "y": 261, "graphic": "IAM004L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1799, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1 },
"ButtonSleepWake": { "x": 1799, "y": 293, "graphic": "IAM005L.DEF", "playerColoured": 1, "additionalDefs":["IAM011L.DEF"] },
"ButtonMoveHero": { "x": 1799, "y": 326, "graphic": "IAM006L.DEF", "playerColoured": 1 },
"ButtonSpellbook": { "x": 1799, "y": 359, "graphic": "IAM007L.DEF", "playerColoured": 1 },
"ButtonAdvOptions": { "x": 1799, "y": 392, "graphic": "IAM008L.DEF", "playerColoured": 1 },