mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
* moved map reading to the map.cpp
* merged changes from trunk (since r461)
This commit is contained in:
parent
c7dde147c3
commit
c351496a47
@ -316,6 +316,7 @@ void CTerrainRect::clickLeft(tribool down)
|
||||
//Convert to old format.
|
||||
currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->ConvertToOldFormat(p);
|
||||
|
||||
delete p;
|
||||
//currentPath = LOCPLINT->adventureInt->heroList.items[LOCPLINT->adventureInt->heroList.selected].second = CGI->pathf->getPath(bufpos,mp,currentHero,1);
|
||||
}
|
||||
}
|
||||
|
@ -213,7 +213,7 @@ void CBattleInterface::show(SDL_Surface * to)
|
||||
}
|
||||
}
|
||||
//showing selected unit's range
|
||||
if(creAnims[activeStack]->getType() != 0) //don't show if unit is moving
|
||||
if(activeStack != -1 && creAnims[activeStack]->getType() != 0) //don't show if unit is moving
|
||||
{
|
||||
showRange(to, activeStack);
|
||||
}
|
||||
@ -240,37 +240,68 @@ void CBattleInterface::show(SDL_Surface * to)
|
||||
defendingHero->show(to);
|
||||
|
||||
//showing units //a lot of work...
|
||||
int stackByHex[187];
|
||||
for(int b=0; b<187; ++b)
|
||||
stackByHex[b] = -1;
|
||||
std::vector<int> stackAliveByHex[187];
|
||||
//double loop because dead stacks should be printed first
|
||||
for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
|
||||
{
|
||||
stackByHex[j->second.position] = j->second.ID;
|
||||
if(j->second.alive)
|
||||
stackAliveByHex[j->second.position].push_back(j->second.ID);
|
||||
}
|
||||
std::vector<int> stackDeadByHex[187];
|
||||
for(std::map<int, CStack>::iterator j=stacks.begin(); j!=stacks.end(); ++j)
|
||||
{
|
||||
if(!j->second.alive)
|
||||
stackDeadByHex[j->second.position].push_back(j->second.ID);
|
||||
}
|
||||
|
||||
attackingShowHelper(); // handle attack animation
|
||||
|
||||
for(int b=0; b<187; ++b)
|
||||
for(int b=0; b<187; ++b) //showing dead stacks
|
||||
{
|
||||
if(stackByHex[b]!=-1)
|
||||
for(int v=0; v<stackDeadByHex[b].size(); ++v)
|
||||
{
|
||||
creAnims[stackByHex[b]]->nextFrame(to, creAnims[stackByHex[b]]->pos.x, creAnims[stackByHex[b]]->pos.y, creDir[stackByHex[b]], (animCount%2==0 || creAnims[stackByHex[b]]->getType()!=2) && stacks[stackByHex[b]].alive, stackByHex[b]==activeStack); //increment always when moving, never if stack died
|
||||
creAnims[stackDeadByHex[b][v]]->nextFrame(to, creAnims[stackDeadByHex[b][v]]->pos.x, creAnims[stackDeadByHex[b][v]]->pos.y, creDir[stackDeadByHex[b][v]], (animCount%2==0 || creAnims[stackDeadByHex[b][v]]->getType()!=2) && stacks[stackDeadByHex[b][v]].alive, stackDeadByHex[b][v]==activeStack); //increment always when moving, never if stack died
|
||||
//printing amount
|
||||
if(stacks[stackByHex[b]].amount > 0) //don't print if stack is not alive
|
||||
if(stacks[stackDeadByHex[b][v]].amount > 0) //don't print if stack is not alive
|
||||
{
|
||||
if(stacks[stackByHex[b]].attackerOwned)
|
||||
if(stacks[stackDeadByHex[b][v]].attackerOwned)
|
||||
{
|
||||
CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackByHex[b]]->pos.x + 220, creAnims[stackByHex[b]]->pos.y + 260));
|
||||
CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackDeadByHex[b][v]]->pos.x + 220, creAnims[stackDeadByHex[b][v]]->pos.y + 260));
|
||||
std::stringstream ss;
|
||||
ss<<stacks[stackByHex[b]].amount;
|
||||
CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackByHex[b]]->pos.x + 220 + 14, creAnims[stackByHex[b]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
|
||||
ss<<stacks[stackDeadByHex[b][v]].amount;
|
||||
CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackDeadByHex[b][v]]->pos.x + 220 + 14, creAnims[stackDeadByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
|
||||
}
|
||||
else
|
||||
{
|
||||
CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackByHex[b]]->pos.x + 202, creAnims[stackByHex[b]]->pos.y + 260));
|
||||
CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackDeadByHex[b][v]]->pos.x + 202, creAnims[stackDeadByHex[b][v]]->pos.y + 260));
|
||||
std::stringstream ss;
|
||||
ss<<stacks[stackByHex[b]].amount;
|
||||
CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackByHex[b]]->pos.x + 202 + 14, creAnims[stackByHex[b]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
|
||||
ss<<stacks[stackDeadByHex[b][v]].amount;
|
||||
CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackDeadByHex[b][v]]->pos.x + 202 + 14, creAnims[stackDeadByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int b=0; b<187; ++b) //showing alive stacks
|
||||
{
|
||||
for(int v=0; v<stackAliveByHex[b].size(); ++v)
|
||||
{
|
||||
creAnims[stackAliveByHex[b][v]]->nextFrame(to, creAnims[stackAliveByHex[b][v]]->pos.x, creAnims[stackAliveByHex[b][v]]->pos.y, creDir[stackAliveByHex[b][v]], (animCount%2==0 || creAnims[stackAliveByHex[b][v]]->getType()!=2) && stacks[stackAliveByHex[b][v]].alive, stackAliveByHex[b][v]==activeStack); //increment always when moving, never if stack died
|
||||
//printing amount
|
||||
if(stacks[stackAliveByHex[b][v]].amount > 0) //don't print if stack is not alive
|
||||
{
|
||||
if(stacks[stackAliveByHex[b][v]].attackerOwned)
|
||||
{
|
||||
CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + 220, creAnims[stackAliveByHex[b][v]]->pos.y + 260));
|
||||
std::stringstream ss;
|
||||
ss<<stacks[stackAliveByHex[b][v]].amount;
|
||||
CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackAliveByHex[b][v]]->pos.x + 220 + 14, creAnims[stackAliveByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
|
||||
}
|
||||
else
|
||||
{
|
||||
CSDL_Ext::blit8bppAlphaTo24bpp(amountNormal, NULL, to, &genRect(amountNormal->h, amountNormal->w, creAnims[stackAliveByHex[b][v]]->pos.x + 202, creAnims[stackAliveByHex[b][v]]->pos.y + 260));
|
||||
std::stringstream ss;
|
||||
ss<<stacks[stackAliveByHex[b][v]].amount;
|
||||
CSDL_Ext::printAtMiddleWB(ss.str(), creAnims[stackAliveByHex[b][v]]->pos.x + 202 + 14, creAnims[stackAliveByHex[b][v]]->pos.y + 260 + 4, GEOR13, 20, zwykly, to);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1113,12 +1144,11 @@ bool CBattleConsole::addText(std::string text)
|
||||
{
|
||||
texts.push_back( text.substr(firstInToken, i-firstInToken) );
|
||||
firstInToken = i+1;
|
||||
lastShown++;
|
||||
}
|
||||
}
|
||||
|
||||
texts.push_back( text.substr(firstInToken, text.size()) );
|
||||
lastShown++;
|
||||
lastShown = texts.size()-1;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ public:
|
||||
bool hovered, strictHovered;
|
||||
CBattleInterface * myInterface; //interface that owns me
|
||||
static std::pair<int, int> getXYUnitAnim(int hexNum, bool attacker, CCreature * creature); //returns (x, y) of left top corner of animation
|
||||
static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left)
|
||||
static signed char mutualPosition(int hex1, int hex2); //returns info about mutual position of given hexes (-1 - they're distant, 0 - left top, 1 - right top, 2 - right, 3 - right bottom, 4 - left bottom, 5 - left)
|
||||
//for user interactions
|
||||
void hover (bool on);
|
||||
void activate();
|
||||
|
@ -132,9 +132,10 @@ bool CCallback::moveHero(int ID, CPath * path, int idtype, int pathType)
|
||||
{
|
||||
hero->pos = endpos;
|
||||
}*/
|
||||
if((hero->movement>=CGI->mh->getCost(int3(stpos.x-1, stpos.y, stpos.z), int3(endpos.x-1, endpos.y, endpos.z), hero)) || player==-1)
|
||||
if(hero->movement >= (ourPath->nodes.size()>=2 ? (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist || player==-1)
|
||||
{ //performing move
|
||||
hero->movement-=CGI->mh->getCost(int3(stpos.x-1, stpos.y, stpos.z), int3(endpos.x-1, endpos.y, endpos.z), hero);
|
||||
hero->movement -= (ourPath->nodes.size()>=2 ? (*(ourPath->nodes.end()-2)).dist : 0) - ourPath->nodes[i].dist;
|
||||
ourPath->nodes.pop_back();
|
||||
|
||||
std::vector< CGObjectInstance * > vis = CGI->mh->getVisitableObjs(CGHeroInstance::convertPosition(curd.dst,false));
|
||||
bool blockvis = false;
|
||||
|
@ -16,6 +16,13 @@
|
||||
#include "hch/CLodHandler.h"
|
||||
#include "boost/filesystem/operations.hpp"
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#ifdef WIN32
|
||||
#include <conio.h>
|
||||
#else
|
||||
#endif
|
||||
|
||||
bool continueReadingConsole = true;
|
||||
|
||||
int internalFunc(void * callback)
|
||||
{
|
||||
CCallback * cb = (CCallback*)callback;
|
||||
@ -23,119 +30,127 @@ int internalFunc(void * callback)
|
||||
std::string readed;
|
||||
while(true)
|
||||
{
|
||||
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;
|
||||
|
||||
int heronum;
|
||||
int3 dest;
|
||||
|
||||
if(pom==std::string("die, fool"))
|
||||
exit(0);
|
||||
else if(pom==std::string("get txt"))
|
||||
#ifdef WIN32
|
||||
if(continueReadingConsole && kbhit())
|
||||
#else
|
||||
#endif
|
||||
{
|
||||
boost::filesystem::create_directory("Extracted_txts");
|
||||
std::cout<<"Command accepted. Opening .lod file...\t";
|
||||
CLodHandler * txth = new CLodHandler;
|
||||
txth->init(std::string("Data\\H3bitmap.lod"),"Data");
|
||||
std::cout<<"done.\nScanning .lod file\n";
|
||||
int curp=0;
|
||||
std::string pattern = ".TXT";
|
||||
for(int i=0;i<txth->entries.size(); i++)
|
||||
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;
|
||||
|
||||
int heronum;
|
||||
int3 dest;
|
||||
|
||||
if(pom==std::string("die, fool"))
|
||||
exit(0);
|
||||
else if(pom==std::string("get txt"))
|
||||
{
|
||||
std::string pom = txth->entries[i].nameStr;
|
||||
if(boost::algorithm::find_last(pom,pattern))
|
||||
boost::filesystem::create_directory("Extracted_txts");
|
||||
std::cout<<"Command accepted. Opening .lod file...\t";
|
||||
CLodHandler * txth = new CLodHandler;
|
||||
txth->init(std::string("Data\\H3bitmap.lod"),"data");
|
||||
std::cout<<"done.\nScanning .lod file\n";
|
||||
int curp=0;
|
||||
std::string pattern = ".TXT";
|
||||
for(int i=0;i<txth->entries.size(); i++)
|
||||
{
|
||||
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<<"%";
|
||||
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<<"%";
|
||||
}
|
||||
}
|
||||
std::cout<<"\rExtracting done :)\n";
|
||||
}
|
||||
std::cout<<"\rExtracting done :)\n";
|
||||
}
|
||||
vector<Coordinate>* p;
|
||||
switch (*cn.c_str())
|
||||
{
|
||||
//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->mh->map->heroes.size()<<std::endl;
|
||||
break;
|
||||
case 'H': //position of hero
|
||||
readed>>heronum;
|
||||
std::cout<<"Position of hero "<<heronum<<": "<<CGI->mh->map->heroes[heronum]->getPosition(false)<<std::endl;
|
||||
break;
|
||||
case 'M': //move heroa
|
||||
vector<Coordinate>* p;
|
||||
switch (*cn.c_str())
|
||||
{
|
||||
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]);
|
||||
//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;
|
||||
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;
|
||||
}
|
||||
case 'D': //pos description
|
||||
readed>>src;
|
||||
CGI->mh->getObjDescriptions(src);
|
||||
break;
|
||||
}
|
||||
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)
|
||||
case 'I':
|
||||
{
|
||||
int3 csrc = src;
|
||||
csrc.y+=g;
|
||||
csrc.x+=v;
|
||||
if(CGI->mh->getObjDescriptions(csrc).size())
|
||||
std::cout<<'x';
|
||||
else
|
||||
std::cout<<'o';
|
||||
SDL_Surface * temp = LOCPLINT->infoWin(NULL);
|
||||
blitAtWR(temp,605,389);
|
||||
SDL_FreeSurface(temp);
|
||||
break;
|
||||
}
|
||||
std::cout<<std::endl;
|
||||
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;
|
||||
//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;
|
||||
}
|
||||
break;
|
||||
case 'A': //hide everything from map
|
||||
for(int c=0; c<CGI->mh->map->objects.size(); ++c)
|
||||
{
|
||||
CGI->mh->hideObject(CGI->mh->map->objects[c]);
|
||||
}
|
||||
break;
|
||||
case 'R': //restora all objects after A has been pressed
|
||||
for(int c=0; c<CGI->mh->map->objects.size(); ++c)
|
||||
{
|
||||
CGI->mh->printObject(CGI->mh->map->objects[c]);
|
||||
}
|
||||
break;
|
||||
//SDL_Delay(100);
|
||||
delete p;
|
||||
}
|
||||
//SDL_Delay(100);
|
||||
delete p;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
SDL_Thread * consoleReadingThread;
|
||||
|
||||
void CConsoleHandler::runConsole()
|
||||
{
|
||||
SDL_Thread * myth = SDL_CreateThread(&internalFunc, cb);
|
||||
consoleReadingThread = SDL_CreateThread(&internalFunc, cb);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <algorithm>
|
||||
#include "SDL_Thread.h"
|
||||
#include "SDL_Extensions.h"
|
||||
#include "CBattleInterface.h" //for CBattleHex
|
||||
#include <queue>
|
||||
|
||||
|
||||
@ -161,7 +162,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C
|
||||
else if(j->first == curB->side2) //player is defender
|
||||
side = true;
|
||||
else
|
||||
return; //no witnesses
|
||||
continue; //no witnesses
|
||||
if(CGI->playerint[j->second.serial]->human)
|
||||
{
|
||||
((CPlayerInterface*)( CGI->playerint[j->second.serial] ))->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side);
|
||||
@ -283,9 +284,12 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
|
||||
|| (curB->stacks[g]->creature->isDoubleWide() && curB->stacks[g]->attackerOwned && curB->stacks[g]->position-1 == dest)
|
||||
|| (curB->stacks[g]->creature->isDoubleWide() && !curB->stacks[g]->attackerOwned && curB->stacks[g]->position+1 == dest))
|
||||
{
|
||||
stackAtEnd = true;
|
||||
numberOfStackAtEnd = g;
|
||||
break;
|
||||
if(curB->stacks[g]->alive)
|
||||
{
|
||||
stackAtEnd = true;
|
||||
numberOfStackAtEnd = g;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -307,7 +311,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
|
||||
accessibility[k] = true;
|
||||
for(int g=0; g<curB->stacks.size(); ++g)
|
||||
{
|
||||
if(curB->stacks[g]->ID != ID) //we don't want to lock enemy's positions and this units' position
|
||||
if(curB->stacks[g]->ID != ID && curB->stacks[g]->alive) //we don't want to lock enemy's positions and this units' position
|
||||
{
|
||||
accessibility[curB->stacks[g]->position] = false;
|
||||
if(curB->stacks[g]->creature->isDoubleWide()) //if it's a double hex creature
|
||||
@ -402,7 +406,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest)
|
||||
}
|
||||
}
|
||||
//following the Path
|
||||
if(dists[dest] > curStack->creature->speed)
|
||||
if(dists[dest] > curStack->creature->speed && !(stackAtEnd && dists[dest] == curStack->creature->speed+1)) //we can attack a stack if we can go to adjacent hex
|
||||
return false;
|
||||
std::vector<int> path;
|
||||
int curElem = dest;
|
||||
@ -544,7 +548,7 @@ std::vector<int> CGameState::battleGetRange(int ID)
|
||||
accessibility[k] = true;
|
||||
for(int g=0; g<curB->stacks.size(); ++g)
|
||||
{
|
||||
if(curB->stacks[g]->ID != ID) //we don't want to lock current unit's position
|
||||
if(curB->stacks[g]->ID != ID && curB->stacks[g]->alive) //we don't want to lock current unit's position
|
||||
{
|
||||
accessibility[curB->stacks[g]->position] = false;
|
||||
if(curB->stacks[g]->creature->isDoubleWide()) //if it's a double hex creature
|
||||
@ -637,6 +641,46 @@ std::vector<int> CGameState::battleGetRange(int ID)
|
||||
ret.push_back(i);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
std::vector<int> additionals;
|
||||
|
||||
//adding enemies' positions
|
||||
for(int c=0; c<curB->stacks.size(); ++c)
|
||||
{
|
||||
if(curB->stacks[c]->alive && curB->stacks[c]->owner != owner)
|
||||
{
|
||||
for(int g=0; g<ret.size(); ++g)
|
||||
{
|
||||
if(CBattleHex::mutualPosition(ret[g], curB->stacks[c]->position) != -1)
|
||||
{
|
||||
additionals.push_back(curB->stacks[c]->position);
|
||||
}
|
||||
if(curB->stacks[c]->creature->isDoubleWide() && curB->stacks[c]->attackerOwned && CBattleHex::mutualPosition(ret[g], curB->stacks[c]->position-1) != -1)
|
||||
{
|
||||
additionals.push_back(curB->stacks[c]->position-1);
|
||||
}
|
||||
if(curB->stacks[c]->creature->isDoubleWide() && !curB->stacks[c]->attackerOwned && CBattleHex::mutualPosition(ret[g], curB->stacks[c]->position+1) != -1)
|
||||
{
|
||||
additionals.push_back(curB->stacks[c]->position+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for(int g=0; g<additionals.size(); ++g)
|
||||
{
|
||||
ret.push_back(additionals[g]);
|
||||
}
|
||||
|
||||
std::sort(ret.begin(), ret.end());
|
||||
std::vector<int>::iterator nend = std::unique(ret.begin(), ret.end());
|
||||
|
||||
std::vector<int> ret2;
|
||||
|
||||
for(std::vector<int>::iterator it = ret.begin(); it != nend; ++it)
|
||||
{
|
||||
ret2.push_back(*it);
|
||||
}
|
||||
|
||||
return ret2;
|
||||
}
|
||||
|
||||
|
10
CGameState.h
10
CGameState.h
@ -13,6 +13,7 @@ class CCreatureSet;
|
||||
class CStack;
|
||||
class CGHeroInstance;
|
||||
class CArmedInstance;
|
||||
struct Mapa;
|
||||
|
||||
struct PlayerState
|
||||
{
|
||||
@ -56,12 +57,13 @@ public:
|
||||
class CGameState
|
||||
{
|
||||
private:
|
||||
int currentPlayer;
|
||||
int currentPlayer; //ID of player currently having turn
|
||||
BattleInfo *curB; //current battle
|
||||
int day; //total number of days in game
|
||||
std::map<int,PlayerState> players; //color <-> playerstate
|
||||
std::set<CCPPObjectScript *> cppscripts;
|
||||
std::map<int, std::map<std::string, CObjectScript*> > objscr; //custom user scripts (as for now only Lua)
|
||||
Mapa * map;
|
||||
std::map<int,PlayerState> players; //ID <-> playerstate
|
||||
std::set<CCPPObjectScript *> cppscripts; //C++ scripts
|
||||
std::map<int, std::map<std::string, CObjectScript*> > objscr; //non-C++ scripts
|
||||
|
||||
|
||||
bool checkFunc(int obid, std::string name)
|
||||
|
@ -43,8 +43,9 @@ CHeroWindow::CHeroWindow(int playerColor):
|
||||
gar1button = new AdventureMapButton(CGI->generaltexth->heroscrn[23], CGI->generaltexth->heroscrn[29], boost::bind(&CHeroWindow::gar1,this), 546, 491, "hsbtns6.def", false, NULL, false);
|
||||
gar2button = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::gar2,this), 604, 491, "hsbtns8.def", false, NULL, false);
|
||||
gar3button = new AdventureMapButton(CGI->generaltexth->heroscrn[24], CGI->generaltexth->heroscrn[30], boost::bind(&CHeroWindow::gar3,this), 546, 527, "hsbtns7.def", false, NULL, false);
|
||||
gar4button = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[32], boost::bind(&CGarrisonInt::splitClick,garInt), 604, 527, "hsbtns9.def", false, NULL, false);
|
||||
gar4button = new AdventureMapButton(std::string(), CGI->generaltexth->heroscrn[32], boost::function<void()>(), 604, 527, "hsbtns9.def", false, NULL, false);
|
||||
|
||||
//boost::bind(&CGarrisonInt::splitClick,garInt)
|
||||
leftArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::leftArtRoller,this), 379, 364, "hsbtns3.def", false, NULL, false);
|
||||
rightArtRoll = new AdventureMapButton(std::string(), std::string(), boost::bind(&CHeroWindow::rightArtRoller,this), 632, 364, "hsbtns5.def", false, NULL, false);
|
||||
|
||||
@ -207,6 +208,8 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
|
||||
delete garInt;
|
||||
/*gar4button->owner = */garInt = new CGarrisonInt(80, 493, 8, 0, curBack, 13, 482, curHero);
|
||||
garInt->update = false;
|
||||
gar4button->callback = boost::bind(&CGarrisonInt::splitClick,garInt);//actualization of callback function
|
||||
|
||||
for(int g=0; g<primSkillAreas.size(); ++g)
|
||||
{
|
||||
primSkillAreas[g]->bonus = hero->primSkills[g];
|
||||
|
11
CMT.cpp
11
CMT.cpp
@ -492,21 +492,18 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
initTable[ss] = mapstr[ss];
|
||||
}
|
||||
std::cout<<"done."<<std::endl;
|
||||
|
||||
CAmbarCendamo * ac = new CAmbarCendamo(initTable);
|
||||
THC std::cout<<"Reading file: "<<tmh.getDif()<<std::endl;
|
||||
ac->deh3m();
|
||||
THC std::cout<<"Detecting file (together): "<<tmh.getDif()<<std::endl;
|
||||
Mapa * mapa = new Mapa(initTable);
|
||||
THC std::cout<<"Reading and detecting map file (together): "<<tmh.getDif()<<std::endl;
|
||||
CMapHandler * mh = new CMapHandler();
|
||||
cgi->mh = mh;
|
||||
mh->map = &ac->map;
|
||||
mh->map = mapa;
|
||||
THC std::cout<<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
|
||||
mh->loadDefs();
|
||||
THC std::cout<<"Reading terrain defs: "<<tmh.getDif()<<std::endl;
|
||||
mh->init();
|
||||
THC std::cout<<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl;
|
||||
|
||||
initGameState(&ac->map,cgi);
|
||||
initGameState(mapa,cgi);
|
||||
THC std::cout<<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
|
||||
for (int i=0; i<cgi->scenarioOps.playerInfos.size();i++) //initializing interfaces
|
||||
{
|
||||
|
@ -149,33 +149,33 @@ void CPathfinder::AddNeighbors(vector<Coordinate>* branch)
|
||||
// 6 7 8
|
||||
|
||||
Coordinate node = branch->back();
|
||||
Coordinate* c;
|
||||
Coordinate c;
|
||||
|
||||
for(int i = node.x-1; i<node.x+2;i++)
|
||||
{
|
||||
for(int j = node.y-1; j < node.y+2; j++)
|
||||
{
|
||||
if(i > 0 && j > 0 && i < CGI->mh->sizes.x-1 && j < CGI->mh->sizes.y-1)
|
||||
if(i >= 0 && j >= 0 && i < CGI->mh->sizes.x && j < CGI->mh->sizes.y)
|
||||
{
|
||||
c = new Coordinate(i,j,node.z);
|
||||
c = Coordinate(i,j,node.z);
|
||||
|
||||
//Calculate the distance from the end node
|
||||
CalcG(c);
|
||||
CalcG(&c);
|
||||
|
||||
//Calculate the movement cost
|
||||
CalcH(c);
|
||||
CalcH(&c);
|
||||
|
||||
if(c->g != -1 && c->h != -1)
|
||||
if(c.g != -1 && c.h != -1)
|
||||
{
|
||||
vector<Coordinate> toAdd = *branch;
|
||||
toAdd.push_back(*c);
|
||||
toAdd.push_back(c);
|
||||
Open.push(toAdd);
|
||||
}
|
||||
//delete c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete c;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -238,6 +238,8 @@ CPath* CPathfinder::ConvertToOldFormat(vector<Coordinate>* p)
|
||||
|
||||
CPath* path = new CPath();
|
||||
|
||||
std::vector<int> costs; //vector with costs of tiles
|
||||
|
||||
for(int i = 0; i < p->size(); i++)
|
||||
{
|
||||
CPathNode temp;
|
||||
@ -256,19 +258,16 @@ CPath* CPathfinder::ConvertToOldFormat(vector<Coordinate>* p)
|
||||
}
|
||||
//set diagonality
|
||||
float diagonal = 1.0f; //by default
|
||||
if(i+1<p->size())
|
||||
if(i>0)
|
||||
{
|
||||
if(p->at(i+1).x != temp.coord.x && p->at(i+1).y != temp.coord.y)
|
||||
if(p->at(i-1).x != temp.coord.x && p->at(i-1).y != temp.coord.y)
|
||||
{
|
||||
diagonal = sqrt(2.0f);
|
||||
}
|
||||
}
|
||||
|
||||
//Set distance
|
||||
if(i == 0)
|
||||
temp.dist = p->at(i).h * diagonal;
|
||||
else
|
||||
temp.dist = p->at(i).h * diagonal + path->nodes.back().dist;
|
||||
costs.push_back( i==0 ? 0 : p->at(i - 1).h * diagonal );
|
||||
|
||||
//theNodeBefore is never used outside of pathfinding?
|
||||
|
||||
@ -278,13 +277,10 @@ CPath* CPathfinder::ConvertToOldFormat(vector<Coordinate>* p)
|
||||
path->nodes.push_back(temp);
|
||||
}
|
||||
|
||||
//YOU ARE ALL BACKWARDS!! =P
|
||||
//Flip the distances.
|
||||
for(int i = 0; i < path->nodes.size()/2;i++)
|
||||
costs.push_back(0);
|
||||
for(int i=path->nodes.size()-1; i>=0; --i)
|
||||
{
|
||||
int t = path->nodes[i].dist;
|
||||
path->nodes[i].dist = path->nodes[path->nodes.size()-i-1].dist;
|
||||
path->nodes[path->nodes.size()-i-1].dist = t;
|
||||
path->nodes[i].dist = costs[i+1] + ((i == path->nodes.size()-1) ? 0 : path->nodes[i+1].dist);
|
||||
}
|
||||
|
||||
return path;
|
||||
|
@ -31,6 +31,7 @@
|
||||
using namespace CSDL_Ext;
|
||||
|
||||
extern TTF_Font * GEOR16;
|
||||
extern bool continueReadingConsole;
|
||||
|
||||
class OCM_HLP_CGIN
|
||||
{
|
||||
@ -1705,6 +1706,7 @@ void CPlayerInterface::handleKeyDown(SDL_Event *sEvent)
|
||||
}
|
||||
case (SDLK_q):
|
||||
{
|
||||
continueReadingConsole = false;
|
||||
exit(0);
|
||||
break;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -7,26 +7,13 @@
|
||||
#include "../map.h"
|
||||
#include "CCreatureHandler.h"
|
||||
|
||||
enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF, EVENTOBJ_DEF, SIGN_DEF, GARRISON_DEF, ARTIFACT_DEF, WITCHHUT_DEF, SCHOLAR_DEF, PLAYERONLY_DEF, SHRINE_DEF, SPELLSCROLL_DEF, PANDORA_DEF, GRAIL_DEF, CREGEN_DEF, CREGEN2_DEF, CREGEN3_DEF, BORDERGUARD_DEF, HEROPLACEHOLDER_DEF};
|
||||
|
||||
class DLL_EXPORT CAmbarCendamo
|
||||
{
|
||||
public:
|
||||
/////////////////member variables
|
||||
Mapa map;
|
||||
//Mapa* map;
|
||||
|
||||
//map file
|
||||
unsigned char * bufor; // here we store map bytecode
|
||||
int i; //our pos in the file
|
||||
|
||||
CAmbarCendamo (const char * tie); // c-tor; tie is the path of the map file
|
||||
CAmbarCendamo (unsigned char * map); // c-tor; map is pointer to array containing map; it is not copied, so don't delete
|
||||
~CAmbarCendamo (); // d-tor
|
||||
int readNormalNr (int pos, int bytCon=4, bool cyclic = false); //read number from bytCon bytes starting from pos position in buffer ; if cyclic is true, number is treated as it were signed number with bytCon bytes
|
||||
void deh3m(); // decode file, results are stored in map
|
||||
EDefType getDefType(CGDefInfo * a); //returns type of object in def
|
||||
CCreatureSet readCreatureSet(int number = 7); //reads creature set in most recently encountered format; reades number units (default is 7)
|
||||
char readChar();
|
||||
std::string readString();
|
||||
//CAmbarCendamo (unsigned char * data); // c-tor; data is pointer to decompressed h3m data
|
||||
//~CAmbarCendamo (); // d-tor
|
||||
};
|
||||
#endif //CAMBARCENDAMO_H
|
7
map.h
7
map.h
@ -10,7 +10,10 @@ class CGObjectInstance;
|
||||
class CGHeroInstance;
|
||||
class CGTownInstance;
|
||||
enum ESortBy{name,playerAm,size,format, viccon,loscon};
|
||||
|
||||
enum EDefType {TOWN_DEF, HERO_DEF, CREATURES_DEF, SEERHUT_DEF, RESOURCE_DEF, TERRAINOBJ_DEF,
|
||||
EVENTOBJ_DEF, SIGN_DEF, GARRISON_DEF, ARTIFACT_DEF, WITCHHUT_DEF, SCHOLAR_DEF, PLAYERONLY_DEF,
|
||||
SHRINE_DEF, SPELLSCROLL_DEF, PANDORA_DEF, GRAIL_DEF, CREGEN_DEF, CREGEN2_DEF, CREGEN3_DEF,
|
||||
BORDERGUARD_DEF, HEROPLACEHOLDER_DEF};
|
||||
class DLL_EXPORT CSpecObjInfo //class with object - specific info (eg. different information for creatures and heroes); use inheritance to make object - specific classes
|
||||
{
|
||||
};
|
||||
@ -391,6 +394,8 @@ struct DLL_EXPORT Mapa
|
||||
std::vector<CGObjectInstance*> objects;
|
||||
std::vector<CGHeroInstance*> heroes;
|
||||
std::vector<CGTownInstance*> towns;
|
||||
|
||||
Mapa(unsigned char * bufor); //creates map from decompressed .h3m data
|
||||
};
|
||||
class DLL_EXPORT CMapHeader
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user