CLua.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #pragma once
  2. #include "global.h"
  3. #ifndef _MSC_VER
  4. extern "C" {
  5. #endif
  6. //#include "lstate.h"
  7. #ifndef _MSC_VER
  8. }
  9. #endif
  10. #include <set>
  11. #include <map>
  12. class CLua;
  13. struct SDL_Surface;
  14. class CGObjectInstance;
  15. class CGameInfo;
  16. class CGHeroInstance;
  17. class CScriptCallback;
  18. class SComponent;
  19. class CSelectableComponent;
  20. class CGameState;
  21. struct Mapa;
  22. struct lua_State;
  23. enum ESLan{UNDEF=-1,CPP,ERM,LUA};
  24. class CObjectScript
  25. {
  26. public:
  27. int owner, language;
  28. std::string filename;
  29. int getOwner(){return owner;} //255 - neutral / 254 - not flaggable
  30. CObjectScript();
  31. virtual ~CObjectScript();
  32. //functions to be called in script
  33. //virtual void init(){};
  34. virtual void newObject(int objid){};
  35. virtual void onHeroVisit(int objid, int heroID){};
  36. virtual void onHeroLeave(int objid, int heroID){};
  37. virtual std::string hoverText(int objid){return "";};
  38. virtual void newTurn (){};
  39. //TODO: implement functions below:
  40. virtual void equipArtefact(int HID, int AID, int slot, bool putOn){}; //putOn==0 means that artifact is taken off
  41. virtual void battleStart(int phase){}; //phase==0 - very start, before initialization of battle; phase==1 - just before battle starts
  42. virtual void battleNewTurn (int turn){}; //turn==-1 is for tactic stage
  43. //virtual void battleAction (int type,int destination, int stack, int owner, int){};
  44. //virtual void mouseClick (down,left,screen?, pos??){};
  45. virtual void heroLevelUp (int HID){}; //add possibility of changing available sec. skills
  46. };
  47. class CScript
  48. {
  49. public:
  50. CScript();
  51. virtual ~CScript();
  52. };
  53. class IChosen
  54. {
  55. public:
  56. virtual void chosen(int which)=0;
  57. };
  58. class CLua :public CScript
  59. {
  60. protected:
  61. lua_State * is; /// tez niebezpieczne!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (ale chwilowo okielznane)
  62. bool opened;
  63. public:
  64. CLua(std::string initpath);
  65. void open(std::string initpath);
  66. void registerCLuaCallback();
  67. CLua();
  68. virtual ~CLua();
  69. void findF(std::string fname);
  70. void findF2(std::string fname);
  71. void findFS(std::string fname);
  72. friend class CGameState;
  73. };
  74. class CLuaObjectScript : public CLua, public CObjectScript
  75. {
  76. public:
  77. CLuaObjectScript(std::string filename);
  78. virtual ~CLuaObjectScript();
  79. static std::string genFN(std::string base, int ID);
  80. void init();
  81. void newObject(int objid);
  82. void onHeroVisit(int objid, int heroID);
  83. };
  84. class CCPPObjectScript: public CObjectScript
  85. {
  86. public:
  87. CScriptCallback * cb;
  88. CCPPObjectScript(CScriptCallback * CB){cb=CB;};
  89. virtual std::vector<int> yourObjects()=0; //returns IDs of objects which are handled by script
  90. };
  91. class CVisitableOPH : public CCPPObjectScript //once per hero
  92. {
  93. public:
  94. CVisitableOPH(CScriptCallback * CB):CCPPObjectScript(CB){};
  95. std::map<int,std::set<int> > visitors;
  96. void onNAHeroVisit(int objid, int heroID, bool alreadyVisited);
  97. void newObject(int objid);
  98. void onHeroVisit(int objid, int heroID);
  99. std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
  100. };
  101. class CVisitableOPW : public CCPPObjectScript //once per week
  102. {
  103. public:
  104. CVisitableOPW(CScriptCallback * CB):CCPPObjectScript(CB){};
  105. std::map<int,bool> visited;
  106. void onNAHeroVisit(int objid, int heroID, bool alreadyVisited);
  107. void newObject(int objid);
  108. void onHeroVisit(int objid, int heroID);
  109. std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
  110. void newTurn ();
  111. };
  112. class CMines : public CCPPObjectScript //flaggable, and giving resource at each day
  113. {
  114. public:
  115. CMines(CScriptCallback * CB):CCPPObjectScript(CB){};
  116. std::vector<int> ourObjs;
  117. void newObject(int objid);
  118. void onHeroVisit(int objid, int heroID);
  119. std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
  120. void newTurn ();
  121. };
  122. class CPickable : public CCPPObjectScript, public IChosen //pickable - resources, artifacts, etc
  123. {
  124. public:
  125. std::vector<CSelectableComponent*> tempStore;
  126. int player;
  127. CPickable(CScriptCallback * CB):CCPPObjectScript(CB){};
  128. void chosen(int which);
  129. void newObject(int objid);
  130. void onHeroVisit(int objid, int heroID);
  131. std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
  132. };
  133. class CTownScript : public CCPPObjectScript //pickable - resources, artifacts, etc
  134. {
  135. public:
  136. CTownScript(CScriptCallback * CB):CCPPObjectScript(CB){};
  137. void onHeroVisit(int objid, int heroID);
  138. void onHeroLeave(int objid, int heroID);
  139. void newObject(int objid);
  140. std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
  141. };
  142. class CHeroScript : public CCPPObjectScript
  143. {
  144. public:
  145. CHeroScript(CScriptCallback * CB):CCPPObjectScript(CB){};
  146. void newObject(int objid);
  147. void onHeroVisit(int objid, int heroID);
  148. std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
  149. };
  150. class CMonsterS : public CCPPObjectScript
  151. {
  152. public:
  153. std::map<int, int> amounts; //monster id -> stack quantity
  154. CMonsterS(CScriptCallback * CB):CCPPObjectScript(CB){};
  155. void newObject(int objid);
  156. void onHeroVisit(int objid, int heroID);
  157. std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
  158. };
  159. class CCreatureGen : public CCPPObjectScript
  160. {
  161. public:
  162. std::map<int, int> amount; //amount of creatures in each dwelling
  163. CCreatureGen(CScriptCallback * CB):CCPPObjectScript(CB){};
  164. void newObject(int objid);
  165. void onHeroVisit(int objid, int heroID);
  166. std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
  167. };