CObjectHandler.h 15 KB

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