mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-20 20:23:03 +02:00
unified guardians names
This commit is contained in:
parent
b356524aee
commit
b54a3bfb7c
@ -1,8 +1,5 @@
|
||||
#ifndef __AI_BASE_H__
|
||||
#define __AI_BASE_H__
|
||||
#ifndef __AI_BASE_H__
|
||||
#define __AI_BASE_H__
|
||||
|
||||
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
@ -11,4 +8,3 @@
|
||||
#define AI_INTERFACE_VER 1
|
||||
|
||||
#endif // __AI_BASE_H__
|
||||
#endif // __AI_BASE_H__
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef ADVENTUREMAPBUTTON_H
|
||||
#define ADVENTUREMAPBUTTON_H
|
||||
#ifndef __ADVENTUREMAPBUTTON_H__
|
||||
#define __ADVENTUREMAPBUTTON_H__
|
||||
|
||||
|
||||
|
||||
@ -95,4 +95,5 @@ public:
|
||||
int Value=0, bool Horizontal=true);
|
||||
~CSlider();
|
||||
};
|
||||
#endif //ADVENTUREMAPBUTTON_H
|
||||
|
||||
#endif // __ADVENTUREMAPBUTTON_H__
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef CBATTLEINTERFACE_H
|
||||
#define CBATTLEINTERFACE_H
|
||||
#ifndef __CBATTLEINTERFACE_H__
|
||||
#define __CBATTLEINTERFACE_H__
|
||||
|
||||
|
||||
|
||||
@ -255,4 +255,5 @@ public:
|
||||
friend class CBattleReslutWindow;
|
||||
friend class CPlayerInterface;
|
||||
};
|
||||
#endif //CBATTLEINTERFACE_H
|
||||
|
||||
#endif // __CBATTLEINTERFACE_H__
|
||||
|
379
CCallback.h
379
CCallback.h
@ -1,189 +1,190 @@
|
||||
#ifndef CCALLBACK_H
|
||||
#define CCALLBACK_H
|
||||
|
||||
#include "global.h"
|
||||
#ifdef _WIN32
|
||||
#include "tchar.h"
|
||||
#else
|
||||
#include "tchar_amigaos4.h" //XXX this is mingw header are we need this for something? for 'true'
|
||||
//support of unicode we should use ICU or some boost wraper areound it
|
||||
//(boost using this lib during compilation i dont know what for exactly)
|
||||
#endif
|
||||
#include "CGameState.h"
|
||||
|
||||
class CGHeroInstance;
|
||||
class CGameState;
|
||||
struct CPath;
|
||||
class CGObjectInstance;
|
||||
class CArmedInstance;
|
||||
class SComponent;
|
||||
class IChosen;
|
||||
class CSelectableComponent;
|
||||
struct BattleAction;
|
||||
class CGTownInstance;
|
||||
struct StartInfo;
|
||||
class CStack;
|
||||
struct lua_State;
|
||||
class CClient;
|
||||
//structure gathering info about upgrade possibilites
|
||||
|
||||
class ICallback
|
||||
{
|
||||
public:
|
||||
virtual bool moveHero(int ID, CPath * path, int idtype, int pathType=0)=0;//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero
|
||||
//pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
|
||||
virtual int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2)=0;//swaps creatures between two posiibly different garrisons // TODO: AI-unsafe code - fix it!
|
||||
virtual int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2)=0;//joins first stack tothe second (creatures must be same type)
|
||||
virtual int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val)=0;//split creatures from the first stack
|
||||
virtual bool dismissHero(const CGHeroInstance * hero)=0; //dismisses diven hero; true - successfuly, false - not successfuly
|
||||
virtual bool swapArifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)=0; //swaps artifacts between two given heroes
|
||||
virtual void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount)=0;
|
||||
virtual bool dismissCreature(const CArmedInstance *obj, int stackPos)=0;
|
||||
virtual bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1)=0; //if newID==-1 then best possible upgrade will be made
|
||||
virtual void endTurn()=0;
|
||||
virtual void swapGarrisonHero(const CGTownInstance *town)=0;
|
||||
virtual void buyArtifact(const CGHeroInstance *hero, int aid)=0; //used to buy artifacts in towns (including spell book in the guild and war machines in blacksmith)
|
||||
virtual void trade(int mode, int id1, int id2, int val1)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce
|
||||
virtual void setFormation(const CGHeroInstance * hero, bool tight)=0;
|
||||
virtual void setSelection(const CArmedInstance * obj)=0;
|
||||
virtual void recruitHero(const CGTownInstance *town, const CGHeroInstance *hero)=0;
|
||||
|
||||
//get info
|
||||
virtual bool verifyPath(CPath * path, bool blockSea)const =0;
|
||||
virtual int getDate(int mode=0)const =0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
virtual std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap()const =0; //returns visibility map (TODO: make it const)
|
||||
virtual const CGHeroInstance * getHeroInfo(int val, int mode=2)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||
virtual int getResourceAmount(int type)const =0;
|
||||
virtual int howManyHeroes()const =0;
|
||||
virtual const CGTownInstance * getTownInfo(int val, bool mode)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||
virtual int howManyTowns()const =0;
|
||||
virtual std::vector < std::string > getObjDescriptions(int3 pos)const =0; //returns descriptions of objects at pos in order from the lowest to the highest
|
||||
virtual std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true)const =0;
|
||||
virtual bool isVisible(int3 pos)const =0;
|
||||
virtual int getMyColor()const =0;
|
||||
virtual int getMySerial()const =0;
|
||||
virtual int getHeroSerial(const CGHeroInstance * hero)const =0;
|
||||
virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)const =0;
|
||||
virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)const =0;
|
||||
virtual const StartInfo * getStartInfo()const =0;
|
||||
virtual std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos)const =0;
|
||||
virtual std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos)const =0;
|
||||
virtual void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0)const =0;
|
||||
virtual std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const =0;
|
||||
virtual int3 getMapSize() const =0; //returns size of map - z is 1 for one - level map and 2 for two level map
|
||||
virtual std::vector<const CGHeroInstance *> getAvailableHeroes(const CGTownInstance * town) const =0; //heroes that can be recruited
|
||||
|
||||
//battle
|
||||
virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
|
||||
virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield
|
||||
virtual int battleGetStack(int pos)=0; //returns ID of stack on the tile
|
||||
virtual CStack * battleGetStackByID(int ID)=0; //returns stack info by given ID
|
||||
virtual CStack * battleGetStackByPos(int pos)=0; //returns stack info by given pos
|
||||
virtual int battleGetPos(int stack)=0; //returns position (tile ID) of stack
|
||||
virtual int battleMakeAction(BattleAction* action)=0;//for casting spells by hero - DO NOT use it for moving active stack
|
||||
virtual std::map<int, CStack> battleGetStacks()=0; //returns stacks on battlefield
|
||||
virtual std::vector<CStack> battleGetStackQueue()=0; //returns vector of stack in order of their move sequence
|
||||
virtual CCreature battleGetCreature(int number)=0; //returns type of creature by given number of stack
|
||||
//virtual bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible
|
||||
virtual std::vector<int> battleGetAvailableHexes(int ID)=0; //reutrns numbers of hexes reachable by creature with id ID
|
||||
virtual bool battleIsStackMine(int ID)=0; //returns true if stack with id ID belongs to caller
|
||||
virtual bool battleCanShoot(int ID, int dest)=0; //returns true if unit with id ID can shoot to dest
|
||||
};
|
||||
|
||||
struct HeroMoveDetails
|
||||
{
|
||||
HeroMoveDetails(){};
|
||||
HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho);
|
||||
int3 src, dst; //source and destination points
|
||||
CGHeroInstance * ho; //object instance of this hero
|
||||
int owner, style; //style: 0 - normal move, 1 - teleport, 2 - instant jump
|
||||
bool successful;
|
||||
};
|
||||
|
||||
class CCallback : public ICallback
|
||||
{
|
||||
private:
|
||||
CCallback(CGameState * GS, int Player, CClient *C):gs(GS), cl(C), player(Player){};
|
||||
CGameState * gs;
|
||||
CClient *cl;
|
||||
bool isVisible(int3 pos, int Player) const;
|
||||
bool isVisible(CGObjectInstance *obj, int Player) const;
|
||||
|
||||
protected:
|
||||
int player;
|
||||
|
||||
public:
|
||||
//commands
|
||||
bool moveHero(int ID, CPath * path, int idtype, int pathType=0);//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero
|
||||
//pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
|
||||
void selectionMade(int selection, int asker);
|
||||
int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2);
|
||||
int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2); //first goes to the second
|
||||
int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val);
|
||||
bool dismissHero(const CGHeroInstance * hero);
|
||||
bool swapArifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2);
|
||||
bool buildBuilding(const CGTownInstance *town, si32 buildingID);
|
||||
void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount);
|
||||
bool dismissCreature(const CArmedInstance *obj, int stackPos);
|
||||
bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1);
|
||||
void endTurn();
|
||||
void swapGarrisonHero(const CGTownInstance *town);
|
||||
void buyArtifact(const CGHeroInstance *hero, int aid);
|
||||
void trade(int mode, int id1, int id2, int val1);
|
||||
void setFormation(const CGHeroInstance * hero, bool tight);
|
||||
void setSelection(const CArmedInstance * obj);
|
||||
void recruitHero(const CGTownInstance *town, const CGHeroInstance *hero);
|
||||
|
||||
//get info
|
||||
bool verifyPath(CPath * path, bool blockSea) const;
|
||||
int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap() const; //returns visibility map (TODO: make it const)
|
||||
const CGHeroInstance * getHeroInfo(int val, int mode=2) const; //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||
int getResourceAmount(int type) const;
|
||||
std::vector<si32> getResourceAmount() const;
|
||||
int howManyHeroes() const;
|
||||
const CGTownInstance * getTownInfo(int val, bool mode) const; //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||
std::vector < const CGTownInstance *> getTownsInfo(bool onlyOur=true) const;
|
||||
int howManyTowns()const;
|
||||
std::vector < std::string > getObjDescriptions(int3 pos) const; //returns descriptions of objects at pos in order from the lowest to the highest
|
||||
std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true) const;
|
||||
bool isVisible(int3 pos) const;
|
||||
int getMyColor() const;
|
||||
int getHeroSerial(const CGHeroInstance * hero) const;
|
||||
int getMySerial() const;
|
||||
const CCreatureSet* getGarrison(const CGObjectInstance *obj) const;
|
||||
UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos) const;
|
||||
const StartInfo * getStartInfo() const;
|
||||
std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos) const;
|
||||
std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos) const;
|
||||
void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0) const;
|
||||
std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
|
||||
int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
|
||||
std::vector<const CGHeroInstance *> getAvailableHeroes(const CGTownInstance * town) const; //heroes that can be recruited
|
||||
|
||||
//battle
|
||||
int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
|
||||
int battleGetObstaclesAtTile(int tile); //returns bitfield
|
||||
int battleGetStack(int pos); //returns ID of stack on the tile
|
||||
CStack * battleGetStackByID(int ID); //returns stack info by given ID
|
||||
CStack * battleGetStackByPos(int pos); //returns stack info by given pos
|
||||
int battleGetPos(int stack); //returns position (tile ID) of stack
|
||||
int battleMakeAction(BattleAction* action);//for casting spells by hero - DO NOT use it for moving active stack
|
||||
std::map<int, CStack> battleGetStacks(); //returns stacks on battlefield
|
||||
std::vector<CStack> battleGetStackQueue(); //returns vector of stack in order of their move sequence
|
||||
CCreature battleGetCreature(int number); //returns type of creature by given number of stack
|
||||
std::vector<int> battleGetAvailableHexes(int ID); //reutrns numbers of hexes reachable by creature with id ID
|
||||
bool battleIsStackMine(int ID); //returns true if stack with id ID belongs to caller
|
||||
bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest
|
||||
|
||||
|
||||
//XXX hmmm _tmain on _GNUC_ wtf?
|
||||
//friends
|
||||
friend class CClient;
|
||||
#ifndef __GNUC__
|
||||
friend int _tmain(int argc, _TCHAR* argv[]);
|
||||
#else
|
||||
friend int main(int argc, char** argv);
|
||||
#endif
|
||||
};
|
||||
#endif //CCALLBACK_H
|
||||
#ifndef __CCALLBACK_H__
|
||||
#define __CCALLBACK_H__
|
||||
|
||||
#include "global.h"
|
||||
#ifdef _WIN32
|
||||
#include "tchar.h"
|
||||
#else
|
||||
#include "tchar_amigaos4.h" //XXX this is mingw header are we need this for something? for 'true'
|
||||
//support of unicode we should use ICU or some boost wraper areound it
|
||||
//(boost using this lib during compilation i dont know what for exactly)
|
||||
#endif
|
||||
#include "CGameState.h"
|
||||
|
||||
class CGHeroInstance;
|
||||
class CGameState;
|
||||
struct CPath;
|
||||
class CGObjectInstance;
|
||||
class CArmedInstance;
|
||||
class SComponent;
|
||||
class IChosen;
|
||||
class CSelectableComponent;
|
||||
struct BattleAction;
|
||||
class CGTownInstance;
|
||||
struct StartInfo;
|
||||
class CStack;
|
||||
struct lua_State;
|
||||
class CClient;
|
||||
//structure gathering info about upgrade possibilites
|
||||
|
||||
class ICallback
|
||||
{
|
||||
public:
|
||||
virtual bool moveHero(int ID, CPath * path, int idtype, int pathType=0)=0;//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero
|
||||
//pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
|
||||
virtual int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2)=0;//swaps creatures between two posiibly different garrisons // TODO: AI-unsafe code - fix it!
|
||||
virtual int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2)=0;//joins first stack tothe second (creatures must be same type)
|
||||
virtual int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val)=0;//split creatures from the first stack
|
||||
virtual bool dismissHero(const CGHeroInstance * hero)=0; //dismisses diven hero; true - successfuly, false - not successfuly
|
||||
virtual bool swapArifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2)=0; //swaps artifacts between two given heroes
|
||||
virtual void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount)=0;
|
||||
virtual bool dismissCreature(const CArmedInstance *obj, int stackPos)=0;
|
||||
virtual bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1)=0; //if newID==-1 then best possible upgrade will be made
|
||||
virtual void endTurn()=0;
|
||||
virtual void swapGarrisonHero(const CGTownInstance *town)=0;
|
||||
virtual void buyArtifact(const CGHeroInstance *hero, int aid)=0; //used to buy artifacts in towns (including spell book in the guild and war machines in blacksmith)
|
||||
virtual void trade(int mode, int id1, int id2, int val1)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce
|
||||
virtual void setFormation(const CGHeroInstance * hero, bool tight)=0;
|
||||
virtual void setSelection(const CArmedInstance * obj)=0;
|
||||
virtual void recruitHero(const CGTownInstance *town, const CGHeroInstance *hero)=0;
|
||||
|
||||
//get info
|
||||
virtual bool verifyPath(CPath * path, bool blockSea)const =0;
|
||||
virtual int getDate(int mode=0)const =0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
virtual std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap()const =0; //returns visibility map (TODO: make it const)
|
||||
virtual const CGHeroInstance * getHeroInfo(int val, int mode=2)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||
virtual int getResourceAmount(int type)const =0;
|
||||
virtual int howManyHeroes()const =0;
|
||||
virtual const CGTownInstance * getTownInfo(int val, bool mode)const =0; //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||
virtual int howManyTowns()const =0;
|
||||
virtual std::vector < std::string > getObjDescriptions(int3 pos)const =0; //returns descriptions of objects at pos in order from the lowest to the highest
|
||||
virtual std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true)const =0;
|
||||
virtual bool isVisible(int3 pos)const =0;
|
||||
virtual int getMyColor()const =0;
|
||||
virtual int getMySerial()const =0;
|
||||
virtual int getHeroSerial(const CGHeroInstance * hero)const =0;
|
||||
virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)const =0;
|
||||
virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)const =0;
|
||||
virtual const StartInfo * getStartInfo()const =0;
|
||||
virtual std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos)const =0;
|
||||
virtual std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos)const =0;
|
||||
virtual void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0)const =0;
|
||||
virtual std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const =0;
|
||||
virtual int3 getMapSize() const =0; //returns size of map - z is 1 for one - level map and 2 for two level map
|
||||
virtual std::vector<const CGHeroInstance *> getAvailableHeroes(const CGTownInstance * town) const =0; //heroes that can be recruited
|
||||
|
||||
//battle
|
||||
virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
|
||||
virtual int battleGetObstaclesAtTile(int tile)=0; //returns bitfield
|
||||
virtual int battleGetStack(int pos)=0; //returns ID of stack on the tile
|
||||
virtual CStack * battleGetStackByID(int ID)=0; //returns stack info by given ID
|
||||
virtual CStack * battleGetStackByPos(int pos)=0; //returns stack info by given pos
|
||||
virtual int battleGetPos(int stack)=0; //returns position (tile ID) of stack
|
||||
virtual int battleMakeAction(BattleAction* action)=0;//for casting spells by hero - DO NOT use it for moving active stack
|
||||
virtual std::map<int, CStack> battleGetStacks()=0; //returns stacks on battlefield
|
||||
virtual std::vector<CStack> battleGetStackQueue()=0; //returns vector of stack in order of their move sequence
|
||||
virtual CCreature battleGetCreature(int number)=0; //returns type of creature by given number of stack
|
||||
//virtual bool battleMoveCreature(int ID, int dest)=0; //moves creature with id ID to dest if possible
|
||||
virtual std::vector<int> battleGetAvailableHexes(int ID)=0; //reutrns numbers of hexes reachable by creature with id ID
|
||||
virtual bool battleIsStackMine(int ID)=0; //returns true if stack with id ID belongs to caller
|
||||
virtual bool battleCanShoot(int ID, int dest)=0; //returns true if unit with id ID can shoot to dest
|
||||
};
|
||||
|
||||
struct HeroMoveDetails
|
||||
{
|
||||
HeroMoveDetails(){};
|
||||
HeroMoveDetails(int3 Src, int3 Dst, CGHeroInstance*Ho);
|
||||
int3 src, dst; //source and destination points
|
||||
CGHeroInstance * ho; //object instance of this hero
|
||||
int owner, style; //style: 0 - normal move, 1 - teleport, 2 - instant jump
|
||||
bool successful;
|
||||
};
|
||||
|
||||
class CCallback : public ICallback
|
||||
{
|
||||
private:
|
||||
CCallback(CGameState * GS, int Player, CClient *C):gs(GS), cl(C), player(Player){};
|
||||
CGameState * gs;
|
||||
CClient *cl;
|
||||
bool isVisible(int3 pos, int Player) const;
|
||||
bool isVisible(CGObjectInstance *obj, int Player) const;
|
||||
|
||||
protected:
|
||||
int player;
|
||||
|
||||
public:
|
||||
//commands
|
||||
bool moveHero(int ID, CPath * path, int idtype, int pathType=0);//idtype: 0 - position in vector of heroes (of that player); 1 - ID of hero
|
||||
//pathType: 0 - nodes are manifestation pos, 1 - nodes are object pos
|
||||
void selectionMade(int selection, int asker);
|
||||
int swapCreatures(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2);
|
||||
int mergeStacks(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2); //first goes to the second
|
||||
int splitStack(const CGObjectInstance *s1, const CGObjectInstance *s2, int p1, int p2, int val);
|
||||
bool dismissHero(const CGHeroInstance * hero);
|
||||
bool swapArifacts(const CGHeroInstance * hero1, ui16 pos1, const CGHeroInstance * hero2, ui16 pos2);
|
||||
bool buildBuilding(const CGTownInstance *town, si32 buildingID);
|
||||
void recruitCreatures(const CGObjectInstance *obj, ui32 ID, ui32 amount);
|
||||
bool dismissCreature(const CArmedInstance *obj, int stackPos);
|
||||
bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1);
|
||||
void endTurn();
|
||||
void swapGarrisonHero(const CGTownInstance *town);
|
||||
void buyArtifact(const CGHeroInstance *hero, int aid);
|
||||
void trade(int mode, int id1, int id2, int val1);
|
||||
void setFormation(const CGHeroInstance * hero, bool tight);
|
||||
void setSelection(const CArmedInstance * obj);
|
||||
void recruitHero(const CGTownInstance *town, const CGHeroInstance *hero);
|
||||
|
||||
//get info
|
||||
bool verifyPath(CPath * path, bool blockSea) const;
|
||||
int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
std::vector< std::vector< std::vector<unsigned char> > > & getVisibilityMap() const; //returns visibility map (TODO: make it const)
|
||||
const CGHeroInstance * getHeroInfo(int val, int mode=2) const; //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||
int getResourceAmount(int type) const;
|
||||
std::vector<si32> getResourceAmount() const;
|
||||
int howManyHeroes() const;
|
||||
const CGTownInstance * getTownInfo(int val, bool mode) const; //mode = 0 -> val = serial; mode = 1 -> val = ID
|
||||
std::vector < const CGTownInstance *> getTownsInfo(bool onlyOur=true) const;
|
||||
int howManyTowns()const;
|
||||
std::vector < std::string > getObjDescriptions(int3 pos) const; //returns descriptions of objects at pos in order from the lowest to the highest
|
||||
std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true) const;
|
||||
bool isVisible(int3 pos) const;
|
||||
int getMyColor() const;
|
||||
int getHeroSerial(const CGHeroInstance * hero) const;
|
||||
int getMySerial() const;
|
||||
const CCreatureSet* getGarrison(const CGObjectInstance *obj) const;
|
||||
UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos) const;
|
||||
const StartInfo * getStartInfo() const;
|
||||
std::vector < const CGObjectInstance * > getBlockingObjs(int3 pos) const;
|
||||
std::vector < const CGObjectInstance * > getVisitableObjs(int3 pos) const;
|
||||
void getMarketOffer(int t1, int t2, int &give, int &rec, int mode=0) const;
|
||||
std::vector < const CGObjectInstance * > getFlaggableObjects(int3 pos) const;
|
||||
int3 getMapSize() const; //returns size of map - z is 1 for one - level map and 2 for two level map
|
||||
std::vector<const CGHeroInstance *> getAvailableHeroes(const CGTownInstance * town) const; //heroes that can be recruited
|
||||
|
||||
//battle
|
||||
int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship
|
||||
int battleGetObstaclesAtTile(int tile); //returns bitfield
|
||||
int battleGetStack(int pos); //returns ID of stack on the tile
|
||||
CStack * battleGetStackByID(int ID); //returns stack info by given ID
|
||||
CStack * battleGetStackByPos(int pos); //returns stack info by given pos
|
||||
int battleGetPos(int stack); //returns position (tile ID) of stack
|
||||
int battleMakeAction(BattleAction* action);//for casting spells by hero - DO NOT use it for moving active stack
|
||||
std::map<int, CStack> battleGetStacks(); //returns stacks on battlefield
|
||||
std::vector<CStack> battleGetStackQueue(); //returns vector of stack in order of their move sequence
|
||||
CCreature battleGetCreature(int number); //returns type of creature by given number of stack
|
||||
std::vector<int> battleGetAvailableHexes(int ID); //reutrns numbers of hexes reachable by creature with id ID
|
||||
bool battleIsStackMine(int ID); //returns true if stack with id ID belongs to caller
|
||||
bool battleCanShoot(int ID, int dest); //returns true if unit with id ID can shoot to dest
|
||||
|
||||
|
||||
//XXX hmmm _tmain on _GNUC_ wtf?
|
||||
//friends
|
||||
friend class CClient;
|
||||
#ifndef __GNUC__
|
||||
friend int _tmain(int argc, _TCHAR* argv[]);
|
||||
#else
|
||||
friend int main(int argc, char** argv);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // __CCALLBACK_H__
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef CCASTLEINTERFACE_H
|
||||
#define CCASTLEINTERFACE_H
|
||||
#ifndef __CCASTLEINTERFACE_H__
|
||||
#define __CCASTLEINTERFACE_H__
|
||||
|
||||
|
||||
|
||||
@ -225,4 +225,5 @@ public:
|
||||
void activate();
|
||||
void deactivate();
|
||||
};
|
||||
#endif //CCASTLEINTERFACE_H
|
||||
|
||||
#endif // __CCASTLEINTERFACE_H__
|
||||
|
@ -1,41 +1,42 @@
|
||||
#ifndef CCONSOLEHANDLER_H
|
||||
#define CCONSOLEHANDLER_H
|
||||
|
||||
#ifndef _WIN32
|
||||
#define WORD std::string
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#define _kill_thread(a,b) pthread_cancel(a);
|
||||
#else
|
||||
#define _kill_thread(a,b) TerminateThread(a,b);
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template<typename signature>
|
||||
class function;
|
||||
}
|
||||
class DLL_EXPORT CConsoleHandler
|
||||
{
|
||||
public:
|
||||
boost::function<void(const std::string &)> *cb;
|
||||
int curLvl;
|
||||
int run();
|
||||
void setColor(int level);
|
||||
CConsoleHandler();
|
||||
~CConsoleHandler();
|
||||
#ifndef _WIN32
|
||||
static void killConsole(pthread_t hThread); //for windows only, use native handle to the thread
|
||||
#else
|
||||
static void killConsole(void *hThread); //for windows only, use native handle to the thread
|
||||
#endif
|
||||
template<typename T> void print(const T &data, int level)
|
||||
{
|
||||
setColor(level);
|
||||
std::cout << data << std::flush;
|
||||
setColor(-1);
|
||||
}
|
||||
};
|
||||
|
||||
#endif //CCONSOLEHANDLER_H
|
||||
#ifndef __CCONSOLEHANDLER_H__
|
||||
#define __CCONSOLEHANDLER_H__
|
||||
|
||||
#ifndef _WIN32
|
||||
#define WORD std::string
|
||||
#endif
|
||||
|
||||
#ifndef _WIN32
|
||||
#define _kill_thread(a,b) pthread_cancel(a);
|
||||
#else
|
||||
#define _kill_thread(a,b) TerminateThread(a,b);
|
||||
#endif
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template<typename signature>
|
||||
class function;
|
||||
}
|
||||
class DLL_EXPORT CConsoleHandler
|
||||
{
|
||||
public:
|
||||
boost::function<void(const std::string &)> *cb;
|
||||
int curLvl;
|
||||
int run();
|
||||
void setColor(int level);
|
||||
CConsoleHandler();
|
||||
~CConsoleHandler();
|
||||
#ifndef _WIN32
|
||||
static void killConsole(pthread_t hThread); //for windows only, use native handle to the thread
|
||||
#else
|
||||
static void killConsole(void *hThread); //for windows only, use native handle to the thread
|
||||
#endif
|
||||
template<typename T> void print(const T &data, int level)
|
||||
{
|
||||
setColor(level);
|
||||
std::cout << data << std::flush;
|
||||
setColor(-1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // __CCONSOLEHANDLER_H__
|
||||
|
@ -1,28 +1,29 @@
|
||||
#ifndef CCURSORHANDLER_H
|
||||
#define CCURSORHANDLER_H
|
||||
#include "global.h"
|
||||
#include <vector>
|
||||
struct SDL_Thread;
|
||||
class CDefHandler;
|
||||
struct SDL_Surface;
|
||||
|
||||
class CCursorHandler //handles cursor
|
||||
{
|
||||
public:
|
||||
int mode, number;
|
||||
SDL_Surface * help;
|
||||
bool Show;
|
||||
|
||||
std::vector<CDefHandler*> cursors;
|
||||
int xpos, ypos; //position of cursor
|
||||
void initCursor(); //inits cursorHandler
|
||||
void cursorMove(const int & x, const int & y); //change cursor's positions to (x, y)
|
||||
void changeGraphic(const int & type, const int & no); //changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame no (not used for type 3)
|
||||
void draw1();
|
||||
void draw2();
|
||||
void hide(){Show=0;};
|
||||
void show(){Show=1;};
|
||||
};
|
||||
|
||||
|
||||
#endif //CCURSORHANDLER_H
|
||||
#ifndef __CCURSORHANDLER_H__
|
||||
#define __CCURSORHANDLER_H__
|
||||
#include "global.h"
|
||||
#include <vector>
|
||||
struct SDL_Thread;
|
||||
class CDefHandler;
|
||||
struct SDL_Surface;
|
||||
|
||||
class CCursorHandler //handles cursor
|
||||
{
|
||||
public:
|
||||
int mode, number;
|
||||
SDL_Surface * help;
|
||||
bool Show;
|
||||
|
||||
std::vector<CDefHandler*> cursors;
|
||||
int xpos, ypos; //position of cursor
|
||||
void initCursor(); //inits cursorHandler
|
||||
void cursorMove(const int & x, const int & y); //change cursor's positions to (x, y)
|
||||
void changeGraphic(const int & type, const int & no); //changes cursor graphic for type type (0 - adventure, 1 - combat, 2 - default, 3 - spellbook) and frame no (not used for type 3)
|
||||
void draw1();
|
||||
void draw2();
|
||||
void hide(){Show=0;};
|
||||
void show(){Show=1;};
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // __CCURSORHANDLER_H__
|
||||
|
133
CGameInfo.h
133
CGameInfo.h
@ -1,66 +1,67 @@
|
||||
#ifndef CGAMEINFO_H
|
||||
#define CGAMEINFO_H
|
||||
#include "global.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
class CMapHandler;
|
||||
class CArtHandler;
|
||||
class CHeroHandler;
|
||||
class CCreatureHandler;
|
||||
class CAbilityHandler;
|
||||
class CSpellHandler;
|
||||
class CAmbarCendamo;
|
||||
class CPreGameTextHandler;
|
||||
class CBuildingHandler;
|
||||
class CObjectHandler;
|
||||
class CMusicHandler;
|
||||
class CSemiLodHandler;
|
||||
class CDefObjInfoHandler;
|
||||
class CTownHandler;
|
||||
class CLodHandler;
|
||||
class CGeneralTextHandler;
|
||||
class CConsoleHandler;
|
||||
class CPathfinder;
|
||||
class CCursorHandler;
|
||||
class CScreenHandler;
|
||||
class CGameState;
|
||||
class CMapHandler;
|
||||
class CGameInterface;
|
||||
class CPreGame;
|
||||
class CDefHandler;
|
||||
/*
|
||||
CGameInfo class
|
||||
for allowing different functions for modifying game informations
|
||||
*/
|
||||
class CGameInfo
|
||||
{
|
||||
public:
|
||||
CGameState * state;
|
||||
CArtHandler * arth;
|
||||
CHeroHandler * heroh;
|
||||
CCreatureHandler * creh;
|
||||
CAbilityHandler * abilh;
|
||||
CSpellHandler * spellh;
|
||||
CMapHandler * mh;
|
||||
CBuildingHandler * buildh;
|
||||
CObjectHandler * objh;
|
||||
CMusicHandler * mush;
|
||||
CSemiLodHandler * sspriteh;
|
||||
CDefObjInfoHandler * dobjinfo;
|
||||
CTownHandler * townh;
|
||||
CLodHandler * spriteh;
|
||||
CLodHandler * bitmaph;
|
||||
CGeneralTextHandler * generaltexth;
|
||||
CConsoleHandler * consoleh;
|
||||
CPathfinder * pathf;
|
||||
CCursorHandler * curh;
|
||||
CScreenHandler * screenh;
|
||||
};
|
||||
|
||||
#endif //CGAMEINFO_H
|
||||
#ifndef __CGAMEINFO_H__
|
||||
#define __CGAMEINFO_H__
|
||||
#include "global.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
||||
class CMapHandler;
|
||||
class CArtHandler;
|
||||
class CHeroHandler;
|
||||
class CCreatureHandler;
|
||||
class CAbilityHandler;
|
||||
class CSpellHandler;
|
||||
class CAmbarCendamo;
|
||||
class CPreGameTextHandler;
|
||||
class CBuildingHandler;
|
||||
class CObjectHandler;
|
||||
class CMusicHandler;
|
||||
class CSemiLodHandler;
|
||||
class CDefObjInfoHandler;
|
||||
class CTownHandler;
|
||||
class CLodHandler;
|
||||
class CGeneralTextHandler;
|
||||
class CConsoleHandler;
|
||||
class CPathfinder;
|
||||
class CCursorHandler;
|
||||
class CScreenHandler;
|
||||
class CGameState;
|
||||
class CMapHandler;
|
||||
class CGameInterface;
|
||||
class CPreGame;
|
||||
class CDefHandler;
|
||||
/*
|
||||
CGameInfo class
|
||||
for allowing different functions for modifying game informations
|
||||
*/
|
||||
class CGameInfo
|
||||
{
|
||||
public:
|
||||
CGameState * state;
|
||||
CArtHandler * arth;
|
||||
CHeroHandler * heroh;
|
||||
CCreatureHandler * creh;
|
||||
CAbilityHandler * abilh;
|
||||
CSpellHandler * spellh;
|
||||
CMapHandler * mh;
|
||||
CBuildingHandler * buildh;
|
||||
CObjectHandler * objh;
|
||||
CMusicHandler * mush;
|
||||
CSemiLodHandler * sspriteh;
|
||||
CDefObjInfoHandler * dobjinfo;
|
||||
CTownHandler * townh;
|
||||
CLodHandler * spriteh;
|
||||
CLodHandler * bitmaph;
|
||||
CGeneralTextHandler * generaltexth;
|
||||
CConsoleHandler * consoleh;
|
||||
CPathfinder * pathf;
|
||||
CCursorHandler * curh;
|
||||
CScreenHandler * screenh;
|
||||
};
|
||||
|
||||
|
||||
#endif // __CGAMEINFO_H__
|
||||
|
203
CGameInterface.h
203
CGameInterface.h
@ -1,101 +1,102 @@
|
||||
#ifndef CGAMEINTERFACE_H
|
||||
#define CGAMEINTERFACE_H
|
||||
#include "global.h"
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include "lib/BattleAction.h"
|
||||
#include "client/FunctionList.h"
|
||||
|
||||
using namespace boost::logic;
|
||||
class CCallback;
|
||||
class ICallback;
|
||||
class CGlobalAI;
|
||||
class CGHeroInstance;
|
||||
class Component;
|
||||
class CSelectableComponent;
|
||||
struct HeroMoveDetails;
|
||||
class CGHeroInstance;
|
||||
class CGTownInstance;
|
||||
class CGObjectInstance;
|
||||
class CCreatureSet;
|
||||
class CArmedInstance;
|
||||
struct BattleResult;
|
||||
struct BattleAttack;
|
||||
struct BattleStackAttacked;
|
||||
struct SpellCasted;
|
||||
class CObstacle
|
||||
{
|
||||
int ID;
|
||||
int position;
|
||||
//TODO: add some kind of the blockmap
|
||||
};
|
||||
|
||||
struct StackState
|
||||
{
|
||||
StackState(){attackBonus=defenseBonus=healthBonus=speedBonus=morale=luck=shotsLeft=currentHealth=0;};
|
||||
int attackBonus, defenseBonus, healthBonus, speedBonus;
|
||||
int currentHealth;
|
||||
int shotsLeft;
|
||||
std::set<int> effects; //IDs of spells affecting stack
|
||||
int morale, luck;
|
||||
};
|
||||
|
||||
class CGameInterface
|
||||
{
|
||||
public:
|
||||
bool human;
|
||||
int playerID, serialID;
|
||||
|
||||
virtual void buildChanged(const CGTownInstance *town, int buildingID, int what){}; //what: 1 - built, 2 - demolished
|
||||
virtual void garrisonChanged(const CGObjectInstance * obj){};
|
||||
virtual void heroArtifactSetChanged(const CGHeroInstance*hero){};
|
||||
virtual void heroCreated(const CGHeroInstance*){};
|
||||
virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback)=0; //pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id
|
||||
virtual void heroInGarrisonChange(const CGTownInstance *town){};
|
||||
virtual void heroKilled(const CGHeroInstance*){};
|
||||
virtual void heroMoved(const HeroMoveDetails & details){};
|
||||
virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val){};
|
||||
virtual void heroManaPointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after spell casts
|
||||
virtual void heroMovePointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after movement
|
||||
virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){};
|
||||
virtual void init(ICallback * CB){};
|
||||
virtual void receivedResource(int type, int val){};
|
||||
virtual void showInfoDialog(std::string &text, const std::vector<Component*> &components){};
|
||||
virtual void showSelDialog(std::string &text, const std::vector<Component*> &components, ui32 askID){};
|
||||
virtual void showYesNoDialog(std::string &text, const std::vector<Component*> &components, ui32 askID){};
|
||||
virtual void tileHidden(const std::set<int3> &pos){};
|
||||
virtual void tileRevealed(const std::set<int3> &pos){};
|
||||
virtual void yourTurn(){};
|
||||
virtual void availableCreaturesChanged(const CGTownInstance *town){};
|
||||
|
||||
//battle call-ins
|
||||
virtual void actionFinished(const BattleAction *action){};//occurs AFTER every action taken by any stack or by the hero
|
||||
virtual void actionStarted(const BattleAction *action){};//occurs BEFORE every action taken by any stack or by the hero
|
||||
virtual BattleAction activeStack(int stackID)=0; //called when it's turn of that stack
|
||||
virtual void battleAttack(BattleAttack *ba){}; //called when stack is performing attack
|
||||
virtual void battleStackAttacked(BattleStackAttacked * bsa){}; //called when stack receives damage (after battleAttack())
|
||||
virtual void battleEnd(BattleResult *br){};
|
||||
virtual void battleNewRound(int round){}; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
|
||||
virtual void battleStackMoved(int ID, int dest){};
|
||||
virtual void battleSpellCasted(SpellCasted *sc){};
|
||||
virtual void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right
|
||||
virtual void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles){}; //called when battlefield is prepared, prior the battle beginning
|
||||
};
|
||||
class CAIHandler
|
||||
{
|
||||
public:
|
||||
static CGlobalAI * getNewAI(CCallback * cb, std::string dllname);
|
||||
};
|
||||
class CGlobalAI : public CGameInterface // AI class (to derivate)
|
||||
{
|
||||
public:
|
||||
//CGlobalAI();
|
||||
virtual void yourTurn(){};
|
||||
virtual void heroKilled(const CGHeroInstance*){};
|
||||
virtual void heroCreated(const CGHeroInstance*){};
|
||||
virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving){};
|
||||
virtual void battleStackAttacking(int ID, int dest){};
|
||||
virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting){};
|
||||
virtual BattleAction activeStack(int stackID) {BattleAction ba; ba.actionType = 3; ba.stackNumber = stackID; return ba;};
|
||||
};
|
||||
#endif //CGAMEINTERFACE_H
|
||||
#ifndef __CGAMEINTERFACE_H__
|
||||
#define __CGAMEINTERFACE_H__
|
||||
#include "global.h"
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include "lib/BattleAction.h"
|
||||
#include "client/FunctionList.h"
|
||||
|
||||
using namespace boost::logic;
|
||||
class CCallback;
|
||||
class ICallback;
|
||||
class CGlobalAI;
|
||||
class CGHeroInstance;
|
||||
class Component;
|
||||
class CSelectableComponent;
|
||||
struct HeroMoveDetails;
|
||||
class CGHeroInstance;
|
||||
class CGTownInstance;
|
||||
class CGObjectInstance;
|
||||
class CCreatureSet;
|
||||
class CArmedInstance;
|
||||
struct BattleResult;
|
||||
struct BattleAttack;
|
||||
struct BattleStackAttacked;
|
||||
struct SpellCasted;
|
||||
class CObstacle
|
||||
{
|
||||
int ID;
|
||||
int position;
|
||||
//TODO: add some kind of the blockmap
|
||||
};
|
||||
|
||||
struct StackState
|
||||
{
|
||||
StackState(){attackBonus=defenseBonus=healthBonus=speedBonus=morale=luck=shotsLeft=currentHealth=0;};
|
||||
int attackBonus, defenseBonus, healthBonus, speedBonus;
|
||||
int currentHealth;
|
||||
int shotsLeft;
|
||||
std::set<int> effects; //IDs of spells affecting stack
|
||||
int morale, luck;
|
||||
};
|
||||
|
||||
class CGameInterface
|
||||
{
|
||||
public:
|
||||
bool human;
|
||||
int playerID, serialID;
|
||||
|
||||
virtual void buildChanged(const CGTownInstance *town, int buildingID, int what){}; //what: 1 - built, 2 - demolished
|
||||
virtual void garrisonChanged(const CGObjectInstance * obj){};
|
||||
virtual void heroArtifactSetChanged(const CGHeroInstance*hero){};
|
||||
virtual void heroCreated(const CGHeroInstance*){};
|
||||
virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback)=0; //pskill is gained primary skill, interface has to choose one of given skills and call callback with selection id
|
||||
virtual void heroInGarrisonChange(const CGTownInstance *town){};
|
||||
virtual void heroKilled(const CGHeroInstance*){};
|
||||
virtual void heroMoved(const HeroMoveDetails & details){};
|
||||
virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val){};
|
||||
virtual void heroManaPointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after spell casts
|
||||
virtual void heroMovePointsChanged(const CGHeroInstance * hero){} //not called at the beginning of turn and after movement
|
||||
virtual void heroVisitsTown(const CGHeroInstance* hero, const CGTownInstance * town){};
|
||||
virtual void init(ICallback * CB){};
|
||||
virtual void receivedResource(int type, int val){};
|
||||
virtual void showInfoDialog(std::string &text, const std::vector<Component*> &components){};
|
||||
virtual void showSelDialog(std::string &text, const std::vector<Component*> &components, ui32 askID){};
|
||||
virtual void showYesNoDialog(std::string &text, const std::vector<Component*> &components, ui32 askID){};
|
||||
virtual void tileHidden(const std::set<int3> &pos){};
|
||||
virtual void tileRevealed(const std::set<int3> &pos){};
|
||||
virtual void yourTurn(){};
|
||||
virtual void availableCreaturesChanged(const CGTownInstance *town){};
|
||||
|
||||
//battle call-ins
|
||||
virtual void actionFinished(const BattleAction *action){};//occurs AFTER every action taken by any stack or by the hero
|
||||
virtual void actionStarted(const BattleAction *action){};//occurs BEFORE every action taken by any stack or by the hero
|
||||
virtual BattleAction activeStack(int stackID)=0; //called when it's turn of that stack
|
||||
virtual void battleAttack(BattleAttack *ba){}; //called when stack is performing attack
|
||||
virtual void battleStackAttacked(BattleStackAttacked * bsa){}; //called when stack receives damage (after battleAttack())
|
||||
virtual void battleEnd(BattleResult *br){};
|
||||
virtual void battleNewRound(int round){}; //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn
|
||||
virtual void battleStackMoved(int ID, int dest){};
|
||||
virtual void battleSpellCasted(SpellCasted *sc){};
|
||||
virtual void battleStart(CCreatureSet *army1, CCreatureSet *army2, int3 tile, CGHeroInstance *hero1, CGHeroInstance *hero2, bool side){}; //called by engine when battle starts; side=0 - left, side=1 - right
|
||||
virtual void battlefieldPrepared(int battlefieldType, std::vector<CObstacle*> obstacles){}; //called when battlefield is prepared, prior the battle beginning
|
||||
};
|
||||
class CAIHandler
|
||||
{
|
||||
public:
|
||||
static CGlobalAI * getNewAI(CCallback * cb, std::string dllname);
|
||||
};
|
||||
class CGlobalAI : public CGameInterface // AI class (to derivate)
|
||||
{
|
||||
public:
|
||||
//CGlobalAI();
|
||||
virtual void yourTurn(){};
|
||||
virtual void heroKilled(const CGHeroInstance*){};
|
||||
virtual void heroCreated(const CGHeroInstance*){};
|
||||
virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving){};
|
||||
virtual void battleStackAttacking(int ID, int dest){};
|
||||
virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting){};
|
||||
virtual BattleAction activeStack(int stackID) {BattleAction ba; ba.actionType = 3; ba.stackNumber = stackID; return ba;};
|
||||
};
|
||||
|
||||
#endif // __CGAMEINTERFACE_H__
|
||||
|
443
CGameState.h
443
CGameState.h
@ -1,221 +1,222 @@
|
||||
#ifndef CGAMESTATE_H
|
||||
#define CGAMESTATE_H
|
||||
#include "global.h"
|
||||
#ifndef _MSC_VER
|
||||
#include "hch/CCreatureHandler.h"
|
||||
#include "lib/VCMI_Lib.h"
|
||||
#endif
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#ifdef _WIN32
|
||||
#include <tchar.h>
|
||||
#else
|
||||
#include "tchar_amigaos4.h"
|
||||
#endif
|
||||
|
||||
class CTown;
|
||||
class CScriptCallback;
|
||||
class CCallback;
|
||||
class CLuaCallback;
|
||||
class CCPPObjectScript;
|
||||
class CCreatureSet;
|
||||
class CStack;
|
||||
class CGHeroInstance;
|
||||
class CGTownInstance;
|
||||
class CArmedInstance;
|
||||
class CGDefInfo;
|
||||
class CObjectScript;
|
||||
class CGObjectInstance;
|
||||
class CCreature;
|
||||
struct Mapa;
|
||||
struct StartInfo;
|
||||
struct SDL_Surface;
|
||||
class CMapHandler;
|
||||
class CPathfinder;
|
||||
struct IPack;
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class shared_mutex;
|
||||
}
|
||||
|
||||
struct DLL_EXPORT PlayerState
|
||||
{
|
||||
public:
|
||||
ui8 color, serial;
|
||||
ui32 currentSelection; //id of hero/town, 0xffffffff if none
|
||||
std::vector<std::vector<std::vector<ui8> > > fogOfWarMap; //true - visible, false - hidden
|
||||
std::vector<si32> resources;
|
||||
std::vector<CGHeroInstance *> heroes;
|
||||
std::vector<CGTownInstance *> towns;
|
||||
std::vector<CGHeroInstance *> availableHeroes; //heroes available in taverns
|
||||
PlayerState():color(-1),currentSelection(0xffffffff){};
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & color & serial & currentSelection & fogOfWarMap & resources;
|
||||
//TODO: vectors of heroes/towns
|
||||
}
|
||||
};
|
||||
|
||||
struct DLL_EXPORT BattleInfo
|
||||
{
|
||||
ui8 side1, side2;
|
||||
si32 round, activeStack;
|
||||
ui8 siege; // = 0 ordinary battle = 1 a siege with a Fort = 2 a siege with a Citadel = 3 a siege with a Castle
|
||||
int3 tile; //for background and bonuses
|
||||
si32 hero1, hero2;
|
||||
CCreatureSet army1, army2;
|
||||
std::vector<CStack*> stacks;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & side1 & side2 & round & activeStack & siege & tile & stacks & army1 & army2 & hero1 & hero2;
|
||||
}
|
||||
CStack * getNextStack(); //which stack will have turn after current one
|
||||
std::vector<CStack> getStackQueue(); //returns stack in order of their movement action
|
||||
CStack * getStack(int stackID);
|
||||
CStack * getStackT(int tileID);
|
||||
void getAccessibilityMap(bool *accessibility, int stackToOmmit=-1); //send pointer to at least 187 allocated bytes
|
||||
void getAccessibilityMapForTwoHex(bool *accessibility, bool atackerSide, int stackToOmmit=-1); //send pointer to at least 187 allocated bytes
|
||||
void makeBFS(int start, bool*accessibility, int *predecessor, int *dists); //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result
|
||||
std::vector<int> getPath(int start, int dest, bool*accessibility);
|
||||
std::vector<int> getAccessibility(int stackID); //returns vector of accessible tiles (taking into account the creature range)
|
||||
|
||||
bool isStackBlocked(int ID); //returns true if there is neighbouring enemy stack
|
||||
static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left)
|
||||
static std::vector<int> neighbouringTiles(int hex);
|
||||
static int calculateDmg(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting); //TODO: add additional conditions and require necessary data
|
||||
void calculateCasualties(std::set<std::pair<ui32,si32> > *casualties);
|
||||
};
|
||||
|
||||
class DLL_EXPORT CStack
|
||||
{
|
||||
public:
|
||||
ui32 ID; //unique ID of stack
|
||||
CCreature * creature;
|
||||
ui32 amount, baseAmount;
|
||||
ui32 firstHPleft; //HP of first creature in stack
|
||||
ui8 owner, slot; //owner - player colour (255 for neutrals), slot - position in garrison (may be 255 for neutrals/called creatures)
|
||||
ui8 attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle)
|
||||
ui16 position; //position on battlefield
|
||||
ui8 counterAttacks; //how many counter attacks can be performed more in this turn (by default set at the beginning of the round to 1)
|
||||
si16 shots; //how many shots left
|
||||
|
||||
std::set<EAbilities> abilities;
|
||||
std::set<ECombatInfo> state;
|
||||
struct StackEffect
|
||||
{
|
||||
ui16 id; //spell id
|
||||
ui8 level; //skill level
|
||||
ui16 turnsRemain;
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & id & level & turnsRemain;
|
||||
}
|
||||
};
|
||||
std::vector<StackEffect> effects;
|
||||
|
||||
CStack(CCreature * C, int A, int O, int I, bool AO, int S);
|
||||
CStack() : creature(NULL),amount(-1),owner(255), position(-1), ID(-1), attackerOwned(true), firstHPleft(-1), slot(255), baseAmount(-1), counterAttacks(1), effects(), state(), abilities(){}
|
||||
const StackEffect * getEffect(ui16 id) const; //effect id (SP)
|
||||
ui32 speed() const;
|
||||
template <typename Handler> void save(Handler &h, const int version)
|
||||
{
|
||||
h & creature->idNumber;
|
||||
}
|
||||
template <typename Handler> void load(Handler &h, const int version)
|
||||
{
|
||||
ui32 id;
|
||||
h & id;
|
||||
creature = &VLC->creh->creatures[id];
|
||||
abilities = creature->abilities;
|
||||
}
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & ID & amount & baseAmount & firstHPleft & owner & slot & attackerOwned & position & state & counterAttacks
|
||||
& shots;
|
||||
if(h.saving)
|
||||
save(h,version);
|
||||
else
|
||||
load(h,version);
|
||||
}
|
||||
bool alive() const
|
||||
{
|
||||
return vstd::contains(state,ALIVE);
|
||||
}
|
||||
};
|
||||
|
||||
struct UpgradeInfo
|
||||
{
|
||||
int oldID; //creature to be upgraded
|
||||
std::vector<int> newID; //possible upgrades
|
||||
std::vector<std::set<std::pair<int,int> > > cost; // cost[upgrade_serial] -> set of pairs<resource_ID,resource_amount>
|
||||
UpgradeInfo(){oldID = -1;};
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGameState
|
||||
{
|
||||
private:
|
||||
StartInfo* scenarioOps;
|
||||
ui32 seed;
|
||||
ui8 currentPlayer; //ID of player currently having turn
|
||||
BattleInfo *curB; //current battle
|
||||
ui32 day; //total number of days in game
|
||||
Mapa * map;
|
||||
std::map<ui8,PlayerState> players; //ID <-> player state
|
||||
std::map<int, CGDefInfo*> villages, forts, capitols; //def-info for town graphics
|
||||
std::vector<ui32> resVals;
|
||||
|
||||
struct DLL_EXPORT HeroesPool
|
||||
{
|
||||
std::map<ui32,CGHeroInstance *> heroesPool; //[subID] - heroes available to buy; NULL if not available
|
||||
std::map<ui32,ui8> pavailable; // [subid] -> which players can recruit hero
|
||||
|
||||
CGHeroInstance * pickHeroFor(bool native, int player, const CTown *town, int notThatOne=-1);
|
||||
} hpool; //we have here all heroes available on this map that are not hired
|
||||
|
||||
boost::shared_mutex *mx;
|
||||
|
||||
CGameState();
|
||||
~CGameState();
|
||||
void init(StartInfo * si, Mapa * map, int Seed);
|
||||
void loadTownDInfos();
|
||||
void applyNL(IPack * pack);
|
||||
void apply(IPack * pack);
|
||||
void randomizeObject(CGObjectInstance *cur);
|
||||
std::pair<int,int> pickObject(CGObjectInstance *obj);
|
||||
int pickHero(int owner);
|
||||
|
||||
CGHeroInstance *getHero(int objid);
|
||||
CGTownInstance *getTown(int objid);
|
||||
|
||||
bool battleMoveCreatureStack(int ID, int dest);
|
||||
bool battleAttackCreatureStack(int ID, int dest);
|
||||
bool battleShootCreatureStack(int ID, int dest);
|
||||
int battleGetStack(int pos); //returns ID of stack at given tile
|
||||
UpgradeInfo getUpgradeInfo(CArmedInstance *obj, int stackPos);
|
||||
float getMarketEfficiency(int player, int mode=0);
|
||||
std::set<int3> tilesToReveal(int3 pos, int radious, int player) const; //if player==-1 => adds all tiles in radious
|
||||
public:
|
||||
int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & scenarioOps & seed & currentPlayer & day & map & players & resVals;
|
||||
if(!h.saving)
|
||||
{
|
||||
loadTownDInfos();
|
||||
}
|
||||
//TODO: hero pool
|
||||
}
|
||||
|
||||
friend class CCallback;
|
||||
friend class CPathfinder;;
|
||||
friend class CLuaCallback;
|
||||
friend class CClient;
|
||||
friend void initGameState(Mapa * map, CGameInfo * cgi);
|
||||
friend class CScriptCallback;
|
||||
friend class CMapHandler;
|
||||
friend class CGameHandler;
|
||||
};
|
||||
|
||||
#endif //CGAMESTATE_H
|
||||
#ifndef __CGAMESTATE_H__
|
||||
#define __CGAMESTATE_H__
|
||||
#include "global.h"
|
||||
#ifndef _MSC_VER
|
||||
#include "hch/CCreatureHandler.h"
|
||||
#include "lib/VCMI_Lib.h"
|
||||
#endif
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#ifdef _WIN32
|
||||
#include <tchar.h>
|
||||
#else
|
||||
#include "tchar_amigaos4.h"
|
||||
#endif
|
||||
|
||||
class CTown;
|
||||
class CScriptCallback;
|
||||
class CCallback;
|
||||
class CLuaCallback;
|
||||
class CCPPObjectScript;
|
||||
class CCreatureSet;
|
||||
class CStack;
|
||||
class CGHeroInstance;
|
||||
class CGTownInstance;
|
||||
class CArmedInstance;
|
||||
class CGDefInfo;
|
||||
class CObjectScript;
|
||||
class CGObjectInstance;
|
||||
class CCreature;
|
||||
struct Mapa;
|
||||
struct StartInfo;
|
||||
struct SDL_Surface;
|
||||
class CMapHandler;
|
||||
class CPathfinder;
|
||||
struct IPack;
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class shared_mutex;
|
||||
}
|
||||
|
||||
struct DLL_EXPORT PlayerState
|
||||
{
|
||||
public:
|
||||
ui8 color, serial;
|
||||
ui32 currentSelection; //id of hero/town, 0xffffffff if none
|
||||
std::vector<std::vector<std::vector<ui8> > > fogOfWarMap; //true - visible, false - hidden
|
||||
std::vector<si32> resources;
|
||||
std::vector<CGHeroInstance *> heroes;
|
||||
std::vector<CGTownInstance *> towns;
|
||||
std::vector<CGHeroInstance *> availableHeroes; //heroes available in taverns
|
||||
PlayerState():color(-1),currentSelection(0xffffffff){};
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & color & serial & currentSelection & fogOfWarMap & resources;
|
||||
//TODO: vectors of heroes/towns
|
||||
}
|
||||
};
|
||||
|
||||
struct DLL_EXPORT BattleInfo
|
||||
{
|
||||
ui8 side1, side2;
|
||||
si32 round, activeStack;
|
||||
ui8 siege; // = 0 ordinary battle = 1 a siege with a Fort = 2 a siege with a Citadel = 3 a siege with a Castle
|
||||
int3 tile; //for background and bonuses
|
||||
si32 hero1, hero2;
|
||||
CCreatureSet army1, army2;
|
||||
std::vector<CStack*> stacks;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & side1 & side2 & round & activeStack & siege & tile & stacks & army1 & army2 & hero1 & hero2;
|
||||
}
|
||||
CStack * getNextStack(); //which stack will have turn after current one
|
||||
std::vector<CStack> getStackQueue(); //returns stack in order of their movement action
|
||||
CStack * getStack(int stackID);
|
||||
CStack * getStackT(int tileID);
|
||||
void getAccessibilityMap(bool *accessibility, int stackToOmmit=-1); //send pointer to at least 187 allocated bytes
|
||||
void getAccessibilityMapForTwoHex(bool *accessibility, bool atackerSide, int stackToOmmit=-1); //send pointer to at least 187 allocated bytes
|
||||
void makeBFS(int start, bool*accessibility, int *predecessor, int *dists); //*accessibility must be prepared bool[187] array; last two pointers must point to the at least 187-elements int arrays - there is written result
|
||||
std::vector<int> getPath(int start, int dest, bool*accessibility);
|
||||
std::vector<int> getAccessibility(int stackID); //returns vector of accessible tiles (taking into account the creature range)
|
||||
|
||||
bool isStackBlocked(int ID); //returns true if there is neighbouring enemy stack
|
||||
static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left)
|
||||
static std::vector<int> neighbouringTiles(int hex);
|
||||
static int calculateDmg(const CStack* attacker, const CStack* defender, const CGHeroInstance * attackerHero, const CGHeroInstance * defendingHero, bool shooting); //TODO: add additional conditions and require necessary data
|
||||
void calculateCasualties(std::set<std::pair<ui32,si32> > *casualties);
|
||||
};
|
||||
|
||||
class DLL_EXPORT CStack
|
||||
{
|
||||
public:
|
||||
ui32 ID; //unique ID of stack
|
||||
CCreature * creature;
|
||||
ui32 amount, baseAmount;
|
||||
ui32 firstHPleft; //HP of first creature in stack
|
||||
ui8 owner, slot; //owner - player colour (255 for neutrals), slot - position in garrison (may be 255 for neutrals/called creatures)
|
||||
ui8 attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle)
|
||||
ui16 position; //position on battlefield
|
||||
ui8 counterAttacks; //how many counter attacks can be performed more in this turn (by default set at the beginning of the round to 1)
|
||||
si16 shots; //how many shots left
|
||||
|
||||
std::set<EAbilities> abilities;
|
||||
std::set<ECombatInfo> state;
|
||||
struct StackEffect
|
||||
{
|
||||
ui16 id; //spell id
|
||||
ui8 level; //skill level
|
||||
ui16 turnsRemain;
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & id & level & turnsRemain;
|
||||
}
|
||||
};
|
||||
std::vector<StackEffect> effects;
|
||||
|
||||
CStack(CCreature * C, int A, int O, int I, bool AO, int S);
|
||||
CStack() : creature(NULL),amount(-1),owner(255), position(-1), ID(-1), attackerOwned(true), firstHPleft(-1), slot(255), baseAmount(-1), counterAttacks(1), effects(), state(), abilities(){}
|
||||
const StackEffect * getEffect(ui16 id) const; //effect id (SP)
|
||||
ui32 speed() const;
|
||||
template <typename Handler> void save(Handler &h, const int version)
|
||||
{
|
||||
h & creature->idNumber;
|
||||
}
|
||||
template <typename Handler> void load(Handler &h, const int version)
|
||||
{
|
||||
ui32 id;
|
||||
h & id;
|
||||
creature = &VLC->creh->creatures[id];
|
||||
abilities = creature->abilities;
|
||||
}
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & ID & amount & baseAmount & firstHPleft & owner & slot & attackerOwned & position & state & counterAttacks
|
||||
& shots;
|
||||
if(h.saving)
|
||||
save(h,version);
|
||||
else
|
||||
load(h,version);
|
||||
}
|
||||
bool alive() const
|
||||
{
|
||||
return vstd::contains(state,ALIVE);
|
||||
}
|
||||
};
|
||||
|
||||
struct UpgradeInfo
|
||||
{
|
||||
int oldID; //creature to be upgraded
|
||||
std::vector<int> newID; //possible upgrades
|
||||
std::vector<std::set<std::pair<int,int> > > cost; // cost[upgrade_serial] -> set of pairs<resource_ID,resource_amount>
|
||||
UpgradeInfo(){oldID = -1;};
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGameState
|
||||
{
|
||||
private:
|
||||
StartInfo* scenarioOps;
|
||||
ui32 seed;
|
||||
ui8 currentPlayer; //ID of player currently having turn
|
||||
BattleInfo *curB; //current battle
|
||||
ui32 day; //total number of days in game
|
||||
Mapa * map;
|
||||
std::map<ui8,PlayerState> players; //ID <-> player state
|
||||
std::map<int, CGDefInfo*> villages, forts, capitols; //def-info for town graphics
|
||||
std::vector<ui32> resVals;
|
||||
|
||||
struct DLL_EXPORT HeroesPool
|
||||
{
|
||||
std::map<ui32,CGHeroInstance *> heroesPool; //[subID] - heroes available to buy; NULL if not available
|
||||
std::map<ui32,ui8> pavailable; // [subid] -> which players can recruit hero
|
||||
|
||||
CGHeroInstance * pickHeroFor(bool native, int player, const CTown *town, int notThatOne=-1);
|
||||
} hpool; //we have here all heroes available on this map that are not hired
|
||||
|
||||
boost::shared_mutex *mx;
|
||||
|
||||
CGameState();
|
||||
~CGameState();
|
||||
void init(StartInfo * si, Mapa * map, int Seed);
|
||||
void loadTownDInfos();
|
||||
void applyNL(IPack * pack);
|
||||
void apply(IPack * pack);
|
||||
void randomizeObject(CGObjectInstance *cur);
|
||||
std::pair<int,int> pickObject(CGObjectInstance *obj);
|
||||
int pickHero(int owner);
|
||||
|
||||
CGHeroInstance *getHero(int objid);
|
||||
CGTownInstance *getTown(int objid);
|
||||
|
||||
bool battleMoveCreatureStack(int ID, int dest);
|
||||
bool battleAttackCreatureStack(int ID, int dest);
|
||||
bool battleShootCreatureStack(int ID, int dest);
|
||||
int battleGetStack(int pos); //returns ID of stack at given tile
|
||||
UpgradeInfo getUpgradeInfo(CArmedInstance *obj, int stackPos);
|
||||
float getMarketEfficiency(int player, int mode=0);
|
||||
std::set<int3> tilesToReveal(int3 pos, int radious, int player) const; //if player==-1 => adds all tiles in radious
|
||||
public:
|
||||
int getDate(int mode=0) const; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & scenarioOps & seed & currentPlayer & day & map & players & resVals;
|
||||
if(!h.saving)
|
||||
{
|
||||
loadTownDInfos();
|
||||
}
|
||||
//TODO: hero pool
|
||||
}
|
||||
|
||||
friend class CCallback;
|
||||
friend class CPathfinder;;
|
||||
friend class CLuaCallback;
|
||||
friend class CClient;
|
||||
friend void initGameState(Mapa * map, CGameInfo * cgi);
|
||||
friend class CScriptCallback;
|
||||
friend class CMapHandler;
|
||||
friend class CGameHandler;
|
||||
};
|
||||
|
||||
|
||||
#endif // __CGAMESTATE_H__
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef CHEROWINDOW_H
|
||||
#define CHEROWINDOW_H
|
||||
#ifndef __CHEROWINDOW_H__
|
||||
#define __CHEROWINDOW_H__
|
||||
|
||||
|
||||
#include "CPlayerInterface.h"
|
||||
@ -130,4 +130,5 @@ public:
|
||||
friend void CArtPlace::clickLeft(tribool down);
|
||||
friend class CPlayerInterface;
|
||||
};
|
||||
#endif //CHEROWINDOW_H
|
||||
|
||||
#endif // __CHEROWINDOW_H__
|
||||
|
@ -1,23 +1,24 @@
|
||||
#ifndef CLUAHANDLER_H
|
||||
#define CLUAHANDLER_H
|
||||
#include "global.h"
|
||||
#if (LUA_VERSION_NUM < 500)
|
||||
# define LUA_OPEN_LIB(L, lib) lib(L)
|
||||
#else
|
||||
# define LUA_OPEN_LIB(L, lib) \
|
||||
lua_pushcfunction((L), lib); \
|
||||
lua_pcall((L), 0, 0, 0);
|
||||
#endif
|
||||
class CLuaHandler
|
||||
{
|
||||
public:
|
||||
CLuaHandler();
|
||||
|
||||
static std::vector<std::string> * searchForScripts(std::string fol);
|
||||
static std::vector<std::string> * functionList(std::string file);
|
||||
|
||||
~CLuaHandler();
|
||||
|
||||
void test();
|
||||
};
|
||||
#endif //CLUAHANDLER_H
|
||||
#ifndef __CLUAHANDLER_H__
|
||||
#define __CLUAHANDLER_H__
|
||||
#include "global.h"
|
||||
#if (LUA_VERSION_NUM < 500)
|
||||
# define LUA_OPEN_LIB(L, lib) lib(L)
|
||||
#else
|
||||
# define LUA_OPEN_LIB(L, lib) \
|
||||
lua_pushcfunction((L), lib); \
|
||||
lua_pcall((L), 0, 0, 0);
|
||||
#endif
|
||||
class CLuaHandler
|
||||
{
|
||||
public:
|
||||
CLuaHandler();
|
||||
|
||||
static std::vector<std::string> * searchForScripts(std::string fol);
|
||||
static std::vector<std::string> * functionList(std::string file);
|
||||
|
||||
~CLuaHandler();
|
||||
|
||||
void test();
|
||||
};
|
||||
|
||||
#endif // __CLUAHANDLER_H__
|
||||
|
105
CMessage.h
105
CMessage.h
@ -1,52 +1,53 @@
|
||||
#ifndef CMESSAGE_H
|
||||
#define CMESSAGE_H
|
||||
|
||||
#include "global.h"
|
||||
#include <SDL_ttf.h>
|
||||
#include <SDL.h>
|
||||
#include "CPreGame.h"
|
||||
|
||||
enum EWindowType {infoOnly, infoOK, yesOrNO};
|
||||
class CPreGame;
|
||||
class MapSel;
|
||||
class CSimpleWindow;
|
||||
class CInfoWindow;
|
||||
class CDefHandler;
|
||||
class SComponent;
|
||||
class CSelWindow;
|
||||
class CSelectableComponent;
|
||||
namespace NMessage
|
||||
{
|
||||
extern CDefHandler * ok, *cancel;
|
||||
extern std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
|
||||
extern SDL_Surface * background ;
|
||||
}
|
||||
|
||||
class CMessage
|
||||
{
|
||||
public:
|
||||
|
||||
static std::pair<int,int> getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg);
|
||||
static std::pair<int, int> getMaxSizes(std::vector< std::vector<SComponent*> > * komp);
|
||||
static std::vector<std::vector<SDL_Surface*> > * drawText(std::vector<std::string> * brtext);
|
||||
static SDL_Surface * blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int & curh, SDL_Surface * ret);
|
||||
static SDL_Surface * blitCompsOnSur(std::vector<SComponent*> & comps, int maxw, int inter, int & curh, SDL_Surface * ret);
|
||||
static SDL_Surface * blitCompsOnSur(SDL_Surface *_or, std::vector< std::vector<SComponent*> > *komp, int inter, int &curh, SDL_Surface *ret);
|
||||
static void drawIWindow(CInfoWindow * ret, std::string text, int player, int charperline);
|
||||
static std::vector< std::vector<SComponent*> > * breakComps(std::vector<SComponent*> &comps, int maxw, SDL_Surface* _or=NULL);
|
||||
static CSelWindow * genSelWindow(std::string text, int player, int charperline, std::vector<CSelectableComponent*> & comps, int owner);
|
||||
static CSimpleWindow * genWindow(std::string text, int player, int Lmar=35, int Rmar=35, int Tmar=35, int Bmar=35);//supports h3 text formatting; player sets color of window, Lmar/Rmar/Tmar/Bmar are Left/Right/Top/Bottom margins
|
||||
static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly,
|
||||
std::vector<CDefHandler*> *addPics=NULL, void * cb=NULL);
|
||||
static SDL_Surface * drawBox1(int w, int h, int playerColor=1);
|
||||
static void drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x=0, int y=0);
|
||||
static SDL_Surface * drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline=30, int imgToBmp=55);
|
||||
static std::vector<std::string> * breakText(std::string text, size_t line=30, bool userBreak=true, bool ifor=true); //line - chars per line
|
||||
CMessage();
|
||||
static void init();
|
||||
static void dispose();
|
||||
};
|
||||
//
|
||||
|
||||
|
||||
#endif //CMESSAGE_H
|
||||
#ifndef __CMESSAGE_H__
|
||||
#define __CMESSAGE_H__
|
||||
|
||||
#include "global.h"
|
||||
#include <SDL_ttf.h>
|
||||
#include <SDL.h>
|
||||
#include "CPreGame.h"
|
||||
|
||||
enum EWindowType {infoOnly, infoOK, yesOrNO};
|
||||
class CPreGame;
|
||||
class MapSel;
|
||||
class CSimpleWindow;
|
||||
class CInfoWindow;
|
||||
class CDefHandler;
|
||||
class SComponent;
|
||||
class CSelWindow;
|
||||
class CSelectableComponent;
|
||||
namespace NMessage
|
||||
{
|
||||
extern CDefHandler * ok, *cancel;
|
||||
extern std::vector<std::vector<SDL_Surface*> > piecesOfBox; //in colors of all players
|
||||
extern SDL_Surface * background ;
|
||||
}
|
||||
|
||||
class CMessage
|
||||
{
|
||||
public:
|
||||
|
||||
static std::pair<int,int> getMaxSizes(std::vector<std::vector<SDL_Surface*> > * txtg);
|
||||
static std::pair<int, int> getMaxSizes(std::vector< std::vector<SComponent*> > * komp);
|
||||
static std::vector<std::vector<SDL_Surface*> > * drawText(std::vector<std::string> * brtext);
|
||||
static SDL_Surface * blitTextOnSur(std::vector<std::vector<SDL_Surface*> > * txtg, int & curh, SDL_Surface * ret);
|
||||
static SDL_Surface * blitCompsOnSur(std::vector<SComponent*> & comps, int maxw, int inter, int & curh, SDL_Surface * ret);
|
||||
static SDL_Surface * blitCompsOnSur(SDL_Surface *_or, std::vector< std::vector<SComponent*> > *komp, int inter, int &curh, SDL_Surface *ret);
|
||||
static void drawIWindow(CInfoWindow * ret, std::string text, int player, int charperline);
|
||||
static std::vector< std::vector<SComponent*> > * breakComps(std::vector<SComponent*> &comps, int maxw, SDL_Surface* _or=NULL);
|
||||
static CSelWindow * genSelWindow(std::string text, int player, int charperline, std::vector<CSelectableComponent*> & comps, int owner);
|
||||
static CSimpleWindow * genWindow(std::string text, int player, int Lmar=35, int Rmar=35, int Tmar=35, int Bmar=35);//supports h3 text formatting; player sets color of window, Lmar/Rmar/Tmar/Bmar are Left/Right/Top/Bottom margins
|
||||
static SDL_Surface * genMessage(std::string title, std::string text, EWindowType type=infoOnly,
|
||||
std::vector<CDefHandler*> *addPics=NULL, void * cb=NULL);
|
||||
static SDL_Surface * drawBox1(int w, int h, int playerColor=1);
|
||||
static void drawBorder(int playerColor, SDL_Surface * ret, int w, int h, int x=0, int y=0);
|
||||
static SDL_Surface * drawBoxTextBitmapSub(int player, std::string text, SDL_Surface* bitmap, std::string sub, int charperline=30, int imgToBmp=55);
|
||||
static std::vector<std::string> * breakText(std::string text, size_t line=30, bool userBreak=true, bool ifor=true); //line - chars per line
|
||||
CMessage();
|
||||
static void init();
|
||||
static void dispose();
|
||||
};
|
||||
//
|
||||
|
||||
|
||||
|
||||
#endif // __CMESSAGE_H__
|
||||
|
@ -1,42 +1,43 @@
|
||||
#ifndef CPATHFINDER_H
|
||||
#define CPATHFINDER_H
|
||||
#include "global.h"
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
class CGHeroInstance;
|
||||
|
||||
struct CPathNode
|
||||
{
|
||||
bool accesible; //true if a hero can be on this node
|
||||
int dist; //distance from the first node of searching; -1 is infinity
|
||||
CPathNode * theNodeBefore;
|
||||
int3 coord; //coordiantes
|
||||
bool visited;
|
||||
};
|
||||
|
||||
struct CPath
|
||||
{
|
||||
std::vector<CPathNode> nodes; //just get node by node
|
||||
|
||||
int3 startPos(); // start point
|
||||
int3 endPos(); //destination point
|
||||
};
|
||||
|
||||
/**
|
||||
* main pathfinder class
|
||||
*/
|
||||
class CPathfinder
|
||||
{
|
||||
private:
|
||||
std::vector< std::vector<CPathNode> > graph;
|
||||
void processNode(CPathNode & dp, const CGHeroInstance * hero, std::queue<CPathNode> & mq, const CPathNode & cp, const int3 & src, bool diagonal); //helper function for getPath
|
||||
bool checkForVisitableDir(const int3 & src, const int3 & dst) const;
|
||||
public:
|
||||
CPath * getPath(int3 src, int3 dest, const CGHeroInstance * hero, unsigned char type=0); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; type - type of calculation: 0 - positions are normal positions of hero; 1 - given places are tiles blocked by hero
|
||||
CPath * getPath(const int3 & src, const int3 & dest, const CGHeroInstance * hero, int (*getDist)(int3 & a, int3 & b), unsigned char type=0); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; uses getDist to calculate distance; type - type of calculation: 0 - positions are normal positions of hero; 1 - given places are tiles blocked by hero
|
||||
|
||||
static void convertPath(CPath * path, unsigned int mode); //mode=0 -> from 'manifest' to 'object'
|
||||
};
|
||||
|
||||
#endif //CPATHFINDER_H
|
||||
#ifndef __CPATHFINDER_H__
|
||||
#define __CPATHFINDER_H__
|
||||
#include "global.h"
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
|
||||
class CGHeroInstance;
|
||||
|
||||
struct CPathNode
|
||||
{
|
||||
bool accesible; //true if a hero can be on this node
|
||||
int dist; //distance from the first node of searching; -1 is infinity
|
||||
CPathNode * theNodeBefore;
|
||||
int3 coord; //coordiantes
|
||||
bool visited;
|
||||
};
|
||||
|
||||
struct CPath
|
||||
{
|
||||
std::vector<CPathNode> nodes; //just get node by node
|
||||
|
||||
int3 startPos(); // start point
|
||||
int3 endPos(); //destination point
|
||||
};
|
||||
|
||||
/**
|
||||
* main pathfinder class
|
||||
*/
|
||||
class CPathfinder
|
||||
{
|
||||
private:
|
||||
std::vector< std::vector<CPathNode> > graph;
|
||||
void processNode(CPathNode & dp, const CGHeroInstance * hero, std::queue<CPathNode> & mq, const CPathNode & cp, const int3 & src, bool diagonal); //helper function for getPath
|
||||
bool checkForVisitableDir(const int3 & src, const int3 & dst) const;
|
||||
public:
|
||||
CPath * getPath(int3 src, int3 dest, const CGHeroInstance * hero, unsigned char type=0); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; type - type of calculation: 0 - positions are normal positions of hero; 1 - given places are tiles blocked by hero
|
||||
CPath * getPath(const int3 & src, const int3 & dest, const CGHeroInstance * hero, int (*getDist)(int3 & a, int3 & b), unsigned char type=0); //calculates path between src and dest; returns pointer to CPath or NULL if path does not exists; uses getDist to calculate distance; type - type of calculation: 0 - positions are normal positions of hero; 1 - given places are tiles blocked by hero
|
||||
|
||||
static void convertPath(CPath * path, unsigned int mode); //mode=0 -> from 'manifest' to 'object'
|
||||
};
|
||||
|
||||
|
||||
#endif // __CPATHFINDER_H__
|
||||
|
1433
CPlayerInterface.h
1433
CPlayerInterface.h
File diff suppressed because it is too large
Load Diff
593
CPreGame.h
593
CPreGame.h
@ -1,296 +1,297 @@
|
||||
#ifndef CPREGAME_H
|
||||
#define CPREGAME_H
|
||||
#include "global.h"
|
||||
#include <set>
|
||||
#include <SDL.h>
|
||||
#include "StartInfo.h"
|
||||
#include "CMessage.h"
|
||||
#include "map.h"
|
||||
#include "hch/CMusicHandler.h"
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
class CPreGame;
|
||||
class CDefHandler;
|
||||
extern CPreGame * CPG;
|
||||
|
||||
typedef void(CPreGame::*ttt)();
|
||||
class CGroup;
|
||||
class CPoinGroup ;
|
||||
class IntSelBut;
|
||||
|
||||
struct HighButton
|
||||
{
|
||||
int ID;
|
||||
int type;
|
||||
SDL_Rect pos;
|
||||
CDefHandler* imgs;
|
||||
int state;
|
||||
HighButton( SDL_Rect Pos, CDefHandler* Imgs, bool Sel=false, int id=-1);
|
||||
HighButton();
|
||||
~HighButton();
|
||||
bool selectable, selected;
|
||||
bool highlightable, highlighted;
|
||||
virtual void show();
|
||||
virtual void press(bool down=true);
|
||||
virtual void hover(bool on=true)=0;
|
||||
virtual void select(bool on=true)=0;
|
||||
};
|
||||
struct Button: public HighButton
|
||||
{
|
||||
CGroup *ourGroup;
|
||||
Button( SDL_Rect Pos, boost::function<void()> Fun,CDefHandler* Imgs, bool Sel=false, CGroup* gr=NULL, int id=-1);
|
||||
Button();
|
||||
boost::function<void()> fun;
|
||||
virtual void hover(bool on=true);
|
||||
virtual void select(bool on=true);
|
||||
};
|
||||
struct SetrButton: public Button
|
||||
{
|
||||
int key, * poin;
|
||||
virtual void press(bool down=true);
|
||||
SetrButton();
|
||||
};
|
||||
|
||||
class Slider
|
||||
{
|
||||
public:
|
||||
bool vertical; // false means horizontal
|
||||
SDL_Rect pos; // position
|
||||
Button *up, *down, //or left/right
|
||||
*slider;
|
||||
int positionsAmnt, capacity;// capacity - amount of positions dispplayed at once
|
||||
int whereAreWe; // first displayed thing
|
||||
bool moving;
|
||||
boost::function<void(int)> fun;
|
||||
void clickDown(int x, int y, bool bzgl=true);
|
||||
void clickUp(int x, int y, bool bzgl=true);
|
||||
void mMove(int x, int y, bool bzgl=true);
|
||||
void moveUp();
|
||||
void moveDown();
|
||||
void deactivate();
|
||||
void activate();
|
||||
Slider(int x, int y, int h, int amnt, int cap, bool ver);
|
||||
~Slider();
|
||||
void updateSlid();
|
||||
void handleIt(SDL_Event sev);
|
||||
};
|
||||
|
||||
struct IntBut: public Button
|
||||
{
|
||||
public:
|
||||
int key;
|
||||
int * what;
|
||||
IntBut();
|
||||
void set();
|
||||
};
|
||||
class CGroup
|
||||
{
|
||||
public:
|
||||
Button * selected;
|
||||
int type; // 1=sinsel
|
||||
CGroup():selected(NULL),type(0){};
|
||||
};
|
||||
|
||||
class CPoinGroup :public CGroup
|
||||
{
|
||||
public:
|
||||
int * gdzie; //where (po polsku, bo by by�o s�owo kluczowe :/)
|
||||
void setYour(IntSelBut * your);
|
||||
};
|
||||
struct IntSelBut: public Button
|
||||
{
|
||||
public:
|
||||
CPoinGroup * ourPoinGroup;
|
||||
int key;
|
||||
IntSelBut(){};
|
||||
IntSelBut( SDL_Rect Pos, boost::function<void()> Fun,CDefHandler* Imgs, bool Sel=false, CPoinGroup* gr=NULL, int My=-1);
|
||||
void select(bool on=true);
|
||||
};
|
||||
class PreGameTab
|
||||
{
|
||||
public:
|
||||
bool showed;
|
||||
virtual void init()=0;
|
||||
virtual void show()=0;
|
||||
virtual void hide()=0;
|
||||
PreGameTab();
|
||||
};
|
||||
class RanSel : public PreGameTab
|
||||
{
|
||||
Button horcpl[9], horcte[9], conpl[9], conte[8], water[4], monster[4], //last is random
|
||||
size[4], twoLevel, showRand;
|
||||
CGroup *Ghorcpl, *Ghorcte, *Gconpl, *Gconte, *Gwater, *Gmonster, *Gsize;
|
||||
};
|
||||
class Options : public PreGameTab
|
||||
{
|
||||
bool inited;
|
||||
struct OptionSwitch:public HighButton
|
||||
{
|
||||
void hover(bool on=true){};
|
||||
void select(bool on=true){};
|
||||
OptionSwitch( SDL_Rect Pos, CDefHandler* Imgs, bool Left, int Which)
|
||||
:HighButton(Pos,Imgs,false,7),left(Left),which(Which)
|
||||
{selectable=false;highlightable=false;}
|
||||
void press(bool down=true);
|
||||
bool left;
|
||||
int playerID;
|
||||
int serialID;
|
||||
int which; //-1=castle;0=hero;1=bonus
|
||||
};
|
||||
struct PlayerFlag:public HighButton
|
||||
{
|
||||
int color;
|
||||
PlayerFlag(SDL_Rect Pos, CDefHandler* Imgs, int Color)
|
||||
:HighButton(Pos,Imgs,false,7),color(Color)
|
||||
{selectable=false;highlightable=true;}
|
||||
void hover(bool on=true);
|
||||
void press(bool down=true);
|
||||
void select(bool on=true){};
|
||||
};
|
||||
struct PlayerOptions
|
||||
{
|
||||
PlayerOptions(int serial, int player);
|
||||
Ecolor color;
|
||||
PlayerFlag flag;
|
||||
//SDL_Surface * bg;
|
||||
OptionSwitch Cleft, Cright, Hleft, Hright, Bleft, Bright;
|
||||
int nr;
|
||||
};
|
||||
public:
|
||||
std::set<int> usedHeroes;
|
||||
Slider * turnLength;
|
||||
SDL_Surface * bg,
|
||||
* rHero, * rCastle, * nHero, * nCastle;
|
||||
std::vector<SDL_Surface*> bgs;
|
||||
std::vector<CDefHandler*> flags;
|
||||
CDefHandler //* castles, * heroes, * bonus,
|
||||
* left, * right,
|
||||
* bonuses;
|
||||
std::vector<PlayerOptions*> poptions;
|
||||
void show();
|
||||
void hide();
|
||||
void init();
|
||||
void showIcon (int what, int nr, bool abs); //what: -1=castle, 0=hero, 1=bonus, 2=all; abs=true -> nr is absolute
|
||||
bool canUseThisHero(int ID);
|
||||
int nextAllowedHero(int min, int max, int incl, int dir); //incl 0 - wlacznie; incl 1 - wylacznie; min-max - zakres szukania
|
||||
Options(){inited=showed=false;};
|
||||
~Options();
|
||||
};
|
||||
class MapSel : public PreGameTab
|
||||
{
|
||||
public:
|
||||
ESortBy sortBy;
|
||||
SDL_Surface * bg;
|
||||
int selected; //selected map
|
||||
CDefHandler * Dtypes, * Dvic;
|
||||
CDefHandler *Dsizes, * Dloss,
|
||||
* sFlags;
|
||||
std::vector<Mapa*> scenList;
|
||||
std::vector<SDL_Surface*> scenImgs;
|
||||
//int current;
|
||||
std::vector<CMapInfo> ourMaps;
|
||||
std::vector<CMapInfo> ourGames;
|
||||
IntBut small, medium, large, xlarge, all;
|
||||
SetrButton nrplayer, mapsize, type, name, viccon, loscon;
|
||||
Slider *slid, *descslid;
|
||||
int sizeFilter;
|
||||
int whichWL(int nr);
|
||||
int countWL();
|
||||
void show();
|
||||
void hide();
|
||||
void init();
|
||||
std::string gdiff(std::string ss);
|
||||
void printMaps(int from,int to=18, int at=0, bool abs=false);
|
||||
void select(int which, bool updateMapsList=true, bool forceSettingsUpdate=false);
|
||||
void moveByOne(bool up);
|
||||
void printSelectedInfo();
|
||||
void printFlags();
|
||||
void processMaps(std::vector<std::string> &pliczkiTemp, int &index);
|
||||
MapSel();
|
||||
~MapSel();
|
||||
};
|
||||
class ScenSel
|
||||
{
|
||||
public:
|
||||
CPoinGroup * difficulty;
|
||||
bool listShowed;
|
||||
//RanSel ransel;
|
||||
MapSel mapsel;
|
||||
SDL_Surface * background, *scenInf, *scenList, *randMap, *options ;
|
||||
Button bScens, bOptions, bRandom, bBegin, bBack;
|
||||
IntSelBut bEasy, bNormal, bHard, bExpert, bImpossible;
|
||||
Button * pressed;
|
||||
std::vector<Mapa> maps;
|
||||
int selectedDiff;
|
||||
void initRanSel();
|
||||
void showRanSel();
|
||||
void hideRanSel();
|
||||
void genScenList();
|
||||
ScenSel();
|
||||
~ScenSel();
|
||||
} ;
|
||||
class CPreGame
|
||||
{
|
||||
public:
|
||||
std::string playerName;
|
||||
int playerColor;
|
||||
HighButton * highlighted;
|
||||
PreGameTab* currentTab;
|
||||
StartInfo ret;
|
||||
bool run;
|
||||
bool first; //hasn't we showed the scensel
|
||||
std::vector<Slider *> interested;
|
||||
CMusicHandler * mush;
|
||||
std::vector<HighButton *> btns;
|
||||
SDL_Rect * currentMessage;
|
||||
SDL_Surface * behindCurMes;
|
||||
CDefHandler *ok, *cancel;
|
||||
enum EState { //where are we?
|
||||
mainMenu, newGame, loadGame, ScenarioList
|
||||
} state;
|
||||
struct menuItems {
|
||||
menuItems();
|
||||
~menuItems();
|
||||
SDL_Surface * background, *bgAd;
|
||||
CDefHandler *newGame, *loadGame, *highScores,*credits, *quit;
|
||||
SDL_Rect lNewGame, lLoadGame, lHighScores, lCredits, lQuit;
|
||||
ttt fNewGame, fLoadGame, fHighScores, fCredits, fQuit;
|
||||
int highlighted;//0=none; 1=new game; 2=load game; 3=high score; 4=credits; 5=quit
|
||||
} * ourMainMenu, * ourNewMenu, * ourLoadMenu;
|
||||
ScenSel * ourScenSel;
|
||||
Options * ourOptions;
|
||||
std::string map; //selected map
|
||||
CPreGame(); //c-tor
|
||||
~CPreGame();//d-tor
|
||||
std::string buttonText(int which);
|
||||
menuItems * currentItems();
|
||||
void(CPreGame::*handleOther)(SDL_Event&);
|
||||
void scenHandleEv(SDL_Event& sEvent);
|
||||
void begin(){run=false;ret.difficulty=ourScenSel->selectedDiff;};
|
||||
void quitAskBox();
|
||||
void quit(){exit(EXIT_SUCCESS);};
|
||||
void initScenSel();
|
||||
void showScenSel();
|
||||
void showScenList();
|
||||
void initOptions();
|
||||
void showOptions();
|
||||
void initNewMenu();
|
||||
void initLoadMenu();
|
||||
void showNewMenu();
|
||||
void showLoadMenu();
|
||||
void showMainMenu();
|
||||
StartInfo runLoop(); // runs mainloop of PreGame
|
||||
void initMainMenu(); //loads components for main menu
|
||||
void highlightButton(int which, int on); //highlights one from 5 main menu buttons
|
||||
void showCenBox (std::string data); //
|
||||
void showAskBox (std::string data, void(*f1)(),void(*f2)());
|
||||
void hideBox ();
|
||||
void printRating();
|
||||
void printMapsFrom(int from);
|
||||
void setTurnLength(int on);
|
||||
void sortMaps();
|
||||
};
|
||||
|
||||
#endif //CPREGAME_H
|
||||
#ifndef __CPREGAME_H__
|
||||
#define __CPREGAME_H__
|
||||
#include "global.h"
|
||||
#include <set>
|
||||
#include <SDL.h>
|
||||
#include "StartInfo.h"
|
||||
#include "CMessage.h"
|
||||
#include "map.h"
|
||||
#include "hch/CMusicHandler.h"
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <cstdlib>
|
||||
|
||||
class CPreGame;
|
||||
class CDefHandler;
|
||||
extern CPreGame * CPG;
|
||||
|
||||
typedef void(CPreGame::*ttt)();
|
||||
class CGroup;
|
||||
class CPoinGroup ;
|
||||
class IntSelBut;
|
||||
|
||||
struct HighButton
|
||||
{
|
||||
int ID;
|
||||
int type;
|
||||
SDL_Rect pos;
|
||||
CDefHandler* imgs;
|
||||
int state;
|
||||
HighButton( SDL_Rect Pos, CDefHandler* Imgs, bool Sel=false, int id=-1);
|
||||
HighButton();
|
||||
~HighButton();
|
||||
bool selectable, selected;
|
||||
bool highlightable, highlighted;
|
||||
virtual void show();
|
||||
virtual void press(bool down=true);
|
||||
virtual void hover(bool on=true)=0;
|
||||
virtual void select(bool on=true)=0;
|
||||
};
|
||||
struct Button: public HighButton
|
||||
{
|
||||
CGroup *ourGroup;
|
||||
Button( SDL_Rect Pos, boost::function<void()> Fun,CDefHandler* Imgs, bool Sel=false, CGroup* gr=NULL, int id=-1);
|
||||
Button();
|
||||
boost::function<void()> fun;
|
||||
virtual void hover(bool on=true);
|
||||
virtual void select(bool on=true);
|
||||
};
|
||||
struct SetrButton: public Button
|
||||
{
|
||||
int key, * poin;
|
||||
virtual void press(bool down=true);
|
||||
SetrButton();
|
||||
};
|
||||
|
||||
class Slider
|
||||
{
|
||||
public:
|
||||
bool vertical; // false means horizontal
|
||||
SDL_Rect pos; // position
|
||||
Button *up, *down, //or left/right
|
||||
*slider;
|
||||
int positionsAmnt, capacity;// capacity - amount of positions dispplayed at once
|
||||
int whereAreWe; // first displayed thing
|
||||
bool moving;
|
||||
boost::function<void(int)> fun;
|
||||
void clickDown(int x, int y, bool bzgl=true);
|
||||
void clickUp(int x, int y, bool bzgl=true);
|
||||
void mMove(int x, int y, bool bzgl=true);
|
||||
void moveUp();
|
||||
void moveDown();
|
||||
void deactivate();
|
||||
void activate();
|
||||
Slider(int x, int y, int h, int amnt, int cap, bool ver);
|
||||
~Slider();
|
||||
void updateSlid();
|
||||
void handleIt(SDL_Event sev);
|
||||
};
|
||||
|
||||
struct IntBut: public Button
|
||||
{
|
||||
public:
|
||||
int key;
|
||||
int * what;
|
||||
IntBut();
|
||||
void set();
|
||||
};
|
||||
class CGroup
|
||||
{
|
||||
public:
|
||||
Button * selected;
|
||||
int type; // 1=sinsel
|
||||
CGroup():selected(NULL),type(0){};
|
||||
};
|
||||
|
||||
class CPoinGroup :public CGroup
|
||||
{
|
||||
public:
|
||||
int * gdzie; //where (po polsku, bo by by�o s�owo kluczowe :/)
|
||||
void setYour(IntSelBut * your);
|
||||
};
|
||||
struct IntSelBut: public Button
|
||||
{
|
||||
public:
|
||||
CPoinGroup * ourPoinGroup;
|
||||
int key;
|
||||
IntSelBut(){};
|
||||
IntSelBut( SDL_Rect Pos, boost::function<void()> Fun,CDefHandler* Imgs, bool Sel=false, CPoinGroup* gr=NULL, int My=-1);
|
||||
void select(bool on=true);
|
||||
};
|
||||
class PreGameTab
|
||||
{
|
||||
public:
|
||||
bool showed;
|
||||
virtual void init()=0;
|
||||
virtual void show()=0;
|
||||
virtual void hide()=0;
|
||||
PreGameTab();
|
||||
};
|
||||
class RanSel : public PreGameTab
|
||||
{
|
||||
Button horcpl[9], horcte[9], conpl[9], conte[8], water[4], monster[4], //last is random
|
||||
size[4], twoLevel, showRand;
|
||||
CGroup *Ghorcpl, *Ghorcte, *Gconpl, *Gconte, *Gwater, *Gmonster, *Gsize;
|
||||
};
|
||||
class Options : public PreGameTab
|
||||
{
|
||||
bool inited;
|
||||
struct OptionSwitch:public HighButton
|
||||
{
|
||||
void hover(bool on=true){};
|
||||
void select(bool on=true){};
|
||||
OptionSwitch( SDL_Rect Pos, CDefHandler* Imgs, bool Left, int Which)
|
||||
:HighButton(Pos,Imgs,false,7),left(Left),which(Which)
|
||||
{selectable=false;highlightable=false;}
|
||||
void press(bool down=true);
|
||||
bool left;
|
||||
int playerID;
|
||||
int serialID;
|
||||
int which; //-1=castle;0=hero;1=bonus
|
||||
};
|
||||
struct PlayerFlag:public HighButton
|
||||
{
|
||||
int color;
|
||||
PlayerFlag(SDL_Rect Pos, CDefHandler* Imgs, int Color)
|
||||
:HighButton(Pos,Imgs,false,7),color(Color)
|
||||
{selectable=false;highlightable=true;}
|
||||
void hover(bool on=true);
|
||||
void press(bool down=true);
|
||||
void select(bool on=true){};
|
||||
};
|
||||
struct PlayerOptions
|
||||
{
|
||||
PlayerOptions(int serial, int player);
|
||||
Ecolor color;
|
||||
PlayerFlag flag;
|
||||
//SDL_Surface * bg;
|
||||
OptionSwitch Cleft, Cright, Hleft, Hright, Bleft, Bright;
|
||||
int nr;
|
||||
};
|
||||
public:
|
||||
std::set<int> usedHeroes;
|
||||
Slider * turnLength;
|
||||
SDL_Surface * bg,
|
||||
* rHero, * rCastle, * nHero, * nCastle;
|
||||
std::vector<SDL_Surface*> bgs;
|
||||
std::vector<CDefHandler*> flags;
|
||||
CDefHandler //* castles, * heroes, * bonus,
|
||||
* left, * right,
|
||||
* bonuses;
|
||||
std::vector<PlayerOptions*> poptions;
|
||||
void show();
|
||||
void hide();
|
||||
void init();
|
||||
void showIcon (int what, int nr, bool abs); //what: -1=castle, 0=hero, 1=bonus, 2=all; abs=true -> nr is absolute
|
||||
bool canUseThisHero(int ID);
|
||||
int nextAllowedHero(int min, int max, int incl, int dir); //incl 0 - wlacznie; incl 1 - wylacznie; min-max - zakres szukania
|
||||
Options(){inited=showed=false;};
|
||||
~Options();
|
||||
};
|
||||
class MapSel : public PreGameTab
|
||||
{
|
||||
public:
|
||||
ESortBy sortBy;
|
||||
SDL_Surface * bg;
|
||||
int selected; //selected map
|
||||
CDefHandler * Dtypes, * Dvic;
|
||||
CDefHandler *Dsizes, * Dloss,
|
||||
* sFlags;
|
||||
std::vector<Mapa*> scenList;
|
||||
std::vector<SDL_Surface*> scenImgs;
|
||||
//int current;
|
||||
std::vector<CMapInfo> ourMaps;
|
||||
std::vector<CMapInfo> ourGames;
|
||||
IntBut small, medium, large, xlarge, all;
|
||||
SetrButton nrplayer, mapsize, type, name, viccon, loscon;
|
||||
Slider *slid, *descslid;
|
||||
int sizeFilter;
|
||||
int whichWL(int nr);
|
||||
int countWL();
|
||||
void show();
|
||||
void hide();
|
||||
void init();
|
||||
std::string gdiff(std::string ss);
|
||||
void printMaps(int from,int to=18, int at=0, bool abs=false);
|
||||
void select(int which, bool updateMapsList=true, bool forceSettingsUpdate=false);
|
||||
void moveByOne(bool up);
|
||||
void printSelectedInfo();
|
||||
void printFlags();
|
||||
void processMaps(std::vector<std::string> &pliczkiTemp, int &index);
|
||||
MapSel();
|
||||
~MapSel();
|
||||
};
|
||||
class ScenSel
|
||||
{
|
||||
public:
|
||||
CPoinGroup * difficulty;
|
||||
bool listShowed;
|
||||
//RanSel ransel;
|
||||
MapSel mapsel;
|
||||
SDL_Surface * background, *scenInf, *scenList, *randMap, *options ;
|
||||
Button bScens, bOptions, bRandom, bBegin, bBack;
|
||||
IntSelBut bEasy, bNormal, bHard, bExpert, bImpossible;
|
||||
Button * pressed;
|
||||
std::vector<Mapa> maps;
|
||||
int selectedDiff;
|
||||
void initRanSel();
|
||||
void showRanSel();
|
||||
void hideRanSel();
|
||||
void genScenList();
|
||||
ScenSel();
|
||||
~ScenSel();
|
||||
} ;
|
||||
class CPreGame
|
||||
{
|
||||
public:
|
||||
std::string playerName;
|
||||
int playerColor;
|
||||
HighButton * highlighted;
|
||||
PreGameTab* currentTab;
|
||||
StartInfo ret;
|
||||
bool run;
|
||||
bool first; //hasn't we showed the scensel
|
||||
std::vector<Slider *> interested;
|
||||
CMusicHandler * mush;
|
||||
std::vector<HighButton *> btns;
|
||||
SDL_Rect * currentMessage;
|
||||
SDL_Surface * behindCurMes;
|
||||
CDefHandler *ok, *cancel;
|
||||
enum EState { //where are we?
|
||||
mainMenu, newGame, loadGame, ScenarioList
|
||||
} state;
|
||||
struct menuItems {
|
||||
menuItems();
|
||||
~menuItems();
|
||||
SDL_Surface * background, *bgAd;
|
||||
CDefHandler *newGame, *loadGame, *highScores,*credits, *quit;
|
||||
SDL_Rect lNewGame, lLoadGame, lHighScores, lCredits, lQuit;
|
||||
ttt fNewGame, fLoadGame, fHighScores, fCredits, fQuit;
|
||||
int highlighted;//0=none; 1=new game; 2=load game; 3=high score; 4=credits; 5=quit
|
||||
} * ourMainMenu, * ourNewMenu, * ourLoadMenu;
|
||||
ScenSel * ourScenSel;
|
||||
Options * ourOptions;
|
||||
std::string map; //selected map
|
||||
CPreGame(); //c-tor
|
||||
~CPreGame();//d-tor
|
||||
std::string buttonText(int which);
|
||||
menuItems * currentItems();
|
||||
void(CPreGame::*handleOther)(SDL_Event&);
|
||||
void scenHandleEv(SDL_Event& sEvent);
|
||||
void begin(){run=false;ret.difficulty=ourScenSel->selectedDiff;};
|
||||
void quitAskBox();
|
||||
void quit(){exit(EXIT_SUCCESS);};
|
||||
void initScenSel();
|
||||
void showScenSel();
|
||||
void showScenList();
|
||||
void initOptions();
|
||||
void showOptions();
|
||||
void initNewMenu();
|
||||
void initLoadMenu();
|
||||
void showNewMenu();
|
||||
void showLoadMenu();
|
||||
void showMainMenu();
|
||||
StartInfo runLoop(); // runs mainloop of PreGame
|
||||
void initMainMenu(); //loads components for main menu
|
||||
void highlightButton(int which, int on); //highlights one from 5 main menu buttons
|
||||
void showCenBox (std::string data); //
|
||||
void showAskBox (std::string data, void(*f1)(),void(*f2)());
|
||||
void hideBox ();
|
||||
void printRating();
|
||||
void printMapsFrom(int from);
|
||||
void setTurnLength(int on);
|
||||
void sortMaps();
|
||||
};
|
||||
|
||||
|
||||
#endif // __CPREGAME_H__
|
||||
|
@ -1,42 +1,43 @@
|
||||
#ifndef CTHREADHELPER_H
|
||||
#define CTHREADHELPER_H
|
||||
|
||||
#include "global.h"
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
typedef boost::function<void()> Task;
|
||||
|
||||
class CThreadHelper
|
||||
{
|
||||
boost::mutex rtinm;
|
||||
int currentTask, amount, threads;
|
||||
std::vector<Task> *tasks;
|
||||
|
||||
|
||||
void processTasks();
|
||||
public:
|
||||
CThreadHelper(std::vector<boost::function<void()> > *Tasks, int Threads);
|
||||
void run();
|
||||
};
|
||||
|
||||
template <typename T> inline void setData(T * data, boost::function<T()> func)
|
||||
{
|
||||
*data = func();
|
||||
}
|
||||
|
||||
|
||||
#define GET_DATA(TYPE,DESTINATION,FUNCTION_TO_GET) \
|
||||
(boost::bind(&setData<TYPE>,&DESTINATION,FUNCTION_TO_GET))
|
||||
#define GET_SURFACE(SUR_DESTINATION, SUR_NAME) \
|
||||
(GET_DATA \
|
||||
(SDL_Surface*,SUR_DESTINATION,\
|
||||
boost::function<SDL_Surface*()>(boost::bind(&BitmapHandler::loadBitmap,SUR_NAME,true))))
|
||||
#define GET_DEF(DESTINATION, DEF_NAME) \
|
||||
(GET_DATA \
|
||||
(CDefHandler*,DESTINATION,\
|
||||
boost::function<CDefHandler*()>(boost::bind(CDefHandler::giveDef,DEF_NAME,(CLodHandler*)NULL))))
|
||||
#define GET_DEF_ESS(DESTINATION, DEF_NAME) \
|
||||
(GET_DATA \
|
||||
(CDefEssential*,DESTINATION,\
|
||||
boost::function<CDefEssential*()>(boost::bind(CDefHandler::giveDefEss,DEF_NAME,(CLodHandler*)NULL))))
|
||||
#endif //CTHREADHELPER_H
|
||||
#ifndef __CTHREADHELPER_H__
|
||||
#define __CTHREADHELPER_H__
|
||||
|
||||
#include "global.h"
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
typedef boost::function<void()> Task;
|
||||
|
||||
class CThreadHelper
|
||||
{
|
||||
boost::mutex rtinm;
|
||||
int currentTask, amount, threads;
|
||||
std::vector<Task> *tasks;
|
||||
|
||||
|
||||
void processTasks();
|
||||
public:
|
||||
CThreadHelper(std::vector<boost::function<void()> > *Tasks, int Threads);
|
||||
void run();
|
||||
};
|
||||
|
||||
template <typename T> inline void setData(T * data, boost::function<T()> func)
|
||||
{
|
||||
*data = func();
|
||||
}
|
||||
|
||||
|
||||
#define GET_DATA(TYPE,DESTINATION,FUNCTION_TO_GET) \
|
||||
(boost::bind(&setData<TYPE>,&DESTINATION,FUNCTION_TO_GET))
|
||||
#define GET_SURFACE(SUR_DESTINATION, SUR_NAME) \
|
||||
(GET_DATA \
|
||||
(SDL_Surface*,SUR_DESTINATION,\
|
||||
boost::function<SDL_Surface*()>(boost::bind(&BitmapHandler::loadBitmap,SUR_NAME,true))))
|
||||
#define GET_DEF(DESTINATION, DEF_NAME) \
|
||||
(GET_DATA \
|
||||
(CDefHandler*,DESTINATION,\
|
||||
boost::function<CDefHandler*()>(boost::bind(CDefHandler::giveDef,DEF_NAME,(CLodHandler*)NULL))))
|
||||
#define GET_DEF_ESS(DESTINATION, DEF_NAME) \
|
||||
(GET_DATA \
|
||||
(CDefEssential*,DESTINATION,\
|
||||
boost::function<CDefEssential*()>(boost::bind(CDefHandler::giveDefEss,DEF_NAME,(CLodHandler*)NULL))))
|
||||
|
||||
#endif // __CTHREADHELPER_H__
|
||||
|
113
SDL_Extensions.h
113
SDL_Extensions.h
@ -1,56 +1,57 @@
|
||||
#ifndef SDL_EXTENSIONS_H
|
||||
#define SDL_EXTENSIONS_H
|
||||
#include "SDL.h"
|
||||
#include "SDL_ttf.h"
|
||||
|
||||
|
||||
extern SDL_Surface * screen;
|
||||
extern SDL_Color tytulowy, tlo, zwykly ;
|
||||
extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
|
||||
void blitAtWR(SDL_Surface * src, int x, int y, SDL_Surface * dst=screen);
|
||||
void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=screen);
|
||||
void blitAtWR(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst=screen);
|
||||
void blitAt(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst=screen);
|
||||
void updateRect (SDL_Rect * rect, SDL_Surface * scr = screen);
|
||||
bool isItIn(const SDL_Rect * rect, int x, int y);
|
||||
template <typename T> int getIndexOf(const std::vector<T> & v, const T & val)
|
||||
{
|
||||
for(int i=0;i<v.size();i++)
|
||||
if(v[i]==val)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
inline SDL_Rect genRect(const int & hh, const int & ww, const int & xx, const int & yy);
|
||||
namespace CSDL_Ext
|
||||
{
|
||||
extern SDL_Surface * std32bppSurface;
|
||||
inline void SDL_PutPixel(SDL_Surface *ekran, const int & x, const int & y, const Uint8 & R, const Uint8 & G, const Uint8 & B, Uint8 A = 255); //myC influences the start of reading pixels
|
||||
inline void SDL_PutPixelWithoutRefresh(SDL_Surface *ekran, const int & x, const int & y, const Uint8 & R, const Uint8 & G, const Uint8 & B, Uint8 A = 255); //myC influences the start of reading pixels ; without refreshing
|
||||
SDL_Surface * rotate01(SDL_Surface * toRot); //vertical flip
|
||||
SDL_Surface * hFlip(SDL_Surface * toRot); //horizontal flip
|
||||
SDL_Surface * rotate02(SDL_Surface * toRot); //rotate 90 degrees left
|
||||
SDL_Surface * rotate03(SDL_Surface * toRot); //rotate 180 degrees
|
||||
SDL_Cursor * SurfaceToCursor(SDL_Surface *image, int hx, int hy);
|
||||
Uint32 SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte = false);
|
||||
SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y);
|
||||
SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details)
|
||||
void blitWithRotate1(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests
|
||||
void blitWithRotate2(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests
|
||||
void blitWithRotate3(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests
|
||||
int blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface
|
||||
Uint32 colorToUint32(const SDL_Color * color); //little endian only
|
||||
void printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)
|
||||
void printToWR(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)
|
||||
void printAtMiddle(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2, bool refresh = false); // quality: 0 - lowest, 1 - medium, 2 - highest
|
||||
void printAtMiddleWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
|
||||
void printAtWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
|
||||
void printAt(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest
|
||||
void update(SDL_Surface * what = screen); //updates whole surface (default - main screen)
|
||||
void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, int3 color);
|
||||
void setPlayerColor(SDL_Surface * sur, unsigned char player); //sets correct color of flags; -1 for neutral
|
||||
std::string processStr(std::string str, std::vector<std::string> & tor); //replaces %s in string
|
||||
SDL_Surface * newSurface(int w, int h, SDL_Surface * mod=screen); //creates new surface, with flags/format same as in surface given
|
||||
SDL_Surface * copySurface(SDL_Surface * mod); //returns copy of given surface
|
||||
};
|
||||
|
||||
#endif // SDL_EXTENSIONS_H
|
||||
#ifndef __SDL_EXTENSIONS_H__
|
||||
#define __SDL_EXTENSIONS_H__
|
||||
#include "SDL.h"
|
||||
#include "SDL_ttf.h"
|
||||
|
||||
|
||||
extern SDL_Surface * screen;
|
||||
extern SDL_Color tytulowy, tlo, zwykly ;
|
||||
extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
|
||||
void blitAtWR(SDL_Surface * src, int x, int y, SDL_Surface * dst=screen);
|
||||
void blitAt(SDL_Surface * src, int x, int y, SDL_Surface * dst=screen);
|
||||
void blitAtWR(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst=screen);
|
||||
void blitAt(SDL_Surface * src, SDL_Rect pos, SDL_Surface * dst=screen);
|
||||
void updateRect (SDL_Rect * rect, SDL_Surface * scr = screen);
|
||||
bool isItIn(const SDL_Rect * rect, int x, int y);
|
||||
template <typename T> int getIndexOf(const std::vector<T> & v, const T & val)
|
||||
{
|
||||
for(int i=0;i<v.size();i++)
|
||||
if(v[i]==val)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
inline SDL_Rect genRect(const int & hh, const int & ww, const int & xx, const int & yy);
|
||||
namespace CSDL_Ext
|
||||
{
|
||||
extern SDL_Surface * std32bppSurface;
|
||||
inline void SDL_PutPixel(SDL_Surface *ekran, const int & x, const int & y, const Uint8 & R, const Uint8 & G, const Uint8 & B, Uint8 A = 255); //myC influences the start of reading pixels
|
||||
inline void SDL_PutPixelWithoutRefresh(SDL_Surface *ekran, const int & x, const int & y, const Uint8 & R, const Uint8 & G, const Uint8 & B, Uint8 A = 255); //myC influences the start of reading pixels ; without refreshing
|
||||
SDL_Surface * rotate01(SDL_Surface * toRot); //vertical flip
|
||||
SDL_Surface * hFlip(SDL_Surface * toRot); //horizontal flip
|
||||
SDL_Surface * rotate02(SDL_Surface * toRot); //rotate 90 degrees left
|
||||
SDL_Surface * rotate03(SDL_Surface * toRot); //rotate 180 degrees
|
||||
SDL_Cursor * SurfaceToCursor(SDL_Surface *image, int hx, int hy);
|
||||
Uint32 SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte = false);
|
||||
SDL_Color SDL_GetPixelColor(SDL_Surface *surface, int x, int y);
|
||||
SDL_Surface * alphaTransform(SDL_Surface * src); //adds transparency and shadows (partial handling only; see examples of using for details)
|
||||
void blitWithRotate1(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests
|
||||
void blitWithRotate2(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests
|
||||
void blitWithRotate3(SDL_Surface *src,SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect);//srcRect is not used, works with 8bpp sources and 24bpp dests
|
||||
int blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect); //blits 8 bpp surface with alpha channel to 24 bpp surface
|
||||
Uint32 colorToUint32(const SDL_Color * color); //little endian only
|
||||
void printTo(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)
|
||||
void printToWR(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2);// quality: 0 - lowest, 1 - medium, 2 - highest; prints at right bottom corner of specific area. position of corner indicated by (x, y)
|
||||
void printAtMiddle(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2, bool refresh = false); // quality: 0 - lowest, 1 - medium, 2 - highest
|
||||
void printAtMiddleWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
|
||||
void printAtWB(const std::string & text, int x, int y, TTF_Font * font, int charpr, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen);
|
||||
void printAt(const std::string & text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=screen, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest
|
||||
void update(SDL_Surface * what = screen); //updates whole surface (default - main screen)
|
||||
void drawBorder(SDL_Surface * sur, int x, int y, int w, int h, int3 color);
|
||||
void setPlayerColor(SDL_Surface * sur, unsigned char player); //sets correct color of flags; -1 for neutral
|
||||
std::string processStr(std::string str, std::vector<std::string> & tor); //replaces %s in string
|
||||
SDL_Surface * newSurface(int w, int h, SDL_Surface * mod=screen); //creates new surface, with flags/format same as in surface given
|
||||
SDL_Surface * copySurface(SDL_Surface * mod); //returns copy of given surface
|
||||
};
|
||||
|
||||
|
||||
#endif // __SDL_EXTENSIONS_H__
|
||||
|
117
StartInfo.h
117
StartInfo.h
@ -1,58 +1,59 @@
|
||||
#ifndef STARTINFO_H
|
||||
#define STARTINFO_H
|
||||
|
||||
#include "global.h"
|
||||
#include <vector>
|
||||
|
||||
enum Ebonus {brandom=-1,bartifact, bgold, bresource};
|
||||
|
||||
struct StartInfo
|
||||
{
|
||||
struct PlayerSettings
|
||||
{
|
||||
si32 castle, hero, //ID, if -1 then random, if -2 then none
|
||||
heroPortrait; //-1 if default, else ID
|
||||
std::string heroName;
|
||||
si8 bonus; //usees enum type Ebonus
|
||||
ui8 color; //from 0 -
|
||||
ui8 serial;
|
||||
ui8 handicap;//0-no, 1-mild, 2-severe
|
||||
std::string name;
|
||||
bool human;
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & castle;
|
||||
h & hero;
|
||||
h & heroPortrait;
|
||||
h & heroName;
|
||||
h & bonus;
|
||||
h & color;
|
||||
h & serial;
|
||||
h & handicap;
|
||||
h & name;
|
||||
h & human;
|
||||
}
|
||||
};
|
||||
si32 difficulty; //0=easy; 4=impossible
|
||||
std::vector<PlayerSettings> playerInfos;
|
||||
ui8 turnTime; //in minutes, 0=unlimited
|
||||
std::string mapname;
|
||||
PlayerSettings & getIthPlayersSettings(int no)
|
||||
{
|
||||
for(unsigned int i=0; i<playerInfos.size(); ++i)
|
||||
if(playerInfos[i].color == no)
|
||||
return playerInfos[i];
|
||||
tlog1 << "Cannot find info about player " << no <<". Throwing...\n";
|
||||
throw std::string("Cannot find info about player");
|
||||
|
||||
}
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & difficulty;
|
||||
h & playerInfos;
|
||||
h & turnTime;
|
||||
h & mapname;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
#ifndef __STARTINFO_H__
|
||||
#define __STARTINFO_H__
|
||||
|
||||
#include "global.h"
|
||||
#include <vector>
|
||||
|
||||
enum Ebonus {brandom=-1,bartifact, bgold, bresource};
|
||||
|
||||
struct StartInfo
|
||||
{
|
||||
struct PlayerSettings
|
||||
{
|
||||
si32 castle, hero, //ID, if -1 then random, if -2 then none
|
||||
heroPortrait; //-1 if default, else ID
|
||||
std::string heroName;
|
||||
si8 bonus; //usees enum type Ebonus
|
||||
ui8 color; //from 0 -
|
||||
ui8 serial;
|
||||
ui8 handicap;//0-no, 1-mild, 2-severe
|
||||
std::string name;
|
||||
bool human;
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & castle;
|
||||
h & hero;
|
||||
h & heroPortrait;
|
||||
h & heroName;
|
||||
h & bonus;
|
||||
h & color;
|
||||
h & serial;
|
||||
h & handicap;
|
||||
h & name;
|
||||
h & human;
|
||||
}
|
||||
};
|
||||
si32 difficulty; //0=easy; 4=impossible
|
||||
std::vector<PlayerSettings> playerInfos;
|
||||
ui8 turnTime; //in minutes, 0=unlimited
|
||||
std::string mapname;
|
||||
PlayerSettings & getIthPlayersSettings(int no)
|
||||
{
|
||||
for(unsigned int i=0; i<playerInfos.size(); ++i)
|
||||
if(playerInfos[i].color == no)
|
||||
return playerInfos[i];
|
||||
tlog1 << "Cannot find info about player " << no <<". Throwing...\n";
|
||||
throw std::string("Cannot find info about player");
|
||||
|
||||
}
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & difficulty;
|
||||
h & playerInfos;
|
||||
h & turnTime;
|
||||
h & mapname;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // __STARTINFO_H__
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef CBITMAPHANDLER_H
|
||||
#define CBITMAPHANDLER_H
|
||||
#ifndef __CBITMAPHANDLER_H__
|
||||
#define __CBITMAPHANDLER_H__
|
||||
|
||||
|
||||
|
||||
@ -41,4 +41,5 @@ namespace BitmapHandler
|
||||
extern CLodHandler *bitmaph;
|
||||
SDL_Surface * loadBitmap(std::string fname, bool setKey=false);
|
||||
};
|
||||
#endif //CBITMAPHANDLER_H
|
||||
|
||||
#endif // __CBITMAPHANDLER_H__
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef CCONFIGHANDLER_H
|
||||
#define CCONFIGHANDLER_H
|
||||
#ifndef __CCONFIGHANDLER_H__
|
||||
#define __CCONFIGHANDLER_H__
|
||||
#include "../global.h"
|
||||
class CAdvMapInt;
|
||||
namespace config
|
||||
@ -63,4 +63,5 @@ namespace config
|
||||
};
|
||||
}
|
||||
extern config::CConfigHandler conf;
|
||||
#endif //CCONFIGHANDLER_H
|
||||
|
||||
#endif // __CCONFIGHANDLER_H__
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef CCREATUREANIMATION_H
|
||||
#define CCREATUREANIMATION_H
|
||||
#ifndef __CCREATUREANIMATION_H__
|
||||
#define __CCREATUREANIMATION_H__
|
||||
|
||||
|
||||
#include "../global.h"
|
||||
@ -51,4 +51,5 @@ public:
|
||||
|
||||
int framesInGroup(int group) const; //retirns number of fromes in given group
|
||||
};
|
||||
#endif //CCREATUREANIMATION_H
|
||||
|
||||
#endif // __CCREATUREANIMATION_H__
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef CSPELLWINDOW_H
|
||||
#define CSPELLWINDOW_H
|
||||
#ifndef __CSPELLWINDOW_H__
|
||||
#define __CSPELLWINDOW_H__
|
||||
|
||||
|
||||
#include "../global.h"
|
||||
@ -89,4 +89,5 @@ public:
|
||||
void deactivate();
|
||||
void show(SDL_Surface * to = NULL);
|
||||
};
|
||||
#endif //CSPELLWINDOW_H
|
||||
|
||||
#endif // __CSPELLWINDOW_H__
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef CLIENT_H
|
||||
#define CLIENT_H
|
||||
#ifndef __CLIENT_H__
|
||||
#define __CLIENT_H__
|
||||
|
||||
|
||||
#include "../global.h"
|
||||
@ -59,4 +59,5 @@ public:
|
||||
friend class CScriptCallback; //for objects scripts
|
||||
friend void processCommand(const std::string &message, CClient *&client); //handling console
|
||||
};
|
||||
#endif //CLIENT_H
|
||||
|
||||
#endif // __CLIENT_H__
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef GRAPHICS_H
|
||||
#define GRAPHICS_H
|
||||
#ifndef __GRAPHICS_H__
|
||||
#define __GRAPHICS_H__
|
||||
|
||||
|
||||
#include "../global.h"
|
||||
@ -63,4 +63,5 @@ public:
|
||||
};
|
||||
|
||||
extern Graphics * graphics;
|
||||
#endif //GRAPHICS_H
|
||||
|
||||
#endif // __GRAPHICS_H__
|
||||
|
541
global.h
541
global.h
@ -1,270 +1,271 @@
|
||||
#ifndef GLOBAL_H
|
||||
#define GLOBAL_H
|
||||
#include <iostream>
|
||||
#include <algorithm> //std::find
|
||||
#include <boost/logic/tribool.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes)
|
||||
typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes)
|
||||
typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes)
|
||||
typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte)
|
||||
typedef boost::int64_t si64; //signed int 64 bits (8 bytes)
|
||||
typedef boost::int32_t si32; //signed int 32 bits (4 bytes)
|
||||
typedef boost::int16_t si16; //signed int 16 bits (2 bytes)
|
||||
typedef boost::int8_t si8; //signed int 8 bits (1 byte)
|
||||
#include "int3.h"
|
||||
#define CHECKTIME 1
|
||||
#if CHECKTIME
|
||||
#include "timeHandler.h"
|
||||
#define THC
|
||||
#endif
|
||||
|
||||
#define NAME_VER ("VCMI 0.65")
|
||||
#define CONSOLE_LOGGING_LEVEL 5
|
||||
#define FILE_LOGGING_LEVEL 6
|
||||
|
||||
#ifdef _WIN32
|
||||
#define PATHSEPARATOR "\\"
|
||||
#define DATA_DIR ""
|
||||
#define SERVER_NAME "VCMI_server.exe"
|
||||
#else
|
||||
#define PATHSEPARATOR "/"
|
||||
#define DATA_DIR ""
|
||||
#define SERVER_NAME "./vcmiserver"
|
||||
#endif
|
||||
|
||||
enum Ecolor {RED, BLUE, TAN, GREEN, ORANGE, PURPLE, TEAL, PINK}; //player's colors
|
||||
enum EterrainType {border=-1, dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock};
|
||||
enum Eriver {noRiver=0, clearRiver, icyRiver, muddyRiver, lavaRiver};
|
||||
enum Eroad {dirtRoad=1, grazvelRoad, cobblestoneRoad};
|
||||
enum Eformat { WoG=0x33, AB=0x15, RoE=0x0e, SoD=0x1c};
|
||||
enum EvictoryConditions {artifact, gatherTroop, gatherResource, buildCity, buildGrail, beatHero,
|
||||
captureCity, beatMonster, takeDwellings, takeMines, transportItem, winStandard=255};
|
||||
enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=255};
|
||||
enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HERO_ALCHEMIST, HERO_WIZARD,
|
||||
HERO_DEMONIAC, HERO_HERETIC, HERO_DEATHKNIGHT, HERO_NECROMANCER, HERO_WARLOCK, HERO_OVERLORD,
|
||||
HERO_BARBARIAN, HERO_BATTLEMAGE, HERO_BEASTMASTER, HERO_WITCH, HERO_PLANESWALKER, HERO_ELEMENTALIST};
|
||||
enum EAbilities {DOUBLE_WIDE, FLYING, SHOOTER, TWO_HEX_ATTACK, SIEGE_ABILITY, SIEGE_WEAPON,
|
||||
KING1, KING2, KING3, MIND_IMMUNITY, NO_OBSTACLE_PENALTY, NO_CLOSE_COMBAT_PENALTY,
|
||||
JOUSTING, FIRE_IMMUNITY, TWICE_ATTACK, NO_ENEMY_RETALIATION, NO_MORAL_PENALTY,
|
||||
UNDEAD, MULTI_HEAD_ATTACK, EXTENDED_RADIOUS_SHOOTER, GHOST, RAISES_MORALE,
|
||||
LOWERS_MORALE, DRAGON, STRIKE_AND_RETURN, FEARLESS, REBIRTH}; //some flags are used only for battles
|
||||
enum ECombatInfo{ALIVE = REBIRTH+1, SUMMONED, CLONED, HAD_MORALE, WAITING, MOVED, DEFENDING};
|
||||
class CGameInfo;
|
||||
extern CGameInfo* CGI;
|
||||
|
||||
#define HEROI_TYPE (34)
|
||||
#define TOWNI_TYPE (98)
|
||||
|
||||
const int F_NUMBER = 9; //factions (town types) quantity
|
||||
const int PLAYER_LIMIT = 8; //player limit per map
|
||||
const int HEROES_PER_TYPE=8; //amount of heroes of each type
|
||||
const int SKILL_QUANTITY=28;
|
||||
const int SKILL_PER_HERO=8;
|
||||
const int ARTIFACTS_QUANTITY=171;
|
||||
const int HEROES_QUANTITY=156;
|
||||
const int SPELLS_QUANTITY=70;
|
||||
const int RESOURCE_QUANTITY=8;
|
||||
const int TERRAIN_TYPES=10;
|
||||
const int PRIMARY_SKILLS=4;
|
||||
const int NEUTRAL_PLAYER=255;
|
||||
const int NAMES_PER_TOWN=16;
|
||||
const int CREATURES_PER_TOWN = 7; //without upgrades
|
||||
const int MAX_BUILDING_PER_TURN = 1;
|
||||
const int SPELL_LEVELS = 5;
|
||||
|
||||
#define BFIELD_WIDTH (17)
|
||||
#define BFIELD_HEIGHT (11)
|
||||
#define BFIELD_SIZE ((BFIELD_WIDTH) * (BFIELD_HEIGHT))
|
||||
|
||||
//uncomment to make it work
|
||||
//#define MARK_BLOCKED_POSITIONS
|
||||
//#define MARK_VISITABLE_POSITIONS
|
||||
|
||||
#define DEFBYPASS
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef VCMI_DLL
|
||||
#define DLL_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define DLL_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||
#define DLL_EXPORT __attribute__ ((visibility("default")))
|
||||
#else
|
||||
#define DLL_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace vstd
|
||||
{
|
||||
template <typename Container, typename Item>
|
||||
bool contains(const Container & c, const Item &i)
|
||||
{
|
||||
return std::find(c.begin(),c.end(),i) != c.end();
|
||||
}
|
||||
template <typename V, typename Item, typename Item2>
|
||||
bool contains(const std::map<Item,V> & c, const Item2 &i)
|
||||
{
|
||||
return c.find(i)!=c.end();
|
||||
}
|
||||
template <typename Container1, typename Container2>
|
||||
typename Container2::iterator findFirstNot(Container1 &c1, Container2 &c2)//returns first element of c2 not present in c1
|
||||
{
|
||||
typename Container2::iterator itr = c2.begin();
|
||||
while(itr != c2.end())
|
||||
if(!contains(c1,*itr))
|
||||
return itr;
|
||||
else
|
||||
++itr;
|
||||
return c2.end();
|
||||
}
|
||||
template <typename Container, typename Item>
|
||||
typename Container::iterator find(const Container & c, const Item &i)
|
||||
{
|
||||
return std::find(c.begin(),c.end(),i);
|
||||
}
|
||||
template <typename T1, typename T2>
|
||||
int findPos(const std::vector<T1> & c, const T2 &s)
|
||||
{
|
||||
for(size_t i=0; i < c.size(); ++i)
|
||||
if(c[i] == s)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
template <typename T1, typename T2, typename Func>
|
||||
int findPos(const std::vector<T1> & c, const T2 &s, const Func &f) //Func(T1,T2) must say if these elements matches
|
||||
{
|
||||
for(size_t i=0; i < c.size(); ++i)
|
||||
if(f(c[i],s))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
template <typename Container, typename Item>
|
||||
typename Container::iterator find(Container & c, const Item &i)
|
||||
{
|
||||
return std::find(c.begin(),c.end(),i);
|
||||
}
|
||||
template <typename Container, typename Item>
|
||||
bool operator-=(Container &c, const Item &i)
|
||||
{
|
||||
typename Container::iterator itr = find(c,i);
|
||||
if(itr == c.end())
|
||||
return false;
|
||||
c.erase(itr);
|
||||
return true;
|
||||
}
|
||||
template <typename t1>
|
||||
void delObj(t1 *a1)
|
||||
{
|
||||
delete a1;
|
||||
}
|
||||
template <typename t1, typename t2>
|
||||
void assign(t1 &a1, const t2 &a2)
|
||||
{
|
||||
a1 = a2;
|
||||
}
|
||||
template <typename t1, typename t2>
|
||||
struct assigner
|
||||
{
|
||||
public:
|
||||
t1 &op1;
|
||||
t2 op2;
|
||||
assigner(t1 &a1, t2 a2)
|
||||
:op1(a1), op2(a2)
|
||||
{}
|
||||
void operator()()
|
||||
{
|
||||
op1 = op2;
|
||||
}
|
||||
};
|
||||
template <typename t1, typename t2>
|
||||
assigner<t1,t2> assigno(t1 &a1, const t2 &a2)
|
||||
{
|
||||
return assigner<t1,t2>(a1,a2);
|
||||
}
|
||||
template <typename t1, typename t2, typename t3>
|
||||
bool equal(const t1 &a1, const t3 t1::* point, const t2 &a2)
|
||||
{
|
||||
return a1.*point == a2;
|
||||
}
|
||||
template <typename t1, typename t2>
|
||||
bool equal(const t1 &a1, const t2 &a2)
|
||||
{
|
||||
return a1 == a2;
|
||||
}
|
||||
}
|
||||
using vstd::operator-=;
|
||||
|
||||
#include "CConsoleHandler.h"
|
||||
extern DLL_EXPORT std::ostream *logfile;
|
||||
extern DLL_EXPORT CConsoleHandler *console;
|
||||
template <int lvl> class CLogger
|
||||
{
|
||||
public:
|
||||
CLogger<lvl>& operator<<(std::ostream& (*fun)(std::ostream&))
|
||||
{
|
||||
if(lvl < CONSOLE_LOGGING_LEVEL)
|
||||
std::cout << fun;
|
||||
if((lvl < FILE_LOGGING_LEVEL) && logfile)
|
||||
*logfile << fun;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
CLogger<lvl> & operator<<(const T & data)
|
||||
{
|
||||
if(lvl < CONSOLE_LOGGING_LEVEL)
|
||||
{
|
||||
if(console)
|
||||
{
|
||||
console->print(data,lvl);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << data << std::flush;
|
||||
}
|
||||
}
|
||||
if((lvl < FILE_LOGGING_LEVEL) && logfile)
|
||||
{
|
||||
*logfile << data << std::flush;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
extern DLL_EXPORT CLogger<0> tlog0; //green - standard progress info
|
||||
extern DLL_EXPORT CLogger<1> tlog1; //red - big errors
|
||||
extern DLL_EXPORT CLogger<2> tlog2; //magenta - major warnings
|
||||
extern DLL_EXPORT CLogger<3> tlog3; //yellow - minor warnings
|
||||
extern DLL_EXPORT CLogger<4> tlog4; //white - detailed log info
|
||||
extern DLL_EXPORT CLogger<5> tlog5; //gray - minor log info
|
||||
|
||||
//XXX pls dont - 'debug macros' are usually more trubble then its worth
|
||||
#define HANDLE_EXCEPTION \
|
||||
catch (const std::exception& e) { \
|
||||
tlog1 << e.what() << std::endl; \
|
||||
} \
|
||||
catch (const std::exception * e) \
|
||||
{ \
|
||||
tlog1 << e->what()<< std::endl; \
|
||||
delete e; \
|
||||
} \
|
||||
catch (const std::string& e) { \
|
||||
tlog1 << e << std::endl; \
|
||||
}
|
||||
|
||||
#define HANDLE_EXCEPTIONC(COMMAND) \
|
||||
catch (const std::exception& e) { \
|
||||
COMMAND; \
|
||||
tlog1 << e.what() << std::endl; \
|
||||
} \
|
||||
catch (const std::exception * e) \
|
||||
{ \
|
||||
COMMAND; \
|
||||
tlog1 << e->what()<< std::endl; \
|
||||
delete e; \
|
||||
}
|
||||
|
||||
#endif //GLOBAL_H
|
||||
#ifndef __GLOBAL_H__
|
||||
#define __GLOBAL_H__
|
||||
#include <iostream>
|
||||
#include <algorithm> //std::find
|
||||
#include <boost/logic/tribool.hpp>
|
||||
#include <boost/cstdint.hpp>
|
||||
typedef boost::uint64_t ui64; //unsigned int 64 bits (8 bytes)
|
||||
typedef boost::uint32_t ui32; //unsigned int 32 bits (4 bytes)
|
||||
typedef boost::uint16_t ui16; //unsigned int 16 bits (2 bytes)
|
||||
typedef boost::uint8_t ui8; //unsigned int 8 bits (1 byte)
|
||||
typedef boost::int64_t si64; //signed int 64 bits (8 bytes)
|
||||
typedef boost::int32_t si32; //signed int 32 bits (4 bytes)
|
||||
typedef boost::int16_t si16; //signed int 16 bits (2 bytes)
|
||||
typedef boost::int8_t si8; //signed int 8 bits (1 byte)
|
||||
#include "int3.h"
|
||||
#define CHECKTIME 1
|
||||
#if CHECKTIME
|
||||
#include "timeHandler.h"
|
||||
#define THC
|
||||
#endif
|
||||
|
||||
#define NAME_VER ("VCMI 0.65")
|
||||
#define CONSOLE_LOGGING_LEVEL 5
|
||||
#define FILE_LOGGING_LEVEL 6
|
||||
|
||||
#ifdef _WIN32
|
||||
#define PATHSEPARATOR "\\"
|
||||
#define DATA_DIR ""
|
||||
#define SERVER_NAME "VCMI_server.exe"
|
||||
#else
|
||||
#define PATHSEPARATOR "/"
|
||||
#define DATA_DIR ""
|
||||
#define SERVER_NAME "./vcmiserver"
|
||||
#endif
|
||||
|
||||
enum Ecolor {RED, BLUE, TAN, GREEN, ORANGE, PURPLE, TEAL, PINK}; //player's colors
|
||||
enum EterrainType {border=-1, dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock};
|
||||
enum Eriver {noRiver=0, clearRiver, icyRiver, muddyRiver, lavaRiver};
|
||||
enum Eroad {dirtRoad=1, grazvelRoad, cobblestoneRoad};
|
||||
enum Eformat { WoG=0x33, AB=0x15, RoE=0x0e, SoD=0x1c};
|
||||
enum EvictoryConditions {artifact, gatherTroop, gatherResource, buildCity, buildGrail, beatHero,
|
||||
captureCity, beatMonster, takeDwellings, takeMines, transportItem, winStandard=255};
|
||||
enum ElossCon {lossCastle, lossHero, timeExpires, lossStandard=255};
|
||||
enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HERO_ALCHEMIST, HERO_WIZARD,
|
||||
HERO_DEMONIAC, HERO_HERETIC, HERO_DEATHKNIGHT, HERO_NECROMANCER, HERO_WARLOCK, HERO_OVERLORD,
|
||||
HERO_BARBARIAN, HERO_BATTLEMAGE, HERO_BEASTMASTER, HERO_WITCH, HERO_PLANESWALKER, HERO_ELEMENTALIST};
|
||||
enum EAbilities {DOUBLE_WIDE, FLYING, SHOOTER, TWO_HEX_ATTACK, SIEGE_ABILITY, SIEGE_WEAPON,
|
||||
KING1, KING2, KING3, MIND_IMMUNITY, NO_OBSTACLE_PENALTY, NO_CLOSE_COMBAT_PENALTY,
|
||||
JOUSTING, FIRE_IMMUNITY, TWICE_ATTACK, NO_ENEMY_RETALIATION, NO_MORAL_PENALTY,
|
||||
UNDEAD, MULTI_HEAD_ATTACK, EXTENDED_RADIOUS_SHOOTER, GHOST, RAISES_MORALE,
|
||||
LOWERS_MORALE, DRAGON, STRIKE_AND_RETURN, FEARLESS, REBIRTH}; //some flags are used only for battles
|
||||
enum ECombatInfo{ALIVE = REBIRTH+1, SUMMONED, CLONED, HAD_MORALE, WAITING, MOVED, DEFENDING};
|
||||
class CGameInfo;
|
||||
extern CGameInfo* CGI;
|
||||
|
||||
#define HEROI_TYPE (34)
|
||||
#define TOWNI_TYPE (98)
|
||||
|
||||
const int F_NUMBER = 9; //factions (town types) quantity
|
||||
const int PLAYER_LIMIT = 8; //player limit per map
|
||||
const int HEROES_PER_TYPE=8; //amount of heroes of each type
|
||||
const int SKILL_QUANTITY=28;
|
||||
const int SKILL_PER_HERO=8;
|
||||
const int ARTIFACTS_QUANTITY=171;
|
||||
const int HEROES_QUANTITY=156;
|
||||
const int SPELLS_QUANTITY=70;
|
||||
const int RESOURCE_QUANTITY=8;
|
||||
const int TERRAIN_TYPES=10;
|
||||
const int PRIMARY_SKILLS=4;
|
||||
const int NEUTRAL_PLAYER=255;
|
||||
const int NAMES_PER_TOWN=16;
|
||||
const int CREATURES_PER_TOWN = 7; //without upgrades
|
||||
const int MAX_BUILDING_PER_TURN = 1;
|
||||
const int SPELL_LEVELS = 5;
|
||||
|
||||
#define BFIELD_WIDTH (17)
|
||||
#define BFIELD_HEIGHT (11)
|
||||
#define BFIELD_SIZE ((BFIELD_WIDTH) * (BFIELD_HEIGHT))
|
||||
|
||||
//uncomment to make it work
|
||||
//#define MARK_BLOCKED_POSITIONS
|
||||
//#define MARK_VISITABLE_POSITIONS
|
||||
|
||||
#define DEFBYPASS
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef VCMI_DLL
|
||||
#define DLL_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define DLL_EXPORT __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#if defined(__GNUC__) && __GNUC__ >= 4
|
||||
#define DLL_EXPORT __attribute__ ((visibility("default")))
|
||||
#else
|
||||
#define DLL_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
namespace vstd
|
||||
{
|
||||
template <typename Container, typename Item>
|
||||
bool contains(const Container & c, const Item &i)
|
||||
{
|
||||
return std::find(c.begin(),c.end(),i) != c.end();
|
||||
}
|
||||
template <typename V, typename Item, typename Item2>
|
||||
bool contains(const std::map<Item,V> & c, const Item2 &i)
|
||||
{
|
||||
return c.find(i)!=c.end();
|
||||
}
|
||||
template <typename Container1, typename Container2>
|
||||
typename Container2::iterator findFirstNot(Container1 &c1, Container2 &c2)//returns first element of c2 not present in c1
|
||||
{
|
||||
typename Container2::iterator itr = c2.begin();
|
||||
while(itr != c2.end())
|
||||
if(!contains(c1,*itr))
|
||||
return itr;
|
||||
else
|
||||
++itr;
|
||||
return c2.end();
|
||||
}
|
||||
template <typename Container, typename Item>
|
||||
typename Container::iterator find(const Container & c, const Item &i)
|
||||
{
|
||||
return std::find(c.begin(),c.end(),i);
|
||||
}
|
||||
template <typename T1, typename T2>
|
||||
int findPos(const std::vector<T1> & c, const T2 &s)
|
||||
{
|
||||
for(size_t i=0; i < c.size(); ++i)
|
||||
if(c[i] == s)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
template <typename T1, typename T2, typename Func>
|
||||
int findPos(const std::vector<T1> & c, const T2 &s, const Func &f) //Func(T1,T2) must say if these elements matches
|
||||
{
|
||||
for(size_t i=0; i < c.size(); ++i)
|
||||
if(f(c[i],s))
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
template <typename Container, typename Item>
|
||||
typename Container::iterator find(Container & c, const Item &i)
|
||||
{
|
||||
return std::find(c.begin(),c.end(),i);
|
||||
}
|
||||
template <typename Container, typename Item>
|
||||
bool operator-=(Container &c, const Item &i)
|
||||
{
|
||||
typename Container::iterator itr = find(c,i);
|
||||
if(itr == c.end())
|
||||
return false;
|
||||
c.erase(itr);
|
||||
return true;
|
||||
}
|
||||
template <typename t1>
|
||||
void delObj(t1 *a1)
|
||||
{
|
||||
delete a1;
|
||||
}
|
||||
template <typename t1, typename t2>
|
||||
void assign(t1 &a1, const t2 &a2)
|
||||
{
|
||||
a1 = a2;
|
||||
}
|
||||
template <typename t1, typename t2>
|
||||
struct assigner
|
||||
{
|
||||
public:
|
||||
t1 &op1;
|
||||
t2 op2;
|
||||
assigner(t1 &a1, t2 a2)
|
||||
:op1(a1), op2(a2)
|
||||
{}
|
||||
void operator()()
|
||||
{
|
||||
op1 = op2;
|
||||
}
|
||||
};
|
||||
template <typename t1, typename t2>
|
||||
assigner<t1,t2> assigno(t1 &a1, const t2 &a2)
|
||||
{
|
||||
return assigner<t1,t2>(a1,a2);
|
||||
}
|
||||
template <typename t1, typename t2, typename t3>
|
||||
bool equal(const t1 &a1, const t3 t1::* point, const t2 &a2)
|
||||
{
|
||||
return a1.*point == a2;
|
||||
}
|
||||
template <typename t1, typename t2>
|
||||
bool equal(const t1 &a1, const t2 &a2)
|
||||
{
|
||||
return a1 == a2;
|
||||
}
|
||||
}
|
||||
using vstd::operator-=;
|
||||
|
||||
#include "CConsoleHandler.h"
|
||||
extern DLL_EXPORT std::ostream *logfile;
|
||||
extern DLL_EXPORT CConsoleHandler *console;
|
||||
template <int lvl> class CLogger
|
||||
{
|
||||
public:
|
||||
CLogger<lvl>& operator<<(std::ostream& (*fun)(std::ostream&))
|
||||
{
|
||||
if(lvl < CONSOLE_LOGGING_LEVEL)
|
||||
std::cout << fun;
|
||||
if((lvl < FILE_LOGGING_LEVEL) && logfile)
|
||||
*logfile << fun;
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
CLogger<lvl> & operator<<(const T & data)
|
||||
{
|
||||
if(lvl < CONSOLE_LOGGING_LEVEL)
|
||||
{
|
||||
if(console)
|
||||
{
|
||||
console->print(data,lvl);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << data << std::flush;
|
||||
}
|
||||
}
|
||||
if((lvl < FILE_LOGGING_LEVEL) && logfile)
|
||||
{
|
||||
*logfile << data << std::flush;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
extern DLL_EXPORT CLogger<0> tlog0; //green - standard progress info
|
||||
extern DLL_EXPORT CLogger<1> tlog1; //red - big errors
|
||||
extern DLL_EXPORT CLogger<2> tlog2; //magenta - major warnings
|
||||
extern DLL_EXPORT CLogger<3> tlog3; //yellow - minor warnings
|
||||
extern DLL_EXPORT CLogger<4> tlog4; //white - detailed log info
|
||||
extern DLL_EXPORT CLogger<5> tlog5; //gray - minor log info
|
||||
|
||||
//XXX pls dont - 'debug macros' are usually more trubble then its worth
|
||||
#define HANDLE_EXCEPTION \
|
||||
catch (const std::exception& e) { \
|
||||
tlog1 << e.what() << std::endl; \
|
||||
} \
|
||||
catch (const std::exception * e) \
|
||||
{ \
|
||||
tlog1 << e->what()<< std::endl; \
|
||||
delete e; \
|
||||
} \
|
||||
catch (const std::string& e) { \
|
||||
tlog1 << e << std::endl; \
|
||||
}
|
||||
|
||||
#define HANDLE_EXCEPTIONC(COMMAND) \
|
||||
catch (const std::exception& e) { \
|
||||
COMMAND; \
|
||||
tlog1 << e.what() << std::endl; \
|
||||
} \
|
||||
catch (const std::exception * e) \
|
||||
{ \
|
||||
COMMAND; \
|
||||
tlog1 << e->what()<< std::endl; \
|
||||
delete e; \
|
||||
}
|
||||
|
||||
|
||||
#endif // __GLOBAL_H__
|
||||
|
@ -1,27 +1,28 @@
|
||||
#ifndef CABILITYHANDLER_H
|
||||
#define CABILITYHANDLER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class CDefHandler;
|
||||
|
||||
class CAbility
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
std::vector <std::string> infoTexts; //0 - basic; 2 - advanced
|
||||
int idNumber;
|
||||
bool isAllowed; //true if we can use this hero's ability (map information)
|
||||
};
|
||||
|
||||
class CAbilityHandler
|
||||
{
|
||||
public:
|
||||
std::vector<CAbility *> abilities;
|
||||
CDefHandler * abils32, * abils44, * abils82;
|
||||
std::vector<std::string> levels;
|
||||
void loadAbilities();
|
||||
};
|
||||
|
||||
#endif //CABILITYHANDLER_H
|
||||
#ifndef __CABILITYHANDLER_H__
|
||||
#define __CABILITYHANDLER_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class CDefHandler;
|
||||
|
||||
class CAbility
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
std::vector <std::string> infoTexts; //0 - basic; 2 - advanced
|
||||
int idNumber;
|
||||
bool isAllowed; //true if we can use this hero's ability (map information)
|
||||
};
|
||||
|
||||
class CAbilityHandler
|
||||
{
|
||||
public:
|
||||
std::vector<CAbility *> abilities;
|
||||
CDefHandler * abils32, * abils44, * abils82;
|
||||
std::vector<std::string> levels;
|
||||
void loadAbilities();
|
||||
};
|
||||
|
||||
|
||||
#endif // __CABILITYHANDLER_H__
|
||||
|
@ -1,19 +1,20 @@
|
||||
#ifndef CAMBARCENDAMO_H
|
||||
#define CAMBARCENDAMO_H
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../global.h"
|
||||
#include "../map.h"
|
||||
#include "CCreatureHandler.h"
|
||||
|
||||
class DLL_EXPORT CAmbarCendamo
|
||||
{
|
||||
public:
|
||||
/////////////////member variables
|
||||
//Mapa* map;
|
||||
|
||||
//CAmbarCendamo (unsigned char * data); // c-tor; data is pointer to decompressed h3m data
|
||||
//~CAmbarCendamo (); // d-tor
|
||||
};
|
||||
#endif //CAMBARCENDAMO_H
|
||||
#ifndef __CAMBARCENDAMO_H__
|
||||
#define __CAMBARCENDAMO_H__
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "../global.h"
|
||||
#include "../map.h"
|
||||
#include "CCreatureHandler.h"
|
||||
|
||||
class DLL_EXPORT CAmbarCendamo
|
||||
{
|
||||
public:
|
||||
/////////////////member variables
|
||||
//Mapa* map;
|
||||
|
||||
//CAmbarCendamo (unsigned char * data); // c-tor; data is pointer to decompressed h3m data
|
||||
//~CAmbarCendamo (); // d-tor
|
||||
};
|
||||
|
||||
#endif // __CAMBARCENDAMO_H__
|
||||
|
@ -1,49 +1,50 @@
|
||||
#ifndef CARTHANDLER_H
|
||||
#define CARTHANDLER_H
|
||||
#include "../global.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum EartClass {SartClass=0, TartClass, NartClass, JartClass, RartClass}; //artifact class (relict, treasure, strong, weak etc.)
|
||||
class CDefHandler;
|
||||
|
||||
class DLL_EXPORT CArtifact //container for artifacts
|
||||
{
|
||||
std::string name, description; //set if custom
|
||||
public:
|
||||
const std::string &Name() const;
|
||||
const std::string &Description() const;
|
||||
bool isAllowed; //true if we can use this artifact (map information)
|
||||
//std::string desc2;
|
||||
unsigned int price;
|
||||
std::vector<ui16> possibleSlots; //ids of slots where artifact can be placed
|
||||
//bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4, misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso, lHand, rHand, neck, shoulders, head;
|
||||
EartClass aClass;
|
||||
int id;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & isAllowed & name & description & price & possibleSlots & aClass & id ;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CArtHandler //handles artifacts
|
||||
{
|
||||
public:
|
||||
std::vector<CArtifact*> treasures, minors, majors, relics;
|
||||
std::vector<CArtifact> artifacts;
|
||||
|
||||
void loadArtifacts();
|
||||
void sortArts();
|
||||
static int convertMachineID(int id, bool creToArt);
|
||||
CArtHandler();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & artifacts;
|
||||
if(!h.saving)
|
||||
sortArts();
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CARTHANDLER_H
|
||||
#ifndef __CARTHANDLER_H__
|
||||
#define __CARTHANDLER_H__
|
||||
#include "../global.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
enum EartClass {SartClass=0, TartClass, NartClass, JartClass, RartClass}; //artifact class (relict, treasure, strong, weak etc.)
|
||||
class CDefHandler;
|
||||
|
||||
class DLL_EXPORT CArtifact //container for artifacts
|
||||
{
|
||||
std::string name, description; //set if custom
|
||||
public:
|
||||
const std::string &Name() const;
|
||||
const std::string &Description() const;
|
||||
bool isAllowed; //true if we can use this artifact (map information)
|
||||
//std::string desc2;
|
||||
unsigned int price;
|
||||
std::vector<ui16> possibleSlots; //ids of slots where artifact can be placed
|
||||
//bool spellBook, warMachine1, warMachine2, warMachine3, warMachine4, misc1, misc2, misc3, misc4, misc5, feet, lRing, rRing, torso, lHand, rHand, neck, shoulders, head;
|
||||
EartClass aClass;
|
||||
int id;
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & isAllowed & name & description & price & possibleSlots & aClass & id ;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CArtHandler //handles artifacts
|
||||
{
|
||||
public:
|
||||
std::vector<CArtifact*> treasures, minors, majors, relics;
|
||||
std::vector<CArtifact> artifacts;
|
||||
|
||||
void loadArtifacts();
|
||||
void sortArts();
|
||||
static int convertMachineID(int id, bool creToArt);
|
||||
CArtHandler();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & artifacts;
|
||||
if(!h.saving)
|
||||
sortArts();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // __CARTHANDLER_H__
|
||||
|
@ -1,38 +1,39 @@
|
||||
#ifndef CBUILDINGHANDLER_H
|
||||
#define CBUILDINGHANDLER_H
|
||||
#include "../global.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
//enum EbuildingType {NEUTRAL=-1, CASTLE, RAMPART, TOWER, INFERNO, NECROPOLIS, DUNGEON, STRONGHOLD, FORTRESS, CONFLUX};
|
||||
class DLL_EXPORT CBuilding //a typical building encountered in every castle ;]
|
||||
{
|
||||
public:
|
||||
int tid, bid; //town ID and structure ID
|
||||
std::vector<int> resources;
|
||||
std::string name;
|
||||
std::string description;
|
||||
|
||||
const std::string &Name();
|
||||
const std::string &Description();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & tid & bid & resources & name & description;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CBuildingHandler
|
||||
{
|
||||
public:
|
||||
std::map<int, std::map<int, CBuilding*> > buildings; ///< first int is the castle ID, second the building ID (in ERM-U format)
|
||||
std::map<int, std::pair<std::string,std::vector< std::vector< std::vector<int> > > > > hall; //map<castle ID, pair<hall bg name, std::vector< std::vector<building id> >[5]> - external vector is the vector of buildings in the row, internal is the list of buildings for the specific slot
|
||||
|
||||
void loadBuildings(); //main loader
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & buildings & hall;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //CBUILDINGHANDLER_H
|
||||
#ifndef __CBUILDINGHANDLER_H__
|
||||
#define __CBUILDINGHANDLER_H__
|
||||
#include "../global.h"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
//enum EbuildingType {NEUTRAL=-1, CASTLE, RAMPART, TOWER, INFERNO, NECROPOLIS, DUNGEON, STRONGHOLD, FORTRESS, CONFLUX};
|
||||
class DLL_EXPORT CBuilding //a typical building encountered in every castle ;]
|
||||
{
|
||||
public:
|
||||
int tid, bid; //town ID and structure ID
|
||||
std::vector<int> resources;
|
||||
std::string name;
|
||||
std::string description;
|
||||
|
||||
const std::string &Name();
|
||||
const std::string &Description();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & tid & bid & resources & name & description;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CBuildingHandler
|
||||
{
|
||||
public:
|
||||
std::map<int, std::map<int, CBuilding*> > buildings; ///< first int is the castle ID, second the building ID (in ERM-U format)
|
||||
std::map<int, std::pair<std::string,std::vector< std::vector< std::vector<int> > > > > hall; //map<castle ID, pair<hall bg name, std::vector< std::vector<building id> >[5]> - external vector is the vector of buildings in the row, internal is the list of buildings for the specific slot
|
||||
|
||||
void loadBuildings(); //main loader
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & buildings & hall;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // __CBUILDINGHANDLER_H__
|
||||
|
@ -1,85 +1,86 @@
|
||||
#ifndef CCREATUREHANDLER_H
|
||||
#define CCREATUREHANDLER_H
|
||||
#include "../global.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
class CLodHandler;
|
||||
|
||||
class DLL_EXPORT CCreature
|
||||
{
|
||||
public:
|
||||
std::string namePl, nameSing, nameRef; //name in singular and plural form; and reference name
|
||||
std::vector<ui32> cost; //cost[res_id] - amount of that resource
|
||||
std::set<ui32> upgrades; // IDs of creatures to which this creature can be upgraded
|
||||
ui32 fightValue, AIValue, growth, hordeGrowth, hitPoints, speed, attack, defence, shots, spells;
|
||||
ui32 damageMin, damageMax;
|
||||
ui32 ammMin, ammMax;
|
||||
ui8 level; // 0 - unknown
|
||||
std::string abilityText; //description of abilities
|
||||
std::string abilityRefs; //references to abilities, in textformat
|
||||
std::string animDefName;
|
||||
ui32 idNumber;
|
||||
std::set<EAbilities> abilities;
|
||||
si8 faction; //-1 = neutral
|
||||
|
||||
///animation info
|
||||
float timeBetweenFidgets, walkAnimationTime, attackAnimationTime, flightAnimationDistance;
|
||||
int upperRightMissleOffsetX, rightMissleOffsetX, lowerRightMissleOffsetX, upperRightMissleOffsetY, rightMissleOffsetY, lowerRightMissleOffsetY;
|
||||
float missleFrameAngles[12];
|
||||
int troopCountLocationOffset, attackClimaxFrame;
|
||||
///end of anim info
|
||||
|
||||
bool isDoubleWide() const; //returns true if unit is double wide on battlefield
|
||||
bool isFlying() const; //returns true if it is a flying unit
|
||||
bool isShooting() const; //returns true if unit can shoot
|
||||
si32 maxAmount(const std::vector<si32> &res) const; //how many creatures can be bought
|
||||
static int getQuantityID(const int & quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & namePl & nameSing & nameRef
|
||||
& cost & upgrades
|
||||
& fightValue & AIValue & growth & hordeGrowth & hitPoints & speed & attack & defence & shots & spells
|
||||
& damageMin & damageMax & ammMin & ammMax & level
|
||||
& abilityText & abilityRefs & animDefName
|
||||
& idNumber & abilities & faction
|
||||
|
||||
& timeBetweenFidgets & walkAnimationTime & attackAnimationTime & flightAnimationDistance
|
||||
& upperRightMissleOffsetX & rightMissleOffsetX & lowerRightMissleOffsetX & upperRightMissleOffsetY & rightMissleOffsetY & lowerRightMissleOffsetY
|
||||
& missleFrameAngles & troopCountLocationOffset & attackClimaxFrame;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class DLL_EXPORT CCreatureHandler
|
||||
{
|
||||
public:
|
||||
std::set<int> notUsedMonsters;
|
||||
std::vector<CCreature> creatures; //creature ID -> creature info
|
||||
std::map<int,std::vector<CCreature*> > levelCreatures; //level -> list of creatures
|
||||
std::map<std::string,int> nameToID;
|
||||
std::map<int,std::string> idToProjectile;
|
||||
std::map<int,bool> idToProjectileSpin; //if true, appropriate projectile is spinning during flight
|
||||
void loadCreatures();
|
||||
void loadAnimationInfo();
|
||||
void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);
|
||||
CCreatureHandler();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
//TODO: should be optimized, not all these informations needs to be serialized (same for ccreature)
|
||||
h & notUsedMonsters & creatures & nameToID & idToProjectile & idToProjectileSpin;
|
||||
|
||||
if(!h.saving)
|
||||
{
|
||||
for (int i=0; i<creatures.size(); i++) //recreate levelCreatures map
|
||||
{
|
||||
levelCreatures[creatures[i].level].push_back(&creatures[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif //CCREATUREHANDLER_H
|
||||
#ifndef __CCREATUREHANDLER_H__
|
||||
#define __CCREATUREHANDLER_H__
|
||||
#include "../global.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
class CLodHandler;
|
||||
|
||||
class DLL_EXPORT CCreature
|
||||
{
|
||||
public:
|
||||
std::string namePl, nameSing, nameRef; //name in singular and plural form; and reference name
|
||||
std::vector<ui32> cost; //cost[res_id] - amount of that resource
|
||||
std::set<ui32> upgrades; // IDs of creatures to which this creature can be upgraded
|
||||
ui32 fightValue, AIValue, growth, hordeGrowth, hitPoints, speed, attack, defence, shots, spells;
|
||||
ui32 damageMin, damageMax;
|
||||
ui32 ammMin, ammMax;
|
||||
ui8 level; // 0 - unknown
|
||||
std::string abilityText; //description of abilities
|
||||
std::string abilityRefs; //references to abilities, in textformat
|
||||
std::string animDefName;
|
||||
ui32 idNumber;
|
||||
std::set<EAbilities> abilities;
|
||||
si8 faction; //-1 = neutral
|
||||
|
||||
///animation info
|
||||
float timeBetweenFidgets, walkAnimationTime, attackAnimationTime, flightAnimationDistance;
|
||||
int upperRightMissleOffsetX, rightMissleOffsetX, lowerRightMissleOffsetX, upperRightMissleOffsetY, rightMissleOffsetY, lowerRightMissleOffsetY;
|
||||
float missleFrameAngles[12];
|
||||
int troopCountLocationOffset, attackClimaxFrame;
|
||||
///end of anim info
|
||||
|
||||
bool isDoubleWide() const; //returns true if unit is double wide on battlefield
|
||||
bool isFlying() const; //returns true if it is a flying unit
|
||||
bool isShooting() const; //returns true if unit can shoot
|
||||
si32 maxAmount(const std::vector<si32> &res) const; //how many creatures can be bought
|
||||
static int getQuantityID(const int & quantity); //0 - a few, 1 - several, 2 - pack, 3 - lots, 4 - horde, 5 - throng, 6 - swarm, 7 - zounds, 8 - legion
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & namePl & nameSing & nameRef
|
||||
& cost & upgrades
|
||||
& fightValue & AIValue & growth & hordeGrowth & hitPoints & speed & attack & defence & shots & spells
|
||||
& damageMin & damageMax & ammMin & ammMax & level
|
||||
& abilityText & abilityRefs & animDefName
|
||||
& idNumber & abilities & faction
|
||||
|
||||
& timeBetweenFidgets & walkAnimationTime & attackAnimationTime & flightAnimationDistance
|
||||
& upperRightMissleOffsetX & rightMissleOffsetX & lowerRightMissleOffsetX & upperRightMissleOffsetY & rightMissleOffsetY & lowerRightMissleOffsetY
|
||||
& missleFrameAngles & troopCountLocationOffset & attackClimaxFrame;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class DLL_EXPORT CCreatureHandler
|
||||
{
|
||||
public:
|
||||
std::set<int> notUsedMonsters;
|
||||
std::vector<CCreature> creatures; //creature ID -> creature info
|
||||
std::map<int,std::vector<CCreature*> > levelCreatures; //level -> list of creatures
|
||||
std::map<std::string,int> nameToID;
|
||||
std::map<int,std::string> idToProjectile;
|
||||
std::map<int,bool> idToProjectileSpin; //if true, appropriate projectile is spinning during flight
|
||||
void loadCreatures();
|
||||
void loadAnimationInfo();
|
||||
void loadUnitAnimInfo(CCreature & unit, std::string & src, int & i);
|
||||
CCreatureHandler();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
//TODO: should be optimized, not all these informations needs to be serialized (same for ccreature)
|
||||
h & notUsedMonsters & creatures & nameToID & idToProjectile & idToProjectileSpin;
|
||||
|
||||
if(!h.saving)
|
||||
{
|
||||
for (int i=0; i<creatures.size(); i++) //recreate levelCreatures map
|
||||
{
|
||||
levelCreatures[creatures[i].level].push_back(&creatures[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __CCREATUREHANDLER_H__
|
||||
|
@ -1,60 +1,61 @@
|
||||
#ifndef CDEFHANDLER_H
|
||||
#define CDEFHANDLER_H
|
||||
#include "../client/CBitmapHandler.h"
|
||||
struct SDL_Surface;
|
||||
class CDefEssential;
|
||||
class CLodHandler;
|
||||
|
||||
struct Cimage
|
||||
{
|
||||
int groupNumber;
|
||||
std::string imName; //name without extension
|
||||
SDL_Surface * bitmap;
|
||||
};
|
||||
|
||||
class CDefHandler
|
||||
{
|
||||
private:
|
||||
int totalEntries, DEFType, totalBlocks;
|
||||
bool allowRepaint;
|
||||
int length;
|
||||
unsigned int * RWEntries;
|
||||
struct SEntry
|
||||
{
|
||||
std::string name;
|
||||
int offset;
|
||||
int group;
|
||||
} ;
|
||||
std::vector<SEntry> SEntries ;
|
||||
|
||||
public:
|
||||
int width, height; //width and height
|
||||
static CLodHandler * Spriteh;
|
||||
std::string defName, curDir;
|
||||
std::vector<Cimage> ourImages;
|
||||
bool alphaTransformed;
|
||||
bool notFreeImgs;
|
||||
|
||||
CDefHandler();
|
||||
~CDefHandler();
|
||||
static void print (std::ostream & stream, int nr, int bytcon);
|
||||
int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false);
|
||||
static unsigned char *writeNormalNr (int nr, int bytCon);
|
||||
SDL_Surface * getSprite (int SIndex, unsigned char * FDef, BMPPalette * palette); //zapisuje klatke o zadanym numerze do "testtt.bmp"
|
||||
void openDef(std::string name);
|
||||
void expand(unsigned char N,unsigned char & BL, unsigned char & BR);
|
||||
void openFromMemory(unsigned char * table, std::string name);
|
||||
CDefEssential * essentialize();
|
||||
|
||||
static CDefHandler * giveDef(std::string defName, CLodHandler * spriteh=NULL);
|
||||
static CDefEssential * giveDefEss(std::string defName, CLodHandler * spriteh=NULL);
|
||||
};
|
||||
|
||||
class CDefEssential //DefHandler with images only
|
||||
{
|
||||
public:
|
||||
std::vector<Cimage> ourImages;
|
||||
~CDefEssential();
|
||||
};
|
||||
|
||||
#endif // CDEFHANDLER_H
|
||||
#ifndef __CDEFHANDLER_H__
|
||||
#define __CDEFHANDLER_H__
|
||||
#include "../client/CBitmapHandler.h"
|
||||
struct SDL_Surface;
|
||||
class CDefEssential;
|
||||
class CLodHandler;
|
||||
|
||||
struct Cimage
|
||||
{
|
||||
int groupNumber;
|
||||
std::string imName; //name without extension
|
||||
SDL_Surface * bitmap;
|
||||
};
|
||||
|
||||
class CDefHandler
|
||||
{
|
||||
private:
|
||||
int totalEntries, DEFType, totalBlocks;
|
||||
bool allowRepaint;
|
||||
int length;
|
||||
unsigned int * RWEntries;
|
||||
struct SEntry
|
||||
{
|
||||
std::string name;
|
||||
int offset;
|
||||
int group;
|
||||
} ;
|
||||
std::vector<SEntry> SEntries ;
|
||||
|
||||
public:
|
||||
int width, height; //width and height
|
||||
static CLodHandler * Spriteh;
|
||||
std::string defName, curDir;
|
||||
std::vector<Cimage> ourImages;
|
||||
bool alphaTransformed;
|
||||
bool notFreeImgs;
|
||||
|
||||
CDefHandler();
|
||||
~CDefHandler();
|
||||
static void print (std::ostream & stream, int nr, int bytcon);
|
||||
int readNormalNr (int pos, int bytCon, unsigned char * str=NULL, bool cyclic=false);
|
||||
static unsigned char *writeNormalNr (int nr, int bytCon);
|
||||
SDL_Surface * getSprite (int SIndex, unsigned char * FDef, BMPPalette * palette); //zapisuje klatke o zadanym numerze do "testtt.bmp"
|
||||
void openDef(std::string name);
|
||||
void expand(unsigned char N,unsigned char & BL, unsigned char & BR);
|
||||
void openFromMemory(unsigned char * table, std::string name);
|
||||
CDefEssential * essentialize();
|
||||
|
||||
static CDefHandler * giveDef(std::string defName, CLodHandler * spriteh=NULL);
|
||||
static CDefEssential * giveDefEss(std::string defName, CLodHandler * spriteh=NULL);
|
||||
};
|
||||
|
||||
class CDefEssential //DefHandler with images only
|
||||
{
|
||||
public:
|
||||
std::vector<Cimage> ourImages;
|
||||
~CDefEssential();
|
||||
};
|
||||
|
||||
|
||||
#endif // __CDEFHANDLER_H__
|
||||
|
@ -1,49 +1,50 @@
|
||||
#ifndef CGENERALTEXTHANDLER_H
|
||||
#define CGENERALTEXTHANDLER_H
|
||||
#include "../global.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
|
||||
std::string readTo(std::string &in, unsigned int &it, char end);
|
||||
class DLL_EXPORT CGeneralTextHandler //Handles general texts
|
||||
{
|
||||
public:
|
||||
class HeroTexts
|
||||
{
|
||||
public:
|
||||
std::string bonusName, shortBonus, longBonus; //for special abilities
|
||||
std::string biography; //biography, of course
|
||||
};
|
||||
|
||||
std::vector<HeroTexts> hTxts;
|
||||
std::vector<std::string> allTexts;
|
||||
|
||||
std::vector<std::string> arraytxt;
|
||||
std::vector<std::string> primarySkillNames;
|
||||
std::vector<std::string> jktexts;
|
||||
std::vector<std::string> heroscrn;
|
||||
|
||||
//artifacts
|
||||
std::vector<std::string> artifEvents;
|
||||
std::vector<std::string> artifNames;
|
||||
std::vector<std::string> artifDescriptions;
|
||||
|
||||
//towns
|
||||
std::vector<std::string> tcommands, hcommands; //texts for town screen and town hall screen
|
||||
std::vector<std::vector<std::string> > townNames; //[type id] => vec of names of instances
|
||||
std::vector<std::string> townTypes; //castle, rampart, tower, etc
|
||||
std::map<int, std::map<int, std::pair<std::string, std::string> > > buildings; //map[town id][building id] => pair<name, description>
|
||||
|
||||
std::vector<std::pair<std::string,std::string> > zelp;
|
||||
std::string lossCondtions[4];
|
||||
std::string victoryConditions[14];
|
||||
|
||||
std::string getTitle(std::string text);
|
||||
std::string getDescr(std::string text);
|
||||
|
||||
void loadTexts();
|
||||
void load();
|
||||
};
|
||||
|
||||
|
||||
#endif //CGENERALTEXTHANDLER_H
|
||||
#ifndef __CGENERALTEXTHANDLER_H__
|
||||
#define __CGENERALTEXTHANDLER_H__
|
||||
#include "../global.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
|
||||
std::string readTo(std::string &in, unsigned int &it, char end);
|
||||
class DLL_EXPORT CGeneralTextHandler //Handles general texts
|
||||
{
|
||||
public:
|
||||
class HeroTexts
|
||||
{
|
||||
public:
|
||||
std::string bonusName, shortBonus, longBonus; //for special abilities
|
||||
std::string biography; //biography, of course
|
||||
};
|
||||
|
||||
std::vector<HeroTexts> hTxts;
|
||||
std::vector<std::string> allTexts;
|
||||
|
||||
std::vector<std::string> arraytxt;
|
||||
std::vector<std::string> primarySkillNames;
|
||||
std::vector<std::string> jktexts;
|
||||
std::vector<std::string> heroscrn;
|
||||
|
||||
//artifacts
|
||||
std::vector<std::string> artifEvents;
|
||||
std::vector<std::string> artifNames;
|
||||
std::vector<std::string> artifDescriptions;
|
||||
|
||||
//towns
|
||||
std::vector<std::string> tcommands, hcommands; //texts for town screen and town hall screen
|
||||
std::vector<std::vector<std::string> > townNames; //[type id] => vec of names of instances
|
||||
std::vector<std::string> townTypes; //castle, rampart, tower, etc
|
||||
std::map<int, std::map<int, std::pair<std::string, std::string> > > buildings; //map[town id][building id] => pair<name, description>
|
||||
|
||||
std::vector<std::pair<std::string,std::string> > zelp;
|
||||
std::string lossCondtions[4];
|
||||
std::string victoryConditions[14];
|
||||
|
||||
std::string getTitle(std::string text);
|
||||
std::string getDescr(std::string text);
|
||||
|
||||
void loadTexts();
|
||||
void load();
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // __CGENERALTEXTHANDLER_H__
|
||||
|
@ -1,82 +1,83 @@
|
||||
#ifndef CHEROHANDLER_H
|
||||
#define CHEROHANDLER_H
|
||||
#include "../global.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
class CHeroClass;
|
||||
class CDefHandler;
|
||||
class CGameInfo;
|
||||
class CGHeroInstance;
|
||||
class DLL_EXPORT CHero
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
int ID;
|
||||
int lowStack[3], highStack[3]; //amount of units; described below
|
||||
std::string refTypeStack[3]; //reference names of units appearing in hero's army if he is recruited in tavern
|
||||
CHeroClass * heroClass;
|
||||
EHeroClasses heroType; //hero class
|
||||
std::vector<std::pair<ui8,ui8> > secSkillsInit; //initial secondary skills; first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert)
|
||||
//bool operator<(CHero& drugi){if (ID < drugi.ID) return true; else return false;}
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & name & ID & lowStack & highStack & refTypeStack & heroType & ID;
|
||||
//hero class pointer is restored by herohandler
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CHeroClass
|
||||
{
|
||||
public:
|
||||
ui32 skillLimit; //how many secondary skills can hero learn
|
||||
std::string name;
|
||||
float aggression;
|
||||
int initialAttack, initialDefence, initialPower, initialKnowledge;
|
||||
std::vector<std::pair<int,int> > primChance;//primChance[PRIMARY_SKILL_ID] - first is for levels 2 - 9, second for 10+;;; probability (%) of getting point of primary skill when getting new level
|
||||
std::vector<int> proSec; //probabilities of gaining secondary skills (out of 112), in id order
|
||||
int selectionProbability[9]; //probability of selection in towns
|
||||
std::vector<int> terrCosts; //default costs of going through terrains: dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock; -1 means terrain is imapassable
|
||||
CDefHandler * moveAnim; //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
|
||||
|
||||
int chooseSecSkill(const std::set<int> & possibles) const; //picks secondary skill out from given possibilities
|
||||
CHeroClass();
|
||||
~CHeroClass();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & skillLimit & name & aggression & initialAttack & initialDefence & initialPower & initialKnowledge & primChance
|
||||
& proSec & selectionProbability & terrCosts;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CHeroHandler
|
||||
{
|
||||
public:
|
||||
std::vector<CHero*> heroes; //by³o nodrze
|
||||
std::vector<CHeroClass *> heroClasses;
|
||||
std::vector<int> expPerLevel; //expPerLEvel[i] is amount of exp needed to reach level i; if it is not in this vector, multiplicate last value by 1,2 to get next value
|
||||
|
||||
unsigned int level(unsigned int experience);
|
||||
unsigned int reqExp(unsigned int level);
|
||||
void loadHeroes();
|
||||
void loadHeroClasses();
|
||||
void initHeroClasses();
|
||||
~CHeroHandler();
|
||||
void initTerrainCosts();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & heroClasses & heroes & expPerLevel;
|
||||
if(!h.saving)
|
||||
{
|
||||
//restore class pointers
|
||||
for (int i=0; i<heroes.size(); i++)
|
||||
{
|
||||
heroes[i]->heroClass = heroClasses[heroes[i]->heroType];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif //CHEROHANDLER_H
|
||||
#ifndef __CHEROHANDLER_H__
|
||||
#define __CHEROHANDLER_H__
|
||||
#include "../global.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
class CHeroClass;
|
||||
class CDefHandler;
|
||||
class CGameInfo;
|
||||
class CGHeroInstance;
|
||||
class DLL_EXPORT CHero
|
||||
{
|
||||
public:
|
||||
std::string name;
|
||||
int ID;
|
||||
int lowStack[3], highStack[3]; //amount of units; described below
|
||||
std::string refTypeStack[3]; //reference names of units appearing in hero's army if he is recruited in tavern
|
||||
CHeroClass * heroClass;
|
||||
EHeroClasses heroType; //hero class
|
||||
std::vector<std::pair<ui8,ui8> > secSkillsInit; //initial secondary skills; first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert)
|
||||
//bool operator<(CHero& drugi){if (ID < drugi.ID) return true; else return false;}
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & name & ID & lowStack & highStack & refTypeStack & heroType & ID;
|
||||
//hero class pointer is restored by herohandler
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CHeroClass
|
||||
{
|
||||
public:
|
||||
ui32 skillLimit; //how many secondary skills can hero learn
|
||||
std::string name;
|
||||
float aggression;
|
||||
int initialAttack, initialDefence, initialPower, initialKnowledge;
|
||||
std::vector<std::pair<int,int> > primChance;//primChance[PRIMARY_SKILL_ID] - first is for levels 2 - 9, second for 10+;;; probability (%) of getting point of primary skill when getting new level
|
||||
std::vector<int> proSec; //probabilities of gaining secondary skills (out of 112), in id order
|
||||
int selectionProbability[9]; //probability of selection in towns
|
||||
std::vector<int> terrCosts; //default costs of going through terrains: dirt, sand, grass, snow, swamp, rough, subterranean, lava, water, rock; -1 means terrain is imapassable
|
||||
CDefHandler * moveAnim; //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
|
||||
|
||||
int chooseSecSkill(const std::set<int> & possibles) const; //picks secondary skill out from given possibilities
|
||||
CHeroClass();
|
||||
~CHeroClass();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & skillLimit & name & aggression & initialAttack & initialDefence & initialPower & initialKnowledge & primChance
|
||||
& proSec & selectionProbability & terrCosts;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CHeroHandler
|
||||
{
|
||||
public:
|
||||
std::vector<CHero*> heroes; //by³o nodrze
|
||||
std::vector<CHeroClass *> heroClasses;
|
||||
std::vector<int> expPerLevel; //expPerLEvel[i] is amount of exp needed to reach level i; if it is not in this vector, multiplicate last value by 1,2 to get next value
|
||||
|
||||
unsigned int level(unsigned int experience);
|
||||
unsigned int reqExp(unsigned int level);
|
||||
void loadHeroes();
|
||||
void loadHeroClasses();
|
||||
void initHeroClasses();
|
||||
~CHeroHandler();
|
||||
void initTerrainCosts();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & heroClasses & heroes & expPerLevel;
|
||||
if(!h.saving)
|
||||
{
|
||||
//restore class pointers
|
||||
for (int i=0; i<heroes.size(); i++)
|
||||
{
|
||||
heroes[i]->heroClass = heroClasses[heroes[i]->heroType];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif // __CHEROHANDLER_H__
|
||||
|
@ -1,61 +1,62 @@
|
||||
#ifndef CLODHANDLER_H
|
||||
#define CLODHANDLER_H
|
||||
#include "../global.h"
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "../nodrze.h"
|
||||
|
||||
struct SDL_Surface;
|
||||
class CDefHandler;
|
||||
class CDefEssential;
|
||||
namespace boost
|
||||
{class mutex;};
|
||||
namespace NLoadHandlerHelp
|
||||
{
|
||||
const int dmHelp=0, dmNoExtractingMask=1;
|
||||
//std::string P1,P2,CurDir;
|
||||
const int fCHUNK = 50000;
|
||||
};
|
||||
|
||||
struct Entry
|
||||
{
|
||||
unsigned char name[12], //filename
|
||||
hlam_1[4], //???
|
||||
hlam_2[4]; //probably type of file
|
||||
std::string nameStr;
|
||||
int offset, //from beginning
|
||||
realSize, //size without compression
|
||||
size; //and with
|
||||
bool operator<(const std::string & comp) const
|
||||
{
|
||||
return nameStr<comp;
|
||||
}
|
||||
bool operator<(const Entry & comp) const
|
||||
{
|
||||
return nameStr<comp.nameStr;
|
||||
}
|
||||
Entry(std::string con): nameStr(con){};
|
||||
//Entry(unsigned char ): nameStr(con){};
|
||||
Entry(){};
|
||||
};
|
||||
class DLL_EXPORT CLodHandler
|
||||
{
|
||||
public:
|
||||
FILE* FLOD;
|
||||
nodrze<Entry> entries;
|
||||
unsigned int totalFiles;
|
||||
boost::mutex *mutex;
|
||||
std::string myDir; //load files from this dir instead of .lod file
|
||||
|
||||
int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper
|
||||
int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler
|
||||
int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
|
||||
unsigned char * giveFile(std::string defName, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed!
|
||||
std::string getTextFile(std::string name); //extracts one file
|
||||
void extract(std::string FName);
|
||||
void extractFile(std::string FName, std::string name); //extracts a specific file
|
||||
void init(std::string lodFile, std::string dirName);
|
||||
};
|
||||
|
||||
#endif //CLODHANDLER_H
|
||||
#ifndef __CLODHANDLER_H__
|
||||
#define __CLODHANDLER_H__
|
||||
#include "../global.h"
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "../nodrze.h"
|
||||
|
||||
struct SDL_Surface;
|
||||
class CDefHandler;
|
||||
class CDefEssential;
|
||||
namespace boost
|
||||
{class mutex;};
|
||||
namespace NLoadHandlerHelp
|
||||
{
|
||||
const int dmHelp=0, dmNoExtractingMask=1;
|
||||
//std::string P1,P2,CurDir;
|
||||
const int fCHUNK = 50000;
|
||||
};
|
||||
|
||||
struct Entry
|
||||
{
|
||||
unsigned char name[12], //filename
|
||||
hlam_1[4], //???
|
||||
hlam_2[4]; //probably type of file
|
||||
std::string nameStr;
|
||||
int offset, //from beginning
|
||||
realSize, //size without compression
|
||||
size; //and with
|
||||
bool operator<(const std::string & comp) const
|
||||
{
|
||||
return nameStr<comp;
|
||||
}
|
||||
bool operator<(const Entry & comp) const
|
||||
{
|
||||
return nameStr<comp.nameStr;
|
||||
}
|
||||
Entry(std::string con): nameStr(con){};
|
||||
//Entry(unsigned char ): nameStr(con){};
|
||||
Entry(){};
|
||||
};
|
||||
class DLL_EXPORT CLodHandler
|
||||
{
|
||||
public:
|
||||
FILE* FLOD;
|
||||
nodrze<Entry> entries;
|
||||
unsigned int totalFiles;
|
||||
boost::mutex *mutex;
|
||||
std::string myDir; //load files from this dir instead of .lod file
|
||||
|
||||
int readNormalNr (unsigned char* bufor, int bytCon, bool cyclic=false); //lod header reading helper
|
||||
int infs(unsigned char * in, int size, int realSize, std::ofstream & out, int wBits=15); //zlib fast handler
|
||||
int infs2(unsigned char * in, int size, int realSize, unsigned char*& out, int wBits=15); //zlib fast handler
|
||||
unsigned char * giveFile(std::string defName, int * length=NULL); //returns pointer to the decompressed data - it must be deleted when no longer needed!
|
||||
std::string getTextFile(std::string name); //extracts one file
|
||||
void extract(std::string FName);
|
||||
void extractFile(std::string FName, std::string name); //extracts a specific file
|
||||
void init(std::string lodFile, std::string dirName);
|
||||
};
|
||||
|
||||
|
||||
#endif // __CLODHANDLER_H__
|
||||
|
@ -1,20 +1,21 @@
|
||||
#ifndef CMUSICHANDLER_H
|
||||
#define CMUSICHANDLER_H
|
||||
|
||||
#include <SDL_mixer.h>
|
||||
#include "CSndHandler.h"
|
||||
|
||||
class CMusicHandler
|
||||
{
|
||||
protected:
|
||||
CSndHandler *sndh;
|
||||
public:
|
||||
Mix_Music *AITheme0, *AITheme1, *AITheme2, *combat1, *combat2, *combat3, *combat4, *castleTown, *defendCastle, *dirt, *dungeon, *elemTown, *evilTheme, *fortressTown, *goodTheme, *grass, *infernoTown, *lava, *loopLepr, *loseCampain, *loseCastle, *loseCombat, *mainMenu, *mainMenuWoG, *necroTown, *neutralTheme, *rampart, *retreatBattle, *rough, *sand, *secretTheme, *snow, *stronghold, *surrenderBattle, *swamp, *towerTown, *ultimateLose, *underground, *water, *winScenario, *winBattle;
|
||||
Mix_Chunk * buildTown, *click;
|
||||
void initMusics();
|
||||
void playClick(); //plays click music ;]
|
||||
void playLodSnd(std::string sndname); // plays sound wavs from Heroes3.snd
|
||||
};
|
||||
|
||||
|
||||
#endif //CMUSICHANDLER_H
|
||||
#ifndef __CMUSICHANDLER_H__
|
||||
#define __CMUSICHANDLER_H__
|
||||
|
||||
#include <SDL_mixer.h>
|
||||
#include "CSndHandler.h"
|
||||
|
||||
class CMusicHandler
|
||||
{
|
||||
protected:
|
||||
CSndHandler *sndh;
|
||||
public:
|
||||
Mix_Music *AITheme0, *AITheme1, *AITheme2, *combat1, *combat2, *combat3, *combat4, *castleTown, *defendCastle, *dirt, *dungeon, *elemTown, *evilTheme, *fortressTown, *goodTheme, *grass, *infernoTown, *lava, *loopLepr, *loseCampain, *loseCastle, *loseCombat, *mainMenu, *mainMenuWoG, *necroTown, *neutralTheme, *rampart, *retreatBattle, *rough, *sand, *secretTheme, *snow, *stronghold, *surrenderBattle, *swamp, *towerTown, *ultimateLose, *underground, *water, *winScenario, *winBattle;
|
||||
Mix_Chunk * buildTown, *click;
|
||||
void initMusics();
|
||||
void playClick(); //plays click music ;]
|
||||
void playLodSnd(std::string sndname); // plays sound wavs from Heroes3.snd
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // __CMUSICHANDLER_H__
|
||||
|
@ -1,438 +1,439 @@
|
||||
#ifndef COBJECTHANDLER_H
|
||||
#define COBJECTHANDLER_H
|
||||
#include "../global.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include "CCreatureHandler.h"
|
||||
|
||||
using boost::logic::tribool;
|
||||
class IGameCallback;
|
||||
struct BattleResult;
|
||||
class CCPPObjectScript;
|
||||
class CGObjectInstance;
|
||||
class CScript;
|
||||
class CObjectScript;
|
||||
class CGHeroInstance;
|
||||
class CTown;
|
||||
class CHero;
|
||||
class CBuilding;
|
||||
class CSpell;
|
||||
class CGTownInstance;
|
||||
class CArtifact;
|
||||
class CGDefInfo;
|
||||
class CSpecObjInfo;
|
||||
|
||||
class DLL_EXPORT CCastleEvent
|
||||
{
|
||||
public:
|
||||
std::string name, message;
|
||||
int wood, mercury, ore, sulfur, crystal, gems, gold; //gain / loss of resources
|
||||
unsigned char players; //players for whom this event can be applied
|
||||
bool forHuman, forComputer;
|
||||
int firstShow; //postpone of first encounter time in days
|
||||
int forEvery; //every n days this event will occure
|
||||
|
||||
unsigned char bytes[6]; //build specific buildings (raw format, similar to town's)
|
||||
|
||||
int gen[7]; //additional creatures in i-th level dwelling
|
||||
|
||||
bool operator<(const CCastleEvent &drugie) const
|
||||
{
|
||||
return firstShow<drugie.firstShow;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT IObjectInterface
|
||||
{
|
||||
public:
|
||||
static IGameCallback *cb;
|
||||
|
||||
IObjectInterface();
|
||||
virtual ~IObjectInterface();
|
||||
|
||||
virtual void onHeroVisit(const CGHeroInstance * h);
|
||||
virtual void onHeroLeave(const CGHeroInstance * h);
|
||||
virtual void newTurn();
|
||||
virtual void initObj();
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGObjectInstance : protected IObjectInterface
|
||||
{
|
||||
protected:
|
||||
public:
|
||||
mutable std::string hoverName;
|
||||
int3 pos; //h3m pos
|
||||
int ID, subID; //normal ID (this one from OH3 maps ;]) - eg. town=98; hero=34
|
||||
si32 id;//number of object in CObjectHandler's vector
|
||||
CGDefInfo * defInfo;
|
||||
CCPPObjectScript * state;
|
||||
CSpecObjInfo * info;
|
||||
unsigned char animPhaseShift;
|
||||
|
||||
ui8 tempOwner; //uzywane dla szybkosci, skrypt ma obowiazek aktualizowac te zmienna
|
||||
ui8 blockVisit; //if non-zero then blocks the tile but is visitable from neighbouring tile
|
||||
|
||||
int getOwner() const;
|
||||
void setOwner(int ow);
|
||||
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 object is visitable at location (x, y) form left top tile of image (x, y in tiles)
|
||||
bool blockingAt(int x, int y) const; //returns true if object is blocking 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);
|
||||
virtual const std::string & getHoverText() const;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void initObj();
|
||||
|
||||
friend class CGameHandler;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CArmedInstance: public CGObjectInstance
|
||||
{
|
||||
public:
|
||||
CCreatureSet army; //army
|
||||
virtual bool needsLastStack() const; //true if last stack cannot be taken
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGHeroInstance : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
mutable int moveDir; //format: 123
|
||||
// 8 4
|
||||
// 765
|
||||
mutable ui8 isStanding, tacticFormationEnabled;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CHero * type;
|
||||
ui32 exp; //experience point
|
||||
int level; //current level of hero
|
||||
std::string name; //may be custom
|
||||
std::string biography; //if custom
|
||||
int portrait; //may be custom
|
||||
int mana; // remaining spell points
|
||||
std::vector<int> primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge
|
||||
std::vector<std::pair<ui8,ui8> > secSkills; //first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert); if hero has ability (-1, -1) it meansthat it should have default secondary abilities
|
||||
int movement; //remaining movement points
|
||||
int identifier; //from the map file
|
||||
bool sex;
|
||||
struct DLL_EXPORT Patrol
|
||||
{
|
||||
Patrol(){patrolling=false;patrolRadious=-1;};
|
||||
bool patrolling;
|
||||
int patrolRadious;
|
||||
} patrol;
|
||||
bool inTownGarrison; // if hero is in town garrison
|
||||
CGTownInstance * visitedTown; //set if hero is visiting town or in the town garrison
|
||||
std::vector<ui32> artifacts; //hero's artifacts from bag
|
||||
std::map<ui16,ui32> 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
|
||||
std::set<ui32> spells; //known spells (spell IDs)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const std::string &getBiography() const;
|
||||
bool needsLastStack()const;
|
||||
unsigned int getTileCost(const EterrainType & ttype, const Eroad & rdtype, const Eriver & rvtype) const;
|
||||
unsigned int getLowestCreatureSpeed() const;
|
||||
unsigned int getAdditiveMoveBonus() const;
|
||||
float getMultiplicativeMoveBonus() const;
|
||||
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
|
||||
int manaLimit() const; //maximum mana value for this hero (basically 10*knowledge)
|
||||
bool canWalkOnSea() const;
|
||||
int getCurrentLuck() const;
|
||||
int getCurrentMorale() const;
|
||||
int getPrimSkillLevel(int id) const;
|
||||
int getSecSkillLevel(const int & ID) const; //0 - no skill
|
||||
int maxMovePoints(bool onLand) const;
|
||||
ui32 getArtAtPos(ui16 pos) const; //-1 - no artifact
|
||||
void setArtAtPos(ui16 pos, int art);
|
||||
const CArtifact * getArt(int pos) const;
|
||||
int getSpellSecLevel(int spell) const; //returns level of secondary ability (fire, water, earth, air magic) known to this hero and applicable to given spell; -1 if error
|
||||
static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void initHero();
|
||||
void initHero(int SUBID);
|
||||
CGHeroInstance();
|
||||
virtual ~CGHeroInstance();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void initObj();
|
||||
void onHeroVisit(const CGHeroInstance * h);
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGTownInstance : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
CTown * town;
|
||||
std::string name; // name of town
|
||||
int builded; //how many buildings has been built this turn
|
||||
int destroyed; //how many buildings has been destroyed this turn
|
||||
const CGHeroInstance * garrisonHero, *visitingHero;
|
||||
int identifier; //special identifier from h3m (only > RoE maps)
|
||||
int alignment;
|
||||
std::set<si32> forbiddenBuildings, builtBuildings;
|
||||
std::vector<int> possibleSpells, obligatorySpells;
|
||||
std::vector<std::vector<ui32> > spells; //spells[level] -> vector of spells, first will be available in guild
|
||||
|
||||
struct StrInfo
|
||||
{
|
||||
std::map<si32,ui32> creatures; //level - available amount
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & creatures;
|
||||
}
|
||||
} strInfo;
|
||||
std::set<CCastleEvent> events;
|
||||
|
||||
|
||||
bool needsLastStack() const;
|
||||
int getSightDistance() const; //returns sight distance
|
||||
int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle
|
||||
int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
|
||||
int mageGuildLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
|
||||
bool creatureDwelling(const int & level, bool upgraded=false) const;
|
||||
int getHordeLevel(const int & HID) const; //HID - 0 or 1; returns creature level or -1 if that horde structure is not present
|
||||
int creatureGrowth(const int & level) const;
|
||||
bool hasFort() const;
|
||||
bool hasCapitol() const;
|
||||
int dailyIncome() const;
|
||||
int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5)
|
||||
|
||||
CGTownInstance();
|
||||
virtual ~CGTownInstance();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h);
|
||||
void onHeroLeave(const CGHeroInstance * h);
|
||||
void initObj();
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGVisitableOPH : public CGObjectInstance //objects visitable only once per hero
|
||||
{
|
||||
public:
|
||||
std::set<si32> visitors; //ids of heroes who have visited this obj
|
||||
si8 ttype; //tree type - used only by trees of knowledge: 0 - give level for free; 1 - take 2000 gold; 2 - take 10 gems
|
||||
const std::string & getHoverText() const;
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h);
|
||||
void onNAHeroVisit(int heroID, bool alreadyVisited);
|
||||
void initObj();
|
||||
void treeSelected(int heroID, int resType, int resVal, int expVal, ui32 result); //handle player's anwer to the Tree of Knowledge dialog
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGEvent : public CGObjectInstance //event objects
|
||||
{
|
||||
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
|
||||
std::vector<int> abilities; //gained abilities
|
||||
std::vector<int> abilityLevels; //levels of gained abilities
|
||||
std::vector<int> artifacts; //gained artifacts
|
||||
std::vector<int> spells; //gained spells
|
||||
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
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGCreature : public CArmedInstance //creatures on map
|
||||
{
|
||||
public:
|
||||
ui32 identifier; //unique code for this monster (used in missions)
|
||||
ui8 character; //chracter of this set of creatures (0 - the most friendly, 4 - the most hostile)
|
||||
std::string message; //message printed for attacking hero
|
||||
std::vector<ui32> resources; //[res_id], resources given to hero that has won with monsters
|
||||
si32 gainedArtifact; //ID of artifact gained to hero, -1 if none
|
||||
ui8 neverFlees; //if true, the troops will never flee
|
||||
ui8 notGrowingTeam; //if true, number of units won't grow
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h);
|
||||
void endBattle(BattleResult *result);
|
||||
void initObj();
|
||||
};
|
||||
|
||||
|
||||
class DLL_EXPORT CGSignBottle : public CGObjectInstance //signs and ocean bottles
|
||||
{
|
||||
//TODO: generate default message if sign is 'empty'
|
||||
public:
|
||||
std::string message;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGSeerHut : public CGObjectInstance
|
||||
{
|
||||
public:
|
||||
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
|
||||
bool isDayLimit; //if true, there is a day limit
|
||||
int lastDay; //after this day (first day is 0) mission cannot be completed
|
||||
int m1level; //for mission 1
|
||||
int m2attack, m2defence, m2power, m2knowledge;//for mission 2
|
||||
unsigned char m3bytes[4];//for mission 3
|
||||
unsigned char m4bytes[4];//for mission 4
|
||||
std::vector<int> m5arts;//for mission 5 - artifact ID
|
||||
std::vector<CCreature *> m6cre;//for mission 6
|
||||
std::vector<int> m6number;
|
||||
int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; //for mission 7
|
||||
int m8hero;//for mission 8 - hero ID
|
||||
int m9player; //for mission 9 - number; from 0 to 7
|
||||
|
||||
std::string firstVisitText, nextVisitText, completedText;
|
||||
|
||||
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
|
||||
int r7ability; //ability id
|
||||
unsigned char r7level; //1 - basic, 2 - advanced, 3 - expert
|
||||
//for reward 8
|
||||
int r8art;//artifact id
|
||||
//for reward 9
|
||||
int r9spell;//spell id
|
||||
//for reward 10
|
||||
int r10creature; //creature id
|
||||
int r10amount;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGWitchHut : public CGObjectInstance
|
||||
{
|
||||
public:
|
||||
std::vector<int> allowedAbilities;
|
||||
};
|
||||
|
||||
|
||||
class DLL_EXPORT CGScholar : public CGObjectInstance
|
||||
{
|
||||
public:
|
||||
ui8 bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell
|
||||
|
||||
ui8 r0type;
|
||||
ui32 r1; //Ability ID
|
||||
ui32 r2; //Spell ID
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGGarrison : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
bool removableUnits;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGArtifact : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
std::string message;
|
||||
ui32 spell; //if it's spell scroll
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGResource : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
int amount; //0 if random
|
||||
std::string message;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGShrine : public CGObjectInstance
|
||||
{
|
||||
public:
|
||||
unsigned char spell; //number of spell or 255 if random
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGPandoraBox : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
std::string message;
|
||||
|
||||
//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<int> abilities;
|
||||
std::vector<int> abilityLevels;
|
||||
std::vector<int> artifacts;
|
||||
std::vector<int> spells;
|
||||
CCreatureSet creatures;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGQuestGuard : public CArmedInstance
|
||||
{
|
||||
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<int> m5arts; //artifacts id
|
||||
//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
|
||||
int m8hero; //hero id
|
||||
//for mission 9
|
||||
int m9player; //number; from 0 to 7
|
||||
|
||||
std::string firstVisitText, nextVisitText, completedText;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CObjectHandler
|
||||
{
|
||||
public:
|
||||
std::vector<std::string> names; //vector of objects; i-th object in vector has subnumber i
|
||||
std::vector<int> cregens; //type 17. dwelling subid -> creature ID
|
||||
void loadObjects();
|
||||
|
||||
std::vector<std::string> creGens; //names of creatures' generators
|
||||
std::vector<std::string> advobtxt;
|
||||
std::vector<std::string> xtrainfo;
|
||||
std::vector<std::string> restypes;
|
||||
std::vector<std::pair<std::string,std::string> > mines; //first - name; second - event description
|
||||
};
|
||||
|
||||
|
||||
#endif //COBJECTHANDLER_H
|
||||
#ifndef __COBJECTHANDLER_H__
|
||||
#define __COBJECTHANDLER_H__
|
||||
#include "../global.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <map>
|
||||
#include "CCreatureHandler.h"
|
||||
|
||||
using boost::logic::tribool;
|
||||
class IGameCallback;
|
||||
struct BattleResult;
|
||||
class CCPPObjectScript;
|
||||
class CGObjectInstance;
|
||||
class CScript;
|
||||
class CObjectScript;
|
||||
class CGHeroInstance;
|
||||
class CTown;
|
||||
class CHero;
|
||||
class CBuilding;
|
||||
class CSpell;
|
||||
class CGTownInstance;
|
||||
class CArtifact;
|
||||
class CGDefInfo;
|
||||
class CSpecObjInfo;
|
||||
|
||||
class DLL_EXPORT CCastleEvent
|
||||
{
|
||||
public:
|
||||
std::string name, message;
|
||||
int wood, mercury, ore, sulfur, crystal, gems, gold; //gain / loss of resources
|
||||
unsigned char players; //players for whom this event can be applied
|
||||
bool forHuman, forComputer;
|
||||
int firstShow; //postpone of first encounter time in days
|
||||
int forEvery; //every n days this event will occure
|
||||
|
||||
unsigned char bytes[6]; //build specific buildings (raw format, similar to town's)
|
||||
|
||||
int gen[7]; //additional creatures in i-th level dwelling
|
||||
|
||||
bool operator<(const CCastleEvent &drugie) const
|
||||
{
|
||||
return firstShow<drugie.firstShow;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT IObjectInterface
|
||||
{
|
||||
public:
|
||||
static IGameCallback *cb;
|
||||
|
||||
IObjectInterface();
|
||||
virtual ~IObjectInterface();
|
||||
|
||||
virtual void onHeroVisit(const CGHeroInstance * h);
|
||||
virtual void onHeroLeave(const CGHeroInstance * h);
|
||||
virtual void newTurn();
|
||||
virtual void initObj();
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGObjectInstance : protected IObjectInterface
|
||||
{
|
||||
protected:
|
||||
public:
|
||||
mutable std::string hoverName;
|
||||
int3 pos; //h3m pos
|
||||
int ID, subID; //normal ID (this one from OH3 maps ;]) - eg. town=98; hero=34
|
||||
si32 id;//number of object in CObjectHandler's vector
|
||||
CGDefInfo * defInfo;
|
||||
CCPPObjectScript * state;
|
||||
CSpecObjInfo * info;
|
||||
unsigned char animPhaseShift;
|
||||
|
||||
ui8 tempOwner; //uzywane dla szybkosci, skrypt ma obowiazek aktualizowac te zmienna
|
||||
ui8 blockVisit; //if non-zero then blocks the tile but is visitable from neighbouring tile
|
||||
|
||||
int getOwner() const;
|
||||
void setOwner(int ow);
|
||||
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 object is visitable at location (x, y) form left top tile of image (x, y in tiles)
|
||||
bool blockingAt(int x, int y) const; //returns true if object is blocking 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);
|
||||
virtual const std::string & getHoverText() const;
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void initObj();
|
||||
|
||||
friend class CGameHandler;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CArmedInstance: public CGObjectInstance
|
||||
{
|
||||
public:
|
||||
CCreatureSet army; //army
|
||||
virtual bool needsLastStack() const; //true if last stack cannot be taken
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGHeroInstance : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
mutable int moveDir; //format: 123
|
||||
// 8 4
|
||||
// 765
|
||||
mutable ui8 isStanding, tacticFormationEnabled;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
CHero * type;
|
||||
ui32 exp; //experience point
|
||||
int level; //current level of hero
|
||||
std::string name; //may be custom
|
||||
std::string biography; //if custom
|
||||
int portrait; //may be custom
|
||||
int mana; // remaining spell points
|
||||
std::vector<int> primSkills; //0-attack, 1-defence, 2-spell power, 3-knowledge
|
||||
std::vector<std::pair<ui8,ui8> > secSkills; //first - ID of skill, second - level of skill (1 - basic, 2 - adv., 3 - expert); if hero has ability (-1, -1) it meansthat it should have default secondary abilities
|
||||
int movement; //remaining movement points
|
||||
int identifier; //from the map file
|
||||
bool sex;
|
||||
struct DLL_EXPORT Patrol
|
||||
{
|
||||
Patrol(){patrolling=false;patrolRadious=-1;};
|
||||
bool patrolling;
|
||||
int patrolRadious;
|
||||
} patrol;
|
||||
bool inTownGarrison; // if hero is in town garrison
|
||||
CGTownInstance * visitedTown; //set if hero is visiting town or in the town garrison
|
||||
std::vector<ui32> artifacts; //hero's artifacts from bag
|
||||
std::map<ui16,ui32> 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
|
||||
std::set<ui32> spells; //known spells (spell IDs)
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const std::string &getBiography() const;
|
||||
bool needsLastStack()const;
|
||||
unsigned int getTileCost(const EterrainType & ttype, const Eroad & rdtype, const Eriver & rvtype) const;
|
||||
unsigned int getLowestCreatureSpeed() const;
|
||||
unsigned int getAdditiveMoveBonus() const;
|
||||
float getMultiplicativeMoveBonus() const;
|
||||
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
|
||||
int manaLimit() const; //maximum mana value for this hero (basically 10*knowledge)
|
||||
bool canWalkOnSea() const;
|
||||
int getCurrentLuck() const;
|
||||
int getCurrentMorale() const;
|
||||
int getPrimSkillLevel(int id) const;
|
||||
int getSecSkillLevel(const int & ID) const; //0 - no skill
|
||||
int maxMovePoints(bool onLand) const;
|
||||
ui32 getArtAtPos(ui16 pos) const; //-1 - no artifact
|
||||
void setArtAtPos(ui16 pos, int art);
|
||||
const CArtifact * getArt(int pos) const;
|
||||
int getSpellSecLevel(int spell) const; //returns level of secondary ability (fire, water, earth, air magic) known to this hero and applicable to given spell; -1 if error
|
||||
static int3 convertPosition(int3 src, bool toh3m); //toh3m=true: manifest->h3m; toh3m=false: h3m->manifest
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void initHero();
|
||||
void initHero(int SUBID);
|
||||
CGHeroInstance();
|
||||
virtual ~CGHeroInstance();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
void initObj();
|
||||
void onHeroVisit(const CGHeroInstance * h);
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGTownInstance : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
CTown * town;
|
||||
std::string name; // name of town
|
||||
int builded; //how many buildings has been built this turn
|
||||
int destroyed; //how many buildings has been destroyed this turn
|
||||
const CGHeroInstance * garrisonHero, *visitingHero;
|
||||
int identifier; //special identifier from h3m (only > RoE maps)
|
||||
int alignment;
|
||||
std::set<si32> forbiddenBuildings, builtBuildings;
|
||||
std::vector<int> possibleSpells, obligatorySpells;
|
||||
std::vector<std::vector<ui32> > spells; //spells[level] -> vector of spells, first will be available in guild
|
||||
|
||||
struct StrInfo
|
||||
{
|
||||
std::map<si32,ui32> creatures; //level - available amount
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & creatures;
|
||||
}
|
||||
} strInfo;
|
||||
std::set<CCastleEvent> events;
|
||||
|
||||
|
||||
bool needsLastStack() const;
|
||||
int getSightDistance() const; //returns sight distance
|
||||
int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle
|
||||
int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
|
||||
int mageGuildLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
|
||||
bool creatureDwelling(const int & level, bool upgraded=false) const;
|
||||
int getHordeLevel(const int & HID) const; //HID - 0 or 1; returns creature level or -1 if that horde structure is not present
|
||||
int creatureGrowth(const int & level) const;
|
||||
bool hasFort() const;
|
||||
bool hasCapitol() const;
|
||||
int dailyIncome() const;
|
||||
int spellsAtLevel(int level, bool checkGuild) const; //levels are counted from 1 (1 - 5)
|
||||
|
||||
CGTownInstance();
|
||||
virtual ~CGTownInstance();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h);
|
||||
void onHeroLeave(const CGHeroInstance * h);
|
||||
void initObj();
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGVisitableOPH : public CGObjectInstance //objects visitable only once per hero
|
||||
{
|
||||
public:
|
||||
std::set<si32> visitors; //ids of heroes who have visited this obj
|
||||
si8 ttype; //tree type - used only by trees of knowledge: 0 - give level for free; 1 - take 2000 gold; 2 - take 10 gems
|
||||
const std::string & getHoverText() const;
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h);
|
||||
void onNAHeroVisit(int heroID, bool alreadyVisited);
|
||||
void initObj();
|
||||
void treeSelected(int heroID, int resType, int resVal, int expVal, ui32 result); //handle player's anwer to the Tree of Knowledge dialog
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGEvent : public CGObjectInstance //event objects
|
||||
{
|
||||
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
|
||||
std::vector<int> abilities; //gained abilities
|
||||
std::vector<int> abilityLevels; //levels of gained abilities
|
||||
std::vector<int> artifacts; //gained artifacts
|
||||
std::vector<int> spells; //gained spells
|
||||
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
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGCreature : public CArmedInstance //creatures on map
|
||||
{
|
||||
public:
|
||||
ui32 identifier; //unique code for this monster (used in missions)
|
||||
ui8 character; //chracter of this set of creatures (0 - the most friendly, 4 - the most hostile)
|
||||
std::string message; //message printed for attacking hero
|
||||
std::vector<ui32> resources; //[res_id], resources given to hero that has won with monsters
|
||||
si32 gainedArtifact; //ID of artifact gained to hero, -1 if none
|
||||
ui8 neverFlees; //if true, the troops will never flee
|
||||
ui8 notGrowingTeam; //if true, number of units won't grow
|
||||
|
||||
void onHeroVisit(const CGHeroInstance * h);
|
||||
void endBattle(BattleResult *result);
|
||||
void initObj();
|
||||
};
|
||||
|
||||
|
||||
class DLL_EXPORT CGSignBottle : public CGObjectInstance //signs and ocean bottles
|
||||
{
|
||||
//TODO: generate default message if sign is 'empty'
|
||||
public:
|
||||
std::string message;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGSeerHut : public CGObjectInstance
|
||||
{
|
||||
public:
|
||||
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
|
||||
bool isDayLimit; //if true, there is a day limit
|
||||
int lastDay; //after this day (first day is 0) mission cannot be completed
|
||||
int m1level; //for mission 1
|
||||
int m2attack, m2defence, m2power, m2knowledge;//for mission 2
|
||||
unsigned char m3bytes[4];//for mission 3
|
||||
unsigned char m4bytes[4];//for mission 4
|
||||
std::vector<int> m5arts;//for mission 5 - artifact ID
|
||||
std::vector<CCreature *> m6cre;//for mission 6
|
||||
std::vector<int> m6number;
|
||||
int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; //for mission 7
|
||||
int m8hero;//for mission 8 - hero ID
|
||||
int m9player; //for mission 9 - number; from 0 to 7
|
||||
|
||||
std::string firstVisitText, nextVisitText, completedText;
|
||||
|
||||
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
|
||||
int r7ability; //ability id
|
||||
unsigned char r7level; //1 - basic, 2 - advanced, 3 - expert
|
||||
//for reward 8
|
||||
int r8art;//artifact id
|
||||
//for reward 9
|
||||
int r9spell;//spell id
|
||||
//for reward 10
|
||||
int r10creature; //creature id
|
||||
int r10amount;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGWitchHut : public CGObjectInstance
|
||||
{
|
||||
public:
|
||||
std::vector<int> allowedAbilities;
|
||||
};
|
||||
|
||||
|
||||
class DLL_EXPORT CGScholar : public CGObjectInstance
|
||||
{
|
||||
public:
|
||||
ui8 bonusType; //255 - random, 0 - primary skill, 1 - secondary skill, 2 - spell
|
||||
|
||||
ui8 r0type;
|
||||
ui32 r1; //Ability ID
|
||||
ui32 r2; //Spell ID
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGGarrison : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
bool removableUnits;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGArtifact : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
std::string message;
|
||||
ui32 spell; //if it's spell scroll
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGResource : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
int amount; //0 if random
|
||||
std::string message;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGShrine : public CGObjectInstance
|
||||
{
|
||||
public:
|
||||
unsigned char spell; //number of spell or 255 if random
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGPandoraBox : public CArmedInstance
|
||||
{
|
||||
public:
|
||||
std::string message;
|
||||
|
||||
//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<int> abilities;
|
||||
std::vector<int> abilityLevels;
|
||||
std::vector<int> artifacts;
|
||||
std::vector<int> spells;
|
||||
CCreatureSet creatures;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CGQuestGuard : public CArmedInstance
|
||||
{
|
||||
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<int> m5arts; //artifacts id
|
||||
//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
|
||||
int m8hero; //hero id
|
||||
//for mission 9
|
||||
int m9player; //number; from 0 to 7
|
||||
|
||||
std::string firstVisitText, nextVisitText, completedText;
|
||||
};
|
||||
|
||||
class DLL_EXPORT CObjectHandler
|
||||
{
|
||||
public:
|
||||
std::vector<std::string> names; //vector of objects; i-th object in vector has subnumber i
|
||||
std::vector<int> cregens; //type 17. dwelling subid -> creature ID
|
||||
void loadObjects();
|
||||
|
||||
std::vector<std::string> creGens; //names of creatures' generators
|
||||
std::vector<std::string> advobtxt;
|
||||
std::vector<std::string> xtrainfo;
|
||||
std::vector<std::string> restypes;
|
||||
std::vector<std::pair<std::string,std::string> > mines; //first - name; second - event description
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // __COBJECTHANDLER_H__
|
||||
|
@ -1,59 +1,60 @@
|
||||
#ifndef CSNDHANDLER_H
|
||||
#define CSNDHANDLER_H
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
struct MemberFile
|
||||
{
|
||||
std::ifstream * ifs;
|
||||
int length;
|
||||
};
|
||||
class CSndHandler
|
||||
{
|
||||
protected:
|
||||
const int CHUNK;
|
||||
struct Entry
|
||||
{
|
||||
std::string name;
|
||||
int size, offset;
|
||||
};
|
||||
std::ifstream file;
|
||||
int readNormalNr (int pos, int bytCon);
|
||||
bool opened;
|
||||
public:
|
||||
std::vector<Entry> entries;
|
||||
std::map<std::string, int> fimap; // map of wav file and index
|
||||
~CSndHandler();
|
||||
CSndHandler(std::string fname);
|
||||
void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file
|
||||
unsigned char * extract (std::string srcfile, int & size); //return selecte file data, NULL if file doesn't exist
|
||||
void extract(int index, std::string dstfile); //saves selected file
|
||||
MemberFile getFile(std::string name);//nie testowane - sprawdzic
|
||||
unsigned char * extract (int index, int & size); //return selecte file - NIE TESTOWANE
|
||||
};
|
||||
class CVidHandler
|
||||
{
|
||||
protected:
|
||||
const int CHUNK;
|
||||
struct Entry
|
||||
{
|
||||
std::string name;
|
||||
int size, offset, something;
|
||||
};
|
||||
std::ifstream file;
|
||||
int readNormalNr (int pos, int bytCon);
|
||||
bool opened;
|
||||
public:
|
||||
std::vector<Entry> entries;
|
||||
~CVidHandler();
|
||||
CVidHandler(std::string fname);
|
||||
std::ifstream & extract(std::string srcfile);
|
||||
void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file
|
||||
unsigned char * extract (std::string srcfile, int & size); //return selecte file,
|
||||
void extract(int index, std::string dstfile); //saves selected file
|
||||
MemberFile getFile(std::string name); //nie testowane - sprawdzic
|
||||
};
|
||||
|
||||
|
||||
#endif //CSNDHANDLER_H
|
||||
#ifndef __CSNDHANDLER_H__
|
||||
#define __CSNDHANDLER_H__
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
struct MemberFile
|
||||
{
|
||||
std::ifstream * ifs;
|
||||
int length;
|
||||
};
|
||||
class CSndHandler
|
||||
{
|
||||
protected:
|
||||
const int CHUNK;
|
||||
struct Entry
|
||||
{
|
||||
std::string name;
|
||||
int size, offset;
|
||||
};
|
||||
std::ifstream file;
|
||||
int readNormalNr (int pos, int bytCon);
|
||||
bool opened;
|
||||
public:
|
||||
std::vector<Entry> entries;
|
||||
std::map<std::string, int> fimap; // map of wav file and index
|
||||
~CSndHandler();
|
||||
CSndHandler(std::string fname);
|
||||
void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file
|
||||
unsigned char * extract (std::string srcfile, int & size); //return selecte file data, NULL if file doesn't exist
|
||||
void extract(int index, std::string dstfile); //saves selected file
|
||||
MemberFile getFile(std::string name);//nie testowane - sprawdzic
|
||||
unsigned char * extract (int index, int & size); //return selecte file - NIE TESTOWANE
|
||||
};
|
||||
class CVidHandler
|
||||
{
|
||||
protected:
|
||||
const int CHUNK;
|
||||
struct Entry
|
||||
{
|
||||
std::string name;
|
||||
int size, offset, something;
|
||||
};
|
||||
std::ifstream file;
|
||||
int readNormalNr (int pos, int bytCon);
|
||||
bool opened;
|
||||
public:
|
||||
std::vector<Entry> entries;
|
||||
~CVidHandler();
|
||||
CVidHandler(std::string fname);
|
||||
std::ifstream & extract(std::string srcfile);
|
||||
void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file
|
||||
unsigned char * extract (std::string srcfile, int & size); //return selecte file,
|
||||
void extract(int index, std::string dstfile); //saves selected file
|
||||
MemberFile getFile(std::string name); //nie testowane - sprawdzic
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // __CSNDHANDLER_H__
|
||||
|
@ -1,49 +1,50 @@
|
||||
#ifndef CSPELLHANDLER_H
|
||||
#define CSPELLHANDLER_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class CSpell
|
||||
{
|
||||
public:
|
||||
ui32 id;
|
||||
std::string name;
|
||||
std::string abbName; //abbreviated name
|
||||
std::vector<std::string> descriptions; //descriptions of spell for skill levels: 0 - none, 1 - basic, etc
|
||||
si32 level;
|
||||
bool earth;
|
||||
bool water;
|
||||
bool fire;
|
||||
bool air;
|
||||
si32 power; //spell's power
|
||||
std::vector<si32> costs; //per skill level: 0 - none, 1 - basic, etc
|
||||
std::vector<si32> powers; //[er skill level: 0 - none, 1 - basic, etc
|
||||
std::vector<si32> probabilities; //% chance to gain for castles
|
||||
std::vector<si32> AIVals; //AI values: per skill level: 0 - none, 1 - basic, etc
|
||||
std::string attributes; //reference only attributes
|
||||
bool combatSpell; //is this spell combat (true) or adventure (false)
|
||||
bool creatureAbility; //if true, only creatures can use this spell
|
||||
si8 positiveness; //1 if spell is positive for influenced stacks, 0 if it is indifferent, -1 if it's negative
|
||||
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & id & name & abbName & descriptions & level & earth & water & fire & air & power & costs
|
||||
& powers & probabilities & AIVals & attributes & combatSpell & creatureAbility & positiveness;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CSpellHandler
|
||||
{
|
||||
public:
|
||||
std::vector<CSpell> spells;
|
||||
void loadSpells();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & spells;
|
||||
}
|
||||
};
|
||||
|
||||
#endif //CSPELLHANDLER_H
|
||||
#ifndef __CSPELLHANDLER_H__
|
||||
#define __CSPELLHANDLER_H__
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class CSpell
|
||||
{
|
||||
public:
|
||||
ui32 id;
|
||||
std::string name;
|
||||
std::string abbName; //abbreviated name
|
||||
std::vector<std::string> descriptions; //descriptions of spell for skill levels: 0 - none, 1 - basic, etc
|
||||
si32 level;
|
||||
bool earth;
|
||||
bool water;
|
||||
bool fire;
|
||||
bool air;
|
||||
si32 power; //spell's power
|
||||
std::vector<si32> costs; //per skill level: 0 - none, 1 - basic, etc
|
||||
std::vector<si32> powers; //[er skill level: 0 - none, 1 - basic, etc
|
||||
std::vector<si32> probabilities; //% chance to gain for castles
|
||||
std::vector<si32> AIVals; //AI values: per skill level: 0 - none, 1 - basic, etc
|
||||
std::string attributes; //reference only attributes
|
||||
bool combatSpell; //is this spell combat (true) or adventure (false)
|
||||
bool creatureAbility; //if true, only creatures can use this spell
|
||||
si8 positiveness; //1 if spell is positive for influenced stacks, 0 if it is indifferent, -1 if it's negative
|
||||
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & id & name & abbName & descriptions & level & earth & water & fire & air & power & costs
|
||||
& powers & probabilities & AIVals & attributes & combatSpell & creatureAbility & positiveness;
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CSpellHandler
|
||||
{
|
||||
public:
|
||||
std::vector<CSpell> spells;
|
||||
void loadSpells();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & spells;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // __CSPELLHANDLER_H__
|
||||
|
@ -1,72 +1,73 @@
|
||||
#ifndef CTOWNHANDLER_H
|
||||
#define CTOWNHANDLER_H
|
||||
#include "../global.h"
|
||||
#include <set>
|
||||
class CBuilding;
|
||||
class CSpell;
|
||||
class CHero;
|
||||
class CGTownInstance;
|
||||
class DLL_EXPORT CTown
|
||||
{
|
||||
std::string name; //name of type
|
||||
public:
|
||||
|
||||
std::vector<std::string> names; //names of the town instances
|
||||
std::vector<int> basicCreatures; //level (from 0) -> ID
|
||||
std::vector<int> upgradedCreatures; //level (from 0) -> ID
|
||||
std::map<int,int> hordeLvl; //[0] - first horde building creature level; [1] - second horde building (-1 if not present)
|
||||
ui32 mageLevel; //max available mage guild level
|
||||
int bonus; //pic number
|
||||
ui16 primaryRes, warMachine;
|
||||
ui8 typeID;
|
||||
|
||||
|
||||
const std::vector<std::string> & Names() const;
|
||||
const std::string & Name() const;
|
||||
void Name(const std::string & val) { name = val; }
|
||||
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & names & basicCreatures & upgradedCreatures & hordeLvl & mageLevel & bonus
|
||||
& primaryRes & warMachine & typeID;
|
||||
}
|
||||
};
|
||||
|
||||
struct DLL_EXPORT Structure
|
||||
{
|
||||
int ID;
|
||||
int3 pos;
|
||||
std::string defName, borderName, areaName, name;
|
||||
int townID, group;
|
||||
|
||||
bool operator<(const Structure & p2) const
|
||||
{
|
||||
if(pos.z != p2.pos.z)
|
||||
return (pos.z) < (p2.pos.z);
|
||||
else
|
||||
return (ID) < (p2.ID);
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CTownHandler
|
||||
{
|
||||
public:
|
||||
std::vector<CTown> towns;
|
||||
std::map<int,std::map<int, Structure*> > structures; // <town ID, <structure ID, structure>>
|
||||
std::map<int, std::map<int,std::set<int> > > requirements; //requirements[town_id][structure_id] -> set of required buildings
|
||||
|
||||
CTownHandler();
|
||||
~CTownHandler();
|
||||
void loadNames();
|
||||
void loadStructures();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & towns & requirements;
|
||||
if(!h.saving)
|
||||
loadStructures();
|
||||
}
|
||||
};
|
||||
|
||||
#endif //CTOWNHANDLER_H
|
||||
#ifndef __CTOWNHANDLER_H__
|
||||
#define __CTOWNHANDLER_H__
|
||||
#include "../global.h"
|
||||
#include <set>
|
||||
class CBuilding;
|
||||
class CSpell;
|
||||
class CHero;
|
||||
class CGTownInstance;
|
||||
class DLL_EXPORT CTown
|
||||
{
|
||||
std::string name; //name of type
|
||||
public:
|
||||
|
||||
std::vector<std::string> names; //names of the town instances
|
||||
std::vector<int> basicCreatures; //level (from 0) -> ID
|
||||
std::vector<int> upgradedCreatures; //level (from 0) -> ID
|
||||
std::map<int,int> hordeLvl; //[0] - first horde building creature level; [1] - second horde building (-1 if not present)
|
||||
ui32 mageLevel; //max available mage guild level
|
||||
int bonus; //pic number
|
||||
ui16 primaryRes, warMachine;
|
||||
ui8 typeID;
|
||||
|
||||
|
||||
const std::vector<std::string> & Names() const;
|
||||
const std::string & Name() const;
|
||||
void Name(const std::string & val) { name = val; }
|
||||
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & names & basicCreatures & upgradedCreatures & hordeLvl & mageLevel & bonus
|
||||
& primaryRes & warMachine & typeID;
|
||||
}
|
||||
};
|
||||
|
||||
struct DLL_EXPORT Structure
|
||||
{
|
||||
int ID;
|
||||
int3 pos;
|
||||
std::string defName, borderName, areaName, name;
|
||||
int townID, group;
|
||||
|
||||
bool operator<(const Structure & p2) const
|
||||
{
|
||||
if(pos.z != p2.pos.z)
|
||||
return (pos.z) < (p2.pos.z);
|
||||
else
|
||||
return (ID) < (p2.ID);
|
||||
}
|
||||
};
|
||||
|
||||
class DLL_EXPORT CTownHandler
|
||||
{
|
||||
public:
|
||||
std::vector<CTown> towns;
|
||||
std::map<int,std::map<int, Structure*> > structures; // <town ID, <structure ID, structure>>
|
||||
std::map<int, std::map<int,std::set<int> > > requirements; //requirements[town_id][structure_id] -> set of required buildings
|
||||
|
||||
CTownHandler();
|
||||
~CTownHandler();
|
||||
void loadNames();
|
||||
void loadStructures();
|
||||
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & towns & requirements;
|
||||
if(!h.saving)
|
||||
loadStructures();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // __CTOWNHANDLER_H__
|
||||
|
235
int3.h
235
int3.h
@ -1,117 +1,118 @@
|
||||
#ifndef INT3_H
|
||||
#define INT3_H
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
class CCreature;
|
||||
class CCreatureSet //seven combined creatures
|
||||
{
|
||||
public:
|
||||
std::map<si32,std::pair<ui32,si32> > slots; //slots[slot_id]=> pair(creature_id,creature_quantity)
|
||||
bool formation; //false - wide, true - tight
|
||||
si32 getSlotFor(ui32 creature, ui32 slotsAmount=7) //returns -1 if no slot available
|
||||
{
|
||||
for(std::map<si32,std::pair<ui32,si32> >::iterator i=slots.begin(); i!=slots.end(); ++i)
|
||||
{
|
||||
if(i->second.first == creature)
|
||||
{
|
||||
return i->first; //if there is already such creature we return its slot id
|
||||
}
|
||||
}
|
||||
for(ui32 i=0; i<slotsAmount; i++)
|
||||
{
|
||||
if(slots.find(i) == slots.end())
|
||||
{
|
||||
return i; //return first free slot
|
||||
}
|
||||
}
|
||||
return -1; //no slot available
|
||||
}
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & slots & formation;
|
||||
}
|
||||
};
|
||||
|
||||
class int3
|
||||
{
|
||||
public:
|
||||
si32 x,y,z;
|
||||
inline int3():x(0),y(0),z(0){}; //c-tor, x/y/z initialized to 0
|
||||
inline int3(const si32 & X, const si32 & Y, const si32 & Z):x(X),y(Y),z(Z){}; //c-tor
|
||||
inline int3(const int3 & val) : x(val.x), y(val.y), z(val.z){} //copy c-tor
|
||||
inline int3 operator=(const int3 & val) {x = val.x; y = val.y; z = val.z; return *this;} //assignemt operator
|
||||
~int3() {} // d-tor - does nothing
|
||||
inline int3 operator+(const int3 & i) const //returns int3 with coordinates increased by corresponding coordinate of given int3
|
||||
{return int3(x+i.x,y+i.y,z+i.z);}
|
||||
inline int3 operator+(const si32 i) const //returns int3 with coordinates increased by given numer
|
||||
{return int3(x+i,y+i,z+i);}
|
||||
inline int3 operator-(const int3 & i) const //returns int3 with coordinates decreased by corresponding coordinate of given int3
|
||||
{return int3(x-i.x,y-i.y,z-i.z);}
|
||||
inline int3 operator-(const si32 i) const //returns int3 with coordinates decreased by given numer
|
||||
{return int3(x-i,y-i,z-i);}
|
||||
inline int3 operator-() const //returns opposite position
|
||||
{return int3(-x,-y,-z);}
|
||||
inline double dist2d(const int3 other) const //distance (z coord is not used)
|
||||
{return std::sqrt((double)(x-other.x)*(x-other.x) + (y-other.y)*(y-other.y));}
|
||||
inline void operator+=(const int3 & i)
|
||||
{
|
||||
x+=i.x;
|
||||
y+=i.y;
|
||||
z+=i.z;
|
||||
}
|
||||
inline void operator+=(const si32 & i)
|
||||
{
|
||||
x+=i;
|
||||
y+=i;
|
||||
z+=i;
|
||||
}
|
||||
inline void operator-=(const int3 & i)
|
||||
{
|
||||
x-=i.x;
|
||||
y-=i.y;
|
||||
z-=i.z;
|
||||
}
|
||||
inline void operator-=(const si32 & i)
|
||||
{
|
||||
x+=i;
|
||||
y+=i;
|
||||
z+=i;
|
||||
}
|
||||
inline bool operator==(const int3 & i) const
|
||||
{return (x==i.x) && (y==i.y) && (z==i.z);}
|
||||
inline bool operator!=(const int3 & i) const
|
||||
{return !(*this==i);}
|
||||
inline bool operator<(const int3 & i) const
|
||||
{
|
||||
if (z<i.z)
|
||||
return true;
|
||||
if (z>i.z)
|
||||
return false;
|
||||
if (y<i.y)
|
||||
return true;
|
||||
if (y>i.y)
|
||||
return false;
|
||||
if (x<i.x)
|
||||
return true;
|
||||
if (x>i.x)
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & x & y & z;
|
||||
}
|
||||
};
|
||||
inline std::istream & operator>>(std::istream & str, int3 & dest)
|
||||
{
|
||||
str>>dest.x>>dest.y>>dest.z;
|
||||
return str;
|
||||
}
|
||||
inline std::ostream & operator<<(std::ostream & str, const int3 & sth)
|
||||
{
|
||||
return str<<sth.x<<' '<<sth.y<<' '<<sth.z;
|
||||
}
|
||||
#endif //INT3_H
|
||||
#ifndef __INT3_H__
|
||||
#define __INT3_H__
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
|
||||
class CCreature;
|
||||
class CCreatureSet //seven combined creatures
|
||||
{
|
||||
public:
|
||||
std::map<si32,std::pair<ui32,si32> > slots; //slots[slot_id]=> pair(creature_id,creature_quantity)
|
||||
bool formation; //false - wide, true - tight
|
||||
si32 getSlotFor(ui32 creature, ui32 slotsAmount=7) //returns -1 if no slot available
|
||||
{
|
||||
for(std::map<si32,std::pair<ui32,si32> >::iterator i=slots.begin(); i!=slots.end(); ++i)
|
||||
{
|
||||
if(i->second.first == creature)
|
||||
{
|
||||
return i->first; //if there is already such creature we return its slot id
|
||||
}
|
||||
}
|
||||
for(ui32 i=0; i<slotsAmount; i++)
|
||||
{
|
||||
if(slots.find(i) == slots.end())
|
||||
{
|
||||
return i; //return first free slot
|
||||
}
|
||||
}
|
||||
return -1; //no slot available
|
||||
}
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & slots & formation;
|
||||
}
|
||||
};
|
||||
|
||||
class int3
|
||||
{
|
||||
public:
|
||||
si32 x,y,z;
|
||||
inline int3():x(0),y(0),z(0){}; //c-tor, x/y/z initialized to 0
|
||||
inline int3(const si32 & X, const si32 & Y, const si32 & Z):x(X),y(Y),z(Z){}; //c-tor
|
||||
inline int3(const int3 & val) : x(val.x), y(val.y), z(val.z){} //copy c-tor
|
||||
inline int3 operator=(const int3 & val) {x = val.x; y = val.y; z = val.z; return *this;} //assignemt operator
|
||||
~int3() {} // d-tor - does nothing
|
||||
inline int3 operator+(const int3 & i) const //returns int3 with coordinates increased by corresponding coordinate of given int3
|
||||
{return int3(x+i.x,y+i.y,z+i.z);}
|
||||
inline int3 operator+(const si32 i) const //returns int3 with coordinates increased by given numer
|
||||
{return int3(x+i,y+i,z+i);}
|
||||
inline int3 operator-(const int3 & i) const //returns int3 with coordinates decreased by corresponding coordinate of given int3
|
||||
{return int3(x-i.x,y-i.y,z-i.z);}
|
||||
inline int3 operator-(const si32 i) const //returns int3 with coordinates decreased by given numer
|
||||
{return int3(x-i,y-i,z-i);}
|
||||
inline int3 operator-() const //returns opposite position
|
||||
{return int3(-x,-y,-z);}
|
||||
inline double dist2d(const int3 other) const //distance (z coord is not used)
|
||||
{return std::sqrt((double)(x-other.x)*(x-other.x) + (y-other.y)*(y-other.y));}
|
||||
inline void operator+=(const int3 & i)
|
||||
{
|
||||
x+=i.x;
|
||||
y+=i.y;
|
||||
z+=i.z;
|
||||
}
|
||||
inline void operator+=(const si32 & i)
|
||||
{
|
||||
x+=i;
|
||||
y+=i;
|
||||
z+=i;
|
||||
}
|
||||
inline void operator-=(const int3 & i)
|
||||
{
|
||||
x-=i.x;
|
||||
y-=i.y;
|
||||
z-=i.z;
|
||||
}
|
||||
inline void operator-=(const si32 & i)
|
||||
{
|
||||
x+=i;
|
||||
y+=i;
|
||||
z+=i;
|
||||
}
|
||||
inline bool operator==(const int3 & i) const
|
||||
{return (x==i.x) && (y==i.y) && (z==i.z);}
|
||||
inline bool operator!=(const int3 & i) const
|
||||
{return !(*this==i);}
|
||||
inline bool operator<(const int3 & i) const
|
||||
{
|
||||
if (z<i.z)
|
||||
return true;
|
||||
if (z>i.z)
|
||||
return false;
|
||||
if (y<i.y)
|
||||
return true;
|
||||
if (y>i.y)
|
||||
return false;
|
||||
if (x<i.x)
|
||||
return true;
|
||||
if (x>i.x)
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
template <typename Handler> void serialize(Handler &h, const int version)
|
||||
{
|
||||
h & x & y & z;
|
||||
}
|
||||
};
|
||||
inline std::istream & operator>>(std::istream & str, int3 & dest)
|
||||
{
|
||||
str>>dest.x>>dest.y>>dest.z;
|
||||
return str;
|
||||
}
|
||||
inline std::ostream & operator<<(std::ostream & str, const int3 & sth)
|
||||
{
|
||||
return str<<sth.x<<' '<<sth.y<<' '<<sth.z;
|
||||
}
|
||||
|
||||
#endif // __INT3_H__
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef CONNECTION_H
|
||||
#define CONNECTION_H
|
||||
#ifndef __CONNECTION_H__
|
||||
#define __CONNECTION_H__
|
||||
#include "../global.h"
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -413,4 +413,5 @@ public:
|
||||
void close();
|
||||
~CConnection(void);
|
||||
};
|
||||
#endif //CONNECTION_H
|
||||
|
||||
#endif // __CONNECTION_H__
|
||||
|
@ -1,45 +1,46 @@
|
||||
#ifndef VCMI_LIB_H
|
||||
#define VCMI_LIB_H
|
||||
#include "../global.h"
|
||||
|
||||
class CLodHandler;
|
||||
class CArtHandler;
|
||||
class CHeroHandler;
|
||||
class CCreatureHandler;
|
||||
//class CAbilityHandler;
|
||||
class CSpellHandler;
|
||||
//class CPreGameTextHandler;
|
||||
class CBuildingHandler;
|
||||
class CObjectHandler;
|
||||
//class CMusicHandler;
|
||||
//class CSemiLodHandler;
|
||||
class CDefObjInfoHandler;
|
||||
class CTownHandler;
|
||||
class CGeneralTextHandler;
|
||||
//class CConsoleHandler;
|
||||
//class CPathfinder;
|
||||
//class CGameState;
|
||||
|
||||
class LibClasses
|
||||
{
|
||||
public:
|
||||
CArtHandler * arth;
|
||||
CHeroHandler * heroh;
|
||||
CCreatureHandler * creh;
|
||||
CSpellHandler * spellh;
|
||||
CBuildingHandler * buildh;
|
||||
CObjectHandler * objh;
|
||||
CDefObjInfoHandler * dobjinfo;
|
||||
CTownHandler * townh;
|
||||
CGeneralTextHandler * generaltexth;
|
||||
//CPathfinder * pathf;
|
||||
};
|
||||
|
||||
extern DLL_EXPORT LibClasses * VLC;
|
||||
extern CLodHandler * bitmaph;
|
||||
|
||||
DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
|
||||
DLL_EXPORT void loadToIt(si32 &dest, std::string &src, int &iter, int mode);
|
||||
DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *Logfile);
|
||||
|
||||
#endif //VCMI_LIB_H
|
||||
#ifndef __VCMI_LIB_H__
|
||||
#define __VCMI_LIB_H__
|
||||
#include "../global.h"
|
||||
|
||||
class CLodHandler;
|
||||
class CArtHandler;
|
||||
class CHeroHandler;
|
||||
class CCreatureHandler;
|
||||
//class CAbilityHandler;
|
||||
class CSpellHandler;
|
||||
//class CPreGameTextHandler;
|
||||
class CBuildingHandler;
|
||||
class CObjectHandler;
|
||||
//class CMusicHandler;
|
||||
//class CSemiLodHandler;
|
||||
class CDefObjInfoHandler;
|
||||
class CTownHandler;
|
||||
class CGeneralTextHandler;
|
||||
//class CConsoleHandler;
|
||||
//class CPathfinder;
|
||||
//class CGameState;
|
||||
|
||||
class LibClasses
|
||||
{
|
||||
public:
|
||||
CArtHandler * arth;
|
||||
CHeroHandler * heroh;
|
||||
CCreatureHandler * creh;
|
||||
CSpellHandler * spellh;
|
||||
CBuildingHandler * buildh;
|
||||
CObjectHandler * objh;
|
||||
CDefObjInfoHandler * dobjinfo;
|
||||
CTownHandler * townh;
|
||||
CGeneralTextHandler * generaltexth;
|
||||
//CPathfinder * pathf;
|
||||
};
|
||||
|
||||
extern DLL_EXPORT LibClasses * VLC;
|
||||
extern CLodHandler * bitmaph;
|
||||
|
||||
DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode);
|
||||
DLL_EXPORT void loadToIt(si32 &dest, std::string &src, int &iter, int mode);
|
||||
DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *Logfile);
|
||||
|
||||
|
||||
#endif // __VCMI_LIB_H__
|
||||
|
231
mapHandler.h
231
mapHandler.h
@ -1,115 +1,116 @@
|
||||
#ifndef MAPHANDLER_H
|
||||
#define MAPHANDLER_H
|
||||
#include "global.h"
|
||||
#include <list>
|
||||
#include <set>
|
||||
const int Woff = 12; //width of map's frame
|
||||
const int Hoff = 8;
|
||||
|
||||
class CGObjectInstance;
|
||||
class CGHeroInstance;
|
||||
struct Mapa;
|
||||
class CGDefInfo;
|
||||
class CGObjectInstance;
|
||||
class CDefHandler;
|
||||
struct TerrainTile;
|
||||
struct SDL_Surface;
|
||||
struct SDL_Rect;
|
||||
|
||||
struct TerrainTile2
|
||||
{
|
||||
int3 pos;
|
||||
const TerrainTile *tileInfo;
|
||||
SDL_Surface * terbitmap; //frames of terrain animation
|
||||
std::vector<SDL_Surface *> rivbitmap; //frames of river animation
|
||||
std::vector<SDL_Surface *> roadbitmap; //frames of road animation
|
||||
|
||||
std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen
|
||||
TerrainTile2();
|
||||
};
|
||||
|
||||
//pathfinder
|
||||
// map<int,int> iDTerenu=>koszt_pola
|
||||
// map<int,int> IDdrogi=>koszt_drogi
|
||||
template <typename T> class PseudoV
|
||||
{
|
||||
public:
|
||||
int offset;
|
||||
std::vector<T> inver;
|
||||
PseudoV(){};
|
||||
PseudoV(std::vector<T> &src, int rest, int Offset, const T& fill)
|
||||
{
|
||||
inver.resize(Offset*2+rest);
|
||||
offset=Offset;
|
||||
for(int i=0; i<offset;i++)
|
||||
inver[i] = fill;
|
||||
for(int i=0;i<src.size();i++)
|
||||
inver[offset+i] = src[i];
|
||||
for(int i=src.size(); i<src.size()+offset;i++)
|
||||
inver[offset+i] = fill;
|
||||
}
|
||||
inline T & operator[](const int & n)
|
||||
{
|
||||
return inver[n+offset];
|
||||
}
|
||||
inline const T & operator[](const int & n) const
|
||||
{
|
||||
return inver[n+offset];
|
||||
}
|
||||
void resize(int rest,int Offset)
|
||||
{
|
||||
inver.resize(Offset*2+rest);
|
||||
offset=Offset;
|
||||
}
|
||||
int size() const
|
||||
{
|
||||
return inver.size();
|
||||
}
|
||||
};
|
||||
class CMapHandler
|
||||
{
|
||||
public:
|
||||
PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles;
|
||||
int3 sizes;
|
||||
Mapa * map;
|
||||
std::set<int> usedHeroes;
|
||||
CDefHandler * fullHide;
|
||||
CDefHandler * partialHide;
|
||||
|
||||
std::vector<std::vector<SDL_Surface *> > terrainGraphics; // [terrain id] [view type] [rotation type]
|
||||
std::vector<CDefHandler *> roadDefs;
|
||||
std::vector<CDefHandler *> staticRiverDefs;
|
||||
std::vector<CDefHandler*> defs;
|
||||
|
||||
std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
|
||||
|
||||
std::vector<std::vector<std::vector<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
|
||||
|
||||
void loadDefs();
|
||||
SDL_Surface * getVisBitmap(int x, int y, const std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl);
|
||||
|
||||
int getCost(int3 & a, int3 & b, const CGHeroInstance * hero);
|
||||
std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
|
||||
//std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position
|
||||
CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
|
||||
std::string getDefName(int id, int subid); //returns name of def for object with given id and subid
|
||||
bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
|
||||
bool hideObject(const CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
|
||||
bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
|
||||
void initHeroDef(CGHeroInstance * h);
|
||||
void init();
|
||||
void calculateBlockedPos();
|
||||
void initObjectRects();
|
||||
void borderAndTerrainBitmapInit();
|
||||
void roadsRiverTerrainInit();
|
||||
void prepareFOWDefs();
|
||||
|
||||
SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap = NULL, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it
|
||||
void updateWater();
|
||||
unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function
|
||||
void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper
|
||||
static unsigned char getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b]
|
||||
|
||||
};
|
||||
|
||||
#endif //MAPHANDLER_H
|
||||
#ifndef __MAPHANDLER_H__
|
||||
#define __MAPHANDLER_H__
|
||||
#include "global.h"
|
||||
#include <list>
|
||||
#include <set>
|
||||
const int Woff = 12; //width of map's frame
|
||||
const int Hoff = 8;
|
||||
|
||||
class CGObjectInstance;
|
||||
class CGHeroInstance;
|
||||
struct Mapa;
|
||||
class CGDefInfo;
|
||||
class CGObjectInstance;
|
||||
class CDefHandler;
|
||||
struct TerrainTile;
|
||||
struct SDL_Surface;
|
||||
struct SDL_Rect;
|
||||
|
||||
struct TerrainTile2
|
||||
{
|
||||
int3 pos;
|
||||
const TerrainTile *tileInfo;
|
||||
SDL_Surface * terbitmap; //frames of terrain animation
|
||||
std::vector<SDL_Surface *> rivbitmap; //frames of river animation
|
||||
std::vector<SDL_Surface *> roadbitmap; //frames of road animation
|
||||
|
||||
std::vector < std::pair<const CGObjectInstance*,SDL_Rect> > objects; //poiters to objects being on this tile with rects to be easier to blit this tile on screen
|
||||
TerrainTile2();
|
||||
};
|
||||
|
||||
//pathfinder
|
||||
// map<int,int> iDTerenu=>koszt_pola
|
||||
// map<int,int> IDdrogi=>koszt_drogi
|
||||
template <typename T> class PseudoV
|
||||
{
|
||||
public:
|
||||
int offset;
|
||||
std::vector<T> inver;
|
||||
PseudoV(){};
|
||||
PseudoV(std::vector<T> &src, int rest, int Offset, const T& fill)
|
||||
{
|
||||
inver.resize(Offset*2+rest);
|
||||
offset=Offset;
|
||||
for(int i=0; i<offset;i++)
|
||||
inver[i] = fill;
|
||||
for(int i=0;i<src.size();i++)
|
||||
inver[offset+i] = src[i];
|
||||
for(int i=src.size(); i<src.size()+offset;i++)
|
||||
inver[offset+i] = fill;
|
||||
}
|
||||
inline T & operator[](const int & n)
|
||||
{
|
||||
return inver[n+offset];
|
||||
}
|
||||
inline const T & operator[](const int & n) const
|
||||
{
|
||||
return inver[n+offset];
|
||||
}
|
||||
void resize(int rest,int Offset)
|
||||
{
|
||||
inver.resize(Offset*2+rest);
|
||||
offset=Offset;
|
||||
}
|
||||
int size() const
|
||||
{
|
||||
return inver.size();
|
||||
}
|
||||
};
|
||||
class CMapHandler
|
||||
{
|
||||
public:
|
||||
PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles;
|
||||
int3 sizes;
|
||||
Mapa * map;
|
||||
std::set<int> usedHeroes;
|
||||
CDefHandler * fullHide;
|
||||
CDefHandler * partialHide;
|
||||
|
||||
std::vector<std::vector<SDL_Surface *> > terrainGraphics; // [terrain id] [view type] [rotation type]
|
||||
std::vector<CDefHandler *> roadDefs;
|
||||
std::vector<CDefHandler *> staticRiverDefs;
|
||||
std::vector<CDefHandler*> defs;
|
||||
|
||||
std::map<std::string, CDefHandler*> loadedDefs; //pointers to loaded defs (key is filename, uppercase)
|
||||
|
||||
std::vector<std::vector<std::vector<unsigned char> > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile
|
||||
|
||||
void loadDefs();
|
||||
SDL_Surface * getVisBitmap(int x, int y, const std::vector< std::vector< std::vector<unsigned char> > > & visibilityMap, int lvl);
|
||||
|
||||
int getCost(int3 & a, int3 & b, const CGHeroInstance * hero);
|
||||
std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position
|
||||
//std::vector< CGObjectInstance * > getVisitableObjs(int3 pos); //returns vector of visitable objects at certain position
|
||||
CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
|
||||
std::string getDefName(int id, int subid); //returns name of def for object with given id and subid
|
||||
bool printObject(const CGObjectInstance * obj); //puts appropriate things to ttiles, so obj will be visible on map
|
||||
bool hideObject(const CGObjectInstance * obj); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
|
||||
bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
|
||||
void initHeroDef(CGHeroInstance * h);
|
||||
void init();
|
||||
void calculateBlockedPos();
|
||||
void initObjectRects();
|
||||
void borderAndTerrainBitmapInit();
|
||||
void roadsRiverTerrainInit();
|
||||
void prepareFOWDefs();
|
||||
|
||||
SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap = NULL, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it
|
||||
void updateWater();
|
||||
unsigned char getHeroFrameNum(const unsigned char & dir, const bool & isMoving) const; //terrainRect helper function
|
||||
void validateRectTerr(SDL_Rect * val, const SDL_Rect * ext); //terrainRect helper
|
||||
static unsigned char getDir(const int3 & a, const int3 & b); //returns direction number in range 0 - 7 (0 is left top, clockwise) [direction: form a to b]
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // __MAPHANDLER_H__
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef CGAMEHANDLER_H
|
||||
#define CGAMEHANDLER_H
|
||||
#ifndef __CGAMEHANDLER_H__
|
||||
#define __CGAMEHANDLER_H__
|
||||
|
||||
#include "../global.h"
|
||||
#include <set>
|
||||
@ -169,4 +169,5 @@ public:
|
||||
friend class CVCMIServer;
|
||||
friend class CScriptCallback;
|
||||
};
|
||||
#endif //CGAMEHANDLER_H
|
||||
|
||||
#endif // __CGAMEHANDLER_H__
|
||||
|
3
stdafx.h
3
stdafx.h
@ -1,7 +1,5 @@
|
||||
#ifndef __STDAFX_H__
|
||||
#define __STDAFX_H__
|
||||
#ifndef __STDAFX_H__
|
||||
#define __STDAFX_H__
|
||||
|
||||
// stdafx.h : include file for standard system include files,
|
||||
// or project specific include files that are used frequently, but
|
||||
@ -24,4 +22,3 @@
|
||||
// TODO: reference additional headers your program requires here
|
||||
|
||||
#endif // __STDAFX_H__
|
||||
#endif // __STDAFX_H__
|
||||
|
@ -1,16 +1,17 @@
|
||||
#ifndef TIMEHANDLER_H
|
||||
#define TIMEHANDLER_H
|
||||
|
||||
#include <ctime>
|
||||
class timeHandler
|
||||
{
|
||||
public:
|
||||
clock_t start, last, mem;
|
||||
timeHandler():start(clock()){last=clock();mem=0;};
|
||||
long getDif(){long ret=clock()-last;last=clock();return ret;};
|
||||
void update(){last=clock();};
|
||||
void remember(){mem=clock();};
|
||||
long memDif(){return mem-clock();};
|
||||
};
|
||||
|
||||
#endif //TIMEHANDLER_H
|
||||
#ifndef __TIMEHANDLER_H__
|
||||
#define __TIMEHANDLER_H__
|
||||
|
||||
#include <ctime>
|
||||
class timeHandler
|
||||
{
|
||||
public:
|
||||
clock_t start, last, mem;
|
||||
timeHandler():start(clock()){last=clock();mem=0;};
|
||||
long getDif(){long ret=clock()-last;last=clock();return ret;};
|
||||
void update(){last=clock();};
|
||||
void remember(){mem=clock();};
|
||||
long memDif(){return mem-clock();};
|
||||
};
|
||||
|
||||
|
||||
#endif // __TIMEHANDLER_H__
|
||||
|
Loading…
Reference in New Issue
Block a user