mirror of
https://github.com/vcmi/vcmi.git
synced 2025-01-12 02:28:11 +02:00
* restored objects functionalities (hopefully working)
* new file in vcmi lib: IGameCallback.cpp
This commit is contained in:
parent
d0d60175d7
commit
4a8ae4ed9a
@ -23,7 +23,6 @@ public:
|
||||
std::map<int,SDL_Color> colors;
|
||||
std::map<int,SDL_Color> colorsBlocked;
|
||||
std::vector<SDL_Surface *> map, FoW; //one bitmap for each level (terrain, Fog of War)
|
||||
//TODO flagged buildings
|
||||
std::string statusbarTxt, rcText;
|
||||
|
||||
CMinimap(bool draw=true);
|
||||
|
@ -648,7 +648,10 @@ void CCallback::setFormation(const CGHeroInstance * hero, bool tight)
|
||||
|
||||
void CCallback::setSelection(const CArmedInstance * obj)
|
||||
{
|
||||
*cl->serv << ui16(514) << obj->id;
|
||||
SetSelection ss;
|
||||
ss.player = player;
|
||||
ss.id = obj->id;
|
||||
*cl->serv << ui16(514) << ss;
|
||||
}
|
||||
|
||||
void CCallback::recruitHero(const CGTownInstance *town, const CGHeroInstance *hero)
|
||||
|
126
CGameState.cpp
126
CGameState.cpp
@ -6,6 +6,7 @@
|
||||
#include <boost/random/linear_congruential.hpp>
|
||||
#include "hch/CDefObjInfoHandler.h"
|
||||
#include "hch/CArtHandler.h"
|
||||
#include "hch/CGeneralTextHandler.h"
|
||||
#include "hch/CTownHandler.h"
|
||||
#include "hch/CSpellHandler.h"
|
||||
#include "hch/CHeroHandler.h"
|
||||
@ -28,6 +29,79 @@ boost::rand48 ran;
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
std::string DLL_EXPORT toString(MetaString &ms)
|
||||
{
|
||||
std::string ret;
|
||||
for(size_t i=0;i<ms.message.size();++i)
|
||||
{
|
||||
if(ms.message[i]>0)
|
||||
{
|
||||
ret += ms.strings[ms.message[i]-1];
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<std::string> *vec;
|
||||
int type = ms.texts[-ms.message[i]-1].first,
|
||||
ser = ms.texts[-ms.message[i]-1].second;
|
||||
if(type == 5)
|
||||
{
|
||||
ret += VLC->arth->artifacts[ser].Name();
|
||||
continue;
|
||||
}
|
||||
else if(type == 7)
|
||||
{
|
||||
ret += VLC->creh->creatures[ser].namePl;
|
||||
continue;
|
||||
}
|
||||
else if(type == 9)
|
||||
{
|
||||
ret += VLC->objh->mines[ser].first;
|
||||
continue;
|
||||
}
|
||||
else if(type == 10)
|
||||
{
|
||||
ret += VLC->objh->mines[ser].second;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case 1:
|
||||
vec = &VLC->generaltexth->allTexts;
|
||||
break;
|
||||
case 2:
|
||||
vec = &VLC->objh->xtrainfo;
|
||||
break;
|
||||
case 3:
|
||||
vec = &VLC->objh->names;
|
||||
break;
|
||||
case 4:
|
||||
vec = &VLC->objh->restypes;
|
||||
break;
|
||||
case 6:
|
||||
vec = &VLC->generaltexth->arraytxt;
|
||||
break;
|
||||
case 8:
|
||||
vec = &VLC->objh->creGens;
|
||||
break;
|
||||
case 11:
|
||||
vec = &VLC->objh->advobtxt;
|
||||
break;
|
||||
case 12:
|
||||
vec = &VLC->generaltexth->artifEvents;
|
||||
break;
|
||||
}
|
||||
ret += (*vec)[ser];
|
||||
}
|
||||
}
|
||||
}
|
||||
for(size_t i=0; i < ms.replacements.size(); ++i)
|
||||
{
|
||||
ret.replace(ret.find("%s"),2,ms.replacements[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
CGObjectInstance * createObject(int id, int subid, int3 pos, int owner)
|
||||
{
|
||||
@ -624,6 +698,12 @@ void CGameState::applyNL(IPack * pack)
|
||||
h->artifWorn = sha->artifWorn;
|
||||
break;
|
||||
}
|
||||
case 514:
|
||||
{
|
||||
SetSelection *ss = static_cast<SetSelection*>(pack);
|
||||
players[ss->player].currentSelection = ss->id;
|
||||
break;
|
||||
}
|
||||
case 515:
|
||||
{
|
||||
HeroRecruited *sha = static_cast<HeroRecruited*>(pack);
|
||||
@ -652,23 +732,13 @@ void CGameState::applyNL(IPack * pack)
|
||||
case 1001://set object property
|
||||
{
|
||||
SetObjectProperty *p = static_cast<SetObjectProperty*>(pack);
|
||||
if(p->what == 3) //set creatures amount
|
||||
{
|
||||
tlog5 << "Setting creatures amount in " << p->id << std::endl;
|
||||
static_cast<CGCreature*>(map->objects[p->id])->army.slots[0].second = p->val;
|
||||
setObjProperty(p);
|
||||
break;
|
||||
}
|
||||
ui8 CGObjectInstance::*point;
|
||||
switch(p->what)
|
||||
case 1002:
|
||||
{
|
||||
case 1:
|
||||
point = &CGObjectInstance::tempOwner;
|
||||
break;
|
||||
case 2:
|
||||
point = &CGObjectInstance::blockVisit;
|
||||
break;
|
||||
}
|
||||
map->objects[p->id]->*point = p->val;
|
||||
SetHoverName *shn = static_cast<SetHoverName*>(pack);
|
||||
map->objects[shn->id]->hoverName = toString(shn->name);
|
||||
break;
|
||||
}
|
||||
case 2000:
|
||||
@ -1381,6 +1451,9 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int i=0; i<map->objects.size(); i++)
|
||||
map->objects[i]->initObj();
|
||||
}
|
||||
|
||||
bool CGameState::battleShootCreatureStack(int ID, int dest)
|
||||
@ -1498,6 +1571,31 @@ void CGameState::loadTownDInfos()
|
||||
capitols[i] = new CGDefInfo(*VLC->dobjinfo->castles[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void CGameState::setObjProperty( SetObjectProperty * p )
|
||||
{
|
||||
CGObjectInstance *obj = map->objects[p->id];
|
||||
|
||||
switch(p->what)
|
||||
{
|
||||
case 1:
|
||||
obj->tempOwner = p->val;
|
||||
break;
|
||||
case 2:
|
||||
obj->blockVisit = p->val;
|
||||
break;
|
||||
case 3:
|
||||
static_cast<CArmedInstance*>(obj)->army.slots[0].second = p->val;
|
||||
break;
|
||||
case 4:
|
||||
static_cast<CGVisitableOPH*>(obj)->visitors.insert(p->val);
|
||||
break;
|
||||
case 5:
|
||||
static_cast<CGVisitableOPW*>(obj)->visited = p->val;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int BattleInfo::calculateDmg(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting)
|
||||
{
|
||||
int attackerAttackBonus = attacker->creature->attack + (attackerHero ? attackerHero->getPrimSkillLevel(0) : 0);
|
||||
|
10
CGameState.h
10
CGameState.h
@ -33,6 +33,12 @@ struct SDL_Surface;
|
||||
class CMapHandler;
|
||||
class CPathfinder;
|
||||
struct IPack;
|
||||
struct SetObjectProperty;
|
||||
struct MetaString;
|
||||
|
||||
|
||||
std::string DLL_EXPORT toString(MetaString &ms);
|
||||
|
||||
|
||||
namespace boost
|
||||
{
|
||||
@ -181,6 +187,8 @@ private:
|
||||
void init(StartInfo * si, Mapa * map, int Seed);
|
||||
void loadTownDInfos();
|
||||
void applyNL(IPack * pack);
|
||||
|
||||
void setObjProperty( SetObjectProperty * p );
|
||||
void apply(IPack * pack);
|
||||
void randomizeObject(CGObjectInstance *cur);
|
||||
std::pair<int,int> pickObject(CGObjectInstance *obj);
|
||||
@ -213,7 +221,7 @@ public:
|
||||
friend class CLuaCallback;
|
||||
friend class CClient;
|
||||
friend void initGameState(Mapa * map, CGameInfo * cgi);
|
||||
friend class CScriptCallback;
|
||||
friend class IGameCallback;
|
||||
friend class CMapHandler;
|
||||
friend class CGameHandler;
|
||||
};
|
||||
|
@ -1076,6 +1076,8 @@ void CPlayerInterface::yourTurn()
|
||||
|
||||
adventureInt->infoBar.newDay(cb->getDate(1));
|
||||
|
||||
//select first hero if available.
|
||||
//TODO: check if hero is slept
|
||||
if(adventureInt->heroList.items.size())
|
||||
adventureInt->select(adventureInt->heroList.items[0].first);
|
||||
else
|
||||
@ -1193,7 +1195,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
|
||||
if(adventureInt == curint)
|
||||
adventureInt->minimap.draw();
|
||||
|
||||
if(details.style)
|
||||
if(details.style>0)
|
||||
return;
|
||||
|
||||
//initializing objects and performing first step of move
|
||||
|
20
ChangeLog
20
ChangeLog
@ -1,12 +1,14 @@
|
||||
0.64 -> 0.next (???) [as for r651]
|
||||
0.64 -> 0.next (???) [as for r672]
|
||||
GENERAL:
|
||||
* move some settings to the config/settings.txt file
|
||||
* partial support for new screen resolutions
|
||||
* /Data and /Sprites subfolders can be used for adding files not present in .lod archives
|
||||
* fixed crashbug occuring when hero levelled above 15 level
|
||||
* support for non-standard screen resolutions
|
||||
|
||||
ADVENTURE INTERFACE:
|
||||
* added water animation
|
||||
* speed of scrolling map and hero movement can be adjusted in the System Options Window
|
||||
|
||||
TOWN INTERFACE:
|
||||
* the scroll tab won't remain hanged to our mouse position if we move the mouse away from the scroll bar
|
||||
@ -18,6 +20,9 @@ BATTLES
|
||||
* war machines support partially added
|
||||
* queue of stacks narrowed
|
||||
* spell effect animation displaying improvements
|
||||
* positive/negative spells cannot be cast on hostile/our stacks
|
||||
* showing spell effects affecting stack in creature info window
|
||||
* more appropriate coloring of stack amount box when stack is affected by a spell
|
||||
* several reported bugs fixed
|
||||
* new spells supported:
|
||||
a) Haste
|
||||
@ -26,12 +31,19 @@ BATTLES
|
||||
d) slow
|
||||
e) implosion
|
||||
f) forgetfulness
|
||||
g) shield
|
||||
h) air shield
|
||||
i) bless
|
||||
j) curse
|
||||
k) bloodlust
|
||||
l) weakness
|
||||
m) stone skin
|
||||
n) prayer
|
||||
o) frenzy
|
||||
|
||||
AI:
|
||||
AI PLAYER:
|
||||
* Genius AI (first VCMI AI) will control computer creatures during the combat.
|
||||
|
||||
GENERAL:
|
||||
* started making external settings file (will be used for support for non 800x600 screen resolutions)
|
||||
And a lot of minor fixes
|
||||
|
||||
0.63 -> 0.64 (Nov 01 2008)
|
||||
|
@ -18,82 +18,9 @@
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
#include <sstream>
|
||||
CSharedCond<std::set<IPack*> > mess(new std::set<IPack*>);
|
||||
|
||||
std::string toString(MetaString &ms)
|
||||
{
|
||||
std::string ret;
|
||||
for(size_t i=0;i<ms.message.size();++i)
|
||||
{
|
||||
if(ms.message[i]>0)
|
||||
{
|
||||
ret += ms.strings[ms.message[i]-1];
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<std::string> *vec;
|
||||
int type = ms.texts[-ms.message[i]-1].first,
|
||||
ser = ms.texts[-ms.message[i]-1].second;
|
||||
if(type == 5)
|
||||
{
|
||||
ret += CGI->arth->artifacts[ser].Name();
|
||||
continue;
|
||||
}
|
||||
else if(type == 7)
|
||||
{
|
||||
ret += CGI->creh->creatures[ser].namePl;
|
||||
continue;
|
||||
}
|
||||
else if(type == 9)
|
||||
{
|
||||
ret += CGI->objh->mines[ser].first;
|
||||
continue;
|
||||
}
|
||||
else if(type == 10)
|
||||
{
|
||||
ret += CGI->objh->mines[ser].second;
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case 1:
|
||||
vec = &CGI->generaltexth->allTexts;
|
||||
break;
|
||||
case 2:
|
||||
vec = &CGI->objh->xtrainfo;
|
||||
break;
|
||||
case 3:
|
||||
vec = &CGI->objh->names;
|
||||
break;
|
||||
case 4:
|
||||
vec = &CGI->objh->restypes;
|
||||
break;
|
||||
case 6:
|
||||
vec = &CGI->generaltexth->arraytxt;
|
||||
break;
|
||||
case 8:
|
||||
vec = &CGI->objh->creGens;
|
||||
break;
|
||||
case 11:
|
||||
vec = &CGI->objh->advobtxt;
|
||||
break;
|
||||
case 12:
|
||||
vec = &CGI->generaltexth->artifEvents;
|
||||
break;
|
||||
}
|
||||
ret += (*vec)[ser];
|
||||
}
|
||||
}
|
||||
}
|
||||
for(size_t i=0; i < ms.replacements.size(); ++i)
|
||||
{
|
||||
ret.replace(ret.find("%s"),2,ms.replacements[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
CClient::CClient(void)
|
||||
{
|
||||
}
|
||||
@ -101,6 +28,7 @@ CClient::CClient(CConnection *con, StartInfo *si)
|
||||
:serv(con)
|
||||
{
|
||||
timeHandler tmh;
|
||||
IObjectInterface::cb = this;
|
||||
CGI->state = new CGameState();
|
||||
tlog0 <<"\tGamestate: "<<tmh.getDif()<<std::endl;
|
||||
CConnection &c(*con);
|
||||
@ -449,6 +377,14 @@ void CClient::process(int what)
|
||||
tlog4 << "Player "<<(int)color<<" sends a message: " << message << std::endl;
|
||||
break;
|
||||
}
|
||||
case 514:
|
||||
{
|
||||
SetSelection ss;
|
||||
*serv >> ss;
|
||||
tlog5 << "Selection of player " << (int)ss.player << " set to " << ss.id << std::endl;
|
||||
gs->apply(&ss);
|
||||
break;
|
||||
}
|
||||
case 515:
|
||||
{
|
||||
HeroRecruited hr;
|
||||
@ -475,9 +411,7 @@ void CClient::process(int what)
|
||||
SetHoverName shn;
|
||||
*serv >> shn;
|
||||
tlog5 << "Setting a name of " << shn.id <<" object to "<< toString(shn.name) <<std::endl;
|
||||
gs->mx->lock();
|
||||
//gs->map->objects[shn.id]->hoverName = toString(shn.name);
|
||||
gs->mx->unlock();
|
||||
gs->apply(&shn);
|
||||
break;
|
||||
}
|
||||
case 2000:
|
||||
@ -668,8 +602,11 @@ void CClient::process(int what)
|
||||
case 9999:
|
||||
break;
|
||||
default:
|
||||
throw std::string("Not supported server message!");
|
||||
break;
|
||||
{
|
||||
std::ostringstream ex;
|
||||
ex << "Not supported server message (type=" << what <<")";
|
||||
throw ex.str();
|
||||
}
|
||||
}
|
||||
}
|
||||
void CClient::waitForMoveAndSend(int color)
|
||||
@ -709,3 +646,13 @@ void CClient::save(const std::string & fname)
|
||||
{
|
||||
*serv << ui16(98) << fname;
|
||||
}
|
||||
|
||||
int CClient::getCurrentPlayer()
|
||||
{
|
||||
return gs->currentPlayer;
|
||||
}
|
||||
|
||||
int CClient::getSelectedHero()
|
||||
{
|
||||
return IGameCallback::getSelectedHero(getCurrentPlayer())->id;
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include "../global.h"
|
||||
#include <boost/thread.hpp>
|
||||
#include "../lib/IGameCallback.h"
|
||||
struct StartInfo;
|
||||
class CGameState;
|
||||
class CGameInterface;
|
||||
@ -37,10 +38,9 @@ struct CSharedCond
|
||||
}
|
||||
};
|
||||
|
||||
class CClient
|
||||
class CClient : public IGameCallback
|
||||
{
|
||||
CCallback *cb;
|
||||
CGameState *gs;
|
||||
std::map<ui8,CGameInterface *> playerint;
|
||||
CConnection *serv;
|
||||
|
||||
@ -54,9 +54,33 @@ public:
|
||||
void save(const std::string & fname);
|
||||
void process(int what);
|
||||
void run();
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//from IGameCallback
|
||||
int getCurrentPlayer();
|
||||
int getSelectedHero();
|
||||
|
||||
//not working yet, will be implement somewhen later with support for local-sim-based gameplay
|
||||
void changeSpells(int hid, bool give, const std::set<ui32> &spells){};
|
||||
void removeObject(int objid){};
|
||||
void setBlockVis(int objid, bool bv){};
|
||||
void setOwner(int objid, ui8 owner){};
|
||||
void setHoverName(int objid, MetaString * name){};
|
||||
void setObjProperty(int objid, int prop, int val){};
|
||||
void changePrimSkill(int ID, int which, int val, bool abs=false){};
|
||||
void showInfoDialog(InfoWindow *iw){};
|
||||
void showYesNoDialog(YesNoDialog *iw, const CFunctionList<void(ui32)> &callback){};
|
||||
void showSelectionDialog(SelectionDialog *iw, const CFunctionList<void(ui32)> &callback){}; //returns question id
|
||||
void giveResource(int player, int which, int val){};
|
||||
void showCompInfo(ShowInInfobox * comp){};
|
||||
void heroVisitCastle(int obj, int heroID){};
|
||||
void stopHeroVisitCastle(int obj, int heroID){};
|
||||
void giveHeroArtifact(int artid, int hid, int position){}; //pos==-1 - first free slot in backpack=0; pos==-2 - default if available or backpack
|
||||
void startBattleI(const CCreatureSet * army1, const CCreatureSet * army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, boost::function<void(BattleResult*)> cb){}; //use hero=NULL for no hero
|
||||
void startBattleI(int heroID, CCreatureSet army, int3 tile, boost::function<void(BattleResult*)> cb){}; //for hero<=>neutral army
|
||||
void setAmount(int objid, ui32 val){};
|
||||
void moveHero(int hid, int3 pos, bool instant){};
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
friend class CCallback; //handling players actions
|
||||
friend class CScriptCallback; //for objects scripts
|
||||
friend void processCommand(const std::string &message, CClient *&client); //handling console
|
||||
};
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
clientSettings
|
||||
{
|
||||
port=3030;
|
||||
resolution=800x600; // format: WxH
|
||||
resolution=1024x768; // format: WxH
|
||||
bpp=24; // bpp!=24 => problems
|
||||
fullscreen=0; //0 - windowed mode, 1 - fullscreen
|
||||
server=127.0.0.1; //use 127.0.0.1 for localhost
|
||||
|
@ -17,19 +17,20 @@
|
||||
#include "../CGameState.h"
|
||||
#include "../lib/NetPacks.h"
|
||||
|
||||
std::map<int,std::map<int, std::vector<int> > > CGTeleport::objs;
|
||||
IGameCallback * IObjectInterface::cb = NULL;
|
||||
DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
|
||||
extern CLodHandler * bitmaph;
|
||||
extern boost::rand48 ran;
|
||||
|
||||
|
||||
void IObjectInterface::onHeroVisit(const CGHeroInstance * h)
|
||||
void IObjectInterface::onHeroVisit(const CGHeroInstance * h) const
|
||||
{};
|
||||
|
||||
void IObjectInterface::onHeroLeave(const CGHeroInstance * h)
|
||||
void IObjectInterface::onHeroLeave(const CGHeroInstance * h) const
|
||||
{};
|
||||
|
||||
void IObjectInterface::newTurn ()
|
||||
void IObjectInterface::newTurn () const
|
||||
{};
|
||||
|
||||
IObjectInterface::~IObjectInterface()
|
||||
@ -645,7 +646,7 @@ bool CGHeroInstance::needsLastStack() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
void CGHeroInstance::onHeroVisit(const CGHeroInstance * h)
|
||||
void CGHeroInstance::onHeroVisit(const CGHeroInstance * h) const
|
||||
{
|
||||
//TODO: check for allies
|
||||
if(tempOwner == h->tempOwner) //our hero
|
||||
@ -673,7 +674,7 @@ const std::string & CGHeroInstance::getBiography() const
|
||||
}
|
||||
void CGHeroInstance::initObj()
|
||||
{
|
||||
cb->setBlockVis(id,true);
|
||||
blockVisit = true;
|
||||
}
|
||||
int CGTownInstance::getSightDistance() const //returns sight distance
|
||||
{
|
||||
@ -795,7 +796,7 @@ bool CGTownInstance::needsLastStack() const
|
||||
else return false;
|
||||
}
|
||||
|
||||
void CGTownInstance::onHeroVisit(const CGHeroInstance * h)
|
||||
void CGTownInstance::onHeroVisit(const CGHeroInstance * h) const
|
||||
{
|
||||
if(getOwner() != h->getOwner())
|
||||
{
|
||||
@ -804,7 +805,7 @@ void CGTownInstance::onHeroVisit(const CGHeroInstance * h)
|
||||
cb->heroVisitCastle(id,h->id);
|
||||
}
|
||||
|
||||
void CGTownInstance::onHeroLeave(const CGHeroInstance * h)
|
||||
void CGTownInstance::onHeroLeave(const CGHeroInstance * h) const
|
||||
{
|
||||
cb->stopHeroVisitCastle(id,h->id);
|
||||
}
|
||||
@ -813,28 +814,16 @@ void CGTownInstance::initObj()
|
||||
{
|
||||
MetaString ms;
|
||||
ms << name << ", " << town->Name();
|
||||
cb->setHoverName(id,&ms);
|
||||
hoverName = toString(ms);
|
||||
}
|
||||
|
||||
//std::vector<int> CVisitableOPH::yourObjects()
|
||||
//{
|
||||
// std::vector<int> ret;
|
||||
// ret.push_back(51);//camp
|
||||
// ret.push_back(23);//tower
|
||||
// ret.push_back(61);//axis
|
||||
// ret.push_back(32);//garden
|
||||
// ret.push_back(100);//stone
|
||||
// ret.push_back(102);//tree
|
||||
// return ret;
|
||||
//}
|
||||
|
||||
void CGVisitableOPH::onHeroVisit( const CGHeroInstance * h )
|
||||
void CGVisitableOPH::onHeroVisit( const CGHeroInstance * h ) const
|
||||
{
|
||||
if(visitors.find(h->id)==visitors.end())
|
||||
{
|
||||
onNAHeroVisit(h->id, false);
|
||||
if(ID != 102) //not tree
|
||||
visitors.insert(h->id);
|
||||
cb->setObjProperty(id,4,h->id); //add to the visitors
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -850,16 +839,16 @@ void CGVisitableOPH::initObj()
|
||||
ttype = -1;
|
||||
}
|
||||
|
||||
void CGVisitableOPH::treeSelected( int heroID, int resType, int resVal, int expVal, ui32 result )
|
||||
void CGVisitableOPH::treeSelected( int heroID, int resType, int resVal, int expVal, ui32 result ) const
|
||||
{
|
||||
if(result==0) //player agreed to give res for exp
|
||||
{
|
||||
cb->giveResource(cb->getOwner(heroID),resType,-resVal); //take resource
|
||||
cb->changePrimSkill(heroID,4,expVal); //give exp
|
||||
visitors.insert(heroID); //set state to visited
|
||||
cb->setObjProperty(id,4,heroID); //add to the visitors
|
||||
}
|
||||
}
|
||||
void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited)
|
||||
void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited) const
|
||||
{
|
||||
int id=0, subid=0, ot=0, val=1;
|
||||
switch(ID)
|
||||
@ -925,7 +914,7 @@ void CGVisitableOPH::onNAHeroVisit(int heroID, bool alreadyVisited)
|
||||
val = VLC->heroh->reqExp(h->level+val) - VLC->heroh->reqExp(h->level);
|
||||
if(!ttype)
|
||||
{
|
||||
visitors.insert(heroID);
|
||||
cb->setObjProperty(id,4,heroID); //add to the visitors
|
||||
InfoWindow iw;
|
||||
iw.components.push_back(Component(id,subid,1,0));
|
||||
iw.player = cb->getOwner(heroID);
|
||||
@ -1010,9 +999,10 @@ const std::string & CGVisitableOPH::getHoverText() const
|
||||
const CGHeroInstance *h = cb->getSelectedHero(cb->getCurrentPlayer());
|
||||
if(h)
|
||||
{
|
||||
hoverName += ' ';
|
||||
hoverName += (vstd::contains(visitors,h->id))
|
||||
? (VLC->generaltexth->allTexts[353]) //not visited
|
||||
: ( VLC->generaltexth->allTexts[352]); //visited
|
||||
? (VLC->generaltexth->allTexts[352]) //visited
|
||||
: ( VLC->generaltexth->allTexts[353]); //not visited
|
||||
}
|
||||
return hoverName;
|
||||
}
|
||||
@ -1022,13 +1012,12 @@ bool CArmedInstance::needsLastStack() const
|
||||
return false;
|
||||
}
|
||||
|
||||
void CGCreature::onHeroVisit( const CGHeroInstance * h )
|
||||
void CGCreature::onHeroVisit( const CGHeroInstance * h ) const
|
||||
{
|
||||
army.slots[0].first = subID;
|
||||
cb->startBattleI(h->id,army,pos,boost::bind(&CGCreature::endBattle,this,_1));
|
||||
}
|
||||
|
||||
void CGCreature::endBattle( BattleResult *result )
|
||||
void CGCreature::endBattle( BattleResult *result ) const
|
||||
{
|
||||
if(result->winner==0)
|
||||
{
|
||||
@ -1040,12 +1029,19 @@ void CGCreature::endBattle( BattleResult *result )
|
||||
for(std::set<std::pair<ui32,si32> >::iterator i=result->casualties[1].begin(); i!=result->casualties[1].end(); i++)
|
||||
if(i->first == subID)
|
||||
killedAmount += i->second;
|
||||
cb->setAmount(id, army.slots[0].second - killedAmount);
|
||||
cb->setAmount(id, army.slots.find(0)->second.second - killedAmount);
|
||||
|
||||
MetaString ms;
|
||||
int pom = CCreature::getQuantityID(army.slots.find(0)->second.second);
|
||||
pom = 174 + 3*pom + 1;
|
||||
ms << std::pair<ui8,ui32>(6,pom) << " " << std::pair<ui8,ui32>(7,subID);
|
||||
cb->setHoverName(id,&ms);
|
||||
}
|
||||
}
|
||||
|
||||
void CGCreature::initObj()
|
||||
{
|
||||
army.slots[0].first = subID;
|
||||
si32 &amount = army.slots[0].second;
|
||||
CCreature &c = VLC->creh->creatures[subID];
|
||||
if(!amount)
|
||||
@ -1053,4 +1049,364 @@ void CGCreature::initObj()
|
||||
amount = c.ammMax;
|
||||
else
|
||||
amount = c.ammMin + (ran() % (c.ammMax - c.ammMin));
|
||||
|
||||
MetaString ms;
|
||||
int pom = CCreature::getQuantityID(army.slots.find(0)->second.second);
|
||||
pom = 174 + 3*pom + 1;
|
||||
ms << std::pair<ui8,ui32>(6,pom) << " " << std::pair<ui8,ui32>(7,subID);
|
||||
hoverName = toString(ms);
|
||||
}
|
||||
|
||||
void CGMine::onHeroVisit( const CGHeroInstance * h ) const
|
||||
{
|
||||
if(subID == 7) //TODO: support for abandoned mine
|
||||
return;
|
||||
|
||||
if(h->tempOwner == tempOwner) //we're visiting our mine
|
||||
return; //TODO: leaving garrison
|
||||
|
||||
//TODO: check if mine is guarded
|
||||
cb->setOwner(id,h->tempOwner); //not ours? flag it!
|
||||
|
||||
MetaString ms;
|
||||
ms << std::pair<ui8,ui32>(9,subID) << " (" << std::pair<ui8,ui32>(6,23+h->tempOwner) << ")";
|
||||
cb->setHoverName(id,&ms);
|
||||
|
||||
int vv=1; //amount of resource per turn
|
||||
if (subID==0 || subID==2)
|
||||
vv++;
|
||||
else if (subID==6)
|
||||
vv = 1000;
|
||||
|
||||
InfoWindow iw;
|
||||
iw.text << std::pair<ui8,ui32>(10,subID);
|
||||
iw.player = h->tempOwner;
|
||||
iw.components.push_back(Component(2,subID,vv,-1));
|
||||
cb->showInfoDialog(&iw);
|
||||
}
|
||||
|
||||
void CGMine::newTurn() const
|
||||
{
|
||||
if (tempOwner == NEUTRAL_PLAYER)
|
||||
return;
|
||||
int vv = 1;
|
||||
if (subID==0 || subID==2)
|
||||
vv++;
|
||||
else if (subID==6)
|
||||
vv = 1000;
|
||||
cb->giveResource(tempOwner,subID,vv);
|
||||
}
|
||||
|
||||
void CGMine::initObj()
|
||||
{
|
||||
MetaString ms;
|
||||
ms << std::pair<ui8,ui32>(9,subID);
|
||||
if(tempOwner >= PLAYER_LIMIT)
|
||||
tempOwner = NEUTRAL_PLAYER;
|
||||
else
|
||||
ms << " (" << std::pair<ui8,ui32>(6,23+tempOwner) << ")";
|
||||
hoverName = toString(ms);
|
||||
}
|
||||
|
||||
void CGResource::initObj()
|
||||
{
|
||||
blockVisit = true;
|
||||
hoverName = VLC->objh->restypes[subID];
|
||||
|
||||
if(!amount)
|
||||
{
|
||||
switch(subID)
|
||||
{
|
||||
case 6:
|
||||
amount = 500 + (rand()%6)*100;
|
||||
break;
|
||||
case 0: case 2:
|
||||
amount = 6 + (rand()%5);
|
||||
break;
|
||||
default:
|
||||
amount = 3 + (rand()%3);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CGResource::onHeroVisit( const CGHeroInstance * h ) const
|
||||
{
|
||||
//TODO: handle guards (when battles are finished)
|
||||
if(message.length())
|
||||
{
|
||||
InfoWindow iw;
|
||||
iw.player = h->tempOwner;
|
||||
iw.text << message;
|
||||
cb->showInfoDialog(&iw);
|
||||
}
|
||||
|
||||
cb->giveResource(h->tempOwner,subID,amount);
|
||||
|
||||
ShowInInfobox sii;
|
||||
sii.player = h->tempOwner;
|
||||
sii.c = Component(2,subID,amount,0);
|
||||
sii.text << std::pair<ui8,ui32>(11,113);
|
||||
sii.text.replacements.push_back(VLC->objh->restypes[subID]);
|
||||
cb->showCompInfo(&sii);
|
||||
cb->removeObject(id);
|
||||
}
|
||||
|
||||
void CGVisitableOPW::newTurn() const
|
||||
{
|
||||
if (cb->getDate(1)==1) //first day of week
|
||||
{
|
||||
cb->setObjProperty(id,5,false);
|
||||
MetaString ms; //set text to "not visited"
|
||||
ms << std::pair<ui8,ui32>(3,ID) << " " << std::pair<ui8,ui32>(1,353);
|
||||
cb->setHoverName(id,&ms);
|
||||
}
|
||||
}
|
||||
|
||||
void CGVisitableOPW::onHeroVisit( const CGHeroInstance * h ) const
|
||||
{
|
||||
int mid;
|
||||
switch (ID)
|
||||
{
|
||||
case 55:
|
||||
mid = 92;
|
||||
break;
|
||||
case 112:
|
||||
mid = 170;
|
||||
break;
|
||||
case 109:
|
||||
mid = 164;
|
||||
break;
|
||||
}
|
||||
if (visited)
|
||||
{
|
||||
if (ID!=112)
|
||||
mid++;
|
||||
else
|
||||
mid--;
|
||||
|
||||
InfoWindow iw;
|
||||
iw.player = h->tempOwner;
|
||||
iw.text << std::pair<ui8,ui32>(11,mid);
|
||||
cb->showInfoDialog(&iw);
|
||||
}
|
||||
else
|
||||
{
|
||||
int type, sub, val;
|
||||
type = 2;
|
||||
switch (ID)
|
||||
{
|
||||
case 55:
|
||||
if (rand()%2)
|
||||
{
|
||||
sub = 5;
|
||||
val = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
sub = 6;
|
||||
val = 500;
|
||||
}
|
||||
break;
|
||||
case 112:
|
||||
mid = 170;
|
||||
sub = (rand() % 5) + 1;
|
||||
val = (rand() % 4) + 3;
|
||||
break;
|
||||
case 109:
|
||||
mid = 164;
|
||||
sub = 6;
|
||||
if(cb->getDate(2)<2)
|
||||
val = 500;
|
||||
else
|
||||
val = 1000;
|
||||
}
|
||||
cb->giveResource(h->tempOwner,sub,val);
|
||||
InfoWindow iw;
|
||||
iw.player = h->tempOwner;
|
||||
iw.components.push_back(Component(type,sub,val,0));
|
||||
iw.text << std::pair<ui8,ui32>(11,mid);
|
||||
cb->showInfoDialog(&iw);
|
||||
cb->setObjProperty(id,5,true);
|
||||
MetaString ms; //set text to "visited"
|
||||
ms << std::pair<ui8,ui32>(3,ID) << " " << std::pair<ui8,ui32>(1,352);
|
||||
cb->setHoverName(id,&ms);
|
||||
}
|
||||
}
|
||||
|
||||
void CGTeleport::onHeroVisit( const CGHeroInstance * h ) const
|
||||
{
|
||||
int destinationid=-1;
|
||||
switch(ID)
|
||||
{
|
||||
case 43: //one way - find correspong exit monolith
|
||||
if(vstd::contains(objs,44) && vstd::contains(objs[44],subID) && objs[44][subID].size())
|
||||
destinationid = objs[44][subID][rand()%objs[44][subID].size()];
|
||||
else
|
||||
tlog2 << "Cannot find corresponding exit monolith for "<< id << std::endl;
|
||||
break;
|
||||
case 45: //two way monolith - pick any other one
|
||||
if(vstd::contains(objs,45) && vstd::contains(objs[45],subID) && objs[45][subID].size()>1)
|
||||
while ((destinationid = objs[45][subID][rand()%objs[45][subID].size()])==id);
|
||||
else
|
||||
tlog2 << "Cannot find corresponding exit monolith for "<< id << std::endl;
|
||||
break;
|
||||
case 103: //find nearest subterranean gate on the other level
|
||||
{
|
||||
std::pair<int,double> best(-1,150000); //pair<id,dist>
|
||||
for(int i=0; i<objs[103][0].size(); i++)
|
||||
{
|
||||
if(cb->getObj(objs[103][0][i])->pos.z == pos.z) continue; //gates on our level are not interesting
|
||||
double hlp = cb->getObj(objs[103][0][i])->pos.dist2d(pos);
|
||||
if(hlp<best.second)
|
||||
{
|
||||
best.first = objs[103][0][i];
|
||||
best.second = hlp;
|
||||
}
|
||||
}
|
||||
if(best.first<0)
|
||||
return;
|
||||
else
|
||||
destinationid = best.first;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(destinationid < 0)
|
||||
{
|
||||
tlog2 << "Cannot find exit... :( \n";
|
||||
return;
|
||||
}
|
||||
cb->moveHero(h->id,
|
||||
(ID!=103)
|
||||
? (CGHeroInstance::convertPosition(cb->getObj(destinationid)->pos,true))
|
||||
: (cb->getObj(destinationid)->pos),
|
||||
true);
|
||||
}
|
||||
|
||||
void CGTeleport::initObj()
|
||||
{
|
||||
objs[ID][subID].push_back(id);
|
||||
}
|
||||
|
||||
void CGArtifact::initObj()
|
||||
{
|
||||
blockVisit = true;
|
||||
if(ID == 5)
|
||||
hoverName = VLC->arth->artifacts[subID].Name();
|
||||
}
|
||||
|
||||
void CGArtifact::onHeroVisit( const CGHeroInstance * h ) const
|
||||
{
|
||||
cb->giveHeroArtifact(subID,h->id,-2);
|
||||
InfoWindow iw;
|
||||
iw.player = h->tempOwner;
|
||||
iw.components.push_back(Component(4,subID,0,0));
|
||||
iw.text << std::pair<ui8,ui32>(12,subID);
|
||||
cb->showInfoDialog(&iw);
|
||||
}
|
||||
|
||||
void CGPickable::initObj()
|
||||
{
|
||||
blockVisit = true;
|
||||
switch(ID)
|
||||
{
|
||||
case 12: //campfire
|
||||
val2 = (ran()%3) + 4; //4 - 6
|
||||
val1 = val2 * 100;
|
||||
type = ran()%6; //given resource
|
||||
break;
|
||||
case 101: //treasure chest
|
||||
{
|
||||
int hlp = ran()%100;
|
||||
if(hlp >= 95)
|
||||
{
|
||||
type = 1;
|
||||
val1 = VLC->arth->treasures[ran()%VLC->arth->treasures.size()]->id;
|
||||
return;
|
||||
}
|
||||
else if (hlp >= 65)
|
||||
{
|
||||
val1 = 2000;
|
||||
}
|
||||
else if(hlp >= 33)
|
||||
{
|
||||
val1 = 1500;
|
||||
}
|
||||
else
|
||||
{
|
||||
val1 = 1000;
|
||||
}
|
||||
|
||||
val2 = val1 - 500;
|
||||
type = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CGPickable::onHeroVisit( const CGHeroInstance * h ) const
|
||||
{
|
||||
|
||||
switch(ID)
|
||||
{
|
||||
case 12: //campfire
|
||||
{
|
||||
cb->giveResource(h->tempOwner,type,val2); //non-gold resource
|
||||
cb->giveResource(h->tempOwner,6,val1);//gold
|
||||
InfoWindow iw;
|
||||
iw.player = h->tempOwner;
|
||||
iw.components.push_back(Component(2,6,val1,0));
|
||||
iw.components.push_back(Component(2,type,val2,0));
|
||||
iw.text << std::pair<ui8,ui32>(11,23);
|
||||
cb->showInfoDialog(&iw);
|
||||
break;
|
||||
}
|
||||
case 101: //treasure chest
|
||||
{
|
||||
if (subID) //not OH3 treasure chest
|
||||
{
|
||||
tlog2 << "Not supported WoG treasure chest!\n";
|
||||
return;
|
||||
}
|
||||
|
||||
if(type) //there is an artifact
|
||||
{
|
||||
cb->giveHeroArtifact(val1,h->id,-2);
|
||||
InfoWindow iw;
|
||||
iw.player = h->tempOwner;
|
||||
iw.components.push_back(Component(4,val1,1,0));
|
||||
iw.text << std::pair<ui8,ui32>(11,145);
|
||||
iw.text.replacements.push_back(VLC->arth->artifacts[val1].Name());
|
||||
cb->showInfoDialog(&iw);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectionDialog sd;
|
||||
sd.player = h->tempOwner;
|
||||
sd.text << std::pair<ui8,ui32>(11,146);
|
||||
sd.components.push_back(Component(2,6,val1,0));
|
||||
sd.components.push_back(Component(5,0,val2,0));
|
||||
boost::function<void(ui32)> fun = boost::bind(&CGPickable::chosen,this,_1,h->id);
|
||||
cb->showSelectionDialog(&sd,fun);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
cb->removeObject(id);
|
||||
}
|
||||
|
||||
void CGPickable::chosen( int which, int heroID ) const
|
||||
{
|
||||
switch(which)
|
||||
{
|
||||
case 0: //player pick gold
|
||||
cb->giveResource(cb->getOwner(heroID),6,val1);
|
||||
break;
|
||||
case 1: //player pick exp
|
||||
cb->changePrimSkill(heroID, 4, val2);
|
||||
break;
|
||||
default:
|
||||
throw std::string("Unhandled treasure choice");
|
||||
}
|
||||
}
|
@ -44,6 +44,21 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class CQuest
|
||||
{
|
||||
public:
|
||||
ui8 missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain playe
|
||||
si32 lastDay; //after this day (first day is 0) mission cannot be completed; if -1 - no limit
|
||||
|
||||
ui32 m13489val;
|
||||
std::vector<ui32> m2stats;
|
||||
std::vector<ui16> m5arts; //artifacts id
|
||||
std::vector<std::pair<ui32, ui32> > m6creatures; //pair[cre id, cre count]
|
||||
std::vector<ui32> m7resources;
|
||||
|
||||
std::string firstVisitText, nextVisitText, completedText;
|
||||
};
|
||||
|
||||
class DLL_EXPORT IObjectInterface
|
||||
{
|
||||
public:
|
||||
@ -52,9 +67,9 @@ public:
|
||||
IObjectInterface();
|
||||
virtual ~IObjectInterface();
|
||||
|
||||
virtual void onHeroVisit(const CGHeroInstance * h);
|
||||
virtual void onHeroLeave(const CGHeroInstance * h);
|
||||
virtual void newTurn();
|
||||
virtual void onHeroVisit(const CGHeroInstance * h) const;
|
||||
virtual void onHeroLeave(const CGHeroInstance * h) const;
|
||||
virtual void newTurn() const;
|
||||
virtual void initObj();
|
||||
};
|
||||
|
||||
@ -167,7 +182,7 @@ public:
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void initObj();
|
||||
void onHeroVisit(const CGHeroInstance * h);
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGTownInstance : public CArmedInstance
|
||||
@ -215,8 +230,8 @@ public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h);
|
||||
void onHeroLeave(const CGHeroInstance * h);
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
void onHeroLeave(const CGHeroInstance * h) const;
|
||||
void initObj();
|
||||
};
|
||||
|
||||
@ -227,10 +242,10 @@ public:
|
||||
si8 ttype; //tree type - used only by trees of knowledge: 0 - give level for free; 1 - take 2000 gold; 2 - take 10 gems
|
||||
const std::string & getHoverText() const;
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h);
|
||||
void onNAHeroVisit(int heroID, bool alreadyVisited);
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
void onNAHeroVisit(int heroID, bool alreadyVisited) const;
|
||||
void initObj();
|
||||
void treeSelected(int heroID, int resType, int resVal, int expVal, ui32 result); //handle player's anwer to the Tree of Knowledge dialog
|
||||
void treeSelected(int heroID, int resType, int resVal, int expVal, ui32 result) const; //handle player's anwer to the Tree of Knowledge dialog
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGEvent : public CGObjectInstance //event objects
|
||||
@ -270,8 +285,8 @@ public:
|
||||
ui8 neverFlees; //if true, the troops will never flee
|
||||
ui8 notGrowingTeam; //if true, number of units won't grow
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h);
|
||||
void endBattle(BattleResult *result);
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
void endBattle(BattleResult *result) const;
|
||||
void initObj();
|
||||
};
|
||||
|
||||
@ -283,25 +298,9 @@ public:
|
||||
std::string message;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGSeerHut : public CGObjectInstance
|
||||
class DLL_EXPORT CGSeerHut : public CGObjectInstance, public CQuest
|
||||
{
|
||||
public:
|
||||
unsigned char missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain player
|
||||
bool isDayLimit; //if true, there is a day limit
|
||||
int lastDay; //after this day (first day is 0) mission cannot be completed
|
||||
int m1level; //for mission 1
|
||||
int m2attack, m2defence, m2power, m2knowledge;//for mission 2
|
||||
unsigned char m3bytes[4];//for mission 3
|
||||
unsigned char m4bytes[4];//for mission 4
|
||||
std::vector<int> m5arts;//for mission 5 - artifact ID
|
||||
std::vector<CCreature *> m6cre;//for mission 6
|
||||
std::vector<int> m6number;
|
||||
int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; //for mission 7
|
||||
int m8hero;//for mission 8 - hero ID
|
||||
int m9player; //for mission 9 - number; from 0 to 7
|
||||
|
||||
std::string firstVisitText, nextVisitText, completedText;
|
||||
|
||||
char rewardType; //type of reward: 0 - no reward; 1 - experience; 2 - mana points; 3 - morale bonus; 4 - luck bonus; 5 - resources; 6 - main ability bonus (attak, defence etd.); 7 - secondary ability gain; 8 - artifact; 9 - spell; 10 - creature
|
||||
//for reward 1
|
||||
int r1exp;
|
||||
@ -357,6 +356,8 @@ class DLL_EXPORT CGArtifact : public CArmedInstance
|
||||
public:
|
||||
std::string message;
|
||||
ui32 spell; //if it's spell scroll
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
void initObj();
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGResource : public CArmedInstance
|
||||
@ -364,6 +365,18 @@ class DLL_EXPORT CGResource : public CArmedInstance
|
||||
public:
|
||||
int amount; //0 if random
|
||||
std::string message;
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
void initObj();
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGPickable : public CGObjectInstance //campfire, treasure chest
|
||||
{
|
||||
ui32 type, val1, val2;
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
void initObj();
|
||||
void chosen(int which, int heroID) const;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGShrine : public CGObjectInstance
|
||||
@ -391,33 +404,34 @@ public:
|
||||
CCreatureSet creatures;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGQuestGuard : public CArmedInstance
|
||||
class DLL_EXPORT CGQuestGuard : public CGObjectInstance, public CQuest
|
||||
{
|
||||
public:
|
||||
char missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain player
|
||||
bool isDayLimit; //if true, there is a day limit
|
||||
int lastDay; //after this day (first day is 0) mission cannot be completed
|
||||
//for mission 1
|
||||
int m1level;
|
||||
//for mission 2
|
||||
int m2attack, m2defence, m2power, m2knowledge;
|
||||
//for mission 3
|
||||
unsigned char m3bytes[4];
|
||||
//for mission 4
|
||||
unsigned char m4bytes[4];
|
||||
//for mission 5
|
||||
std::vector<int> m5arts; //artifacts id
|
||||
//for mission 6
|
||||
std::vector<CCreature *> m6cre;
|
||||
std::vector<int> m6number;
|
||||
//for mission 7
|
||||
int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold;
|
||||
//for mission 8
|
||||
int m8hero; //hero id
|
||||
//for mission 9
|
||||
int m9player; //number; from 0 to 7
|
||||
};
|
||||
|
||||
std::string firstVisitText, nextVisitText, completedText;
|
||||
class DLL_EXPORT CGMine : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
void newTurn() const;
|
||||
void initObj();
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGVisitableOPW : public CGObjectInstance //objects visitable OPW
|
||||
{
|
||||
public:
|
||||
ui8 visited; //true if object has been visited this week
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
void newTurn() const;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGTeleport : public CGObjectInstance //teleports and subterranean gates
|
||||
{
|
||||
public:
|
||||
static std::map<int,std::map<int, std::vector<int> > > objs; //map[ID][subID] => vector of ids
|
||||
void onHeroVisit(const CGHeroInstance * h) const;
|
||||
void initObj();
|
||||
};
|
||||
|
||||
class DLL_EXPORT CObjectHandler
|
||||
|
36
lib/IGameCallback.cpp
Normal file
36
lib/IGameCallback.cpp
Normal file
@ -0,0 +1,36 @@
|
||||
#define VCMI_DLL
|
||||
#include "IGameCallback.h"
|
||||
#include "../CGameState.h"
|
||||
#include "../map.h"
|
||||
#include "../hch/CObjectHandler.h"
|
||||
|
||||
const CGObjectInstance* IGameCallback::getObj(int objid)
|
||||
{
|
||||
return gs->map->objects[objid];
|
||||
}
|
||||
const CGHeroInstance* IGameCallback::getHero(int objid)
|
||||
{
|
||||
return dynamic_cast<const CGHeroInstance*>(gs->map->objects[objid]);
|
||||
}
|
||||
const CGTownInstance* IGameCallback::getTown(int objid)
|
||||
{
|
||||
return dynamic_cast<const CGTownInstance*>(gs->map->objects[objid]);
|
||||
}
|
||||
|
||||
int IGameCallback::getOwner(int heroID)
|
||||
{
|
||||
return gs->map->objects[heroID]->tempOwner;
|
||||
}
|
||||
int IGameCallback::getResource(int player, int which)
|
||||
{
|
||||
return gs->players.find(player)->second.resources[which];
|
||||
}
|
||||
int IGameCallback::getDate(int mode)
|
||||
{
|
||||
return gs->getDate(mode);
|
||||
}
|
||||
|
||||
const CGHeroInstance* IGameCallback::getSelectedHero( int player )
|
||||
{
|
||||
return getHero(gs->players.find(player)->second.currentSelection);
|
||||
}
|
@ -15,21 +15,24 @@ struct InfoWindow;
|
||||
struct MetaString;
|
||||
struct ShowInInfobox;
|
||||
struct BattleResult;
|
||||
class CGameState;
|
||||
|
||||
class IGameCallback
|
||||
class DLL_EXPORT IGameCallback
|
||||
{
|
||||
protected:
|
||||
CGameState *gs;
|
||||
public:
|
||||
virtual ~IGameCallback(){};
|
||||
|
||||
virtual int getOwner(int heroID)=0;
|
||||
virtual int getResource(int player, int which)=0;
|
||||
virtual int getSelectedHero()=0;
|
||||
virtual int getDate(int mode=0)=0;
|
||||
virtual const CGObjectInstance* getObj(int objid)=0;
|
||||
virtual const CGHeroInstance* getHero(int objid)=0;
|
||||
virtual const CGTownInstance* getTown(int objid)=0;
|
||||
virtual const CGHeroInstance* getSelectedHero(int player)=0; //NULL if no hero is selected
|
||||
virtual int getOwner(int heroID);
|
||||
virtual int getResource(int player, int which);
|
||||
virtual int getDate(int mode=0);
|
||||
virtual const CGObjectInstance* getObj(int objid);
|
||||
virtual const CGHeroInstance* getHero(int objid);
|
||||
virtual const CGTownInstance* getTown(int objid);
|
||||
virtual const CGHeroInstance* getSelectedHero(int player); //NULL if no hero is selected
|
||||
virtual int getCurrentPlayer()=0;
|
||||
virtual int getSelectedHero()=0;
|
||||
|
||||
//do sth
|
||||
virtual void changeSpells(int hid, bool give, const std::set<ui32> &spells)=0;
|
||||
@ -37,6 +40,7 @@ public:
|
||||
virtual void setBlockVis(int objid, bool bv)=0;
|
||||
virtual void setOwner(int objid, ui8 owner)=0;
|
||||
virtual void setHoverName(int objid, MetaString * name)=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 showInfoDialog(InfoWindow *iw)=0;
|
||||
virtual void showYesNoDialog(YesNoDialog *iw, const CFunctionList<void(ui32)> &callback)=0;
|
||||
|
@ -236,6 +236,18 @@ struct SetHeroArtifacts : public CPack<SetHeroArtifacts> //509
|
||||
}
|
||||
};
|
||||
|
||||
struct SetSelection : public CPack<SetSelection> //514
|
||||
{
|
||||
SetSelection(){type = 514;};
|
||||
ui8 player;
|
||||
ui32 id;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & id & player;
|
||||
}
|
||||
};
|
||||
|
||||
struct HeroRecruited : public CPack<HeroRecruited> //515
|
||||
{
|
||||
HeroRecruited(){type = 515;};
|
||||
@ -346,7 +358,7 @@ struct InfoWindow : public CPack<InfoWindow> //103 - displays simple info windo
|
||||
struct SetObjectProperty : public CPack<SetObjectProperty>//1001
|
||||
{
|
||||
ui32 id;
|
||||
ui8 what; //1 - owner; 2 - blockvis; 3 - amount (works with creatures stacks)
|
||||
ui8 what; //1 - owner; 2 - blockvis
|
||||
ui32 val;
|
||||
SetObjectProperty(){type = 1001;};
|
||||
SetObjectProperty(ui32 ID, ui8 What, ui32 Val):id(ID),what(What),val(Val){type = 1001;};
|
||||
|
@ -310,6 +310,10 @@
|
||||
RelativePath="..\hch\CTownHandler.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\IGameCallback.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\map.cpp"
|
||||
>
|
||||
|
531
map.cpp
531
map.cpp
@ -577,203 +577,7 @@ int Mapa::loadSeerHut( unsigned char * bufor, int i, CGObjectInstance *& nobj )
|
||||
|
||||
if(version>RoE)
|
||||
{
|
||||
hut->missionType = bufor[i]; ++i;
|
||||
switch(hut->missionType)
|
||||
{
|
||||
case 0:
|
||||
i+=3;
|
||||
return i;
|
||||
case 1:
|
||||
{
|
||||
hut->m1level = readNormalNr(bufor,i); i+=4;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
hut->isDayLimit = false;
|
||||
hut->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hut->isDayLimit = true;
|
||||
hut->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
hut->m2attack = bufor[i]; ++i;
|
||||
hut->m2defence = bufor[i]; ++i;
|
||||
hut->m2power = bufor[i]; ++i;
|
||||
hut->m2knowledge = bufor[i]; ++i;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
hut->isDayLimit = false;
|
||||
hut->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hut->isDayLimit = true;
|
||||
hut->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
hut->m3bytes[0] = bufor[i]; ++i;
|
||||
hut->m3bytes[1] = bufor[i]; ++i;
|
||||
hut->m3bytes[2] = bufor[i]; ++i;
|
||||
hut->m3bytes[3] = bufor[i]; ++i;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
hut->isDayLimit = false;
|
||||
hut->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hut->isDayLimit = true;
|
||||
hut->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
hut->m4bytes[0] = bufor[i]; ++i;
|
||||
hut->m4bytes[1] = bufor[i]; ++i;
|
||||
hut->m4bytes[2] = bufor[i]; ++i;
|
||||
hut->m4bytes[3] = bufor[i]; ++i;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
hut->isDayLimit = false;
|
||||
hut->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hut->isDayLimit = true;
|
||||
hut->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
int artNumber = bufor[i]; ++i;
|
||||
for(int yy=0; yy<artNumber; ++yy)
|
||||
{
|
||||
int artid = readNormalNr(bufor,i, 2); i+=2;
|
||||
hut->m5arts.push_back(artid);
|
||||
}
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
hut->isDayLimit = false;
|
||||
hut->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hut->isDayLimit = true;
|
||||
hut->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
int typeNumber = bufor[i]; ++i;
|
||||
for(int hh=0; hh<typeNumber; ++hh)
|
||||
{
|
||||
int creType = readNormalNr(bufor,i, 2); i+=2;
|
||||
int creNumb = readNormalNr(bufor,i, 2); i+=2;
|
||||
hut->m6cre.push_back(&(VLC->creh->creatures[creType]));
|
||||
hut->m6number.push_back(creNumb);
|
||||
}
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
hut->isDayLimit = false;
|
||||
hut->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hut->isDayLimit = true;
|
||||
hut->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 7:
|
||||
{
|
||||
hut->m7wood = readNormalNr(bufor,i); i+=4;
|
||||
hut->m7mercury = readNormalNr(bufor,i); i+=4;
|
||||
hut->m7ore = readNormalNr(bufor,i); i+=4;
|
||||
hut->m7sulfur = readNormalNr(bufor,i); i+=4;
|
||||
hut->m7crystal = readNormalNr(bufor,i); i+=4;
|
||||
hut->m7gems = readNormalNr(bufor,i); i+=4;
|
||||
hut->m7gold = readNormalNr(bufor,i); i+=4;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
hut->isDayLimit = false;
|
||||
hut->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hut->isDayLimit = true;
|
||||
hut->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 8:
|
||||
{
|
||||
int heroType = bufor[i]; ++i;
|
||||
hut->m8hero = heroType;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
hut->isDayLimit = false;
|
||||
hut->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hut->isDayLimit = true;
|
||||
hut->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 9:
|
||||
{
|
||||
hut->m9player = bufor[i]; ++i;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
hut->isDayLimit = false;
|
||||
hut->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
hut->isDayLimit = true;
|
||||
hut->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}//internal switch end (seer huts)
|
||||
|
||||
int len1 = readNormalNr(bufor,i); i+=4;
|
||||
for(int ee=0; ee<len1; ++ee)
|
||||
{
|
||||
hut->firstVisitText += bufor[i]; ++i;
|
||||
}
|
||||
|
||||
int len2 = readNormalNr(bufor,i); i+=4;
|
||||
for(int ee=0; ee<len2; ++ee)
|
||||
{
|
||||
hut->nextVisitText += bufor[i]; ++i;
|
||||
}
|
||||
|
||||
int len3 = readNormalNr(bufor,i); i+=4;
|
||||
for(int ee=0; ee<len3; ++ee)
|
||||
{
|
||||
hut->completedText += bufor[i]; ++i;
|
||||
}
|
||||
loadQuest(hut,bufor,i);
|
||||
}
|
||||
else //RoE
|
||||
{
|
||||
@ -1848,7 +1652,40 @@ void Mapa::readObjects( unsigned char * bufor, int &i)
|
||||
loadHero(nobj, bufor, i);
|
||||
break;
|
||||
}
|
||||
case 54: case 71: case 72: case 73: case 74: case 75: case 162: case 163: case 164:
|
||||
case 51: //Mercenary Camp
|
||||
case 23: //Marletto Tower
|
||||
case 61: // Star Axis
|
||||
case 32: // Garden of Revelation
|
||||
case 100: //Learning Stone
|
||||
case 102: //Tree of Knowledge
|
||||
{
|
||||
nobj = new CGVisitableOPH();
|
||||
break;
|
||||
}
|
||||
case 55: //mystical garden
|
||||
case 112://windmill
|
||||
case 109://water wheel
|
||||
{
|
||||
nobj = new CGVisitableOPW();
|
||||
break;
|
||||
}
|
||||
case 43: //teleport
|
||||
case 44: //teleport
|
||||
case 45: //teleport
|
||||
case 103://subterranean gate
|
||||
{
|
||||
nobj = new CGTeleport();
|
||||
break;
|
||||
}
|
||||
case 12: //campfire
|
||||
case 101: //treasure chest
|
||||
{
|
||||
nobj = new CGPickable();
|
||||
break;
|
||||
}
|
||||
case 54: //Monster
|
||||
case 71: case 72: case 73: case 74: case 75: // Random Monster 1 - 4
|
||||
case 162: case 163: case 164: // Random Monster 5 - 7
|
||||
{
|
||||
CGCreature *cre = new CGCreature();
|
||||
nobj = cre;
|
||||
@ -1971,7 +1808,8 @@ void Mapa::readObjects( unsigned char * bufor, int &i)
|
||||
i+=8;
|
||||
break;
|
||||
}
|
||||
case 5: case 65: case 66: case 67: case 68: case 69: //artifact
|
||||
case 5: //artifact
|
||||
case 65: case 66: case 67: case 68: case 69: //random artifact
|
||||
case 93: //spell scroll
|
||||
{
|
||||
CGArtifact *art = new CGArtifact();
|
||||
@ -1991,7 +1829,7 @@ void Mapa::readObjects( unsigned char * bufor, int &i)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 76: case 79: //resource
|
||||
case 76: case 79: //random resource; resource
|
||||
{
|
||||
CGResource *res = new CGResource();
|
||||
nobj = res;
|
||||
@ -2011,12 +1849,22 @@ void Mapa::readObjects( unsigned char * bufor, int &i)
|
||||
|
||||
break;
|
||||
}
|
||||
case 77: case 98: //town
|
||||
case 77: case 98: //random town; town
|
||||
{
|
||||
loadTown(nobj, bufor, i);
|
||||
break;
|
||||
}
|
||||
case 53: case 17: case 18: case 19: case 20: case 42: case 87: case 220://cases 17 - 20 and 42 - tests
|
||||
case 53:
|
||||
{
|
||||
nobj = new CGMine();
|
||||
nobj->setOwner(bufor[i++]);
|
||||
i+=3;
|
||||
break;
|
||||
}
|
||||
case 17: case 18: case 19: case 20: //dwellings
|
||||
case 42: //lighthouse
|
||||
case 87: //shipyard
|
||||
case 220://mine (?)
|
||||
{
|
||||
nobj = new CGObjectInstance();
|
||||
nobj->setOwner(bufor[i++]);
|
||||
@ -2157,206 +2005,7 @@ void Mapa::readObjects( unsigned char * bufor, int &i)
|
||||
{
|
||||
CGQuestGuard *guard = new CGQuestGuard();
|
||||
nobj = guard;
|
||||
guard->missionType = bufor[i]; ++i;
|
||||
int len1, len2, len3;
|
||||
switch(guard->missionType)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
goto borderguardend;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
guard->m1level = readNormalNr(bufor,i); i+=4;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
guard->isDayLimit = false;
|
||||
guard->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
guard->isDayLimit = true;
|
||||
guard->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
guard->m2attack = bufor[i]; ++i;
|
||||
guard->m2defence = bufor[i]; ++i;
|
||||
guard->m2power = bufor[i]; ++i;
|
||||
guard->m2knowledge = bufor[i]; ++i;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
guard->isDayLimit = false;
|
||||
guard->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
guard->isDayLimit = true;
|
||||
guard->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 3:
|
||||
{
|
||||
guard->m3bytes[0] = bufor[i]; ++i;
|
||||
guard->m3bytes[1] = bufor[i]; ++i;
|
||||
guard->m3bytes[2] = bufor[i]; ++i;
|
||||
guard->m3bytes[3] = bufor[i]; ++i;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
guard->isDayLimit = false;
|
||||
guard->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
guard->isDayLimit = true;
|
||||
guard->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 4:
|
||||
{
|
||||
guard->m4bytes[0] = bufor[i]; ++i;
|
||||
guard->m4bytes[1] = bufor[i]; ++i;
|
||||
guard->m4bytes[2] = bufor[i]; ++i;
|
||||
guard->m4bytes[3] = bufor[i]; ++i;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
guard->isDayLimit = false;
|
||||
guard->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
guard->isDayLimit = true;
|
||||
guard->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
int artNumber = bufor[i]; ++i;
|
||||
for(int yy=0; yy<artNumber; ++yy)
|
||||
{
|
||||
guard->m5arts.push_back(readNormalNr(bufor,i, 2)); i+=2;
|
||||
}
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
guard->isDayLimit = false;
|
||||
guard->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
guard->isDayLimit = true;
|
||||
guard->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
int typeNumber = bufor[i]; ++i;
|
||||
for(int hh=0; hh<typeNumber; ++hh)
|
||||
{
|
||||
int creType = readNormalNr(bufor,i, 2); i+=2;
|
||||
int creNumb = readNormalNr(bufor,i, 2); i+=2;
|
||||
guard->m6cre.push_back(&(VLC->creh->creatures[creType]));
|
||||
guard->m6number.push_back(creNumb);
|
||||
}
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
guard->isDayLimit = false;
|
||||
guard->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
guard->isDayLimit = true;
|
||||
guard->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 7:
|
||||
{
|
||||
guard->m7wood = readNormalNr(bufor,i); i+=4;
|
||||
guard->m7mercury = readNormalNr(bufor,i); i+=4;
|
||||
guard->m7ore = readNormalNr(bufor,i); i+=4;
|
||||
guard->m7sulfur = readNormalNr(bufor,i); i+=4;
|
||||
guard->m7crystal = readNormalNr(bufor,i); i+=4;
|
||||
guard->m7gems = readNormalNr(bufor,i); i+=4;
|
||||
guard->m7gold = readNormalNr(bufor,i); i+=4;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
guard->isDayLimit = false;
|
||||
guard->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
guard->isDayLimit = true;
|
||||
guard->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 8:
|
||||
{
|
||||
int heroType = bufor[i]; ++i;
|
||||
guard->m8hero = heroType;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
guard->isDayLimit = false;
|
||||
guard->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
guard->isDayLimit = true;
|
||||
guard->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 9:
|
||||
{
|
||||
guard->m9player = bufor[i]; ++i;
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
guard->isDayLimit = false;
|
||||
guard->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
guard->isDayLimit = true;
|
||||
guard->lastDay = limit;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}//internal switch end (seer huts)
|
||||
|
||||
len1 = readNormalNr(bufor,i); i+=4;
|
||||
for(int ee=0; ee<len1; ++ee)
|
||||
{
|
||||
guard->firstVisitText += bufor[i]; ++i;
|
||||
}
|
||||
|
||||
len2 = readNormalNr(bufor,i); i+=4;
|
||||
for(int ee=0; ee<len2; ++ee)
|
||||
{
|
||||
guard->nextVisitText += bufor[i]; ++i;
|
||||
}
|
||||
|
||||
len3 = readNormalNr(bufor,i); i+=4;
|
||||
for(int ee=0; ee<len3; ++ee)
|
||||
{
|
||||
guard->completedText += bufor[i]; ++i;
|
||||
}
|
||||
borderguardend:
|
||||
loadQuest(guard, bufor, i);
|
||||
break;
|
||||
}
|
||||
case 214: //hero placeholder
|
||||
@ -2428,3 +2077,81 @@ bool Mapa::isInTheMap( int3 pos )
|
||||
return false;
|
||||
else return true;
|
||||
}
|
||||
|
||||
void Mapa::loadQuest(CQuest * guard, unsigned char * bufor, int & i)
|
||||
{
|
||||
guard->missionType = bufor[i]; ++i;
|
||||
int len1, len2, len3;
|
||||
switch(guard->missionType)
|
||||
{
|
||||
case 0:
|
||||
return;
|
||||
case 2:
|
||||
{
|
||||
guard->m2stats.resize(4);
|
||||
for(int x=0; x<4; x++)
|
||||
{
|
||||
guard->m2stats[x] = bufor[i++];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
case 3:
|
||||
case 4:
|
||||
{
|
||||
guard->m13489val = readNormalNr(bufor,i); i+=4;
|
||||
break;
|
||||
}
|
||||
case 5:
|
||||
{
|
||||
int artNumber = bufor[i]; ++i;
|
||||
for(int yy=0; yy<artNumber; ++yy)
|
||||
{
|
||||
guard->m5arts.push_back(readNormalNr(bufor,i, 2)); i+=2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 6:
|
||||
{
|
||||
int typeNumber = bufor[i]; ++i;
|
||||
for(int hh=0; hh<typeNumber; ++hh)
|
||||
{
|
||||
ui32 creType = readNormalNr(bufor,i, 2); i+=2;
|
||||
ui32 creNumb = readNormalNr(bufor,i, 2); i+=2;
|
||||
guard->m6creatures.push_back(std::make_pair(creType,creNumb));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 7:
|
||||
{
|
||||
guard->m7resources.resize(7);
|
||||
for(int x=0; x<7; x++)
|
||||
{
|
||||
guard->m7resources[x] = readNormalNr(bufor,i);
|
||||
i+=4;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 8:
|
||||
case 9:
|
||||
{
|
||||
guard->m13489val = bufor[i]; ++i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int limit = readNormalNr(bufor,i); i+=4;
|
||||
if(limit == ((int)0xffffffff))
|
||||
{
|
||||
guard->lastDay = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
guard->lastDay = limit;
|
||||
}
|
||||
|
||||
guard->firstVisitText = readString(bufor,i);
|
||||
guard->nextVisitText = readString(bufor,i);
|
||||
guard->completedText = readString(bufor,i);
|
||||
}
|
2
map.h
2
map.h
@ -11,6 +11,7 @@
|
||||
class CGDefInfo;
|
||||
class CGObjectInstance;
|
||||
class CGHeroInstance;
|
||||
class CQuest;
|
||||
class CGTownInstance;
|
||||
enum ESortBy{_name, _playerAm, _size, _format, _viccon, _loscon};
|
||||
enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF,
|
||||
@ -338,6 +339,7 @@ struct DLL_EXPORT Mapa
|
||||
|
||||
void readEvents( unsigned char * bufor, int &i);
|
||||
void readObjects( unsigned char * bufor, int &i);
|
||||
void loadQuest( CQuest * guard, unsigned char * bufor, int & i);
|
||||
void readDefInfo( unsigned char * bufor, int &i);
|
||||
void readTerrain( unsigned char * bufor, int &i);
|
||||
void readPredefinedHeroes( unsigned char * bufor, int &i);
|
||||
|
@ -1027,9 +1027,9 @@ upgend:
|
||||
}
|
||||
case 514:
|
||||
{
|
||||
ui32 id;
|
||||
c >> id;
|
||||
gs->players[*players.begin()].currentSelection = id;
|
||||
SetSelection ss;
|
||||
c >> ss;
|
||||
sendAndApply(&ss);
|
||||
break;
|
||||
}
|
||||
case 515:
|
||||
@ -1517,9 +1517,6 @@ void CGameHandler::init(StartInfo *si, int Seed)
|
||||
gs->init(si,map,Seed);
|
||||
tlog0 << "Gamestate initialized!" << std::endl;
|
||||
|
||||
|
||||
for(int i=0; i<gs->map->objects.size(); i++)
|
||||
gs->map->objects[i]->initObj();
|
||||
/****************************LUA OBJECT SCRIPTS************************************************/
|
||||
//std::vector<std::string> * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files
|
||||
//for (int i=0; i<lf->size(); i++)
|
||||
@ -1627,6 +1624,7 @@ void CGameHandler::newTurn()
|
||||
sendAndApply(&n);
|
||||
tlog5 << "Info about turn " << n.day << "has been sent!" << std::endl;
|
||||
for(size_t i = 0; i<gs->map->objects.size(); i++)
|
||||
if(gs->map->objects[i])
|
||||
gs->map->objects[i]->newTurn();
|
||||
}
|
||||
void CGameHandler::run()
|
||||
@ -1962,32 +1960,11 @@ void CGameHandler::setOwner(int objid, ui8 owner)
|
||||
SetObjectProperty sop(objid,1,owner);
|
||||
sendAndApply(&sop);
|
||||
}
|
||||
const CGObjectInstance* CGameHandler::getObj(int objid)
|
||||
{
|
||||
return gs->map->objects[objid];
|
||||
}
|
||||
const CGHeroInstance* CGameHandler::getHero(int objid)
|
||||
{
|
||||
return dynamic_cast<const CGHeroInstance*>(gs->map->objects[objid]);
|
||||
}
|
||||
const CGTownInstance* CGameHandler::getTown(int objid)
|
||||
{
|
||||
return dynamic_cast<const CGTownInstance*>(gs->map->objects[objid]);
|
||||
}
|
||||
void CGameHandler::setHoverName(int objid, MetaString* name)
|
||||
{
|
||||
SetHoverName shn(objid, *name);
|
||||
sendAndApply(&shn);
|
||||
}
|
||||
|
||||
int CGameHandler::getOwner(int heroID)
|
||||
{
|
||||
return gs->map->objects[heroID]->tempOwner;
|
||||
}
|
||||
int CGameHandler::getResource(int player, int which)
|
||||
{
|
||||
return gs->players.find(player)->second.resources[which];
|
||||
}
|
||||
void CGameHandler::showInfoDialog(InfoWindow *iw)
|
||||
{
|
||||
sendToAllClients(iw);
|
||||
@ -2000,26 +1977,11 @@ void CGameHandler::showSelectionDialog(SelectionDialog *iw, const CFunctionList<
|
||||
{
|
||||
ask(iw,iw->player,callback);
|
||||
}
|
||||
|
||||
int CGameHandler::getSelectedHero()
|
||||
int CGameHandler::getCurrentPlayer()
|
||||
{
|
||||
//int ret;
|
||||
//if (LOCPLINT->adventureInt->selection->ID == HEROI_TYPE)
|
||||
// ret = ((CGHeroInstance*)(LOCPLINT->adventureInt->selection))->subID;
|
||||
//else
|
||||
// ret = -1;;
|
||||
return -1;
|
||||
return gs->currentPlayer;
|
||||
}
|
||||
|
||||
const CGHeroInstance* CGameHandler::getSelectedHero( int player )
|
||||
{
|
||||
return getHero(gs->players.find(player)->second.currentSelection);
|
||||
}
|
||||
|
||||
int CGameHandler::getDate(int mode)
|
||||
{
|
||||
return getDate(mode);
|
||||
}
|
||||
void CGameHandler::giveResource(int player, int which, int val)
|
||||
{
|
||||
SetResource sr;
|
||||
@ -2108,7 +2070,16 @@ void CGameHandler::changeSpells( int hid, bool give, const std::set<ui32> &spell
|
||||
sendAndApply(&cs);
|
||||
}
|
||||
|
||||
int CGameHandler::getCurrentPlayer()
|
||||
int CGameHandler::getSelectedHero()
|
||||
{
|
||||
return gs->currentPlayer;
|
||||
return IGameCallback::getSelectedHero(getCurrentPlayer())->id;
|
||||
}
|
||||
|
||||
void CGameHandler::setObjProperty( int objid, int prop, int val )
|
||||
{
|
||||
SetObjectProperty sob;
|
||||
sob.id = objid;
|
||||
sob.what = prop;
|
||||
sob.val = val;
|
||||
sendAndApply(&sob);
|
||||
}
|
@ -57,7 +57,6 @@ public:
|
||||
class CGameHandler : public IGameCallback
|
||||
{
|
||||
static ui32 QID;
|
||||
CGameState *gs;
|
||||
//std::set<CCPPObjectScript *> cppscripts; //C++ scripts
|
||||
//std::map<int, std::map<std::string, CObjectScript*> > objscr; //non-C++ scripts
|
||||
|
||||
@ -82,15 +81,9 @@ public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//from IGameCallback
|
||||
//get info
|
||||
int getOwner(int heroID);
|
||||
int getResource(int player, int which);
|
||||
int getSelectedHero();
|
||||
int getDate(int mode=0);
|
||||
const CGObjectInstance* getObj(int objid);
|
||||
const CGHeroInstance* getHero(int objid);
|
||||
const CGTownInstance* getTown(int objid);
|
||||
const CGHeroInstance* getSelectedHero(int player); //NULL if no hero is selected
|
||||
int getCurrentPlayer();
|
||||
int getSelectedHero();
|
||||
|
||||
|
||||
//do sth
|
||||
void changeSpells(int hid, bool give, const std::set<ui32> &spells);
|
||||
@ -98,6 +91,7 @@ public:
|
||||
void setBlockVis(int objid, bool bv);
|
||||
void setOwner(int objid, ui8 owner);
|
||||
void setHoverName(int objid, MetaString * name);
|
||||
void setObjProperty(int objid, int prop, int val);
|
||||
void changePrimSkill(int ID, int which, int val, bool abs=false);
|
||||
void showInfoDialog(InfoWindow *iw);
|
||||
void showYesNoDialog(YesNoDialog *iw, const CFunctionList<void(ui32)> &callback);
|
||||
|
Loading…
Reference in New Issue
Block a user