1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-15 01:24:45 +02:00

Cleanups/refactoring

This commit is contained in:
Michał W. Urbańczyk
2008-06-11 01:53:57 +00:00
parent 798fd11f65
commit dbca25df74
21 changed files with 353 additions and 425 deletions

View File

@ -167,7 +167,7 @@ public:
void startBattle(int heroID, CCreatureSet * army, int3 tile); //for hero<=>neutral army
//friends
friend void initGameState(CGameInfo * cgi);
friend void initGameState(Mapa * map, CGameInfo * cgi);
};
class CLuaCallback : public CScriptCallback
{
@ -179,6 +179,6 @@ private:
static int getGnrlText(lua_State * L);//(int ID, int which, int val);
static int getSelectedHero(lua_State * L);//()
friend void initGameState(CGameInfo * cgi);
friend void initGameState(Mapa * map, CGameInfo * cgi);
};
#endif //CCALLBACK_H

View File

@ -64,20 +64,20 @@ int internalFunc(void * callback)
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);
//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;
//break;
case 'm': //number of heroes
std::cout<<"Number of heroes: "<<CGI->heroh->heroInstances.size()<<std::endl;
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->heroh->heroInstances[heronum]->getPosition(false)<<std::endl;
std::cout<<"Position of hero "<<heronum<<": "<<CGI->mh->map->heroes[heronum]->getPosition(false)<<std::endl;
break;
case 'M': //move heroa
{
@ -117,15 +117,15 @@ int internalFunc(void * callback)
}
break;
case 'A': //hide everything from map
for(int c=0; c<CGI->objh->objInstances.size(); ++c)
for(int c=0; c<CGI->mh->map->objects.size(); ++c)
{
CGI->mh->hideObject(CGI->objh->objInstances[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->objh->objInstances.size(); ++c)
for(int c=0; c<CGI->mh->map->objects.size(); ++c)
{
CGI->mh->printObject(CGI->objh->objInstances[c]);
CGI->mh->printObject(CGI->mh->map->objects[c]);
}
break;
}

View File

@ -98,7 +98,7 @@ public:
friend CPathfinder;;
friend CLuaCallback;
friend int _tmain(int argc, _TCHAR* argv[]);
friend void initGameState(CGameInfo * cgi);
friend void initGameState(Mapa * map, CGameInfo * cgi);
friend CScriptCallback;
friend void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * script);
//CCallback * cb; //for communication between PlayerInterface/AI and GameState

View File

@ -257,209 +257,209 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
}
backpack.clear();
artWorn[8] = new CArtPlace(hero->artifWorn[8]);
artWorn[8] = new CArtPlace(hero->getArt(8));
artWorn[8]->pos.x = 515;
artWorn[8]->pos.y = 295;
artWorn[8]->pos.h = artWorn[8]->pos.w = 44;
if(hero->artifWorn[8])
if(hero->getArt(8))
artWorn[8]->text = hero->getArt(8)->description;
else
artWorn[8]->text = std::string();
artWorn[8]->ourWindow = this;
artWorn[8]->feet = true;
artWorn[0] = new CArtPlace(hero->artifWorn[0]);
artWorn[0] = new CArtPlace(hero->getArt(0));
artWorn[0]->pos.x = 509;
artWorn[0]->pos.y = 30;
artWorn[0]->pos.h = artWorn[0]->pos.w = 44;
if(hero->artifWorn[0])
if(hero->getArt(0))
artWorn[0]->text = hero->getArt(0)->description;
else
artWorn[0]->text = std::string();
artWorn[0]->ourWindow = this;
artWorn[0]->head = true;
artWorn[4] = new CArtPlace(hero->artifWorn[4]);
artWorn[4] = new CArtPlace(hero->getArt(4));
artWorn[4]->pos.x = 564;
artWorn[4]->pos.y = 183;
artWorn[4]->pos.h = artWorn[4]->pos.w = 44;
if(hero->artifWorn[4])
if(hero->getArt(4))
artWorn[4]->text = hero->getArt(4)->description;
else
artWorn[4]->text = std::string();
artWorn[4]->ourWindow = this;
artWorn[4]->lHand = true;
artWorn[7] = new CArtPlace(hero->artifWorn[7]);
artWorn[7] = new CArtPlace(hero->getArt(7));
artWorn[7]->pos.x = 610;
artWorn[7]->pos.y = 183;
artWorn[7]->pos.h = artWorn[7]->pos.w = 44;
if(hero->artifWorn[7])
if(hero->getArt(7))
artWorn[7]->text = hero->getArt(7)->description;
else
artWorn[7]->text = std::string();
artWorn[7]->ourWindow = this;
artWorn[7]->lRing = true;
artWorn[13] = new CArtPlace(hero->artifWorn[13]);
artWorn[13] = new CArtPlace(hero->getArt(13));
artWorn[13]->pos.x = 564;
artWorn[13]->pos.y = 30;
artWorn[13]->pos.h = artWorn[13]->pos.w = 44;
if(hero->artifWorn[13])
if(hero->getArt(13))
artWorn[13]->text = hero->getArt(13)->description;
else
artWorn[13]->text = std::string();
artWorn[13]->ourWindow = this;
artWorn[13]->warMachine1 = true;
artWorn[14] = new CArtPlace(hero->artifWorn[14]);
artWorn[14] = new CArtPlace(hero->getArt(14));
artWorn[14]->pos.x = 610;
artWorn[14]->pos.y = 30;
artWorn[14]->pos.h = artWorn[14]->pos.w = 44;
if(hero->artifWorn[14])
if(hero->getArt(14))
artWorn[14]->text = hero->getArt(14)->description;
else
artWorn[14]->text = std::string();
artWorn[14]->ourWindow = this;
artWorn[14]->warMachine2 = true;
artWorn[15] = new CArtPlace(hero->artifWorn[15]);
artWorn[15] = new CArtPlace(hero->getArt(15));
artWorn[15]->pos.x = 610;
artWorn[15]->pos.y = 76;
artWorn[15]->pos.h = artWorn[15]->pos.w = 44;
if(hero->artifWorn[15])
if(hero->getArt(15))
artWorn[15]->text = hero->getArt(15)->description;
else
artWorn[15]->text = std::string();
artWorn[15]->ourWindow = this;
artWorn[15]->warMachine3 = true;
artWorn[16] = new CArtPlace(hero->artifWorn[16]);
artWorn[16] = new CArtPlace(hero->getArt(16));
artWorn[16]->pos.x = 610;
artWorn[16]->pos.y = 122;
artWorn[16]->pos.h = artWorn[16]->pos.w = 44;
if(hero->artifWorn[16])
if(hero->getArt(16))
artWorn[16]->text = hero->getArt(16)->description;
else
artWorn[16]->text = std::string();
artWorn[16]->ourWindow = this;
artWorn[16]->warMachine4 = true;
artWorn[9] = new CArtPlace(hero->artifWorn[9]);
artWorn[9] = new CArtPlace(hero->getArt(9));
artWorn[9]->pos.x = 383;
artWorn[9]->pos.y = 143;
artWorn[9]->pos.h = artWorn[9]->pos.w = 44;
if(hero->artifWorn[9])
if(hero->getArt(9))
artWorn[9]->text = hero->getArt(9)->description;
else
artWorn[9]->text = std::string();
artWorn[9]->ourWindow = this;
artWorn[9]->misc1 = true;
artWorn[10] = new CArtPlace(hero->artifWorn[10]);
artWorn[10] = new CArtPlace(hero->getArt(10));
artWorn[10]->pos.x = 399;
artWorn[10]->pos.y = 194;
artWorn[10]->pos.h = artWorn[10]->pos.w = 44;
if(hero->artifWorn[10])
if(hero->getArt(10))
artWorn[10]->text = hero->getArt(10)->description;
else
artWorn[10]->text = std::string();
artWorn[10]->ourWindow = this;
artWorn[10]->misc1 = true;
artWorn[11] = new CArtPlace(hero->artifWorn[11]);
artWorn[11] = new CArtPlace(hero->getArt(11));
artWorn[11]->pos.x = 415;
artWorn[11]->pos.y = 245;
artWorn[11]->pos.h = artWorn[11]->pos.w = 44;
if(hero->artifWorn[11])
if(hero->getArt(11))
artWorn[11]->text = hero->getArt(11)->description;
else
artWorn[11]->text = std::string();
artWorn[11]->ourWindow = this;
artWorn[11]->misc3 = true;
artWorn[12] = new CArtPlace(hero->artifWorn[12]);
artWorn[12] = new CArtPlace(hero->getArt(12));
artWorn[12]->pos.x = 431;
artWorn[12]->pos.y = 296;
artWorn[12]->pos.h = artWorn[12]->pos.w = 44;
if(hero->artifWorn[12])
if(hero->getArt(12))
artWorn[12]->text = hero->getArt(12)->description;
else
artWorn[12]->text = std::string();
artWorn[12]->ourWindow = this;
artWorn[12]->misc4 = true;
artWorn[18] = new CArtPlace(hero->artifWorn[18]);
artWorn[18] = new CArtPlace(hero->getArt(18));
artWorn[18]->pos.x = 381;
artWorn[18]->pos.y = 296;
artWorn[18]->pos.h = artWorn[18]->pos.w = 44;
if(hero->artifWorn[18])
if(hero->getArt(18))
artWorn[18]->text = hero->getArt(18)->description;
else
artWorn[18]->text = std::string();
artWorn[18]->ourWindow = this;
artWorn[18]->misc5 = true;
artWorn[2] = new CArtPlace(hero->artifWorn[2]);
artWorn[2] = new CArtPlace(hero->getArt(2));
artWorn[2]->pos.x = 508;
artWorn[2]->pos.y = 79;
artWorn[2]->pos.h = artWorn[2]->pos.w = 44;
if(hero->artifWorn[2])
if(hero->getArt(2))
artWorn[2]->text = hero->getArt(2)->description;
else
artWorn[2]->text = std::string();
artWorn[2]->ourWindow = this;
artWorn[2]->neck = true;
artWorn[3] = new CArtPlace(hero->artifWorn[3]);
artWorn[3] = new CArtPlace(hero->getArt(3));
artWorn[3]->pos.x = 383;
artWorn[3]->pos.y = 68;
artWorn[3]->pos.h = artWorn[3]->pos.w = 44;
if(hero->artifWorn[3])
if(hero->getArt(3))
artWorn[3]->text = hero->getArt(3)->description;
else
artWorn[3]->text = std::string();
artWorn[3]->ourWindow = this;
artWorn[3]->rHand = true;
artWorn[6] = new CArtPlace(hero->artifWorn[6]);
artWorn[6] = new CArtPlace(hero->getArt(6));
artWorn[6]->pos.x = 431;
artWorn[6]->pos.y = 68;
artWorn[6]->pos.h = artWorn[6]->pos.w = 44;
if(hero->artifWorn[6])
if(hero->getArt(6))
artWorn[6]->text = hero->getArt(6)->description;
else
artWorn[6]->text = std::string();
artWorn[6]->ourWindow = this;
artWorn[6]->rRing = true;
artWorn[1] = new CArtPlace(hero->artifWorn[1]);
artWorn[1] = new CArtPlace(hero->getArt(1));
artWorn[1]->pos.x = 567;
artWorn[1]->pos.y = 240;
artWorn[1]->pos.h = artWorn[1]->pos.w = 44;
if(hero->artifWorn[1])
if(hero->getArt(1))
artWorn[1]->text = hero->getArt(1)->description;
else
artWorn[1]->text = std::string();
artWorn[1]->ourWindow = this;
artWorn[1]->shoulders = true;
artWorn[17] = new CArtPlace(hero->artifWorn[17]);
artWorn[17] = new CArtPlace(hero->getArt(17));
artWorn[17]->pos.x = 610;
artWorn[17]->pos.y = 310;
artWorn[17]->pos.h = artWorn[17]->pos.w = 44;
if(hero->artifWorn[17])
if(hero->getArt(17))
artWorn[17]->text = hero->getArt(17)->description;
else
artWorn[17]->text = std::string();
artWorn[17]->ourWindow = this;
artWorn[17]->spellBook = true;
artWorn[5] = new CArtPlace(hero->artifWorn[5]);
artWorn[5] = new CArtPlace(hero->getArt(5));
artWorn[5]->pos.x = 509;
artWorn[5]->pos.y = 130;
artWorn[5]->pos.h = artWorn[5]->pos.w = 44;
if(hero->artifWorn[5])
if(hero->getArt(5))
artWorn[5]->text = hero->getArt(5)->description;
else
artWorn[5]->text = std::string();
@ -480,7 +480,7 @@ void CHeroWindow::setHero(const CGHeroInstance *Hero)
{
CArtPlace * add;
if( s < curHero->artifacts.size() )
add = new CArtPlace(curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]);
add = new CArtPlace(&CGI->arth->artifacts[curHero->artifacts[(s+backpackPos) % curHero->artifacts.size() ]]);
else
add = new CArtPlace(NULL);
add->pos.x = 403 + 46*s;
@ -876,7 +876,7 @@ void CHeroWindow::redrawCurBack()
CSDL_Ext::printAt(manastr.str(), 212, 247, GEOR16, zwykly, curBack);
}
CArtPlace::CArtPlace(int Art): ourArt(&CGI->arth->artifacts[Art]), active(false), clicked(false),
CArtPlace::CArtPlace(const CArtifact* Art): ourArt(Art), active(false), clicked(false),
spellBook(false), warMachine1(false), warMachine2(false), warMachine3(false),
warMachine4(false),misc1(false), misc2(false), misc3(false), misc4(false),
misc5(false), feet(false), lRing(false), rRing(false), torso(false),

View File

@ -70,7 +70,7 @@ public:
bool clicked;
CHeroWindow * ourWindow;
const CArtifact * ourArt;
CArtPlace(int Art);
CArtPlace(const CArtifact * Art);
void clickLeft (tribool down);
void clickRight (tribool down);
void activate();

21
CLua.h
View File

@ -11,6 +11,7 @@ class CGHeroInstance;
class CScriptCallback;
class SComponent;
class CSelectableComponent;
struct Mapa;
enum ESLan{UNDEF=-1,CPP,ERM,LUA};
class CObjectScript
{
@ -69,7 +70,7 @@ public:
void findFS(std::string fname);
friend void initGameState(CGameInfo * cgi);
friend void initGameState(Mapa * map, CGameInfo * cgi);
};
class CLuaObjectScript : public CLua, public CObjectScript
@ -84,7 +85,7 @@ public:
void onHeroVisit(CGObjectInstance *os, int heroID);
std::string hoverText(CGObjectInstance *os);
friend void initGameState(CGameInfo * cgi);
friend void initGameState(Mapa * map, CGameInfo * cgi);
};
class CCPPObjectScript: public CObjectScript
{
@ -106,7 +107,7 @@ class CVisitableOPH : public CCPPObjectScript //once per hero
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
std::string hoverText(CGObjectInstance *os);
friend void initGameState(CGameInfo * cgi);
friend void initGameState(Mapa * map, CGameInfo * cgi);
};
class CVisitableOPW : public CCPPObjectScript //once per week
@ -120,7 +121,7 @@ class CVisitableOPW : public CCPPObjectScript //once per week
std::string hoverText(CGObjectInstance *os);
void newTurn ();
friend void initGameState(CGameInfo * cgi);
friend void initGameState(Mapa * map, CGameInfo * cgi);
};
class CMines : public CCPPObjectScript //flaggable, and giving resource at each day
@ -135,7 +136,7 @@ class CMines : public CCPPObjectScript //flaggable, and giving resource at each
std::string hoverText(CGObjectInstance *os);
void newTurn ();
friend void initGameState(CGameInfo * cgi);
friend void initGameState(Mapa * map, CGameInfo * cgi);
};
class CPickable : public CCPPObjectScript, public IChosen //pickable - resources, artifacts, etc
@ -150,7 +151,7 @@ class CPickable : public CCPPObjectScript, public IChosen //pickable - resource
std::string hoverText(CGObjectInstance *os);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
friend void initGameState(CGameInfo * cgi);
friend void initGameState(Mapa * map, CGameInfo * cgi);
};
class CTownScript : public CCPPObjectScript //pickable - resources, artifacts, etc
@ -161,7 +162,7 @@ class CTownScript : public CCPPObjectScript //pickable - resources, artifacts,
std::string hoverText(CGObjectInstance *os);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
friend void initGameState(CGameInfo * cgi);
friend void initGameState(Mapa * map, CGameInfo * cgi);
};
class CHeroScript : public CCPPObjectScript
@ -173,7 +174,7 @@ class CHeroScript : public CCPPObjectScript
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
std::string hoverText(CGObjectInstance *os);
friend void initGameState(CGameInfo * cgi);
friend void initGameState(Mapa * map, CGameInfo * cgi);
};
class CMonsterS : public CCPPObjectScript
@ -185,7 +186,7 @@ class CMonsterS : public CCPPObjectScript
void onHeroVisit(CGObjectInstance *os, int heroID);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
friend void initGameState(CGameInfo * cgi);
friend void initGameState(Mapa * map, CGameInfo * cgi);
};
class CCreatureGen : public CCPPObjectScript
@ -197,5 +198,5 @@ class CCreatureGen : public CCPPObjectScript
void onHeroVisit(CGObjectInstance *os, int heroID);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script
friend void initGameState(CGameInfo * cgi);
friend void initGameState(Mapa * map, CGameInfo * cgi);
};

82
CMT.cpp
View File

@ -61,7 +61,7 @@
CGameInfo* CGI;
#endif
#define CHUNK 16384
const char * NAME = "VCMI 0.6";
const char * NAME = "VCMI \"Altanatse\" 0.7";
SDL_Color playerColorPalette[256]; //palette to make interface colors good
@ -77,7 +77,7 @@ void handleCPPObjS(std::map<int,CCPPObjectScript*> * mapa, CCPPObjectScript * sc
}
CGI->state->cppscripts.insert(script);
}
void initGameState(CGameInfo * cgi)
void initGameState(Mapa * map, CGameInfo * cgi)
{
cgi->state->day=0;
/*********creating players entries in gs****************************************/
@ -115,14 +115,14 @@ void initGameState(CGameInfo * cgi)
}
/*************************HEROES************************************************/
for (int i=0; i<cgi->heroh->heroInstances.size();i++) //heroes instances
for (int i=0; i<map->heroes.size();i++) //heroes instances
{
if (!cgi->heroh->heroInstances[i]->type || cgi->heroh->heroInstances[i]->getOwner()<0)
if (map->heroes[i]->getOwner()<0)
continue;
//CGHeroInstance * vhi = new CGHeroInstance();
//*vhi=*(cgi->heroh->heroInstances[i]);
CGHeroInstance * vhi = (cgi->heroh->heroInstances[i]);
vhi->subID = vhi->type->ID;
CGHeroInstance * vhi = (map->heroes[i]);
if(!vhi->type)
vhi->type = cgi->heroh->heroes[vhi->subID];
//vhi->subID = vhi->type->ID;
if (vhi->level<1)
{
vhi->exp=40+rand()%50;
@ -137,8 +137,8 @@ void initGameState(CGameInfo * cgi)
vhi->primSkills[1] = vhi->type->heroClass->initialDefence;
vhi->primSkills[2] = vhi->type->heroClass->initialPower;
vhi->primSkills[3] = vhi->type->heroClass->initialKnowledge;
vhi->mana = vhi->primSkills[3]*10;
}
vhi->mana = vhi->primSkills[3]*10;
if (!vhi->name.length())
{
vhi->name = vhi->type->name;
@ -186,21 +186,21 @@ void initGameState(CGameInfo * cgi)
/*************************FOG**OF**WAR******************************************/
for(std::map<int, PlayerState>::iterator k=cgi->state->players.begin(); k!=cgi->state->players.end(); ++k)
{
k->second.fogOfWarMap.resize(cgi->ac->map.width, Woff);
for(int g=-Woff; g<cgi->ac->map.width+Woff; ++g)
k->second.fogOfWarMap[g].resize(cgi->ac->map.height, Hoff);
k->second.fogOfWarMap.resize(map->width, Woff);
for(int g=-Woff; g<map->width+Woff; ++g)
k->second.fogOfWarMap[g].resize(map->height, Hoff);
for(int g=-Woff; g<cgi->ac->map.width+Woff; ++g)
for(int h=-Hoff; h<cgi->ac->map.height+Hoff; ++h)
k->second.fogOfWarMap[g][h].resize(cgi->ac->map.twoLevel+1, 0);
for(int g=-Woff; g<map->width+Woff; ++g)
for(int h=-Hoff; h<map->height+Hoff; ++h)
k->second.fogOfWarMap[g][h].resize(map->twoLevel+1, 0);
for(int g=-Woff; g<cgi->ac->map.width+Woff; ++g)
for(int h=-Hoff; h<cgi->ac->map.height+Hoff; ++h)
for(int v=0; v<cgi->ac->map.twoLevel+1; ++v)
for(int g=-Woff; g<map->width+Woff; ++g)
for(int h=-Hoff; h<map->height+Hoff; ++h)
for(int v=0; v<map->twoLevel+1; ++v)
k->second.fogOfWarMap[g][h][v] = 0;
for(int xd=0; xd<cgi->ac->map.width; ++xd) //revealing part of map around heroes
for(int xd=0; xd<map->width; ++xd) //revealing part of map around heroes
{
for(int yd=0; yd<cgi->ac->map.height; ++yd)
for(int yd=0; yd<map->height; ++yd)
{
for(int ch=0; ch<k->second.heroes.size(); ++ch)
{
@ -213,16 +213,20 @@ void initGameState(CGameInfo * cgi)
}
}
/****************************TOWNS************************************************/
for (int i=0;i<cgi->townh->townInstances.size();i++)
for (int i=0;i<map->towns.size();i++)
{
//CGTownInstance * vti = new CGTownInstance();
//(*vti)=*(cgi->townh->townInstances[i]);
CGTownInstance * vti =(cgi->townh->townInstances[i]);
//vti->creatureIncome.resize(CREATURES_PER_TOWN);
//vti->creaturesLeft.resize(CREATURES_PER_TOWN);
CGTownInstance * vti =(map->towns[i]);
if (vti->name.length()==0) // if town hasn't name we draw it
vti->name=vti->town->names[rand()%vti->town->names.size()];
if(vti->builtBuildings.find(-50)!=vti->builtBuildings.end()) //give standard set of buildings
{
vti->builtBuildings.erase(-50);
vti->builtBuildings.insert(10);
vti->builtBuildings.insert(5);
vti->builtBuildings.insert(30);
if(rand()%2)
vti->builtBuildings.insert(31);
}
cgi->state->players[vti->getOwner()].towns.push_back(vti);
}
@ -230,9 +234,9 @@ void initGameState(CGameInfo * cgi)
{
if(k->first==-1 || k->first==255)
continue;
for(int xd=0; xd<cgi->ac->map.width; ++xd) //revealing part of map around towns
for(int xd=0; xd<map->width; ++xd) //revealing part of map around towns
{
for(int yd=0; yd<cgi->ac->map.height; ++yd)
for(int yd=0; yd<map->height; ++yd)
{
for(int ch=0; ch<k->second.towns.size(); ++ch)
{
@ -300,22 +304,22 @@ void initGameState(CGameInfo * cgi)
}
/****************************INITIALIZING OBJECT SCRIPTS************************************************/
std::string temps("newObject");
for (int i=0; i<CGI->objh->objInstances.size(); i++)
for (int i=0; i<map->objects.size(); i++)
{
//c++ scripts
if (scripts.find(CGI->objh->objInstances[i]->ID) != scripts.end())
if (scripts.find(map->objects[i]->ID) != scripts.end())
{
CGI->objh->objInstances[i]->state = scripts[CGI->objh->objInstances[i]->ID];
CGI->objh->objInstances[i]->state->newObject(CGI->objh->objInstances[i]);
map->objects[i]->state = scripts[map->objects[i]->ID];
map->objects[i]->state->newObject(map->objects[i]);
}
else
{
CGI->objh->objInstances[i]->state = NULL;
map->objects[i]->state = NULL;
}
// lua scripts
if(cgi->state->checkFunc(CGI->objh->objInstances[i]->ID,temps))
(*skrypty)[CGI->objh->objInstances[i]->ID][temps]->newObject(CGI->objh->objInstances[i]);
if(cgi->state->checkFunc(map->objects[i]->ID,temps))
(*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]);
}
delete lf;
@ -856,14 +860,14 @@ int _tmain(int argc, _TCHAR* argv[])
THC std::cout<<"Detecting file (together): "<<tmh.getDif()<<std::endl;
CMapHandler * mh = new CMapHandler();
cgi->mh = mh;
mh->reader = ac;
mh->map = &ac->map;
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(cgi);
initGameState(&ac->map,cgi);
THC std::cout<<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
/*for(int d=0; d<PLAYER_LIMIT; ++d)
@ -893,7 +897,7 @@ int _tmain(int argc, _TCHAR* argv[])
int mw = mm.map[0]->w, mh = mm.map[0]->h,
wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y;
for(int d=0; d<cgi->mh->reader->map.twoLevel+1; ++d)
for(int d=0; d<cgi->mh->map->twoLevel+1; ++d)
{
SDL_Surface * pt = CSDL_Ext::newSurface(mm.pos.w, mm.pos.h, CSDL_Ext::std32bppSurface);

View File

@ -206,13 +206,13 @@ void CPathfinder::CalcH(Coordinate* node)
int ret=-1;
int x = node->x;
int y = node->y;
if(node->x>=CGI->mh->reader->map.width)
x = CGI->mh->reader->map.width-1;
if(node->y>=CGI->mh->reader->map.height)
y = CGI->mh->reader->map.height-1;
if(node->x>=CGI->mh->map->width)
x = CGI->mh->map->width-1;
if(node->y>=CGI->mh->map->height)
y = CGI->mh->map->height-1;
//Get the movement cost.
ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].terType, CGI->mh->reader->map.terrain[x][y].malle,CGI->mh->reader->map.terrain[x][y].nuine);
ret = Hero->getTileCost(CGI->mh->ttiles[x][y][node->z].terType, CGI->mh->map->terrain[x][y].malle,CGI->mh->map->terrain[x][y].nuine);
node->h = ret;
}

View File

@ -1897,10 +1897,10 @@ int3 CPlayerInterface::repairScreenPos(int3 pos)
pos.x = -Woff+1;
if(pos.y<=-Hoff)
pos.y = -Hoff+1;
if(pos.x>CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff)
pos.x = CGI->mh->reader->map.width - this->adventureInt->terrain.tilesw + Woff;
if(pos.y>CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff)
pos.y = CGI->mh->reader->map.height - this->adventureInt->terrain.tilesh + Hoff;
if(pos.x>CGI->mh->map->width - this->adventureInt->terrain.tilesw + Woff)
pos.x = CGI->mh->map->width - this->adventureInt->terrain.tilesw + Woff;
if(pos.y>CGI->mh->map->height - this->adventureInt->terrain.tilesh + Hoff)
pos.y = CGI->mh->map->height - this->adventureInt->terrain.tilesh + Hoff;
return pos;
}
void CPlayerInterface::heroPrimarySkillChanged(const CGHeroInstance * hero, int which, int val)

View File

@ -2,12 +2,12 @@
#include "CAmbarCendamo.h"
#include "../CGameInfo.h"
#include "CObjectHandler.h"
#include "CCastleHandler.h"
#include "CTownHandler.h"
#include "CDefObjInfoHandler.h"
#include "../SDL_Extensions.h"
#include "../CGameState.h"
#include "CLodHandler.h"
#include "SDL.h"
#include "CDefHandler.h"
#include "CCreatureHandler.h"
#include <set>
#include <iomanip>
#include <sstream>
@ -383,19 +383,18 @@ void CAmbarCendamo::deh3m()
int ist;
ist=i; //starting i for loop
map.allowedHeroes.resize(HEROES_QUANTITY);
for(int xx=0;xx<HEROES_QUANTITY;xx++)
map.allowedHeroes[xx] = true;
for(i; i<ist+ (map.version == Eformat::RoE ? 16 : 20) ; ++i)
{
unsigned char c = bufor[i];
for(int yy=0; yy<8; ++yy)
{
if((i-ist)*8+yy < CGameInfo::mainObj->heroh->heroes.size())
{
if(c == (c|((unsigned char)intPow(2, yy))))
CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy]->isAllowed = true;
else
CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy]->isAllowed = false;
}
}
if((i-ist)*8+yy < HEROES_QUANTITY)
if(c != (c|((unsigned char)intPow(2, yy))))
map.allowedHeroes[(i-ist)*8+yy] = false;
}
if(map.version>RoE) //probably reserved for further heroes
i+=4;
@ -682,7 +681,7 @@ void CAmbarCendamo::deh3m()
{
//std::cout << "object nr "<<ww<<"\ti= "<<i<<std::endl;
CGObjectInstance * nobj = new CGObjectInstance(); //we will read this object
nobj->id = CGameInfo::mainObj->objh->objInstances.size();
nobj->id = map.objects.size();
nobj->pos.x = bufor[i++];
nobj->pos.y = bufor[i++];
nobj->pos.z = bufor[i++];
@ -789,14 +788,7 @@ void CAmbarCendamo::deh3m()
nhi->identifier = readNormalNr(i, 4); i+=4;
}
nhi->setOwner(bufor[i]); ++i;
int typeBuf = readNormalNr(i, 1); ++i;
//we should already know type from subID
//if(typeBuf==0xff)
// spec->type = NULL;
//else
// spec->type = CGameInfo::mainObj->heroh->heroes[typeBuf];
nhi->subID = readNormalNr(i, 1); ++i;
if(readChar())//true if hero has nonstandard name
nhi->name = readString();
if(map.version>AB)
@ -840,10 +832,9 @@ void CAmbarCendamo::deh3m()
//misc5 art //17
if(map.version>=SoD)
{
i+=2;
//int id = readNormalNr(i, artidlen); i+=artidlen;
//if(id!=artmask)
// spec->artifWorn[16] = id;
int id = readNormalNr(i, artidlen); i+=artidlen;
if(id!=artmask)
nhi->artifWorn[16] = id;
}
//spellbook
int id = readNormalNr(i, artidlen); i+=artidlen;
@ -871,22 +862,16 @@ void CAmbarCendamo::deh3m()
}
} //artifacts
nhi->patrolRadious = readNormalNr(i, 1); ++i;
if(nhi->patrolRadious == 0xff)
nhi->patrolRadious = -1;
nhi->patrol.patrolRadious = readNormalNr(i, 1); ++i;
if(nhi->patrol.patrolRadious == 0xff)
nhi->patrol.patrolling = false;
else
nhi->patrol.patrolling = true;
if(map.version>RoE)
{
if(readChar())//true if hero has nonstandard (mapmaker defined) biography
{
int length = readNormalNr(i); i+=4;
int iStart = i;
i+=length;
for(int bb=0; bb<length; ++bb)
{
nhi->biography+=bufor[iStart+bb];
}
}
nhi->biography = readString();
nhi->sex = !(bufor[i]); ++i;
}
//spells
@ -936,9 +921,9 @@ void CAmbarCendamo::deh3m()
nhi->mana = -1;
nhi->movement = -1;
if(nhi->ID==34)
CGI->heroh->heroInstances.push_back(nhi);
else
CGI->objh->objInstances.push_back(nhi);
map.heroes.push_back(nhi);
//else
// CGI->objh->objInstances.push_back(nhi);
break;
}
@ -1159,7 +1144,7 @@ void CAmbarCendamo::deh3m()
case 8:
{
int heroType = bufor[i]; ++i;
spec->m8hero = CGameInfo::mainObj->heroh->heroes[heroType];
spec->m8hero = heroType;
int limit = readNormalNr(i); i+=4;
if(limit == ((int)0xffffffff))
{
@ -1426,7 +1411,6 @@ void CAmbarCendamo::deh3m()
}
case EDefType::TOWN_DEF:
{
CCastleObjInfo * spec = new CCastleObjInfo;
CGTownInstance * nt = new CGTownInstance();
(*(static_cast<CGObjectInstance*>(nt))) = *nobj;
delete nobj;
@ -1449,7 +1433,7 @@ void CAmbarCendamo::deh3m()
{
for(int bit=0;bit<8;bit++)
if(bufor[i] & (1<<bit))
nt->h3mbuildings.insert(byte*8+bit);
nt->builtBuildings.insert(byte*8+bit);
i++;
}
//forbidden buildings
@ -1460,18 +1444,14 @@ void CAmbarCendamo::deh3m()
nt->forbiddenBuildings.insert(byte*8+bit);
i++;
}
nt->builtBuildings = convertBuildings(nt->h3mbuildings,nt->subID);
nt->builtBuildings = convertBuildings(nt->builtBuildings,nt->subID);
nt->forbiddenBuildings = convertBuildings(nt->forbiddenBuildings,nt->subID);
}
else //standard buildings
{
if(readChar()) //has fort
nt->builtBuildings.insert(7);
nt->builtBuildings.insert(10);
nt->builtBuildings.insert(5);
nt->builtBuildings.insert(30);
if(rand()%2)
nt->builtBuildings.insert(31);
nt->builtBuildings.insert(-50); //means that set of standard building should be included
}
int ist = i;
@ -1555,7 +1535,7 @@ void CAmbarCendamo::deh3m()
nce.gen[vv] = readNormalNr(i, 2); i+=2;
}
i+=4;
spec->events.push_back(nce);
nt->events.insert(nce);
}//castle events have been read
if(map.version > AB)
@ -1569,7 +1549,7 @@ void CAmbarCendamo::deh3m()
nt->builded = 0;
nt->destroyed = 0;
nt->garrisonHero = NULL;
CGI->townh->townInstances.push_back(nt);
map.towns.push_back(nt);
break;
}
case EDefType::PLAYERONLY_DEF:
@ -1896,7 +1876,7 @@ void CAmbarCendamo::deh3m()
case 8:
{
int heroType = bufor[i]; ++i;
spec->m8hero = CGameInfo::mainObj->heroh->heroes[heroType];
spec->m8hero = heroType;
int limit = readNormalNr(i); i+=4;
if(limit == ((int)0xffffffff))
{
@ -1955,33 +1935,10 @@ borderguardend:
break;
}
} //end of main switch
CGameInfo::mainObj->objh->objInstances.push_back(nobj);
map.objects.push_back(nobj);
}//end of loading objects
THC std::cout<<"\tReading objects: "<<th.getDif()<<std::endl;
///loading defs from lod
for (int ir=0;ir<map.defy.size();ir++)
{
map.defy[ir]->handler=CGI->spriteh->giveDef(map.defy[ir]->name);
CGDefInfo* pom = CGI->dobjinfo->gobjs[map.defy[ir]->id][map.defy[ir]->subid];
if(pom)
pom->handler=map.defy[ir]->handler;
else
std::cout << "Lacking def info for " << map.defy[ir]->id << " " << map.defy[ir]->subid <<" " << map.defy[ir]->name << std::endl;
}
for(int vv=0; vv<map.defy.size(); ++vv)
{
if(map.defy[vv]->handler->alphaTransformed)
continue;
for(int yy=0; yy<map.defy[vv]->handler->ourImages.size(); ++yy)
{
map.defy[vv]->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map.defy[vv]->handler->ourImages[yy].bitmap);
map.defy[vv]->handler->alphaTransformed = true;
}
}
THC std::cout<<"\tUnpacking and handling defs: "<<th.getDif()<<std::endl;
//loading events
int numberOfEvents = readNormalNr(i); i+=4;
for(int yyoo=0; yyoo<numberOfEvents; ++yyoo)

View File

@ -4,9 +4,7 @@
#include <string>
#include <vector>
#include "../global.h"
#include "SDL.h"
#include "../map.h"
#include "CDefHandler.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};

View File

@ -1,2 +0,0 @@
#include "../stdafx.h"
#include "CCastleHandler.h"

View File

@ -1,49 +0,0 @@
#ifndef CCASTLEHANDLER_H
#define CCASTLEHANDLER_H
#include "CBuildingHandler.h"
#include "CHeroHandler.h"
#include "CObjectHandler.h"
#include "CCreatureHandler.h"
class CCastleEvent
{
public:
std::string name, message;
int wood, mercury, ore, sulfur, crystal, gems, gold; //gain / loss of resources
unsigned char players; //players for whom this event can be applied
bool forHuman, forComputer;
int firstShow; //postpone of first encounter time in days
int forEvery; //every n days this event will occure
unsigned char bytes[6]; //build specific buildings (raw format, similar to town's)
int gen[7]; //additional creatures in i-th level dwelling
};
class CCastleObjInfo : public CSpecObjInfo //castle class
{
public:
int x, y, z; //posiotion
std::vector<CBuilding> buildings; //buildings we can build in this castle
std::vector<bool> isBuild; //isBuild[i] is true, when building buildings[i] has been built
std::vector<bool> isLocked; //isLocked[i] is true, when building buildings[i] canot be built
bool unusualBuildins; //if true, intrepret bytes below
unsigned char buildingSettings[12]; //raw format for two vectors above (greatly depends on town type)
bool hasFort; //used only if unusualBuildings is false
unsigned char bytes[4]; //identifying bytes
unsigned char player; //255 - nobody, players 0 - 7
std::string name; //town name
CCreatureSet garrison;
std::vector<CSpell *> possibleSpells;
std::vector<CSpell *> obligatorySpells;
std::vector<CSpell *> availableSpells;
std::vector<CCastleEvent> events;
unsigned char alignment; //255 - same as owner/random, 0 - same as red, 1 - same as blue, etc
};
#endif //CCASTLEHANDLER_H

View File

@ -9,7 +9,7 @@
#include "../SDL_Extensions.h"
#include <cmath>
#include <iomanip>
#include "CDefHandler.h"
CHeroHandler::~CHeroHandler()
{
for (int j=0;j<heroes.size();j++)

View File

@ -46,7 +46,6 @@ public:
class CHeroHandler
{
public:
std::vector<CGHeroInstance *> heroInstances;
std::vector<CHero*> heroes; //by�o nodrze
std::vector<CHeroClass *> heroClasses;
std::vector<CDefHandler *> flags1, flags2, flags3, flags4; //flags blitted on heroes when ,

View File

@ -242,7 +242,10 @@ int CGHeroInstance::getSecSkillLevel(const int & ID) const
}
const CArtifact * CGHeroInstance::getArt(int pos)
{
if(artifWorn.find(pos)!=artifWorn.end())
return &CGI->arth->artifacts[artifWorn[pos]];
else
return NULL;
}
int CGTownInstance::getSightDistance() const //returns sight distance
@ -355,6 +358,7 @@ CGHeroInstance::CGHeroInstance()
moveDir = 4;
mana = 0;
visitedTown = NULL;
type = NULL;
}
CGHeroInstance::~CGHeroInstance()

View File

@ -48,30 +48,25 @@ public:
bool humanActivate; //true if human player can activate this event
};
//class CHeroObjInfo : public CSpecObjInfo
//{
//public:
// unsigned char bytes[4]; //mysterius bytes identifying hero in a strange way
// int player;
// CHero * type;
// std::string name; //if nonstandard
// bool standardGarrison; //true if hero has standard garrison
// CCreatureSet garrison; //hero's army
// std::vector<int> artifacts; //hero's artifacts from bag
// //CArtifact * artHead, * artLRing, * artRRing, * artLHand, * artRhand, * artFeet, * artSpellBook, * artMach1, * artMach2, * artMach3, * artMach4, * artMisc1, * artMisc2, * artMisc3, * artMisc4, * artMisc5, * artTorso, * artNeck, * artShoulders; //working artifactsstd::vector<CArtifact *> artifWorn; // 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
// std::map<int,int> artifWorn; // keys: 0 - head; 1 - shoulders; 2 - neck; 3 - right hand; 4 - left hand; 5 - torso; 6 - right ring; 7 - left ring; 8 - feet; 9 - misc1; 10 - misc2; 11 - misc3; 12 - misc4; 13 - mach1; 14 - mach2; 15 - mach3; 16 - mach4; 17 - spellbook; 18 - misc5
// bool isGuarding;
// int guardRange; //range of hero's guard
// std::string biography; //if nonstandard
// bool sex; //if true, reverse hero's sex
// std::vector<int> spells; //hero's spells
// int attack, defence, power, knowledge; //main hero's attributes
// unsigned int experience; //hero's experience points
// std::vector<int> abilities; //hero's abilities
// std::vector<int> abilityLevels; //hero ability levels
// bool defaultMainStats; //if true attack, defence, power and knowledge are typical
// CGHeroInstance * myInstance; //pointer to appropriate hero instance
//};
class CCastleEvent
{
public:
std::string name, message;
int wood, mercury, ore, sulfur, crystal, gems, gold; //gain / loss of resources
unsigned char players; //players for whom this event can be applied
bool forHuman, forComputer;
int firstShow; //postpone of first encounter time in days
int forEvery; //every n days this event will occure
unsigned char bytes[6]; //build specific buildings (raw format, similar to town's)
int gen[7]; //additional creatures in i-th level dwelling
bool operator<(const CCastleEvent &drugie) const
{
return firstShow<drugie.firstShow;
}
};
class CCreatureObjInfo : public CSpecObjInfo
{
@ -106,7 +101,7 @@ public:
std::vector<CCreature *> m6cre;//for mission 6
std::vector<int> m6number;
int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; //for mission 7
CHero * m8hero;//for mission 8
int m8hero;//for mission 8 - hero ID
int m9player; //for mission 9 - number; from 0 to 7
std::string firstVisitText, nextVisitText, completedText;
@ -276,7 +271,7 @@ public:
//for mission 7
int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold;
//for mission 8
CHero * m8hero;
int m8hero; //hero id
//for mission 9
int m9player; //number; from 0 to 7
@ -343,9 +338,16 @@ public:
std::vector<std::pair<int,int> > secSkills; //first - ID of skill, second - level of skill (0 - basic, 1 - adv., 2 - expert)
int movement; //remaining movement points
int identifier; //from the map file
int patrolRadious; //-1 - no patrol
bool sex;
struct Patrol
{
Patrol(){patrolling=false;patrolRadious=-1;};
bool patrolling;
int patrolRadious;
} patrol;
bool inTownGarrison; // if hero is in town garrison
CGTownInstance * visitedTown; //set if hero is visiting town or in the town garrison
@ -379,29 +381,25 @@ public:
std::string name; // name of town
int builded; //how many buildings has been built this turn
int destroyed; //how many buildings has been destroyed this turn
const CGHeroInstance * garrisonHero, *visitingHero;
int identifier; //special identifier from h3m (only > RoE maps)
int alignment;
std::set<int> forbiddenBuildings, builtBuildings;
std::vector<int> possibleSpells, obligatorySpells, availableSpells;
struct StrInfo
{
std::map<int,int> creatures; //level - available amount
} strInfo;
std::set<CCastleEvent> events;
std::set<int> forbiddenBuildings, builtBuildings, h3mbuildings;
const CGHeroInstance * garrisonHero, *visitingHero;
std::vector<int> possibleSpells, obligatorySpells, availableSpells;
int getSightDistance() const; //returns sight distance
int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle
int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
bool creatureDwelling(const int & level, bool upgraded=false) const;
int getHordeLevel(const int & HID) const; //HID - 0 or 1; returns creature level or -1 if that horde structure is not present
int creatureGrowth(const int & level) const;
bool hasFort() const;
bool hasCapitol() const;
int dailyIncome() const;
@ -414,7 +412,6 @@ class CObjectHandler
{
public:
std::vector<CObject> objects; //vector of objects; i-th object in vector has subnumber i
std::vector<CGObjectInstance*> objInstances; //vector with objects on map
std::vector<int> cregens; //type 17. dwelling subid -> creature ID
void loadObjects();

View File

@ -53,9 +53,6 @@ public:
std::map<int,std::map<int, Structure*> > structures; // <town ID, <structure ID, structure>>
std::map<int, std::map<int,std::set<int> > > requirements; //requirements[town_id][structure_id] -> set of required buildings
std::vector<CGTownInstance *> townInstances;
};
#endif //CTOWNHANDLER_H

17
map.h
View File

@ -6,14 +6,15 @@
#include <map>
#include "global.h"
class CGDefInfo;
class CHeroObjInfo;
class CGObjectInstance;
class CGHeroInstance;
class CGTownInstance;
enum ESortBy{name,playerAm,size,format, viccon,loscon};
struct Sresource
{
std::string resName; //name of this resource
int amount; //it can be greater and lesser than 0
};
class CGHeroInstance;
struct TimeEvent
{
std::string eventName;
@ -106,12 +107,6 @@ struct VicCon7 : public CspecificVictoryConidtions // defeat a specific monster
{
int3 locationOfMonster;
};
/*struct VicCon8 : public CspecificVictoryConidtions // flag all creature dwellings
{
};
struct VicCon9 : public CspecificVictoryConidtions // flag all mines
{
};*/
struct VicCona : public CspecificVictoryConidtions //transport specific artifact
{
int artifactID;
@ -141,7 +136,6 @@ public:
int firstOccurence;
int nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time;
};
struct Mapa
{
Eformat version; // version of map Eformat
@ -167,7 +161,12 @@ struct Mapa
std::vector<bool> allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed
std::vector<bool> allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed
std::vector<bool> allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed
std::vector<bool> allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed
std::vector<CMapEvent> events;
std::vector<CGObjectInstance*> objects;
std::vector<CGHeroInstance*> heroes;
std::vector<CGTownInstance*> towns;
};
class CMapHeader
{

View File

@ -9,7 +9,6 @@
#include <algorithm>
#include "CGameState.h"
#include "CLua.h"
#include "hch\CCastleHandler.h"
#include "hch\CHeroHandler.h"
#include "hch\CTownHandler.h"
#include "hch\CArtHandler.h"
@ -178,17 +177,17 @@ std::pair<int,int> CMapHandler::pickObject(CGObjectInstance *obj)
CCreGen2ObjInfo* info =(CCreGen2ObjInfo*)obj->info;
if (info->asCastle)
{
for(int i=0;i<CGI->objh->objInstances.size();i++)
for(int i=0;i<map->objects.size();i++)
{
if(CGI->objh->objInstances[i]->ID==77 && dynamic_cast<CGTownInstance*>(CGI->objh->objInstances[i])->identifier == info->identifier)
if(map->objects[i]->ID==77 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
randomizeObject(CGI->objh->objInstances[i]); //we have to randomize the castle first
faction = CGI->objh->objInstances[i]->subID;
randomizeObject(map->objects[i]); //we have to randomize the castle first
faction = map->objects[i]->subID;
break;
}
else if(CGI->objh->objInstances[i]->ID==98 && dynamic_cast<CGTownInstance*>(CGI->objh->objInstances[i])->identifier == info->identifier)
else if(map->objects[i]->ID==98 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
faction = CGI->objh->objInstances[i]->subID;
faction = map->objects[i]->subID;
break;
}
}
@ -216,17 +215,17 @@ std::pair<int,int> CMapHandler::pickObject(CGObjectInstance *obj)
CCreGenObjInfo* info =(CCreGenObjInfo*)obj->info;
if (info->asCastle)
{
for(int i=0;i<CGI->objh->objInstances.size();i++)
for(int i=0;i<map->objects.size();i++)
{
if(CGI->objh->objInstances[i]->ID==77 && dynamic_cast<CGTownInstance*>(CGI->objh->objInstances[i])->identifier == info->identifier)
if(map->objects[i]->ID==77 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
randomizeObject(CGI->objh->objInstances[i]); //we have to randomize the castle first
faction = CGI->objh->objInstances[i]->subID;
randomizeObject(map->objects[i]); //we have to randomize the castle first
faction = map->objects[i]->subID;
break;
}
else if(CGI->objh->objInstances[i]->ID==98 && dynamic_cast<CGTownInstance*>(CGI->objh->objInstances[i])->identifier == info->identifier)
else if(map->objects[i]->ID==98 && dynamic_cast<CGTownInstance*>(map->objects[i])->identifier == info->identifier)
{
faction = CGI->objh->objInstances[i]->subID;
faction = map->objects[i]->subID;
break;
}
}
@ -290,8 +289,8 @@ void CMapHandler::randomizeObject(CGObjectInstance *cur)
cur->ID = ran.first;
cur->subID = ran.second;
h->type = CGI->heroh->heroes[ran.second];
CGI->heroh->heroInstances.push_back(h);
CGI->objh->objInstances.erase(std::find(CGI->objh->objInstances.begin(),CGI->objh->objInstances.end(),h));
map->heroes.push_back(h);
map->objects.erase(std::find(map->objects.begin(),map->objects.end(),h));
return; //TODO: maybe we should do something with definfo?
}
else if(ran.first==98)//special code for town
@ -330,11 +329,11 @@ void CMapHandler::randomizeObject(CGObjectInstance *cur)
void CMapHandler::randomizeObjects()
{
CGObjectInstance * cur;
for(int no=0; no<CGI->objh->objInstances.size(); ++no)
for(int no=0; no<map->objects.size(); ++no)
{
randomizeObject(CGI->objh->objInstances[no]);
if(CGI->objh->objInstances[no]->ID==26)
CGI->objh->objInstances[no]->defInfo->handler=NULL;
randomizeObject(map->objects[no]);
if(map->objects[no]->ID==26)
map->objects[no]->defInfo->handler=NULL;
}
}
void CMapHandler::prepareFOWDefs()
@ -385,11 +384,11 @@ void CMapHandler::prepareFOWDefs()
{
CSDL_Ext::alphaTransform(partialHide->ourImages[i].bitmap);
}
//visibility.resize(reader->map.width+2*Woff);
//for(int gg=0; gg<reader->map.width+2*Woff; ++gg)
//visibility.resize(map->width+2*Woff);
//for(int gg=0; gg<map->width+2*Woff; ++gg)
//{
// visibility[gg].resize(reader->map.height+2*Hoff);
// for(int jj=0; jj<reader->map.height+2*Hoff; ++jj)
// visibility[gg].resize(map->height+2*Hoff);
// for(int jj=0; jj<map->height+2*Hoff; ++jj)
// visibility[gg][jj] = true;
//}
@ -458,9 +457,9 @@ void CMapHandler::roadsRiverTerrainInit()
}
}
//roadBitmaps = new SDL_Surface** [reader->map.width+2*Woff];
//for (int ii=0;ii<reader->map.width+2*Woff;ii++)
// roadBitmaps[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory
//roadBitmaps = new SDL_Surface** [map->width+2*Woff];
//for (int ii=0;ii<map->width+2*Woff;ii++)
// roadBitmaps[ii] = new SDL_Surface*[map->height+2*Hoff]; // allocate memory
sizes.x = CGI->ac->map.width;
sizes.y = CGI->ac->map.height;
sizes.z = CGI->ac->map.twoLevel+1;
@ -477,42 +476,42 @@ void CMapHandler::roadsRiverTerrainInit()
for (int i=0; i<reader->map.width; i++) //jest po szeroko�ci
for (int i=0; i<map->width; i++) //jest po szeroko�ci
{
for (int j=0; j<reader->map.height;j++) //po wysoko�ci
for (int j=0; j<map->height;j++) //po wysoko�ci
{
for (int k=0; k<=reader->map.twoLevel; ++k)
for (int k=0; k<=map->twoLevel; ++k)
{
TerrainTile** pomm = reader->map.terrain; ;
TerrainTile** pomm = map->terrain; ;
if (k==0)
pomm = reader->map.terrain;
pomm = map->terrain;
else
pomm = reader->map.undergroungTerrain;
pomm = map->undergroungTerrain;
if(pomm[i][j].malle)
{
int cDir;
bool rotV, rotH;
if(k==0)
{
int roadpom = reader->map.terrain[i][j].malle-1,
impom = reader->map.terrain[i][j].roadDir;
int roadpom = map->terrain[i][j].malle-1,
impom = map->terrain[i][j].roadDir;
SDL_Surface *pom1 = roadDefs[roadpom]->ourImages[impom].bitmap;
ttiles[i][j][k].roadbitmap.push_back(pom1);
cDir = reader->map.terrain[i][j].roadDir;
cDir = map->terrain[i][j].roadDir;
rotH = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 5) & 1;
rotV = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 4) & 1;
rotH = (map->terrain[i][j].siodmyTajemniczyBajt >> 5) & 1;
rotV = (map->terrain[i][j].siodmyTajemniczyBajt >> 4) & 1;
}
else
{
int pom111 = reader->map.undergroungTerrain[i][j].malle-1,
pom777 = reader->map.undergroungTerrain[i][j].roadDir;
int pom111 = map->undergroungTerrain[i][j].malle-1,
pom777 = map->undergroungTerrain[i][j].roadDir;
SDL_Surface *pom1 = roadDefs[pom111]->ourImages[pom777].bitmap;
ttiles[i][j][k].roadbitmap.push_back(pom1);
cDir = reader->map.undergroungTerrain[i][j].roadDir;
cDir = map->undergroungTerrain[i][j].roadDir;
rotH = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 5) & 1;
rotV = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 4) & 1;
rotH = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 5) & 1;
rotV = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 4) & 1;
}
if(rotH)
{
@ -557,20 +556,20 @@ void CMapHandler::roadsRiverTerrainInit()
}
//simple values initialized
for (int i=0; i<reader->map.width; i++) //jest po szeroko�ci
for (int i=0; i<map->width; i++) //jest po szeroko�ci
{
for (int j=0; j<reader->map.height;j++) //po wysoko�ci
for (int j=0; j<map->height;j++) //po wysoko�ci
{
for(int k=0; k<=reader->map.twoLevel; ++k)
for(int k=0; k<=map->twoLevel; ++k)
{
TerrainTile** pomm = reader->map.terrain;
TerrainTile** pomm = map->terrain;
if(k==0)
{
pomm = reader->map.terrain;
pomm = map->terrain;
}
else
{
pomm = reader->map.undergroungTerrain;
pomm = map->undergroungTerrain;
}
if(pomm[i][j].nuine)
{
@ -578,17 +577,17 @@ void CMapHandler::roadsRiverTerrainInit()
bool rotH, rotV;
if(k==0)
{
ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[reader->map.terrain[i][j].nuine-1]->ourImages[reader->map.terrain[i][j].rivDir].bitmap);
cDir = reader->map.terrain[i][j].rivDir;
rotH = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 3) & 1;
rotV = (reader->map.terrain[i][j].siodmyTajemniczyBajt >> 2) & 1;
ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[map->terrain[i][j].nuine-1]->ourImages[map->terrain[i][j].rivDir].bitmap);
cDir = map->terrain[i][j].rivDir;
rotH = (map->terrain[i][j].siodmyTajemniczyBajt >> 3) & 1;
rotV = (map->terrain[i][j].siodmyTajemniczyBajt >> 2) & 1;
}
else
{
ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[reader->map.undergroungTerrain[i][j].nuine-1]->ourImages[reader->map.undergroungTerrain[i][j].rivDir].bitmap);
cDir = reader->map.undergroungTerrain[i][j].rivDir;
rotH = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 3) & 1;
rotV = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt >> 2) & 1;
ttiles[i][j][k].rivbitmap.push_back(staticRiverDefs[map->undergroungTerrain[i][j].nuine-1]->ourImages[map->undergroungTerrain[i][j].rivDir].bitmap);
cDir = map->undergroungTerrain[i][j].rivDir;
rotH = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 3) & 1;
rotV = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt >> 2) & 1;
}
if(rotH)
{
@ -609,56 +608,56 @@ void CMapHandler::roadsRiverTerrainInit()
}
void CMapHandler::borderAndTerrainBitmapInit()
{
//terrainBitmap = new SDL_Surface **[reader->map.width+2*Woff];
//for (int ii=0;ii<reader->map.width+2*Woff;ii++)
// terrainBitmap[ii] = new SDL_Surface*[reader->map.height+2*Hoff]; // allocate memory
//terrainBitmap = new SDL_Surface **[map->width+2*Woff];
//for (int ii=0;ii<map->width+2*Woff;ii++)
// terrainBitmap[ii] = new SDL_Surface*[map->height+2*Hoff]; // allocate memory
CDefHandler * bord = CGameInfo::mainObj->spriteh->giveDef("EDG.DEF");
bord->notFreeImgs = true;
for (int i=0-Woff; i<reader->map.width+Woff; i++) //jest po szeroko�ci
for (int i=0-Woff; i<map->width+Woff; i++) //jest po szeroko�ci
{
for (int j=0-Hoff; j<reader->map.height+Hoff;j++) //po wysoko�ci
for (int j=0-Hoff; j<map->height+Hoff;j++) //po wysoko�ci
{
for(int k=0; k<=reader->map.twoLevel; ++k)
for(int k=0; k<=map->twoLevel; ++k)
{
if(i < 0 || i > (reader->map.width-1) || j < 0 || j > (reader->map.height-1))
if(i < 0 || i > (map->width-1) || j < 0 || j > (map->height-1))
{
if(i==-1 && j==-1)
{
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[16].bitmap);
continue;
}
else if(i==-1 && j==(reader->map.height))
else if(i==-1 && j==(map->height))
{
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[19].bitmap);
continue;
}
else if(i==(reader->map.width) && j==-1)
else if(i==(map->width) && j==-1)
{
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[17].bitmap);
continue;
}
else if(i==(reader->map.width) && j==(reader->map.height))
else if(i==(map->width) && j==(map->height))
{
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[18].bitmap);
continue;
}
else if(j == -1 && i > -1 && i < reader->map.height)
else if(j == -1 && i > -1 && i < map->height)
{
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[22+rand()%2].bitmap);
continue;
}
else if(i == -1 && j > -1 && j < reader->map.height)
else if(i == -1 && j > -1 && j < map->height)
{
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[33+rand()%2].bitmap);
continue;
}
else if(j == reader->map.height && i >-1 && i < reader->map.width)
else if(j == map->height && i >-1 && i < map->width)
{
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[29+rand()%2].bitmap);
continue;
}
else if(i == reader->map.width && j > -1 && j < reader->map.height)
else if(i == map->width && j > -1 && j < map->height)
{
ttiles[i][j][k].terbitmap.push_back(bord->ourImages[25+rand()%2].bitmap);
continue;
@ -669,12 +668,12 @@ void CMapHandler::borderAndTerrainBitmapInit()
continue;
}
}
//TerrainTile zz = reader->map.terrain[i-Woff][j-Hoff];
//TerrainTile zz = map->terrain[i-Woff][j-Hoff];
std::string name;
if (k>0)
name = nameFromType(reader->map.undergroungTerrain[i][j].tertype);
name = nameFromType(map->undergroungTerrain[i][j].tertype);
else
name = nameFromType(reader->map.terrain[i][j].tertype);
name = nameFromType(map->terrain[i][j].tertype);
for (unsigned int m=0; m<defs.size(); m++)
{
try
@ -685,15 +684,15 @@ void CMapHandler::borderAndTerrainBitmapInit()
{
int ktora;
if (k==0)
ktora = reader->map.terrain[i][j].terview;
ktora = map->terrain[i][j].terview;
else
ktora = reader->map.undergroungTerrain[i][j].terview;
ktora = map->undergroungTerrain[i][j].terview;
ttiles[i][j][k].terbitmap.push_back(defs[m]->ourImages[ktora].bitmap);
int zz;
if (k==0)
zz = (reader->map.terrain[i][j].siodmyTajemniczyBajt)%4;
zz = (map->terrain[i][j].siodmyTajemniczyBajt)%4;
else
zz = (reader->map.undergroungTerrain[i][j].siodmyTajemniczyBajt)%4;
zz = (map->undergroungTerrain[i][j].siodmyTajemniczyBajt)%4;
switch (zz)
{
case 1:
@ -729,15 +728,15 @@ void CMapHandler::borderAndTerrainBitmapInit()
void CMapHandler::initObjectRects()
{
//initializing objects / rects
for(int f=0; f<CGI->objh->objInstances.size(); ++f)
for(int f=0; f<map->objects.size(); ++f)
{
/*CGI->objh->objInstances[f]->pos.x+=1;
CGI->objh->objInstances[f]->pos.y+=1;*/
if(!CGI->objh->objInstances[f]->defInfo)
/*map->objects[f]->pos.x+=1;
map->objects[f]->pos.y+=1;*/
if(!map->objects[f]->defInfo)
{
continue;
}
CDefHandler * curd = CGI->objh->objInstances[f]->defInfo->handler;
CDefHandler * curd = map->objects[f]->defInfo->handler;
if(curd)
{
for(int fx=0; fx<curd->ourImages[0].bitmap->w>>5; ++fx) //curd->ourImages[0].bitmap->w/32
@ -749,21 +748,21 @@ void CMapHandler::initObjectRects()
cr.h = 32;
cr.x = fx<<5; //fx*32
cr.y = fy<<5; //fy*32
std::pair<CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(CGI->objh->objInstances[f],cr);
std::pair<CGObjectInstance*,SDL_Rect> toAdd = std::make_pair(map->objects[f],cr);
if((CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
if((map->objects[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)>=0 && (map->objects[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1)<ttiles.size()-Woff && (map->objects[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)>=0 && (map->objects[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1)<ttiles[0].size()-Hoff)
{
//TerrainTile2 & curt =
// ttiles
// [CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32]
//[CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32]
//[CGI->objh->objInstances[f]->pos.z];
ttiles[CGI->objh->objInstances[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][CGI->objh->objInstances[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][CGI->objh->objInstances[f]->pos.z].objects.push_back(toAdd);
// [map->objects[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32]
//[map->objects[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32]
//[map->objects[f]->pos.z];
ttiles[map->objects[f]->pos.x + fx - curd->ourImages[0].bitmap->w/32+1][map->objects[f]->pos.y + fy - curd->ourImages[0].bitmap->h/32+1][map->objects[f]->pos.z].objects.push_back(toAdd);
}
} // for(int fy=0; fy<curd->ourImages[0].bitmap->h/32; ++fy)
} //for(int fx=0; fx<curd->ourImages[0].bitmap->w/32; ++fx)
}//if curd
} // for(int f=0; f<CGI->objh->objInstances.size(); ++f)
} // for(int f=0; f<map->objects.size(); ++f)
for(int ix=0; ix<ttiles.size()-Woff; ++ix)
{
for(int iy=0; iy<ttiles[0].size()-Hoff; ++iy)
@ -777,24 +776,24 @@ void CMapHandler::initObjectRects()
}
void CMapHandler::calculateBlockedPos()
{
for(int f=0; f<CGI->objh->objInstances.size(); ++f) //calculationg blocked / visitable positions
for(int f=0; f<map->objects.size(); ++f) //calculationg blocked / visitable positions
{
if(!CGI->objh->objInstances[f]->defInfo)
if(!map->objects[f]->defInfo)
continue;
CDefHandler * curd = CGI->objh->objInstances[f]->defInfo->handler;
CDefHandler * curd = map->objects[f]->defInfo->handler;
for(int fx=0; fx<8; ++fx)
{
for(int fy=0; fy<6; ++fy)
{
int xVal = CGI->objh->objInstances[f]->pos.x + fx - 7;
int yVal = CGI->objh->objInstances[f]->pos.y + fy - 5;
int zVal = CGI->objh->objInstances[f]->pos.z;
int xVal = map->objects[f]->pos.x + fx - 7;
int yVal = map->objects[f]->pos.y + fy - 5;
int zVal = map->objects[f]->pos.z;
if(xVal>=0 && xVal<ttiles.size()-Woff && yVal>=0 && yVal<ttiles[0].size()-Hoff)
{
TerrainTile2 & curt = ttiles[xVal][yVal][zVal];
if(((CGI->objh->objInstances[f]->defInfo->visitMap[fy] >> (7 - fx)) & 1))
if(((map->objects[f]->defInfo->visitMap[fy] >> (7 - fx)) & 1))
curt.visitable = true;
if(!((CGI->objh->objInstances[f]->defInfo->blockMap[fy] >> (7 - fx)) & 1))
if(!((map->objects[f]->defInfo->blockMap[fy] >> (7 - fx)) & 1))
curt.blocked = true;
}
}
@ -803,6 +802,31 @@ void CMapHandler::calculateBlockedPos()
}
void CMapHandler::init()
{
timeHandler th;
th.getDif();
///loading defs from lod
for (int ir=0;ir<map->defy.size();ir++)
{
map->defy[ir]->handler=CGI->spriteh->giveDef(map->defy[ir]->name);
CGDefInfo* pom = CGI->dobjinfo->gobjs[map->defy[ir]->id][map->defy[ir]->subid];
if(pom)
pom->handler=map->defy[ir]->handler;
else
std::cout << "Lacking def info for " << map->defy[ir]->id << " " << map->defy[ir]->subid <<" " << map->defy[ir]->name << std::endl;
}
for(int vv=0; vv<map->defy.size(); ++vv)
{
if(map->defy[vv]->handler->alphaTransformed)
continue;
for(int yy=0; yy<map->defy[vv]->handler->ourImages.size(); ++yy)
{
map->defy[vv]->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(map->defy[vv]->handler->ourImages[yy].bitmap);
map->defy[vv]->handler->alphaTransformed = true;
}
}
THC std::cout<<"\tUnpacking and handling defs: "<<th.getDif()<<std::endl;
//loading castles' defs
std::ifstream ifs("config/townsDefs.txt");
int ccc;
@ -828,29 +852,28 @@ void CMapHandler::init()
do
{
f = rand()%F_NUMBER;
}while(!(reader->map.players[CGI->scenarioOps.playerInfos[i].color].allowedFactions & 1<<f));
}while(!(map->players[CGI->scenarioOps.playerInfos[i].color].allowedFactions & 1<<f));
CGI->scenarioOps.playerInfos[i].castle = f;
}
}
for(int i=0;i<PLAYER_LIMIT;i++)
{
for(int j=0; j<reader->map.players[i].heroesNames.size();j++)
for(int j=0; j<map->players[i].heroesNames.size();j++)
{
usedHeroes.insert(reader->map.players[i].heroesNames[j].heroID);
usedHeroes.insert(map->players[i].heroesNames[j].heroID);
}
}
std::cout<<"\tLoading town defs, picking random factions and heroes: "<<th.getDif()<<std::endl;
timeHandler th;
th.getDif();
randomizeObjects();//randomizing objects on map
std::cout<<"\tRandomizing objects: "<<th.getDif()<<std::endl;
for(int h=0; h<reader->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
{
//std::string hlp = reader->map.defy[h]->name;
//std::string hlp = map->defy[h]->name;
//std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper);
CGI->mh->loadedDefs.insert(std::make_pair(reader->map.defy[h]->name, reader->map.defy[h]->handler));
CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler));
}
std::cout<<"\tCollecting loaded def's handlers: "<<th.getDif()<<std::endl;
@ -862,9 +885,9 @@ void CMapHandler::init()
//giving starting hero
for(int i=0;i<PLAYER_LIMIT;i++)
{
if((reader->map.players[i].generateHeroAtMainTown && reader->map.players[i].hasMainTown) || (reader->map.players[i].hasMainTown && reader->map.version==RoE))
if((map->players[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==RoE))
{
int3 hpos = reader->map.players[i].posOfMainTown;
int3 hpos = map->players[i].posOfMainTown;
hpos.x+=1;// hpos.y+=1;
int j;
for(j=0;j<CGI->scenarioOps.playerInfos.size();j++)
@ -877,8 +900,8 @@ void CMapHandler::init()
h=pickHero(i);
CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,h,hpos,i);
nnn->defInfo->handler = CGI->heroh->flags1[0];
CGI->heroh->heroInstances.push_back(nnn);
CGI->objh->objInstances.push_back(nnn);
map->heroes.push_back(nnn);
map->objects.push_back(nnn);
}
}
std::cout<<"\tGiving starting heroes: "<<th.getDif()<<std::endl;
@ -929,7 +952,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
su = CSDL_Ext::newSurface(dx*32, dy*32, CSDL_Ext::std32bppSurface);
}
if (((dx+x)>((reader->map.width+Woff)) || (dy+y)>((reader->map.height+Hoff))) || ((x<-Woff)||(y<-Hoff) ) )
if (((dx+x)>((map->width+Woff)) || (dy+y)>((map->height+Hoff))) || ((x<-Woff)||(y<-Hoff) ) )
throw new std::string("terrainRect: out of range");
////printing terrain
for (int bx=0; bx<dx; bx++)
@ -1081,7 +1104,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
sr.h=sr.w=32;
validateRectTerr(&sr, extRect);
if(bx+x>=0 && by+y>=0 && bx+x<CGI->mh->reader->map.width && by+y<CGI->mh->reader->map.height && !visibilityMap[bx+x][by+y][level])
if(bx+x>=0 && by+y>=0 && bx+x<CGI->mh->map->width && by+y<CGI->mh->map->height && !visibilityMap[bx+x][by+y][level])
{
SDL_Surface * hide = getVisBitmap(bx+x, by+y, visibilityMap, level);
CSDL_Ext::blit8bppAlphaTo24bpp(hide, &genRect(sr.h, sr.w, 0, 0), su, &sr);
@ -1094,7 +1117,7 @@ SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level,
{
for (int by=0; by<dy; by++)
{
if(bx+x<0 || by+y<0 || bx+x>reader->map.width+(-1) || by+y>reader->map.height+(-1))
if(bx+x<0 || by+y<0 || bx+x>map->width+(-1) || by+y>map->height+(-1))
{
SDL_Rect sr;
sr.y=by*32;
@ -1412,12 +1435,12 @@ SDL_Surface * CMapHandler::getVisBitmap(int x, int y, PseudoV< PseudoV< PseudoV<
int CMapHandler::getCost(int3 &a, int3 &b, const CGHeroInstance *hero)
{
int ret=-1;
if(a.x>=CGI->mh->reader->map.width && a.y>=CGI->mh->reader->map.height)
ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->reader->map.width-1][CGI->mh->reader->map.width-1][a.z].malle];
else if(a.x>=CGI->mh->reader->map.width && a.y<CGI->mh->reader->map.height)
ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->reader->map.width-1][a.y][a.z].malle];
else if(a.x<CGI->mh->reader->map.width && a.y>=CGI->mh->reader->map.height)
ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][CGI->mh->reader->map.width-1][a.z].malle];
if(a.x>=CGI->mh->map->width && a.y>=CGI->mh->map->height)
ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->map->width-1][CGI->mh->map->width-1][a.z].malle];
else if(a.x>=CGI->mh->map->width && a.y<CGI->mh->map->height)
ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->map->width-1][a.y][a.z].malle];
else if(a.x<CGI->mh->map->width && a.y>=CGI->mh->map->height)
ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][CGI->mh->map->width-1][a.z].malle];
else
ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[a.x][a.y][a.z].malle];
if(!(a.x==b.x || a.y==b.y))
@ -1591,10 +1614,10 @@ std::string CMapHandler::getRandomizedDefName(CGDefInfo *di, CGObjectInstance *
bool CMapHandler::removeObject(CGObjectInstance *obj)
{
hideObject(obj);
std::vector<CGObjectInstance *>::iterator db = std::find(CGI->objh->objInstances.begin(), CGI->objh->objInstances.end(), obj);
std::vector<CGObjectInstance *>::iterator db = std::find(map->objects.begin(), map->objects.end(), obj);
recalculateHideVisPosUnderObj(*db);
delete *db;
CGI->objh->objInstances.erase(db);
map->objects.erase(db);
return true;
}
@ -1792,20 +1815,20 @@ unsigned char CMapHandler::getDir(const int3 &a, const int3 &b)
void CMapHandler::loadDefs()
{
std::set<int> loadedTypes;
for (int i=0; i<reader->map.width; i++)
for (int i=0; i<map->width; i++)
{
for (int j=0; j<reader->map.width; j++)
for (int j=0; j<map->width; j++)
{
if (loadedTypes.find(reader->map.terrain[i][j].tertype)==loadedTypes.end())
if (loadedTypes.find(map->terrain[i][j].tertype)==loadedTypes.end())
{
CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(reader->map.terrain[i][j].tertype).c_str());
loadedTypes.insert(reader->map.terrain[i][j].tertype);
CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(map->terrain[i][j].tertype).c_str());
loadedTypes.insert(map->terrain[i][j].tertype);
defs.push_back(sdh);
}
if (reader->map.twoLevel && loadedTypes.find(reader->map.undergroungTerrain[i][j].tertype)==loadedTypes.end())
if (map->twoLevel && loadedTypes.find(map->undergroungTerrain[i][j].tertype)==loadedTypes.end())
{
CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(reader->map.undergroungTerrain[i][j].tertype).c_str());
loadedTypes.insert(reader->map.undergroungTerrain[i][j].tertype);
CDefHandler *sdh = CGI->spriteh->giveDef(nameFromType(map->undergroungTerrain[i][j].tertype).c_str());
loadedTypes.insert(map->undergroungTerrain[i][j].tertype);
defs.push_back(sdh);
}
}

View File

@ -60,7 +60,7 @@ class CMapHandler
public:
PseudoV< PseudoV< PseudoV<TerrainTile2> > > ttiles;
int3 sizes;
CAmbarCendamo * reader;
Mapa * map;
std::set<int> usedHeroes;
CDefHandler * fullHide;
CDefHandler * partialHide;