1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-26 03:52:01 +02:00

* support for prison

* updated changelog
This commit is contained in:
Michał W. Urbańczyk 2009-02-14 19:12:40 +00:00
parent 99aef852be
commit adf5c052f9
12 changed files with 121 additions and 20 deletions

View File

@ -821,6 +821,20 @@ void CGameState::applyNL(IPack * pack)
h->inTownGarrison = false; h->inTownGarrison = false;
break; break;
} }
case 516:
{
GiveHero *sha = static_cast<GiveHero*>(pack);
CGHeroInstance *h = getHero(sha->id);
map->removeBlockVisTiles(h,true);
h->setOwner(sha->player);
h->movement = h->maxMovePoints(true);
h->initHeroDefInfo();
map->heroes.push_back(h);
players[h->tempOwner].heroes.push_back(h);
map->addBlockVisTiles(h);
h->inTownGarrison = false;
break;
}
case 1001://set object property case 1001://set object property
{ {
SetObjectProperty *p = static_cast<SetObjectProperty*>(pack); SetObjectProperty *p = static_cast<SetObjectProperty*>(pack);
@ -1559,7 +1573,11 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed)
} }
for(int i=0; i<map->objects.size(); i++) for(int i=0; i<map->objects.size(); i++)
{
map->objects[i]->initObj(); map->objects[i]->initObj();
if(map->objects[i]->ID == 62) //prison also needs to initialize hero
static_cast<CGHeroInstance*>(map->objects[i])->initHero();
}
} }
bool CGameState::battleShootCreatureStack(int ID, int dest) bool CGameState::battleShootCreatureStack(int ID, int dest)
@ -1761,6 +1779,9 @@ void CGameState::setObjProperty( SetObjectProperty * p )
case 5: case 5:
static_cast<CGVisitableOPW*>(obj)->visited = p->val; static_cast<CGVisitableOPW*>(obj)->visited = p->val;
break; break;
case 6:
obj->ID = p->val;
break;
} }
} }

View File

@ -9,6 +9,8 @@ GENERAL:
* fixed crash when there was no hero available to hire for some player * fixed crash when there was no hero available to hire for some player
* fixed problems with 1024x600 screen resolution * fixed problems with 1024x600 screen resolution
* updating blockmap/visitmap of randomized objects * updating blockmap/visitmap of randomized objects
* fixed crashes on loading maps with flag all mines/dwelling victory condition
* further fixes for leveling-up (stability and identical offered skills bug)
ADVENTURE INTERFACE: ADVENTURE INTERFACE:
* added missing path arrows * added missing path arrows
@ -16,19 +18,22 @@ ADVENTURE INTERFACE:
* recalculating hero path after reselecting hero * recalculating hero path after reselecting hero
* further changes in pathfinder making it more like original one * further changes in pathfinder making it more like original one
* orientation of hero can't be change if movement points are exhausted * orientation of hero can't be change if movement points are exhausted
* campfire, borderguard, bordergate, questguard will be accessible from the top * campfire, borderguard, bordergate, questguard will be accessible from the top
* new movement cost calculation algorithm
BATTLES: BATTLES:
* partial support for battle obstacles * partial support for battle obstacles
* spells not known by hero can't be casted * spells not known by hero can't be casted
* spell books won't be placed in War Machine slots after battle * spell books won't be placed in War Machine slots after battle
* attack is now possible when hex under cursor is not displayed * attack is now possible when hex under cursor is not displayed
* fixes for two-hex creatures attacks * fixes for two-hex creatures actions
* a few tweaks in battle path/available hexes calculation (more of them is needed)
* fixed positions of stack queue and battle result window when resolution is != 800x600 * fixed positions of stack queue and battle result window when resolution is != 800x600
* corrected duration of frenzy spell which was incorrect in certain cases * corrected duration of frenzy spell which was incorrect in certain cases
* corrected hero spell casting animation * corrected hero spell casting animation
* better support for battle backgrounds * better support for battle backgrounds
* blocked "save" command during battle * blocked "save" command during battle
* spellbook displays only spells known by Hero
New spells supported: New spells supported:
- Mirth - Mirth
- Sorrow - Sorrow
@ -52,6 +57,7 @@ PREGAME:
OBJECTS: OBJECTS:
New objects supported: New objects supported:
* Prison
* Magic Well * Magic Well
* Faerie Ring * Faerie Ring
* Swan Pond * Swan Pond

View File

@ -377,6 +377,19 @@ void CClient::process(int what)
playerint[h->tempOwner]->heroInGarrisonChange(gs->getTown(hr.tid)); playerint[h->tempOwner]->heroInGarrisonChange(gs->getTown(hr.tid));
break; break;
} }
case 516:
{
GiveHero hr;
*serv >> hr;
tlog5 << "Players receives hero\n";
CGHeroInstance *h = gs->getHero(hr.id);
CGI->mh->hideObject(h);
gs->apply(&hr);
CGI->mh->initHeroDef(h);
CGI->mh->printObject(h);
playerint[h->tempOwner]->heroCreated(h);
break;
}
case 1001: case 1001:
{ {
SetObjectProperty sop; SetObjectProperty sop;

View File

@ -88,6 +88,7 @@ public:
void giveHeroBonus(GiveBonus * bonus){}; void giveHeroBonus(GiveBonus * bonus){};
void setMovePoints(SetMovePoints * smp){}; void setMovePoints(SetMovePoints * smp){};
void setManaPoints(int hid, int val){}; void setManaPoints(int hid, int val){};
void giveHero(int id, int player){};
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
friend class CCallback; //handling players actions friend class CCallback; //handling players actions
friend void processCommand(const std::string &message, CClient *&client); //handling console friend void processCommand(const std::string &message, CClient *&client); //handling console

View File

@ -434,7 +434,8 @@ void CGHeroInstance::initHero(int SUBID)
void CGHeroInstance::initHero() void CGHeroInstance::initHero()
{ {
initHeroDefInfo(); if(ID == 34)
initHeroDefInfo();
if(!type) if(!type)
type = VLC->heroh->heroes[subID]; type = VLC->heroh->heroes[subID];
artifWorn[16] = 3; artifWorn[16] = 3;
@ -504,7 +505,7 @@ void CGHeroInstance::initHero()
void CGHeroInstance::initHeroDefInfo() void CGHeroInstance::initHeroDefInfo()
{ {
if(!defInfo) if(!defInfo || defInfo->id != 34)
{ {
defInfo = new CGDefInfo(); defInfo = new CGDefInfo();
defInfo->id = 34; defInfo->id = 34;
@ -531,20 +532,43 @@ bool CGHeroInstance::needsLastStack() const
} }
void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const
{ {
//TODO: check for allies if (ID == 34) //hero
if(tempOwner == h->tempOwner) //our hero
{ {
//exchange //TODO: check for allies
if(tempOwner == h->tempOwner) //our hero
{
//exchange
}
else
{
cb->startBattleI(
&h->army,
&army,
h->pos,
h,
this,
0);
}
} }
else else if(ID == 62) //prison
{ {
cb->startBattleI( if(cb->getHeroCount(h->tempOwner,false) < 8) //free hero slot
&h->army, {
&army, cb->setObjProperty(id,6,34); //set ID to 34
h->pos, cb->giveHero(id,h->tempOwner); //recreates def and adds hero to player
h,
this, InfoWindow iw;
0); iw.player = h->tempOwner;
iw.text << std::pair<ui8,ui32>(11,102);
cb->showInfoDialog(&iw);
}
else //already 8 wandering heroes
{
InfoWindow iw;
iw.player = h->tempOwner;
iw.text << std::pair<ui8,ui32>(11,103);
cb->showInfoDialog(&iw);
}
} }
} }

View File

@ -39,4 +39,16 @@ const CGHeroInstance* IGameCallback::getSelectedHero( int player )
const PlayerSettings * IGameCallback::getPlayerSettings( int color ) const PlayerSettings * IGameCallback::getPlayerSettings( int color )
{ {
return &gs->scenarioOps->getIthPlayersSettings(color); return &gs->scenarioOps->getIthPlayersSettings(color);
}
int IGameCallback::getHeroCount( int player, bool includeGarrisoned )
{
int ret = 0;
if(includeGarrisoned)
return gs->players[player].heroes.size();
else
for(int i=0; i < gs->players[player].heroes.size(); i++)
if(!gs->players[player].heroes[i]->inTownGarrison)
ret++;
return ret;
} }

View File

@ -37,6 +37,7 @@ public:
virtual int getCurrentPlayer()=0; virtual int getCurrentPlayer()=0;
virtual int getSelectedHero()=0; virtual int getSelectedHero()=0;
virtual const PlayerSettings * getPlayerSettings(int color); virtual const PlayerSettings * getPlayerSettings(int color);
virtual int getHeroCount(int player, bool includeGarrisoned);
//do sth //do sth
virtual void changeSpells(int hid, bool give, const std::set<ui32> &spells)=0; virtual void changeSpells(int hid, bool give, const std::set<ui32> &spells)=0;
@ -62,5 +63,6 @@ public:
virtual void giveHeroBonus(GiveBonus * bonus)=0; virtual void giveHeroBonus(GiveBonus * bonus)=0;
virtual void setMovePoints(SetMovePoints * smp)=0; virtual void setMovePoints(SetMovePoints * smp)=0;
virtual void setManaPoints(int hid, int val)=0; virtual void setManaPoints(int hid, int val)=0;
virtual void giveHero(int id, int player)=0;
}; };
#endif // __IGAMECALLBACK_H__ #endif // __IGAMECALLBACK_H__

View File

@ -311,6 +311,19 @@ struct HeroRecruited : public CPack<HeroRecruited> //515
h & hid & tid & tile & player; h & hid & tid & tile & player;
} }
}; };
struct GiveHero : public CPack<GiveHero> //516
{
GiveHero(){type = 516;};
ui32 id; //object id
ui8 player;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & id & player;
}
};
struct NewTurn : public CPack<NewTurn> //101 struct NewTurn : public CPack<NewTurn> //101
{ {
struct Hero struct Hero
@ -376,7 +389,7 @@ struct InfoWindow : public CPack<InfoWindow> //103 - displays simple info windo
struct SetObjectProperty : public CPack<SetObjectProperty>//1001 struct SetObjectProperty : public CPack<SetObjectProperty>//1001
{ {
ui32 id; ui32 id;
ui8 what; //1 - owner; 2 - blockvis ui8 what; //1 - owner; 2 - blockvis; 3 - first stack count; 4 - visitors; 5 - visited; 6 - ID (if 34 then also def is replaced)
ui32 val; ui32 val;
SetObjectProperty(){type = 1001;}; SetObjectProperty(){type = 1001;};
SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;}; SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;};

View File

@ -477,7 +477,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
} }
tlog0<<"\tCalculating blocked/visitable tiles: "<<th.getDif()<<std::endl; tlog0<<"\tCalculating blocked/visitable tiles: "<<th.getDif()<<std::endl;
} }
void Mapa::removeBlockVisTiles(CGObjectInstance * obj) void Mapa::removeBlockVisTiles(CGObjectInstance * obj, bool total)
{ {
for(int fx=0; fx<8; ++fx) for(int fx=0; fx<8; ++fx)
{ {
@ -489,12 +489,12 @@ void Mapa::removeBlockVisTiles(CGObjectInstance * obj)
if(xVal>=0 && xVal<width && yVal>=0 && yVal<height) if(xVal>=0 && xVal<width && yVal>=0 && yVal<height)
{ {
TerrainTile & curt = terrain[xVal][yVal][zVal]; TerrainTile & curt = terrain[xVal][yVal][zVal];
if(((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1)) if(total || ((obj->defInfo->visitMap[fy] >> (7 - fx)) & 1))
{ {
curt.visitableObjects -= obj; curt.visitableObjects -= obj;
curt.visitable = curt.visitableObjects.size(); curt.visitable = curt.visitableObjects.size();
} }
if(!((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1)) if(total || !((obj->defInfo->blockMap[fy] >> (7 - fx)) & 1))
{ {
curt.blockingObjects -= obj; curt.blockingObjects -= obj;
curt.blocked = curt.blockingObjects.size(); curt.blocked = curt.blockingObjects.size();

2
map.h
View File

@ -322,7 +322,7 @@ struct DLL_EXPORT Mapa : public CMapHeader
void addBlockVisTiles(CGObjectInstance * obj); void addBlockVisTiles(CGObjectInstance * obj);
void removeBlockVisTiles(CGObjectInstance * obj); void removeBlockVisTiles(CGObjectInstance * obj, bool total=false);
Mapa(std::string filename); //creates map structure from .h3m file Mapa(std::string filename); //creates map structure from .h3m file
Mapa(); Mapa();
~Mapa(); ~Mapa();

View File

@ -2314,4 +2314,12 @@ void CGameHandler::setManaPoints( int hid, int val )
sm.hid = hid; sm.hid = hid;
sm.val = val; sm.val = val;
sendAndApply(&sm); sendAndApply(&sm);
}
void CGameHandler::giveHero( int id, int player )
{
GiveHero gh;
gh.id = id;
gh.player = player;
sendAndApply(&gh);
} }

View File

@ -106,6 +106,7 @@ public:
void giveHeroBonus(GiveBonus * bonus); void giveHeroBonus(GiveBonus * bonus);
void setMovePoints(SetMovePoints * smp); void setMovePoints(SetMovePoints * smp);
void setManaPoints(int hid, int val); void setManaPoints(int hid, int val);
void giveHero(int id, int player);
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
void init(StartInfo *si, int Seed); void init(StartInfo *si, int Seed);