CObjectHandler.h 13 KB

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