2008-02-22 17:47:01 +02:00
|
|
|
#pragma once
|
2007-10-28 13:34:33 +02:00
|
|
|
#include "global.h"
|
2008-07-25 20:28:28 +03:00
|
|
|
//#include "lstate.h"
|
2007-11-19 00:58:28 +02:00
|
|
|
#include <set>
|
|
|
|
#include <map>
|
2007-10-28 13:34:33 +02:00
|
|
|
class CLua;
|
2007-11-19 00:58:28 +02:00
|
|
|
struct SDL_Surface;
|
|
|
|
class CGObjectInstance;
|
|
|
|
class CGameInfo;
|
|
|
|
class CGHeroInstance;
|
|
|
|
class CScriptCallback;
|
2007-12-25 18:25:53 +02:00
|
|
|
class SComponent;
|
2007-12-27 02:11:46 +02:00
|
|
|
class CSelectableComponent;
|
2008-06-30 03:06:41 +03:00
|
|
|
class CGameState;
|
2008-06-11 04:53:57 +03:00
|
|
|
struct Mapa;
|
2008-07-25 20:28:28 +03:00
|
|
|
struct lua_State;
|
2007-11-19 00:58:28 +02:00
|
|
|
enum ESLan{UNDEF=-1,CPP,ERM,LUA};
|
2007-10-28 13:34:33 +02:00
|
|
|
class CObjectScript
|
|
|
|
{
|
|
|
|
public:
|
2007-11-19 00:58:28 +02:00
|
|
|
int owner, language;
|
|
|
|
std::string filename;
|
|
|
|
|
2007-10-28 13:34:33 +02:00
|
|
|
int getOwner(){return owner;} //255 - neutral / 254 - not flaggable
|
|
|
|
CObjectScript();
|
|
|
|
virtual ~CObjectScript();
|
2007-11-19 00:58:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
//functions to be called in script
|
|
|
|
//virtual void init(){};
|
2008-07-30 20:51:19 +03:00
|
|
|
virtual void newObject(int objid){};
|
|
|
|
virtual void onHeroVisit(int objid, int heroID){};
|
|
|
|
virtual void onHeroLeave(int objid, int heroID){};
|
|
|
|
virtual std::string hoverText(int objid){return "";};
|
2007-11-24 00:33:55 +02:00
|
|
|
virtual void newTurn (){};
|
|
|
|
|
2007-11-19 00:58:28 +02:00
|
|
|
|
|
|
|
//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
|
|
|
|
|
2007-10-28 13:34:33 +02:00
|
|
|
};
|
|
|
|
class CScript
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CScript();
|
|
|
|
virtual ~CScript();
|
|
|
|
};
|
2007-12-25 18:25:53 +02:00
|
|
|
class IChosen
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual void chosen(int which)=0;
|
|
|
|
};
|
2007-10-28 13:34:33 +02:00
|
|
|
class CLua :public CScript
|
|
|
|
{
|
2007-11-19 00:58:28 +02:00
|
|
|
protected:
|
2007-10-28 13:34:33 +02:00
|
|
|
lua_State * is; /// tez niebezpieczne!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ale chwilowo okielznane)
|
|
|
|
bool opened;
|
|
|
|
public:
|
|
|
|
CLua(std::string initpath);
|
2007-11-19 00:58:28 +02:00
|
|
|
void open(std::string initpath);
|
2007-10-28 13:34:33 +02:00
|
|
|
void registerCLuaCallback();
|
|
|
|
CLua();
|
|
|
|
virtual ~CLua();
|
2007-11-19 00:58:28 +02:00
|
|
|
|
|
|
|
void findF(std::string fname);
|
|
|
|
void findF2(std::string fname);
|
|
|
|
void findFS(std::string fname);
|
|
|
|
|
|
|
|
|
2008-06-30 03:06:41 +03:00
|
|
|
friend CGameState;
|
2007-10-28 13:34:33 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CLuaObjectScript : public CLua, public CObjectScript
|
|
|
|
{
|
|
|
|
public:
|
2007-11-19 00:58:28 +02:00
|
|
|
CLuaObjectScript(std::string filename);
|
2007-10-28 13:34:33 +02:00
|
|
|
virtual ~CLuaObjectScript();
|
2007-11-19 00:58:28 +02:00
|
|
|
static std::string genFN(std::string base, int ID);
|
|
|
|
|
|
|
|
void init();
|
2008-07-30 20:51:19 +03:00
|
|
|
void newObject(int objid);
|
|
|
|
void onHeroVisit(int objid, int heroID);
|
2007-11-19 00:58:28 +02:00
|
|
|
};
|
|
|
|
class CCPPObjectScript: public CObjectScript
|
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
public:
|
2007-11-19 00:58:28 +02:00
|
|
|
CScriptCallback * cb;
|
|
|
|
CCPPObjectScript(CScriptCallback * CB){cb=CB;};
|
|
|
|
virtual std::vector<int> yourObjects()=0; //returns IDs of objects which are handled by script
|
|
|
|
};
|
|
|
|
class CVisitableOPH : public CCPPObjectScript //once per hero
|
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
public:
|
2007-11-19 00:58:28 +02:00
|
|
|
CVisitableOPH(CScriptCallback * CB):CCPPObjectScript(CB){};
|
2008-07-30 20:51:19 +03:00
|
|
|
std::map<int,std::set<int> > visitors;
|
2007-11-19 00:58:28 +02:00
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
void onNAHeroVisit(int objid, int heroID, bool alreadyVisited);
|
|
|
|
void newObject(int objid);
|
|
|
|
void onHeroVisit(int objid, int heroID);
|
2007-11-19 00:58:28 +02:00
|
|
|
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
|
|
|
|
};
|
|
|
|
|
2007-11-24 00:33:55 +02:00
|
|
|
class CVisitableOPW : public CCPPObjectScript //once per week
|
2007-11-19 00:58:28 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
public:
|
2007-11-24 00:33:55 +02:00
|
|
|
CVisitableOPW(CScriptCallback * CB):CCPPObjectScript(CB){};
|
2008-07-30 20:51:19 +03:00
|
|
|
std::map<int,bool> visited;
|
|
|
|
void onNAHeroVisit(int objid, int heroID, bool alreadyVisited);
|
|
|
|
void newObject(int objid);
|
|
|
|
void onHeroVisit(int objid, int heroID);
|
2007-11-24 00:33:55 +02:00
|
|
|
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
|
|
|
|
void newTurn ();
|
2007-11-24 16:17:57 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CMines : public CCPPObjectScript //flaggable, and giving resource at each day
|
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
public:
|
2007-11-24 16:17:57 +02:00
|
|
|
CMines(CScriptCallback * CB):CCPPObjectScript(CB){};
|
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
std::vector<int> ourObjs;
|
2007-11-24 16:17:57 +02:00
|
|
|
|
2008-07-30 20:51:19 +03:00
|
|
|
void newObject(int objid);
|
|
|
|
void onHeroVisit(int objid, int heroID);
|
2007-11-24 16:17:57 +02:00
|
|
|
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
|
|
|
|
void newTurn ();
|
2007-11-25 15:16:45 +02:00
|
|
|
};
|
|
|
|
|
2007-12-25 18:25:53 +02:00
|
|
|
class CPickable : public CCPPObjectScript, public IChosen //pickable - resources, artifacts, etc
|
2007-11-25 15:16:45 +02:00
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
public:
|
2007-12-27 02:11:46 +02:00
|
|
|
std::vector<CSelectableComponent*> tempStore;
|
2007-12-25 18:25:53 +02:00
|
|
|
int player;
|
2007-11-25 15:16:45 +02:00
|
|
|
|
2007-12-25 18:25:53 +02:00
|
|
|
CPickable(CScriptCallback * CB):CCPPObjectScript(CB){};
|
|
|
|
void chosen(int which);
|
2008-07-30 20:51:19 +03:00
|
|
|
void newObject(int objid);
|
|
|
|
void onHeroVisit(int objid, int heroID);
|
2007-11-25 15:16:45 +02:00
|
|
|
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
|
2008-01-28 16:01:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CTownScript : public CCPPObjectScript //pickable - resources, artifacts, etc
|
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
public:
|
2008-01-28 16:01:09 +02:00
|
|
|
CTownScript(CScriptCallback * CB):CCPPObjectScript(CB){};
|
2008-07-30 20:51:19 +03:00
|
|
|
void onHeroVisit(int objid, int heroID);
|
|
|
|
void onHeroLeave(int objid, int heroID);
|
|
|
|
void newObject(int objid);
|
2008-01-28 16:01:09 +02:00
|
|
|
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
|
2008-02-25 01:06:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CHeroScript : public CCPPObjectScript
|
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
public:
|
2008-02-25 01:06:27 +02:00
|
|
|
CHeroScript(CScriptCallback * CB):CCPPObjectScript(CB){};
|
2008-07-30 20:51:19 +03:00
|
|
|
void newObject(int objid);
|
|
|
|
void onHeroVisit(int objid, int heroID);
|
2008-02-25 01:06:27 +02:00
|
|
|
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
|
|
|
|
};
|
|
|
|
|
|
|
|
class CMonsterS : public CCPPObjectScript
|
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
public:
|
|
|
|
std::map<int, int> amounts; //monster id -> stack quantity
|
2008-02-25 01:06:27 +02:00
|
|
|
CMonsterS(CScriptCallback * CB):CCPPObjectScript(CB){};
|
2008-07-30 20:51:19 +03:00
|
|
|
void newObject(int objid);
|
|
|
|
void onHeroVisit(int objid, int heroID);
|
2008-02-25 01:06:27 +02:00
|
|
|
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
|
2008-03-01 00:14:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
class CCreatureGen : public CCPPObjectScript
|
|
|
|
{
|
2008-07-30 20:51:19 +03:00
|
|
|
public:
|
|
|
|
std::map<int, int> amount; //amount of creatures in each dwelling
|
2008-03-01 00:14:53 +02:00
|
|
|
CCreatureGen(CScriptCallback * CB):CCPPObjectScript(CB){};
|
2008-07-30 20:51:19 +03:00
|
|
|
void newObject(int objid);
|
|
|
|
void onHeroVisit(int objid, int heroID);
|
2008-03-01 00:14:53 +02:00
|
|
|
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
|
2007-10-28 13:34:33 +02:00
|
|
|
};
|