diff --git a/CCallback.h b/CCallback.h index 4d745ea62..23ebf3d9b 100644 --- a/CCallback.h +++ b/CCallback.h @@ -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 \ No newline at end of file diff --git a/CConsoleHandler.cpp b/CConsoleHandler.cpp index c1e403cdb..dac629a8b 100644 --- a/CConsoleHandler.cpp +++ b/CConsoleHandler.cpp @@ -64,20 +64,20 @@ int internalFunc(void * callback) vector* p; switch (*cn.c_str()) { - case 'P': - std::cout<<"Policzyc sciezke."<>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."<>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: "<heroh->heroInstances.size()<mh->map->heroes.size()<>heronum; - std::cout<<"Position of hero "<heroh->heroInstances[heronum]->getPosition(false)<mh->map->heroes[heronum]->getPosition(false)<objh->objInstances.size(); ++c) + for(int c=0; cmh->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; cobjh->objInstances.size(); ++c) + for(int c=0; cmh->map->objects.size(); ++c) { - CGI->mh->printObject(CGI->objh->objInstances[c]); + CGI->mh->printObject(CGI->mh->map->objects[c]); } break; } diff --git a/CGameState.h b/CGameState.h index 966909625..4ac7cb62a 100644 --- a/CGameState.h +++ b/CGameState.h @@ -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 * mapa, CCPPObjectScript * script); //CCallback * cb; //for communication between PlayerInterface/AI and GameState diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index 2eac173e4..84bc77e18 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -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), diff --git a/CHeroWindow.h b/CHeroWindow.h index 2adb74b9b..473fad101 100644 --- a/CHeroWindow.h +++ b/CHeroWindow.h @@ -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(); diff --git a/CLua.h b/CLua.h index 398206097..9309335cd 100644 --- a/CLua.h +++ b/CLua.h @@ -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 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 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 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 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 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 yourObjects(); //returns IDs of objects which are handled by script - friend void initGameState(CGameInfo * cgi); + friend void initGameState(Mapa * map, CGameInfo * cgi); }; \ No newline at end of file diff --git a/CMT.cpp b/CMT.cpp index e4b1b33e7..2daa4657f 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -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 * 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; iheroh->heroInstances.size();i++) //heroes instances + for (int i=0; iheroes.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::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; gac->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; gwidth+Woff; ++g) + k->second.fogOfWarMap[g].resize(map->height, Hoff); - for(int g=-Woff; gac->map.width+Woff; ++g) - for(int h=-Hoff; hac->map.height+Hoff; ++h) - k->second.fogOfWarMap[g][h].resize(cgi->ac->map.twoLevel+1, 0); + for(int g=-Woff; gwidth+Woff; ++g) + for(int h=-Hoff; hheight+Hoff; ++h) + k->second.fogOfWarMap[g][h].resize(map->twoLevel+1, 0); - for(int g=-Woff; gac->map.width+Woff; ++g) - for(int h=-Hoff; hac->map.height+Hoff; ++h) - for(int v=0; vac->map.twoLevel+1; ++v) + for(int g=-Woff; gwidth+Woff; ++g) + for(int h=-Hoff; hheight+Hoff; ++h) + for(int v=0; vtwoLevel+1; ++v) k->second.fogOfWarMap[g][h][v] = 0; - for(int xd=0; xdac->map.width; ++xd) //revealing part of map around heroes + for(int xd=0; xdwidth; ++xd) //revealing part of map around heroes { - for(int yd=0; ydac->map.height; ++yd) + for(int yd=0; ydheight; ++yd) { for(int ch=0; chsecond.heroes.size(); ++ch) { @@ -213,16 +213,20 @@ void initGameState(CGameInfo * cgi) } } /****************************TOWNS************************************************/ - for (int i=0;itownh->townInstances.size();i++) + for (int i=0;itowns.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; xdac->map.width; ++xd) //revealing part of map around towns + for(int xd=0; xdwidth; ++xd) //revealing part of map around towns { - for(int yd=0; ydac->map.height; ++yd) + for(int yd=0; ydheight; ++yd) { for(int ch=0; chsecond.towns.size(); ++ch) { @@ -300,22 +304,22 @@ void initGameState(CGameInfo * cgi) } /****************************INITIALIZING OBJECT SCRIPTS************************************************/ std::string temps("newObject"); - for (int i=0; iobjh->objInstances.size(); i++) + for (int i=0; iobjects.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): "<mh = mh; - mh->reader = ac; + mh->map = &ac->map; THC std::cout<<"Creating mapHandler: "<loadDefs(); THC std::cout<<"Reading terrain defs: "<init(); THC std::cout<<"Initializing mapHandler (together): "<map,cgi); THC std::cout<<"Initializing GameState (together): "<w, mh = mm.map[0]->h, wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y; - for(int d=0; dmh->reader->map.twoLevel+1; ++d) + for(int d=0; dmh->map->twoLevel+1; ++d) { SDL_Surface * pt = CSDL_Ext::newSurface(mm.pos.w, mm.pos.h, CSDL_Ext::std32bppSurface); diff --git a/CPathfinder.cpp b/CPathfinder.cpp index 148564e71..3510918a2 100644 --- a/CPathfinder.cpp +++ b/CPathfinder.cpp @@ -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; } diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 2a6a70dc2..609909e92 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -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) diff --git a/hch/CAmbarCendamo.cpp b/hch/CAmbarCendamo.cpp index 0316cc837..d678b6737 100644 --- a/hch/CAmbarCendamo.cpp +++ b/hch/CAmbarCendamo.cpp @@ -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 #include #include @@ -383,19 +383,18 @@ void CAmbarCendamo::deh3m() int ist; ist=i; //starting i for loop + + map.allowedHeroes.resize(HEROES_QUANTITY); + for(int xx=0;xxheroh->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 "<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; bbbiography+=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(nt))) = *nobj; delete nobj; @@ -1449,7 +1433,7 @@ void CAmbarCendamo::deh3m() { for(int bit=0;bit<8;bit++) if(bufor[i] & (1<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: "<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; vvhandler->alphaTransformed) - continue; - for(int yy=0; yyhandler->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: "< #include #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}; diff --git a/hch/CCastleHandler.cpp b/hch/CCastleHandler.cpp deleted file mode 100644 index 8f24dbd55..000000000 --- a/hch/CCastleHandler.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "../stdafx.h" -#include "CCastleHandler.h" \ No newline at end of file diff --git a/hch/CCastleHandler.h b/hch/CCastleHandler.h deleted file mode 100644 index b017b4712..000000000 --- a/hch/CCastleHandler.h +++ /dev/null @@ -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 buildings; //buildings we can build in this castle - std::vector isBuild; //isBuild[i] is true, when building buildings[i] has been built - std::vector 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 possibleSpells; - std::vector obligatorySpells; - std::vector availableSpells; - - std::vector events; - - unsigned char alignment; //255 - same as owner/random, 0 - same as red, 1 - same as blue, etc -}; - -#endif //CCASTLEHANDLER_H \ No newline at end of file diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index 585148f1a..3713e920d 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -9,7 +9,7 @@ #include "../SDL_Extensions.h" #include #include - +#include "CDefHandler.h" CHeroHandler::~CHeroHandler() { for (int j=0;j heroInstances; std::vector heroes; //było nodrze std::vector heroClasses; std::vector flags1, flags2, flags3, flags4; //flags blitted on heroes when , diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index 030d38d42..0af46e127 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -242,7 +242,10 @@ int CGHeroInstance::getSecSkillLevel(const int & ID) const } const CArtifact * CGHeroInstance::getArt(int pos) { - return &CGI->arth->artifacts[artifWorn[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() diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index 90073fb61..4f4abc3e9 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -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 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 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 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 spells; //hero's spells -// int attack, defence, power, knowledge; //main hero's attributes -// unsigned int experience; //hero's experience points -// std::vector abilities; //hero's abilities -// std::vector 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 m6cre;//for mission 6 std::vector 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 > 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 forbiddenBuildings, builtBuildings; + std::vector possibleSpells, obligatorySpells, availableSpells; struct StrInfo { std::map creatures; //level - available amount } strInfo; - - std::set forbiddenBuildings, builtBuildings, h3mbuildings; + std::set events; - const CGHeroInstance * garrisonHero, *visitingHero; - - std::vector 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 objects; //vector of objects; i-th object in vector has subnumber i - std::vector objInstances; //vector with objects on map std::vector cregens; //type 17. dwelling subid -> creature ID void loadObjects(); diff --git a/hch/CTownHandler.h b/hch/CTownHandler.h index 64fcd5b27..58f5ebffc 100644 --- a/hch/CTownHandler.h +++ b/hch/CTownHandler.h @@ -53,9 +53,6 @@ public: std::map > structures; // > std::map > > requirements; //requirements[town_id][structure_id] -> set of required buildings - - std::vector townInstances; - }; #endif //CTOWNHANDLER_H \ No newline at end of file diff --git a/map.h b/map.h index ff9b07945..6a9e332d0 100644 --- a/map.h +++ b/map.h @@ -6,14 +6,15 @@ #include #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 allowedSpell; //allowedSpell[spell_ID] - if the spell is allowed std::vector allowedArtifact; //allowedArtifact[artifact_ID] - if the artifact is allowed std::vector allowedAbilities; //allowedAbilities[ability_ID] - if the ability is allowed + std::vector allowedHeroes; //allowedHeroes[hero_ID] - if the hero is allowed std::vector events; + + std::vector objects; + std::vector heroes; + std::vector towns; }; class CMapHeader { diff --git a/mapHandler.cpp b/mapHandler.cpp index 8ed75b2ed..8164e9e04 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -9,7 +9,6 @@ #include #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 CMapHandler::pickObject(CGObjectInstance *obj) CCreGen2ObjInfo* info =(CCreGen2ObjInfo*)obj->info; if (info->asCastle) { - for(int i=0;iobjh->objInstances.size();i++) + for(int i=0;iobjects.size();i++) { - if(CGI->objh->objInstances[i]->ID==77 && dynamic_cast(CGI->objh->objInstances[i])->identifier == info->identifier) + if(map->objects[i]->ID==77 && dynamic_cast(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(CGI->objh->objInstances[i])->identifier == info->identifier) + else if(map->objects[i]->ID==98 && dynamic_cast(map->objects[i])->identifier == info->identifier) { - faction = CGI->objh->objInstances[i]->subID; + faction = map->objects[i]->subID; break; } } @@ -216,17 +215,17 @@ std::pair CMapHandler::pickObject(CGObjectInstance *obj) CCreGenObjInfo* info =(CCreGenObjInfo*)obj->info; if (info->asCastle) { - for(int i=0;iobjh->objInstances.size();i++) + for(int i=0;iobjects.size();i++) { - if(CGI->objh->objInstances[i]->ID==77 && dynamic_cast(CGI->objh->objInstances[i])->identifier == info->identifier) + if(map->objects[i]->ID==77 && dynamic_cast(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(CGI->objh->objInstances[i])->identifier == info->identifier) + else if(map->objects[i]->ID==98 && dynamic_cast(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; noobjh->objInstances.size(); ++no) + for(int no=0; noobjects.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; ggmap.width+2*Woff; ++gg) + //visibility.resize(map->width+2*Woff); + //for(int gg=0; ggwidth+2*Woff; ++gg) //{ - // visibility[gg].resize(reader->map.height+2*Hoff); - // for(int jj=0; jjmap.height+2*Hoff; ++jj) + // visibility[gg].resize(map->height+2*Hoff); + // for(int jj=0; jjheight+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;iimap.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;iiwidth+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; imap.width; i++) //jest po szerokości + for (int i=0; iwidth; i++) //jest po szerokości { - for (int j=0; jmap.height;j++) //po wysokości + for (int j=0; jheight;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; imap.width; i++) //jest po szerokości + for (int i=0; iwidth; i++) //jest po szerokości { - for (int j=0; jmap.height;j++) //po wysokości + for (int j=0; jheight;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;iimap.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;iiwidth+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; imap.width+Woff; i++) //jest po szerokości + for (int i=0-Woff; iwidth+Woff; i++) //jest po szerokości { - for (int j=0-Hoff; jmap.height+Hoff;j++) //po wysokości + for (int j=0-Hoff; jheight+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; mmap.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; fobjh->objInstances.size(); ++f) + for(int f=0; fobjects.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; fxourImages[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 toAdd = std::make_pair(CGI->objh->objInstances[f],cr); + std::pair 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)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)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)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)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; fyourImages[0].bitmap->h/32; ++fy) } //for(int fx=0; fxourImages[0].bitmap->w/32; ++fx) }//if curd - } // for(int f=0; fobjh->objInstances.size(); ++f) + } // for(int f=0; fobjects.size(); ++f) for(int ix=0; ixobjh->objInstances.size(); ++f) //calculationg blocked / visitable positions + for(int f=0; fobjects.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=0 && yValobjh->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;irdefy.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; vvdefy.size(); ++vv) + { + if(map->defy[vv]->handler->alphaTransformed) + continue; + for(int yy=0; yydefy[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: "<map.players[CGI->scenarioOps.playerInfos[i].color].allowedFactions & 1<players[CGI->scenarioOps.playerInfos[i].color].allowedFactions & 1<scenarioOps.playerInfos[i].castle = f; } } for(int i=0;imap.players[i].heroesNames.size();j++) + for(int j=0; jplayers[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: "<map.defy.size(); ++h) //initializing loaded def handler's info + for(int h=0; hdefy.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: "<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;jscenarioOps.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: "<((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=0 && by+y>=0 && bx+xmh->reader->map.width && by+ymh->reader->map.height && !visibilityMap[bx+x][by+y][level]) + if(bx+x>=0 && by+y>=0 && bx+xmh->map->width && by+ymh->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; byreader->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.ymh->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.xmh->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.ymh->map->height) + ret = hero->type->heroClass->terrCosts[CGI->mh->ttiles[CGI->mh->map->width-1][a.y][a.z].malle]; + else if(a.xmh->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::iterator db = std::find(CGI->objh->objInstances.begin(), CGI->objh->objInstances.end(), obj); + std::vector::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 loadedTypes; - for (int i=0; imap.width; i++) + for (int i=0; iwidth; i++) { - for (int j=0; jmap.width; j++) + for (int j=0; jwidth; 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); } } diff --git a/mapHandler.h b/mapHandler.h index c0aeb7547..013e9a700 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -60,7 +60,7 @@ class CMapHandler public: PseudoV< PseudoV< PseudoV > > ttiles; int3 sizes; - CAmbarCendamo * reader; + Mapa * map; std::set usedHeroes; CDefHandler * fullHide; CDefHandler * partialHide;