CObjectHandler.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  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 artifactsstd::vector<CArtifact *> artifWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
  60. std::vector<CArtifact *> artifWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
  61. bool isGuarding;
  62. int guardRange; //range of hero's guard
  63. std::string biography; //if nonstandard
  64. bool sex; //if true, reverse hero's sex
  65. std::vector<CSpell *> spells; //hero's spells
  66. int attack, defence, power, knowledge; //main hero's attributes
  67. unsigned int experience; //hero's experience points
  68. std::vector<CAbility *> abilities; //hero's abilities
  69. std::vector<int> abilityLevels; //hero ability levels
  70. bool defaultMainStats; //if true attack, defence, power and knowledge are typical
  71. CGHeroInstance * myInstance; //pointer to appropriate hero instance
  72. };
  73. class CCreatureObjInfo : public CSpecObjInfo
  74. {
  75. public:
  76. unsigned char bytes[4]; //mysterious bytes identifying creature
  77. unsigned int number; //number of units (0 - random)
  78. unsigned char character; //chracter of this set of creatures (0 - the most friendly, 4 - the most hostile)
  79. std::string message; //message printed for attacking hero
  80. int wood, mercury, ore, sulfur, crytal, gems, gold; //resources gained to hero that has won with monsters
  81. CArtifact * gainedArtifact; //artifact gained to hero
  82. bool neverFlees; //if true, the troops will never flee
  83. bool notGrowingTeam; //if true, number of units won't grow
  84. };
  85. class CSignObjInfo : public CSpecObjInfo
  86. {
  87. public:
  88. std::string message; //message
  89. };
  90. class CSeerHutObjInfo : public CSpecObjInfo
  91. {
  92. public:
  93. 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
  94. bool isDayLimit; //if true, there is a day limit
  95. int lastDay; //after this day (first day is 0) mission cannot be completed
  96. //for mission 1
  97. int m1level;
  98. //for mission 2
  99. int m2attack, m2defence, m2power, m2knowledge;
  100. //for mission 3
  101. unsigned char m3bytes[4];
  102. //for mission 4
  103. unsigned char m4bytes[4];
  104. //for mission 5
  105. std::vector<CArtifact *> m5arts;
  106. //for mission 6
  107. std::vector<CCreature *> m6cre;
  108. std::vector<int> m6number;
  109. //for mission 7
  110. int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold;
  111. //for mission 8
  112. CHero * m8hero;
  113. //for mission 9
  114. int m9player; //number; from 0 to 7
  115. std::string firstVisitText, nextVisitText, completedText;
  116. 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
  117. //for reward 1
  118. int r1exp;
  119. //for reward 2
  120. int r2mana;
  121. //for reward 3
  122. int r3morale;
  123. //for reward 4
  124. int r4luck;
  125. //for reward 5
  126. unsigned char r5type; //0 - wood, 1 - mercury, 2 - ore, 3 - sulfur, 4 - crystal, 5 - gems, 6 - gold
  127. int r5amount;
  128. //for reward 6
  129. unsigned char r6type; //0 - attack, 1 - defence, 2 - power, 3 - knowledge
  130. int r6amount;
  131. //for reward 7
  132. CAbility * r7ability;
  133. unsigned char r7level; //1 - basic, 2 - advanced, 3 - expert
  134. //for reward 8
  135. CArtifact * r8art;
  136. //for reward 9
  137. CSpell * r9spell;
  138. //for reward 10
  139. CCreature * r10creature;
  140. int r10amount;
  141. };
  142. class CWitchHutObjInfo : public CSpecObjInfo
  143. {
  144. public:
  145. std::vector<CAbility *> allowedAbilities;
  146. };
  147. class CScholarObjInfo : public CSpecObjInfo
  148. {
  149. public:
  150. unsigned char bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell
  151. unsigned char r0type;
  152. CAbility * r1;
  153. CSpell * r2;
  154. };
  155. class CGarrisonObjInfo : public CSpecObjInfo
  156. {
  157. public:
  158. unsigned char player; //255 - nobody; 0 - 7 - players
  159. CCreatureSet units;
  160. bool movableUnits; //if true, units can be moved
  161. };
  162. class CArtifactObjInfo : public CSpecObjInfo
  163. {
  164. public:
  165. bool areGuards;
  166. std::string message;
  167. CCreatureSet guards;
  168. };
  169. class CResourceObjInfo : public CSpecObjInfo
  170. {
  171. public:
  172. bool randomAmount;
  173. int amount; //if not random
  174. bool areGuards;
  175. CCreatureSet guards;
  176. std::string message;
  177. };
  178. class CPlayerOnlyObjInfo : public CSpecObjInfo
  179. {
  180. public:
  181. unsigned char player; //FF - nobody, 0 - 7
  182. };
  183. class CShrineObjInfo : public CSpecObjInfo
  184. {
  185. public:
  186. unsigned char spell; //number of spell or 255
  187. };
  188. class CSpellScrollObjinfo : public CSpecObjInfo
  189. {
  190. public:
  191. std::string message;
  192. CSpell * spell;
  193. bool areGuarders;
  194. CCreatureSet guarders;
  195. };
  196. class CPandorasBoxObjInfo : public CSpecObjInfo
  197. {
  198. public:
  199. std::string message;
  200. bool areGuarders;
  201. CCreatureSet guarders;
  202. //gained things:
  203. unsigned int gainedExp;
  204. int manaDiff;
  205. int moraleDiff;
  206. int luckDiff;
  207. int wood, mercury, ore, sulfur, crystal, gems, gold;
  208. int attack, defence, power, knowledge;
  209. std::vector<CAbility *> abilities;
  210. std::vector<int> abilityLevels;
  211. std::vector<CArtifact *> artifacts;
  212. std::vector<CSpell *> spells;
  213. CCreatureSet creatures;
  214. };
  215. class CGrailObjInfo : public CSpecObjInfo
  216. {
  217. public:
  218. int radius; //place grail at the distance lesser or equal radius from this place
  219. };
  220. class CCreGenObjInfo : public CSpecObjInfo
  221. {
  222. public:
  223. unsigned char player; //owner
  224. bool asCastle;
  225. int identifier;
  226. unsigned char castles[2]; //allowed castles
  227. };
  228. class CCreGen2ObjInfo : public CSpecObjInfo
  229. {
  230. public:
  231. unsigned char player; //owner
  232. bool asCastle;
  233. int identifier;
  234. unsigned char castles[2]; //allowed castles
  235. unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6>
  236. };
  237. class CCreGen3ObjInfo : public CSpecObjInfo
  238. {
  239. public:
  240. unsigned char player; //owner
  241. unsigned char minLevel, maxLevel; //minimal and maximal level of creature in dwelling: <0, 6>
  242. };
  243. class CBorderGuardObjInfo : public CSpecObjInfo //copied form seer huts, seems to be similar
  244. {
  245. public:
  246. 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
  247. bool isDayLimit; //if true, there is a day limit
  248. int lastDay; //after this day (first day is 0) mission cannot be completed
  249. //for mission 1
  250. int m1level;
  251. //for mission 2
  252. int m2attack, m2defence, m2power, m2knowledge;
  253. //for mission 3
  254. unsigned char m3bytes[4];
  255. //for mission 4
  256. unsigned char m4bytes[4];
  257. //for mission 5
  258. std::vector<CArtifact *> m5arts;
  259. //for mission 6
  260. std::vector<CCreature *> m6cre;
  261. std::vector<int> m6number;
  262. //for mission 7
  263. int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold;
  264. //for mission 8
  265. CHero * m8hero;
  266. //for mission 9
  267. int m9player; //number; from 0 to 7
  268. std::string firstVisitText, nextVisitText, completedText;
  269. };
  270. class CObject //typical object that can be encountered on a map
  271. {
  272. public:
  273. std::string name; //object's name
  274. };
  275. class CGDefInfo;
  276. class CGObjectInstance
  277. {
  278. public:
  279. int3 pos; //h3m pos
  280. int ID, subID; //normal ID (this one from OH3 maps ;])
  281. int id;//number of object in CObjectHandler's vector
  282. CGDefInfo * defInfo;
  283. CCPPObjectScript * state;
  284. CSpecObjInfo * info;
  285. int tempOwner; //uzywane dla szybkosci, skrypt ma obowiazek aktualizowac te zmienna
  286. bool blockVisit;
  287. virtual bool isHero() const;
  288. int getOwner() const;
  289. void setOwner(int ow);
  290. int getWidth() const; //returns width of object graphic in tiles
  291. int getHeight() const; //returns height of object graphic in tiles
  292. 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)
  293. bool operator<(const CGObjectInstance & cmp) const; //screen printing priority comparing
  294. CGObjectInstance();
  295. virtual ~CGObjectInstance();
  296. CGObjectInstance(const CGObjectInstance & right);
  297. CGObjectInstance& operator=(const CGObjectInstance & right);
  298. };
  299. class CGHeroInstance : public CGObjectInstance
  300. {
  301. public:
  302. int moveDir;
  303. bool isStanding;
  304. bool flagPrinted;
  305. CHero * type;
  306. int exp; //experience point
  307. int level; //current level of hero
  308. std::string name; //may be custom
  309. std::string biography; //may be custom
  310. int portrait; //may be custom
  311. CCreatureSet army; //army
  312. int mana; // remaining spell points
  313. std::vector<int> primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge
  314. std::vector<std::pair<int,int> > secSkills; //first - ID of skill, second - level of skill (0 - basic, 1 - adv., 2 - expert)
  315. int movement; //remaining movement points
  316. bool inTownGarrison; // if hero is in town garrison
  317. std::vector<CArtifact *> artifacts; //hero's artifacts from bag
  318. //CArtifact * artHead, * artLRing, * artRRing, * artLHand,
  319. // * artRhand, * artFeet, * artSpellBook, * artMach1,
  320. // * artMach2, * artMach3, * artMach4, * artMisc1, * artMisc2,
  321. // * artMisc3, * artMisc4, * artMisc5, * artTorso, * artNeck,
  322. // * artShoulders; //working artifacts
  323. std::vector<CArtifact *> artifWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
  324. virtual bool isHero() const;
  325. unsigned int getTileCost(EterrainType & ttype, Eroad & rdtype, Eriver & rvtype);
  326. unsigned int getLowestCreatureSpeed();
  327. unsigned int getAdditiveMoveBonus();
  328. float getMultiplicativeMoveBonus();
  329. static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
  330. int3 getPosition(bool h3m) const; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
  331. int getSightDistance() const; //returns sight distance of this hero
  332. void setPosition(int3 Pos, bool h3m); //as above, but sets position
  333. bool canWalkOnSea() const;
  334. int getCurrentLuck() const;
  335. int getCurrentMorale() const;
  336. CGHeroInstance();
  337. virtual ~CGHeroInstance();
  338. };
  339. class CGTownInstance : public CGObjectInstance
  340. {
  341. public:
  342. CTown * town;
  343. std::string name; // name of town
  344. CCreatureSet garrison;
  345. int builded; //how many buildings has been built this turn
  346. int destroyed; //how many buildings has been destroyed this turn
  347. int identifier;
  348. int income;
  349. //TODO:
  350. std::set<int> possibleBuildings, builtBuildings, h3mbuildings;
  351. std::vector<int> creatureIncome; //vector by level - that valueis addedto thebasic growth
  352. std::vector<int> creaturesLeft; //that can be recruited
  353. const CGHeroInstance * garrisonHero, *visitingHero;
  354. std::vector<CSpell *> possibleSpells, obligatorySpells, availableSpells;
  355. int getSightDistance() const; //returns sight distance
  356. bool hasFort() const;
  357. bool hasCapitol() const;
  358. int dailyIncome() const;
  359. CGTownInstance();
  360. virtual ~CGTownInstance();
  361. };
  362. class CObjectHandler
  363. {
  364. public:
  365. std::vector<CObject> objects; //vector of objects; i-th object in vector has subnumber i
  366. std::vector<CGObjectInstance*> objInstances; //vector with objects on map
  367. std::vector<int> cregens; //type 17. dwelling subid -> creature ID
  368. void loadObjects();
  369. std::vector<std::string> advobtxt;
  370. std::vector<std::string> xtrainfo;
  371. std::vector<std::string> restypes;
  372. std::vector<std::pair<std::string,std::string> > mines; //first - name; second - event description
  373. };
  374. #endif //COBJECTHANDLER_H