1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-07-17 01:32:21 +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 void startBattle(int heroID, CCreatureSet * army, int3 tile); //for hero<=>neutral army
//friends //friends
friend void initGameState(CGameInfo * cgi); friend void initGameState(Mapa * map, CGameInfo * cgi);
}; };
class CLuaCallback : public CScriptCallback class CLuaCallback : public CScriptCallback
{ {
@ -179,6 +179,6 @@ private:
static int getGnrlText(lua_State * L);//(int ID, int which, int val); static int getGnrlText(lua_State * L);//(int ID, int which, int val);
static int getSelectedHero(lua_State * L);//() static int getSelectedHero(lua_State * L);//()
friend void initGameState(CGameInfo * cgi); friend void initGameState(Mapa * map, CGameInfo * cgi);
}; };
#endif //CCALLBACK_H #endif //CCALLBACK_H

View File

@ -64,20 +64,20 @@ int internalFunc(void * callback)
vector<Coordinate>* p; vector<Coordinate>* p;
switch (*cn.c_str()) switch (*cn.c_str())
{ {
case 'P': //case 'P':
std::cout<<"Policzyc sciezke."<<std::endl; // std::cout<<"Policzyc sciezke."<<std::endl;
readed>>src>>dst; // readed>>src>>dst;
//
p = CGI->pathf->GetPath(Coordinate(src),Coordinate(dst),CGI->heroh->heroInstances[0]); // 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->ConvertToOldFormat(p);
//LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]); //LOCPLINT->adventureInt->terrain.currentPath = CGI->pathf->getPath(src,dst,CGI->heroh->heroInstances[0]);
break; //break;
case 'm': //number of heroes 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; break;
case 'H': //position of hero case 'H': //position of hero
readed>>heronum; 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; break;
case 'M': //move heroa case 'M': //move heroa
{ {
@ -117,15 +117,15 @@ int internalFunc(void * callback)
} }
break; break;
case 'A': //hide everything from map 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; break;
case 'R': //restora all objects after A has been pressed 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; break;
} }

View File

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

View File

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

View File

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

21
CLua.h
View File

@ -11,6 +11,7 @@ class CGHeroInstance;
class CScriptCallback; class CScriptCallback;
class SComponent; class SComponent;
class CSelectableComponent; class CSelectableComponent;
struct Mapa;
enum ESLan{UNDEF=-1,CPP,ERM,LUA}; enum ESLan{UNDEF=-1,CPP,ERM,LUA};
class CObjectScript class CObjectScript
{ {
@ -69,7 +70,7 @@ public:
void findFS(std::string fname); void findFS(std::string fname);
friend void initGameState(CGameInfo * cgi); friend void initGameState(Mapa * map, CGameInfo * cgi);
}; };
class CLuaObjectScript : public CLua, public CObjectScript class CLuaObjectScript : public CLua, public CObjectScript
@ -84,7 +85,7 @@ public:
void onHeroVisit(CGObjectInstance *os, int heroID); void onHeroVisit(CGObjectInstance *os, int heroID);
std::string hoverText(CGObjectInstance *os); std::string hoverText(CGObjectInstance *os);
friend void initGameState(CGameInfo * cgi); friend void initGameState(Mapa * map, CGameInfo * cgi);
}; };
class CCPPObjectScript: public CObjectScript 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::vector<int> yourObjects(); //returns IDs of objects which are handled by script
std::string hoverText(CGObjectInstance *os); std::string hoverText(CGObjectInstance *os);
friend void initGameState(CGameInfo * cgi); friend void initGameState(Mapa * map, CGameInfo * cgi);
}; };
class CVisitableOPW : public CCPPObjectScript //once per week class CVisitableOPW : public CCPPObjectScript //once per week
@ -120,7 +121,7 @@ class CVisitableOPW : public CCPPObjectScript //once per week
std::string hoverText(CGObjectInstance *os); std::string hoverText(CGObjectInstance *os);
void newTurn (); 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 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); std::string hoverText(CGObjectInstance *os);
void newTurn (); void newTurn ();
friend void initGameState(CGameInfo * cgi); friend void initGameState(Mapa * map, CGameInfo * cgi);
}; };
class CPickable : public CCPPObjectScript, public IChosen //pickable - resources, artifacts, etc 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::string hoverText(CGObjectInstance *os);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script 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 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::string hoverText(CGObjectInstance *os);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script 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 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::vector<int> yourObjects(); //returns IDs of objects which are handled by script
std::string hoverText(CGObjectInstance *os); std::string hoverText(CGObjectInstance *os);
friend void initGameState(CGameInfo * cgi); friend void initGameState(Mapa * map, CGameInfo * cgi);
}; };
class CMonsterS : public CCPPObjectScript class CMonsterS : public CCPPObjectScript
@ -185,7 +186,7 @@ class CMonsterS : public CCPPObjectScript
void onHeroVisit(CGObjectInstance *os, int heroID); void onHeroVisit(CGObjectInstance *os, int heroID);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script 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 class CCreatureGen : public CCPPObjectScript
@ -197,5 +198,5 @@ class CCreatureGen : public CCPPObjectScript
void onHeroVisit(CGObjectInstance *os, int heroID); void onHeroVisit(CGObjectInstance *os, int heroID);
std::vector<int> yourObjects(); //returns IDs of objects which are handled by script 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; CGameInfo* CGI;
#endif #endif
#define CHUNK 16384 #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 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); CGI->state->cppscripts.insert(script);
} }
void initGameState(CGameInfo * cgi) void initGameState(Mapa * map, CGameInfo * cgi)
{ {
cgi->state->day=0; cgi->state->day=0;
/*********creating players entries in gs****************************************/ /*********creating players entries in gs****************************************/
@ -115,14 +115,14 @@ void initGameState(CGameInfo * cgi)
} }
/*************************HEROES************************************************/ /*************************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; continue;
//CGHeroInstance * vhi = new CGHeroInstance(); CGHeroInstance * vhi = (map->heroes[i]);
//*vhi=*(cgi->heroh->heroInstances[i]); if(!vhi->type)
CGHeroInstance * vhi = (cgi->heroh->heroInstances[i]); vhi->type = cgi->heroh->heroes[vhi->subID];
vhi->subID = vhi->type->ID; //vhi->subID = vhi->type->ID;
if (vhi->level<1) if (vhi->level<1)
{ {
vhi->exp=40+rand()%50; vhi->exp=40+rand()%50;
@ -137,8 +137,8 @@ void initGameState(CGameInfo * cgi)
vhi->primSkills[1] = vhi->type->heroClass->initialDefence; vhi->primSkills[1] = vhi->type->heroClass->initialDefence;
vhi->primSkills[2] = vhi->type->heroClass->initialPower; vhi->primSkills[2] = vhi->type->heroClass->initialPower;
vhi->primSkills[3] = vhi->type->heroClass->initialKnowledge; vhi->primSkills[3] = vhi->type->heroClass->initialKnowledge;
vhi->mana = vhi->primSkills[3]*10;
} }
vhi->mana = vhi->primSkills[3]*10;
if (!vhi->name.length()) if (!vhi->name.length())
{ {
vhi->name = vhi->type->name; vhi->name = vhi->type->name;
@ -186,21 +186,21 @@ void initGameState(CGameInfo * cgi)
/*************************FOG**OF**WAR******************************************/ /*************************FOG**OF**WAR******************************************/
for(std::map<int, PlayerState>::iterator k=cgi->state->players.begin(); k!=cgi->state->players.end(); ++k) 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); k->second.fogOfWarMap.resize(map->width, Woff);
for(int g=-Woff; g<cgi->ac->map.width+Woff; ++g) for(int g=-Woff; g<map->width+Woff; ++g)
k->second.fogOfWarMap[g].resize(cgi->ac->map.height, Hoff); k->second.fogOfWarMap[g].resize(map->height, Hoff);
for(int g=-Woff; g<cgi->ac->map.width+Woff; ++g) for(int g=-Woff; g<map->width+Woff; ++g)
for(int h=-Hoff; h<cgi->ac->map.height+Hoff; ++h) for(int h=-Hoff; h<map->height+Hoff; ++h)
k->second.fogOfWarMap[g][h].resize(cgi->ac->map.twoLevel+1, 0); k->second.fogOfWarMap[g][h].resize(map->twoLevel+1, 0);
for(int g=-Woff; g<cgi->ac->map.width+Woff; ++g) for(int g=-Woff; g<map->width+Woff; ++g)
for(int h=-Hoff; h<cgi->ac->map.height+Hoff; ++h) for(int h=-Hoff; h<map->height+Hoff; ++h)
for(int v=0; v<cgi->ac->map.twoLevel+1; ++v) for(int v=0; v<map->twoLevel+1; ++v)
k->second.fogOfWarMap[g][h][v] = 0; 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) for(int ch=0; ch<k->second.heroes.size(); ++ch)
{ {
@ -213,16 +213,20 @@ void initGameState(CGameInfo * cgi)
} }
} }
/****************************TOWNS************************************************/ /****************************TOWNS************************************************/
for (int i=0;i<cgi->townh->townInstances.size();i++) for (int i=0;i<map->towns.size();i++)
{ {
//CGTownInstance * vti = new CGTownInstance(); CGTownInstance * vti =(map->towns[i]);
//(*vti)=*(cgi->townh->townInstances[i]);
CGTownInstance * vti =(cgi->townh->townInstances[i]);
//vti->creatureIncome.resize(CREATURES_PER_TOWN);
//vti->creaturesLeft.resize(CREATURES_PER_TOWN);
if (vti->name.length()==0) // if town hasn't name we draw it if (vti->name.length()==0) // if town hasn't name we draw it
vti->name=vti->town->names[rand()%vti->town->names.size()]; 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); cgi->state->players[vti->getOwner()].towns.push_back(vti);
} }
@ -230,9 +234,9 @@ void initGameState(CGameInfo * cgi)
{ {
if(k->first==-1 || k->first==255) if(k->first==-1 || k->first==255)
continue; 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) for(int ch=0; ch<k->second.towns.size(); ++ch)
{ {
@ -300,22 +304,22 @@ void initGameState(CGameInfo * cgi)
} }
/****************************INITIALIZING OBJECT SCRIPTS************************************************/ /****************************INITIALIZING OBJECT SCRIPTS************************************************/
std::string temps("newObject"); 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 //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]; map->objects[i]->state = scripts[map->objects[i]->ID];
CGI->objh->objInstances[i]->state->newObject(CGI->objh->objInstances[i]); map->objects[i]->state->newObject(map->objects[i]);
} }
else else
{ {
CGI->objh->objInstances[i]->state = NULL; map->objects[i]->state = NULL;
} }
// lua scripts // lua scripts
if(cgi->state->checkFunc(CGI->objh->objInstances[i]->ID,temps)) if(cgi->state->checkFunc(map->objects[i]->ID,temps))
(*skrypty)[CGI->objh->objInstances[i]->ID][temps]->newObject(CGI->objh->objInstances[i]); (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]);
} }
delete lf; delete lf;
@ -856,14 +860,14 @@ int _tmain(int argc, _TCHAR* argv[])
THC std::cout<<"Detecting file (together): "<<tmh.getDif()<<std::endl; THC std::cout<<"Detecting file (together): "<<tmh.getDif()<<std::endl;
CMapHandler * mh = new CMapHandler(); CMapHandler * mh = new CMapHandler();
cgi->mh = mh; cgi->mh = mh;
mh->reader = ac; mh->map = &ac->map;
THC std::cout<<"Creating mapHandler: "<<tmh.getDif()<<std::endl; THC std::cout<<"Creating mapHandler: "<<tmh.getDif()<<std::endl;
mh->loadDefs(); mh->loadDefs();
THC std::cout<<"Reading terrain defs: "<<tmh.getDif()<<std::endl; THC std::cout<<"Reading terrain defs: "<<tmh.getDif()<<std::endl;
mh->init(); mh->init();
THC std::cout<<"Initializing mapHandler (together): "<<tmh.getDif()<<std::endl; 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; THC std::cout<<"Initializing GameState (together): "<<tmh.getDif()<<std::endl;
/*for(int d=0; d<PLAYER_LIMIT; ++d) /*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, int mw = mm.map[0]->w, mh = mm.map[0]->h,
wo = mw/CGI->mh->sizes.x, ho = mh/CGI->mh->sizes.y; 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); 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 ret=-1;
int x = node->x; int x = node->x;
int y = node->y; int y = node->y;
if(node->x>=CGI->mh->reader->map.width) if(node->x>=CGI->mh->map->width)
x = CGI->mh->reader->map.width-1; x = CGI->mh->map->width-1;
if(node->y>=CGI->mh->reader->map.height) if(node->y>=CGI->mh->map->height)
y = CGI->mh->reader->map.height-1; y = CGI->mh->map->height-1;
//Get the movement cost. //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; node->h = ret;
} }

View File

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

View File

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

View File

@ -4,9 +4,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "../global.h" #include "../global.h"
#include "SDL.h"
#include "../map.h" #include "../map.h"
#include "CDefHandler.h"
#include "CCreatureHandler.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}; 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 "../SDL_Extensions.h"
#include <cmath> #include <cmath>
#include <iomanip> #include <iomanip>
#include "CDefHandler.h"
CHeroHandler::~CHeroHandler() CHeroHandler::~CHeroHandler()
{ {
for (int j=0;j<heroes.size();j++) for (int j=0;j<heroes.size();j++)

View File

@ -46,7 +46,6 @@ public:
class CHeroHandler class CHeroHandler
{ {
public: public:
std::vector<CGHeroInstance *> heroInstances;
std::vector<CHero*> heroes; //by�o nodrze std::vector<CHero*> heroes; //by�o nodrze
std::vector<CHeroClass *> heroClasses; std::vector<CHeroClass *> heroClasses;
std::vector<CDefHandler *> flags1, flags2, flags3, flags4; //flags blitted on heroes when , 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) const CArtifact * CGHeroInstance::getArt(int pos)
{ {
if(artifWorn.find(pos)!=artifWorn.end())
return &CGI->arth->artifacts[artifWorn[pos]]; return &CGI->arth->artifacts[artifWorn[pos]];
else
return NULL;
} }
int CGTownInstance::getSightDistance() const //returns sight distance int CGTownInstance::getSightDistance() const //returns sight distance
@ -355,6 +358,7 @@ CGHeroInstance::CGHeroInstance()
moveDir = 4; moveDir = 4;
mana = 0; mana = 0;
visitedTown = NULL; visitedTown = NULL;
type = NULL;
} }
CGHeroInstance::~CGHeroInstance() CGHeroInstance::~CGHeroInstance()

View File

@ -48,30 +48,25 @@ public:
bool humanActivate; //true if human player can activate this event bool humanActivate; //true if human player can activate this event
}; };
//class CHeroObjInfo : public CSpecObjInfo class CCastleEvent
//{ {
//public: public:
// unsigned char bytes[4]; //mysterius bytes identifying hero in a strange way std::string name, message;
// int player; int wood, mercury, ore, sulfur, crystal, gems, gold; //gain / loss of resources
// CHero * type; unsigned char players; //players for whom this event can be applied
// std::string name; //if nonstandard bool forHuman, forComputer;
// bool standardGarrison; //true if hero has standard garrison int firstShow; //postpone of first encounter time in days
// CCreatureSet garrison; //hero's army int forEvery; //every n days this event will occure
// 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 unsigned char bytes[6]; //build specific buildings (raw format, similar to town's)
// 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 gen[7]; //additional creatures in i-th level dwelling
// int guardRange; //range of hero's guard
// std::string biography; //if nonstandard bool operator<(const CCastleEvent &drugie) const
// bool sex; //if true, reverse hero's sex {
// std::vector<int> spells; //hero's spells return firstShow<drugie.firstShow;
// 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 CCreatureObjInfo : public CSpecObjInfo class CCreatureObjInfo : public CSpecObjInfo
{ {
@ -106,7 +101,7 @@ public:
std::vector<CCreature *> m6cre;//for mission 6 std::vector<CCreature *> m6cre;//for mission 6
std::vector<int> m6number; std::vector<int> m6number;
int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; //for mission 7 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 int m9player; //for mission 9 - number; from 0 to 7
std::string firstVisitText, nextVisitText, completedText; std::string firstVisitText, nextVisitText, completedText;
@ -276,7 +271,7 @@ public:
//for mission 7 //for mission 7
int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold; int m7wood, m7mercury, m7ore, m7sulfur, m7crystal, m7gems, m7gold;
//for mission 8 //for mission 8
CHero * m8hero; int m8hero; //hero id
//for mission 9 //for mission 9
int m9player; //number; from 0 to 7 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) 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 movement; //remaining movement points
int identifier; //from the map file int identifier; //from the map file
int patrolRadious; //-1 - no patrol
bool sex; bool sex;
struct Patrol
{
Patrol(){patrolling=false;patrolRadious=-1;};
bool patrolling;
int patrolRadious;
} patrol;
bool inTownGarrison; // if hero is in town garrison bool inTownGarrison; // if hero is in town garrison
CGTownInstance * visitedTown; //set if hero is visiting town or in the 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 std::string name; // name of town
int builded; //how many buildings has been built this turn int builded; //how many buildings has been built this turn
int destroyed; //how many buildings has been destroyed 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 identifier; //special identifier from h3m (only > RoE maps)
int alignment; int alignment;
std::set<int> forbiddenBuildings, builtBuildings;
std::vector<int> possibleSpells, obligatorySpells, availableSpells;
struct StrInfo struct StrInfo
{ {
std::map<int,int> creatures; //level - available amount std::map<int,int> creatures; //level - available amount
} strInfo; } 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 getSightDistance() const; //returns sight distance
int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle
int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol
bool creatureDwelling(const int & level, bool upgraded=false) const; 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 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; int creatureGrowth(const int & level) const;
bool hasFort() const; bool hasFort() const;
bool hasCapitol() const; bool hasCapitol() const;
int dailyIncome() const; int dailyIncome() const;
@ -414,7 +412,6 @@ class CObjectHandler
{ {
public: public:
std::vector<CObject> objects; //vector of objects; i-th object in vector has subnumber i 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 std::vector<int> cregens; //type 17. dwelling subid -> creature ID
void loadObjects(); 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, 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::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 #endif //CTOWNHANDLER_H

17
map.h
View File

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

View File

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

View File

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