diff --git a/AI_Base.h b/AI_Base.h new file mode 100644 index 000000000..52d378114 --- /dev/null +++ b/AI_Base.h @@ -0,0 +1,19 @@ +#pragma once +#include +#include +#include "int3.h" +#include "CGameInterface.h" +class CAIBase : public CGameInterface +{ +}; + +#define AI_INTERFACE_VER 1 +#ifdef _WIN32 + #define DLL_EXPORT extern "C" __declspec(dllexport) + #define VCMI_API +#elif __GNUC__ >= 4 + #define DLL_EXPORT extern "C" __attribute__ ((visibility("default"))) + #define VCMI_API __attribute__ ((visibility("default"))) +#else + #define VCMI_EXPORT extern "C" +#endif \ No newline at end of file diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index a76e0acc9..2a5f6ad88 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -172,7 +172,7 @@ void CHeroList::init() } void CHeroList::genList() { - int howMany = LOCPLINT->cb->howManyHeroes(LOCPLINT->playerID); + int howMany = LOCPLINT->cb->howManyHeroes(); for (int i=0;i(LOCPLINT->cb->getHeroInfo(LOCPLINT->playerID,i,0),NULL)); @@ -572,7 +572,7 @@ CMinimap::CMinimap(bool draw) pos.x=630; pos.y=26; pos.h=pos.w=144; - radar = CGI->spriteh->giveDef("RADAR.DEF"); + //radar = CGI->spriteh->giveDef("RADAR.DEF"); std::ifstream is("config/minimap.txt",std::ifstream::in); for (int i=0;iadventureInt->position.z],pos.x,pos.y); + + //draw heroes + std::vector * hh = LOCPLINT->cb->getHeroesInfo(false); + int mw = map[0]->w, mh = map[0]->h, + wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y; + for (int i=0; isize();i++) + { + int3 hpos = (*hh)[i]->getPosition(false); + float zawx = ((float)hpos.x/CGI->mh->sizes.x), zawy = ((float)hpos.y/CGI->mh->sizes.y); + int3 maplgp ( zawx*mw, zawy*mh, hpos.z ); + for (int ii=0; iiplayerColors[(*hh)[i]->owner].r,CGI->playerColors[(*hh)[i]->owner].g,CGI->playerColors[(*hh)[i]->owner].b); + } + } + } + SDL_UpdateRect(ekran,pos.x,pos.y,pos.w,pos.h); + delete hh; + + //draw FoW + for (int i=0; imh->sizes.x); + pp.y = (((float)j/mh)*CGI->mh->sizes.y); + pp.z = LOCPLINT->adventureInt->position.z; + if ( !LOCPLINT->cb->isVisible(pp) ) + { + for (int ii=0; ii redraw all levels { diff --git a/CCallback.cpp b/CCallback.cpp index 48c2c88bf..e39713354 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -105,16 +105,6 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) if((hero->movement>=CGI->mh->getCost(stpos, endpos, hero)) || player==-1) { //performing move hero->movement-=CGI->mh->getCost(stpos, endpos, hero); - int nn=0; //number of interfece of currently browsed player - for(std::map::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing - { - if(j->second.fogOfWarMap[stpos.x-1][stpos.y][stpos.z] || j->second.fogOfWarMap[endpos.x-1][endpos.y][endpos.z]) - { //player should be notified - CGI->playerint[nn]->heroMoved(curd); - } - ++nn; - break; //for testing only - } for(int xd=0; xdac->map.width; ++xd) //revealing part of map around heroes { @@ -126,10 +116,21 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType) gs->players[player].fogOfWarMap[xd][yd][hero->getPosition(false).z] = 1; } } + + hero->pos = curd.dst; + int nn=0; //number of interfece of currently browsed player + for(std::map::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing + { + if(j->second.fogOfWarMap[stpos.x-1][stpos.y][stpos.z] || j->second.fogOfWarMap[endpos.x-1][endpos.y][endpos.z]) + { //player should be notified + CGI->playerint[nn]->heroMoved(curd); + } + ++nn; + break; //for testing only + } } else return true; //move ended - no more movement points - hero->pos = curd.dst; hero->ourObject->pos = curd.dst; } return true; @@ -158,10 +159,8 @@ const CTownInstance * CCallback::getTownInfo(int val, bool mode) //mode = 0 -> v } return NULL; } -int CCallback::howManyHeroes(int player) +int CCallback::howManyHeroes() { - if (gs->currentPlayer!=player) //TODO: checking if we are allowed to give that info - return -1; return gs->players[player].heroes.size(); } const CHeroInstance * CCallback::getHeroInfo(int player, int val, bool mode) //mode = 0 -> val = serial; mode = 1 -> val = ID @@ -250,4 +249,31 @@ std::vector < std::string > CCallback::getObjDescriptions(int3 pos) PseudoV< PseudoV< PseudoV > > & CCallback::getVisibilityMap() { return gs->players[player].fogOfWarMap; +} + + +bool CCallback::isVisible(int3 pos, int Player) +{ + return gs->players[Player].fogOfWarMap[pos.x][pos.y][pos.z]; +} + +std::vector < const CHeroInstance *> * CCallback::getHeroesInfo(bool onlyOur) +{ + std::vector < const CHeroInstance *> * ret = new std::vector < const CHeroInstance *>(); + for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) + { + for (int j=0;j<(*i).second.heroes.size();j++) + { + if ( ( isVisible((*i).second.heroes[j]->getPosition(false),player) ) || (*i).first==player) + { + ret->push_back((*i).second.heroes[j]); + } + } + } // for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) + return ret; +} + +bool CCallback::isVisible(int3 pos) +{ + return isVisible(pos,player); } \ No newline at end of file diff --git a/CCallback.h b/CCallback.h index 5a5a466d0..004272f95 100644 --- a/CCallback.h +++ b/CCallback.h @@ -24,25 +24,30 @@ private: CGameState * gs; int lowestSpeed(CHeroInstance * chi); //speed of the slowest stack int valMovePoints(CHeroInstance * chi); + bool isVisible(int3 pos, int Player); 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 - std::vector < std::string > getObjDescriptions(int3 pos); //returns descriptions of objects at pos in order from the lowest to the highest - int howManyTowns(); - const CTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID - - int howManyHeroes(int player); +//get info + bool verifyPath(CPath * path, bool blockSea); + int getDate(int mode=0); //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month + PseudoV< PseudoV< PseudoV > > & getVisibilityMap(); //returns visibility map (TODO: make it const) const CHeroInstance * getHeroInfo(int player, int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID int getResourceAmount(int type); - PseudoV< PseudoV< PseudoV > > & getVisibilityMap(); //returns visibility map (TODO: make it const) - int getDate(int mode=0); //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month - bool verifyPath(CPath * path, bool blockSea); - + int howManyHeroes(); + const CTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID + int howManyTowns(); + std::vector < std::string > getObjDescriptions(int3 pos); //returns descriptions of objects at pos in order from the lowest to the highest + std::vector < const CHeroInstance *> * getHeroesInfo(bool onlyOur=true); + bool isVisible(int3 pos); + +//friends friend int _tmain(int argc, _TCHAR* argv[]); }; diff --git a/CGameInterface.cpp b/CGameInterface.cpp index 5340891af..c1387aa91 100644 --- a/CGameInterface.cpp +++ b/CGameInterface.cpp @@ -233,6 +233,7 @@ inline void delObjRect(const int & x, const int & y, const int & z, const int & void CPlayerInterface::heroMoved(const HeroMoveDetails & details) { + adventureInt->minimap.draw(); //initializing objects and performing first step of move CObjectInstance * ho = details.ho; //object representing this hero int3 hp = details.src; @@ -831,8 +832,9 @@ SDL_Surface * CPlayerInterface::infoWin(void * specific) //specific=0 => draws i } else if (adventureInt->selection.type == TOWNI_TYPE) { - //TODO: do it - return NULL; + char * buf = new char[10]; + SDL_Surface * ret = copySurface(hInfo); + return ret; } else return NULL;