CObjectHandler.h 14 KB

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