2007-06-11 20:21:27 +03:00
# ifndef COBJECTHANDLER_H
# define COBJECTHANDLER_H
# include <string>
# include <vector>
2008-01-09 19:21:31 +02:00
# include <set>
2007-06-12 23:09:23 +03:00
# include "CCreatureHandler.h"
# include "CArtHandler.h"
# include "CAbilityHandler.h"
# include "CSpellHandler.h"
2007-11-19 00:58:28 +02:00
//#include "CHeroHandler.h"
using boost : : logic : : tribool ;
class CCPPObjectScript ;
class CGObjectInstance ;
2007-10-27 22:38:48 +03:00
class CScript ;
class CObjectScript ;
class CGHeroInstance ;
class CTown ;
class CHero ;
class CBuilding ;
class CSpell ;
2007-06-11 20:21:27 +03:00
class CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes
{
} ;
2007-06-12 23:09:23 +03:00
class CEventObjInfo : public CSpecObjInfo
{
public :
bool areGuarders ; //true if there are
CCreatureSet guarders ;
bool isMessage ; //true if there is a message
std : : string message ;
unsigned int gainedExp ;
int manaDiff ; //amount of gained / lost mana
int moraleDiff ; //morale modifier
int luckDiff ; //luck modifier
int wood , mercury , ore , sulfur , crystal , gems , gold ; //gained / lost resources
unsigned int attack ; //added attack points
unsigned int defence ; //added defence points
unsigned int power ; //added power points
unsigned int knowledge ; //added knowledge points
2007-06-13 23:17:48 +03:00
std : : vector < CAbility * > abilities ; //gained abilities
2007-06-12 23:09:23 +03:00
std : : vector < int > abilityLevels ; //levels of gained abilities
2007-06-13 23:17:48 +03:00
std : : vector < CArtifact * > artifacts ; //gained artifacts
std : : vector < CSpell * > spells ; //gained spells
2007-06-12 23:09:23 +03:00
CCreatureSet creatures ; //gained creatures
unsigned char availableFor ; //players whom this event is available for
bool computerActivate ; //true if computre player can activate this event
bool humanActivate ; //true if human player can activate this event
} ;
2007-06-13 23:17:48 +03:00
class CHeroObjInfo : public CSpecObjInfo
{
public :
2007-06-15 19:50:02 +03:00
unsigned char bytes [ 4 ] ; //mysterius bytes identifying hero in a strange way
2007-06-13 23:17:48 +03:00
int player ;
CHero * type ;
std : : string name ; //if nonstandard
2007-06-14 20:07:26 +03:00
bool standardGarrison ; //true if hero has standard garrison
2007-06-13 23:17:48 +03:00
CCreatureSet garrison ; //hero's army
2007-06-14 20:07:26 +03:00
std : : vector < CArtifact * > artifacts ; //hero's artifacts from bag
2008-01-30 12:55:43 +02:00
//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
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
2007-06-13 23:17:48 +03:00
bool isGuarding ;
int guardRange ; //range of hero's guard
std : : string biography ; //if nonstandard
bool sex ; //if true, reverse hero's sex
std : : vector < CSpell * > spells ; //hero's spells
int attack , defence , power , knowledge ; //main hero's attributes
unsigned int experience ; //hero's experience points
std : : vector < CAbility * > abilities ; //hero's abilities
std : : vector < int > abilityLevels ; //hero ability levels
2007-08-26 19:02:36 +03:00
bool defaultMainStats ; //if true attack, defence, power and knowledge are typical
2007-10-27 22:38:48 +03:00
CGHeroInstance * myInstance ; //pointer to appropriate hero instance
2007-06-15 19:50:02 +03:00
} ;
class CCreatureObjInfo : public CSpecObjInfo
{
public :
unsigned char bytes [ 4 ] ; //mysterious bytes identifying creature
unsigned int number ; //number of units (0 - random)
unsigned char character ; //chracter of this set of creatures (0 - the most friendly, 4 - the most hostile)
std : : string message ; //message printed for attacking hero
int wood , mercury , ore , sulfur , crytal , gems , gold ; //resources gained to hero that has won with monsters
CArtifact * gainedArtifact ; //artifact gained to hero
bool neverFlees ; //if true, the troops will never flee
bool notGrowingTeam ; //if true, number of units won't grow
} ;
class CSignObjInfo : public CSpecObjInfo
{
public :
std : : string message ; //message
} ;
class CSeerHutObjInfo : public CSpecObjInfo
{
public :
2008-01-08 18:08:25 +02:00
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
2007-06-15 19:50:02 +03:00
bool isDayLimit ; //if true, there is a day limit
int lastDay ; //after this day (first day is 0) mission cannot be completed
//for mission 1
int m1level ;
//for mission 2
int m2attack , m2defence , m2power , m2knowledge ;
//for mission 3
unsigned char m3bytes [ 4 ] ;
//for mission 4
unsigned char m4bytes [ 4 ] ;
//for mission 5
std : : vector < CArtifact * > m5arts ;
//for mission 6
std : : vector < CCreature * > m6cre ;
std : : vector < int > m6number ;
//for mission 7
int m7wood , m7mercury , m7ore , m7sulfur , m7crystal , m7gems , m7gold ;
//for mission 8
CHero * m8hero ;
//for mission 9
int m9player ; //number; from 0 to 7
std : : string firstVisitText , nextVisitText , completedText ;
2007-06-15 23:11:52 +03:00
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
//for reward 1
int r1exp ;
//for reward 2
int r2mana ;
//for reward 3
int r3morale ;
//for reward 4
int r4luck ;
//for reward 5
unsigned char r5type ; //0 - wood, 1 - mercury, 2 - ore, 3 - sulfur, 4 - crystal, 5 - gems, 6 - gold
int r5amount ;
//for reward 6
unsigned char r6type ; //0 - attack, 1 - defence, 2 - power, 3 - knowledge
int r6amount ;
//for reward 7
CAbility * r7ability ;
unsigned char r7level ; //1 - basic, 2 - advanced, 3 - expert
//for reward 8
CArtifact * r8art ;
//for reward 9
CSpell * r9spell ;
//for reward 10
CCreature * r10creature ;
int r10amount ;
} ;
class CWitchHutObjInfo : public CSpecObjInfo
{
public :
std : : vector < CAbility * > allowedAbilities ;
} ;
class CScholarObjInfo : public CSpecObjInfo
{
public :
unsigned char bonusType ; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell
unsigned char r0type ;
CAbility * r1 ;
CSpell * r2 ;
} ;
class CGarrisonObjInfo : public CSpecObjInfo
{
public :
unsigned char player ; //255 - nobody; 0 - 7 - players
CCreatureSet units ;
bool movableUnits ; //if true, units can be moved
} ;
class CArtifactObjInfo : public CSpecObjInfo
{
public :
bool areGuards ;
std : : string message ;
CCreatureSet guards ;
} ;
class CResourceObjInfo : public CSpecObjInfo
{
public :
bool randomAmount ;
int amount ; //if not random
bool areGuards ;
CCreatureSet guards ;
std : : string message ;
2007-06-13 23:17:48 +03:00
} ;
2007-06-17 19:59:14 +03:00
class CPlayerOnlyObjInfo : public CSpecObjInfo
2007-06-16 23:12:08 +03:00
{
public :
unsigned char player ; //FF - nobody, 0 - 7
} ;
class CShrineObjInfo : public CSpecObjInfo
{
public :
unsigned char spell ; //number of spell or 255
} ;
2007-06-17 19:59:14 +03:00
class CSpellScrollObjinfo : public CSpecObjInfo
{
public :
std : : string message ;
CSpell * spell ;
bool areGuarders ;
CCreatureSet guarders ;
} ;
class CPandorasBoxObjInfo : public CSpecObjInfo
{
public :
std : : string message ;
bool areGuarders ;
CCreatureSet guarders ;
//gained things:
unsigned int gainedExp ;
int manaDiff ;
int moraleDiff ;
int luckDiff ;
int wood , mercury , ore , sulfur , crystal , gems , gold ;
int attack , defence , power , knowledge ;
std : : vector < CAbility * > abilities ;
std : : vector < int > abilityLevels ;
std : : vector < CArtifact * > artifacts ;
std : : vector < CSpell * > spells ;
CCreatureSet creatures ;
} ;
class CGrailObjInfo : public CSpecObjInfo
{
public :
int radius ; //place grail at the distance lesser or equal radius from this place
} ;
class CCreGenObjInfo : public CSpecObjInfo
{
public :
unsigned char player ; //owner
bool asCastle ;
unsigned char bytes [ 4 ] ; //castle identifier
unsigned char castles [ 2 ] ; //allowed castles
} ;
class CCreGen2ObjInfo : public CSpecObjInfo
{
public :
unsigned char player ; //owner
bool asCastle ;
unsigned char bytes [ 4 ] ; //castle identifier
unsigned char castles [ 2 ] ; //allowed castles
unsigned char minLevel , maxLevel ; //minimal and maximal level of creature in dwelling: <0, 6>
} ;
class CCreGen3ObjInfo : public CSpecObjInfo
{
public :
unsigned char player ; //owner
unsigned char minLevel , maxLevel ; //minimal and maximal level of creature in dwelling: <0, 6>
} ;
class CBorderGuardObjInfo : public CSpecObjInfo //copied form seer huts, seems to be similar
{
public :
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
bool isDayLimit ; //if true, there is a day limit
int lastDay ; //after this day (first day is 0) mission cannot be completed
//for mission 1
int m1level ;
//for mission 2
int m2attack , m2defence , m2power , m2knowledge ;
//for mission 3
unsigned char m3bytes [ 4 ] ;
//for mission 4
unsigned char m4bytes [ 4 ] ;
//for mission 5
std : : vector < CArtifact * > m5arts ;
//for mission 6
std : : vector < CCreature * > m6cre ;
std : : vector < int > m6number ;
//for mission 7
int m7wood , m7mercury , m7ore , m7sulfur , m7crystal , m7gems , m7gold ;
//for mission 8
CHero * m8hero ;
//for mission 9
int m9player ; //number; from 0 to 7
std : : string firstVisitText , nextVisitText , completedText ;
} ;
2007-06-11 20:21:27 +03:00
class CObject //typical object that can be encountered on a map
{
public :
std : : string name ; //object's name
} ;
class CObjectInstance //instance of object
{
public :
int defNumber ; //specifies number of def file with animation of this object
2007-08-11 17:58:07 +03:00
int defObjInfoNumber ; //number of this object's def's additional informations in CDefObjInfo's vector
2007-09-30 19:16:00 +03:00
int id ; //number of object in CObjectHandler's vector //TODO: absolutnie wywalic i zastapic czyms sensownym
2007-08-04 00:47:34 +03:00
int3 pos ; // position
2007-06-11 20:21:27 +03:00
CSpecObjInfo * info ; //pointer to something with additional information
2007-09-15 21:04:12 +03:00
bool isHero ; //true if this is a hero
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)
2007-10-08 21:47:23 +03:00
bool isStanding ; //true if is standing, flase if is moving
2007-10-13 21:49:43 +03:00
unsigned char flagPrinted ; //true if flag has been printed //number of print hits
2007-10-07 19:01:53 +03:00
unsigned char owner ; //if 254, object cannot have owner; if it has, it equal to owner's ID (or 255, when no owner)
2007-10-26 20:55:33 +03:00
int getWidth ( ) const ; //returns width of object graphic in tiles
int getHeight ( ) const ; //returns height of object graphic in tiles
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)
2007-08-09 19:28:01 +03:00
bool operator < ( const CObjectInstance & cmp ) const ; //screen printing priority comparing
2007-06-11 20:21:27 +03:00
} ;
2007-10-27 22:38:48 +03:00
class CGDefInfo
{
public :
std : : string name ;
unsigned char visitMap [ 6 ] ;
unsigned char blockMap [ 6 ] ;
2007-11-03 18:46:08 +02:00
int id , subid ; //of object described by this defInfo
2007-10-28 19:56:16 +02:00
int terrainAllowed , //on which terrain it is possible to place object
terrainMenu ; //in which menus in map editor object will be showed
2007-11-03 18:46:08 +02:00
int type ; //(0- ground, 1- towns, 2-creatures, 3- heroes, 4-artifacts, 5- resources)
2007-10-27 22:38:48 +03:00
CDefHandler * handler ;
int printPriority ;
bool isOnDefList ;
bool isVisitable ( ) ;
} ;
2007-11-19 00:58:28 +02:00
//class CObjectType
//{
//public:
// CGObjectInstance * ourObj;
// int type;
// int owner; //254 - can't be flagged; 255 - neutral
////};
//class IVisitable
//{
// virtual void newObject(CGObjectInstance *os);
// virtual void onHeroVisit(CGObjectInstance *os, int heroID);
// virtual void getRightText(tribool visited);
// virtual void getHoverText(tribool visited);
//};
//
//class CVisitableOPH //object visitable once per hero
//{
// virtual void newObject(CGObjectInstance *os);
// virtual void onHeroVisit(CGObjectInstance *os, int heroID);
// virtual void getRightText(tribool visited);
// virtual void getHoverText(tribool visited);
//};
2007-10-27 22:38:48 +03:00
class CGObjectInstance
{
public :
int3 pos ; //h3m pos
int ID , subID ; //normal ID (this one from OH3 maps ;])
int id ; //number of object in CObjectHandler's vector
CGDefInfo * defInfo ;
2007-11-19 00:58:28 +02:00
CCPPObjectScript * state ;
2007-10-27 22:38:48 +03:00
CSpecObjInfo * info ;
int defObjInfoNumber ;
2007-11-19 00:58:28 +02:00
int tempOwner ; //uzywane dla szybkosci, skrypt ma obowiazek aktualizowac te zmienna
2007-11-24 00:33:55 +02:00
bool blockVisit ;
2007-10-27 22:38:48 +03:00
virtual bool isHero ( ) const ;
int getOwner ( ) const ;
2007-11-19 00:58:28 +02:00
void setOwner ( int ow ) ;
2007-10-27 22:38:48 +03:00
int getWidth ( ) const ; //returns width of object graphic in tiles
int getHeight ( ) const ; //returns height of object graphic in tiles
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)
bool operator < ( const CGObjectInstance & cmp ) const ; //screen printing priority comparing
CGObjectInstance ( ) ;
virtual ~ CGObjectInstance ( ) ;
CGObjectInstance ( const CGObjectInstance & right ) ;
CGObjectInstance & operator = ( const CGObjectInstance & right ) ;
} ;
class CGHeroInstance : public CGObjectInstance
{
public :
int moveDir ;
bool isStanding ;
bool flagPrinted ;
CHero * type ;
int exp ; //experience point
int level ; //current level of hero
std : : string name ; //may be custom
std : : string biography ; //may be custom
int portrait ; //may be custom
CCreatureSet army ; //army
int mana ; // remaining spell points
std : : vector < int > primSkills ; //0-attack, 1-defence, 2-spell power, 3-knowledge
std : : vector < std : : pair < int , int > > secSkills ; //first - ID of skill, second - level of skill (0 - basic, 1 - adv., 2 - expert)
int movement ; //remaining movement points
bool inTownGarrison ; // if hero is in town garrison
2008-01-19 15:19:58 +02:00
std : : vector < CArtifact * > artifacts ; //hero's artifacts from bag
2008-01-30 12:55:43 +02:00
//CArtifact * artHead, * artLRing, * artRRing, * artLHand,
// * artRhand, * artFeet, * artSpellBook, * artMach1,
// * artMach2, * artMach3, * artMach4, * artMisc1, * artMisc2,
// * artMisc3, * artMisc4, * artMisc5, * artTorso, * artNeck,
// * artShoulders; //working artifacts
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
2008-01-19 15:19:58 +02:00
2007-10-27 22:38:48 +03:00
virtual bool isHero ( ) const ;
unsigned int getTileCost ( EterrainType & ttype , Eroad & rdtype , Eriver & rvtype ) ;
unsigned int getLowestCreatureSpeed ( ) ;
unsigned int getAdditiveMoveBonus ( ) ;
2007-11-24 00:33:55 +02:00
float getMultiplicativeMoveBonus ( ) ;
2007-10-27 22:38:48 +03:00
static int3 convertPosition ( int3 src , bool toh3m ) ; //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
int3 getPosition ( bool h3m ) const ; //h3m=true - returns position of hero object; h3m=false - returns position of hero 'manifestation'
int getSightDistance ( ) const ; //returns sight distance of this hero
void setPosition ( int3 Pos , bool h3m ) ; //as above, but sets position
bool canWalkOnSea ( ) const ;
int getCurrentLuck ( ) const ;
int getCurrentMorale ( ) const ;
virtual ~ CGHeroInstance ( ) ;
} ;
class CGTownInstance : public CGObjectInstance
{
public :
CTown * town ;
std : : string name ; // name of town
CCreatureSet garrison ;
int builded ; //how many buildings has been built this turn
int destroyed ; //how many buildings has been destroyed this turn
2008-01-09 19:21:31 +02:00
int income ;
2007-10-27 22:38:48 +03:00
//TODO:
2008-01-19 13:55:04 +02:00
std : : set < int > possibleBuildings , builtBuildings , h3mbuildings ;
2008-01-29 17:08:41 +02:00
std : : vector < int > creatureIncome ; //vector by level - that valueis addedto thebasic growth
2007-10-27 22:38:48 +03:00
std : : vector < int > creaturesLeft ; //that can be recruited
2008-01-28 16:01:09 +02:00
const CGHeroInstance * garrisonHero , * visitingHero ;
2007-10-27 22:38:48 +03:00
std : : vector < CSpell * > possibleSpells , obligatorySpells , availableSpells ;
int getSightDistance ( ) const ; //returns sight distance
2008-01-09 19:21:31 +02:00
bool hasFort ( ) const ;
int dailyIncome ( ) const ;
2007-10-27 22:38:48 +03:00
CGTownInstance ( ) ;
virtual ~ CGTownInstance ( ) ;
} ;
2007-06-11 20:21:27 +03:00
class CObjectHandler
{
public :
std : : vector < CObject > objects ; //vector of objects; i-th object in vector has subnumber i
2007-10-27 22:38:48 +03:00
std : : vector < CGObjectInstance * > objInstances ; //vector with objects on map
2007-06-11 20:21:27 +03:00
void loadObjects ( ) ;
2007-11-19 00:58:28 +02:00
std : : vector < std : : string > advobtxt ;
std : : vector < std : : string > xtrainfo ;
2007-11-25 15:16:45 +02:00
std : : vector < std : : string > restypes ;
std : : vector < std : : pair < std : : string , std : : string > > mines ; //first - name; second - event description
2007-06-11 20:21:27 +03:00
} ;
# endif //COBJECTHANDLER_H