1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

* fixed initialization of map of players

* functions in callback for getting info about towns
* added info about towns to CGameState
* minor changes
This commit is contained in:
Michał W. Urbańczyk 2007-09-18 13:30:26 +00:00
parent b0e72f334e
commit 6d0bcef157
12 changed files with 186 additions and 56 deletions

View File

@ -3,8 +3,13 @@
#include "hch\CLodHandler.h" #include "hch\CLodHandler.h"
#include "hch\CPreGameTextHandler.h" #include "hch\CPreGameTextHandler.h"
#include "hch\CGeneralTextHandler.h" #include "hch\CGeneralTextHandler.h"
#include "hch\CTownHandler.h"
#include "CPathfinder.h"
#include "CGameInfo.h"
#include "SDL_Extensions.h"
#include "CCallback.h" #include "CCallback.h"
#include <boost/assign/std/vector.hpp> #include <boost/assign/std/vector.hpp>
#include "mapHandler.h"
extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts extern TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX; //fonts
using namespace boost::logic; using namespace boost::logic;
@ -281,7 +286,8 @@ void CHeroList::keyPressed (SDL_KeyboardEvent & key)
{ {
} }
void CHeroList::draw() void CHeroList::draw()
{ for (int iT=0+from;iT<5+from;iT++) {
for (int iT=0+from;iT<5+from;iT++)
{ {
int i = iT-from; int i = iT-from;
if (iT>=items.size()) if (iT>=items.size())
@ -322,9 +328,24 @@ CTownList::CTownList()
pos = genRect(192,48,747,196); pos = genRect(192,48,747,196);
arrup = CGI->spriteh->giveDef("IAM014.DEF"); arrup = CGI->spriteh->giveDef("IAM014.DEF");
arrdo = CGI->spriteh->giveDef("IAM015.DEF"); arrdo = CGI->spriteh->giveDef("IAM015.DEF");
arrupp.x=747;
arrupp.y=196;
arrdop.x=747;
arrdop.y=372;
posporx = 747;
pospory = 211;
from = 0;
} }
void CTownList::genList() void CTownList::genList()
{ {
int howMany = LOCPLINT->cb->howManyTowns();
for (int i=0;i<howMany;i++)
{
items.push_back(LOCPLINT->cb->getTownInfo(i,0));
}
} }
void CTownList::select(int which) void CTownList::select(int which)
{ {
@ -345,7 +366,33 @@ void CTownList::keyPressed (SDL_KeyboardEvent & key)
{ {
} }
void CTownList::draw() void CTownList::draw()
{ {
for (int iT=0+from;iT<5+from;iT++)
{
int i = iT-from;
if (iT>=items.size())
{
blitAtWR(CGI->townh->getPic(-1),posporx,pospory+i*32);
continue;
}
blitAtWR(CGI->townh->getPic(items[i]->type),posporx,pospory+i*32);
if (selected == iT)
{
blitAtWR(CGI->townh->getPic(-2),posporx,pospory+i*32);
}
//TODO: dodac oznaczanie zbudowania w danej turze i posiadania fortu
}
if (from>0)
blitAtWR(arrup->ourImages[0].bitmap,arrupp.x,arrupp.y);
else
blitAtWR(arrup->ourImages[2].bitmap,arrupp.x,arrupp.y);
if (items.size()-from>5)
blitAtWR(arrdo->ourImages[0].bitmap,arrdop.x,arrdop.y);
else
blitAtWR(arrdo->ourImages[2].bitmap,arrdop.x,arrdop.y);
} }
CStatusBar::CStatusBar(int x, int y) CStatusBar::CStatusBar(int x, int y)
{ {
@ -758,7 +805,10 @@ CResDataBar::CResDataBar()
pos = genRect(bg->h,bg->w,3,575); pos = genRect(bg->h,bg->w,3,575);
txtpos += (std::pair<int,int>(35,577)),(std::pair<int,int>(120,577)),(std::pair<int,int>(205,577)), txtpos += (std::pair<int,int>(35,577)),(std::pair<int,int>(120,577)),(std::pair<int,int>(205,577)),
(std::pair<int,int>(290,577)),(std::pair<int,int>(375,577)),(std::pair<int,int>(460,577)),(std::pair<int,int>(545,577)); (std::pair<int,int>(290,577)),(std::pair<int,int>(375,577)),(std::pair<int,int>(460,577)),
(std::pair<int,int>(545,577)),(std::pair<int,int>(620,577));
datetext = CGI->generaltexth->allTexts[62]+": %s, " + CGI->generaltexth->allTexts[63] + ": %s, " +
CGI->generaltexth->allTexts[64] + ": %s";
} }
CResDataBar::~CResDataBar() CResDataBar::~CResDataBar()
@ -774,8 +824,14 @@ void CResDataBar::draw()
itoa(LOCPLINT->cb->getResourceAmount(i),buf,10); itoa(LOCPLINT->cb->getResourceAmount(i),buf,10);
printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly); printAt(buf,txtpos[i].first,txtpos[i].second,GEOR13,zwykly);
} }
delete buf; std::vector<std::string> temp;
itoa(LOCPLINT->cb->getDate(3),buf,10); temp+=std::string(buf);
itoa(LOCPLINT->cb->getDate(2),buf,10); temp+=std::string(buf);
itoa(LOCPLINT->cb->getDate(1),buf,10); temp+=std::string(buf);
printAt(processStr(datetext,temp),txtpos[7].first,txtpos[7].second,GEOR13,zwykly);
temp.clear();
updateRect(&pos,ekran); updateRect(&pos,ekran);
delete buf;
} }
CAdvMapInt::CAdvMapInt(int Player) CAdvMapInt::CAdvMapInt(int Player)
@ -824,6 +880,8 @@ endTurn(CGI->preth->advEndTurn.first,CGI->preth->advEndTurn.second,
heroList.init(); heroList.init();
heroList.genList(); heroList.genList();
//townList.init();
townList.genList();
gems.push_back(CGI->spriteh->giveDef("agemLL.def")); gems.push_back(CGI->spriteh->giveDef("agemLL.def"));
gems.push_back(CGI->spriteh->giveDef("agemLR.def")); gems.push_back(CGI->spriteh->giveDef("agemLR.def"));
@ -907,6 +965,8 @@ void CAdvMapInt::show()
minimap.draw(); minimap.draw();
heroList.activate(); heroList.activate();
heroList.draw(); heroList.draw();
townList.activate();
townList.draw();
resdatabar.draw(); resdatabar.draw();

View File

@ -1,18 +1,16 @@
#ifndef CADVENTUREMAPINTERFACE_H #ifndef CADVENTUREMAPINTERFACE_H
#define CADVENTUREMAPINTERFACE_H #define CADVENTUREMAPINTERFACE_H
#include <typeinfo> #include <typeinfo>
#include "SDL.h"
#include "hch\CDefHandler.h"
#include "SDL_Extensions.h"
#include "CGameInterface.h"
#include "CGameInfo.h"
#include "SDL_Extensions.h"
#include <boost/logic/tribool.hpp>
#include "global.h" #include "global.h"
#include "CPathfinder.h" #include "SDL.h"
#include "mapHandler.h" #include "CGameInterface.h"
#include <boost/logic/tribool.hpp>
#include <map>
class CDefHandler;
class CCallback; class CCallback;
class CTownInstance;
class CPath;
class AdventureMapButton class AdventureMapButton
: public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public CButtonBase : public ClickableL, public ClickableR, public Hoverable, public KeyInterested, public CButtonBase
@ -81,6 +79,8 @@ class CTownList
: public CList : public CList
{ {
public: public:
std::vector<const CTownInstance*> items;
int posporx,pospory;
CTownList(); CTownList();
void genList(); void genList();
@ -165,6 +165,7 @@ class CResDataBar
public: public:
SDL_Surface * bg; SDL_Surface * bg;
std::vector<std::pair<int,int> > txtpos; std::vector<std::pair<int,int> > txtpos;
std::string datetext;
void clickRight (tribool down); void clickRight (tribool down);
void activate(); void activate();

View File

@ -2,6 +2,7 @@
#include "CCallback.h" #include "CCallback.h"
#include "CPathfinder.h" #include "CPathfinder.h"
#include "hch\CHeroHandler.h" #include "hch\CHeroHandler.h"
#include "hch\CTownHandler.h"
#include "CGameInfo.h" #include "CGameInfo.h"
#include "hch\CAmbarCendamo.h" #include "hch\CAmbarCendamo.h"
#include "mapHandler.h" #include "mapHandler.h"
@ -51,6 +52,28 @@ bool CCallback::moveHero(int ID, int3 destPoint)
} }
int CCallback::howManyTowns()
{
return gs->players[gs->currentPlayer].towns.size();
}
const CTownInstance * CCallback::getTownInfo(int val, bool mode) //mode = 0 -> val = serial; mode = 1 -> val = ID
{
if (!mode)
return gs->players[gs->currentPlayer].towns[val];
else
{
//TODO: add some smart ID to the CTownInstance
//for (int i=0; i<gs->players[gs->currentPlayer].towns.size();i++)
//{
// if (gs->players[gs->currentPlayer].towns[i]->someID==val)
// return gs->players[gs->currentPlayer].towns[i];
//}
return NULL;
}
return NULL;
}
int CCallback::howManyHeroes(int player) int CCallback::howManyHeroes(int player)
{ {
if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info
@ -73,7 +96,30 @@ const CHeroInstance * CCallback::getHeroInfo(int player, int val, bool mode) //m
} }
return NULL; return NULL;
} }
int CCallback::getResourceAmount(int type) int CCallback::getResourceAmount(int type)
{ {
return gs->players[gs->currentPlayer].resources[type]; return gs->players[gs->currentPlayer].resources[type];
}
int CCallback::getDate(int mode)
{
int temp;
switch (mode)
{
case 0:
return gs->day;
case 1:
temp = (gs->day)%7;
if (temp)
return temp;
else return 7;
case 2:
temp = ((gs->day-1)/7)+1;
if (temp%4)
return temp;
else return 4;
case 3:
return ((gs->day-1)/28)+1;
}
} }

View File

@ -2,6 +2,7 @@
#define CCALLBACK_H #define CCALLBACK_H
class CGameState; class CGameState;
class CHeroInstance; class CHeroInstance;
class CTownInstance;
struct HeroMoveDetails struct HeroMoveDetails
{ {
int3 src, dst; //source and destination points int3 src, dst; //source and destination points
@ -20,9 +21,13 @@ public:
CCallback(CGameState * GS):gs(GS){}; CCallback(CGameState * GS):gs(GS){};
bool moveHero(int ID, int3 destPoint); bool moveHero(int ID, int3 destPoint);
int howManyTowns();
const CTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
int howManyHeroes(int player); int howManyHeroes(int player);
const CHeroInstance * getHeroInfo(int player, int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID const CHeroInstance * getHeroInfo(int player, int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID
int getResourceAmount(int type); int getResourceAmount(int type);
int getDate(int mode=0); //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month
}; };
#endif //CCALLBACK_H #endif //CCALLBACK_H

View File

@ -7,6 +7,8 @@
#include "global.h" #include "global.h"
#include "CGameState.h" #include "CGameState.h"
#include "CCallback.h" #include "CCallback.h"
#include "CPathfinder.h"
#include "mapHandler.h"
#include <sstream> #include <sstream>
int internalFunc(void * nothingUsed) int internalFunc(void * nothingUsed)

View File

@ -2,11 +2,13 @@
#include "CGameInterface.h" #include "CGameInterface.h"
#include "CAdvMapInterface.h" #include "CAdvMapInterface.h"
#include "CMessage.h" #include "CMessage.h"
#include "mapHandler.h"
#include "SDL_Extensions.h" #include "SDL_Extensions.h"
#include "SDL_framerate.h" #include "SDL_framerate.h"
#include "CScreenHandler.h" #include "CScreenHandler.h"
#include "CCursorHandler.h" #include "CCursorHandler.h"
#include "CCallback.h" #include "CCallback.h"
#include "SDL_Extensions.h"
using namespace CSDL_Ext; using namespace CSDL_Ext;
class OCM_HLP_CGIN class OCM_HLP_CGIN
{ {
@ -730,6 +732,7 @@ void CPlayerInterface::heroMoved(const HeroMoveDetails & details)
delObjRect(hp.x, hp.y, hp.z, ho->id); delObjRect(hp.x, hp.y, hp.z, ho->id);
} }
CGI->heroh->heroInstances[details.heroID]->pos = details.dst; //actualizing hero position CGI->heroh->heroInstances[details.heroID]->pos = details.dst; //actualizing hero position
CGI->heroh->heroInstances[details.heroID]->ourObject->pos = details.dst; //copy of hero's position
ho->moveDir = 0; //move ended ho->moveDir = 0; //move ended
//move finished //move finished
} }

View File

@ -2,16 +2,19 @@
#define CGAMEINTERFACE_H #define CGAMEINTERFACE_H
#include "SDL.h" #include "SDL.h"
#include "hch\CDefHandler.h"
#include "SDL_Extensions.h"
#include <boost/logic/tribool.hpp> #include <boost/logic/tribool.hpp>
#include "SDL_framerate.h" #include "SDL_framerate.h"
BOOST_TRIBOOL_THIRD_STATE(outOfRange) BOOST_TRIBOOL_THIRD_STATE(outOfRange)
using namespace boost::logic; using namespace boost::logic;
class CAdvMapInt; class CAdvMapInt;
class CCallback; class CCallback;
class CHeroInstance; class CHeroInstance;
class CDefHandler;
struct HeroMoveDetails; struct HeroMoveDetails;
class CIntObject //interface object class CIntObject //interface object
{ {
public: public:

View File

@ -13,17 +13,19 @@ public:
std::vector<int> resources; std::vector<int> resources;
std::vector<CHeroInstance *> heroes; std::vector<CHeroInstance *> heroes;
std::vector<CTownInstance *> towns; std::vector<CTownInstance *> towns;
PlayerState():color(-1){};
}; };
class CGameState class CGameState
{ {
int currentPlayer; int currentPlayer;
int day; //total number of days in game
std::map<int,PlayerState> players; //color <-> playerstate std::map<int,PlayerState> players; //color <-> playerstate
public: public:
friend CCallback; friend CCallback;
friend int _tmain(int argc, _TCHAR* argv[]); friend int _tmain(int argc, _TCHAR* argv[]);
friend void initGameState(CGameInfo * cgi); friend void initGameState(CGameInfo * cgi);
friend void CAmbarCendamo::deh3m();
CCallback * cb; //for communication between PlayerInterface/AI and GameState CCallback * cb; //for communication between PlayerInterface/AI and GameState
}; };

81
CMT.cpp
View File

@ -55,12 +55,6 @@
#define CHUNK 16384 #define CHUNK 16384
const char * NAME = "VCMI 0.3 \"Tol Galen\""; const char * NAME = "VCMI 0.3 \"Tol Galen\"";
/* Compress from file source to file dest until EOF on source.
def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_STREAM_ERROR if an invalid compression
level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
version of the library linked do not match, or Z_ERRNO if there is
an error reading or writing the files. */
SDL_Surface * ekran, * screen, * screen2; SDL_Surface * ekran, * screen, * screen2;
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM; TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
@ -85,10 +79,43 @@ TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
void initGameState(CGameInfo * cgi) void initGameState(CGameInfo * cgi)
{ {
cgi->state->day=1;
/*********creating players entries in gs****************************************/
for (int i=0; i<cgi->scenarioOps.playerInfos.size();i++)
{
std::pair<int,PlayerState> ins(cgi->scenarioOps.playerInfos[i].color,PlayerState());
cgi->state->players.insert(ins);
}
/******************RESOURCES****************************************************/
//TODO: zeby komputer dostawal inaczej niz gracz
std::vector<int> startres;
std::ifstream tis("config/startres.txt");
int k;
for (int j=0;j<cgi->scenarioOps.difficulty;j++)
{
tis >> k;
for (int z=0;z<RESOURCE_QUANTITY;z++)
tis>>k;
}
tis >> k;
for (int i=0;i<RESOURCE_QUANTITY;i++)
{
tis >> k;
startres.push_back(k);
}
tis.close();
for (std::map<int,PlayerState>::iterator i = cgi->state->players.begin(); i!=cgi->state->players.end(); i++)
{
(*i).second.resources.resize(RESOURCE_QUANTITY);
for (int x=0;x<RESOURCE_QUANTITY;x++)
(*i).second.resources[x] = startres[x];
}
/*************************HEROES************************************************/ /*************************HEROES************************************************/
for (int i=0; i<cgi->heroh->heroInstances.size();i++) //heroes instances for (int i=0; i<cgi->heroh->heroInstances.size();i++) //heroes instances
{ {
if (!cgi->heroh->heroInstances[i]->type || cgi->heroh->heroInstances[i]->owner<0 || cgi->heroh->heroInstances[i]->owner==255) if (!cgi->heroh->heroInstances[i]->type || cgi->heroh->heroInstances[i]->owner<0)
continue; continue;
CHeroInstance * vhi = new CHeroInstance(); CHeroInstance * vhi = new CHeroInstance();
*vhi=*(cgi->heroh->heroInstances[i]); *vhi=*(cgi->heroh->heroInstances[i]);
@ -121,31 +148,6 @@ void initGameState(CGameInfo * cgi)
cgi->state->players[vhi->owner].heroes.push_back(vhi); cgi->state->players[vhi->owner].heroes.push_back(vhi);
}
/******************RESOURCES****************************************************/
//TODO: zeby komputer dostawal inaczej niz gracz
std::vector<int> startres;
std::ifstream tis("config/startres.txt");
int k;
for (int j=0;j<cgi->scenarioOps.difficulty;j++)
{
tis >> k;
for (int z=0;z<RESOURCE_QUANTITY;z++)
tis>>k;
}
tis >> k;
for (int i=0;i<RESOURCE_QUANTITY;i++)
{
tis >> k;
startres.push_back(k);
}
tis.close();
for (std::map<int,PlayerState>::iterator i = cgi->state->players.begin(); i!=cgi->state->players.end(); i++)
{
(*i).second.resources.resize(RESOURCE_QUANTITY);
for (int x=0;x<RESOURCE_QUANTITY;x++)
(*i).second.resources[x] = startres[x];
} }
/*************************FOG**OF**WAR******************************************/ /*************************FOG**OF**WAR******************************************/
for(std::map<int, PlayerState>::iterator k=cgi->state->players.begin(); k!=cgi->state->players.end(); ++k) for(std::map<int, PlayerState>::iterator k=cgi->state->players.begin(); k!=cgi->state->players.end(); ++k)
@ -164,7 +166,14 @@ void initGameState(CGameInfo * cgi)
k->second.fogOfWarMap[g][h][v] = 1; k->second.fogOfWarMap[g][h][v] = 1;
} }
/****************************TOWNS************************************************/ /****************************TOWNS************************************************/
for (int i=0;i<cgi->townh->townInstances.size();i++)
{
CTownInstance * vti = new CTownInstance();
(*vti)=*(cgi->townh->townInstances[i]);
cgi->state->players[vti->owner].towns.push_back(vti);
}
} }
int _tmain(int argc, _TCHAR* argv[]) int _tmain(int argc, _TCHAR* argv[])
@ -228,13 +237,9 @@ int _tmain(int argc, _TCHAR* argv[])
GEORXX = TTF_OpenFont("Fonts\\tnrb.ttf",22); GEORXX = TTF_OpenFont("Fonts\\tnrb.ttf",22);
GEORM = TTF_OpenFont("Fonts\\georgia.ttf",10); GEORM = TTF_OpenFont("Fonts\\georgia.ttf",10);
//initializing audio CMusicHandler * mush = new CMusicHandler; //initializing audio
CMusicHandler * mush = new CMusicHandler;
mush->initMusics(); mush->initMusics();
//CSndHandler snd("Heroes3.snd");
//snd.extract("AELMMOVE.wav","snddd.wav");
//audio initialized //audio initialized
/*if(Mix_PlayMusic(mush->mainMenuWoG, -1)==-1) //uncomment this fragment to have music /*if(Mix_PlayMusic(mush->mainMenuWoG, -1)==-1) //uncomment this fragment to have music
{ {
printf("Mix_PlayMusic: %s\n", Mix_GetError()); printf("Mix_PlayMusic: %s\n", Mix_GetError());
@ -287,8 +292,6 @@ int _tmain(int argc, _TCHAR* argv[])
cgi->playerColors.push_back(p);//pink cgi->playerColors.push_back(p);//pink
p.r = 0x84; p.g = 0x84; p.b = 0x84;//gray p.r = 0x84; p.g = 0x84; p.b = 0x84;//gray
cgi->neutralColor = p;//gray cgi->neutralColor = p;//gray
cgi->playerColorInfo.push_back(cgi->spriteh->giveDef("agemLL.def")); //todo: finish
//colors initialized //colors initialized
cgi->townh = new CTownHandler; cgi->townh = new CTownHandler;

Binary file not shown.

View File

@ -1503,6 +1503,7 @@ void CAmbarCendamo::deh3m()
nobj->info = spec; nobj->info = spec;
//////////// rewriting info to CTownInstance class ///////////////////// //////////// rewriting info to CTownInstance class /////////////////////
CTownInstance * nt = new CTownInstance; CTownInstance * nt = new CTownInstance;
nt->owner = spec->player;
nt->type = CTownHandler::getTypeByDefName(map.defy[nobj->defNumber].name); nt->type = CTownHandler::getTypeByDefName(map.defy[nobj->defNumber].name);
nt->builded = 0; nt->builded = 0;
nt->destroyed = 0; nt->destroyed = 0;
@ -1512,7 +1513,7 @@ void CAmbarCendamo::deh3m()
nt->pos = int3(spec->x, spec->y, spec->z); nt->pos = int3(spec->x, spec->y, spec->z);
nt->possibleSpells = spec->possibleSpells; nt->possibleSpells = spec->possibleSpells;
nt->obligatorySpells = spec->obligatorySpells; nt->obligatorySpells = spec->obligatorySpells;
CGI->state->players[spec->player].towns.push_back(nt); CGI->townh->townInstances.push_back(nt);
break; break;
} }
case EDefType::PLAYERONLY_DEF: case EDefType::PLAYERONLY_DEF:

View File

@ -11,6 +11,7 @@
class CBuilding; class CBuilding;
class CSpell; class CSpell;
class CHero; class CHero;
class CTownInstance;
class CTown class CTown
{ {
@ -30,6 +31,9 @@ public:
void loadNames(); void loadNames();
SDL_Surface * getPic(int ID, bool fort=true, bool builded=false); //ID=-1 - blank; -2 - border; -3 - random SDL_Surface * getPic(int ID, bool fort=true, bool builded=false); //ID=-1 - blank; -2 - border; -3 - random
static int getTypeByDefName(std::string name); static int getTypeByDefName(std::string name);
std::vector<CTownInstance *> townInstances;
}; };
class CTownInstance class CTownInstance