2007-08-15 18:13:11 +03:00
|
|
|
#include "stdafx.h"
|
2007-08-17 20:42:21 +03:00
|
|
|
#include "CConsoleHandler.h"
|
|
|
|
#include "CAdvmapInterface.h"
|
2008-08-22 15:21:09 +03:00
|
|
|
#include "CCastleInterface.h"
|
2007-11-19 00:58:28 +02:00
|
|
|
#include "CPlayerInterface.h"
|
2007-08-15 18:13:11 +03:00
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_thread.h"
|
2007-08-17 20:42:21 +03:00
|
|
|
#include "CGameInfo.h"
|
|
|
|
#include "global.h"
|
2007-08-29 15:18:31 +03:00
|
|
|
#include "CGameState.h"
|
|
|
|
#include "CCallback.h"
|
2007-09-18 16:30:26 +03:00
|
|
|
#include "CPathfinder.h"
|
|
|
|
#include "mapHandler.h"
|
2007-08-17 20:42:21 +03:00
|
|
|
#include <sstream>
|
2007-10-17 01:39:11 +03:00
|
|
|
#include "SDL_Extensions.h"
|
2007-11-19 00:58:28 +02:00
|
|
|
#include "hch/CHeroHandler.h"
|
2008-02-26 01:26:50 +02:00
|
|
|
#include "hch/CLodHandler.h"
|
|
|
|
#include "boost/filesystem/operations.hpp"
|
|
|
|
#include <boost/algorithm/string.hpp>
|
2008-06-21 16:27:52 +03:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <conio.h>
|
|
|
|
#else
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool continueReadingConsole = true;
|
|
|
|
|
2007-09-30 19:16:00 +03:00
|
|
|
int internalFunc(void * callback)
|
2007-08-15 18:13:11 +03:00
|
|
|
{
|
2007-09-30 19:16:00 +03:00
|
|
|
CCallback * cb = (CCallback*)callback;
|
2007-08-15 18:13:11 +03:00
|
|
|
char * usersMessage = new char[500];
|
|
|
|
std::string readed;
|
|
|
|
while(true)
|
|
|
|
{
|
2008-06-21 16:27:52 +03:00
|
|
|
#ifdef WIN32
|
|
|
|
if(continueReadingConsole && kbhit())
|
|
|
|
#else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
std::cin.getline(usersMessage, 500);
|
|
|
|
std::istringstream readed;
|
|
|
|
std::string pom(usersMessage);
|
|
|
|
readed.str(pom);
|
|
|
|
std::string cn; //command name
|
|
|
|
readed >> cn;
|
|
|
|
int3 src, dst;
|
2007-08-29 15:18:31 +03:00
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
int heronum;
|
|
|
|
int3 dest;
|
2007-08-29 15:18:31 +03:00
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
if(pom==std::string("die, fool"))
|
|
|
|
exit(0);
|
2008-08-22 15:21:09 +03:00
|
|
|
if(cn==std::string("activate"))
|
|
|
|
{
|
|
|
|
int what;
|
|
|
|
readed >> what;
|
|
|
|
switch (what)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
LOCPLINT->curint->activate();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
LOCPLINT->adventureInt->activate();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
LOCPLINT->castleInt->activate();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2008-06-21 16:27:52 +03:00
|
|
|
else if(pom==std::string("get txt"))
|
2008-02-26 01:26:50 +02:00
|
|
|
{
|
2008-06-21 16:27:52 +03:00
|
|
|
boost::filesystem::create_directory("Extracted_txts");
|
|
|
|
std::cout<<"Command accepted. Opening .lod file...\t";
|
|
|
|
CLodHandler * txth = new CLodHandler;
|
2008-08-02 18:08:03 +03:00
|
|
|
txth->init(std::string(DATA_DIR "Data" PATHSEPARATOR "H3bitmap.lod"),"data");
|
2008-06-21 16:27:52 +03:00
|
|
|
std::cout<<"done.\nScanning .lod file\n";
|
|
|
|
int curp=0;
|
|
|
|
std::string pattern = ".TXT";
|
|
|
|
for(int i=0;i<txth->entries.size(); i++)
|
2008-02-26 01:26:50 +02:00
|
|
|
{
|
2008-06-21 16:27:52 +03:00
|
|
|
std::string pom = txth->entries[i].nameStr;
|
|
|
|
if(boost::algorithm::find_last(pom,pattern))
|
|
|
|
{
|
|
|
|
txth->extractFile(std::string("Extracted_txts\\")+pom,pom);
|
|
|
|
}
|
|
|
|
int p2 = ((float)i/(float)txth->entries.size())*(float)100;
|
|
|
|
if(p2!=curp)
|
|
|
|
{
|
|
|
|
curp = p2;
|
|
|
|
std::cout<<"\r"<<curp<<"%";
|
|
|
|
}
|
2008-02-26 01:26:50 +02:00
|
|
|
}
|
2008-06-21 16:27:52 +03:00
|
|
|
std::cout<<"\rExtracting done :)\n";
|
2008-02-26 01:26:50 +02:00
|
|
|
}
|
2008-06-21 16:27:52 +03:00
|
|
|
vector<Coordinate>* p;
|
2008-08-02 18:08:03 +03:00
|
|
|
int heroX;
|
|
|
|
int heroY;
|
|
|
|
int heroZ;
|
2008-06-21 16:27:52 +03:00
|
|
|
switch (*cn.c_str())
|
2007-10-17 01:39:11 +03:00
|
|
|
{
|
2008-06-21 16:27:52 +03:00
|
|
|
//case 'P':
|
|
|
|
// std::cout<<"Policzyc sciezke."<<std::endl;
|
|
|
|
// readed>>src>>dst;
|
|
|
|
//
|
|
|
|
// p = CGI->pathf->GetPath(Coordinate(src),Coordinate(dst),CGI->heroh->heroInstances[0]);
|
|
|
|
// LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->ConvertToOldFormat(p);
|
|
|
|
// //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
|
|
|
|
// break;
|
|
|
|
//case 'm': //number of heroes
|
|
|
|
// std::cout<<"Number of heroes: "<<CGI->heroh->heroInstances.size()<<std::endl;
|
|
|
|
// break;
|
|
|
|
//case 'H': //position of hero
|
|
|
|
// readed>>heronum;
|
|
|
|
// std::cout<<"Position of hero "<<heronum<<": "<<CGI->heroh->heroInstances[heronum]->getPosition(false)<<std::endl;
|
|
|
|
// break;
|
2008-07-02 11:39:56 +03:00
|
|
|
//case 'M': //move heroa
|
|
|
|
// {
|
|
|
|
// readed>>heronum>>dest;
|
|
|
|
// const CGHeroInstance * hero = cb->getHeroInfo(0,heronum,0);
|
|
|
|
// p = CGI->pathf->GetPath(Coordinate(hero->getPosition(false)),Coordinate(dest),hero);
|
|
|
|
// cb->moveHero(heronum, CGI->pathf->ConvertToOldFormat(p), 0, 0);
|
|
|
|
// //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
|
|
|
|
// break;
|
|
|
|
// }
|
2008-07-29 12:53:27 +03:00
|
|
|
//case 'D': //pos description
|
|
|
|
// readed>>src;
|
|
|
|
// CGI->mh->getObjDescriptions(src);
|
|
|
|
// break;
|
|
|
|
//case 'I':
|
|
|
|
// {
|
|
|
|
// SDL_Surface * temp = LOCPLINT->infoWin(NULL);
|
|
|
|
// blitAtWR(temp,605,389);
|
|
|
|
// SDL_FreeSurface(temp);
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
//case 'T': //test rect
|
|
|
|
// readed>>src;
|
|
|
|
// for(int g=0; g<8; ++g)
|
|
|
|
// {
|
|
|
|
// for(int v=0; v<8; ++v)
|
|
|
|
// {
|
|
|
|
// int3 csrc = src;
|
|
|
|
// csrc.y+=g;
|
|
|
|
// csrc.x+=v;
|
|
|
|
// if(CGI->mh->getObjDescriptions(csrc).size())
|
|
|
|
// std::cout<<'x';
|
|
|
|
// else
|
|
|
|
// std::cout<<'o';
|
|
|
|
// }
|
|
|
|
// std::cout<<std::endl;
|
|
|
|
// }
|
|
|
|
// break;
|
2008-06-21 16:27:52 +03:00
|
|
|
//case 'A': //hide everything from map
|
|
|
|
// for(int c=0; c<CGI->objh->objInstances.size(); ++c)
|
|
|
|
// {
|
|
|
|
// CGI->mh->hideObject(CGI->objh->objInstances[c]);
|
|
|
|
// }
|
|
|
|
// break;
|
|
|
|
//case 'R': //restora all objects after A has been pressed
|
|
|
|
// for(int c=0; c<CGI->objh->objInstances.size(); ++c)
|
|
|
|
// {
|
|
|
|
// CGI->mh->printObject(CGI->objh->objInstances[c]);
|
|
|
|
// }
|
|
|
|
// break;
|
2007-11-03 18:46:08 +02:00
|
|
|
}
|
2008-06-21 16:27:52 +03:00
|
|
|
//SDL_Delay(100);
|
2008-06-30 03:06:41 +03:00
|
|
|
//delete p;
|
2007-08-17 20:42:21 +03:00
|
|
|
}
|
2008-08-31 20:23:40 +03:00
|
|
|
SDL_Delay(100);
|
2007-08-15 18:13:11 +03:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-06-21 16:27:52 +03:00
|
|
|
SDL_Thread * consoleReadingThread;
|
|
|
|
|
2007-08-15 18:13:11 +03:00
|
|
|
void CConsoleHandler::runConsole()
|
|
|
|
{
|
2008-06-21 16:27:52 +03:00
|
|
|
consoleReadingThread = SDL_CreateThread(&internalFunc, cb);
|
2007-08-15 18:13:11 +03:00
|
|
|
}
|