2007-07-28 18:23:15 +03:00
|
|
|
#ifndef CGAMESTATE_H
|
|
|
|
#define CGAMESTATE_H
|
2008-06-30 03:06:41 +03:00
|
|
|
#include "global.h"
|
2007-11-24 16:17:57 +02:00
|
|
|
#include <set>
|
2008-06-30 03:06:41 +03:00
|
|
|
#include <vector>
|
2008-02-25 01:06:27 +02:00
|
|
|
#include <tchar.h>
|
2008-03-10 22:19:41 +02:00
|
|
|
|
2007-11-19 00:58:28 +02:00
|
|
|
class CScriptCallback;
|
2007-08-27 17:15:03 +03:00
|
|
|
class CCallback;
|
2007-11-19 00:58:28 +02:00
|
|
|
class CLuaCallback;
|
2007-11-24 16:17:57 +02:00
|
|
|
class CCPPObjectScript;
|
2008-02-25 01:06:27 +02:00
|
|
|
class CCreatureSet;
|
|
|
|
class CStack;
|
|
|
|
class CGHeroInstance;
|
2008-06-30 03:06:41 +03:00
|
|
|
class CGTownInstance;
|
2008-02-25 01:06:27 +02:00
|
|
|
class CArmedInstance;
|
2008-06-30 03:06:41 +03:00
|
|
|
class CGDefInfo;
|
|
|
|
class CObjectScript;
|
|
|
|
class CGObjectInstance;
|
|
|
|
class CCreature;
|
2008-06-21 16:27:52 +03:00
|
|
|
struct Mapa;
|
2008-06-30 03:06:41 +03:00
|
|
|
struct StartInfo;
|
|
|
|
struct SDL_Surface;
|
|
|
|
class CMapHandler;
|
|
|
|
class CPathfinder;
|
2008-03-10 22:19:41 +02:00
|
|
|
|
2008-06-30 03:06:41 +03:00
|
|
|
struct DLL_EXPORT PlayerState
|
2007-07-28 18:23:15 +03:00
|
|
|
{
|
2007-08-04 22:01:22 +03:00
|
|
|
public:
|
2007-11-19 00:58:28 +02:00
|
|
|
int color, serial;
|
2008-06-30 03:06:41 +03:00
|
|
|
std::vector<std::vector<std::vector<unsigned char> > > fogOfWarMap; //true - visible, false - hidden
|
2007-07-28 18:23:15 +03:00
|
|
|
std::vector<int> resources;
|
2007-10-27 22:38:48 +03:00
|
|
|
std::vector<CGHeroInstance *> heroes;
|
|
|
|
std::vector<CGTownInstance *> towns;
|
2007-09-18 16:30:26 +03:00
|
|
|
PlayerState():color(-1){};
|
2007-07-29 02:01:25 +03:00
|
|
|
};
|
2008-03-10 22:19:41 +02:00
|
|
|
|
2008-06-30 03:06:41 +03:00
|
|
|
struct DLL_EXPORT BattleInfo
|
2008-02-25 01:06:27 +02:00
|
|
|
{
|
|
|
|
int side1, side2;
|
|
|
|
int round, activeStack;
|
|
|
|
int 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
|
|
|
|
CGHeroInstance *hero1, *hero2;
|
|
|
|
CCreatureSet * army1, * army2;
|
|
|
|
std::vector<CStack*> stacks;
|
2008-03-29 12:59:18 +02:00
|
|
|
bool stackActionPerformed; //true if current stack has been moved
|
2008-02-25 01:06:27 +02:00
|
|
|
};
|
2008-03-10 22:19:41 +02:00
|
|
|
|
2008-06-30 03:06:41 +03:00
|
|
|
class DLL_EXPORT CStack
|
2008-03-10 01:06:35 +02:00
|
|
|
{
|
|
|
|
public:
|
2008-03-14 20:24:37 +02:00
|
|
|
int ID; //unique ID of stack
|
2008-03-10 01:06:35 +02:00
|
|
|
CCreature * creature;
|
|
|
|
int amount;
|
2008-05-30 14:53:04 +03:00
|
|
|
int firstHPleft; //HP of first creature in stack
|
2008-03-10 01:06:35 +02:00
|
|
|
int owner;
|
2008-04-14 21:24:46 +03:00
|
|
|
bool attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle)
|
2008-03-10 22:19:41 +02:00
|
|
|
int position; //position on battlefield
|
|
|
|
bool alive; //true if it is alive
|
2008-06-30 03:06:41 +03:00
|
|
|
CStack(CCreature * C, int A, int O, int I, bool AO);
|
2008-05-30 14:53:04 +03:00
|
|
|
CStack() : creature(NULL),amount(-1),owner(255), alive(true), position(-1), ID(-1), attackerOwned(true), firstHPleft(-1){};
|
2008-03-10 01:06:35 +02:00
|
|
|
};
|
2008-03-10 22:19:41 +02:00
|
|
|
|
2008-06-30 03:06:41 +03:00
|
|
|
class DLL_EXPORT CGameState
|
2007-07-28 18:23:15 +03:00
|
|
|
{
|
2007-11-19 00:58:28 +02:00
|
|
|
private:
|
2008-06-30 03:06:41 +03:00
|
|
|
StartInfo* scenarioOps;
|
2008-07-25 20:28:28 +03:00
|
|
|
ui32 seed;
|
|
|
|
ui8 currentPlayer; //ID of player currently having turn
|
2008-02-25 01:06:27 +02:00
|
|
|
BattleInfo *curB; //current battle
|
2008-07-25 20:28:28 +03:00
|
|
|
ui32 day; //total number of days in game
|
2008-06-21 16:27:52 +03:00
|
|
|
Mapa * map;
|
2008-07-25 20:28:28 +03:00
|
|
|
std::map<ui8,PlayerState> players; //ID <-> playerstate
|
2008-06-21 16:27:52 +03:00
|
|
|
std::set<CCPPObjectScript *> cppscripts; //C++ scripts
|
|
|
|
std::map<int, std::map<std::string, CObjectScript*> > objscr; //non-C++ scripts
|
2007-11-19 00:58:28 +02:00
|
|
|
|
2008-06-30 03:06:41 +03:00
|
|
|
std::map<int, CGDefInfo*> villages, forts, capitols; //def-info for town graphics
|
2007-11-19 00:58:28 +02:00
|
|
|
|
|
|
|
bool checkFunc(int obid, std::string name)
|
|
|
|
{
|
|
|
|
if (objscr.find(obid)!=objscr.end())
|
|
|
|
{
|
|
|
|
if(objscr[obid].find(name)!=objscr[obid].end())
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-30 03:06:41 +03:00
|
|
|
|
2008-07-25 20:28:28 +03:00
|
|
|
void init(StartInfo * si, Mapa * map, int Seed);
|
2008-06-30 03:06:41 +03:00
|
|
|
void randomizeObject(CGObjectInstance *cur);
|
|
|
|
std::pair<int,int> pickObject(CGObjectInstance *obj);
|
|
|
|
int pickHero(int owner);
|
|
|
|
|
2008-02-25 01:06:27 +02:00
|
|
|
void battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2);
|
2008-03-23 19:25:38 +02:00
|
|
|
bool battleMoveCreatureStack(int ID, int dest);
|
2008-05-27 16:16:35 +03:00
|
|
|
bool battleAttackCreatureStack(int ID, int dest);
|
2008-03-29 12:59:18 +02:00
|
|
|
std::vector<int> battleGetRange(int ID); //called by std::vector<int> CCallback::battleGetAvailableHexes(int ID);
|
2007-08-27 17:15:03 +03:00
|
|
|
public:
|
2008-07-25 20:28:28 +03:00
|
|
|
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
|
|
|
|
|
|
|
|
friend class CCallback;
|
|
|
|
friend class CPathfinder;;
|
|
|
|
friend class CLuaCallback;
|
|
|
|
friend class CClient;
|
2008-06-11 04:53:57 +03:00
|
|
|
friend void initGameState(Mapa * map, CGameInfo * cgi);
|
2008-07-25 20:28:28 +03:00
|
|
|
friend class CScriptCallback;
|
2007-11-24 16:17:57 +02:00
|
|
|
friend void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
|
2008-07-02 11:39:56 +03:00
|
|
|
friend class CMapHandler;
|
2008-07-25 20:28:28 +03:00
|
|
|
friend class CGameHandler;
|
2007-07-29 02:01:25 +03:00
|
|
|
};
|
2007-07-28 18:23:15 +03:00
|
|
|
|
2007-09-14 16:11:10 +03:00
|
|
|
#endif //CGAMESTATE_H
|