1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-05-13 22:06:58 +02:00
This commit is contained in:
Michał W. Urbańczyk 2007-10-21 16:45:13 +00:00
parent d1fa849071
commit 04985fce2f
13 changed files with 146 additions and 27 deletions

View File

@ -1,4 +1,13 @@
#include "CEmptyAI.h" #include "CEmptyAI.h"
#include <iostream>
void CEmptyAI::init(CCallback * CB)
{
cb = CB;
human=false;
playerID=-1;
serialID=-1;
std::cout << "EmptyAI initialized." << std::endl;
}
void CEmptyAI::yourTurn() void CEmptyAI::yourTurn()
{ {
} }

View File

@ -1,8 +1,10 @@
#include "../../AI_Base.h" #include "../../AI_Base.h"
class CEmptyAI : public CAIBase class CEmptyAI : public CGlobalAI
{ {
CCallback * cb;
public: public:
void init(CCallback * CB);
void yourTurn(); void yourTurn();
void heroKilled(const CHeroInstance *); void heroKilled(const CHeroInstance *);
void heroCreated(const CHeroInstance *); void heroCreated(const CHeroInstance *);

View File

@ -36,6 +36,8 @@
/> />
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0"
DebugInformationFormat="3"
/> />
<Tool <Tool
Name="VCManagedResourceCompilerTool" Name="VCManagedResourceCompilerTool"
@ -48,7 +50,12 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
OutputFile="EmptyAI.dll" OutputFile="../EmptyAI.dll"
Version="0.1"
GenerateDebugInformation="true"
GenerateMapFile="true"
MapFileName="mapfile.map"
MapExports="true"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"
@ -98,6 +105,12 @@
/> />
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="3"
InlineFunctionExpansion="2"
EnableIntrinsicFunctions="true"
FavorSizeOrSpeed="1"
EnableFiberSafeOptimizations="true"
WholeProgramOptimization="true"
/> />
<Tool <Tool
Name="VCManagedResourceCompilerTool" Name="VCManagedResourceCompilerTool"
@ -110,7 +123,7 @@
/> />
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
OutputFile="EmptyAI.dll" OutputFile="../EmptyAI.dll"
/> />
<Tool <Tool
Name="VCALinkTool" Name="VCALinkTool"

View File

@ -2,7 +2,7 @@
#include "CEmptyAI.h" #include "CEmptyAI.h"
#include <cstring> #include <cstring>
#include <set> #include <set>
std::set<CAIBase*> ais; std::set<CGlobalAI*> ais;
DLL_EXPORT int GetGlobalAiVersion() DLL_EXPORT int GetGlobalAiVersion()
{ {
@ -13,13 +13,19 @@ DLL_EXPORT void GetAiName(char* name)
{ {
strcpy(name,NAME); strcpy(name,NAME);
} }
DLL_EXPORT CAIBase * GetNewAI() DLL_EXPORT char * GetAiNameS()
{
char * ret = new char[50];
strcpy(ret,NAME);
return ret;
}
DLL_EXPORT CGlobalAI * GetNewAI()
{ {
return new CEmptyAI(); return new CEmptyAI();
// return // return
} }
DLL_EXPORT void ReleaseAI(CAIBase * i) DLL_EXPORT void ReleaseAI(CGlobalAI * i)
{ {
//delete (TTAICore*)i; delete (CEmptyAI*)i;
//ais.erase(i); ais.erase(i);
} }

View File

@ -3,9 +3,6 @@
#include <iostream> #include <iostream>
#include "int3.h" #include "int3.h"
#include "CGameInterface.h" #include "CGameInterface.h"
class CAIBase : public CGameInterface
{
};
#define AI_INTERFACE_VER 1 #define AI_INTERFACE_VER 1
#ifdef _WIN32 #ifdef _WIN32

View File

@ -1069,8 +1069,11 @@ CResDataBar::CResDataBar()
{ {
bg = CGI->bitmaph->loadBitmap("ZRESBAR.bmp"); bg = CGI->bitmaph->loadBitmap("ZRESBAR.bmp");
SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
blueToPlayersAdv(bg,LOCPLINT->playerID); //std::vector<SDL_Color> kolory;
//blueToPlayersNice(bg,LOCPLINT->playerID); //SDL_Color p1={40,65,139,255}, p2={36,59,125,255}, p3={35,56,121,255};
//kolory+=p1,p2,p3;
//blueToPlayersAdv(bg,LOCPLINT->playerID,2,&kolory);
blueToPlayersAdv(bg,LOCPLINT->playerID,2);
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)),
@ -1221,6 +1224,7 @@ void CAdvMapInt::fnextHero()
} }
void CAdvMapInt::fendTurn() void CAdvMapInt::fendTurn()
{ {
LOCPLINT->makingTurn = false;
} }
void CAdvMapInt::show() void CAdvMapInt::show()
@ -1262,6 +1266,23 @@ void CAdvMapInt::show()
SDL_Flip(ekran); SDL_Flip(ekran);
} }
void CAdvMapInt::hide()
{
kingOverview.deactivate();
underground.deactivate();
questlog.deactivate();
sleepWake.deactivate();
moveHero.deactivate();
spellbook.deactivate();
advOptions.deactivate();
sysOptions.deactivate();
nextHero.deactivate();
endTurn.deactivate();
minimap.deactivate();
heroList.deactivate();
townList.deactivate();
terrain.deactivate();
}
void CAdvMapInt::update() void CAdvMapInt::update()
{ {
terrain.show(); terrain.show();

View File

@ -253,6 +253,7 @@ public:
void fendTurn(); void fendTurn();
void show(); //shows and activates adv. map interface void show(); //shows and activates adv. map interface
void hide(); //deactivates advmap interface
void update(); //redraws terrain void update(); //redraws terrain
void centerOn(int3 on); void centerOn(int3 on);

View File

@ -32,6 +32,7 @@ int CCallback::valMovePoints(CHeroInstance * chi)
void CCallback::newTurn() void CCallback::newTurn()
{ {
//std::map<int, PlayerState>::iterator i = gs->players.begin() ; //std::map<int, PlayerState>::iterator i = gs->players.begin() ;
gs->day++;
for ( std::map<int, PlayerState>::iterator i=gs->players.begin() ; i!=gs->players.end();i++) 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++) for (int j=0;j<(*i).second.heroes.size();j++)

View File

@ -12,6 +12,12 @@
#include "hch/CLodHandler.h" #include "hch/CLodHandler.h"
#include "CPathfinder.h" #include "CPathfinder.h"
#include <sstream> #include <sstream>
#ifdef _WIN32
#include <windows.h> //for .dll libs
#else
#include <dlfcn.h>
#endif
using namespace CSDL_Ext; using namespace CSDL_Ext;
class OCM_HLP_CGIN class OCM_HLP_CGIN
{ {
@ -111,6 +117,37 @@ void MotionInterested::deactivate()
LOCPLINT-> LOCPLINT->
motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this)); motioninterested.erase(std::find(LOCPLINT->motioninterested.begin(),LOCPLINT->motioninterested.end(),this));
} }
CGlobalAI * CAIHandler::getNewAI(CCallback * cb, std::string dllname)
{
dllname = "AI/"+dllname;
CGlobalAI * ret=NULL;
CGlobalAI*(*getAI)();
void(*getName)(char*);
#ifdef _WIN32
HINSTANCE dll = LoadLibraryA(dllname.c_str());
if (!dll)
{
std::cout << "Cannot open AI library ("<<dllname<<"). Throwing..."<<std::endl;
throw new std::exception("Cannot open AI library");
}
//int len = dllname.size()+1;
getName = (void(*)(char*))GetProcAddress(dll,"GetAiName");
getAI = (CGlobalAI*(*)())GetProcAddress(dll,"GetNewAI");
#else
; //TODO: handle AI library on Linux
#endif
char * temp = new char[50];
getName(temp);
std::cout << "Loaded .dll with AI named " << temp << std::endl;
delete temp;
ret = getAI();
ret->init(cb);
return ret;
}
//CGlobalAI::CGlobalAI()
//{
//}
CPlayerInterface::CPlayerInterface(int Player, int serial) CPlayerInterface::CPlayerInterface(int Player, int serial)
{ {
playerID=Player; playerID=Player;
@ -145,6 +182,7 @@ void CPlayerInterface::init(CCallback * CB)
} }
void CPlayerInterface::yourTurn() void CPlayerInterface::yourTurn()
{ {
makingTurn = true;
CGI->localPlayer = serialID; CGI->localPlayer = serialID;
unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling
adventureInt->show(); adventureInt->show();
@ -156,7 +194,7 @@ void CPlayerInterface::yourTurn()
SDL_setFramerate(mainFPSmng, 24); SDL_setFramerate(mainFPSmng, 24);
SDL_Event sEvent; SDL_Event sEvent;
//framerate keeper initialized //framerate keeper initialized
for(;;) // main loop for(;makingTurn;) // main loop
{ {
CGI->screenh->updateScreen(); CGI->screenh->updateScreen();
@ -215,6 +253,7 @@ void CPlayerInterface::yourTurn()
SDL_Delay(5); //give time for other apps SDL_Delay(5); //give time for other apps
SDL_framerateDelay(mainFPSmng); SDL_framerateDelay(mainFPSmng);
} }
adventureInt->hide();
} }
inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid) inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
@ -807,7 +846,7 @@ SDL_Surface * CPlayerInterface::infoWin(void * specific) //specific=0 => draws i
char * buf = new char[10]; char * buf = new char[10];
SDL_Surface * ret = copySurface(hInfo); SDL_Surface * ret = copySurface(hInfo);
SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255));
blueToPlayersAdv(ret,playerID); // zygzyg - nie koloruje, tylko odrobine smieci blueToPlayersAdv(ret,playerID,1);
const CHeroInstance * curh = (const CHeroInstance *)adventureInt->selection.selected; const CHeroInstance * curh = (const CHeroInstance *)adventureInt->selection.selected;
printAt(curh->name,75,15,GEOR13,zwykly,ret); printAt(curh->name,75,15,GEOR13,zwykly,ret);
for (int i=0;i<PRIMARY_SKILLS;i++) for (int i=0;i<PRIMARY_SKILLS;i++)

View File

@ -91,15 +91,23 @@ public:
bool human; bool human;
int playerID, serialID; int playerID, serialID;
virtual void init(CCallback * CB)=0{};
virtual void yourTurn()=0{}; virtual void yourTurn()=0{};
virtual void heroKilled(const CHeroInstance * hero)=0{}; virtual void heroKilled(const CHeroInstance * hero)=0{};
virtual void heroCreated(const CHeroInstance * hero)=0{}; virtual void heroCreated(const CHeroInstance * hero)=0{};
virtual void heroMoved(const HeroMoveDetails & details)=0; virtual void heroMoved(const HeroMoveDetails & details)=0;
}; };
class CGlobalAI;
class CAIHandler
{
public:
static CGlobalAI * getNewAI(CCallback * cb, std::string dllname);
};
class CGlobalAI : public CGameInterface // AI class (to derivate) class CGlobalAI : public CGameInterface // AI class (to derivate)
{ {
public: public:
//CGlobalAI();
virtual void yourTurn(){}; virtual void yourTurn(){};
virtual void heroKilled(const CHeroInstance * hero){}; virtual void heroKilled(const CHeroInstance * hero){};
virtual void heroCreated(const CHeroInstance * hero){}; virtual void heroCreated(const CHeroInstance * hero){};
@ -107,6 +115,7 @@ public:
class CPlayerInterface : public CGameInterface class CPlayerInterface : public CGameInterface
{ {
public: public:
bool makingTurn;
SDL_Event * current; SDL_Event * current;
CAdvMapInt * adventureInt; CAdvMapInt * adventureInt;
FPSmanager * mainFPSmng; FPSmanager * mainFPSmng;

10
CMT.cpp
View File

@ -60,7 +60,7 @@ TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM;
void initGameState(CGameInfo * cgi) void initGameState(CGameInfo * cgi)
{ {
cgi->state->day=1; cgi->state->day=0;
/*********creating players entries in gs****************************************/ /*********creating players entries in gs****************************************/
for (int i=0; i<cgi->scenarioOps.playerInfos.size();i++) for (int i=0; i<cgi->scenarioOps.playerInfos.size();i++)
{ {
@ -649,11 +649,9 @@ int _tmain(int argc, _TCHAR* argv[])
for (int i=0; i<cgi->scenarioOps.playerInfos.size();i++) //initializing interfaces for (int i=0; i<cgi->scenarioOps.playerInfos.size();i++) //initializing interfaces
{ {
//TODO: uncomment when AI will be done if(cgi->scenarioOps.playerInfos[i].name=="Computer")
cgi->playerint.push_back(CAIHandler::getNewAI(new CCallback(cgi->state,cgi->scenarioOps.playerInfos[i].color),"EmptyAI.dll"));
//if(cgi->scenarioOps.playerInfos[i].name=="AI") else
// cgi->playerint.push_back(new CGlobalAI());
//else
{ {
cgi->state->currentPlayer=cgi->scenarioOps.playerInfos[i].color; cgi->state->currentPlayer=cgi->scenarioOps.playerInfos[i].color;
cgi->playerint.push_back(new CPlayerInterface(cgi->scenarioOps.playerInfos[i].color,i)); cgi->playerint.push_back(new CPlayerInterface(cgi->scenarioOps.playerInfos[i].color,i));

View File

@ -8,7 +8,6 @@
#include "CMessage.h" #include "CMessage.h"
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include "hch\CDefHandler.h" #include "hch\CDefHandler.h"
SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given
{ {
return SDL_CreateRGBSurface(mod->flags,w,h,mod->format->BitsPerPixel,mod->format->Rmask,mod->format->Gmask,mod->format->Bmask,mod->format->Amask); return SDL_CreateRGBSurface(mod->flags,w,h,mod->format->BitsPerPixel,mod->format->Rmask,mod->format->Gmask,mod->format->Bmask,mod->format->Amask);
@ -538,17 +537,34 @@ void CSDL_Ext::blueToPlayers(SDL_Surface * sur, int player)
} }
} }
void CSDL_Ext::blueToPlayersAdv(SDL_Surface * sur, int player) void CSDL_Ext::blueToPlayersAdv(SDL_Surface * sur, int player, int mode, void* additionalInfo)
{ {
if(player==1) //it is actually blue... if(player==1) //it is actually blue...
return; return;
if(sur->format->BitsPerPixel == 8) if(sur->format->BitsPerPixel == 8)
{ {
for(int i=0; i<sur->format->palette->ncolors; ++i) for(int i=0; i<sur->format->palette->ncolors; ++i) //message, button, avmap, resbar
{ {
SDL_Color * cc = sur->format->palette->colors+i; SDL_Color * cc = sur->format->palette->colors+i;
if(cc->b>cc->g && cc->b>cc->r) if(
((mode==0) && (cc->b>cc->g) && (cc->b>cc->r)) ||
((mode==1) && (cc->r<45) && (cc->b>80) && (cc->g<70) && ((cc->b-cc->r)>40)) ||
((mode==2) && (cc->r<110) && (cc->b>63) && (cc->g<122) && ((cc->b-cc->r)>44) && ((cc->b-cc->g)>32))
)
{ {
if ((mode==2) && additionalInfo)
{
for (int vi=0; vi<((std::vector<SDL_Color>*)additionalInfo)->size(); vi++)
{
if
(
((*((std::vector<SDL_Color>*)additionalInfo))[vi].r==cc->r) &&
((*((std::vector<SDL_Color>*)additionalInfo))[vi].g==cc->g) &&
((*((std::vector<SDL_Color>*)additionalInfo))[vi].b==cc->b)
)
goto main8bitloopend;
}
}
std::vector<long long int> sort1; std::vector<long long int> sort1;
sort1.push_back(cc->r); sort1.push_back(cc->r);
sort1.push_back(cc->g); sort1.push_back(cc->g);
@ -569,6 +585,8 @@ void CSDL_Ext::blueToPlayersAdv(SDL_Surface * sur, int player)
(*sort2[hh].second) = (sort1[hh]*0.8 + sort2[hh].first)/2; (*sort2[hh].second) = (sort1[hh]*0.8 + sort2[hh].first)/2;
} }
} }
main8bitloopend:
;
} }
} }
else if(sur->format->BitsPerPixel == 24) else if(sur->format->BitsPerPixel == 24)
@ -605,7 +623,10 @@ void CSDL_Ext::blueToPlayersAdv(SDL_Surface * sur, int player)
} }
else else
{ {
if(cp[0]>cp[1] && cp[0]>cp[2]) if(
((mode==0) && (cp[0]>cp[1]) && (cp[0]>cp[2])) ||
((mode==1) && (cp[2]<45) && (cp[0]>80) && (cp[1]<70) && ((cp[0]-cp[1])>40))
)
{ {
std::vector<long long int> sort1; std::vector<long long int> sort1;
sort1.push_back(cp[2]); sort1.push_back(cp[2]);

View File

@ -31,7 +31,9 @@ namespace CSDL_Ext
void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest void printAt(std::string text, int x, int y, TTF_Font * font, SDL_Color kolor=tytulowy, SDL_Surface * dst=ekran, unsigned char quality = 2); // quality: 0 - lowest, 1 - medium, 2 - highest
void update(SDL_Surface * what = ekran); //updates whole surface (default - main screen) void update(SDL_Surface * what = ekran); //updates whole surface (default - main screen)
void blueToPlayers(SDL_Surface * sur, int player); //simple color substitution void blueToPlayers(SDL_Surface * sur, int player); //simple color substitution
void blueToPlayersAdv(SDL_Surface * sur, int player); //substitute blue color by another one, makes it nicer keeping nuances void blueToPlayersAdv(SDL_Surface * sur, int player, int mode=0, void* additionalInfo=NULL); //substitute blue color by another one, makes it nicer keeping nuances
//mode 1 is calibrated for hero infobox
//mode 2 is calibrated for resbar and gets in additionalInfo a pointer to the set of (SDL_Color) which shouldn't be replaced
void blueToPlayersNice(SDL_Surface * sur, int player); //uses interface gems to substitute colours void blueToPlayersNice(SDL_Surface * sur, int player); //uses interface gems to substitute colours
void setPlayerColor(SDL_Surface * sur, unsigned char player); //sets correct color of flags; -1 for neutral 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 std::string processStr(std::string str, std::vector<std::string> & tor); //replaces %s in string