1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-26 22:57:00 +02:00
vcmi/CLua.h

183 lines
5.4 KiB
C
Raw Normal View History

#pragma once
#include "global.h"
//#include "lstate.h"
#include <set>
#include <map>
class CLua;
struct SDL_Surface;
class CGObjectInstance;
class CGameInfo;
class CGHeroInstance;
class CScriptCallback;
2007-12-25 18:25:53 +02:00
class SComponent;
class CSelectableComponent;
class CGameState;
2008-06-11 04:53:57 +03:00
struct Mapa;
struct lua_State;
enum ESLan{UNDEF=-1,CPP,ERM,LUA};
class CObjectScript
{
public:
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(){};
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 "";};
virtual void newTurn (){};
//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
{
public:
CScript();
virtual ~CScript();
};
2007-12-25 18:25:53 +02:00
class IChosen
{
public:
virtual void chosen(int which)=0;
};
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 CGameState;
};
class CLuaObjectScript : public CLua, public CObjectScript
{
public:
CLuaObjectScript(std::string filename);
virtual ~CLuaObjectScript();
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);
};
class CCPPObjectScript: public CObjectScript
{
2008-07-30 20:51:19 +03:00
public:
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:
CVisitableOPH(CScriptCallback * CB):CCPPObjectScript(CB){};
2008-07-30 20:51:19 +03:00
std::map<int,std::set<int> > visitors;
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);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
};
class CVisitableOPW : public CCPPObjectScript //once per week
{
2008-07-30 20:51:19 +03:00
public:
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);
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:
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
};
class CTownScript : public CCPPObjectScript //pickable - resources, artifacts, etc
{
2008-07-30 20:51:19 +03:00
public:
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);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
};
class CHeroScript : public CCPPObjectScript
{
2008-07-30 20:51:19 +03:00
public:
CHeroScript(CScriptCallback * CB):CCPPObjectScript(CB){};
2008-07-30 20:51:19 +03:00
void newObject(int objid);
void onHeroVisit(int objid, int heroID);
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
CMonsterS(CScriptCallback * CB):CCPPObjectScript(CB){};
2008-07-30 20:51:19 +03:00
void newObject(int objid);
void onHeroVisit(int objid, int heroID);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
};
class CCreatureGen : public CCPPObjectScript
{
2008-07-30 20:51:19 +03:00
public:
std::map<int, int> amount; //amount of creatures in each dwelling
CCreatureGen(CScriptCallback * CB):CCPPObjectScript(CB){};
2008-07-30 20:51:19 +03:00
void newObject(int objid);
void onHeroVisit(int objid, int heroID);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
};