CObjectHandler.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. #ifndef COBJECTHANDLER_H
  2. #define COBJECTHANDLER_H
  3. #include <string>
  4. #include <vector>
  5. #include <set>
  6. #include "CCreatureHandler.h"
  7. #include "CArtHandler.h"
  8. #include "CAbilityHandler.h"
  9. #include "CSpellHandler.h"
  10. //#include "CHeroHandler.h"
  11. using boost::logic::tribool;
  12. class CCPPObjectScript;
  13. class CGObjectInstance;
  14. class CScript;
  15. class CObjectScript;
  16. class CGHeroInstance;
  17. class CTown;
  18. class CHero;
  19. class CBuilding;
  20. class CSpell;
  21. class CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes
  22. {
  23. };
  24. class CEventObjInfo : public CSpecObjInfo
  25. {
  26. public:
  27. bool areGuarders; //true if there are
  28. CCreatureSet guarders;
  29. bool isMessage; //true if there is a message
  30. std::string message;
  31. unsigned int gainedExp;
  32. int manaDiff; //amount of gained / lost mana
  33. int moraleDiff; //morale modifier
  34. int luckDiff; //luck modifier
  35. int wood, mercury, ore, sulfur, crystal, gems, gold; //gained / lost resources
  36. unsigned int attack; //added attack points
  37. unsigned int defence; //added defence points
  38. unsigned int power; //added power points
  39. unsigned int knowledge; //added knowledge points
  40. std::vector<CAbility *> abilities; //gained abilities
  41. std::vector<int> abilityLevels; //levels of gained abilities
  42. std::vector<CArtifact *> artifacts; //gained artifacts
  43. std::vector<CSpell *> spells; //gained spells
  44. CCreatureSet creatures; //gained creatures
  45. unsigned char availableFor; //players whom this event is available for
  46. bool computerActivate; //true if computre player can activate this event
  47. bool humanActivate; //true if human player can activate this event
  48. };
  49. class CHeroObjInfo : public CSpecObjInfo
  50. {
  51. public:
  52. unsigned char bytes[4]; //mysterius bytes identifying hero in a strange way
  53. int player;
  54. CHero * type;
  55. std::string name; //if nonstandard
  56. bool standardGarrison; //true if hero has standard garrison
  57. CCreatureSet garrison; //hero's army
  58. std::vector<CArtifact *> artifacts; //hero's artifacts from bag
  59. CArtifact * artHead, * artLRing, * artRRing, * artLHand, * artRhand, * artFeet, * artSpellBook, * artMach1, * artMach2, * artMach3, * artMach4, * artMisc1, * artMisc2, * artMisc3, * artMisc4, * artMisc5, * artTorso, * artNeck, * artShoulders; //working artifacts
  60. bool isGuarding;
  61. int guardRange; //range of hero's guard
  62. std::string biography; //if nonstandard
  63. bool sex; //if true, reverse hero's sex
  64. std::vector<CSpell *> spells; //hero's spells
  65. int attack, defence, power, knowledge; //main hero's attributes
  66. unsigned int experience; //hero's experience points
  67. std::vector<CAbility *> abilities; //hero's abilities
  68. std::vector<int> abilityLevels; //hero ability levels
  69. bool defaultMainStats; //if true attack, defence, power and knowledge are typical
  70. CGHeroInstance * myInstance; //pointer to appropriate hero instance
  71. };
  72. class CCreatureObjInfo : public CSpecObjInfo
  73. {
  74. public:
  75. unsigned char bytes[4]; //mysterious bytes identifying creature
  76. unsigned int number; //number of units (0 - random)
  77. unsigned char character; //chracter of this set of creatures (0 - the most friendly, 4 - the most hostile)
  78. std::string message; //message printed for attacking hero
  79. int wood, mercury, ore, sulfur, crytal, gems, gold; //resources gained to hero that has won with monsters
  80. CArtifact * gainedArtifact; //artifact gained to hero
  81. bool neverFlees; //if true, the troops will never flee
  82. bool notGrowingTeam; //if true, number of units won't grow
  83. };
  84. class CSignObjInfo : public CSpecObjInfo
  85. {
  86. public:
  87. std::string message; //message
  88. };
  89. class CSeerHutObjInfo : public CSpecObjInfo
  90. {
  91. public:
  92. unsigned char missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain player
  93. bool isDayLimit; //if true, there is a day limit
  94. int lastDay; //after this day (first day is 0) mission cannot be completed
  95. //for mission 1
  96. int m1level;
  97. //for mission 2
  98. int m2attack, m2defence, m2power, m2knowledge;
  99. //for mission 3
  100. unsigned char m3bytes[4];
  101. //for mission 4
  102. unsigned char m4bytes[4];
  103. //for mission 5
  104. std::vector<CArtifact *> m5arts;
  105. //for mission 6
  106. std::vector<CCreature *> m6cre;
  107. std::vector<int> m6number;
  108. //for mission 7
  109. int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold;
  110. //for mission 8
  111. CHero * m8hero;
  112. //for mission 9
  113. int m9player; //number; from 0 to 7
  114. std::string firstVisitText, nextVisitText, completedText;
  115. char rewardType; //type of reward: 0 - no reward; 1 - experience; 2 - mana points; 3 - morale bonus; 4 - luck bonus; 5 - resources; 6 - main ability bonus (attak, defence etd.); 7 - secondary ability gain; 8 - artifact; 9 - spell; 10 - creature
  116. //for reward 1
  117. int r1exp;
  118. //for reward 2
  119. int r2mana;
  120. //for reward 3
  121. int r3morale;
  122. //for reward 4
  123. int r4luck;
  124. //for reward 5
  125. unsigned char r5type; //0 - wood, 1 - mercury, 2 - ore, 3 - sulfur, 4 - crystal, 5 - gems, 6 - gold
  126. int r5amount;
  127. //for reward 6
  128. unsigned char r6type; //0 - attack, 1 - defence, 2 - power, 3 - knowledge
  129. int r6amount;
  130. //for reward 7
  131. CAbility * r7ability;
  132. unsigned char r7level; //1 - basic, 2 - advanced, 3 - expert
  133. //for reward 8
  134. CArtifact * r8art;
  135. //for reward 9
  136. CSpell * r9spell;
  137. //for reward 10
  138. CCreature * r10creature;
  139. int r10amount;
  140. };
  141. class CWitchHutObjInfo : public CSpecObjInfo
  142. {
  143. public:
  144. std::vector<CAbility *> allowedAbilities;
  145. };
  146. class CScholarObjInfo : public CSpecObjInfo
  147. {
  148. public:
  149. unsigned char bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell
  150. unsigned char r0type;
  151. CAbility * r1;
  152. CSpell * r2;
  153. };
  154. class CGarrisonObjInfo : public CSpecObjInfo
  155. {
  156. public:
  157. unsigned char player; //255 - nobody; 0 - 7 - players
  158. CCreatureSet units;
  159. bool movableUnits; //if true, units can be moved
  160. };
  161. class CArtifactObjInfo : public CSpecObjInfo
  162. {
  163. public:
  164. bool areGuards;
  165. std::string message;
  166. CCreatureSet guards;
  167. };
  168. class CResourceObjInfo : public CSpecObjInfo
  169. {
  170. public:
  171. bool randomAmount;
  172. int amount; //if not random
  173. bool areGuards;
  174. CCreatureSet guards;
  175. std::string message;
  176. };
  177. class CPlayerOnlyObjInfo : public CSpecObjInfo
  178. {
  179. public:
  180. unsigned char player; //FF - nobody, 0 - 7
  181. };
  182. class CShrineObjInfo : public CSpecObjInfo
  183. {
  184. public:
  185. unsigned char spell; //number of spell or 255
  186. };
  187. class CSpellScrollObjinfo : public CSpecObjInfo
  188. {
  189. public:
  190. std::string message;
  191. CSpell * spell;
  192. bool areGuarders;
  193. CCreatureSet guarders;
  194. };
  195. class CPandorasBoxObjInfo : public CSpecObjInfo
  196. {
  197. public:
  198. std::string message;
  199. bool areGuarders;
  200. CCreatureSet guarders;
  201. //gained things:
  202. unsigned int gainedExp;
  203. int manaDiff;
  204. int moraleDiff;
  205. int luckDiff;
  206. int wood, mercury, ore, sulfur, crystal, gems, gold;
  207. int attack, defence, power, knowledge;
  208. std::vector<CAbility *> abilities;
  209. std::vector<int> abilityLevels;
  210. std::vector<CArtifact *> artifacts;
  211. std::vector<CSpell *> spells;
  212. CCreatureSet creatures;
  213. };
  214. class CGrailObjInfo : public CSpecObjInfo
  215. {
  216. public:
  217. int radius; //place grail at the distance lesser or equal radius from this place
  218. };
  219. class CCreGenObjInfo : public CSpecObjInfo
  220. {
  221. public:
  222. unsigned char player; //owner
  223. bool asCastle;
  224. unsigned char bytes[4]; //castle identifier
  225. unsigned char castles[2]; //allowed castles
  226. };
  227. class CCreGen2ObjInfo : public CSpecObjInfo
  228. {
  229. public:
  230. unsigned char player; //owner
  231. bool asCastle;
  232. unsigned char bytes[4]; //castle identifier
  233. unsigned char castles[2]; //allowed castles
  234. unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6>
  235. };
  236. class CCreGen3ObjInfo : public CSpecObjInfo
  237. {
  238. public:
  239. unsigned char player; //owner
  240. unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6>
  241. };
  242. class CBorderGuardObjInfo : public CSpecObjInfo //copied form seer huts, seems to be similar
  243. {
  244. public:
  245. char missionType; //type of mission: 0 - no mission; 1 - reach level; 2 - reach main statistics values; 3 - win with a certain hero; 4 - win with a certain creature; 5 - collect some atifacts; 6 - have certain troops in army; 7 - collect resources; 8 - be a certain hero; 9 - be a certain player
  246. bool isDayLimit; //if true, there is a day limit
  247. int lastDay; //after this day (first day is 0) mission cannot be completed
  248. //for mission 1
  249. int m1level;
  250. //for mission 2
  251. int m2attack, m2defence, m2power, m2knowledge;
  252. //for mission 3
  253. unsigned char m3bytes[4];
  254. //for mission 4
  255. unsigned char m4bytes[4];
  256. //for mission 5
  257. std::vector<CArtifact *> m5arts;
  258. //for mission 6
  259. std::vector<CCreature *> m6cre;
  260. std::vector<int> m6number;
  261. //for mission 7
  262. int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold;
  263. //for mission 8
  264. CHero * m8hero;
  265. //for mission 9
  266. int m9player; //number; from 0 to 7
  267. std::string firstVisitText, nextVisitText, completedText;
  268. };
  269. class CObject //typical object that can be encountered on a map
  270. {
  271. public:
  272. std::string name; //object's name
  273. };
  274. class CObjectInstance //instance of object
  275. {
  276. public:
  277. int defNumber; //specifies number of def file with animation of this object
  278. int defObjInfoNumber; //number of this object's def's additional informations in CDefObjInfo's vector
  279. int id; //number of object in CObjectHandler's vector //TODO: absolutnie wywalic i zastapic czyms sensownym
  280. int3 pos; // position
  281. CSpecObjInfo * info; //pointer to something with additional information
  282. bool isHero; //true if this is a hero
  283. unsigned char moveDir; //direction of hero movement (0 - default; 1 - lt; 2 - t; 3 - tr; 4 - r; 5 - br; 6 - b; 7 - bl; 8 - l)
  284. bool isStanding; //true if is standing, flase if is moving
  285. unsigned char flagPrinted; //true if flag has been printed //number of print hits
  286. unsigned char owner; //if 254, object cannot have owner; if it has, it equal to owner's ID (or 255, when no owner)
  287. int getWidth() const; //returns width of object graphic in tiles
  288. int getHeight() const; //returns height of object graphic in tiles
  289. 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)
  290. bool operator<(const CObjectInstance & cmp) const; //screen printing priority comparing
  291. };
  292. class CGDefInfo
  293. {
  294. public:
  295. std::string name;
  296. unsigned char visitMap[6];
  297. unsigned char blockMap[6];
  298. int id, subid; //of object described by this defInfo
  299. int terrainAllowed, //on which terrain it is possible to place object
  300. terrainMenu; //in which menus in map editor object will be showed
  301. int type; //(0- ground, 1- towns, 2-creatures, 3- heroes, 4-artifacts, 5- resources)
  302. CDefHandler * handler;
  303. int printPriority;
  304. bool isOnDefList;
  305. bool isVisitable();
  306. };
  307. //class CObjectType
  308. //{
  309. //public:
  310. // CGObjectInstance * ourObj;
  311. // int type;
  312. // int owner; //254 - can't be flagged; 255 - neutral
  313. ////};
  314. //class IVisitable
  315. //{
  316. // virtual void newObject(CGObjectInstance *os);
  317. // virtual void onHeroVisit(CGObjectInstance *os, int heroID);
  318. // virtual void getRightText(tribool visited);
  319. // virtual void getHoverText(tribool visited);
  320. //};
  321. //
  322. //class CVisitableOPH //object visitable once per hero
  323. //{
  324. // virtual void newObject(CGObjectInstance *os);
  325. // virtual void onHeroVisit(CGObjectInstance *os, int heroID);
  326. // virtual void getRightText(tribool visited);
  327. // virtual void getHoverText(tribool visited);
  328. //};
  329. class CGObjectInstance
  330. {
  331. public:
  332. int3 pos; //h3m pos
  333. int ID, subID; //normal ID (this one from OH3 maps ;])
  334. int id;//number of object in CObjectHandler's vector
  335. CGDefInfo * defInfo;
  336. CCPPObjectScript * state;
  337. CSpecObjInfo * info;
  338. int defObjInfoNumber;
  339. int tempOwner; //uzywane dla szybkosci, skrypt ma obowiazek aktualizowac te zmienna
  340. bool blockVisit;
  341. virtual bool isHero() const;
  342. int getOwner() const;
  343. void setOwner(int ow);
  344. int getWidth() const; //returns width of object graphic in tiles
  345. int getHeight() const; //returns height of object graphic in tiles
  346. 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)
  347. bool operator<(const CGObjectInstance & cmp) const; //screen printing priority comparing
  348. CGObjectInstance();
  349. virtual ~CGObjectInstance();
  350. CGObjectInstance(const CGObjectInstance & right);
  351. CGObjectInstance& operator=(const CGObjectInstance & right);
  352. };
  353. class CGHeroInstance : public CGObjectInstance
  354. {
  355. public:
  356. int moveDir;
  357. bool isStanding;
  358. bool flagPrinted;
  359. CHero * type;
  360. int exp; //experience point
  361. int level; //current level of hero
  362. std::string name; //may be custom
  363. std::string biography; //may be custom
  364. int portrait; //may be custom
  365. CCreatureSet army; //army
  366. int mana; // remaining spell points
  367. std::vector<int> primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge
  368. std::vector<std::pair<int,int> > secSkills; //first - ID of skill, second - level of skill (0 - basic, 1 - adv., 2 - expert)
  369. int movement; //remaining movement points
  370. bool inTownGarrison; // if hero is in town garrison
  371. virtual bool isHero() const;
  372. unsigned int getTileCost(EterrainType & ttype, Eroad & rdtype, Eriver & rvtype);
  373. unsigned int getLowestCreatureSpeed();
  374. unsigned int getAdditiveMoveBonus();
  375. float getMultiplicativeMoveBonus();
  376. static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
  377. int3 getPosition(bool h3m) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
  378. int getSightDistance() const; //returns sight distance of this hero
  379. void setPosition(int3 Pos, bool h3m); //as above, but sets position
  380. bool canWalkOnSea() const;
  381. int getCurrentLuck() const;
  382. int getCurrentMorale() const;
  383. virtual ~CGHeroInstance();
  384. };
  385. class CGTownInstance : public CGObjectInstance
  386. {
  387. public:
  388. CTown * town;
  389. std::string name; // name of town
  390. CCreatureSet garrison;
  391. int builded; //how many buildings has been built this turn
  392. int destroyed; //how many buildings has been destroyed this turn
  393. int income;
  394. //TODO:
  395. std::set<int> possibleBuildings, builtBuildings, h3mbuildings;
  396. std::vector<int> creatureIncome; //vector by level
  397. std::vector<int> creaturesLeft; //that can be recruited
  398. CGHeroInstance * garrisonHero;
  399. std::vector<CSpell *> possibleSpells, obligatorySpells, availableSpells;
  400. int getSightDistance() const; //returns sight distance
  401. bool hasFort() const;
  402. int dailyIncome() const;
  403. CGTownInstance();
  404. virtual ~CGTownInstance();
  405. };
  406. class CObjectHandler
  407. {
  408. public:
  409. std::vector<CObject> objects; //vector of objects; i-th object in vector has subnumber i
  410. std::vector<CGObjectInstance*> objInstances; //vector with objects on map
  411. void loadObjects();
  412. std::vector<std::string> advobtxt;
  413. std::vector<std::string> xtrainfo;
  414. std::vector<std::string> restypes;
  415. std::vector<std::pair<std::string,std::string> > mines; //first - name; second - event description
  416. };
  417. #endif //COBJECTHANDLER_H