mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Improvements for netcode. AI is working. Townlist won't crash. Moving hero is wrong but won't crash. Giving starting hero is working properly. Town defs are wrong but displayed.
This commit is contained in:
parent
b3c5f19c0d
commit
62b0365e70
@ -10,6 +10,7 @@ void CEmptyAI::init(ICallback * CB)
|
||||
}
|
||||
void CEmptyAI::yourTurn()
|
||||
{
|
||||
cb->endTurn();
|
||||
}
|
||||
void CEmptyAI::heroKilled(const CGHeroInstance *)
|
||||
{
|
||||
|
@ -1,30 +1,30 @@
|
||||
#define VCMI_DLL
|
||||
#include "../../AI_Base.h"
|
||||
#include "CEmptyAI.h"
|
||||
#include <cstring>
|
||||
#include <set>
|
||||
std::set<CGlobalAI*> ais;
|
||||
|
||||
DLL_EXPORT int GetGlobalAiVersion()
|
||||
extern "C" DLL_EXPORT int GetGlobalAiVersion()
|
||||
{
|
||||
return AI_INTERFACE_VER;
|
||||
}
|
||||
|
||||
DLL_EXPORT void GetAiName(char* name)
|
||||
extern "C" DLL_EXPORT void GetAiName(char* name)
|
||||
{
|
||||
strcpy(name,NAME);
|
||||
}
|
||||
DLL_EXPORT char * GetAiNameS()
|
||||
extern "C" DLL_EXPORT char * GetAiNameS()
|
||||
{
|
||||
char * ret = new char[50];
|
||||
strcpy(ret,NAME);
|
||||
return ret;
|
||||
}
|
||||
DLL_EXPORT CGlobalAI * GetNewAI()
|
||||
extern "C" DLL_EXPORT CGlobalAI * GetNewAI()
|
||||
{
|
||||
return new CEmptyAI();
|
||||
// return
|
||||
}
|
||||
DLL_EXPORT void ReleaseAI(CGlobalAI * i)
|
||||
extern "C" DLL_EXPORT void ReleaseAI(CGlobalAI * i)
|
||||
{
|
||||
delete (CEmptyAI*)i;
|
||||
ais.erase(i);
|
||||
|
12
AI_Base.h
12
AI_Base.h
@ -1,16 +1,6 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include "int3.h"
|
||||
#include "CGameInterface.h"
|
||||
|
||||
#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
|
||||
#define AI_INTERFACE_VER 1
|
@ -216,17 +216,17 @@ void CMinimap::deactivate()
|
||||
}
|
||||
void CMinimap::showTile(int3 pos)
|
||||
{
|
||||
int mw = map[0]->w, mh = map[0]->h;
|
||||
double wo = ((double)mw)/CGI->mh->sizes.x, ho = ((double)mh)/CGI->mh->sizes.y;
|
||||
for (int ii=0; ii<wo; ii++)
|
||||
{
|
||||
for (int jj=0; jj<ho; jj++)
|
||||
{
|
||||
if ((pos.x*wo+ii<this->pos.w) && (pos.y*ho+jj<this->pos.h))
|
||||
CSDL_Ext::SDL_PutPixel(FoW[pos.z],pos.x*wo+ii,pos.y*ho+jj,0,0,0,0,0);
|
||||
//int mw = map[0]->w, mh = map[0]->h;
|
||||
//double wo = ((double)mw)/CGI->mh->sizes.x, ho = ((double)mh)/CGI->mh->sizes.y;
|
||||
//for (int ii=0; ii<wo; ii++)
|
||||
//{
|
||||
// for (int jj=0; jj<ho; jj++)
|
||||
// {
|
||||
// if ((pos.x*wo+ii<this->pos.w) && (pos.y*ho+jj<this->pos.h))
|
||||
// CSDL_Ext::SDL_PutPixel(FoW[pos.z],pos.x*wo+ii,pos.y*ho+jj,0,0,0,0,0);
|
||||
|
||||
}
|
||||
}
|
||||
// }
|
||||
//}
|
||||
}
|
||||
void CMinimap::hideTile(int3 pos)
|
||||
{
|
||||
@ -598,10 +598,6 @@ CResDataBar::CResDataBar()
|
||||
{
|
||||
bg = BitmapHandler::loadBitmap("ZRESBAR.bmp");
|
||||
SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255));
|
||||
//std::vector<SDL_Color> kolory;
|
||||
//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);
|
||||
graphics->blueToPlayersAdv(bg,LOCPLINT->playerID);
|
||||
pos = genRect(bg->h,bg->w,3,575);
|
||||
|
||||
|
@ -14,6 +14,9 @@
|
||||
#include "CPlayerInterface.h"
|
||||
#include "hch/CBuildingHandler.h"
|
||||
#include "hch/CObjectHandler.h"
|
||||
#include "lib/Connection.h"
|
||||
#include "client/Client.h"
|
||||
#include <boost/thread.hpp>
|
||||
//LUALIB_API int (luaL_error) (lua_State *L, const char *fmt, ...);
|
||||
|
||||
bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
|
||||
@ -205,7 +208,7 @@ void CCallback::recruitCreatures(const CGObjectInstance *obj, int ID, int amount
|
||||
if( ( found = (ID == t->town->basicCreatures[av->first]) ) //creature is available among basic cretures
|
||||
|| (found = (ID == t->town->upgradedCreatures[av->first])) )//creature is available among upgraded cretures
|
||||
{
|
||||
amount = std::min(amount,av->second); //reduce recruited amount up to available amount
|
||||
amount = min(amount,av->second); //reduce recruited amount up to available amount
|
||||
ser = av->first;
|
||||
break;
|
||||
}
|
||||
@ -272,6 +275,13 @@ bool CCallback::upgradeCreature(const CArmedInstance *obj, int stackPos, int new
|
||||
//TODO: write
|
||||
return false;
|
||||
}
|
||||
void CCallback::endTurn()
|
||||
{
|
||||
std::cout << "Player "<<(unsigned)player<<" end his turn."<<std::endl;
|
||||
cl->serv->wmx->lock();
|
||||
*cl->serv << ui16(100); //report that we ended turn
|
||||
cl->serv->wmx->unlock();
|
||||
}
|
||||
UpgradeInfo CCallback::getUpgradeInfo(const CArmedInstance *obj, int stackPos)
|
||||
{
|
||||
UpgradeInfo ret;
|
||||
|
@ -17,6 +17,7 @@ class CGTownInstance;
|
||||
struct StartInfo;
|
||||
class CStack;
|
||||
struct lua_State;
|
||||
class CClient;
|
||||
//structure gathering info about upgrade possibilites
|
||||
struct UpgradeInfo
|
||||
{
|
||||
@ -39,6 +40,7 @@ public:
|
||||
virtual void recruitCreatures(const CGObjectInstance *obj, int ID, int amount)=0;
|
||||
virtual bool dismissCreature(const CArmedInstance *obj, int stackPos)=0;
|
||||
virtual bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1)=0; //if newID==-1 then best possible upgrade will be made
|
||||
virtual void endTurn()=0;
|
||||
|
||||
//get info
|
||||
virtual bool verifyPath(CPath * path, bool blockSea)=0;
|
||||
@ -85,8 +87,9 @@ struct HeroMoveDetails
|
||||
class CCallback : public ICallback
|
||||
{
|
||||
private:
|
||||
CCallback(CGameState * GS, int Player):gs(GS),player(Player){};
|
||||
CCallback(CGameState * GS, int Player, CClient *C):gs(GS),player(Player),cl(C){};
|
||||
CGameState * gs;
|
||||
CClient *cl;
|
||||
bool isVisible(int3 pos, int Player);
|
||||
|
||||
protected:
|
||||
@ -106,7 +109,7 @@ public:
|
||||
void recruitCreatures(const CGObjectInstance *obj, int ID, int amount);
|
||||
bool dismissCreature(const CArmedInstance *obj, int stackPos);
|
||||
bool upgradeCreature(const CArmedInstance *obj, int stackPos, int newID=-1);
|
||||
|
||||
void endTurn();
|
||||
|
||||
//get info
|
||||
bool verifyPath(CPath * path, bool blockSea);
|
||||
|
115
CGameState.cpp
115
CGameState.cpp
@ -22,6 +22,8 @@
|
||||
#include "CLuaHandler.h"
|
||||
#include "lib/NetPacks.h"
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/thread/shared_mutex.hpp>
|
||||
|
||||
boost::rand48 ran;
|
||||
class CMP_stack
|
||||
@ -33,12 +35,80 @@ public:
|
||||
}
|
||||
} cmpst ;
|
||||
|
||||
CGObjectInstance * createObject(int id, int subid, int3 pos, int owner)
|
||||
{
|
||||
CGObjectInstance * nobj;
|
||||
switch(id)
|
||||
{
|
||||
case 34: //hero
|
||||
{
|
||||
CGHeroInstance * nobj;
|
||||
nobj = new CGHeroInstance();
|
||||
nobj->pos = pos;
|
||||
nobj->tempOwner = owner;
|
||||
nobj->defInfo = new CGDefInfo();
|
||||
nobj->defInfo->id = 34;
|
||||
nobj->defInfo->subid = subid;
|
||||
nobj->defInfo->printPriority = 0;
|
||||
nobj->type = VLC->heroh->heroes[subid];
|
||||
for(int i=0;i<6;i++)
|
||||
{
|
||||
nobj->defInfo->blockMap[i]=255;
|
||||
nobj->defInfo->visitMap[i]=0;
|
||||
}
|
||||
nobj->ID = id;
|
||||
nobj->subID = subid;
|
||||
nobj->defInfo->handler=NULL;
|
||||
nobj->defInfo->blockMap[5] = 253;
|
||||
nobj->defInfo->visitMap[5] = 2;
|
||||
nobj->artifacts.resize(20);
|
||||
nobj->artifWorn[16] = 3;
|
||||
nobj->primSkills.resize(4);
|
||||
nobj->primSkills[0] = nobj->type->heroClass->initialAttack;
|
||||
nobj->primSkills[1] = nobj->type->heroClass->initialDefence;
|
||||
nobj->primSkills[2] = nobj->type->heroClass->initialPower;
|
||||
nobj->primSkills[3] = nobj->type->heroClass->initialKnowledge;
|
||||
nobj->mana = 10 * nobj->primSkills[3];
|
||||
return nobj;
|
||||
}
|
||||
case 98: //town
|
||||
nobj = new CGTownInstance;
|
||||
break;
|
||||
default: //rest of objects
|
||||
nobj = new CGObjectInstance;
|
||||
nobj->defInfo = VLC->dobjinfo->gobjs[id][subid];
|
||||
break;
|
||||
}
|
||||
nobj->ID = id;
|
||||
nobj->subID = subid;
|
||||
if(!nobj->defInfo)
|
||||
std::cout <<"No def declaration for " <<id <<" "<<subid<<std::endl;
|
||||
nobj->pos = pos;
|
||||
//nobj->state = NULL;//new CLuaObjectScript();
|
||||
nobj->tempOwner = owner;
|
||||
nobj->info = NULL;
|
||||
nobj->defInfo->id = id;
|
||||
nobj->defInfo->subid = subid;
|
||||
|
||||
//assigning defhandler
|
||||
if(nobj->ID==34 || nobj->ID==98)
|
||||
return nobj;
|
||||
nobj->defInfo = VLC->dobjinfo->gobjs[id][subid];
|
||||
//if(!nobj->defInfo->handler)
|
||||
//{
|
||||
// nobj->defInfo->handler = CDefHandler::giveDef(nobj->defInfo->name);
|
||||
// nobj->defInfo->width = nobj->defInfo->handler->ourImages[0].bitmap->w/32;
|
||||
// nobj->defInfo->height = nobj->defInfo->handler->ourImages[0].bitmap->h/32;
|
||||
//}
|
||||
return nobj;
|
||||
}
|
||||
CStack::CStack(CCreature * C, int A, int O, int I, bool AO)
|
||||
:creature(C),amount(A),owner(O), alive(true), position(-1), ID(I), attackerOwned(AO), firstHPleft(C->hitPoints)
|
||||
{
|
||||
}
|
||||
void CGameState::apply(IPack * pack)
|
||||
{
|
||||
mx->lock();
|
||||
switch(pack->getType())
|
||||
{
|
||||
case 101://NewTurn
|
||||
@ -60,6 +130,7 @@ void CGameState::apply(IPack * pack)
|
||||
t->builded = 0;
|
||||
}
|
||||
}
|
||||
mx->unlock();
|
||||
}
|
||||
int CGameState::pickHero(int owner)
|
||||
{
|
||||
@ -302,6 +373,26 @@ int CGameState::getDate(int mode) const
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
CGameState::CGameState()
|
||||
{
|
||||
mx = new boost::shared_mutex();
|
||||
}
|
||||
CGameState::~CGameState()
|
||||
{
|
||||
delete mx;
|
||||
}
|
||||
bool CGameState::checkFunc(int obid, std::string name)
|
||||
{
|
||||
if (objscr.find(obid)!=objscr.end())
|
||||
{
|
||||
if(objscr[obid].find(name)!=objscr[obid].end())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CGameState::init(StartInfo * si, Mapa * map, int Seed)
|
||||
{
|
||||
day = 0;
|
||||
@ -339,9 +430,29 @@ void CGameState::init(StartInfo * si, Mapa * map, int Seed)
|
||||
}
|
||||
//std::cout<<"\tRandomizing objects: "<<th.getDif()<<std::endl;
|
||||
|
||||
//giving starting hero
|
||||
for(int i=0;i<PLAYER_LIMIT;i++)
|
||||
{
|
||||
if((map->players[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==RoE))
|
||||
{
|
||||
int3 hpos = map->players[i].posOfMainTown;
|
||||
hpos.x+=1;// hpos.y+=1;
|
||||
int j;
|
||||
for(j=0; j<scenarioOps->playerInfos.size(); j++)
|
||||
if(scenarioOps->playerInfos[j].color == i)
|
||||
break;
|
||||
if(j == scenarioOps->playerInfos.size())
|
||||
continue;
|
||||
int h=pickHero(i);
|
||||
CGHeroInstance * nnn = static_cast<CGHeroInstance*>(createObject(34,h,hpos,i));
|
||||
nnn->id = map->objects.size();
|
||||
//nnn->defInfo->handler = graphics->flags1[0];
|
||||
map->heroes.push_back(nnn);
|
||||
map->objects.push_back(nnn);
|
||||
}
|
||||
}
|
||||
//std::cout<<"\tGiving starting heroes: "<<th.getDif()<<std::endl;
|
||||
|
||||
|
||||
day=0;
|
||||
/*********creating players entries in gs****************************************/
|
||||
for (int i=0; i<scenarioOps->playerInfos.size();i++)
|
||||
{
|
||||
|
20
CGameState.h
20
CGameState.h
@ -25,6 +25,11 @@ class CMapHandler;
|
||||
class CPathfinder;
|
||||
struct IPack;
|
||||
|
||||
namespace boost
|
||||
{
|
||||
class shared_mutex;
|
||||
}
|
||||
|
||||
struct DLL_EXPORT PlayerState
|
||||
{
|
||||
public:
|
||||
@ -78,18 +83,11 @@ private:
|
||||
|
||||
std::map<int, CGDefInfo*> villages, forts, capitols; //def-info for town graphics
|
||||
|
||||
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;
|
||||
}
|
||||
boost::shared_mutex *mx;
|
||||
|
||||
CGameState();
|
||||
~CGameState();
|
||||
bool checkFunc(int obid, std::string name);
|
||||
void init(StartInfo * si, Mapa * map, int Seed);
|
||||
void apply(IPack * pack);
|
||||
void randomizeObject(CGObjectInstance *cur);
|
||||
|
31
CMT.cpp
31
CMT.cpp
@ -4,6 +4,7 @@
|
||||
#include <cmath>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <queue>
|
||||
#include <cmath>
|
||||
#include <boost/thread.hpp>
|
||||
#include "SDL_TTF.h"
|
||||
@ -44,6 +45,10 @@ std::string NAME = NAME_VER + std::string(" (client)");
|
||||
DLL_EXPORT void initDLL(CLodHandler *b);
|
||||
SDL_Surface * screen, * screen2;
|
||||
extern SDL_Surface * CSDL_Ext::std32bppSurface;
|
||||
|
||||
std::queue<SDL_Event> events;
|
||||
boost::mutex eventsM;
|
||||
|
||||
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
|
||||
void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script)
|
||||
{
|
||||
@ -56,9 +61,7 @@ void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * sc
|
||||
}
|
||||
int _tmain(int argc, _TCHAR* argv[])
|
||||
{
|
||||
//boost::thread servthr(boost::bind(system,"VCMI_server.exe")); //runs server executable;
|
||||
//TODO: add versions for other platforms
|
||||
|
||||
std::cout.flags(ios::unitbuf);
|
||||
std::cout << NAME << std::endl;
|
||||
srand ( time(NULL) );
|
||||
CPG=NULL;
|
||||
@ -146,9 +149,8 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
StartInfo *options = new StartInfo(cpg->runLoop());
|
||||
///////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cgi->state = new CGameState();
|
||||
THC std::cout<<"\tGamestate: "<<pomtime.getDif()<<std::endl;
|
||||
|
||||
boost::thread servthr(boost::bind(system,"VCMI_server.exe > server_log.txt")); //runs server executable;
|
||||
//TODO: will it work on non-windows platforms?
|
||||
THC tmh.getDif();pomtime.getDif();//reset timers
|
||||
|
||||
|
||||
@ -173,9 +175,23 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
std::ofstream lll("client_log.txt");
|
||||
CConnection c("localhost","3030",NAME,lll);
|
||||
THC std::cout<<"\tConnecting to the server: "<<tmh.getDif()<<std::endl;
|
||||
|
||||
CClient cl(&c,options);
|
||||
boost::thread t(boost::bind(&CClient::run,&cl));
|
||||
|
||||
|
||||
SDL_Event ev;
|
||||
while(1) //main SDL events loop
|
||||
{
|
||||
SDL_WaitEvent(&ev);
|
||||
if(ev.type==SDL_QUIT)
|
||||
{
|
||||
t.interrupt();
|
||||
exit(0);
|
||||
}
|
||||
eventsM.lock();
|
||||
events.push(ev);
|
||||
eventsM.unlock();
|
||||
}
|
||||
|
||||
///claculating FoWs for minimap
|
||||
/****************************Minimaps' FoW******************************************/
|
||||
@ -209,7 +225,6 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
// }
|
||||
|
||||
//}
|
||||
cl.run();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "stdafx.h"
|
||||
#include <queue>
|
||||
#include "CPlayerInterface.h"
|
||||
#include "CAdvmapInterface.h"
|
||||
#include "CMessage.h"
|
||||
@ -20,6 +21,7 @@
|
||||
#include "CCastleInterface.h"
|
||||
#include "CHeroWindow.h"
|
||||
#include "timeHandler.h"
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include "hch/CPreGameTextHandler.h"
|
||||
@ -35,6 +37,9 @@ using namespace CSDL_Ext;
|
||||
|
||||
extern TTF_Font * GEOR16;
|
||||
extern bool continueReadingConsole;
|
||||
CPlayerInterface * LOCPLINT;
|
||||
extern std::queue<SDL_Event> events;
|
||||
extern boost::mutex eventsM;
|
||||
|
||||
class OCM_HLP_CGIN
|
||||
{
|
||||
@ -894,6 +899,7 @@ void TimeInterested::deactivate()
|
||||
}
|
||||
CPlayerInterface::CPlayerInterface(int Player, int serial)
|
||||
{
|
||||
LOCPLINT = this;
|
||||
playerID=Player;
|
||||
serialID=serial;
|
||||
CGI->localPlayer = playerID;
|
||||
@ -920,6 +926,7 @@ void CPlayerInterface::init(ICallback * CB)
|
||||
}
|
||||
void CPlayerInterface::yourTurn()
|
||||
{
|
||||
LOCPLINT = this;
|
||||
makingTurn = true;
|
||||
CGI->localPlayer = serialID;
|
||||
unsigned char & animVal = LOCPLINT->adventureInt->anim; //for animations handling
|
||||
@ -977,10 +984,13 @@ void CPlayerInterface::yourTurn()
|
||||
timeinterested[i]->tick();
|
||||
}
|
||||
LOCPLINT->adventureInt->updateScreen = false;
|
||||
while (SDL_PollEvent(&sEvent)) //wait for event...
|
||||
eventsM.lock();
|
||||
while(!events.empty())
|
||||
{
|
||||
handleEvent(&sEvent);
|
||||
handleEvent(&events.front());
|
||||
events.pop();
|
||||
}
|
||||
eventsM.unlock();
|
||||
if (!castleInt) //stuff for advMapInt
|
||||
{
|
||||
++LOCPLINT->adventureInt->animValHitCount; //for animations
|
||||
@ -1047,6 +1057,7 @@ void CPlayerInterface::yourTurn()
|
||||
SDL_framerateDelay(mainFPSmng);
|
||||
}
|
||||
adventureInt->hide();
|
||||
cb->endTurn();
|
||||
}
|
||||
|
||||
inline void subRect(const int & x, const int & y, const int & z, SDL_Rect & r, const int & hid)
|
||||
@ -2051,7 +2062,7 @@ CStatusBar::CStatusBar(int x, int y, std::string name, int maxw)
|
||||
pos.x=x;
|
||||
pos.y=y;
|
||||
if(maxw >= 0)
|
||||
pos.w = std::min(bg->w,maxw);
|
||||
pos.w = min(bg->w,maxw);
|
||||
else
|
||||
pos.w=bg->w;
|
||||
pos.h=bg->h;
|
||||
@ -2437,7 +2448,7 @@ void CTownList::mouseMoved (SDL_MouseMotionEvent & sEvent)
|
||||
LOCPLINT->statusbar->clear();
|
||||
return;
|
||||
};
|
||||
LOCPLINT->statusbar->print(items[from+ny]->state->hoverText(const_cast<CGTownInstance*>(items[from+ny])));
|
||||
LOCPLINT->statusbar->print(items[from+ny]->name);
|
||||
}
|
||||
|
||||
void CTownList::clickLeft(tribool down)
|
||||
@ -2630,7 +2641,7 @@ void CRecrutationWindow::clickLeft(tribool down)
|
||||
if(isItIn(&genRect(132,102,pos.x+curx,pos.y+64),LOCPLINT->current->motion.x,LOCPLINT->current->motion.y))
|
||||
{
|
||||
which = i;
|
||||
int newAmount = std::min(amounts[i],creatures[i].amount);
|
||||
int newAmount = min(amounts[i],creatures[i].amount);
|
||||
slider->amount = newAmount;
|
||||
if(slider->value > newAmount)
|
||||
slider->moveTo(newAmount);
|
||||
@ -2727,7 +2738,7 @@ CRecrutationWindow::CRecrutationWindow(const std::vector<std::pair<int,int> > &C
|
||||
pos.y = screen->h/2 - bitmap->h/2;
|
||||
pos.w = bitmap->w;
|
||||
pos.h = bitmap->h;
|
||||
slider = new CSlider(pos.x+176,pos.y+279,135,boost::bind(&CRecrutationWindow::sliderMoved,this, _1),1,std::min(amounts[0],creatures[0].amount),0,true);
|
||||
slider = new CSlider(pos.x+176,pos.y+279,135,boost::bind(&CRecrutationWindow::sliderMoved,this, _1),1,min(amounts[0],creatures[0].amount),0,true);
|
||||
std::string pom;
|
||||
printAtMiddle(CGI->generaltexth->allTexts[346],113,231,GEOR13,zwykly,bitmap); //cost per troop t
|
||||
printAtMiddle(CGI->generaltexth->allTexts[465],205,231,GEOR13,zwykly,bitmap); //available t
|
||||
|
@ -524,4 +524,6 @@ public:
|
||||
void show(SDL_Surface * to = NULL);
|
||||
};
|
||||
|
||||
extern CPlayerInterface * LOCPLINT;
|
||||
|
||||
#endif //CPLAYERINTERFACE_H
|
@ -9,14 +9,17 @@
|
||||
#include "../CPlayerInterface.h"
|
||||
#include "../CConsoleHandler.h"
|
||||
#include "../lib/NetPacks.h"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
CClient::CClient(void)
|
||||
{
|
||||
}
|
||||
CClient::CClient(CConnection *con, StartInfo *si)
|
||||
:serv(con)
|
||||
{
|
||||
{
|
||||
timeHandler tmh;
|
||||
CGI->state = new CGameState();
|
||||
THC std::cout<<"\tGamestate: "<<tmh.getDif()<<std::endl;
|
||||
CConnection &c(*con);
|
||||
////////////////////////////////////////////////////
|
||||
ui8 pom8;
|
||||
@ -55,17 +58,17 @@ CClient::CClient(CConnection *con, StartInfo *si)
|
||||
|
||||
for (int i=0; i<CGI->state->scenarioOps->playerInfos.size();i++) //initializing interfaces
|
||||
{
|
||||
|
||||
CCallback *cb = new CCallback(CGI->state,CGI->state->scenarioOps->playerInfos[i].color,this);
|
||||
if(!CGI->state->scenarioOps->playerInfos[i].human)
|
||||
CGI->playerint.push_back(static_cast<CGameInterface*>(CAIHandler::getNewAI(new CCallback(CGI->state,CGI->state->scenarioOps->playerInfos[i].color),"EmptyAI.dll")));
|
||||
CGI->playerint.push_back(static_cast<CGameInterface*>(CAIHandler::getNewAI(cb,"EmptyAI.dll")));
|
||||
else
|
||||
{
|
||||
CGI->state->currentPlayer=CGI->state->scenarioOps->playerInfos[i].color;
|
||||
CGI->playerint.push_back(new CPlayerInterface(CGI->state->scenarioOps->playerInfos[i].color,i));
|
||||
((CPlayerInterface*)(CGI->playerint[i]))->init(new CCallback(CGI->state,CGI->state->scenarioOps->playerInfos[i].color));
|
||||
((CPlayerInterface*)(CGI->playerint[i]))->init(cb);
|
||||
}
|
||||
}
|
||||
CGI->consoleh->cb = new CCallback(CGI->state,-1);
|
||||
CGI->consoleh->cb = new CCallback(CGI->state,-1,this);
|
||||
}
|
||||
CClient::~CClient(void)
|
||||
{
|
||||
@ -79,9 +82,7 @@ void CClient::process(int what)
|
||||
ui8 player;
|
||||
*serv >> player;//who?
|
||||
std::cout << "It's turn of "<<(unsigned)player<<" player."<<std::endl;
|
||||
CGI->playerint[gs->players[player].serial]->yourTurn();
|
||||
*serv << ui16(100); //report that we ended turn
|
||||
std::cout << "Player "<<(unsigned)player<<" end his turn."<<std::endl;
|
||||
boost::thread(boost::bind(&CGameInterface::yourTurn,CGI->playerint[gs->players[player].serial]));
|
||||
break;
|
||||
}
|
||||
case 101:
|
||||
@ -109,16 +110,4 @@ void CClient::run()
|
||||
process(typ);
|
||||
}
|
||||
} HANDLE_EXCEPTION
|
||||
//while(1) //main game loop, one execution per turn
|
||||
//{
|
||||
// CGI->consoleh->cb->newTurn();
|
||||
// for (int i=0;i<CGI->playerint.size();i++)
|
||||
// {
|
||||
// CGI->state->currentPlayer=CGI->playerint[i]->playerID;
|
||||
// try
|
||||
// {
|
||||
// CGI->playerint[i]->yourTurn();
|
||||
// }HANDLE_EXCEPTION
|
||||
// }
|
||||
//}
|
||||
}
|
@ -4,6 +4,7 @@ struct StartInfo;
|
||||
class CGameState;
|
||||
class CGameInterface;
|
||||
class CConnection;
|
||||
class CCallback;
|
||||
class CClient
|
||||
{
|
||||
CGameState *gs;
|
||||
@ -16,4 +17,6 @@ public:
|
||||
|
||||
void process(int what);
|
||||
void run();
|
||||
|
||||
friend class CCallback;
|
||||
};
|
||||
|
4
global.h
4
global.h
@ -31,10 +31,6 @@ enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HERO_ALCHE
|
||||
HERO_BARBARIAN, HERO_BATTLEMAGE, HERO_BEASTMASTER, HERO_WITCH, HERO_PLANESWALKER, HERO_ELEMENTALIST};
|
||||
class CGameInfo;
|
||||
extern CGameInfo* CGI;
|
||||
#define CURPLINT (((CPlayerInterface*)((CGI)->playerint[(CGI)->state->currentPlayer])))
|
||||
#define LOCPLINT (((CPlayerInterface*)((CGI)->playerint[(CGI)->localPlayer])))
|
||||
//CURPLINT gives pointer to the interface of human player which is currently making turn,
|
||||
//LOCPLINT gives pointer to the interface which is currently showed (on this machine)
|
||||
|
||||
#define HEROI_TYPE (0)
|
||||
#define TOWNI_TYPE (1)
|
||||
|
@ -176,8 +176,8 @@ class DLL_EXPORT CConnection
|
||||
std::ostream &out;
|
||||
CConnection(void);
|
||||
void init();
|
||||
boost::mutex *rmx, *wmx; // read/write mutexes
|
||||
public:
|
||||
boost::mutex *rmx, *wmx; // read/write mutexes
|
||||
|
||||
template <typename T>
|
||||
void savePrimitive(const T &data)
|
||||
|
2
map.h
2
map.h
@ -462,7 +462,7 @@ struct DLL_EXPORT Mapa
|
||||
std::vector<DisposedHero> disposedHeroes;
|
||||
std::vector<CGHeroInstance*> predefinedHeroes;
|
||||
std::vector<CGDefInfo *> defy; // list of .def files with definitions from .h3m (may be custom)
|
||||
std::set<CGDefInfo *> defs; // other defInfos - for randomized objects, objects added or modified by script
|
||||
std::set<CGDefInfo *> defs; // other defInfos - for randomized objects, objects added or modified by scripts
|
||||
PlayerInfo players[8]; // info about players
|
||||
std::vector<int> teams; // teams[i] = team of player no i
|
||||
LossCondition lossCondition;
|
||||
|
146
mapHandler.cpp
146
mapHandler.cpp
@ -568,34 +568,41 @@ void CMapHandler::init()
|
||||
{
|
||||
timeHandler th;
|
||||
th.getDif();
|
||||
loadDefs();
|
||||
loadDefs(); //loading castles' defs
|
||||
THC std::cout<<"Reading terrain defs: "<<th.getDif()<<std::endl;
|
||||
|
||||
std::ifstream ifs("config/townsDefs.txt");
|
||||
int ccc;
|
||||
ifs>>ccc;
|
||||
for(int i=0;i<ccc*2;i++)
|
||||
{
|
||||
CGDefInfo *n;
|
||||
if(i<ccc)
|
||||
{
|
||||
n = CGI->state->villages[i];
|
||||
map->defs.insert(CGI->state->forts[i]);
|
||||
}
|
||||
else
|
||||
n = CGI->state->capitols[i%ccc];
|
||||
ifs >> n->name;
|
||||
map->defs.insert(n);
|
||||
}
|
||||
std::cout<<"\tLoading town def info: "<<th.getDif()<<std::endl;
|
||||
|
||||
for(int i=0;i<map->heroes.size();i++)
|
||||
{
|
||||
if(!map->heroes[i]->defInfo->handler)
|
||||
{
|
||||
map->heroes[i]->defInfo->handler = graphics->flags1[0];
|
||||
map->heroes[i]->defInfo->width = map->heroes[i]->defInfo->handler->ourImages[0].bitmap->w/32;
|
||||
map->heroes[i]->defInfo->height = map->heroes[i]->defInfo->handler->ourImages[0].bitmap->h/32;
|
||||
}
|
||||
}
|
||||
|
||||
std::for_each(map->defy.begin(),map->defy.end(),processDef); //load h3m defs
|
||||
std::for_each(map->defs.begin(),map->defs.end(),processDef); //and non-h3m defs
|
||||
THC std::cout<<"\tUnpacking and handling defs: "<<th.getDif()<<std::endl;
|
||||
|
||||
//loading castles' defs
|
||||
//std::ifstream ifs("config/townsDefs.txt");
|
||||
//int ccc;
|
||||
//ifs>>ccc;
|
||||
//for(int i=0;i<ccc*2;i++)
|
||||
//{
|
||||
// //CGDefInfo * n = new CGDefInfo(*CGI->dobjinfo->castles[i%ccc]);
|
||||
// ifs >> n->name;
|
||||
// if (!(n->handler = CDefHandler::giveDef(n->name)))
|
||||
// std::cout << "Cannot open "<<n->name<<std::endl;
|
||||
// else
|
||||
// {
|
||||
// n->width = n->handler->ourImages[0].bitmap->w/32;
|
||||
// n->height = n->handler->ourImages[0].bitmap->h/32;
|
||||
// }
|
||||
// if(i<ccc)
|
||||
// villages[i]=n;
|
||||
// else
|
||||
// capitols[i%ccc]=n;
|
||||
// alphaTransformDef(n);
|
||||
//}
|
||||
|
||||
for(int i=0;i<PLAYER_LIMIT;i++)
|
||||
{
|
||||
for(int j=0; j<map->players[i].heroesNames.size();j++)
|
||||
@ -603,7 +610,7 @@ void CMapHandler::init()
|
||||
usedHeroes.insert(map->players[i].heroesNames[j].heroID);
|
||||
}
|
||||
}
|
||||
std::cout<<"\tLoading town defs, picking random factions and heroes: "<<th.getDif()<<std::endl;
|
||||
std::cout<<"\tChecking used heroes: "<<th.getDif()<<std::endl;
|
||||
|
||||
|
||||
|
||||
@ -615,29 +622,6 @@ void CMapHandler::init()
|
||||
roadsRiverTerrainInit(); //road's and river's DefHandlers; and simple values initialization
|
||||
borderAndTerrainBitmapInit();
|
||||
std::cout<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDif()<<std::endl;
|
||||
|
||||
//giving starting hero
|
||||
//for(int i=0;i<PLAYER_LIMIT;i++)
|
||||
//{
|
||||
// if((map->players[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==RoE))
|
||||
// {
|
||||
// int3 hpos = map->players[i].posOfMainTown;
|
||||
// hpos.x+=1;// hpos.y+=1;
|
||||
// int j;
|
||||
// for(j=0;j<CGI->state->scenarioOps->playerInfos.size();j++)
|
||||
// if(CGI->state->scenarioOps->playerInfos[j].color==i)
|
||||
// break;
|
||||
// if(j==CGI->state->scenarioOps->playerInfos.size())
|
||||
// continue;
|
||||
// int h=pickHero(i);
|
||||
// CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,h,hpos,i);
|
||||
// nnn->defInfo->handler = graphics->flags1[0];
|
||||
// map->heroes.push_back(nnn);
|
||||
// map->objects.push_back(nnn);
|
||||
// }
|
||||
//}
|
||||
std::cout<<"\tGiving starting heroes: "<<th.getDif()<<std::endl;
|
||||
|
||||
initObjectRects();
|
||||
std::cout<<"\tMaking object rects: "<<th.getDif()<<std::endl;
|
||||
calculateBlockedPos();
|
||||
@ -1190,74 +1174,6 @@ std::vector < CGObjectInstance * > CMapHandler::getVisitableObjs(int3 pos)
|
||||
return ret;
|
||||
}
|
||||
|
||||
CGObjectInstance * CMapHandler::createObject(int id, int subid, int3 pos, int owner)
|
||||
{
|
||||
CGObjectInstance * nobj;
|
||||
switch(id)
|
||||
{
|
||||
case 34: //hero
|
||||
{
|
||||
CGHeroInstance * nobj;
|
||||
nobj = new CGHeroInstance();
|
||||
nobj->pos = pos;
|
||||
nobj->tempOwner = owner;
|
||||
nobj->defInfo = new CGDefInfo();
|
||||
nobj->defInfo->id = 34;
|
||||
nobj->defInfo->subid = subid;
|
||||
nobj->defInfo->printPriority = 0;
|
||||
nobj->type = CGI->heroh->heroes[subid];
|
||||
for(int i=0;i<6;i++)
|
||||
{
|
||||
nobj->defInfo->blockMap[i]=255;
|
||||
nobj->defInfo->visitMap[i]=0;
|
||||
}
|
||||
nobj->ID = id;
|
||||
nobj->subID = subid;
|
||||
nobj->defInfo->handler=NULL;
|
||||
nobj->defInfo->blockMap[5] = 253;
|
||||
nobj->defInfo->visitMap[5] = 2;
|
||||
nobj->artifacts.resize(20);
|
||||
nobj->artifWorn[16] = 3;
|
||||
nobj->primSkills.resize(4);
|
||||
nobj->primSkills[0] = nobj->type->heroClass->initialAttack;
|
||||
nobj->primSkills[1] = nobj->type->heroClass->initialDefence;
|
||||
nobj->primSkills[2] = nobj->type->heroClass->initialPower;
|
||||
nobj->primSkills[3] = nobj->type->heroClass->initialKnowledge;
|
||||
nobj->mana = 10 * nobj->primSkills[3];
|
||||
return nobj;
|
||||
}
|
||||
case 98: //town
|
||||
nobj = new CGTownInstance;
|
||||
break;
|
||||
default: //rest of objects
|
||||
nobj = new CGObjectInstance;
|
||||
nobj->defInfo = CGI->dobjinfo->gobjs[id][subid];
|
||||
break;
|
||||
}
|
||||
nobj->ID = id;
|
||||
nobj->subID = subid;
|
||||
if(!nobj->defInfo)
|
||||
std::cout <<"No def declaration for " <<id <<" "<<subid<<std::endl;
|
||||
nobj->pos = pos;
|
||||
//nobj->state = NULL;//new CLuaObjectScript();
|
||||
nobj->tempOwner = owner;
|
||||
nobj->info = NULL;
|
||||
nobj->defInfo->id = id;
|
||||
nobj->defInfo->subid = subid;
|
||||
|
||||
//assigning defhandler
|
||||
if(nobj->ID==34 || nobj->ID==98)
|
||||
return nobj;
|
||||
nobj->defInfo = CGI->dobjinfo->gobjs[id][subid];
|
||||
if(!nobj->defInfo->handler)
|
||||
{
|
||||
nobj->defInfo->handler = CDefHandler::giveDef(nobj->defInfo->name);
|
||||
nobj->defInfo->width = nobj->defInfo->handler->ourImages[0].bitmap->w/32;
|
||||
nobj->defInfo->height = nobj->defInfo->handler->ourImages[0].bitmap->h/32;
|
||||
}
|
||||
return nobj;
|
||||
}
|
||||
|
||||
std::string CMapHandler::getDefName(int id, int subid)
|
||||
{
|
||||
CGDefInfo* temp = CGI->dobjinfo->gobjs[id][subid];
|
||||
|
@ -12,7 +12,8 @@
|
||||
#include "../hch/CObjectHandler.h"
|
||||
#include "../hch/CTownHandler.h"
|
||||
#include "../hch/CHeroHandler.h"
|
||||
|
||||
#include "boost/date_time/posix_time/posix_time_types.hpp" //no i/o just types
|
||||
extern bool end;
|
||||
bool makingTurn;
|
||||
boost::condition_variable cTurn;
|
||||
boost::mutex mTurn;
|
||||
@ -20,23 +21,41 @@ boost::shared_mutex gsm;
|
||||
|
||||
void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
|
||||
{
|
||||
ui16 pom;
|
||||
while(1)
|
||||
try
|
||||
{
|
||||
c >> pom;
|
||||
switch(pom)
|
||||
ui16 pom;
|
||||
while(!end)
|
||||
{
|
||||
case 100: //my interface end its turn
|
||||
mTurn.lock();
|
||||
makingTurn = false;
|
||||
mTurn.unlock();
|
||||
cTurn.notify_all();
|
||||
break;
|
||||
default:
|
||||
throw std::exception("Not supported client message!");
|
||||
break;
|
||||
c >> pom;
|
||||
switch(pom)
|
||||
{
|
||||
case 100: //my interface end its turn
|
||||
mTurn.lock();
|
||||
makingTurn = false;
|
||||
mTurn.unlock();
|
||||
cTurn.notify_all();
|
||||
break;
|
||||
default:
|
||||
throw std::exception("Not supported client message!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
end = true;
|
||||
}
|
||||
catch (const std::exception * e)
|
||||
{
|
||||
std::cerr << e->what()<< std::endl;
|
||||
end = true;
|
||||
delete e;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
end = true;
|
||||
}
|
||||
}
|
||||
template <typename T>void CGameHandler::sendToAllClients(CPack<T> * info)
|
||||
{
|
||||
@ -110,11 +129,12 @@ void CGameHandler::newTurn()
|
||||
// i->second.towns[j]->strInfo.creatures[k]+=i->second.towns[j]->creatureGrowth(k);
|
||||
// }
|
||||
//}
|
||||
if((gs->day>1) && i->first<PLAYER_LIMIT)//not the first day and town not neutral
|
||||
if((gs->day) && i->first<PLAYER_LIMIT)//not the first day and town not neutral
|
||||
r.resources[6] += i->second.towns[j]->dailyIncome();
|
||||
}
|
||||
n.res.insert(r);
|
||||
}
|
||||
gs->apply(&n);
|
||||
sendToAllClients(&n);
|
||||
//for (std::set<CCPPObjectScript *>::iterator i=gs->cppscripts.begin();i!=gs->cppscripts.end();i++)
|
||||
//{
|
||||
@ -147,7 +167,7 @@ void CGameHandler::run()
|
||||
|
||||
boost::thread(boost::bind(&CGameHandler::handleConnection,this,pom,boost::ref(**i)));
|
||||
}
|
||||
while (1)
|
||||
while (!end)
|
||||
{
|
||||
newTurn();
|
||||
for(std::map<ui8,PlayerState>::iterator i = gs->players.begin(); i != gs->players.end(); i++)
|
||||
@ -157,9 +177,11 @@ void CGameHandler::run()
|
||||
*connections[i->first] << ui16(100) << i->first;
|
||||
//wait till turn is done
|
||||
boost::unique_lock<boost::mutex> lock(mTurn);
|
||||
while(makingTurn)
|
||||
while(makingTurn && !end)
|
||||
{
|
||||
cTurn.wait(lock);
|
||||
boost::posix_time::time_duration p;
|
||||
p= boost::posix_time::seconds(1);
|
||||
cTurn.timed_wait(lock,p);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ using namespace boost;
|
||||
using namespace boost::asio;
|
||||
using namespace boost::asio::ip;
|
||||
|
||||
bool end = false;
|
||||
|
||||
CVCMIServer::CVCMIServer()
|
||||
: io(new io_service()), acceptor(new tcp::acceptor(*io, tcp::endpoint(tcp::v4(), 3030)))
|
||||
@ -26,8 +27,8 @@ CVCMIServer::CVCMIServer()
|
||||
}
|
||||
CVCMIServer::~CVCMIServer()
|
||||
{
|
||||
delete io;
|
||||
delete acceptor;
|
||||
//delete io;
|
||||
//delete acceptor;
|
||||
}
|
||||
|
||||
void CVCMIServer::newGame(CConnection &c)
|
||||
@ -96,7 +97,7 @@ void CVCMIServer::start()
|
||||
}
|
||||
CConnection connection(s,NAME,std::cout);
|
||||
std::cout<<"Got connection!" << std::endl;
|
||||
while(1)
|
||||
while(!end)
|
||||
{
|
||||
uint8_t mode;
|
||||
connection >> mode;
|
||||
@ -127,17 +128,9 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
{
|
||||
io_service io_service;
|
||||
CVCMIServer server;
|
||||
while(1)
|
||||
while(!end)
|
||||
server.start();
|
||||
io_service.run();
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
;
|
||||
}
|
||||
} HANDLE_EXCEPTION
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user