1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

* fixes for MSVC (it needs to have global variables from library explicitly exported)

* renamed logging variables to tlogX ('_' in var names looks ugly)
* cleaned it improved setting formations
* fixed crashbug on maps with random hero
This commit is contained in:
Michał W. Urbańczyk
2008-09-19 08:16:19 +00:00
parent a1dd7f22f9
commit 856698bd80
21 changed files with 171 additions and 190 deletions

View File

@@ -186,6 +186,7 @@ void CHighlightableButton::clickLeft( tribool down )
if (pressedL && (down==false)) if (pressedL && (down==false))
{ {
pressedL=state; pressedL=state;
if(!onlyOn || !selected)
select(!selected); select(!selected);
} }
else else
@@ -196,6 +197,7 @@ void CHighlightableButton::clickLeft( tribool down )
CHighlightableButton::CHighlightableButton( const CFunctionList<void()> &onSelect, const CFunctionList<void()> &onDeselect, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, bool activ ) CHighlightableButton::CHighlightableButton( const CFunctionList<void()> &onSelect, const CFunctionList<void()> &onDeselect, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, bool activ )
{ {
onlyOn = false;
init(onSelect,Name,HelpBox,playerColoredButton,defName,add,x,y,activ); init(onSelect,Name,HelpBox,playerColoredButton,defName,add,x,y,activ);
callback2 = onDeselect; callback2 = onDeselect;
} }

View File

@@ -34,7 +34,7 @@ class CHighlightableButton
{ {
public: public:
CHighlightableButton(const CFunctionList<void()> &onSelect, const CFunctionList<void()> &onDeselect, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, bool activ ); CHighlightableButton(const CFunctionList<void()> &onSelect, const CFunctionList<void()> &onDeselect, const std::map<int,std::string> &Name, const std::string &HelpBox, bool playerColoredButton, const std::string &defName, std::vector<std::string> * add, int x, int y, bool activ );
bool selected; bool selected, onlyOn;
CFunctionList<void()> callback2; //when disselecting CFunctionList<void()> callback2; //when disselecting
void select(bool on); void select(bool on);
void clickLeft (tribool down); void clickLeft (tribool down);

View File

@@ -588,8 +588,8 @@ void CCallback::trade( int mode, int id1, int id2, int val1 )
*cl->serv << ui16(511) << ui8(player) << ui32(mode) << ui32(id1) << ui32(id2) << ui32(val1); *cl->serv << ui16(511) << ui8(player) << ui32(mode) << ui32(id1) << ui32(id2) << ui32(val1);
} }
void CCallback::setFormation(const CGHeroInstance * hero, bool loose) void CCallback::setFormation(const CGHeroInstance * hero, bool tight)
{ {
hero->looseFormation = loose; const_cast<CGHeroInstance*>(hero)->army.formation = tight;
*cl->serv << ui16(512) << hero->id << ui8(loose); *cl->serv << ui16(512) << hero->id << ui8(tight);
} }

View File

@@ -42,7 +42,7 @@ public:
virtual void swapGarrisonHero(const CGTownInstance *town)=0; virtual void swapGarrisonHero(const CGTownInstance *town)=0;
virtual void buyArtifact(const CGHeroInstance *hero, int aid)=0; //used to buy artifacts in towns (including spell book in the guild and war machines in blacksmith) virtual void buyArtifact(const CGHeroInstance *hero, int aid)=0; //used to buy artifacts in towns (including spell book in the guild and war machines in blacksmith)
virtual void trade(int mode, int id1, int id2, int val1)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce virtual void trade(int mode, int id1, int id2, int val1)=0; //mode==0: sell val1 units of id1 resource for id2 resiurce
virtual void setFormation(const CGHeroInstance * hero, bool loose)=0; virtual void setFormation(const CGHeroInstance * hero, bool tight)=0;
//get info //get info
virtual bool verifyPath(CPath * path, bool blockSea)=0; virtual bool verifyPath(CPath * path, bool blockSea)=0;
@@ -122,7 +122,7 @@ public:
void swapGarrisonHero(const CGTownInstance *town); void swapGarrisonHero(const CGTownInstance *town);
void buyArtifact(const CGHeroInstance *hero, int aid); void buyArtifact(const CGHeroInstance *hero, int aid);
void trade(int mode, int id1, int id2, int val1); void trade(int mode, int id1, int id2, int val1);
void setFormation(const CGHeroInstance * hero, bool loose); void setFormation(const CGHeroInstance * hero, bool tight);
//get info //get info
bool verifyPath(CPath * path, bool blockSea); bool verifyPath(CPath * path, bool blockSea);

View File

@@ -121,7 +121,7 @@ void CConsoleHandler::killConsole(pthread_t hThread)
void CConsoleHandler::killConsole(void *hThread) void CConsoleHandler::killConsole(void *hThread)
#endif #endif
{ {
_log3 << "Killing console... "; tlog3 << "Killing console... ";
_kill_thread(hThread,0); _kill_thread(hThread,0);
_log3 << "done!\n"; tlog3 << "done!\n";
} }

View File

@@ -50,6 +50,8 @@ CHeroWindow::CHeroWindow(int playerColor):
gar1button = new CHighlightableButton(0,0,map_list_of(0,CGI->generaltexth->heroscrn[23]), CGI->generaltexth->heroscrn[29], false, "hsbtns6.def" , NULL,546, 491, false); gar1button = new CHighlightableButton(0,0,map_list_of(0,CGI->generaltexth->heroscrn[23]), CGI->generaltexth->heroscrn[29], false, "hsbtns6.def" , NULL,546, 491, false);
gar3button = new CHighlightableButton(0,0,map_list_of(0,CGI->generaltexth->heroscrn[24]), CGI->generaltexth->heroscrn[30], false, "hsbtns7.def", NULL, 546, 527, false); gar3button = new CHighlightableButton(0,0,map_list_of(0,CGI->generaltexth->heroscrn[24]), CGI->generaltexth->heroscrn[30], false, "hsbtns7.def", NULL, 546, 527, false);
gar1button->onlyOn = gar3button->onlyOn = true;
gar2button = new CHighlightableButton(0, 0, map_list_of(0,CGI->generaltexth->heroscrn[26])(3,CGI->generaltexth->heroscrn[25]), CGI->generaltexth->heroscrn[31], false, "hsbtns8.def", NULL, 604, 491, false); gar2button = new CHighlightableButton(0, 0, map_list_of(0,CGI->generaltexth->heroscrn[26])(3,CGI->generaltexth->heroscrn[25]), CGI->generaltexth->heroscrn[31], false, "hsbtns8.def", NULL, 604, 491, false);
gar4button = new AdventureMapButton(CGI->generaltexth->allTexts[256], CGI->generaltexth->heroscrn[32], boost::function<void()>(), 604, 527, "hsbtns9.def", false, NULL, false); gar4button = new AdventureMapButton(CGI->generaltexth->allTexts[256], CGI->generaltexth->heroscrn[32], boost::function<void()>(), 604, 527, "hsbtns9.def", false, NULL, false);
boost::algorithm::replace_first(gar4button->hoverTexts[0],"%s",CGI->generaltexth->allTexts[43]); boost::algorithm::replace_first(gar4button->hoverTexts[0],"%s",CGI->generaltexth->allTexts[43]);
@@ -311,17 +313,15 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
gar2button->callback2 = vstd::assigno(hero->tacticFormationEnabled,false); gar2button->callback2 = vstd::assigno(hero->tacticFormationEnabled,false);
} }
gar1button->callback.clear(); gar1button->callback.clear();
gar1button->callback = vstd::assigno(hero->looseFormation,true);
gar1button->callback += boost::bind(&CHighlightableButton::select, gar3button, false); gar1button->callback += boost::bind(&CHighlightableButton::select, gar3button, false);
gar1button->callback += boost::bind(&CCallback::setFormation, LOCPLINT->cb, Hero, true); gar1button->callback += boost::bind(&CCallback::setFormation, LOCPLINT->cb, Hero, false);
gar3button->callback.clear(); gar3button->callback.clear();
gar3button->callback = vstd::assigno(hero->looseFormation,false);
gar3button->callback += boost::bind(&CHighlightableButton::select, gar1button, false); gar3button->callback += boost::bind(&CHighlightableButton::select, gar1button, false);
gar3button->callback += boost::bind(&CCallback::setFormation, LOCPLINT->cb, Hero, false); gar3button->callback += boost::bind(&CCallback::setFormation, LOCPLINT->cb, Hero, true);
if(hero->looseFormation) if(hero->army.formation)
gar1button->select(true);
else
gar3button->select(true); gar3button->select(true);
else
gar1button->select(true);
redrawCurBack(); redrawCurBack();
} }

78
CMT.cpp
View File

@@ -51,14 +51,6 @@ extern SDL_Surface * CSDL_Ext::std32bppSurface;
std::queue<SDL_Event> events; std::queue<SDL_Event> events;
boost::mutex eventsM; boost::mutex eventsM;
TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16;
extern CLogger<0> _log0;
extern CLogger<1> _log1;
extern CLogger<2> _log2;
extern CLogger<3> _log3;
extern CLogger<4> _log4;
extern CLogger<5> _log5;
extern CConsoleHandler *console;// = NULL;
extern std::ostream *logfile;// = NULL;
namespace intpr = boost::interprocess; namespace intpr = boost::interprocess;
void processCommand(const std::string &message); void processCommand(const std::string &message);
#ifndef __GNUC__ #ifndef __GNUC__
@@ -79,7 +71,7 @@ int main(int argc, char** argv)
*::console->cb = &processCommand; *::console->cb = &processCommand;
console = new boost::thread(boost::bind(&CConsoleHandler::run,::console)); console = new boost::thread(boost::bind(&CConsoleHandler::run,::console));
} }
_log0 << "\tConsole and logifle ready!" << std::endl; tlog0 << "\tConsole and logifle ready!" << std::endl;
int port; int port;
if(argc > 1) if(argc > 1)
{ {
@@ -92,10 +84,10 @@ int main(int argc, char** argv)
else else
{ {
port = 3030; port = 3030;
_log0 << "Port " << port << " will be used." << std::endl; tlog0 << "Port " << port << " will be used." << std::endl;
} }
std::cout.flags(ios::unitbuf); std::cout.flags(ios::unitbuf);
_log0 << NAME << std::endl; tlog0 << NAME << std::endl;
srand ( time(NULL) ); srand ( time(NULL) );
CPG=NULL; CPG=NULL;
atexit(SDL_Quit); atexit(SDL_Quit);
@@ -104,13 +96,13 @@ int main(int argc, char** argv)
//luatest.test(); //luatest.test();
//CBIKHandler cb; //CBIKHandler cb;
//cb.open("CSECRET.BIK"); //cb.open("CSECRET.BIK");
_log0 << "Starting... " << std::endl; tlog0 << "Starting... " << std::endl;
THC timeHandler tmh, total, pomtime; THC timeHandler tmh, total, pomtime;
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO)==0) if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_AUDIO)==0)
{ {
screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); //initializing important global surface screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); //initializing important global surface
_log0 <<"\tInitializing screen: "<<pomtime.getDif(); tlog0 <<"\tInitializing screen: "<<pomtime.getDif();
_log0 << std::endl; tlog0 << std::endl;
SDL_WM_SetCaption(NAME.c_str(),""); //set window title SDL_WM_SetCaption(NAME.c_str(),""); //set window title
#if SDL_BYTEORDER == SDL_BIG_ENDIAN #if SDL_BYTEORDER == SDL_BIG_ENDIAN
int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff; int rmask = 0xff000000;int gmask = 0x00ff0000;int bmask = 0x0000ff00;int amask = 0x000000ff;
@@ -118,7 +110,7 @@ int main(int argc, char** argv)
int rmask = 0x000000ff; int gmask = 0x0000ff00; int bmask = 0x00ff0000; int amask = 0xff000000; int rmask = 0x000000ff; int gmask = 0x0000ff00; int bmask = 0x00ff0000; int amask = 0xff000000;
#endif #endif
CSDL_Ext::std32bppSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, rmask, gmask, bmask, amask); CSDL_Ext::std32bppSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 1, 1, 32, rmask, gmask, bmask, amask);
_log0 << "\tInitializing minors: " << pomtime.getDif() << std::endl; tlog0 << "\tInitializing minors: " << pomtime.getDif() << std::endl;
TTF_Init(); TTF_Init();
TNRB16 = TTF_OpenFont("Fonts" PATHSEPARATOR "tnrb.ttf",16); TNRB16 = TTF_OpenFont("Fonts" PATHSEPARATOR "tnrb.ttf",16);
GEOR13 = TTF_OpenFont("Fonts" PATHSEPARATOR "georgia.ttf",13); GEOR13 = TTF_OpenFont("Fonts" PATHSEPARATOR "georgia.ttf",13);
@@ -126,18 +118,18 @@ int main(int argc, char** argv)
GEORXX = TTF_OpenFont("Fonts" PATHSEPARATOR "tnrb.ttf",22); GEORXX = TTF_OpenFont("Fonts" PATHSEPARATOR "tnrb.ttf",22);
GEORM = TTF_OpenFont("Fonts" PATHSEPARATOR "georgia.ttf",10); GEORM = TTF_OpenFont("Fonts" PATHSEPARATOR "georgia.ttf",10);
atexit(TTF_Quit); atexit(TTF_Quit);
THC _log0<<"\tInitializing fonts: "<<pomtime.getDif()<<std::endl; THC tlog0<<"\tInitializing fonts: "<<pomtime.getDif()<<std::endl;
CMusicHandler * mush = new CMusicHandler; //initializing audio CMusicHandler * mush = new CMusicHandler; //initializing audio
mush->initMusics(); mush->initMusics();
//audio initialized //audio initialized
cgi->mush = mush; cgi->mush = mush;
THC _log0<<"\tInitializing sound: "<<pomtime.getDif()<<std::endl; THC tlog0<<"\tInitializing sound: "<<pomtime.getDif()<<std::endl;
THC _log0<<"Initializing screen, fonts and sound handling: "<<tmh.getDif()<<std::endl; THC tlog0<<"Initializing screen, fonts and sound handling: "<<tmh.getDif()<<std::endl;
CDefHandler::Spriteh = cgi->spriteh = new CLodHandler(); CDefHandler::Spriteh = cgi->spriteh = new CLodHandler();
cgi->spriteh->init("Data" PATHSEPARATOR "H3sprite.lod","Sprites"); cgi->spriteh->init("Data" PATHSEPARATOR "H3sprite.lod","Sprites");
BitmapHandler::bitmaph = cgi->bitmaph = new CLodHandler; BitmapHandler::bitmaph = cgi->bitmaph = new CLodHandler;
cgi->bitmaph->init("Data" PATHSEPARATOR "H3bitmap.lod","Data"); cgi->bitmaph->init("Data" PATHSEPARATOR "H3bitmap.lod","Data");
THC _log0<<"Loading .lod files: "<<tmh.getDif()<<std::endl; THC tlog0<<"Loading .lod files: "<<tmh.getDif()<<std::endl;
initDLL(cgi->bitmaph,::console,logfile); initDLL(cgi->bitmaph,::console,logfile);
CGI->arth = VLC->arth; CGI->arth = VLC->arth;
CGI->creh = VLC->creh; CGI->creh = VLC->creh;
@@ -147,7 +139,7 @@ int main(int argc, char** argv)
CGI->spellh = VLC->spellh; CGI->spellh = VLC->spellh;
CGI->dobjinfo = VLC->dobjinfo; CGI->dobjinfo = VLC->dobjinfo;
CGI->buildh = VLC->buildh; CGI->buildh = VLC->buildh;
_log0<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl; tlog0<<"Initializing VCMI_Lib: "<<tmh.getDif()<<std::endl;
//cgi->curh->initCursor(); //cgi->curh->initCursor();
//cgi->curh->showGraphicCursor(); //cgi->curh->showGraphicCursor();
pomtime.getDif(); pomtime.getDif();
@@ -155,28 +147,28 @@ int main(int argc, char** argv)
cgi->curh->initCursor(); cgi->curh->initCursor();
//cgi->screenh = new CScreenHandler; //cgi->screenh = new CScreenHandler;
//cgi->screenh->initScreen(); //cgi->screenh->initScreen();
_log0<<"\tScreen handler: "<<pomtime.getDif()<<std::endl; tlog0<<"\tScreen handler: "<<pomtime.getDif()<<std::endl;
CAbilityHandler * abilh = new CAbilityHandler; CAbilityHandler * abilh = new CAbilityHandler;
abilh->loadAbilities(); abilh->loadAbilities();
cgi->abilh = abilh; cgi->abilh = abilh;
_log0<<"\tAbility handler: "<<pomtime.getDif()<<std::endl; tlog0<<"\tAbility handler: "<<pomtime.getDif()<<std::endl;
_log0<<"Preparing first handlers: "<<tmh.getDif()<<std::endl; tlog0<<"Preparing first handlers: "<<tmh.getDif()<<std::endl;
pomtime.getDif(); pomtime.getDif();
graphics = new Graphics(); graphics = new Graphics();
_log0<<"\tMain graphics: "<<tmh.getDif()<<std::endl; tlog0<<"\tMain graphics: "<<tmh.getDif()<<std::endl;
std::vector<CDefHandler **> animacje; std::vector<CDefHandler **> animacje;
for(std::vector<CHeroClass *>::iterator i = cgi->heroh->heroClasses.begin();i!=cgi->heroh->heroClasses.end();i++) for(std::vector<CHeroClass *>::iterator i = cgi->heroh->heroClasses.begin();i!=cgi->heroh->heroClasses.end();i++)
animacje.push_back(&((*i)->*(&CHeroClass::moveAnim))); animacje.push_back(&((*i)->*(&CHeroClass::moveAnim)));
graphics->loadHeroAnim(animacje); graphics->loadHeroAnim(animacje);
_log0<<"\tHero animations: "<<tmh.getDif()<<std::endl; tlog0<<"\tHero animations: "<<tmh.getDif()<<std::endl;
_log0<<"Initializing game graphics: "<<tmh.getDif()<<std::endl; tlog0<<"Initializing game graphics: "<<tmh.getDif()<<std::endl;
CMessage::init(); CMessage::init();
cgi->generaltexth = new CGeneralTextHandler; cgi->generaltexth = new CGeneralTextHandler;
cgi->generaltexth->load(); cgi->generaltexth->load();
_log0<<"Preparing more handlers: "<<tmh.getDif()<<std::endl; tlog0<<"Preparing more handlers: "<<tmh.getDif()<<std::endl;
CPreGame * cpg = new CPreGame(); //main menu and submenus CPreGame * cpg = new CPreGame(); //main menu and submenus
_log0<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl; tlog0<<"Initialization CPreGame (together): "<<tmh.getDif()<<std::endl;
_log0<<"Initialization of VCMI (togeter): "<<total.getDif()<<std::endl; tlog0<<"Initialization of VCMI (togeter): "<<total.getDif()<<std::endl;
cpg->mush = mush; cpg->mush = mush;
StartInfo *options = new StartInfo(cpg->runLoop()); StartInfo *options = new StartInfo(cpg->runLoop());
@@ -189,17 +181,17 @@ int main(int argc, char** argv)
ServerReady *sr = new(mr.get_address())ServerReady(); ServerReady *sr = new(mr.get_address())ServerReady();
std::string comm = std::string(SERVER_NAME) + " " + portc + " > server_log.txt"; std::string comm = std::string(SERVER_NAME) + " " + portc + " > server_log.txt";
boost::thread servthr(boost::bind(system,comm.c_str())); //runs server executable; //TODO: will it work on non-windows platforms? boost::thread servthr(boost::bind(system,comm.c_str())); //runs server executable; //TODO: will it work on non-windows platforms?
_log0<<"Preparing shared memory and starting server: "<<tmh.getDif()<<std::endl; tlog0<<"Preparing shared memory and starting server: "<<tmh.getDif()<<std::endl;
/////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////
tmh.getDif();pomtime.getDif();//reset timers tmh.getDif();pomtime.getDif();//reset timers
cgi->pathf = new CPathfinder(); cgi->pathf = new CPathfinder();
_log0<<"\tPathfinder: "<<pomtime.getDif()<<std::endl; tlog0<<"\tPathfinder: "<<pomtime.getDif()<<std::endl;
_log0<<"Handlers initialization (together): "<<tmh.getDif()<<std::endl; tlog0<<"Handlers initialization (together): "<<tmh.getDif()<<std::endl;
std::ofstream lll("client_log.txt"); std::ofstream lll("client_log.txt");
CConnection *c=NULL; CConnection *c=NULL;
//wait until server is ready //wait until server is ready
_log0<<"Waiting for server... "; tlog0<<"Waiting for server... ";
{ {
intpr::scoped_lock<intpr::interprocess_mutex> slock(sr->mutex); intpr::scoped_lock<intpr::interprocess_mutex> slock(sr->mutex);
while(!sr->ready) while(!sr->ready)
@@ -208,21 +200,21 @@ int main(int argc, char** argv)
} }
} }
intpr::shared_memory_object::remove("vcmi_memory"); intpr::shared_memory_object::remove("vcmi_memory");
_log0 << tmh.getDif()<<std::endl; tlog0 << tmh.getDif()<<std::endl;
while(!c) while(!c)
{ {
try try
{ {
_log0 << "Establishing connection...\n"; tlog0 << "Establishing connection...\n";
c = new CConnection("127.0.0.1",portc,NAME,lll); c = new CConnection("127.0.0.1",portc,NAME,lll);
} }
catch(...) catch(...)
{ {
_log1 << "\nCannot establish connection! Retrying within 2 seconds" <<std::endl; tlog1 << "\nCannot establish connection! Retrying within 2 seconds" <<std::endl;
SDL_Delay(2000); SDL_Delay(2000);
} }
} }
THC _log0<<"\tConnecting to the server: "<<tmh.getDif()<<std::endl; THC tlog0<<"\tConnecting to the server: "<<tmh.getDif()<<std::endl;
CClient cl(c,options); CClient cl(c,options);
boost::thread t(boost::bind(&CClient::run,&cl)); boost::thread t(boost::bind(&CClient::run,&cl));
SDL_Event ev; SDL_Event ev;
@@ -236,7 +228,7 @@ int main(int argc, char** argv)
::console->killConsole(console->native_handle()); ::console->killConsole(console->native_handle());
#endif #endif
SDL_Delay(750); SDL_Delay(750);
_log0 << "Ending...\n"; tlog0 << "Ending...\n";
exit(0); exit(0);
} }
eventsM.lock(); eventsM.lock();
@@ -246,7 +238,7 @@ int main(int argc, char** argv)
} }
else else
{ {
_log1<<"Something was wrong: "<<SDL_GetError()<<std::endl; tlog1<<"Something was wrong: "<<SDL_GetError()<<std::endl;
return -1; return -1;
} }
} }
@@ -284,10 +276,10 @@ void processCommand(const std::string &message)
else if(message=="get txt") else if(message=="get txt")
{ {
boost::filesystem::create_directory("Extracted_txts"); boost::filesystem::create_directory("Extracted_txts");
_log0<<"Command accepted. Opening .lod file...\t"; tlog0<<"Command accepted. Opening .lod file...\t";
CLodHandler * txth = new CLodHandler; CLodHandler * txth = new CLodHandler;
txth->init(std::string(DATA_DIR "Data" PATHSEPARATOR "H3bitmap.lod"),"data"); txth->init(std::string(DATA_DIR "Data" PATHSEPARATOR "H3bitmap.lod"),"data");
_log0<<"done.\nScanning .lod file\n"; tlog0<<"done.\nScanning .lod file\n";
int curp=0; int curp=0;
std::string pattern = ".TXT"; std::string pattern = ".TXT";
for(int i=0;i<txth->entries.size(); i++) for(int i=0;i<txth->entries.size(); i++)
@@ -302,9 +294,9 @@ void processCommand(const std::string &message)
if(p2!=curp) if(p2!=curp)
{ {
curp = p2; curp = p2;
_log0<<"\r"<<curp<<"%"; tlog0<<"\r"<<curp<<"%";
} }
} }
_log0<<"\rExtracting done :)\n"; tlog0<<"\rExtracting done :)\n";
} }
} }

View File

@@ -1009,7 +1009,7 @@ void MapSel::processMaps(std::vector<std::string> &pliczkiTemp, int &index)
else break; else break;
} }
gzclose(tempf); gzclose(tempf);
if(iii<50) {_log3<<"\t\tWarning: corrupted map file: "<<pliczkiTemp[pom]<<std::endl; continue;} if(iii<50) {tlog3<<"\t\tWarning: corrupted map file: "<<pliczkiTemp[pom]<<std::endl; continue;}
if (!sss[4]) continue; //nie ma graczy? mapa niegrywalna //ju� to kiedy� komentowa�em- - to bzdura //tu calkiem pasuje... if (!sss[4]) continue; //nie ma graczy? mapa niegrywalna //ju� to kiedy� komentowa�em- - to bzdura //tu calkiem pasuje...
CMapInfo mi(pliczkiTemp[pom],sss); CMapInfo mi(pliczkiTemp[pom],sss);
mx.lock(); mx.lock();
@@ -1393,19 +1393,19 @@ CPreGame::CPreGame()
preth = new CPreGameTextHandler; preth = new CPreGameTextHandler;
preth->loadTexts(); preth->loadTexts();
CGI->preth=preth; CGI->preth=preth;
_log0<<"\tCPreGame: loading txts: "<<tmh.getDif()<<std::endl; tlog0<<"\tCPreGame: loading txts: "<<tmh.getDif()<<std::endl;
currentMessage=NULL; currentMessage=NULL;
behindCurMes=NULL; behindCurMes=NULL;
initMainMenu(); initMainMenu();
_log0<<"\tCPreGame: main menu initialization: "<<tmh.getDif()<<std::endl; tlog0<<"\tCPreGame: main menu initialization: "<<tmh.getDif()<<std::endl;
initNewMenu(); initNewMenu();
_log0<<"\tCPreGame: newgame menu initialization: "<<tmh.getDif()<<std::endl; tlog0<<"\tCPreGame: newgame menu initialization: "<<tmh.getDif()<<std::endl;
initScenSel(); initScenSel();
_log0<<"\tCPreGame: scenario choice initialization: "<<tmh.getDif()<<std::endl; tlog0<<"\tCPreGame: scenario choice initialization: "<<tmh.getDif()<<std::endl;
initOptions(); initOptions();
_log0<<"\tCPreGame: scenario options initialization: "<<tmh.getDif()<<std::endl; tlog0<<"\tCPreGame: scenario options initialization: "<<tmh.getDif()<<std::endl;
showMainMenu(); showMainMenu();
_log0<<"\tCPreGame: displaying main menu: "<<tmh.getDif()<<std::endl; tlog0<<"\tCPreGame: displaying main menu: "<<tmh.getDif()<<std::endl;
CPG=this; CPG=this;
playerName="Player"; playerName="Player";
} }

View File

@@ -101,7 +101,7 @@ CClient::CClient(CConnection *con, StartInfo *si)
{ {
timeHandler tmh; timeHandler tmh;
CGI->state = new CGameState(); CGI->state = new CGameState();
_log0 <<"\tGamestate: "<<tmh.getDif()<<std::endl; tlog0 <<"\tGamestate: "<<tmh.getDif()<<std::endl;
CConnection &c(*con); CConnection &c(*con);
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
ui8 pom8; ui8 pom8;
@@ -116,34 +116,34 @@ CClient::CClient(CConnection *con, StartInfo *si)
ui32 seed, sum; ui32 seed, sum;
std::string mapname; std::string mapname;
c >> mapname >> sum >> seed; c >> mapname >> sum >> seed;
_log0 <<"\tSending/Getting info to/from the server: "<<tmh.getDif()<<std::endl; tlog0 <<"\tSending/Getting info to/from the server: "<<tmh.getDif()<<std::endl;
Mapa * mapa = new Mapa(mapname); Mapa * mapa = new Mapa(mapname);
_log0 <<"Reading and detecting map file (together): "<<tmh.getDif()<<std::endl; tlog0 <<"Reading and detecting map file (together): "<<tmh.getDif()<<std::endl;
_log0 << "\tServer checksum for "<<mapname <<": "<<sum << std::endl; tlog0 << "\tServer checksum for "<<mapname <<": "<<sum << std::endl;
_log0 << "\tOur checksum for the map: "<< mapa->checksum << std::endl; tlog0 << "\tOur checksum for the map: "<< mapa->checksum << std::endl;
if(mapa->checksum != sum) if(mapa->checksum != sum)
{ {
_log1 << "Wrong map checksum!!!" << std::endl; tlog1 << "Wrong map checksum!!!" << std::endl;
#ifndef __GNUC__ #ifndef __GNUC__
throw std::exception("Wrong checksum"); throw std::exception("Wrong checksum");
#else #else
throw std::exception(); throw std::exception();
#endif #endif
} }
_log0 << "\tUsing random seed: "<<seed << std::endl; tlog0 << "\tUsing random seed: "<<seed << std::endl;
gs = CGI->state; gs = CGI->state;
gs->scenarioOps = si; gs->scenarioOps = si;
gs->init(si,mapa,seed); gs->init(si,mapa,seed);
CGI->mh = new CMapHandler(); CGI->mh = new CMapHandler();
_log0 <<"Initializing GameState (together): "<<tmh.getDif()<<std::endl; tlog0 <<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
CGI->mh->map = mapa; CGI->mh->map = mapa;
_log0 <<"Creating mapHandler: "<<tmh.getDif()<<std::endl; tlog0 <<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
CGI->mh->init(); CGI->mh->init();
_log0 <<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl; tlog0 <<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
for (int i=0; i<CGI->state->scenarioOps->playerInfos.size();i++) //initializing interfaces for (int i=0; i<CGI->state->scenarioOps->playerInfos.size();i++) //initializing interfaces
{ {
@@ -173,7 +173,7 @@ void CClient::process(int what)
{ {
ui8 player; ui8 player;
*serv >> player;//who? *serv >> player;//who?
_log5 << "It's turn of "<<(unsigned)player<<" player."<<std::endl; tlog5 << "It's turn of "<<(unsigned)player<<" player."<<std::endl;
boost::thread(boost::bind(&CGameInterface::yourTurn,playerint[player])); boost::thread(boost::bind(&CGameInterface::yourTurn,playerint[player]));
break; break;
} }
@@ -181,16 +181,16 @@ void CClient::process(int what)
{ {
NewTurn n; NewTurn n;
*serv >> n; *serv >> n;
_log5 << "New day: "<<(unsigned)n.day<<". Applying changes... "; tlog5 << "New day: "<<(unsigned)n.day<<". Applying changes... ";
gs->apply(&n); gs->apply(&n);
_log5 << "done!"<<std::endl; tlog5 << "done!"<<std::endl;
break; break;
} }
case 102: //set resource amount case 102: //set resource amount
{ {
SetResource sr; SetResource sr;
*serv >> sr; *serv >> sr;
_log5 << "Set amount of "<<CGI->objh->restypes[sr.resid] tlog5 << "Set amount of "<<CGI->objh->restypes[sr.resid]
<< " of player "<<(unsigned)sr.player <<" to "<<sr.val<<std::endl; << " of player "<<(unsigned)sr.player <<" to "<<sr.val<<std::endl;
gs->apply(&sr); gs->apply(&sr);
playerint[sr.player]->receivedResource(sr.resid,sr.val); playerint[sr.player]->receivedResource(sr.resid,sr.val);
@@ -211,7 +211,7 @@ void CClient::process(int what)
{ {
SetResources sr; SetResources sr;
*serv >> sr; *serv >> sr;
_log5 << "Set amount of resources of player "<<(unsigned)sr.player<<std::endl; tlog5 << "Set amount of resources of player "<<(unsigned)sr.player<<std::endl;
gs->apply(&sr); gs->apply(&sr);
playerint[sr.player]->receivedResource(-1,-1); playerint[sr.player]->receivedResource(-1,-1);
break; break;
@@ -220,7 +220,7 @@ void CClient::process(int what)
{ {
SetPrimSkill sps; SetPrimSkill sps;
*serv >> sps; *serv >> sps;
_log5 << "Changing hero primary skill"<<std::endl; tlog5 << "Changing hero primary skill"<<std::endl;
gs->apply(&sps); gs->apply(&sps);
playerint[gs->getHero(sps.id)->tempOwner]->heroPrimarySkillChanged(gs->getHero(sps.id),sps.which,sps.val); playerint[gs->getHero(sps.id)->tempOwner]->heroPrimarySkillChanged(gs->getHero(sps.id),sps.which,sps.val);
break; break;
@@ -229,7 +229,7 @@ void CClient::process(int what)
{ {
SetSecSkill sr; SetSecSkill sr;
*serv >> sr; *serv >> sr;
_log5 << "Changing hero secondary skill"<<std::endl; tlog5 << "Changing hero secondary skill"<<std::endl;
gs->apply(&sr); gs->apply(&sr);
//TODO? - maybe inform interfaces //TODO? - maybe inform interfaces
break; break;
@@ -259,7 +259,7 @@ void CClient::process(int what)
{ {
ChangeSpells vc; ChangeSpells vc;
*serv >> vc; *serv >> vc;
_log5 << "Changing spells of hero "<<vc.hid<<std::endl; tlog5 << "Changing spells of hero "<<vc.hid<<std::endl;
gs->apply(&vc); gs->apply(&vc);
break; break;
} }
@@ -273,7 +273,7 @@ void CClient::process(int what)
if(obj->ID == 34) if(obj->ID == 34)
{ {
CGHeroInstance *h = static_cast<CGHeroInstance*>(obj); CGHeroInstance *h = static_cast<CGHeroInstance*>(obj);
_log5 << "Removing hero with id = "<<(unsigned)rh.id<<std::endl; tlog5 << "Removing hero with id = "<<(unsigned)rh.id<<std::endl;
playerint[h->tempOwner]->heroKilled(h); playerint[h->tempOwner]->heroKilled(h);
} }
break; break;
@@ -282,7 +282,7 @@ void CClient::process(int what)
{ {
TryMoveHero *th = new TryMoveHero; //will be deleted by callback after processing TryMoveHero *th = new TryMoveHero; //will be deleted by callback after processing
*serv >> *th; *serv >> *th;
_log5 << "HeroMove: id="<<th->id<<"\tResult: "<<(unsigned)th->result<<"\tPosition "<<th->end<<std::endl; tlog5 << "HeroMove: id="<<th->id<<"\tResult: "<<(unsigned)th->result<<"\tPosition "<<th->end<<std::endl;
gs->apply(th); gs->apply(th);
int player = gs->map->objects[th->id]->getOwner(); int player = gs->map->objects[th->id]->getOwner();
@@ -317,7 +317,7 @@ void CClient::process(int what)
{ {
SetGarrisons sg; SetGarrisons sg;
*serv >> sg; *serv >> sg;
_log5 << "Setting garrisons." << std::endl; tlog5 << "Setting garrisons." << std::endl;
gs->apply(&sg); gs->apply(&sg);
for(std::map<ui32,CCreatureSet>::iterator i = sg.garrs.begin(); i!=sg.garrs.end(); i++) for(std::map<ui32,CCreatureSet>::iterator i = sg.garrs.begin(); i!=sg.garrs.end(); i++)
playerint[gs->map->objects[i->first]->tempOwner]->garrisonChanged(gs->map->objects[i->first]); playerint[gs->map->objects[i->first]->tempOwner]->garrisonChanged(gs->map->objects[i->first]);
@@ -336,7 +336,7 @@ void CClient::process(int what)
NewStructures ns; NewStructures ns;
*serv >> ns; *serv >> ns;
CGTownInstance *town = static_cast<CGTownInstance*>(gs->map->objects[ns.tid]); CGTownInstance *town = static_cast<CGTownInstance*>(gs->map->objects[ns.tid]);
_log5 << "New structure(s) in " << ns.tid <<" " << town->name << " - " << *ns.bid.begin() << std::endl; tlog5 << "New structure(s) in " << ns.tid <<" " << town->name << " - " << *ns.bid.begin() << std::endl;
gs->apply(&ns); gs->apply(&ns);
BOOST_FOREACH(si32 bid, ns.bid) BOOST_FOREACH(si32 bid, ns.bid)
{ {
@@ -356,7 +356,7 @@ void CClient::process(int what)
{ {
SetAvailableCreatures ns; SetAvailableCreatures ns;
*serv >> ns; *serv >> ns;
_log5 << "Setting available creatures in " << ns.tid << std::endl; tlog5 << "Setting available creatures in " << ns.tid << std::endl;
gs->apply(&ns); gs->apply(&ns);
CGTownInstance *t = gs->getTown(ns.tid); CGTownInstance *t = gs->getTown(ns.tid);
if(vstd::contains(playerint,t->tempOwner)) if(vstd::contains(playerint,t->tempOwner))
@@ -367,7 +367,7 @@ void CClient::process(int what)
{ {
SetHeroesInTown inTown; SetHeroesInTown inTown;
*serv >> inTown; *serv >> inTown;
_log5 << "Setting heroes in town " << inTown.tid << std::endl; tlog5 << "Setting heroes in town " << inTown.tid << std::endl;
gs->apply(&inTown); gs->apply(&inTown);
CGTownInstance *t = gs->getTown(inTown.tid); CGTownInstance *t = gs->getTown(inTown.tid);
if(vstd::contains(playerint,t->tempOwner)) if(vstd::contains(playerint,t->tempOwner))
@@ -378,7 +378,7 @@ void CClient::process(int what)
{ {
SetHeroArtifacts sha; SetHeroArtifacts sha;
*serv >> sha; *serv >> sha;
_log5 << "Setting artifacts of hero " << sha.hid << std::endl; tlog5 << "Setting artifacts of hero " << sha.hid << std::endl;
gs->apply(&sha); gs->apply(&sha);
CGHeroInstance *t = gs->getHero(sha.hid); CGHeroInstance *t = gs->getHero(sha.hid);
if(vstd::contains(playerint,t->tempOwner)) if(vstd::contains(playerint,t->tempOwner))
@@ -389,7 +389,7 @@ void CClient::process(int what)
{ {
SetObjectProperty sop; SetObjectProperty sop;
*serv >> sop; *serv >> sop;
_log5 << "Setting " << (unsigned)sop.what << " property of " << sop.id <<" object to "<<sop.val<<std::endl; tlog5 << "Setting " << (unsigned)sop.what << " property of " << sop.id <<" object to "<<sop.val<<std::endl;
gs->apply(&sop); gs->apply(&sop);
break; break;
} }
@@ -397,7 +397,7 @@ void CClient::process(int what)
{ {
SetHoverName shn; SetHoverName shn;
*serv >> shn; *serv >> shn;
_log5 << "Setting a name of " << shn.id <<" object to "<< toString(shn.name) <<std::endl; tlog5 << "Setting a name of " << shn.id <<" object to "<< toString(shn.name) <<std::endl;
gs->mx->lock(); gs->mx->lock();
gs->map->objects[shn.id]->hoverName = toString(shn.name); gs->map->objects[shn.id]->hoverName = toString(shn.name);
gs->mx->unlock(); gs->mx->unlock();
@@ -407,7 +407,7 @@ void CClient::process(int what)
{ {
HeroLevelUp bs; HeroLevelUp bs;
*serv >> bs; *serv >> bs;
_log5 << "Hero levels up!" <<std::endl; tlog5 << "Hero levels up!" <<std::endl;
gs->apply(&bs); gs->apply(&bs);
CGHeroInstance *h = gs->getHero(bs.heroid); CGHeroInstance *h = gs->getHero(bs.heroid);
if(vstd::contains(playerint,h->tempOwner)) if(vstd::contains(playerint,h->tempOwner))
@@ -421,7 +421,7 @@ void CClient::process(int what)
{ {
SelectionDialog sd; SelectionDialog sd;
*serv >> sd; *serv >> sd;
_log5 << "Showing selection dialog " <<std::endl; tlog5 << "Showing selection dialog " <<std::endl;
std::vector<Component*> comps; std::vector<Component*> comps;
for(int i=0;i<sd.components.size();i++) for(int i=0;i<sd.components.size();i++)
comps.push_back(&sd.components[i]); comps.push_back(&sd.components[i]);
@@ -433,7 +433,7 @@ void CClient::process(int what)
{ {
YesNoDialog ynd; YesNoDialog ynd;
*serv >> ynd; *serv >> ynd;
_log5 << "Showing yes/no dialog " <<std::endl; tlog5 << "Showing yes/no dialog " <<std::endl;
std::vector<Component*> comps; std::vector<Component*> comps;
for(int i=0;i<ynd.components.size();i++) for(int i=0;i<ynd.components.size();i++)
comps.push_back(&ynd.components[i]); comps.push_back(&ynd.components[i]);
@@ -445,7 +445,7 @@ void CClient::process(int what)
{ {
BattleStart bs; BattleStart bs;
*serv >> bs; //uses new to allocate memory for battleInfo - must be deleted when battle is over *serv >> bs; //uses new to allocate memory for battleInfo - must be deleted when battle is over
_log5 << "Starting battle!" <<std::endl; tlog5 << "Starting battle!" <<std::endl;
gs->apply(&bs); gs->apply(&bs);
if(playerint.find(gs->curB->side1) != playerint.end()) if(playerint.find(gs->curB->side1) != playerint.end())
@@ -459,7 +459,7 @@ void CClient::process(int what)
{ {
BattleNextRound bnr; BattleNextRound bnr;
*serv >> bnr; *serv >> bnr;
_log5 << "Round nr " << bnr.round <<std::endl; tlog5 << "Round nr " << bnr.round <<std::endl;
gs->apply(&bnr); gs->apply(&bnr);
//tell players about next round //tell players about next round
@@ -473,7 +473,7 @@ void CClient::process(int what)
{ {
BattleSetActiveStack sas; BattleSetActiveStack sas;
*serv >> sas; *serv >> sas;
_log5 << "Active stack: " << sas.stack <<std::endl; tlog5 << "Active stack: " << sas.stack <<std::endl;
gs->apply(&sas); gs->apply(&sas);
int owner = gs->curB->getStack(sas.stack)->owner; int owner = gs->curB->getStack(sas.stack)->owner;
if(owner >= PLAYER_LIMIT) //ugly workaround to skip neutral creatures - should be replaced with AI if(owner >= PLAYER_LIMIT) //ugly workaround to skip neutral creatures - should be replaced with AI
@@ -493,7 +493,7 @@ void CClient::process(int what)
{ {
BattleResult br; BattleResult br;
*serv >> br; *serv >> br;
_log5 << "Battle ends. Winner: " << (unsigned)br.winner<< ". Type of end: "<< (unsigned)br.result <<std::endl; tlog5 << "Battle ends. Winner: " << (unsigned)br.winner<< ". Type of end: "<< (unsigned)br.result <<std::endl;
if(playerint.find(gs->curB->side1) != playerint.end()) if(playerint.find(gs->curB->side1) != playerint.end())
playerint[gs->curB->side1]->battleEnd(&br); playerint[gs->curB->side1]->battleEnd(&br);
@@ -507,7 +507,7 @@ void CClient::process(int what)
{ {
BattleStackMoved br; BattleStackMoved br;
*serv >> br; *serv >> br;
_log5 << "Stack "<<br.stack <<" moves to the tile "<<br.tile<<std::endl; tlog5 << "Stack "<<br.stack <<" moves to the tile "<<br.tile<<std::endl;
if(playerint.find(gs->curB->side1) != playerint.end()) if(playerint.find(gs->curB->side1) != playerint.end())
playerint[gs->curB->side1]->battleStackMoved(br.stack,br.tile,br.flags&1,br.flags&2); playerint[gs->curB->side1]->battleStackMoved(br.stack,br.tile,br.flags&1,br.flags&2);
if(playerint.find(gs->curB->side2) != playerint.end()) if(playerint.find(gs->curB->side2) != playerint.end())
@@ -519,7 +519,7 @@ void CClient::process(int what)
{ {
BattleAttack ba; BattleAttack ba;
*serv >> ba; *serv >> ba;
_log5 << "Stack: " << ba.stackAttacking << " is attacking stack "<< ba.bsa.stackAttacked <<std::endl; tlog5 << "Stack: " << ba.stackAttacking << " is attacking stack "<< ba.bsa.stackAttacked <<std::endl;
gs->apply(&ba); gs->apply(&ba);
LOCPLINT->battleAttack(&ba); LOCPLINT->battleAttack(&ba);
break; break;
@@ -543,7 +543,7 @@ void CClient::waitForMoveAndSend(int color)
*serv << ui16(3002) << ba; *serv << ui16(3002) << ba;
return; return;
}HANDLE_EXCEPTION }HANDLE_EXCEPTION
_log1 << "We should not be here!" << std::endl; tlog1 << "We should not be here!" << std::endl;
} }
void CClient::run() void CClient::run()
{ {
@@ -560,10 +560,10 @@ void CClient::run()
void CClient::close() void CClient::close()
{ {
_log3 << "Connection has been requested to be closed.\n"; tlog3 << "Connection has been requested to be closed.\n";
boost::unique_lock<boost::mutex>(*serv->wmx); boost::unique_lock<boost::mutex>(*serv->wmx);
*serv << ui16(99); *serv << ui16(99);
_log3 << "Sended closing signal to the server\n"; tlog3 << "Sended closing signal to the server\n";
serv->close(); serv->close();
_log3 << "Our socket has been closed.\n"; tlog3 << "Our socket has been closed.\n";
} }

View File

@@ -396,7 +396,7 @@ void Graphics::loadHeroFlags()
grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[1]),false)); grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[1]),false));
grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[0]),false)); grupa.create_thread(boost::bind(&Graphics::loadHeroFlags,this,boost::ref(pr[0]),false));
grupa.join_all(); grupa.join_all();
_log0 << "Loading and transforming heroes' flags: "<<th.getDif()<<std::endl; tlog0 << "Loading and transforming heroes' flags: "<<th.getDif()<<std::endl;
} }
SDL_Surface * Graphics::getPic(int ID, bool fort, bool builded) SDL_Surface * Graphics::getPic(int ID, bool fort, bool builded)
{ {

View File

@@ -564,10 +564,6 @@
RelativePath="..\ChangeLog" RelativePath="..\ChangeLog"
> >
</File> </File>
<File
RelativePath=".\ttt.txt"
>
</File>
</Files> </Files>
<Globals> <Globals>
</Globals> </Globals>

View File

@@ -190,8 +190,8 @@ namespace vstd
using vstd::operator-=; using vstd::operator-=;
#include "CConsoleHandler.h" #include "CConsoleHandler.h"
extern std::ostream *logfile; extern DLL_EXPORT std::ostream *logfile;
extern CConsoleHandler *console; extern DLL_EXPORT CConsoleHandler *console;
template <int lvl> class CLogger template <int lvl> class CLogger
{ {
public: public:
@@ -218,32 +218,32 @@ public:
} }
}; };
extern CLogger<0> _log0; //green - standard progress info extern DLL_EXPORT CLogger<0> tlog0; //green - standard progress info
extern CLogger<1> _log1; //red - big errors extern DLL_EXPORT CLogger<1> tlog1; //red - big errors
extern CLogger<2> _log2; //magenta - major warnings extern DLL_EXPORT CLogger<2> tlog2; //magenta - major warnings
extern CLogger<3> _log3; //yellow - minor warnings extern DLL_EXPORT CLogger<3> tlog3; //yellow - minor warnings
extern CLogger<4> _log4; //white - detailed log info extern DLL_EXPORT CLogger<4> tlog4; //white - detailed log info
extern CLogger<5> _log5; //gray - minor log info extern DLL_EXPORT CLogger<5> tlog5; //gray - minor log info
#define HANDLE_EXCEPTION \ #define HANDLE_EXCEPTION \
catch (const std::exception& e) { \ catch (const std::exception& e) { \
_log1 << e.what() << std::endl; \ tlog1 << e.what() << std::endl; \
} \ } \
catch (const std::exception * e) \ catch (const std::exception * e) \
{ \ { \
_log1 << e->what()<< std::endl; \ tlog1 << e->what()<< std::endl; \
delete e; \ delete e; \
} }
#define HANDLE_EXCEPTIONC(COMMAND) \ #define HANDLE_EXCEPTIONC(COMMAND) \
catch (const std::exception& e) { \ catch (const std::exception& e) { \
COMMAND; \ COMMAND; \
_log1 << e.what() << std::endl; \ tlog1 << e.what() << std::endl; \
} \ } \
catch (const std::exception * e) \ catch (const std::exception * e) \
{ \ { \
COMMAND; \ COMMAND; \
_log1 << e->what()<< std::endl; \ tlog1 << e->what()<< std::endl; \
delete e; \ delete e; \
} }

View File

@@ -31,7 +31,7 @@ unsigned char * CLodHandler::giveFile(std::string defName, int * length)
Entry * ourEntry = entries.znajdz(Entry(defName)); Entry * ourEntry = entries.znajdz(Entry(defName));
if(!ourEntry) //nothing's been found if(!ourEntry) //nothing's been found
{ {
_log1<<"Cannot find file: "<<defName; tlog1<<"Cannot find file: "<<defName;
return NULL; return NULL;
} }
if(length) *length = ourEntry->realSize; if(length) *length = ourEntry->realSize;
@@ -47,7 +47,7 @@ unsigned char * CLodHandler::giveFile(std::string defName, int * length)
FILE * f = fopen(name,"rb"); FILE * f = fopen(name,"rb");
int result = fread(outp,1,ourEntry->realSize,f); int result = fread(outp,1,ourEntry->realSize,f);
mutex->unlock(); mutex->unlock();
if(result<0) {_log1<<"Error in file reading: "<<name<<std::endl;delete[] outp; return NULL;} if(result<0) {tlog1<<"Error in file reading: "<<name<<std::endl;delete[] outp; return NULL;}
else else
return outp; return outp;
} }
@@ -228,7 +228,7 @@ void CLodHandler::extract(std::string FName)
out.open(bufff.c_str(), std::ios::binary); out.open(bufff.c_str(), std::ios::binary);
if(!out.is_open()) if(!out.is_open())
{ {
_log1<<"Unable to create "<<bufff; tlog1<<"Unable to create "<<bufff;
} }
else else
{ {
@@ -251,7 +251,7 @@ void CLodHandler::extract(std::string FName)
destin.close(); destin.close();
if(decRes!=0) if(decRes!=0)
{ {
_log1<<"LOD Extraction error"<<" "<<decRes<<" while extracting to "<<bufff<<std::endl; tlog1<<"LOD Extraction error"<<" "<<decRes<<" while extracting to "<<bufff<<std::endl;
} }
} }
delete[] outp; delete[] outp;
@@ -279,7 +279,7 @@ void CLodHandler::extractFile(std::string FName, std::string name)
out.open(bufff.c_str(), std::ios::binary); out.open(bufff.c_str(), std::ios::binary);
if(!out.is_open()) if(!out.is_open())
{ {
_log1<<"Unable to create "<<bufff; tlog1<<"Unable to create "<<bufff;
} }
else else
{ {
@@ -302,7 +302,7 @@ void CLodHandler::extractFile(std::string FName, std::string name)
destin.close(); destin.close();
if(decRes!=0) if(decRes!=0)
{ {
_log1<<"LOD Extraction error"<<" "<<decRes<<" while extracting to "<<bufff<<std::endl; tlog1<<"LOD Extraction error"<<" "<<decRes<<" while extracting to "<<bufff<<std::endl;
} }
} }
delete[] outp; delete[] outp;
@@ -391,7 +391,7 @@ void CLodHandler::init(std::string lodFile, std::string dirName)
} }
} }
else else
_log1<<"Warning: No "+dirName+"/ folder!"<<std::endl; tlog1<<"Warning: No "+dirName+"/ folder!"<<std::endl;
} }
std::string CLodHandler::getTextFile(std::string name) std::string CLodHandler::getTextFile(std::string name)
{ {

View File

@@ -397,7 +397,6 @@ CGObjectInstance::~CGObjectInstance()
} }
CGHeroInstance::CGHeroInstance() CGHeroInstance::CGHeroInstance()
{ {
looseFormation = true;
tacticFormationEnabled = inTownGarrison = false; tacticFormationEnabled = inTownGarrison = false;
portrait = level = exp = -1; portrait = level = exp = -1;
isStanding = true; isStanding = true;

View File

@@ -82,7 +82,7 @@ public:
mutable int moveDir; //format: 123 mutable int moveDir; //format: 123
// 8 4 // 8 4
// 765 // 765
mutable ui8 isStanding, tacticFormationEnabled, looseFormation; mutable ui8 isStanding, tacticFormationEnabled;
CHero * type; CHero * type;
ui32 exp; //experience point ui32 exp; //experience point
int level; //current level of hero int level; //current level of hero

View File

@@ -46,27 +46,27 @@ CConnection::CConnection(std::string host, std::string port, std::string Name, s
tcp::resolver::iterator end, pom, endpoint_iterator = resolver.resolve(tcp::resolver::query(host,port),error); tcp::resolver::iterator end, pom, endpoint_iterator = resolver.resolve(tcp::resolver::query(host,port),error);
if(error) if(error)
{ {
_log1 << "Problem with resolving: " << std::endl << error <<std::endl; tlog1 << "Problem with resolving: " << std::endl << error <<std::endl;
goto connerror1; goto connerror1;
} }
pom = endpoint_iterator; pom = endpoint_iterator;
if(pom != end) if(pom != end)
_log0<<"Found endpoints:" << std::endl; tlog0<<"Found endpoints:" << std::endl;
else else
{ {
_log1 << "Critical problem: No endpoints found!" << std::endl; tlog1 << "Critical problem: No endpoints found!" << std::endl;
goto connerror1; goto connerror1;
} }
i=0; i=0;
while(pom != end) while(pom != end)
{ {
_log0 << "\t" << i << ": " << (boost::asio::ip::tcp::endpoint&)*pom << std::endl; tlog0 << "\t" << i << ": " << (boost::asio::ip::tcp::endpoint&)*pom << std::endl;
pom++; pom++;
} }
i=0; i=0;
while(endpoint_iterator != end) while(endpoint_iterator != end)
{ {
_log0 << "Trying connection to " << (boost::asio::ip::tcp::endpoint&)*endpoint_iterator << " (" << i++ << ")" << std::endl; tlog0 << "Trying connection to " << (boost::asio::ip::tcp::endpoint&)*endpoint_iterator << " (" << i++ << ")" << std::endl;
socket->connect(*endpoint_iterator, error); socket->connect(*endpoint_iterator, error);
if(!error) if(!error)
{ {
@@ -75,18 +75,18 @@ CConnection::CConnection(std::string host, std::string port, std::string Name, s
} }
else else
{ {
_log1 << "Problem with connecting: " << std::endl << error << std::endl; tlog1 << "Problem with connecting: " << std::endl << error << std::endl;
} }
endpoint_iterator++; endpoint_iterator++;
} }
//we shouldn't be here - error handling //we shouldn't be here - error handling
connerror1: connerror1:
_log1 << "Something went wrong... checking for error info" << std::endl; tlog1 << "Something went wrong... checking for error info" << std::endl;
if(error) if(error)
std::cout << error <<std::endl; std::cout << error <<std::endl;
else else
_log1 << "No error info. " << std::endl; tlog1 << "No error info. " << std::endl;
delete io_service; delete io_service;
//delete socket; //delete socket;
throw std::string("Can't establish connection :("); throw std::string("Can't establish connection :(");

View File

@@ -12,14 +12,14 @@
class CLodHandler; class CLodHandler;
LibClasses * VLC = NULL; LibClasses * VLC = NULL;
CLodHandler * bitmaph=NULL; CLodHandler * bitmaph=NULL;
CLogger<0> _log0; DLL_EXPORT CLogger<0> tlog0;
CLogger<1> _log1; DLL_EXPORT CLogger<1> tlog1;
CLogger<2> _log2; DLL_EXPORT CLogger<2> tlog2;
CLogger<3> _log3; DLL_EXPORT CLogger<3> tlog3;
CLogger<4> _log4; DLL_EXPORT CLogger<4> tlog4;
CLogger<5> _log5; DLL_EXPORT CLogger<5> tlog5;
CConsoleHandler *console = NULL; DLL_EXPORT CConsoleHandler *console = NULL;
std::ostream *logfile = NULL; DLL_EXPORT std::ostream *logfile = NULL;
DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *Logfile) DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *Logfile)
{ {
console = Console; console = Console;
@@ -32,39 +32,39 @@ DLL_EXPORT void initDLL(CLodHandler *b, CConsoleHandler *Console, std::ostream *
heroh->loadHeroes(); heroh->loadHeroes();
heroh->loadPortraits(); heroh->loadPortraits();
VLC->heroh = heroh; VLC->heroh = heroh;
_log0 <<"\tHero handler: "<<pomtime.getDif()<<std::endl; tlog0 <<"\tHero handler: "<<pomtime.getDif()<<std::endl;
CArtHandler * arth = new CArtHandler; CArtHandler * arth = new CArtHandler;
arth->loadArtifacts(); arth->loadArtifacts();
VLC->arth = arth; VLC->arth = arth;
_log0<<"\tArtifact handler: "<<pomtime.getDif()<<std::endl; tlog0<<"\tArtifact handler: "<<pomtime.getDif()<<std::endl;
CCreatureHandler * creh = new CCreatureHandler(); CCreatureHandler * creh = new CCreatureHandler();
creh->loadCreatures(); creh->loadCreatures();
VLC->creh = creh; VLC->creh = creh;
_log0<<"\tCreature handler: "<<pomtime.getDif()<<std::endl; tlog0<<"\tCreature handler: "<<pomtime.getDif()<<std::endl;
VLC->townh = new CTownHandler; VLC->townh = new CTownHandler;
VLC->townh->loadNames(); VLC->townh->loadNames();
_log0<<"\tTown handler: "<<pomtime.getDif()<<std::endl; tlog0<<"\tTown handler: "<<pomtime.getDif()<<std::endl;
CObjectHandler * objh = new CObjectHandler; CObjectHandler * objh = new CObjectHandler;
objh->loadObjects(); objh->loadObjects();
VLC->objh = objh; VLC->objh = objh;
_log0<<"\tObject handler: "<<pomtime.getDif()<<std::endl; tlog0<<"\tObject handler: "<<pomtime.getDif()<<std::endl;
VLC->dobjinfo = new CDefObjInfoHandler; VLC->dobjinfo = new CDefObjInfoHandler;
VLC->dobjinfo->load(); VLC->dobjinfo->load();
_log0<<"\tDef information handler: "<<pomtime.getDif()<<std::endl; tlog0<<"\tDef information handler: "<<pomtime.getDif()<<std::endl;
VLC->buildh = new CBuildingHandler; VLC->buildh = new CBuildingHandler;
VLC->buildh->loadBuildings(); VLC->buildh->loadBuildings();
_log0<<"\tBuilding handler: "<<pomtime.getDif()<<std::endl; tlog0<<"\tBuilding handler: "<<pomtime.getDif()<<std::endl;
CSpellHandler * spellh = new CSpellHandler; CSpellHandler * spellh = new CSpellHandler;
spellh->loadSpells(); spellh->loadSpells();
VLC->spellh = spellh; VLC->spellh = spellh;
_log0<<"\tSpell handler: "<<pomtime.getDif()<<std::endl; tlog0<<"\tSpell handler: "<<pomtime.getDif()<<std::endl;
} }
DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode) DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mode)

24
map.cpp
View File

@@ -448,25 +448,25 @@ void Mapa::initFromBytes(unsigned char * bufor)
th.getDif(); th.getDif();
int i=0; int i=0;
readHeader(bufor, i); readHeader(bufor, i);
_log0<<"\tReading header: "<<th.getDif()<<std::endl; tlog0<<"\tReading header: "<<th.getDif()<<std::endl;
readRumors(bufor, i); readRumors(bufor, i);
_log0<<"\tReading rumors: "<<th.getDif()<<std::endl; tlog0<<"\tReading rumors: "<<th.getDif()<<std::endl;
readPredefinedHeroes(bufor, i); readPredefinedHeroes(bufor, i);
_log0<<"\tReading predefined heroes: "<<th.getDif()<<std::endl; tlog0<<"\tReading predefined heroes: "<<th.getDif()<<std::endl;
readTerrain(bufor, i); readTerrain(bufor, i);
_log0<<"\tReading terrain: "<<th.getDif()<<std::endl; tlog0<<"\tReading terrain: "<<th.getDif()<<std::endl;
readDefInfo(bufor, i); readDefInfo(bufor, i);
_log0<<"\tReading defs info: "<<th.getDif()<<std::endl; tlog0<<"\tReading defs info: "<<th.getDif()<<std::endl;
readObjects(bufor, i); readObjects(bufor, i);
_log0<<"\tReading objects: "<<th.getDif()<<std::endl; tlog0<<"\tReading objects: "<<th.getDif()<<std::endl;
readEvents(bufor, i); readEvents(bufor, i);
_log0<<"\tReading events: "<<th.getDif()<<std::endl; tlog0<<"\tReading events: "<<th.getDif()<<std::endl;
//map readed, bufor no longer needed //map readed, bufor no longer needed
delete[] bufor; bufor=NULL; delete[] bufor; bufor=NULL;
@@ -478,7 +478,7 @@ void Mapa::initFromBytes(unsigned char * bufor)
continue; continue;
addBlockVisTiles(objects[f]); addBlockVisTiles(objects[f]);
} }
_log0<<"\tCalculating blocked/visitable tiles: "<<th.getDif()<<std::endl; tlog0<<"\tCalculating blocked/visitable tiles: "<<th.getDif()<<std::endl;
} }
void Mapa::removeBlockVisTiles(CGObjectInstance * obj) void Mapa::removeBlockVisTiles(CGObjectInstance * obj)
{ {
@@ -534,7 +534,7 @@ void Mapa::addBlockVisTiles(CGObjectInstance * obj)
} }
Mapa::Mapa(std::string filename) Mapa::Mapa(std::string filename)
{ {
_log0<<"Opening map file: "<<filename<<"\t "<<std::flush; tlog0<<"Opening map file: "<<filename<<"\t "<<std::flush;
gzFile map = gzopen(filename.c_str(),"rb"); gzFile map = gzopen(filename.c_str(),"rb");
std::vector<unsigned char> mapstr; int pom; std::vector<unsigned char> mapstr; int pom;
while((pom=gzgetc(map))>=0) while((pom=gzgetc(map))>=0)
@@ -547,11 +547,11 @@ Mapa::Mapa(std::string filename)
{ {
initTable[ss] = mapstr[ss]; initTable[ss] = mapstr[ss];
} }
_log0<<"done."<<std::endl; tlog0<<"done."<<std::endl;
boost::crc_32_type result; boost::crc_32_type result;
result.process_bytes(initTable,mapstr.size()); result.process_bytes(initTable,mapstr.size());
checksum = result.checksum(); checksum = result.checksum();
_log0 << "\tOur map checksum: "<<result.checksum() << std::endl; tlog0 << "\tOur map checksum: "<<result.checksum() << std::endl;
initFromBytes(initTable); initFromBytes(initTable);
} }
@@ -1725,7 +1725,7 @@ void Mapa::readDefInfo( unsigned char * bufor, int &i)
vinya->visitMap[zi] = reverse(bytes[6+zi]); vinya->visitMap[zi] = reverse(bytes[6+zi]);
} }
i+=16; i+=16;
if(vinya->id!=34) if(vinya->id!=34 && vinya->id!=70)
vinya->visitDir = VLC->dobjinfo->gobjs[vinya->id][vinya->subid]->visitDir; vinya->visitDir = VLC->dobjinfo->gobjs[vinya->id][vinya->subid]->visitDir;
else else
vinya->visitDir = 0xff; vinya->visitDir = 0xff;

View File

@@ -469,7 +469,7 @@ void processDef (CGDefInfo* def)
pom->height = pom->handler->ourImages[0].bitmap->h/32; pom->height = pom->handler->ourImages[0].bitmap->h/32;
} }
else if(def->id != 34 && def->id != 98) else if(def->id != 34 && def->id != 98)
_log3 << "\t\tMinor warning: lacking def info for " << def->id << " " << def->subid <<" " << def->name << std::endl; tlog3 << "\t\tMinor warning: lacking def info for " << def->id << " " << def->subid <<" " << def->name << std::endl;
if(!def->handler->alphaTransformed) if(!def->handler->alphaTransformed)
{ {
for(int yy=0; yy<def->handler->ourImages.size(); ++yy) for(int yy=0; yy<def->handler->ourImages.size(); ++yy)
@@ -484,7 +484,7 @@ void CMapHandler::init()
timeHandler th; timeHandler th;
th.getDif(); th.getDif();
loadDefs(); //loading castles' defs loadDefs(); //loading castles' defs
_log0<<"Reading terrain defs: "<<th.getDif()<<std::endl; tlog0<<"Reading terrain defs: "<<th.getDif()<<std::endl;
std::ifstream ifs("config/townsDefs.txt"); std::ifstream ifs("config/townsDefs.txt");
int ccc; int ccc;
@@ -501,10 +501,10 @@ void CMapHandler::init()
n = CGI->state->capitols[i%ccc]; n = CGI->state->capitols[i%ccc];
ifs >> n->name; ifs >> n->name;
if(!n) if(!n)
_log1 << "*HUGE* Warning - missing town def for " << i << std::endl; tlog1 << "*HUGE* Warning - missing town def for " << i << std::endl;
map->defs.insert(n); map->defs.insert(n);
} }
_log0<<"\tLoading town def info: "<<th.getDif()<<std::endl; tlog0<<"\tLoading town def info: "<<th.getDif()<<std::endl;
for(int i=0;i<map->heroes.size();i++) for(int i=0;i<map->heroes.size();i++)
{ {
@@ -518,7 +518,7 @@ void CMapHandler::init()
std::for_each(map->defy.begin(),map->defy.end(),processDef); //load h3m defs 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 std::for_each(map->defs.begin(),map->defs.end(),processDef); //and non-h3m defs
_log0<<"\tUnpacking and handling defs: "<<th.getDif()<<std::endl; tlog0<<"\tUnpacking and handling defs: "<<th.getDif()<<std::endl;
for(int i=0;i<PLAYER_LIMIT;i++) for(int i=0;i<PLAYER_LIMIT;i++)
{ {
@@ -527,20 +527,20 @@ void CMapHandler::init()
usedHeroes.insert(map->players[i].heroesNames[j].heroID); usedHeroes.insert(map->players[i].heroesNames[j].heroID);
} }
} }
_log0<<"\tChecking used heroes: "<<th.getDif()<<std::endl; tlog0<<"\tChecking used heroes: "<<th.getDif()<<std::endl;
for(int h=0; h<map->defy.size(); ++h) //initializing loaded def handler's info { for(int h=0; h<map->defy.size(); ++h) //initializing loaded def handler's info {
CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler)); CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler));
_log0<<"\tCollecting loaded def's handlers: "<<th.getDif()<<std::endl; tlog0<<"\tCollecting loaded def's handlers: "<<th.getDif()<<std::endl;
prepareFOWDefs(); prepareFOWDefs();
roadsRiverTerrainInit(); //road's and river's DefHandlers; and simple values initialization roadsRiverTerrainInit(); //road's and river's DefHandlers; and simple values initialization
borderAndTerrainBitmapInit(); borderAndTerrainBitmapInit();
_log0<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDif()<<std::endl; tlog0<<"\tPreparing FoW, roads, rivers,borders: "<<th.getDif()<<std::endl;
initObjectRects(); initObjectRects();
_log0<<"\tMaking object rects: "<<th.getDif()<<std::endl; tlog0<<"\tMaking object rects: "<<th.getDif()<<std::endl;
} }
SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect) SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector<unsigned char> > > * visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect)

View File

@@ -341,7 +341,7 @@ void CGameHandler::handleConnection(std::set<int> players, CConnection &c)
{ {
case 99: //end! case 99: //end!
{ {
_log0 << "We have been requested to close.\n"; tlog0 << "We have been requested to close.\n";
exit(0); exit(0);
} }
case 100: //my interface ended its turn case 100: //my interface ended its turn
@@ -856,7 +856,7 @@ upgend:
si32 hid; si32 hid;
ui8 formation; ui8 formation;
c >> hid >> formation; c >> hid >> formation;
gs->getHero(hid)->army.formation = !formation; gs->getHero(hid)->army.formation = formation;
break; break;
} }
case 2001: case 2001:
@@ -967,12 +967,12 @@ upgend:
} }
catch (const std::exception& e) catch (const std::exception& e)
{ {
_log1 << e.what() << std::endl; tlog1 << e.what() << std::endl;
end2 = true; end2 = true;
} }
catch (const std::exception * e) catch (const std::exception * e)
{ {
_log1 << e->what()<< std::endl; tlog1 << e->what()<< std::endl;
end2 = true; end2 = true;
delete e; delete e;
} }
@@ -1273,7 +1273,7 @@ void CGameHandler::setupBattle( BattleInfo * curB, int3 tile, CCreatureSet &army
positions.open("config" PATHSEPARATOR "battleStartpos.txt", std::ios_base::in|std::ios_base::binary); positions.open("config" PATHSEPARATOR "battleStartpos.txt", std::ios_base::in|std::ios_base::binary);
if(!positions.is_open()) if(!positions.is_open())
{ {
_log0<<"Unable to open battleStartpos.txt!"<<std::endl; tlog0<<"Unable to open battleStartpos.txt!"<<std::endl;
} }
std::string dump; std::string dump;
positions>>dump; positions>>dump; positions>>dump; positions>>dump;

View File

@@ -22,14 +22,6 @@ using namespace boost;
using namespace boost::asio; using namespace boost::asio;
using namespace boost::asio::ip; using namespace boost::asio::ip;
namespace intpr = boost::interprocess; namespace intpr = boost::interprocess;
extern CLogger<0> _log0;
extern CLogger<1> _log1;
extern CLogger<2> _log2;
extern CLogger<3> _log3;
extern CLogger<4> _log4;
extern CLogger<5> _log5;
extern CConsoleHandler *console;// = NULL;
extern std::ostream *logfile;// = NULL;
bool end2 = false; bool end2 = false;
int port = 3030; int port = 3030;