mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-20 20:23:03 +02:00
Partially done object scripting and interactions.
Most of 0.4 ;)
This commit is contained in:
parent
8b73ab8492
commit
556311c9ab
@ -9,6 +9,7 @@ public:
|
||||
void heroKilled(const CHeroInstance *);
|
||||
void heroCreated(const CHeroInstance *);
|
||||
void heroMoved(const HeroMoveDetails &);
|
||||
void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val) {};
|
||||
};
|
||||
|
||||
#define NAME "EmptyAI 0.1"
|
@ -1,6 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "CAdvmapInterface.h"
|
||||
#include "hch\CLodHandler.h"
|
||||
#include "CPlayerInterface.h"
|
||||
#include "hch\CPreGameTextHandler.h"
|
||||
#include "hch\CGeneralTextHandler.h"
|
||||
#include "hch\CTownHandler.h"
|
||||
@ -14,6 +15,7 @@
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include "CLua.h"
|
||||
#include "hch/CHeroHandler.h"
|
||||
extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
|
||||
|
||||
using namespace boost::logic;
|
||||
@ -646,7 +648,7 @@ void CMinimap::draw()
|
||||
{
|
||||
for (int jj=0; jj<ho; jj++)
|
||||
{
|
||||
SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,CGI->playerColors[(*hh)[i]->state->owner].r,CGI->playerColors[(*hh)[i]->state->owner].g,CGI->playerColors[(*hh)[i]->state->owner].b);
|
||||
SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,CGI->playerColors[(*hh)[i]->getOwner()].r,CGI->playerColors[(*hh)[i]->getOwner()].g,CGI->playerColors[(*hh)[i]->getOwner()].b);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1146,7 +1148,11 @@ CInfoBar::CInfoBar()
|
||||
}
|
||||
void CInfoBar::draw(void * specific)
|
||||
{
|
||||
//if (!specific)
|
||||
// specific = LOCPLINT->adventureInt->selection.selected;
|
||||
SDL_Surface * todr = LOCPLINT->infoWin(specific);
|
||||
if (!todr)
|
||||
return;
|
||||
blitAt(todr,pos.x,pos.y);
|
||||
SDL_FreeSurface(todr);
|
||||
}
|
||||
@ -1296,6 +1302,8 @@ void CAdvMapInt::show()
|
||||
|
||||
statusbar.show();
|
||||
|
||||
infoBar.draw();
|
||||
|
||||
SDL_Flip(ekran);
|
||||
}
|
||||
void CAdvMapInt::hide()
|
||||
|
@ -3,8 +3,7 @@
|
||||
#include <typeinfo>
|
||||
#include "global.h"
|
||||
#include "SDL.h"
|
||||
#include "CGameInterface.h"
|
||||
#include <boost/logic/tribool.hpp>
|
||||
#include "CPlayerInterface.h"
|
||||
#include <map>
|
||||
|
||||
class CDefHandler;
|
||||
@ -125,7 +124,7 @@ class CMinimap
|
||||
: public ClickableL, public ClickableR, public Hoverable, public MotionInterested, public virtual CIntObject
|
||||
{
|
||||
public:
|
||||
SDL_Surface * radar; //radar.def; TODO: radars for maps with custom dimensions
|
||||
SDL_Surface * radar;
|
||||
SDL_Surface * temps;
|
||||
std::map<int,SDL_Color> colors;
|
||||
std::map<int,SDL_Color> colorsBlocked;
|
||||
|
148
CCallback.cpp
148
CCallback.cpp
@ -7,8 +7,12 @@
|
||||
#include "hch\CAmbarCendamo.h"
|
||||
#include "mapHandler.h"
|
||||
#include "CGameState.h"
|
||||
#include "CGameInterface.h"
|
||||
#include "CPlayerInterface.h"
|
||||
#include "CLua.h"
|
||||
#include "hch/CGeneralTextHandler.h"
|
||||
#include "CAdvmapInterface.h"
|
||||
#include "CPlayerInterface.h"
|
||||
LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
|
||||
int CCallback::lowestSpeed(CGHeroInstance * chi)
|
||||
{
|
||||
int min = 150;
|
||||
@ -99,7 +103,7 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
|
||||
curd.src = stpos;
|
||||
curd.dst = endpos;
|
||||
curd.ho = hero;
|
||||
curd.owner = hero->state->owner;
|
||||
curd.owner = hero->getOwner();
|
||||
/*if(player!=-1)
|
||||
{
|
||||
hero->pos = endpos;
|
||||
@ -145,14 +149,20 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
|
||||
break;
|
||||
if(j->second.fogOfWarMap[stpos.x-1][stpos.y][stpos.z] || j->second.fogOfWarMap[endpos.x-1][endpos.y][endpos.z])
|
||||
{ //player should be notified
|
||||
CGI->playerint[j->first]->heroMoved(curd);
|
||||
CGI->playerint[j->second.serial]->heroMoved(curd);
|
||||
}
|
||||
++nn;
|
||||
}
|
||||
|
||||
std::vector< CGObjectInstance * > vis = CGI->mh->getVisitableObjs(hero->getPosition(false));
|
||||
for (int iii=0; iii<vis.size(); iii++)
|
||||
std::cout<< CGI->objh->objects[vis[iii]->ID].name<<std::endl;
|
||||
{
|
||||
if(gs->checkFunc(vis[iii]->ID,"heroVisit"))
|
||||
gs->objscr[vis[iii]->ID]["heroVisit"]->onHeroVisit(vis[iii],curd.ho->subID);
|
||||
if(vis[iii]->state)
|
||||
vis[iii]->state->onHeroVisit(vis[iii],curd.ho->subID);
|
||||
//std::cout<< CGI->objh->objects[vis[iii]->ID].name<<std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
@ -309,3 +319,133 @@ bool CCallback::isVisible(int3 pos)
|
||||
{
|
||||
return isVisible(pos,player);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int3 CScriptCallback::getPos(CGObjectInstance * ob)
|
||||
{
|
||||
return ob->pos;
|
||||
}
|
||||
void CScriptCallback::changePrimSkill(int ID, int which, int val)
|
||||
{
|
||||
CGHeroInstance * hero = CGI->state->getHero(ID,0);
|
||||
hero->primSkills[which]+=val;
|
||||
for (int i=0; i<CGI->playerint.size(); i++)
|
||||
{
|
||||
if (CGI->playerint[i]->playerID == hero->getOwner())
|
||||
{
|
||||
CGI->playerint[i]->heroPrimarySkillChanged(hero, which, val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int CScriptCallback::getHeroOwner(int heroID)
|
||||
{
|
||||
CGHeroInstance * hero = CGI->state->getHero(heroID,0);
|
||||
return hero->getOwner();
|
||||
}
|
||||
void CScriptCallback::showInfoDialog(int player, std::string text, std::vector<SComponent*> * components)
|
||||
{
|
||||
//TODO: upewniac sie ze mozemy to zrzutowac (przy customowych interfejsach cos moze sie kopnac)
|
||||
if (player>=0)
|
||||
{
|
||||
CGameInterface * temp = CGI->playerint[CGI->state->players[player].serial];
|
||||
if (temp->human)
|
||||
((CPlayerInterface*)(temp))->showInfoDialog(text,*components);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=0; i<CGI->playerint.size();i++)
|
||||
{
|
||||
if (CGI->playerint[i]->human)
|
||||
((CPlayerInterface*)(CGI->playerint[i]))->showInfoDialog(text,*components);
|
||||
}
|
||||
}
|
||||
}
|
||||
int CScriptCallback::getSelectedHero()
|
||||
{
|
||||
int ret;
|
||||
if (LOCPLINT->adventureInt->selection.type == HEROI_TYPE)
|
||||
ret = ((CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->subID;
|
||||
else
|
||||
ret = -1;;
|
||||
return ret;
|
||||
}
|
||||
void CLuaCallback::registerFuncs(lua_State * L)
|
||||
{
|
||||
lua_newtable(L);
|
||||
|
||||
#define REGISTER_C_FUNC(x) \
|
||||
lua_pushstring(L, #x); \
|
||||
lua_pushcfunction(L, x); \
|
||||
lua_rawset(L, -3)
|
||||
|
||||
REGISTER_C_FUNC(getPos);
|
||||
REGISTER_C_FUNC(changePrimSkill);
|
||||
REGISTER_C_FUNC(getGnrlText);
|
||||
REGISTER_C_FUNC(getSelectedHero);
|
||||
|
||||
/*
|
||||
REGISTER_C_FUNC(changePrimSkill);
|
||||
REGISTER_C_FUNC(getGnrlText);
|
||||
REGISTER_C_FUNC(changePrimSkill);
|
||||
REGISTER_C_FUNC(getGnrlText);
|
||||
REGISTER_C_FUNC(changePrimSkill);
|
||||
REGISTER_C_FUNC(getGnrlText);*/
|
||||
|
||||
|
||||
lua_setglobal(L, "vcmi");
|
||||
#undef REGISTER_C_FUNC(x)
|
||||
}
|
||||
int CLuaCallback::getPos(lua_State * L)//(CGObjectInstance * object);
|
||||
{
|
||||
const int args = lua_gettop(L); // number of arguments
|
||||
if ((args < 1) || !lua_isnumber(L, 1) )
|
||||
luaL_error(L,
|
||||
"Incorrect arguments to getPos([Object address])");
|
||||
CGObjectInstance * object = (CGObjectInstance *)(lua_tointeger(L, 1));
|
||||
lua_pushinteger(L,object->pos.x);
|
||||
lua_pushinteger(L,object->pos.y);
|
||||
lua_pushinteger(L,object->pos.z);
|
||||
return 3;
|
||||
}
|
||||
int CLuaCallback::changePrimSkill(lua_State * L)//(int ID, int which, int val);
|
||||
{
|
||||
const int args = lua_gettop(L); // number of arguments
|
||||
if ((args < 1) || !lua_isnumber(L, 1) ||
|
||||
((args >= 2) && !lua_isnumber(L, 2)) ||
|
||||
((args >= 3) && !lua_isnumber(L, 3)) )
|
||||
{
|
||||
luaL_error(L,
|
||||
"Incorrect arguments to changePrimSkill([Hero ID], [Which Primary skill], [Change by])");
|
||||
}
|
||||
int ID = lua_tointeger(L, 1),
|
||||
which = lua_tointeger(L, 2),
|
||||
val = lua_tointeger(L, 3);
|
||||
|
||||
CScriptCallback::changePrimSkill(ID,which,val);
|
||||
|
||||
return 0;
|
||||
}
|
||||
int CLuaCallback::getGnrlText(lua_State * L) //(int which),returns string
|
||||
{
|
||||
const int args = lua_gettop(L); // number of arguments
|
||||
if ((args < 1) || !lua_isnumber(L, 1) )
|
||||
luaL_error(L,
|
||||
"Incorrect arguments to getGnrlText([Text ID])");
|
||||
int which = lua_tointeger(L,1);
|
||||
lua_pushstring(L,CGI->generaltexth->allTexts[which].c_str());
|
||||
return 1;
|
||||
}
|
||||
int CLuaCallback::getSelectedHero(lua_State * L) //(),returns int (ID of hero, -1 if no hero is seleceted)
|
||||
{
|
||||
int ret;
|
||||
if (LOCPLINT->adventureInt->selection.type == HEROI_TYPE)
|
||||
ret = ((CGHeroInstance*)(LOCPLINT->adventureInt->selection.selected))->subID;
|
||||
else
|
||||
ret = -1;
|
||||
lua_pushinteger(L,ret);
|
||||
return 1;
|
||||
}
|
29
CCallback.h
29
CCallback.h
@ -2,13 +2,14 @@
|
||||
#define CCALLBACK_H
|
||||
|
||||
#include "mapHandler.h"
|
||||
|
||||
#include "tchar.h"
|
||||
class CGameState;
|
||||
class CHeroInstance;
|
||||
class CTownInstance;
|
||||
class CPath;
|
||||
class CGObjectInstance;
|
||||
|
||||
struct SComponent;
|
||||
typedef struct lua_State lua_State;
|
||||
struct HeroMoveDetails
|
||||
{
|
||||
int3 src, dst; //source and destination points
|
||||
@ -50,8 +51,28 @@ public:
|
||||
//friends
|
||||
friend int _tmain(int argc, _TCHAR* argv[]);
|
||||
};
|
||||
|
||||
class CLuaCallback
|
||||
class CScriptCallback
|
||||
{
|
||||
public:
|
||||
CGameState * gs;
|
||||
|
||||
static int3 getPos(CGObjectInstance * ob);
|
||||
static void changePrimSkill(int ID, int which, int val);
|
||||
void showInfoDialog(int player, std::string text, std::vector<SComponent*> * components);
|
||||
int getHeroOwner(int heroID);
|
||||
int getSelectedHero();
|
||||
friend void initGameState(CGameInfo * cgi);
|
||||
};
|
||||
class CLuaCallback : public CScriptCallback
|
||||
{
|
||||
private:
|
||||
|
||||
static void registerFuncs(lua_State * L);
|
||||
static int getPos(lua_State * L);//(CGObjectInstance * object);
|
||||
static int changePrimSkill(lua_State * L);//(int ID, int which, int val);
|
||||
static int getGnrlText(lua_State * L);//(int ID, int which, int val);
|
||||
static int getSelectedHero(lua_State * L);//()
|
||||
|
||||
friend void initGameState(CGameInfo * cgi);
|
||||
};
|
||||
#endif //CCALLBACK_H
|
@ -1,6 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "CConsoleHandler.h"
|
||||
#include "CAdvmapInterface.h"
|
||||
#include "CPlayerInterface.h"
|
||||
#include "SDL.h"
|
||||
#include "SDL_thread.h"
|
||||
#include "CGameInfo.h"
|
||||
@ -11,6 +12,7 @@
|
||||
#include "mapHandler.h"
|
||||
#include <sstream>
|
||||
#include "SDL_Extensions.h"
|
||||
#include "hch/CHeroHandler.h"
|
||||
int internalFunc(void * callback)
|
||||
{
|
||||
CCallback * cb = (CCallback*)callback;
|
||||
|
1039
CGameInterface.cpp
1039
CGameInterface.cpp
File diff suppressed because it is too large
Load Diff
123
CGameInterface.h
123
CGameInterface.h
@ -1,91 +1,15 @@
|
||||
#ifndef CGAMEINTERFACE_H
|
||||
#define CGAMEINTERFACE_H
|
||||
|
||||
#include "SDL.h"
|
||||
#include <boost/logic/tribool.hpp>
|
||||
#include "SDL_framerate.h"
|
||||
|
||||
#include "global.h"
|
||||
#include "CCallback.h"
|
||||
BOOST_TRIBOOL_THIRD_STATE(outOfRange)
|
||||
|
||||
using namespace boost::logic;
|
||||
|
||||
class CAdvMapInt;
|
||||
class CCallback;
|
||||
class CHeroInstance;
|
||||
class CDefHandler;
|
||||
struct HeroMoveDetails;
|
||||
class CDefEssential;
|
||||
class CGlobalAI;
|
||||
class CGHeroInstance;
|
||||
class CIntObject //interface object
|
||||
{
|
||||
public:
|
||||
SDL_Rect pos;
|
||||
int ID;
|
||||
};
|
||||
class CSimpleWindow : public virtual CIntObject
|
||||
{
|
||||
public:
|
||||
SDL_Surface * bitmap;
|
||||
CIntObject * owner;
|
||||
CSimpleWindow():bitmap(NULL),owner(NULL){};
|
||||
virtual ~CSimpleWindow();
|
||||
};
|
||||
class CButtonBase : public virtual CIntObject //basic buttton class
|
||||
{
|
||||
public:
|
||||
int type; //advmapbutton=2
|
||||
bool abs;
|
||||
bool active;
|
||||
CIntObject * ourObj;
|
||||
int state;
|
||||
std::vector< std::vector<SDL_Surface*> > imgs;
|
||||
int curimg;
|
||||
virtual void show() ;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
CButtonBase();
|
||||
};
|
||||
class ClickableL : public virtual CIntObject //for left-clicks
|
||||
{
|
||||
public:
|
||||
bool pressedL;
|
||||
ClickableL();
|
||||
virtual void clickLeft (tribool down)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
class ClickableR : public virtual CIntObject //for right-clicks
|
||||
{
|
||||
public:
|
||||
bool pressedR;
|
||||
ClickableR();
|
||||
virtual void clickRight (tribool down)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
class Hoverable : public virtual CIntObject
|
||||
{
|
||||
public:
|
||||
Hoverable(){hovered=false;}
|
||||
bool hovered;
|
||||
virtual void hover (bool on)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
class KeyInterested : public virtual CIntObject
|
||||
{
|
||||
public:
|
||||
virtual void keyPressed (SDL_KeyboardEvent & key)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
class MotionInterested: public virtual CIntObject
|
||||
{
|
||||
public:
|
||||
virtual void mouseMoved (SDL_MouseMotionEvent & sEvent)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
|
||||
class CGameInterface
|
||||
{
|
||||
public:
|
||||
@ -96,10 +20,9 @@ public:
|
||||
virtual void yourTurn()=0{};
|
||||
virtual void heroKilled(const CGHeroInstance*)=0{};
|
||||
virtual void heroCreated(const CGHeroInstance*)=0{};
|
||||
|
||||
virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)=0{};
|
||||
virtual void heroMoved(const HeroMoveDetails & details)=0;
|
||||
};
|
||||
class CGlobalAI;
|
||||
class CAIHandler
|
||||
{
|
||||
public:
|
||||
@ -113,40 +36,4 @@ public:
|
||||
virtual void heroKilled(const CGHeroInstance*){};
|
||||
virtual void heroCreated(const CGHeroInstance*){};
|
||||
};
|
||||
class CPlayerInterface : public CGameInterface
|
||||
{
|
||||
public:
|
||||
bool makingTurn;
|
||||
SDL_Event * current;
|
||||
CAdvMapInt * adventureInt;
|
||||
FPSmanager * mainFPSmng;
|
||||
//TODO: town interace, battle interface, other interfaces
|
||||
|
||||
CCallback * cb;
|
||||
|
||||
std::vector<ClickableL*> lclickable;
|
||||
std::vector<ClickableR*> rclickable;
|
||||
std::vector<Hoverable*> hoverable;
|
||||
std::vector<KeyInterested*> keyinterested;
|
||||
std::vector<MotionInterested*> motioninterested;
|
||||
std::vector<CSimpleWindow*> objsToBlit;
|
||||
|
||||
SDL_Surface * hInfo;
|
||||
std::vector<std::pair<int, int> > slotsPos;
|
||||
CDefEssential *luck22, *luck30, *luck42, *luck82,
|
||||
*morale22, *morale30, *morale42, *morale82;
|
||||
|
||||
//overloaded funcs from Interface
|
||||
void yourTurn();
|
||||
void heroMoved(const HeroMoveDetails & details);
|
||||
void heroKilled(const CGHeroInstance*);
|
||||
void heroCreated(const CGHeroInstance*);
|
||||
|
||||
SDL_Surface * infoWin(void * specific); //specific=0 => draws info about selected town/hero //TODO - gdy sie dorobi sensowna hierarchie klas ins. to wywalic tego brzydkiego void*
|
||||
void handleEvent(SDL_Event * sEvent);
|
||||
void init(CCallback * CB);
|
||||
int3 repairScreenPos(int3 pos);
|
||||
|
||||
CPlayerInterface(int Player, int serial);
|
||||
};
|
||||
#endif //CGAMEINTERFACE_H
|
39
CGameState.h
39
CGameState.h
@ -1,16 +1,15 @@
|
||||
#ifndef CGAMESTATE_H
|
||||
#define CGAMESTATE_H
|
||||
|
||||
#include "mapHandler.h"
|
||||
|
||||
class CScriptCallback;
|
||||
class CHeroInstance;
|
||||
class CTownInstance;
|
||||
class CCallback;
|
||||
|
||||
class CLuaCallback;
|
||||
struct PlayerState
|
||||
{
|
||||
public:
|
||||
int color;
|
||||
int color, serial;
|
||||
//std::vector<std::vector<std::vector<char> > > fogOfWarMap; //true - visible, false - hidden
|
||||
PseudoV< PseudoV< PseudoV<unsigned char> > > fogOfWarMap; //true - visible, false - hidden
|
||||
std::vector<int> resources;
|
||||
@ -21,14 +20,44 @@ public:
|
||||
|
||||
class CGameState
|
||||
{
|
||||
private:
|
||||
int currentPlayer;
|
||||
|
||||
int day; //total number of days in game
|
||||
std::map<int,PlayerState> players; //color <-> playerstate
|
||||
std::map<int, std::map<std::string, CObjectScript*> > objscr; //custom user scripts
|
||||
|
||||
|
||||
bool checkFunc(int obid, std::string name)
|
||||
{
|
||||
if (objscr.find(obid)!=objscr.end())
|
||||
{
|
||||
if(objscr[obid].find(name)!=objscr[obid].end())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
CGHeroInstance * getHero(int ID, int mode)
|
||||
{
|
||||
if (mode != 0)
|
||||
throw new std::exception("gs->getHero: This mode is not supported!");
|
||||
for ( std::map<int, PlayerState>::iterator i=players.begin() ; i!=players.end();i++)
|
||||
{
|
||||
for (int j=0;j<(*i).second.heroes.size();j++)
|
||||
{
|
||||
if (i->second.heroes[j]->subID == ID)
|
||||
return i->second.heroes[j];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
public:
|
||||
friend CCallback;
|
||||
friend CLuaCallback;
|
||||
friend int _tmain(int argc, _TCHAR* argv[]);
|
||||
friend void initGameState(CGameInfo * cgi);
|
||||
friend CScriptCallback;
|
||||
//CCallback * cb; //for communication between PlayerInterface/AI and GameState
|
||||
|
||||
friend SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV<unsigned char> > > & visibilityMap); //todo: wywalic koniecznie, tylko do flag obecnie!!!!
|
||||
|
279
CLua.cpp
279
CLua.cpp
@ -1,11 +1,31 @@
|
||||
#include "stdafx.h"
|
||||
#include "CLua.h"
|
||||
#include "CLuaHandler.h"
|
||||
#include "hch/CHeroHandler.h"
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
#include "lobject.h"
|
||||
#include "lgc.h"
|
||||
#include "lapi.h"
|
||||
#include "CGameInfo.h"
|
||||
#include "CGameState.h"
|
||||
#include <sstream>
|
||||
#include "hch/CObjectHandler.h"
|
||||
#include "CCallback.h"
|
||||
#include "hch/CGeneralTextHandler.h"
|
||||
#include <sstream>
|
||||
bool getGlobalFunc(lua_State * L, std::string fname)
|
||||
{
|
||||
unsigned int hash = lua_calchash(fname.c_str(), fname.size());
|
||||
lua_pushhstring(L, hash, fname.c_str(), fname.size());
|
||||
lua_gettable(L, LUA_GLOBALSINDEX);
|
||||
return lua_isfunction(L, -1);
|
||||
}
|
||||
|
||||
CObjectScript::CObjectScript()
|
||||
{
|
||||
language == ESLan::UNDEF;
|
||||
//std::cout << "Tworze obiekt objectscript "<<this<<std::endl;
|
||||
}
|
||||
|
||||
@ -27,26 +47,30 @@ CScript::~CScript()
|
||||
CLua::CLua(std::string initpath)
|
||||
{
|
||||
opened=false;
|
||||
LST = lua_open();
|
||||
opened = true;
|
||||
LUA_OPEN_LIB(LST, luaopen_base);
|
||||
LUA_OPEN_LIB(LST, luaopen_io);
|
||||
if ((luaL_loadfile (LST, "test.lua")) == 0)
|
||||
{
|
||||
//lua_pcall (LST, 0, LUA_MULTRET, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string temp = "Cannot open script";
|
||||
temp += initpath;
|
||||
throw std::exception(temp.c_str());
|
||||
}
|
||||
open(initpath);
|
||||
}
|
||||
CLua::CLua()
|
||||
{
|
||||
//std::cout << "Tworze obiekt clua "<<this<<std::endl;
|
||||
opened=false;
|
||||
}
|
||||
void CLua::open(std::string initpath)
|
||||
{
|
||||
LST = lua_open();
|
||||
opened = true;
|
||||
LUA_OPEN_LIB(LST, luaopen_base);
|
||||
LUA_OPEN_LIB(LST, luaopen_io);
|
||||
if ((luaL_loadfile (LST, initpath.c_str())) == 0)
|
||||
{
|
||||
lua_pcall (LST, 0, LUA_MULTRET, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string temp = "Cannot open script ";
|
||||
temp += initpath;
|
||||
throw std::exception(temp.c_str());
|
||||
}
|
||||
}
|
||||
void CLua::registerCLuaCallback()
|
||||
{
|
||||
}
|
||||
@ -60,13 +84,238 @@ CLua::~CLua()
|
||||
lua_close(LST);
|
||||
}
|
||||
}
|
||||
|
||||
void CLua::findF(std::string fname)
|
||||
{
|
||||
lua_getfield(is, LUA_GLOBALSINDEX, fname.c_str()); /* function to be called */
|
||||
}
|
||||
void CLua::findF2(std::string fname)
|
||||
{
|
||||
lua_pushstring (is, fname.c_str());
|
||||
lua_gettable (is, LUA_GLOBALSINDEX);
|
||||
}
|
||||
void CLua::findFS(std::string fname)
|
||||
{
|
||||
lua_settop(is, 0);
|
||||
if (!getGlobalFunc(is,fname))
|
||||
{
|
||||
lua_settop(is, 0);
|
||||
throw new std::exception((fname + ": function not defined").c_str()); // the call is not defined
|
||||
}
|
||||
}
|
||||
#undef LST
|
||||
|
||||
CLuaObjectScript::CLuaObjectScript()
|
||||
CLuaObjectScript::CLuaObjectScript(std::string filename)
|
||||
{
|
||||
language == ESLan::LUA;
|
||||
open(filename);
|
||||
//binit = bnewobject = bonherovisit = brightext = false;
|
||||
//std::cout << "Tworze obiekt CLuaObjectScript "<<this<<std::endl;
|
||||
}
|
||||
CLuaObjectScript::~CLuaObjectScript()
|
||||
{
|
||||
//std::cout << "Usuwam obiekt CLuaObjectScript "<<this<<std::endl;
|
||||
}
|
||||
|
||||
void CLuaObjectScript::init()
|
||||
{
|
||||
}
|
||||
|
||||
std::string CLuaObjectScript::genFN(std::string base, int ID)
|
||||
{
|
||||
std::stringstream sts;
|
||||
sts<<base<<"_"<<ID;
|
||||
return sts.str();
|
||||
}
|
||||
|
||||
void CLuaObjectScript::newObject(CGObjectInstance *os)
|
||||
{
|
||||
findF(genFN("newObject",os->ID));
|
||||
lua_pushinteger(is, (int)os);
|
||||
if (lua_pcall (is, 1, 0, 0))
|
||||
{
|
||||
lua_settop(is, 0);
|
||||
throw new std::exception(("Failed to call "+genFN("newObject",os->ID)+" function in lua script.").c_str());
|
||||
}
|
||||
lua_settop(is, 0);
|
||||
return;
|
||||
}
|
||||
void CLuaObjectScript::onHeroVisit(CGObjectInstance *os, int heroID)
|
||||
{
|
||||
findF(genFN("heroVisit",os->ID));
|
||||
lua_pushinteger(is, (int)os);
|
||||
lua_pushinteger(is, heroID);
|
||||
if (lua_pcall (is, 2, 0, 0))
|
||||
{
|
||||
lua_settop(is, 0);
|
||||
throw new std::exception(("Failed to call "+genFN("heroVisit",os->ID)+" function in lua script.").c_str());
|
||||
}
|
||||
lua_settop(is, 0);
|
||||
}
|
||||
std::string CLuaObjectScript::hoverText(CGObjectInstance *os)
|
||||
{
|
||||
findF(genFN("hoverText",os->ID));
|
||||
lua_pushinteger(is, (int)os);
|
||||
if (lua_pcall (is, 1, 1, 0))
|
||||
{
|
||||
lua_settop(is, 0);
|
||||
throw new std::exception(("Failed to call "+genFN("hoverText",os->ID)+" function in lua script.").c_str());
|
||||
}
|
||||
std::string ret = lua_tostring(is,1);
|
||||
lua_settop(is, 0);
|
||||
}
|
||||
|
||||
std::string CCPPObjectScript::hoverText(CGObjectInstance *os)
|
||||
{
|
||||
return CGI->objh->objects[os->defInfo->id].name;
|
||||
}
|
||||
|
||||
void CVisitableOPH::newObject(CGObjectInstance *os)
|
||||
{
|
||||
visitors.insert
|
||||
(std::pair<CGObjectInstance*,std::set<int> >(os,std::set<int>()));
|
||||
};
|
||||
|
||||
void CVisitableOPH::onHeroVisit(CGObjectInstance *os, int heroID)
|
||||
{
|
||||
if (visitors.find(os)!=visitors.end())
|
||||
{
|
||||
if(visitors[os].find(heroID)==visitors[os].end())
|
||||
{
|
||||
onNAHeroVisit(os,heroID, false);
|
||||
visitors[os].insert(heroID);
|
||||
}
|
||||
else
|
||||
{
|
||||
onNAHeroVisit(os,heroID, true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new std::exception("Skrypt nie zainicjalizowal instancji tego obiektu. :(");
|
||||
}
|
||||
};
|
||||
void CVisitableOPH::onNAHeroVisit(CGObjectInstance *os, int heroID, bool alreadyVisited)
|
||||
{
|
||||
if (!alreadyVisited)
|
||||
{
|
||||
switch (os->ID)
|
||||
{
|
||||
case 51:
|
||||
case 23:
|
||||
case 61:
|
||||
case 32:
|
||||
{
|
||||
int w=0, ot=0;
|
||||
switch(os->ID)
|
||||
{
|
||||
case 51:
|
||||
w=0;
|
||||
ot=80;
|
||||
break;
|
||||
case 23:
|
||||
w=1;
|
||||
ot=29;
|
||||
break;
|
||||
case 61:
|
||||
w=2;
|
||||
ot=100;
|
||||
break;
|
||||
case 32:
|
||||
w=3;
|
||||
ot=59;
|
||||
break;
|
||||
}
|
||||
cb->changePrimSkill(heroID,w,1);
|
||||
std::vector<SComponent*> weko;
|
||||
weko.push_back(new SComponent(SComponent::primskill,1,1));
|
||||
cb->showInfoDialog(cb->getHeroOwner(heroID),CGI->objh->advobtxt[ot],&weko);
|
||||
for (int ii=0; ii<weko.size();ii++)
|
||||
delete weko[ii];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<int> CVisitableOPH::yourObjects()
|
||||
{
|
||||
std::vector<int> ret(4);
|
||||
ret.push_back(51);
|
||||
ret.push_back(23);
|
||||
ret.push_back(61);
|
||||
ret.push_back(32);
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::string CVisitableOPH::hoverText(CGObjectInstance *os)
|
||||
{
|
||||
std::string add;
|
||||
int pom;
|
||||
switch(os->ID)
|
||||
{
|
||||
case 51:
|
||||
pom = 8;
|
||||
break;
|
||||
case 23:
|
||||
pom = 7;
|
||||
break;
|
||||
case 61:
|
||||
pom = 11;
|
||||
break;
|
||||
case 32:
|
||||
pom = 4;
|
||||
break;
|
||||
default:
|
||||
throw new std::exception("Unsupported ID in CVisitableOPH::hoverText");
|
||||
}
|
||||
add = " " + CGI->objh->xtrainfo[pom] + " ";
|
||||
int heroID = cb->getSelectedHero();
|
||||
if (heroID>=0)
|
||||
{
|
||||
add += ( (visitors[os].find(heroID) == visitors[os].end())
|
||||
?
|
||||
(CGI->generaltexth->allTexts[353]) //not visited
|
||||
:
|
||||
( CGI->generaltexth->allTexts[352]) ); //visited
|
||||
}
|
||||
return CGI->objh->objects[os->defInfo->id].name + add;
|
||||
}
|
||||
|
||||
|
||||
//std::string SComponent::getSubtitle()
|
||||
//{
|
||||
// std::string ret;
|
||||
//
|
||||
//
|
||||
// return ret;
|
||||
//}
|
||||
//void SComponent::getDescription(Etype Type, int Subtype)
|
||||
//{
|
||||
//}
|
||||
SComponent::SComponent(Etype Type, int Subtype, int Val)
|
||||
{
|
||||
switch (Type)
|
||||
{
|
||||
case primskill:
|
||||
description = CGI->generaltexth->arraytxt[2+Subtype];
|
||||
std::ostringstream oss;
|
||||
oss << ((Val>0)?("+"):("-")) << Val << " " << CGI->heroh->pskillsn[Subtype];
|
||||
subtitle = oss.str();
|
||||
break;
|
||||
}
|
||||
type = Type;
|
||||
subtype = Subtype;
|
||||
val = Val;
|
||||
}
|
||||
|
||||
SDL_Surface * SComponent::getImg()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case primskill:
|
||||
return CGI->heroh->pskillsb[subtype].ourImages[0].bitmap;
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
86
CLua.h
86
CLua.h
@ -1,13 +1,40 @@
|
||||
#include "global.h"
|
||||
#include "lstate.h"
|
||||
#include <set>
|
||||
#include <map>
|
||||
class CLua;
|
||||
struct SDL_Surface;
|
||||
class CGObjectInstance;
|
||||
class CGameInfo;
|
||||
class CGHeroInstance;
|
||||
class CScriptCallback;
|
||||
enum ESLan{UNDEF=-1,CPP,ERM,LUA};
|
||||
class CObjectScript
|
||||
{
|
||||
public:
|
||||
int owner;
|
||||
int owner, language;
|
||||
std::string filename;
|
||||
|
||||
int getOwner(){return owner;} //255 - neutral / 254 - not flaggable
|
||||
CObjectScript();
|
||||
virtual ~CObjectScript();
|
||||
|
||||
|
||||
//functions to be called in script
|
||||
//virtual void init(){};
|
||||
virtual void newObject(CGObjectInstance *os){};
|
||||
virtual void onHeroVisit(CGObjectInstance *os, int heroID){};
|
||||
virtual std::string hoverText(CGObjectInstance *os){return "";};
|
||||
|
||||
//TODO: implement functions below:
|
||||
virtual void equipArtefact(int HID, int AID, int slot, bool putOn){}; //putOn==0 means that artifact is taken off
|
||||
virtual void battleStart(int phase){}; //phase==0 - very start, before initialization of battle; phase==1 - just before battle starts
|
||||
virtual void battleNewTurn (int turn){}; //turn==-1 is for tactic stage
|
||||
//virtual void battleAction (int type,int destination, int stack, int owner, int){};
|
||||
//virtual void mouseClick (down,left,screen?, pos??){};
|
||||
virtual void heroLevelUp (int HID){}; //add possibility of changing available sec. skills
|
||||
|
||||
|
||||
};
|
||||
class CScript
|
||||
{
|
||||
@ -18,19 +45,74 @@ public:
|
||||
|
||||
class CLua :public CScript
|
||||
{
|
||||
protected:
|
||||
lua_State * is; /// tez niebezpieczne!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ale chwilowo okielznane)
|
||||
bool opened;
|
||||
public:
|
||||
CLua(std::string initpath);
|
||||
void open(std::string initpath);
|
||||
void registerCLuaCallback();
|
||||
CLua();
|
||||
virtual ~CLua();
|
||||
|
||||
void findF(std::string fname);
|
||||
void findF2(std::string fname);
|
||||
void findFS(std::string fname);
|
||||
|
||||
|
||||
friend void initGameState(CGameInfo * cgi);
|
||||
};
|
||||
|
||||
class CLuaObjectScript : public CLua, public CObjectScript
|
||||
{
|
||||
public:
|
||||
CLuaObjectScript();
|
||||
CLuaObjectScript(std::string filename);
|
||||
virtual ~CLuaObjectScript();
|
||||
static std::string genFN(std::string base, int ID);
|
||||
|
||||
void init();
|
||||
void newObject(CGObjectInstance *os);
|
||||
void onHeroVisit(CGObjectInstance *os, int heroID);
|
||||
std::string hoverText(CGObjectInstance *os);
|
||||
|
||||
friend void initGameState(CGameInfo * cgi);
|
||||
};
|
||||
class CCPPObjectScript: public CObjectScript
|
||||
{
|
||||
protected:
|
||||
CScriptCallback * cb;
|
||||
CCPPObjectScript(CScriptCallback * CB){cb=CB;};
|
||||
public:
|
||||
virtual std::vector<int> yourObjects()=0; //returns IDs of objects which are handled by script
|
||||
virtual std::string hoverText(CGObjectInstance *os);
|
||||
};
|
||||
class CVisitableOPH : public CCPPObjectScript //once per hero
|
||||
{
|
||||
CVisitableOPH(CScriptCallback * CB):CCPPObjectScript(CB){};
|
||||
std::map<CGObjectInstance*,std::set<int> > visitors;
|
||||
|
||||
void onNAHeroVisit(CGObjectInstance *os, int heroID, bool alreadyVisited);
|
||||
void newObject(CGObjectInstance *os);
|
||||
void onHeroVisit(CGObjectInstance *os, int heroID);
|
||||
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
|
||||
std::string hoverText(CGObjectInstance *os);
|
||||
|
||||
friend void initGameState(CGameInfo * cgi);
|
||||
};
|
||||
|
||||
struct SComponent
|
||||
{
|
||||
enum Etype
|
||||
{
|
||||
primskill, secskill, resource, creature, artifact
|
||||
} type;
|
||||
int subtype;
|
||||
int val;
|
||||
|
||||
std::string description; //r-click
|
||||
std::string subtitle;
|
||||
|
||||
SComponent(Etype Type, int Subtype, int Val);
|
||||
//SComponent(const & SComponent r);
|
||||
SDL_Surface * getImg();
|
||||
};
|
@ -3,9 +3,9 @@
|
||||
#include "lua.h"
|
||||
#include "lualib.h"
|
||||
#include "lauxlib.h"
|
||||
#include <luabind/luabind.hpp>
|
||||
#include <luabind/function.hpp>
|
||||
#include <luabind/class.hpp>
|
||||
//#include <luabind/luabind.hpp>
|
||||
//#include <luabind/function.hpp>
|
||||
//#include <luabind/class.hpp>
|
||||
#include "CLuaHandler.h"
|
||||
#include "boost/filesystem.hpp"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
@ -28,27 +28,35 @@ void CLuaHandler::test()
|
||||
LUA_OPEN_LIB(lua, luaopen_base);
|
||||
LUA_OPEN_LIB(lua, luaopen_io);
|
||||
|
||||
if ((iErr = luaL_loadfile (lua, "test.lua")) == 0)
|
||||
{
|
||||
|
||||
//luabind::open(lua);
|
||||
//luabind::module(lua)
|
||||
//[
|
||||
// luabind::class_<int3>("int3")
|
||||
// //.def(luabind::constructor<>())
|
||||
// //.def(luabind::constructor<const int&,const int&,const int&>())
|
||||
// .def_readwrite("x", &int3::x)
|
||||
// .def_readwrite("y", &int3::y)
|
||||
// .def_readwrite("z", &int3::z)
|
||||
//];
|
||||
//luabind::module(lua)
|
||||
//[
|
||||
// luabind::def("powitanie",&piszpowitanie2)
|
||||
//];
|
||||
|
||||
|
||||
if ((iErr = luaL_loadfile (lua, "scripts/lua/objects/0023_marletto_tower.lua")) == 0)
|
||||
{
|
||||
// Call main...
|
||||
if ((iErr = lua_pcall (lua, 0, LUA_MULTRET, 0)) == 0)
|
||||
{
|
||||
luabind::open(lua);
|
||||
luabind::module(lua)
|
||||
[
|
||||
luabind::def("powitanie",&piszpowitanie2)
|
||||
];
|
||||
|
||||
//int ret = luabind::call_function<int>(lua, "helloWorld2");
|
||||
|
||||
lua_pushstring (lua, "helloWorld2");
|
||||
lua_gettable (lua, LUA_GLOBALSINDEX);
|
||||
lua_pcall (lua, 0, 0, 0);
|
||||
//lua_pushstring (lua, "helloWorld2");
|
||||
//lua_gettable (lua, LUA_GLOBALSINDEX);
|
||||
//lua_pcall (lua, 0, 0, 0);
|
||||
|
||||
// Push the function name onto the stack
|
||||
lua_pushstring (lua, "helloWorld");
|
||||
lua_pushstring (lua, "rightText");
|
||||
lua_gettable (lua, LUA_GLOBALSINDEX);
|
||||
lua_pcall (lua, 0, 0, 0);
|
||||
}
|
||||
@ -77,4 +85,32 @@ std::vector<std::string> * CLuaHandler::searchForScripts(std::string fol)
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
std::vector<std::string> * CLuaHandler::functionList(std::string file)
|
||||
{
|
||||
std::vector<std::string> * ret = new std::vector<std::string> ();
|
||||
char linia[500];
|
||||
std::ifstream is(file.c_str());
|
||||
while (!is.eof())
|
||||
{
|
||||
is.getline(linia,500);
|
||||
std::string ss(linia);
|
||||
boost::algorithm::trim_left(ss);
|
||||
if (boost::algorithm::starts_with(ss,"local"))
|
||||
boost::algorithm::erase_first(ss,"local ");
|
||||
if (boost::algorithm::starts_with(ss,"function"))
|
||||
{
|
||||
boost::algorithm::erase_first(ss,"function ");
|
||||
int ps = ss.find_first_of(' ');
|
||||
int op = ss.find_first_of('(');
|
||||
if (ps<0)
|
||||
ps = ss.length()-1;
|
||||
if (op<0)
|
||||
op = ss.length()-1;
|
||||
ps = std::min(ps,op);
|
||||
ret->push_back(ss.substr(0,ps));
|
||||
}
|
||||
}
|
||||
is.close();
|
||||
return ret;
|
||||
}
|
@ -14,6 +14,7 @@ public:
|
||||
CLuaHandler();
|
||||
|
||||
static std::vector<std::string> * searchForScripts(std::string fol);
|
||||
static std::vector<std::string> * functionList(std::string file);
|
||||
|
||||
~CLuaHandler();
|
||||
|
||||
|
84
CMT.cpp
84
CMT.cpp
@ -43,6 +43,7 @@
|
||||
#include "CPathfinder.h"
|
||||
#include "CGameState.h"
|
||||
#include "CCallback.h"
|
||||
#include "CPlayerInterface.h"
|
||||
#include "CLuaHandler.h"
|
||||
#include "CLua.h"
|
||||
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
|
||||
@ -58,7 +59,14 @@ const char * NAME = "VCMI 0.4 \"Vingilot\"";
|
||||
|
||||
SDL_Surface * ekran, * screen, * screen2;
|
||||
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
|
||||
|
||||
void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script)
|
||||
{
|
||||
std::vector<int> tempv = script->yourObjects();
|
||||
for (int i=0;i<tempv.size();i++)
|
||||
{
|
||||
(*mapa)[tempv[i]]=script;
|
||||
}
|
||||
}
|
||||
void initGameState(CGameInfo * cgi)
|
||||
{
|
||||
cgi->state->day=0;
|
||||
@ -67,6 +75,7 @@ void initGameState(CGameInfo * cgi)
|
||||
{
|
||||
std::pair<int,PlayerState> ins(cgi->scenarioOps.playerInfos[i].color,PlayerState());
|
||||
ins.second.color=ins.first;
|
||||
ins.second.serial=i;
|
||||
cgi->state->players.insert(ins);
|
||||
}
|
||||
/******************RESOURCES****************************************************/
|
||||
@ -98,11 +107,12 @@ void initGameState(CGameInfo * cgi)
|
||||
/*************************HEROES************************************************/
|
||||
for (int i=0; i<cgi->heroh->heroInstances.size();i++) //heroes instances
|
||||
{
|
||||
if (!cgi->heroh->heroInstances[i]->type || cgi->heroh->heroInstances[i]->state->owner<0)
|
||||
if (!cgi->heroh->heroInstances[i]->type || cgi->heroh->heroInstances[i]->getOwner()<0)
|
||||
continue;
|
||||
//CGHeroInstance * vhi = new CGHeroInstance();
|
||||
//*vhi=*(cgi->heroh->heroInstances[i]);
|
||||
CGHeroInstance * vhi = (cgi->heroh->heroInstances[i]);
|
||||
vhi->subID = vhi->type->ID;
|
||||
if (!vhi->level)
|
||||
{
|
||||
vhi->exp=40+rand()%50;
|
||||
@ -141,7 +151,7 @@ void initGameState(CGameInfo * cgi)
|
||||
vhi->army.slots[2].second = (rand()%(vhi->type->high3stack-vhi->type->low3stack))+vhi->type->low3stack;
|
||||
}
|
||||
|
||||
cgi->state->players[vhi->state->owner].heroes.push_back(vhi);
|
||||
cgi->state->players[vhi->getOwner()].heroes.push_back(vhi);
|
||||
|
||||
}
|
||||
/*************************FOG**OF**WAR******************************************/
|
||||
@ -181,7 +191,7 @@ void initGameState(CGameInfo * cgi)
|
||||
if (vti->name.length()==0) // if town hasn't name we draw it
|
||||
vti->name=vti->town->names[rand()%vti->town->names.size()];
|
||||
|
||||
cgi->state->players[vti->state->owner].towns.push_back(vti);
|
||||
cgi->state->players[vti->getOwner()].towns.push_back(vti);
|
||||
}
|
||||
|
||||
for(std::map<int, PlayerState>::iterator k=cgi->state->players.begin(); k!=cgi->state->players.end(); ++k)
|
||||
@ -202,18 +212,68 @@ void initGameState(CGameInfo * cgi)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/****************************SCRIPTS************************************************/
|
||||
std::map<int, std::map<std::string, CObjectScript*> > * skrypty = &cgi->state->objscr; //alias for easier access
|
||||
/****************************C++ OBJECT SCRIPTS************************************************/
|
||||
std::map<int,CCPPObjectScript*> scripts;
|
||||
CScriptCallback * csc = new CScriptCallback();
|
||||
handleCPPObjS(&scripts,new CVisitableOPH(csc));
|
||||
//created map
|
||||
|
||||
|
||||
|
||||
/****************************LUA OBJECT SCRIPTS************************************************/
|
||||
std::vector<std::string> * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files
|
||||
for (int i=0; i<lf->size(); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
std::vector<std::string> * temp = CLuaHandler::functionList((*lf)[i]);
|
||||
CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]);
|
||||
CLuaCallback::registerFuncs(objs->is);
|
||||
//objs
|
||||
for (int j=0; j<temp->size(); j++)
|
||||
{
|
||||
int obid ; //obj ID
|
||||
int dspos = (*temp)[j].find_first_of('_');
|
||||
obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str());
|
||||
std::string fname = (*temp)[j].substr(0,dspos);
|
||||
if (skrypty->find(obid)==skrypty->end())
|
||||
skrypty->insert(std::pair<int, std::map<std::string, CObjectScript*> >(obid,std::map<std::string,CObjectScript*>()));
|
||||
(*skrypty)[obid].insert(std::pair<std::string, CObjectScript*>(fname,objs));
|
||||
}
|
||||
delete temp;
|
||||
}HANDLE_EXCEPTION
|
||||
}
|
||||
/****************************INITIALIZING OBJECT SCRIPTS************************************************/
|
||||
std::string temps("newObject");
|
||||
for (int i=0; i<CGI->objh->objInstances.size(); i++)
|
||||
{
|
||||
//c++ scripts
|
||||
if (scripts.find(CGI->objh->objInstances[i]->ID) != scripts.end())
|
||||
{
|
||||
CGI->objh->objInstances[i]->state = scripts[CGI->objh->objInstances[i]->ID];
|
||||
CGI->objh->objInstances[i]->state->newObject(CGI->objh->objInstances[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
CGI->objh->objInstances[i]->state = NULL;
|
||||
}
|
||||
|
||||
// lua scripts
|
||||
if(cgi->state->checkFunc(CGI->objh->objInstances[i]->ID,temps))
|
||||
(*skrypty)[CGI->objh->objInstances[i]->ID][temps]->newObject(CGI->objh->objInstances[i]);
|
||||
}
|
||||
|
||||
delete lf;
|
||||
}
|
||||
|
||||
int _tmain(int argc, _TCHAR* argv[])
|
||||
{
|
||||
|
||||
CLuaHandler luatest;
|
||||
luatest.test();
|
||||
CLuaHandler::searchForScripts("scripts");
|
||||
CLua * lua = new CLua("test.lua");
|
||||
|
||||
|
||||
|
||||
//CLuaHandler luatest;
|
||||
//luatest.test();
|
||||
|
||||
//CBIKHandler cb;
|
||||
//cb.open("CSECRET.BIK");
|
||||
THC timeHandler tmh;
|
||||
|
124
CMessage.cpp
124
CMessage.cpp
@ -8,12 +8,13 @@
|
||||
#include "hch\CLodHandler.h"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include "CGameInterface.h"
|
||||
#include "CPlayerInterface.h"
|
||||
#include "hch\CDefHandler.h"
|
||||
#include "hch\CSemiDefHandler.h"
|
||||
#include "CGameInfo.h"
|
||||
#include "SDL_Extensions.h"
|
||||
#include <sstream>
|
||||
#include "CLua.h"
|
||||
SDL_Color tytulowy, tlo, zwykly ;
|
||||
SDL_Rect genRect(int hh, int ww, int xx, int yy);
|
||||
|
||||
@ -28,6 +29,7 @@ using namespace NMessage;
|
||||
|
||||
namespace NMessage
|
||||
{
|
||||
CDefHandler * ok, *cancel;
|
||||
std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
|
||||
SDL_Surface * background = NULL;
|
||||
}
|
||||
@ -61,6 +63,8 @@ void CMessage::init()
|
||||
NMessage::background = CGI->bitmaph->loadBitmap("DIBOXBCK.BMP");
|
||||
SDL_SetColorKey(background,SDL_SRCCOLORKEY,SDL_MapRGB(background->format,0,255,255));
|
||||
}
|
||||
ok = CGI->spriteh->giveDef("IOKAY.DEF");
|
||||
cancel = CGI->spriteh->giveDef("ICANCEL.DEF");
|
||||
}
|
||||
|
||||
|
||||
@ -74,6 +78,8 @@ void CMessage::dispose()
|
||||
}
|
||||
}
|
||||
SDL_FreeSurface(background);
|
||||
delete ok;
|
||||
delete cancel;
|
||||
}
|
||||
SDL_Surface * CMessage::drawBox1(int w, int h, int playerColor)
|
||||
{
|
||||
@ -176,13 +182,29 @@ std::vector<std::string> * CMessage::breakText(std::string text, int line, bool
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int Rmar, int Tmar, int Bmar)
|
||||
std::pair<int,int> CMessage::getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg)
|
||||
{
|
||||
CSimpleWindow * ret = new CSimpleWindow();
|
||||
std::vector<std::string> * brtext = breakText(text,32,true,true);
|
||||
std::vector<std::vector<SDL_Surface*> > txtg;
|
||||
txtg.resize(brtext->size());
|
||||
std::pair<int,int> ret;
|
||||
ret.first = -1;
|
||||
ret.second=0;
|
||||
for (int i=0; i<txtg->size();i++) //szukamy najszerszej linii i lacznej wysokosci
|
||||
{
|
||||
int lw=0;
|
||||
for (int j=0;j<(*txtg)[i].size();j++)
|
||||
{
|
||||
lw+=(*txtg)[i][j]->w;
|
||||
ret.second+=(*txtg)[i][j]->h;
|
||||
}
|
||||
if (ret.first<lw)
|
||||
ret.first=lw;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::vector<std::vector<SDL_Surface*> > * CMessage::drawText(std::vector<std::string> * brtext)
|
||||
{
|
||||
std::vector<std::vector<SDL_Surface*> > * txtg = new std::vector<std::vector<SDL_Surface*> >();
|
||||
txtg->resize(brtext->size());
|
||||
for (int i=0; i<brtext->size();i++) //foreach line
|
||||
{
|
||||
while((*brtext)[i].length()) //jesli zostalo cos
|
||||
@ -200,7 +222,7 @@ CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int
|
||||
if (!br)
|
||||
z++;
|
||||
if (z)
|
||||
txtg[i].push_back(TTF_RenderText_Blended(TNRB16,(*brtext)[i].substr(0,z).c_str(),zwykly));
|
||||
(*txtg)[i].push_back(TTF_RenderText_Blended(TNRB16,(*brtext)[i].substr(0,z).c_str(),zwykly));
|
||||
(*brtext)[i].erase(0,z);
|
||||
z=0;
|
||||
if ( ((*brtext)[i].length()==0) || ((*brtext)[i][z]!='{') )
|
||||
@ -210,49 +232,91 @@ CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int
|
||||
while( ((*brtext)[i][++z]) != ('}') )
|
||||
{}
|
||||
//tyemp = (*brtext)[i].substr(1,z-1); //od 1 bo pomijamy otwierajaca klamre
|
||||
txtg[i].push_back(TTF_RenderText_Blended(TNRB16,(*brtext)[i].substr(1,z-1).c_str(),tytulowy));
|
||||
(*txtg)[i].push_back(TTF_RenderText_Blended(TNRB16,(*brtext)[i].substr(1,z-1).c_str(),tytulowy));
|
||||
(*brtext)[i].erase(0,z+1); //z+1 bo dajemy zamykajaca klamre
|
||||
} //ends while((*brtext)[i].length())
|
||||
} //ends for(int i=0; i<brtext->size();i++)
|
||||
int max = -1, lh=0;
|
||||
for (int i=0; i<txtg.size();i++) //szukamy najszerszej linii i lacznej wysokosci
|
||||
{
|
||||
int lw=0;
|
||||
for (int j=0;j<txtg[i].size();j++)
|
||||
{
|
||||
lw+=txtg[i][j]->w;
|
||||
lh+=txtg[i][j]->h;
|
||||
}
|
||||
if (max<lw)
|
||||
max=lw;
|
||||
}
|
||||
ret->bitmap = drawBox1(max+Lmar+Rmar,lh+Tmar+Bmar,0);
|
||||
return txtg;
|
||||
}
|
||||
CSimpleWindow * CMessage::genWindow(std::string text, int player, int Lmar, int Rmar, int Tmar, int Bmar)
|
||||
{
|
||||
CSimpleWindow * ret = new CSimpleWindow();
|
||||
std::vector<std::string> * brtext = breakText(text,32,true,true);
|
||||
std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
|
||||
std::pair<int,int> txts = getMaxSizes(txtg);
|
||||
ret->bitmap = drawBox1(txts.first+Lmar+Rmar,txts.second+Tmar+Bmar,0);
|
||||
ret->pos.h=ret->bitmap->h;
|
||||
ret->pos.w=ret->bitmap->w;
|
||||
for (int i=0; i<txtg.size();i++)
|
||||
for (int i=0; i<txtg->size();i++)
|
||||
{
|
||||
int lw=0;
|
||||
for (int j=0;j<txtg[i].size();j++)
|
||||
lw+=txtg[i][j]->w;
|
||||
for (int j=0;j<(*txtg)[i].size();j++)
|
||||
lw+=(*txtg)[i][j]->w;
|
||||
int pw = ret->bitmap->w/2, ph = ret->bitmap->h/2;
|
||||
//int pw = Tmar, ph = Lmar;
|
||||
pw -= lw/2;
|
||||
ph -= (19*txtg.size())/2;
|
||||
ph -= (19*txtg->size())/2;
|
||||
|
||||
int tw = pw;
|
||||
for (int j=0;j<txtg[i].size();j++)
|
||||
for (int j=0;j<(*txtg)[i].size();j++)
|
||||
{
|
||||
//std::stringstream n;
|
||||
//n <<"temp_"<<i<<"__"<<j<<".bmp";
|
||||
blitAt(txtg[i][j],tw,ph+i*19,ret->bitmap);
|
||||
blitAt((*txtg)[i][j],tw,ph+i*19,ret->bitmap);
|
||||
//SDL_SaveBMP(ret->bitmap,n.str().c_str());
|
||||
tw+=txtg[i][j]->w;
|
||||
SDL_FreeSurface(txtg[i][j]);
|
||||
tw+=(*txtg)[i][j]->w;
|
||||
SDL_FreeSurface((*txtg)[i][j]);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
CInfoWindow * CMessage::genIWindow(std::string text, int player, int charperline, std::vector<SComponent*> & comps)
|
||||
{
|
||||
//TODO: support for more than one component
|
||||
CInfoWindow * ret = new CInfoWindow();
|
||||
|
||||
std::vector<std::string> * brtext = breakText(text,32,true,true);
|
||||
std::vector<std::string> * brdtext = breakText(comps[0]->subtitle,12,true,true);
|
||||
std::vector<std::vector<SDL_Surface*> > * txtg = drawText(brtext);
|
||||
std::pair<int,int> txts = getMaxSizes(txtg);
|
||||
txts.second = txts.second
|
||||
+ 30 //space to first component
|
||||
+ comps[0]->getImg()->h
|
||||
+ brdtext->size() * 10 //subtitle //!!!!!!!!!!!!!!!!!!!!
|
||||
+ 20 // space between subtitle and button
|
||||
+ ok->ourImages[0].bitmap->h //button
|
||||
+ 30; //after button
|
||||
ret->bitmap = drawBox1(txts.first+70,txts.second+70,0);
|
||||
ret->pos.h=ret->bitmap->h;
|
||||
ret->pos.w=ret->bitmap->w;
|
||||
|
||||
|
||||
//for (int i=0; i<txtg->size();i++)
|
||||
//{
|
||||
// int lw=0;
|
||||
// for (int j=0;j<(*txtg)[i].size();j++)
|
||||
// lw+=(*txtg)[i][j]->w;
|
||||
// int pw = ret->bitmap->w/2, ph = ret->bitmap->h/2;
|
||||
// //int pw = Tmar, ph = Lmar;
|
||||
// pw -= lw/2;
|
||||
// ph -= (19*txtg->size())/2;
|
||||
|
||||
// int tw = pw;
|
||||
// for (int j=0;j<(*txtg)[i].size();j++)
|
||||
// {
|
||||
// //std::stringstream n;
|
||||
// //n <<"temp_"<<i<<"__"<<j<<".bmp";
|
||||
// blitAt((*txtg)[i][j],tw,ph+i*19,ret->bitmap);
|
||||
// //SDL_SaveBMP(ret->bitmap,n.str().c_str());
|
||||
// tw+=(*txtg)[i][j]->w;
|
||||
// SDL_FreeSurface((*txtg)[i][j]);
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SDL_Surface * CMessage::genMessage
|
||||
(std::string title, std::string text, EWindowType type, std::vector<CDefHandler*> *addPics, void * cb)
|
||||
|
@ -8,7 +8,9 @@ enum EWindowType {infoOnly, infoOK, yesOrNO};
|
||||
class CPreGame;
|
||||
class MapSel;
|
||||
class CSimpleWindow;
|
||||
class CInfoWindow;
|
||||
class CDefHandler;
|
||||
struct SComponent;
|
||||
namespace NMessage
|
||||
{
|
||||
extern std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
|
||||
@ -18,6 +20,10 @@ namespace NMessage
|
||||
class CMessage
|
||||
{
|
||||
public:
|
||||
|
||||
static std::pair<int,int> getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg);
|
||||
static std::vector<std::vector<SDL_Surface*> > * drawText(std::vector<std::string> * brtext);
|
||||
static CInfoWindow * genIWindow(std::string text, int player, int charperline, std::vector<SComponent*> & comps);
|
||||
static CSimpleWindow * genWindow(std::string text, int player, int Lmar=35, int Rmar=35, int Tmar=35, int Bmar=35);//supports h3 text formatting; player sets color of window, Lmar/Rmar/Tmar/Bmar are Left/Right/Top/Bottom margins
|
||||
static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly,
|
||||
std::vector<CDefHandler*> *addPics=NULL, void * cb=NULL);
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "CGameInfo.h"
|
||||
#include "hch\CAmbarCendamo.h"
|
||||
#include "mapHandler.h"
|
||||
using namespace boost::logic;
|
||||
int3 CPath::startPos()
|
||||
{
|
||||
return int3(nodes[nodes.size()-1].coord.x,nodes[nodes.size()-1].coord.y,nodes[nodes.size()-1].coord.z);
|
||||
|
@ -1,6 +1,6 @@
|
||||
#ifndef CPATHFINDER_H
|
||||
#define CPATHFINDER_H
|
||||
#include "int3.h"
|
||||
#include "global.h"
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
class CHeroInstance;
|
||||
|
1067
CPlayerInterface.cpp
Normal file
1067
CPlayerInterface.cpp
Normal file
File diff suppressed because it is too large
Load Diff
127
CPlayerInterface.h
Normal file
127
CPlayerInterface.h
Normal file
@ -0,0 +1,127 @@
|
||||
#pragma once
|
||||
#include "global.h"
|
||||
#include "CGameInterface.h"
|
||||
#include "SDL.h"
|
||||
#include "SDL_framerate.h"
|
||||
class CDefEssential;
|
||||
|
||||
class CHeroInstance;
|
||||
class CDefHandler;
|
||||
struct HeroMoveDetails;
|
||||
class CDefEssential;
|
||||
class CGHeroInstance;
|
||||
struct SComponent;
|
||||
class CIntObject //interface object
|
||||
{
|
||||
public:
|
||||
SDL_Rect pos;
|
||||
int ID;
|
||||
};
|
||||
class CSimpleWindow : public virtual CIntObject
|
||||
{
|
||||
public:
|
||||
SDL_Surface * bitmap;
|
||||
CIntObject * owner;
|
||||
CSimpleWindow():bitmap(NULL),owner(NULL){};
|
||||
virtual ~CSimpleWindow();
|
||||
};
|
||||
class CInfoWindow : public CSimpleWindow //text + comp. + ok button
|
||||
{
|
||||
public:
|
||||
std::vector<SComponent *> components;
|
||||
CInfoWindow(){};
|
||||
};
|
||||
class CButtonBase : public virtual CIntObject //basic buttton class
|
||||
{
|
||||
public:
|
||||
int type; //advmapbutton=2
|
||||
bool abs;
|
||||
bool active;
|
||||
CIntObject * ourObj;
|
||||
int state;
|
||||
std::vector< std::vector<SDL_Surface*> > imgs;
|
||||
int curimg;
|
||||
virtual void show() ;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
CButtonBase();
|
||||
};
|
||||
class ClickableL : public virtual CIntObject //for left-clicks
|
||||
{
|
||||
public:
|
||||
bool pressedL;
|
||||
ClickableL();
|
||||
virtual void clickLeft (tribool down)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
class ClickableR : public virtual CIntObject //for right-clicks
|
||||
{
|
||||
public:
|
||||
bool pressedR;
|
||||
ClickableR();
|
||||
virtual void clickRight (tribool down)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
class Hoverable : public virtual CIntObject
|
||||
{
|
||||
public:
|
||||
Hoverable(){hovered=false;}
|
||||
bool hovered;
|
||||
virtual void hover (bool on)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
class KeyInterested : public virtual CIntObject
|
||||
{
|
||||
public:
|
||||
virtual void keyPressed (SDL_KeyboardEvent & key)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
class MotionInterested: public virtual CIntObject
|
||||
{
|
||||
public:
|
||||
virtual void mouseMoved (SDL_MouseMotionEvent & sEvent)=0;
|
||||
virtual void activate()=0;
|
||||
virtual void deactivate()=0;
|
||||
};
|
||||
class CPlayerInterface : public CGameInterface
|
||||
{
|
||||
public:
|
||||
bool makingTurn;
|
||||
SDL_Event * current;
|
||||
CAdvMapInt * adventureInt;
|
||||
FPSmanager * mainFPSmng;
|
||||
//TODO: town interace, battle interface, other interfaces
|
||||
|
||||
CCallback * cb;
|
||||
|
||||
std::vector<ClickableL*> lclickable;
|
||||
std::vector<ClickableR*> rclickable;
|
||||
std::vector<Hoverable*> hoverable;
|
||||
std::vector<KeyInterested*> keyinterested;
|
||||
std::vector<MotionInterested*> motioninterested;
|
||||
std::vector<CSimpleWindow*> objsToBlit;
|
||||
|
||||
SDL_Surface * hInfo;
|
||||
std::vector<std::pair<int, int> > slotsPos;
|
||||
CDefEssential *luck22, *luck30, *luck42, *luck82,
|
||||
*morale22, *morale30, *morale42, *morale82;
|
||||
|
||||
//overloaded funcs from Interface
|
||||
void yourTurn();
|
||||
void heroMoved(const HeroMoveDetails & details);
|
||||
void heroKilled(const CGHeroInstance*);
|
||||
void heroCreated(const CGHeroInstance*);
|
||||
void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val);
|
||||
|
||||
SDL_Surface * infoWin(const void * specific); //specific=0 => draws info about selected town/hero //TODO - gdy sie dorobi sensowna hierarchie klas ins. to wywalic tego brzydkiego void*
|
||||
void handleEvent(SDL_Event * sEvent);
|
||||
void init(CCallback * CB);
|
||||
int3 repairScreenPos(int3 pos);
|
||||
void showInfoDialog(std::string text, std::vector<SComponent*> components);
|
||||
|
||||
CPlayerInterface(int Player, int serial);
|
||||
};
|
11
global.h
11
global.h
@ -3,6 +3,7 @@
|
||||
#define CHECKTIME 1
|
||||
#if CHECKTIME
|
||||
#include "timeHandler.h"
|
||||
#include <boost/logic/tribool.hpp>
|
||||
#include "int3.h"
|
||||
#include <iostream>
|
||||
#define THC
|
||||
@ -48,4 +49,14 @@ const int NAMES_PER_TOWN=16;
|
||||
|
||||
#define DEFBYPASS
|
||||
|
||||
#define HANDLE_EXCEPTION \
|
||||
catch (const std::exception& e) { \
|
||||
std::cerr << e.what() << std::endl; \
|
||||
} \
|
||||
catch (const std::exception * e) \
|
||||
{ \
|
||||
std::cerr << e->what()<< std::endl; \
|
||||
delete e; \
|
||||
}
|
||||
|
||||
#endif //GLOBAL_H
|
@ -573,7 +573,7 @@ void CAmbarCendamo::deh3m()
|
||||
//nobj->isHero = false;
|
||||
//nobj->moveDir = 0;
|
||||
//nobj->isStanding = true;
|
||||
nobj->state->owner = 254; //a lot of objs will never have an owner
|
||||
//nobj->state->owner = 254; //a lot of objs will never have an owner
|
||||
|
||||
//if (((nobj.x==0)&&(nobj.y==0)) || nobj.x>map.width || nobj.y>map.height || nobj.z>1 || nobj.defNumber>map.defy.size())
|
||||
// std::cout << "Alarm!!! Obiekt "<<ww<<" jest kopniety (lub wystaje poza mape)\n";
|
||||
@ -921,7 +921,6 @@ void CAmbarCendamo::deh3m()
|
||||
|
||||
}
|
||||
i+=16;
|
||||
nobj->state->owner = spec->player;
|
||||
nobj->info = spec;
|
||||
//////creating CHeroInstance
|
||||
CGHeroInstance * nhi = new CGHeroInstance;
|
||||
@ -941,7 +940,7 @@ void CAmbarCendamo::deh3m()
|
||||
nhi->mana = spec->knowledge * 10;
|
||||
nhi->movement = -1;
|
||||
nhi->name = spec->name;
|
||||
nhi->state->owner = spec->player;
|
||||
nhi->setOwner(spec->player);
|
||||
nhi->pos = nobj->pos;
|
||||
nhi->type = spec->type;
|
||||
nhi->army = spec->garrison;
|
||||
@ -1347,7 +1346,7 @@ void CAmbarCendamo::deh3m()
|
||||
else
|
||||
spec->movableUnits = true;
|
||||
i+=8;
|
||||
nobj->state->owner = spec->player;
|
||||
nobj->setOwner(spec->player);
|
||||
nobj->info = spec;
|
||||
break;
|
||||
}
|
||||
@ -1545,7 +1544,6 @@ void CAmbarCendamo::deh3m()
|
||||
else
|
||||
spec->alignment = 0xff;
|
||||
i+=3;
|
||||
nobj->state->owner = spec->player;
|
||||
nobj->info = spec;
|
||||
//////////// rewriting info to CTownInstance class /////////////////////
|
||||
CGTownInstance * nt = new CGTownInstance();
|
||||
@ -1553,7 +1551,7 @@ void CAmbarCendamo::deh3m()
|
||||
delete nobj;
|
||||
nobj = nt;
|
||||
|
||||
nt->state->owner = spec->player;
|
||||
nt->setOwner(spec->player);
|
||||
nt->town = &CGI->townh->towns[CTownHandler::getTypeByDefName(nobj->defInfo->name)];
|
||||
nt->builded = 0;
|
||||
nt->destroyed = 0;
|
||||
@ -1574,7 +1572,7 @@ void CAmbarCendamo::deh3m()
|
||||
CPlayerOnlyObjInfo * spec = new CPlayerOnlyObjInfo;
|
||||
spec->player = bufor[i]; ++i;
|
||||
i+=3;
|
||||
nobj->state->owner = spec->player;
|
||||
nobj->setOwner(spec->player);
|
||||
nobj->info = spec;
|
||||
break;
|
||||
}
|
||||
@ -1692,7 +1690,7 @@ void CAmbarCendamo::deh3m()
|
||||
{
|
||||
spec->asCastle = true;
|
||||
}
|
||||
nobj->state->owner = spec->player;
|
||||
nobj->setOwner(spec->player);
|
||||
nobj->info = spec;
|
||||
break;
|
||||
}
|
||||
@ -1721,7 +1719,7 @@ void CAmbarCendamo::deh3m()
|
||||
spec->maxLevel = 7;
|
||||
if(spec->minLevel<1)
|
||||
spec->minLevel = 1;
|
||||
nobj->state->owner = spec->player;
|
||||
nobj->setOwner(spec->player);
|
||||
nobj->info = spec;
|
||||
break;
|
||||
}
|
||||
@ -1736,7 +1734,7 @@ void CAmbarCendamo::deh3m()
|
||||
spec->maxLevel = 7;
|
||||
if(spec->minLevel<1)
|
||||
spec->minLevel = 1;
|
||||
nobj->state->owner = spec->player;
|
||||
nobj->setOwner(spec->player);
|
||||
nobj->info = spec;
|
||||
break;
|
||||
}
|
||||
|
@ -4,7 +4,10 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include "CDefHandler.h"
|
||||
|
||||
class CDefHandler;
|
||||
struct SDL_Surface;
|
||||
//#include "CDefHandler.h"
|
||||
|
||||
class CCreature
|
||||
{
|
||||
|
@ -21,6 +21,20 @@ void CGeneralTextHandler::load()
|
||||
loadToIt(buflet, buf, i, 2);
|
||||
allTexts.push_back(buflet);
|
||||
}
|
||||
|
||||
|
||||
std::string strs = CGI->bitmaph->getTextFile("ARRAYTXT.TXT");
|
||||
int itr=0;
|
||||
while(itr<strs.length()-1)
|
||||
{
|
||||
std::string tmp;
|
||||
CGeneralTextHandler::loadToIt(tmp, strs, itr, 3);
|
||||
arraytxt.push_back(tmp);
|
||||
}
|
||||
|
||||
//std::ofstream ofs("arraytxts.txt");
|
||||
//for (int i=0;i<arraytxt.size();i++)
|
||||
// ofs << i <<".\t" << arraytxt[i] << std::endl<< std::endl;
|
||||
/*loadToIt(cantAddManager, buf, i, 2);
|
||||
loadToIt(experienceLimitScenarioReached, buf, i, 2);
|
||||
loadToIt(heroExperienceInfo, buf, i, 2);
|
||||
|
@ -8,6 +8,8 @@ class CGeneralTextHandler //Handles general texts
|
||||
{
|
||||
public:
|
||||
std::vector<std::string> allTexts;
|
||||
|
||||
std::vector<std::string> arraytxt;
|
||||
/*std::string cantAddManager, experienceLimitScenarioReached, heroExperienceInfo, perDay, or, somethingVanquished, lastTownLostInfo, heroesAbandonedYou, heroesAbandonedHim;
|
||||
std::string couldNotSaveGame, errorOpeningFile, newgameUppercase, sureToDismissArmy, playersTurn, errorReceivingDataKeepTrying, somethingTheSomething, recruit, noRoomInGarrision, numberOFAdventuringHeroes, heroWithoutCreatures;
|
||||
std::string videoQuality, itemCantBeTraded, sureDismissHero, selectSpellTarget, invalidTeleportDestination, teleportHere, castSomething, castSomethingOnSomething, sureRetreat, notEnoughGold, capturedEnemyArtifact, none;
|
||||
|
@ -39,6 +39,16 @@ void CHeroHandler::loadPortraits()
|
||||
|
||||
}
|
||||
of.close();
|
||||
pskillsb = CGI->spriteh->giveDef("PSKILL.DEF");
|
||||
|
||||
std::string strs = CGI->bitmaph->getTextFile("PRISKILL.TXT");
|
||||
int itr=0;
|
||||
for (int i=0; i<PRIMARY_SKILLS; i++)
|
||||
{
|
||||
std::string tmp;
|
||||
CGeneralTextHandler::loadToIt(tmp, strs, itr, 3);
|
||||
pskillsn.push_back(tmp);
|
||||
}
|
||||
}
|
||||
void CHeroHandler::loadHeroes()
|
||||
{
|
||||
|
@ -88,13 +88,15 @@ public:
|
||||
std::vector<CGHeroInstance *> heroInstances;
|
||||
std::vector<CHero*> heroes; //by³o nodrze
|
||||
std::vector<CHeroClass *> heroClasses;
|
||||
std::vector<CDefHandler *> flags1, flags2, flags3, flags4; //flags blitted on heroes when
|
||||
std::vector<CDefHandler *> flags1, flags2, flags3, flags4; //flags blitted on heroes when ,
|
||||
CDefHandler * pskillsb; //82x93
|
||||
std::vector<std::string> pskillsn;
|
||||
unsigned int level(unsigned int experience);
|
||||
void loadHeroes();
|
||||
void loadSpecialAbilities();
|
||||
void loadBiographies();
|
||||
void loadHeroClasses();
|
||||
void loadPortraits();
|
||||
void loadPortraits(); //loads also imgs and names of primary skills
|
||||
void initHeroClasses();
|
||||
~CHeroHandler();
|
||||
void initTerrainCosts();
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "../mapHandler.h"
|
||||
#include "CDefObjInfoHandler.h"
|
||||
#include "../CLua.h"
|
||||
#include "CHeroHandler.h"
|
||||
void CObjectHandler::loadObjects()
|
||||
{
|
||||
int ID=0;
|
||||
@ -20,6 +21,25 @@ void CObjectHandler::loadObjects()
|
||||
nobj.name = nobj.name.substr(0, nobj.name.size()-1);
|
||||
objects.push_back(nobj);
|
||||
}
|
||||
|
||||
buf = CGameInfo::mainObj->bitmaph->getTextFile("ADVEVENT.TXT");
|
||||
it=0;
|
||||
std::string temp;
|
||||
while (it<buf.length()-1)
|
||||
{
|
||||
CGeneralTextHandler::loadToIt(temp,buf,it,3);
|
||||
advobtxt.push_back(temp);
|
||||
}
|
||||
|
||||
buf = CGameInfo::mainObj->bitmaph->getTextFile("XTRAINFO.TXT");
|
||||
it=0;
|
||||
temp;
|
||||
while (it<buf.length()-1)
|
||||
{
|
||||
CGeneralTextHandler::loadToIt(temp,buf,it,3);
|
||||
xtrainfo.push_back(temp);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
bool CObjectInstance::operator <(const CObjectInstance &cmp) const
|
||||
@ -71,7 +91,18 @@ bool CGObjectInstance::isHero() const
|
||||
}
|
||||
int CGObjectInstance::getOwner() const
|
||||
{
|
||||
return state->getOwner();
|
||||
//if (state)
|
||||
// return state->owner;
|
||||
//else
|
||||
return tempOwner; //won't have owner
|
||||
}
|
||||
|
||||
void CGObjectInstance::setOwner(int ow)
|
||||
{
|
||||
//if (state)
|
||||
// state->owner = ow;
|
||||
//else
|
||||
tempOwner = ow;
|
||||
}
|
||||
int CGObjectInstance::getWidth() const//returns width of object graphic in tiles
|
||||
{
|
||||
@ -112,7 +143,6 @@ bool CGObjectInstance::operator<(const CGObjectInstance & cmp) const //screen p
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CGDefInfo::isVisitable()
|
||||
{
|
||||
for (int i=0; i<6; i++)
|
||||
@ -122,7 +152,6 @@ bool CGDefInfo::isVisitable()
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool CGHeroInstance::isHero() const
|
||||
{
|
||||
@ -213,22 +242,24 @@ CGTownInstance::CGTownInstance()
|
||||
builded=-1;
|
||||
destroyed=-1;
|
||||
garrisonHero=NULL;
|
||||
state->owner=-1;
|
||||
//state->owner=-1;
|
||||
town=NULL;
|
||||
}
|
||||
|
||||
CGObjectInstance::CGObjectInstance()
|
||||
{
|
||||
//std::cout << "Tworze obiekt "<<this<<std::endl;
|
||||
state = new CLuaObjectScript();
|
||||
//state = new CLuaObjectScript();
|
||||
//state = NULL;
|
||||
defObjInfoNumber = -1;
|
||||
tempOwner = 254;
|
||||
}
|
||||
CGObjectInstance::~CGObjectInstance()
|
||||
{
|
||||
//std::cout << "Usuwam obiekt "<<this<<std::endl;
|
||||
if (state)
|
||||
delete state;
|
||||
state=NULL;
|
||||
//if (state)
|
||||
// delete state;
|
||||
//state=NULL;
|
||||
}
|
||||
|
||||
CGHeroInstance::~CGHeroInstance()
|
||||
@ -246,8 +277,10 @@ CGObjectInstance::CGObjectInstance(const CGObjectInstance & right)
|
||||
defInfo = right.defInfo;
|
||||
info = right.info;
|
||||
defObjInfoNumber = right.defObjInfoNumber;
|
||||
state = new CLuaObjectScript();
|
||||
*state = *right.state;
|
||||
//state = new CLuaObjectScript(right.state->);
|
||||
//*state = *right.state;
|
||||
//state = right.state;
|
||||
tempOwner = right.tempOwner;
|
||||
}
|
||||
CGObjectInstance& CGObjectInstance::operator=(const CGObjectInstance & right)
|
||||
{
|
||||
@ -259,6 +292,7 @@ CGObjectInstance& CGObjectInstance::operator=(const CGObjectInstance & right)
|
||||
info = right.info;
|
||||
defObjInfoNumber = right.defObjInfoNumber;
|
||||
//state = new CLuaObjectScript();
|
||||
*state = *right.state;
|
||||
//*state = *right.state;
|
||||
tempOwner = right.tempOwner;
|
||||
return *this;
|
||||
}
|
@ -1,13 +1,15 @@
|
||||
#ifndef COBJECTHANDLER_H
|
||||
#define COBJECTHANDLER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "CCreatureHandler.h"
|
||||
#include "CArtHandler.h"
|
||||
#include "CAbilityHandler.h"
|
||||
#include "CSpellHandler.h"
|
||||
#include "CHeroHandler.h"
|
||||
//#include "CHeroHandler.h"
|
||||
using boost::logic::tribool;
|
||||
class CCPPObjectScript;
|
||||
class CGObjectInstance;
|
||||
class CScript;
|
||||
class CObjectScript;
|
||||
class CGHeroInstance;
|
||||
@ -330,6 +332,29 @@ public:
|
||||
bool isVisitable();
|
||||
};
|
||||
|
||||
//class CObjectType
|
||||
//{
|
||||
//public:
|
||||
// CGObjectInstance * ourObj;
|
||||
// int type;
|
||||
// int owner; //254 - can't be flagged; 255 - neutral
|
||||
////};
|
||||
//class IVisitable
|
||||
//{
|
||||
// virtual void newObject(CGObjectInstance *os);
|
||||
// virtual void onHeroVisit(CGObjectInstance *os, int heroID);
|
||||
// virtual void getRightText(tribool visited);
|
||||
// virtual void getHoverText(tribool visited);
|
||||
//};
|
||||
//
|
||||
//class CVisitableOPH //object visitable once per hero
|
||||
//{
|
||||
// virtual void newObject(CGObjectInstance *os);
|
||||
// virtual void onHeroVisit(CGObjectInstance *os, int heroID);
|
||||
// virtual void getRightText(tribool visited);
|
||||
// virtual void getHoverText(tribool visited);
|
||||
//};
|
||||
|
||||
class CGObjectInstance
|
||||
{
|
||||
public:
|
||||
@ -337,12 +362,15 @@ public:
|
||||
int ID, subID; //normal ID (this one from OH3 maps ;])
|
||||
int id;//number of object in CObjectHandler's vector
|
||||
CGDefInfo * defInfo;
|
||||
CObjectScript * state;
|
||||
CCPPObjectScript * state;
|
||||
CSpecObjInfo * info;
|
||||
int defObjInfoNumber;
|
||||
|
||||
int tempOwner; //uzywane dla szybkosci, skrypt ma obowiazek aktualizowac te zmienna
|
||||
|
||||
virtual bool isHero() const;
|
||||
int getOwner() const;
|
||||
void setOwner(int ow);
|
||||
int getWidth() const; //returns width of object graphic in tiles
|
||||
int getHeight() const; //returns height of object graphic in tiles
|
||||
bool visitableAt(int x, int y) const; //returns true if ibject is visitable at location (x, y) form left top tile of image (x, y in tiles)
|
||||
@ -418,6 +446,9 @@ public:
|
||||
std::vector<CObject> objects; //vector of objects; i-th object in vector has subnumber i
|
||||
std::vector<CGObjectInstance*> objInstances; //vector with objects on map
|
||||
void loadObjects();
|
||||
|
||||
std::vector<std::string> advobtxt;
|
||||
std::vector<std::string> xtrainfo;
|
||||
};
|
||||
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <algorithm>
|
||||
#include "CGameState.h"
|
||||
#include "CLua.h"
|
||||
#include "hch/CHeroHandler.h"
|
||||
extern SDL_Surface * ekran;
|
||||
|
||||
class OCM_HLP
|
||||
@ -1383,14 +1384,15 @@ std::vector < std::string > CMapHandler::getObjDescriptions(int3 pos)
|
||||
std::vector<std::string> ret;
|
||||
for(int g=0; g<objs.size(); ++g)
|
||||
{
|
||||
if( (5-(objs[g].first->pos.y-pos.y)) >= 0 && (5-(objs[g].first->pos.y-pos.y)) < 6 && (objs[g].first->pos.x-pos.x) >= 0 && (objs[g].first->pos.x-pos.x)<7 && objs[g].first->defObjInfoNumber!=-1 &&
|
||||
(((CGI->dobjinfo->objs[objs[g].first->defObjInfoNumber].blockMap[5-(objs[g].first->pos.y-pos.y)])>>((objs[g].first->pos.x-pos.x)))&1)==0
|
||||
if( (5-(objs[g].first->pos.y-pos.y)) >= 0 && (5-(objs[g].first->pos.y-pos.y)) < 6 && (objs[g].first->pos.x-pos.x) >= 0 && (objs[g].first->pos.x-pos.x)<7 && objs[g].first->defInfo &&
|
||||
(((objs[g].first->defInfo->blockMap[5-(objs[g].first->pos.y-pos.y)])>>((objs[g].first->pos.x-pos.x)))&1)==0
|
||||
) //checking position blocking
|
||||
{
|
||||
unsigned char * blm = CGI->dobjinfo->objs[objs[g].first->defObjInfoNumber].blockMap;
|
||||
ret.push_back(
|
||||
CGI->objh->objects[objs[g].first->defInfo->id].name
|
||||
);
|
||||
//unsigned char * blm = objs[g].first->defInfo->blockMap;
|
||||
if (objs[g].first->state)
|
||||
ret.push_back(objs[g].first->state->hoverText(objs[g].first));
|
||||
else
|
||||
ret.push_back(CGI->objh->objects[objs[g].first->defInfo->id].name);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -1443,8 +1445,8 @@ CGObjectInstance * CMapHandler::createObject(int id, int subid, int3 pos)
|
||||
nobj->defInfo->visitMap[g] = CGI->dobjinfo->objs[nobj->defObjInfoNumber].visitMap[g];
|
||||
nobj->defInfo->printPriority = CGI->dobjinfo->objs[nobj->defObjInfoNumber].priority;
|
||||
nobj->pos = pos;
|
||||
nobj->state = new CLuaObjectScript();
|
||||
nobj->state->owner = 254;
|
||||
//nobj->state = NULL;//new CLuaObjectScript();
|
||||
nobj->tempOwner = 254;
|
||||
nobj->info = NULL;
|
||||
nobj->defInfo->id = id;
|
||||
nobj->defInfo->subid = subid;
|
||||
|
66
scripts/lua/objects/0023_marletto_tower.lua
Normal file
66
scripts/lua/objects/0023_marletto_tower.lua
Normal file
@ -0,0 +1,66 @@
|
||||
-------------------------
|
||||
--
|
||||
-------------------------
|
||||
function find(t, searched)
|
||||
print("searching")
|
||||
for index,value in ipairs(t)
|
||||
do
|
||||
print(index.." "..value)
|
||||
if value==searched
|
||||
then
|
||||
return index
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
function contain(t, searched)
|
||||
print("searching")
|
||||
for index,value in ipairs(t)
|
||||
do
|
||||
print(index.." "..value)
|
||||
if value==searched
|
||||
then
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function push_back(t,value)
|
||||
t[(#t)+1] = value
|
||||
end
|
||||
|
||||
myObjects = {}
|
||||
name = ""
|
||||
visited = {}
|
||||
--------------------------------------------------------------
|
||||
function newObject_23 (ob)
|
||||
myObjects[ob] = {}
|
||||
print("Dostaje info o nowym Marletto Tower spod adresu " .. ob)
|
||||
print(vcmi.getPos(ob))
|
||||
visited[true],visited[false] = vcmi.getGnrlText(352), vcmi.getGnrlText(353)
|
||||
end
|
||||
|
||||
function hoverText_23(Object)
|
||||
local Hero = vcmi.getSelectedHero()
|
||||
local ret = name.." "
|
||||
if Hero>-1
|
||||
then
|
||||
ret = ret..visited[contain(myObjects[ObjectAddress],Hero)]
|
||||
end
|
||||
return name..visited[contain(myObjects[ObjectAddress],Hero)]
|
||||
|
||||
end
|
||||
|
||||
function heroVisit_23(ObjectAddress, HeroID)
|
||||
print("Hero with ID " .. HeroID .. " has visited object at " .. ObjectAddress)
|
||||
if find(myObjects[ObjectAddress],HeroID)
|
||||
then
|
||||
print("Ten bohater juz tu byl")
|
||||
else
|
||||
print("Bierz obrone...")
|
||||
vcmi.changePrimSkill(HeroID, 1, 1)
|
||||
push_back(myObjects[ObjectAddress],HeroID)
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user