CLua.h 5.4 KB

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