ソースを参照

* added #42 and #30
* one more file for AIs

Michał W. Urbańczyk 18 年 前
コミット
2286d37012
5 ファイル変更124 行追加27 行削除
  1. 19 0
      AI_Base.h
  2. 47 2
      CAdvmapInterface.cpp
  3. 40 14
      CCallback.cpp
  4. 14 9
      CCallback.h
  5. 4 2
      CGameInterface.cpp

+ 19 - 0
AI_Base.h

@@ -0,0 +1,19 @@
+#pragma once
+#include <vector>
+#include <iostream>
+#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

+ 47 - 2
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<howMany;i++)
 	{
 		items.push_back(std::pair<const CHeroInstance *,CPath *>(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;i<TERRAIN_TYPES;i++)
 	{
@@ -603,7 +603,52 @@ CMinimap::CMinimap(bool draw)
 }
 void CMinimap::draw()
 {
+	//draw terrain
 	blitAtWR(map[LOCPLINT->adventureInt->position.z],pos.x,pos.y);
+
+	//draw heroes
+	std::vector <const CHeroInstance *> * 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; i<hh->size();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; ii<wo; ii++)
+		{
+			for (int jj=0; jj<ho; jj++)
+			{
+				SDL_PutPixel(ekran,maplgp.x+pos.x+ii,maplgp.y+pos.y+jj,CGI->playerColors[(*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; i<mw; i++)
+	{
+		for (int j=0; j<mh; j++)
+		{
+			int3 pp;
+			pp.x = (((float)i/mw)*CGI->mh->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<wo; ii++)
+				{
+					for (int jj=0; jj<ho; jj++)
+					{
+						if ((i+ii<pos.w-1) && (j+jj<pos.h-1))
+							SDL_PutPixel(ekran,i+pos.x+ii,j+pos.y+jj,0,0,0);
+					}
+				}
+			}
+		}
+	}
+
 }
 void CMinimap::redraw(int level)// (level==-1) => redraw all levels
 {

+ 40 - 14
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<int, PlayerState>::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; xd<CGI->ac->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<int, PlayerState>::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<unsigned char> > > & 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<int, PlayerState>::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<int, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++)
+	return ret;
+}
+
+bool CCallback::isVisible(int3 pos)
+{
+	return isVisible(pos,player);
 }

+ 14 - 9
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<unsigned char> > > & 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<unsigned char> > > & 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[]);
 };
 

+ 4 - 2
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;