diff --git a/AdventureMapButton.cpp b/AdventureMapButton.cpp index d101ee468..745e68046 100644 --- a/AdventureMapButton.cpp +++ b/AdventureMapButton.cpp @@ -7,6 +7,7 @@ #include "hch/CTownHandler.h" #include "CLua.h" #include "CCallback.h" +#include "client/Graphics.h" AdventureMapButton::AdventureMapButton () { type=2; @@ -38,7 +39,7 @@ AdventureMapButton::AdventureMapButton imgs.resize(1); imgs[0].push_back(temp->ourImages[i].bitmap); if(playerColoredButton) - CSDL_Ext::blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID); + graphics->blueToPlayersAdv(imgs[curimg][i],LOCPLINT->playerID); } delete temp; if (add) @@ -52,7 +53,7 @@ AdventureMapButton::AdventureMapButton { imgs[i+1].push_back(temp->ourImages[j].bitmap); if(playerColoredButton) - CSDL_Ext::blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID); + graphics->blueToPlayersAdv(imgs[1+i][j],LOCPLINT->playerID); } delete temp; } diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index c87e5b403..e11e9db64 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -113,7 +113,7 @@ void CMinimap::draw() { for (int jj=0; jjplayerColors[hh[i]->getOwner()].r,CGI->playerColors[hh[i]->getOwner()].g,CGI->playerColors[hh[i]->getOwner()].b); + SDL_PutPixel(temps,maplgp.x+ii,maplgp.y+jj,graphics->playerColors[hh[i]->getOwner()].r,graphics->playerColors[hh[i]->getOwner()].g,graphics->playerColors[hh[i]->getOwner()].b); } } } @@ -600,7 +600,7 @@ CResDataBar::CResDataBar() //SDL_Color p1={40,65,139,255}, p2={36,59,125,255}, p3={35,56,121,255}; //kolory+=p1,p2,p3; //blueToPlayersAdv(bg,LOCPLINT->playerID,2,&kolory); - blueToPlayersAdv(bg,LOCPLINT->playerID,2); + graphics->blueToPlayersAdv(bg,LOCPLINT->playerID); pos = genRect(bg->h,bg->w,3,575); txtpos += (std::pair(35,577)),(std::pair(120,577)),(std::pair(205,577)), @@ -851,7 +851,7 @@ townList(5,&genRect(192,48,747,196),747,196,747,372) townList.fun = boost::bind(&CAdvMapInt::selectionChanged,this); LOCPLINT->adventureInt=this; bg = BitmapHandler::loadBitmap("ADVMAP.bmp"); - blueToPlayersAdv(bg,player); + graphics->blueToPlayersAdv(bg,player); scrollingLeft = false; scrollingRight = false; scrollingUp = false ; diff --git a/CBattleInterface.cpp b/CBattleInterface.cpp index 43c9464e7..fba75b2b4 100644 --- a/CBattleInterface.cpp +++ b/CBattleInterface.cpp @@ -10,6 +10,7 @@ #include "CGameState.h" #include "hch\CGeneralTextHandler.h" #include "client/CCreatureAnimation.h" +#include "client/Graphics.h" #include #include @@ -37,7 +38,7 @@ CBattleInterface::CBattleInterface(CCreatureSet * army1, CCreatureSet * army2, C std::vector< std::string > & backref = CGI->mh->battleBacks[ LOCPLINT->cb->battleGetBattlefieldType() ]; background = BitmapHandler::loadBitmap(backref[ rand() % backref.size()] ); menu = BitmapHandler::loadBitmap("CBAR.BMP"); - CSDL_Ext::blueToPlayersAdv(menu, hero1->tempOwner); + graphics->blueToPlayersAdv(menu, hero1->tempOwner); //preparing graphics for displaying amounts of creatures amountBasic = BitmapHandler::loadBitmap("CMNUMWIN.BMP"); @@ -949,7 +950,7 @@ CBattleHero::CBattleHero(std::string defName, int phaseG, int imageG, bool flipG for(int i=0; iourImages.size(); ++i) { flag->ourImages[i].bitmap = CSDL_Ext::alphaTransform(flag->ourImages[i].bitmap); - CSDL_Ext::blueToPlayersAdv(flag->ourImages[i].bitmap, player); + graphics->blueToPlayersAdv(flag->ourImages[i].bitmap, player); } } diff --git a/CCallback.cpp b/CCallback.cpp index 86ab8b2c5..4a6213278 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -364,6 +364,11 @@ UpgradeInfo CCallback::getUpgradeInfo(const CArmedInstance *obj, int stackPos) return ret; } +const StartInfo * CCallback::getStartInfo() +{ + return gs->scenarioOps; +} + int CCallback::howManyTowns() { return gs->players[gs->currentPlayer].towns.size(); @@ -484,7 +489,7 @@ std::vector < std::string > CCallback::getObjDescriptions(int3 pos) else return std::vector< std::string > (); } -PseudoV< PseudoV< PseudoV > > & CCallback::getVisibilityMap() +std::vector< std::vector< std::vector > > & CCallback::getVisibilityMap() { return gs->players[player].fogOfWarMap; } @@ -844,7 +849,7 @@ int3 CScriptCallback::getPos(CGObjectInstance * ob) } void CScriptCallback::changePrimSkill(int ID, int which, int val) { - CGHeroInstance * hero = CGI->state->getHero(ID,0); + CGHeroInstance * hero = CGI->state->map->getHero(ID,0); if (whichprimSkills[which]+=val; @@ -884,7 +889,7 @@ void CScriptCallback::changePrimSkill(int ID, int which, int val) int CScriptCallback::getHeroOwner(int heroID) { - CGHeroInstance * hero = CGI->state->getHero(heroID,0); + CGHeroInstance * hero = CGI->state->map->getHero(heroID,0); return hero->getOwner(); } void CScriptCallback::showInfoDialog(int player, std::string text, std::vector * components) @@ -966,13 +971,13 @@ void CScriptCallback::heroVisitCastle(CGObjectInstance * ob, int heroID) CGTownInstance * n; if(n = dynamic_cast(ob)) { - n->visitingHero = CGI->state->getHero(heroID,0); - CGI->state->getHero(heroID,0)->visitedTown = n; + n->visitingHero = CGI->state->map->getHero(heroID,0); + CGI->state->map->getHero(heroID,0)->visitedTown = n; for(int b=0; bplayerint.size(); ++b) { if(CGI->playerint[b]->playerID == getHeroOwner(heroID)) { - CGI->playerint[b]->heroVisitsTown(CGI->state->getHero(heroID,0),n); + CGI->playerint[b]->heroVisitsTown(CGI->state->map->getHero(heroID,0),n); break; } } @@ -986,7 +991,7 @@ void CScriptCallback::stopHeroVisitCastle(CGObjectInstance * ob, int heroID) CGTownInstance * n; if(n = dynamic_cast(ob)) { - CGI->state->getHero(heroID,0)->visitedTown = NULL; + CGI->state->map->getHero(heroID,0)->visitedTown = NULL; if(n->visitingHero && n->visitingHero->type->ID == heroID) n->visitingHero = NULL; return; @@ -996,7 +1001,7 @@ void CScriptCallback::stopHeroVisitCastle(CGObjectInstance * ob, int heroID) } void CScriptCallback::giveHeroArtifact(int artid, int hid, int position) //pos==-1 - first free slot in backpack { - CGHeroInstance* h = gs->getHero(hid,0); + CGHeroInstance* h = gs->map->getHero(hid,0); if(position<0) { for(int i=0;iartifacts.size();i++) @@ -1026,7 +1031,7 @@ void CScriptCallback::startBattle(CCreatureSet * army1, CCreatureSet * army2, in } void CScriptCallback::startBattle(int heroID, CCreatureSet * army, int3 tile) //for hero<=>neutral army { - CGHeroInstance* h = gs->getHero(heroID,0); + CGHeroInstance* h = gs->map->getHero(heroID,0); gs->battle(&h->army,army,tile,h,NULL); } void CLuaCallback::registerFuncs(lua_State * L) diff --git a/CCallback.h b/CCallback.h index 07a8c6a69..be5f7ac6d 100644 --- a/CCallback.h +++ b/CCallback.h @@ -40,7 +40,7 @@ public: //get info virtual bool verifyPath(CPath * path, bool blockSea)=0; virtual int getDate(int mode=0)=0; //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month - virtual PseudoV< PseudoV< PseudoV > > & getVisibilityMap()=0; //returns visibility map (TODO: make it const) + virtual std::vector< std::vector< std::vector > > & getVisibilityMap()=0; //returns visibility map (TODO: make it const) virtual const CGHeroInstance * getHeroInfo(int player, int val, bool mode)=0; //mode = 0 -> val = serial; mode = 1 -> val = ID virtual int getResourceAmount(int type)=0; virtual int howManyHeroes()=0; @@ -54,6 +54,7 @@ public: virtual int getHeroSerial(const CGHeroInstance * hero)=0; virtual const CCreatureSet* getGarrison(const CGObjectInstance *obj)=0; virtual UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos)=0; + virtual const StartInfo * getStartInfo()=0; //battle virtual int battleGetBattlefieldType()=0; // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship @@ -110,7 +111,7 @@ public: //get info bool verifyPath(CPath * path, bool blockSea); int getDate(int mode=0); //mode=0 - total days in game, mode=1 - day of week, mode=2 - current week, mode=3 - current month - PseudoV< PseudoV< PseudoV > > & getVisibilityMap(); //returns visibility map (TODO: make it const) + std::vector< std::vector< std::vector > > & getVisibilityMap(); //returns visibility map (TODO: make it const) const CGHeroInstance * getHeroInfo(int player, int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID int getResourceAmount(int type); std::vector getResourceAmount(); @@ -126,6 +127,7 @@ public: int getMySerial(); const CCreatureSet* getGarrison(const CGObjectInstance *obj); UpgradeInfo getUpgradeInfo(const CArmedInstance *obj, int stackPos); + virtual const StartInfo * getStartInfo(); //battle int battleGetBattlefieldType(); // 1. sand/shore 2. sand/mesas 3. dirt/birches 4. dirt/hills 5. dirt/pines 6. grass/hills 7. grass/pines 8. lava 9. magic plains 10. snow/mountains 11. snow/trees 12. subterranean 13. swamp/trees 14. fiery fields 15. rock lands 16. magic clouds 17. lucid pools 18. holy ground 19. clover field 20. evil fog 21. "favourable winds" text on magic plains background 22. cursed ground 23. rough 24. ship to ship 25. ship @@ -169,7 +171,7 @@ public: void startBattle(int heroID, CCreatureSet * army, int3 tile); //for hero<=>neutral army //friends - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CLuaCallback : public CScriptCallback { @@ -181,6 +183,6 @@ private: static int getGnrlText(lua_State * L);//(int ID, int which, int val); static int getSelectedHero(lua_State * L);//() - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; #endif //CCALLBACK_H \ No newline at end of file diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index 6484595ea..3478adc20 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -235,7 +235,7 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate) if((townlist->selected+1) > townlist->SIZE) townlist->from = townlist->selected - townlist->SIZE + 2; - CSDL_Ext::blueToPlayersAdv(townInt,LOCPLINT->playerID); + graphics->blueToPlayersAdv(townInt,LOCPLINT->playerID); exit->bitmapOffset = 4; @@ -660,7 +660,7 @@ CHallInterface::CResDataBar::CResDataBar() { bg = BitmapHandler::loadBitmap("Z2ESBAR.bmp"); SDL_SetColorKey(bg,SDL_SRCCOLORKEY,SDL_MapRGB(bg->format,0,255,255)); - CSDL_Ext::blueToPlayersAdv(bg,LOCPLINT->playerID); + graphics->blueToPlayersAdv(bg,LOCPLINT->playerID); pos.x = 7; pos.y = 575; pos.w = bg->w; @@ -770,7 +770,7 @@ CHallInterface::CBuildingBox::CBuildingBox(int id, int x, int y) CHallInterface::CHallInterface(CCastleInterface * owner) { bg = BitmapHandler::loadBitmap(CGI->buildh->hall[owner->town->subID].first); - CSDL_Ext::blueToPlayersAdv(bg,LOCPLINT->playerID); + graphics->blueToPlayersAdv(bg,LOCPLINT->playerID); bars = CDefHandler::giveDefEss("TPTHBAR.DEF"); status = CDefHandler::giveDefEss("TPTHCHK.DEF"); exit = new AdventureMapButton @@ -1014,7 +1014,7 @@ CHallInterface::CBuildWindow::CBuildWindow(int Tid, int Bid, int State, bool Mod SDL_FreeSurface(hhlp); pos.x = screen->w/2 - bitmap->w/2; pos.y = screen->h/2 - bitmap->h/2; - CSDL_Ext::blueToPlayersAdv(bitmap,LOCPLINT->playerID); + graphics->blueToPlayersAdv(bitmap,LOCPLINT->playerID); blitAt(LOCPLINT->castleInt->bicons->ourImages[bid].bitmap,125,50,bitmap); std::vector pom; pom.push_back(CGI->buildh->buildings[tid][bid]->name); CSDL_Ext::printAtMiddleWB(CGI->buildh->buildings[tid][bid]->description,197,168,GEOR16,40,zwykly,bitmap); diff --git a/CConsoleHandler.cpp b/CConsoleHandler.cpp index f532e872b..14292e4be 100644 --- a/CConsoleHandler.cpp +++ b/CConsoleHandler.cpp @@ -142,7 +142,7 @@ int internalFunc(void * callback) // break; } //SDL_Delay(100); - delete p; + //delete p; } } return -1; diff --git a/CGameInfo.h b/CGameInfo.h index 0e0570427..d8bd87704 100644 --- a/CGameInfo.h +++ b/CGameInfo.h @@ -62,9 +62,6 @@ public: CScreenHandler * screenh; int localPlayer; std::vector playerint; - std::vector playerColors; - SDL_Color neutralColor; - StartInfo scenarioOps; }; #endif //CGAMEINFO_H \ No newline at end of file diff --git a/CGameState.cpp b/CGameState.cpp index 9488b39f4..e50a069a3 100644 --- a/CGameState.cpp +++ b/CGameState.cpp @@ -1,13 +1,28 @@ +#define VCMI_DLL +#include +#include +#include #include "CGameState.h" #include "CGameInterface.h" #include "CPlayerInterface.h" -#include -#include "SDL_Thread.h" #include "SDL_Extensions.h" #include "CBattleInterface.h" //for CBattleHex -#include +#include +#include "hch/CDefObjInfoHandler.h" +#include "hch/CArtHandler.h" +#include "hch/CTownHandler.h" +#include "hch/CHeroHandler.h" +#include "hch/CObjectHandler.h" +#include "hch/CCreatureHandler.h" +#include "lib/VCMI_Lib.h" +#include "map.h" +#include "StartInfo.h" +#include "CLua.h" +#include "CCallback.h" +#include "CLuaHandler.h" +boost::rand48 ran; class CMP_stack { public: @@ -17,8 +32,509 @@ public: } } cmpst ; -void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2) +CStack::CStack(CCreature * C, int A, int O, int I, bool AO) + :creature(C),amount(A),owner(O), alive(true), position(-1), ID(I), attackerOwned(AO), firstHPleft(C->hitPoints) { +} +int CGameState::pickHero(int owner) +{ + int h=-1; + if(map->getHero(h = scenarioOps->getIthPlayersSettings(owner).hero,0) && h>=0) //we haven't used selected hero + return h; + int f = scenarioOps->getIthPlayersSettings(owner).castle; + int i=0; + do //try to find free hero of our faction + { + i++; + h = scenarioOps->getIthPlayersSettings(owner).castle*HEROES_PER_TYPE*2+(ran()%(HEROES_PER_TYPE*2));//->scenarioOps->playerInfos[pru].hero = VLC-> + } while( map->getHero(h) && i<175); + if(i>174) //probably no free heroes - there's no point in further search, we'll take first free + { + std::cout << "Warning: cannot find free hero - trying to get first available..."<getHero(j)) + h=j; + } + return h; +} +std::pair CGameState::pickObject(CGObjectInstance *obj) +{ + switch(obj->ID) + { + case 65: //random artifact + return std::pair(5,(ran()%136)+7); //tylko sensowny zakres - na poczatku sa katapulty itp, na koncu specjalne i blanki + case 66: //random treasure artifact + return std::pair(5,VLC->arth->treasures[ran()%VLC->arth->treasures.size()]->id); + case 67: //random minor artifact + return std::pair(5,VLC->arth->minors[ran()%VLC->arth->minors.size()]->id); + case 68: //random major artifact + return std::pair(5,VLC->arth->majors[ran()%VLC->arth->majors.size()]->id); + case 69: //random relic artifact + return std::pair(5,VLC->arth->relics[ran()%VLC->arth->relics.size()]->id); + case 70: //random hero + { + return std::pair(34,pickHero(obj->tempOwner)); + } + case 71: //random monster + return std::pair(54,ran()%(VLC->creh->creatures.size())); + case 72: //random monster lvl1 + return std::pair(54,VLC->creh->levelCreatures[1][ran()%VLC->creh->levelCreatures[1].size()]->idNumber); + case 73: //random monster lvl2 + return std::pair(54,VLC->creh->levelCreatures[2][ran()%VLC->creh->levelCreatures[2].size()]->idNumber); + case 74: //random monster lvl3 + return std::pair(54,VLC->creh->levelCreatures[3][ran()%VLC->creh->levelCreatures[3].size()]->idNumber); + case 75: //random monster lvl4 + return std::pair(54,VLC->creh->levelCreatures[4][ran()%VLC->creh->levelCreatures[4].size()]->idNumber); + case 76: //random resource + return std::pair(79,ran()%7); //now it's OH3 style, use %8 for mithril + case 77: //random town + { + int align = ((CGTownInstance*)obj)->alignment, + f; + if(align>PLAYER_LIMIT-1)//same as owner / random + { + if(obj->tempOwner > PLAYER_LIMIT-1) + f = -1; //random + else + f = scenarioOps->getIthPlayersSettings(obj->tempOwner).castle; + } + else + { + f = scenarioOps->getIthPlayersSettings(align).castle; + } + if(f<0) f = ran()%VLC->townh->towns.size(); + return std::pair(98,f); + } + case 162: //random monster lvl5 + return std::pair(54,VLC->creh->levelCreatures[5][ran()%VLC->creh->levelCreatures[5].size()]->idNumber); + case 163: //random monster lvl6 + return std::pair(54,VLC->creh->levelCreatures[6][ran()%VLC->creh->levelCreatures[6].size()]->idNumber); + case 164: //random monster lvl7 + return std::pair(54,VLC->creh->levelCreatures[7][ran()%VLC->creh->levelCreatures[7].size()]->idNumber); + case 216: //random dwelling + { + int faction = ran()%F_NUMBER; + CCreGen2ObjInfo* info =(CCreGen2ObjInfo*)obj->info; + if (info->asCastle) + { + for(int i=0;iobjects.size();i++) + { + if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i])->identifier == info->identifier) + { + randomizeObject(map->objects[i]); //we have to randomize the castle first + faction = map->objects[i]->subID; + break; + } + else if(map->objects[i]->ID==98 && dynamic_cast(map->objects[i])->identifier == info->identifier) + { + faction = map->objects[i]->subID; + break; + } + } + } + else + { + while((!(info->castles[0]&(1<7) && (info->castles[1]&(1<<(faction-8)))) + break; + faction = ran()%F_NUMBER; + } + } + int level = ((info->maxLevel-info->minLevel) ? (ran()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel)); + int cid = VLC->townh->towns[faction].basicCreatures[level]; + for(int i=0;iobjh->cregens.size();i++) + if(VLC->objh->cregens[i]==cid) + return std::pair(17,i); + std::cout << "Cannot find a dwelling for creature "<(17,0); + } + case 217: + { + int faction = ran()%F_NUMBER; + CCreGenObjInfo* info =(CCreGenObjInfo*)obj->info; + if (info->asCastle) + { + for(int i=0;iobjects.size();i++) + { + if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i])->identifier == info->identifier) + { + randomizeObject(map->objects[i]); //we have to randomize the castle first + faction = map->objects[i]->subID; + break; + } + else if(map->objects[i]->ID==98 && dynamic_cast(map->objects[i])->identifier == info->identifier) + { + faction = map->objects[i]->subID; + break; + } + } + } + else + { + while((!(info->castles[0]&(1<7) && (info->castles[1]&(1<<(faction-8)))) + break; + faction = ran()%F_NUMBER; + } + } + int cid = VLC->townh->towns[faction].basicCreatures[obj->subID]; + for(int i=0;iobjh->cregens.size();i++) + if(VLC->objh->cregens[i]==cid) + return std::pair(17,i); + std::cout << "Cannot find a dwelling for creature "<(17,0); + } + case 218: + { + CCreGen3ObjInfo* info =(CCreGen3ObjInfo*)obj->info; + int level = ((info->maxLevel-info->minLevel) ? (ran()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel)); + int cid = VLC->townh->towns[obj->subID].basicCreatures[level]; + for(int i=0;iobjh->cregens.size();i++) + if(VLC->objh->cregens[i]==cid) + return std::pair(17,i); + std::cout << "Cannot find a dwelling for creature "<(17,0); + } + } + return std::pair(-1,-1); +} +void CGameState::randomizeObject(CGObjectInstance *cur) +{ + std::pair ran = pickObject(cur); + if(ran.first<0 || ran.second<0) //this is not a random object, or we couldn't find anything + { + if(cur->ID==98) //town - set def + { + CGTownInstance *t = dynamic_cast(cur); + if(t->hasCapitol()) + t->defInfo = capitols[t->subID]; + else if(t->hasFort()) + t->defInfo = forts[t->subID]; + else + t->defInfo = villages[t->subID]; + } + return; + } + else if(ran.first==34)//special code for hero + { + CGHeroInstance *h = dynamic_cast(cur); + if(!h) {std::cout<<"Wrong random hero at "<pos<ID = ran.first; + cur->subID = ran.second; + h->type = VLC->heroh->heroes[ran.second]; + map->heroes.push_back(h); + return; //TODO: maybe we should do something with definfo? + } + else if(ran.first==98)//special code for town + { + CGTownInstance *t = dynamic_cast(cur); + if(!t) {std::cout<<"Wrong random town at "<pos<ID = ran.first; + cur->subID = ran.second; + t->town = &VLC->townh->towns[ran.second]; + if(t->hasCapitol()) + t->defInfo = capitols[t->subID]; + else if(t->hasFort()) + t->defInfo = forts[t->subID]; + else + t->defInfo = villages[t->subID]; + map->towns.push_back(t); + return; + } + //we have to replace normal random object + cur->ID = ran.first; + cur->subID = ran.second; + map->defs.insert(cur->defInfo = VLC->dobjinfo->gobjs[ran.first][ran.second]); + if(!cur->defInfo){std::cout<<"Missing def declaration for "<ID<<" "<subID<map = map; + + for(int i=0;idobjinfo->castles[i]); + forts[i] = VLC->dobjinfo->castles[i]; + capitols[i] = new CGDefInfo(*VLC->dobjinfo->castles[i]); + } + + //picking random factions for players + for(int i=0;iplayerInfos.size();i++) + { + if(scenarioOps->playerInfos[i].castle==-1) + { + int f; + do + { + f = ran()%F_NUMBER; + }while(!(map->players[scenarioOps->playerInfos[i].color].allowedFactions & 1<playerInfos[i].castle = f; + } + } + //randomizing objects + for(int no=0; noobjects.size(); ++no) + { + randomizeObject(map->objects[no]); + if(map->objects[no]->ID==26) + map->objects[no]->defInfo->handler=NULL; + } + //std::cout<<"\tRandomizing objects: "<playerInfos.size();i++) + { + std::pair ins(scenarioOps->playerInfos[i].color,PlayerState()); + ins.second.color=ins.first; + ins.second.serial=i; + players.insert(ins); + } + /******************RESOURCES****************************************************/ + //TODO: zeby komputer dostawal inaczej niz gracz + std::vector startres; + std::ifstream tis("config/startres.txt"); + int k; + for (int j=0;jdifficulty;j++) + { + tis >> k; + for (int z=0;z>k; + } + tis >> k; + for (int i=0;i> k; + startres.push_back(k); + } + tis.close(); + for (std::map::iterator i = players.begin(); i!=players.end(); i++) + { + (*i).second.resources.resize(RESOURCE_QUANTITY); + for (int x=0;xheroes.size();i++) //heroes instances + { + if (map->heroes[i]->getOwner()<0) + continue; + CGHeroInstance * vhi = (map->heroes[i]); + if(!vhi->type) + vhi->type = VLC->heroh->heroes[vhi->subID]; + //vhi->subID = vhi->type->ID; + if (vhi->level<1) + { + vhi->exp=40+ran()%50; + vhi->level = 1; + } + if (vhi->level>1) ;//TODO dodac um dr, ale potrzebne los + if ((!vhi->primSkills.size()) || (vhi->primSkills[0]<0)) + { + if (vhi->primSkills.size()primSkills.resize(PRIMARY_SKILLS); + vhi->primSkills[0] = vhi->type->heroClass->initialAttack; + 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; + if (!vhi->name.length()) + { + vhi->name = vhi->type->name; + } + if (!vhi->biography.length()) + { + vhi->biography = vhi->type->biography; + } + if (vhi->portrait < 0) + vhi->portrait = vhi->type->ID; + + //initial army + if (!vhi->army.slots.size()) //standard army + { + int pom, pom2=0; + for(int x=0;x<3;x++) + { + pom = (VLC->creh->nameToID[vhi->type->refTypeStack[x]]); + if(pom>=145 && pom<=149) //war machine + { + pom2++; + switch (pom) + { + case 145: //catapult + vhi->artifWorn[16] = 3; + break; + default: + pom-=145; + vhi->artifWorn[13+pom] = 4+pom; + break; + } + continue; + } + vhi->army.slots[x-pom2].first = &(VLC->creh->creatures[pom]); + if((pom = (vhi->type->highStack[x]-vhi->type->lowStack[x])) > 0) + vhi->army.slots[x-pom2].second = (ran()%pom)+vhi->type->lowStack[x]; + else + vhi->army.slots[x-pom2].second = +vhi->type->lowStack[x]; + } + } + + players[vhi->getOwner()].heroes.push_back(vhi); + + } + /*************************FOG**OF**WAR******************************************/ + for(std::map::iterator k=players.begin(); k!=players.end(); ++k) + { + k->second.fogOfWarMap.resize(map->width); + for(int g=0; gwidth; ++g) + k->second.fogOfWarMap[g].resize(map->height); + + for(int g=-0; gwidth; ++g) + for(int h=0; hheight; ++h) + k->second.fogOfWarMap[g][h].resize(map->twoLevel+1, 0); + + for(int g=0; gwidth; ++g) + for(int h=0; hheight; ++h) + for(int v=0; vtwoLevel+1; ++v) + k->second.fogOfWarMap[g][h][v] = 0; + for(int xd=0; xdwidth; ++xd) //revealing part of map around heroes + { + for(int yd=0; ydheight; ++yd) + { + for(int ch=0; chsecond.heroes.size(); ++ch) + { + int deltaX = (k->second.heroes[ch]->getPosition(false).x-xd)*(k->second.heroes[ch]->getPosition(false).x-xd); + int deltaY = (k->second.heroes[ch]->getPosition(false).y-yd)*(k->second.heroes[ch]->getPosition(false).y-yd); + if(deltaX+deltaYsecond.heroes[ch]->getSightDistance()*k->second.heroes[ch]->getSightDistance()) + k->second.fogOfWarMap[xd][yd][k->second.heroes[ch]->getPosition(false).z] = 1; + } + } + } + } + /****************************TOWNS************************************************/ + for (int i=0;itowns.size();i++) + { + CGTownInstance * vti =(map->towns[i]); + if(!vti->town) + vti->town = &VLC->townh->towns[vti->subID]; + if (vti->name.length()==0) // if town hasn't name we draw it + vti->name=vti->town->names[ran()%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(ran()%2) + vti->builtBuildings.insert(31); + } + players[vti->getOwner()].towns.push_back(vti); + } + + for(std::map::iterator k=players.begin(); k!=players.end(); ++k) + { + if(k->first==-1 || k->first==255) + continue; + for(int xd=0; xdwidth; ++xd) //revealing part of map around towns + { + for(int yd=0; ydheight; ++yd) + { + for(int ch=0; chsecond.towns.size(); ++ch) + { + int deltaX = (k->second.towns[ch]->pos.x-xd)*(k->second.towns[ch]->pos.x-xd); + int deltaY = (k->second.towns[ch]->pos.y-yd)*(k->second.towns[ch]->pos.y-yd); + if(deltaX+deltaYsecond.towns[ch]->getSightDistance()*k->second.towns[ch]->getSightDistance()) + k->second.fogOfWarMap[xd][yd][k->second.towns[ch]->pos.z] = 1; + } + } + } + + //init visiting heroes + for(int l=0; lsecond.heroes.size();l++) + { + for(int m=0; msecond.towns.size();m++) + { + int3 vistile = k->second.towns[m]->pos; vistile.x--; //tile next to the entrance + if(vistile == k->second.heroes[l]->pos) + { + k->second.towns[m]->visitingHero = k->second.heroes[l]; + break; + } + } + } + } + + /****************************SCRIPTS************************************************/ + std::map > * skrypty = &objscr; //alias for easier access + /****************************C++ OBJECT SCRIPTS************************************************/ + std::map scripts; + CScriptCallback * csc = new CScriptCallback(); + csc->gs = this; + handleCPPObjS(&scripts,new CVisitableOPH(csc)); + handleCPPObjS(&scripts,new CVisitableOPW(csc)); + handleCPPObjS(&scripts,new CPickable(csc)); + handleCPPObjS(&scripts,new CMines(csc)); + handleCPPObjS(&scripts,new CTownScript(csc)); + handleCPPObjS(&scripts,new CHeroScript(csc)); + handleCPPObjS(&scripts,new CMonsterS(csc)); + handleCPPObjS(&scripts,new CCreatureGen(csc)); + //created map + + /****************************LUA OBJECT SCRIPTS************************************************/ + std::vector * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files + for (int i=0; isize(); i++) + { + try + { + std::vector * temp = CLuaHandler::functionList((*lf)[i]); + CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]); + CLuaCallback::registerFuncs(objs->is); + //objs + for (int j=0; jsize(); j++) + { + int obid ; //obj ID + int dspos = (*temp)[j].find_first_of('_'); + obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str()); + std::string fname = (*temp)[j].substr(0,dspos); + if (skrypty->find(obid)==skrypty->end()) + skrypty->insert(std::pair >(obid,std::map())); + (*skrypty)[obid].insert(std::pair(fname,objs)); + } + delete temp; + }HANDLE_EXCEPTION + } + /****************************INITIALIZING OBJECT SCRIPTS************************************************/ + std::string temps("newObject"); + for (int i=0; iobjects.size(); i++) + { + //c++ scripts + if (scripts.find(map->objects[i]->ID) != scripts.end()) + { + map->objects[i]->state = scripts[map->objects[i]->ID]; + map->objects[i]->state->newObject(map->objects[i]); + } + else + { + map->objects[i]->state = NULL; + } + + // lua scripts + if(checkFunc(map->objects[i]->ID,temps)) + (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]); + } + + delete lf; +} +void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2) +{/* curB = new BattleInfo(); std::vector & stacks = (curB->stacks); @@ -150,7 +666,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C std::stable_sort(stacks.begin(),stacks.end(),cmpst); //for start inform players about battle - for(std::map::iterator j=CGI->state->players.begin(); j!=CGI->state->players.end(); ++j)//CGI->state->players.size(); ++j) //for testing + for(std::map::iterator j=players.begin(); j!=players.end(); ++j)//->players.size(); ++j) //for testing { if (j->first > PLAYER_LIMIT) break; @@ -163,13 +679,13 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C side = true; else continue; //no witnesses - if(CGI->playerint[j->second.serial]->human) + if(VLC->playerint[j->second.serial]->human) { - ((CPlayerInterface*)( CGI->playerint[j->second.serial] ))->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); + ((CPlayerInterface*)( VLC->playerint[j->second.serial] ))->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); } else { - //CGI->playerint[j->second.serial]->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); + //VLC->playerint[j->second.serial]->battleStart(army1, army2, tile, curB->hero1, curB->hero2, side); } } } @@ -188,8 +704,8 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C { bool battleEnd = false; //tell players about next round - for(int v=0; vplayerint.size(); ++v) - CGI->playerint[v]->battleNewRound(curB->round); + for(int v=0; vplayerint.size(); ++v) + VLC->playerint[v]->battleNewRound(curB->round); //stack loop for(int i=0;iowner)?(hero2 ? hero2->tempOwner : 255):(hero1->tempOwner); unsigned char serialOwner = -1; - for(int g=0; gplayerint.size(); ++g) + for(int g=0; gplayerint.size(); ++g) { - if(CGI->playerint[g]->playerID == owner) + if(VLC->playerint[g]->playerID == owner) { serialOwner = g; break; @@ -211,9 +727,9 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C if(serialOwner==255) //neutral unit { } - else if(CGI->playerint[serialOwner]->human) + else if(VLC->playerint[serialOwner]->human) { - BattleAction ba = ((CPlayerInterface*)CGI->playerint[serialOwner])->activeStack(stacks[i]->ID); + BattleAction ba = ((CPlayerInterface*)VLC->playerint[serialOwner])->activeStack(stacks[i]->ID); switch(ba.actionType) { case 2: //walk @@ -226,8 +742,8 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C } case 4: //retreat/flee { - for(int v=0; vplayerint.size(); ++v) //tell about the end of this battle to interfaces - CGI->playerint[v]->battleEnd(army1, army2, hero1, hero2, std::vector(), 0, false); + for(int v=0; vplayerint.size(); ++v) //tell about the end of this battle to interfaces + VLC->playerint[v]->battleEnd(army1, army2, hero1, hero2, std::vector(), 0, false); battleEnd = true; break; } @@ -241,7 +757,7 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C } else { - //CGI->playerint[serialOwner]->activeStack(stacks[i]->ID); + //VLC->playerint[serialOwner]->activeStack(stacks[i]->ID); } } if(battleEnd) @@ -257,11 +773,11 @@ void CGameState::battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, C for(int i=0;istackActionPerformed) //because unit cannot be moved more than once return false; @@ -435,7 +951,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest) } else { - damageBase = rand()%(curStack->creature->damageMax - curStack->creature->damageMin) + curStack->creature->damageMin + 1; + damageBase = ran()%(curStack->creature->damageMax - curStack->creature->damageMin) + curStack->creature->damageMin + 1; } float dmgBonusMultiplier = 1.0; @@ -495,7 +1011,7 @@ bool CGameState::battleMoveCreatureStack(int ID, int dest) } } curB->stackActionPerformed = true; - LOCPLINT->actionFinished(BattleAction()); + LOCPLINT->actionFinished(BattleAction());*/ return true; } @@ -517,7 +1033,7 @@ bool CGameState::battleAttackCreatureStack(int ID, int dest) } std::vector CGameState::battleGetRange(int ID) -{ +{/* int initialPlace=-1; //position of unit int radius=-1; //range of unit unsigned char owner = -1; //owner of unit @@ -681,6 +1197,7 @@ std::vector CGameState::battleGetRange(int ID) ret2.push_back(*it); } - return ret2; + return ret2;*/ + return std::vector(); } diff --git a/CGameState.h b/CGameState.h index e4e891e43..b1e6457a5 100644 --- a/CGameState.h +++ b/CGameState.h @@ -1,8 +1,8 @@ #ifndef CGAMESTATE_H #define CGAMESTATE_H - -#include "mapHandler.h" +#include "global.h" #include +#include #include class CScriptCallback; @@ -12,22 +12,30 @@ class CCPPObjectScript; class CCreatureSet; class CStack; class CGHeroInstance; +class CGTownInstance; class CArmedInstance; +class CGDefInfo; +class CObjectScript; +class CGObjectInstance; +class CCreature; struct Mapa; +struct StartInfo; +struct SDL_Surface; +class CMapHandler; +class CPathfinder; -struct PlayerState +struct DLL_EXPORT PlayerState { public: int color, serial; - //std::vector > > fogOfWarMap; //true - visible, false - hidden - PseudoV< PseudoV< PseudoV > > fogOfWarMap; //true - visible, false - hidden + std::vector > > fogOfWarMap; //true - visible, false - hidden std::vector resources; std::vector heroes; std::vector towns; PlayerState():color(-1){}; }; -struct BattleInfo +struct DLL_EXPORT BattleInfo { int side1, side2; int round, activeStack; @@ -39,7 +47,7 @@ struct BattleInfo bool stackActionPerformed; //true if current stack has been moved }; -class CStack +class DLL_EXPORT CStack { public: int ID; //unique ID of stack @@ -50,13 +58,14 @@ public: bool attackerOwned; //if true, this stack is owned by attakcer (this one from left hand side of battle) int position; //position on battlefield bool alive; //true if it is alive - CStack(CCreature * C, int A, int O, int I, bool AO):creature(C),amount(A),owner(O), alive(true), position(-1), ID(I), attackerOwned(AO), firstHPleft(C->hitPoints){}; + CStack(CCreature * C, int A, int O, int I, bool AO); CStack() : creature(NULL),amount(-1),owner(255), alive(true), position(-1), ID(-1), attackerOwned(true), firstHPleft(-1){}; }; -class CGameState +class DLL_EXPORT CGameState { private: + StartInfo* scenarioOps; int currentPlayer; //ID of player currently having turn BattleInfo *curB; //current battle int day; //total number of days in game @@ -65,6 +74,7 @@ private: std::set cppscripts; //C++ scripts std::map > objscr; //non-C++ scripts + std::map villages, forts, capitols; //def-info for town graphics bool checkFunc(int obid, std::string name) { @@ -77,20 +87,12 @@ private: } return false; } - CGHeroInstance * getHero(int ID, int mode) - { - if (mode != 0) - throw new std::exception("gs->getHero: This mode is not supported!"); - for ( std::map::iterator i=players.begin() ; i!=players.end();i++) - { - for (int j=0;j<(*i).second.heroes.size();j++) - { - if (i->second.heroes[j]->subID == ID) - return i->second.heroes[j]; - } - } - return NULL; - } + + void init(StartInfo * si, Mapa * map, int seed); + void randomizeObject(CGObjectInstance *cur); + std::pair pickObject(CGObjectInstance *obj); + int pickHero(int owner); + void battle(CCreatureSet * army1, CCreatureSet * army2, int3 tile, CArmedInstance *hero1, CArmedInstance *hero2); bool battleMoveCreatureStack(int ID, int dest); bool battleAttackCreatureStack(int ID, int dest); @@ -103,7 +105,7 @@ public: friend void initGameState(Mapa * map, CGameInfo * cgi); friend CScriptCallback; friend void handleCPPObjS(std::map * mapa, CCPPObjectScript * script); - friend SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, PseudoV< PseudoV< PseudoV > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect); //todo: wywalic koniecznie, tylko do flag obecnie!!!! + friend CMapHandler; }; #endif //CGAMESTATE_H diff --git a/CHeroWindow.cpp b/CHeroWindow.cpp index defd056d8..e4a980691 100644 --- a/CHeroWindow.cpp +++ b/CHeroWindow.cpp @@ -24,7 +24,7 @@ CHeroWindow::CHeroWindow(int playerColor): { artWorn.resize(19); background = BitmapHandler::loadBitmap("HEROSCR4.bmp"); - CSDL_Ext::blueToPlayersAdv(background, playerColor); + graphics->blueToPlayersAdv(background, playerColor); pos.x = 65; pos.y = 8; pos.h = background->h; diff --git a/CLua.h b/CLua.h index 9309335cd..2d697fe4d 100644 --- a/CLua.h +++ b/CLua.h @@ -11,6 +11,7 @@ class CGHeroInstance; class CScriptCallback; class SComponent; class CSelectableComponent; +class CGameState; struct Mapa; enum ESLan{UNDEF=-1,CPP,ERM,LUA}; class CObjectScript @@ -70,7 +71,7 @@ public: void findFS(std::string fname); - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CLuaObjectScript : public CLua, public CObjectScript @@ -85,7 +86,7 @@ public: void onHeroVisit(CGObjectInstance *os, int heroID); std::string hoverText(CGObjectInstance *os); - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CCPPObjectScript: public CObjectScript { @@ -107,7 +108,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(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CVisitableOPW : public CCPPObjectScript //once per week @@ -121,7 +122,7 @@ class CVisitableOPW : public CCPPObjectScript //once per week std::string hoverText(CGObjectInstance *os); void newTurn (); - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CMines : public CCPPObjectScript //flaggable, and giving resource at each day @@ -136,7 +137,7 @@ class CMines : public CCPPObjectScript //flaggable, and giving resource at each std::string hoverText(CGObjectInstance *os); void newTurn (); - friend void initGameState(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CPickable : public CCPPObjectScript, public IChosen //pickable - resources, artifacts, etc @@ -151,7 +152,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(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CTownScript : public CCPPObjectScript //pickable - resources, artifacts, etc @@ -162,7 +163,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(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CHeroScript : public CCPPObjectScript @@ -174,7 +175,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(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CMonsterS : public CCPPObjectScript @@ -186,7 +187,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(Mapa * map, CGameInfo * cgi); + friend CGameState; }; class CCreatureGen : public CCPPObjectScript @@ -198,5 +199,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(Mapa * map, CGameInfo * cgi); + friend CGameState; }; \ No newline at end of file diff --git a/CMT.cpp b/CMT.cpp index 8bee31431..a2e91aa01 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -9,14 +9,10 @@ #include "SDL_Extensions.h" #include "SDL_framerate.h" #include -#include -#include #include -#include #include #include "zlib.h" #include -#include #include "hch\CArtHandler.h" #include "hch\CHeroHandler.h" #include "hch\CCreatureHandler.h" @@ -28,7 +24,6 @@ #include "hch\CMusicHandler.h" #include "hch\CLodHandler.h" #include "hch\CDefHandler.h" -#include "hch\CSndHandler.h" #include "hch\CTownHandler.h" #include "hch\CDefObjInfoHandler.h" #include "hch\CAmbarCendamo.h" @@ -46,12 +41,11 @@ #include "CLuaHandler.h" #include "CLua.h" #include "CAdvmapInterface.h" -#include "CCastleInterface.h" #include "client\Graphics.h" -const char * NAME = "VCMI \"Altanatse\" 0.7"; +#include +std::string NAME = NAME_VER + std::string(" (client)"); DLL_EXPORT void initDLL(CLodHandler *b); -SDL_Color playerColorPalette[256]; //palette to make interface colors good - +using boost::asio::ip::tcp; SDL_Surface * screen, * screen2; extern SDL_Surface * CSDL_Ext::std32bppSurface; TTF_Font * TNRB16, *TNR, *GEOR13, *GEORXX, *GEORM, *GEOR16; @@ -64,258 +58,30 @@ void handleCPPObjS(std::map * mapa, CCPPObjectScript * sc } CGI->state->cppscripts.insert(script); } -void initGameState(Mapa * map, CGameInfo * cgi) -{ - cgi->state->day=0; - /*********creating players entries in gs****************************************/ - for (int i=0; iscenarioOps.playerInfos.size();i++) - { - std::pair ins(cgi->scenarioOps.playerInfos[i].color,PlayerState()); - ins.second.color=ins.first; - ins.second.serial=i; - cgi->state->players.insert(ins); - } - /******************RESOURCES****************************************************/ - //TODO: zeby komputer dostawal inaczej niz gracz - std::vector startres; - std::ifstream tis("config/startres.txt"); - int k; - for (int j=0;jscenarioOps.difficulty;j++) - { - tis >> k; - for (int z=0;z>k; - } - tis >> k; - for (int i=0;i> k; - startres.push_back(k); - } - tis.close(); - for (std::map::iterator i = cgi->state->players.begin(); i!=cgi->state->players.end(); i++) - { - (*i).second.resources.resize(RESOURCE_QUANTITY); - for (int x=0;xheroes.size();i++) //heroes instances - { - if (map->heroes[i]->getOwner()<0) - continue; - 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; - vhi->level = 1; - } - if (vhi->level>1) ;//TODO dodac um dr, ale potrzebne los - if ((!vhi->primSkills.size()) || (vhi->primSkills[0]<0)) - { - if (vhi->primSkills.size()primSkills.resize(PRIMARY_SKILLS); - vhi->primSkills[0] = vhi->type->heroClass->initialAttack; - 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; - if (!vhi->name.length()) - { - vhi->name = vhi->type->name; - } - if (!vhi->biography.length()) - { - vhi->biography = vhi->type->biography; - } - if (vhi->portrait < 0) - vhi->portrait = vhi->type->ID; - - //initial army - if (!vhi->army.slots.size()) //standard army - { - int pom, pom2=0; - for(int x=0;x<3;x++) - { - pom = (cgi->creh->nameToID[vhi->type->refTypeStack[x]]); - if(pom>=145 && pom<=149) //war machine - { - pom2++; - switch (pom) - { - case 145: //catapult - vhi->artifWorn[16] = 3; - break; - default: - pom-=145; - vhi->artifWorn[13+pom] = 4+pom; - break; - } - continue; - } - vhi->army.slots[x-pom2].first = &(cgi->creh->creatures[pom]); - if((pom = (vhi->type->highStack[x]-vhi->type->lowStack[x])) > 0) - vhi->army.slots[x-pom2].second = (rand()%pom)+vhi->type->lowStack[x]; - else - vhi->army.slots[x-pom2].second = +vhi->type->lowStack[x]; - } - } - - cgi->state->players[vhi->getOwner()].heroes.push_back(vhi); - - } - /*************************FOG**OF**WAR******************************************/ - for(std::map::iterator k=cgi->state->players.begin(); k!=cgi->state->players.end(); ++k) - { - 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; gwidth+Woff; ++g) - for(int h=-Hoff; hheight+Hoff; ++h) - k->second.fogOfWarMap[g][h].resize(map->twoLevel+1, 0); - - 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; xdwidth; ++xd) //revealing part of map around heroes - { - for(int yd=0; ydheight; ++yd) - { - for(int ch=0; chsecond.heroes.size(); ++ch) - { - int deltaX = (k->second.heroes[ch]->getPosition(false).x-xd)*(k->second.heroes[ch]->getPosition(false).x-xd); - int deltaY = (k->second.heroes[ch]->getPosition(false).y-yd)*(k->second.heroes[ch]->getPosition(false).y-yd); - if(deltaX+deltaYsecond.heroes[ch]->getSightDistance()*k->second.heroes[ch]->getSightDistance()) - k->second.fogOfWarMap[xd][yd][k->second.heroes[ch]->getPosition(false).z] = 1; - } - } - } - } - /****************************TOWNS************************************************/ - for (int i=0;itowns.size();i++) - { - CGTownInstance * vti =(map->towns[i]); - if(!vti->town) - vti->town = &CGI->townh->towns[vti->subID]; - 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); - } - - for(std::map::iterator k=cgi->state->players.begin(); k!=cgi->state->players.end(); ++k) - { - if(k->first==-1 || k->first==255) - continue; - for(int xd=0; xdwidth; ++xd) //revealing part of map around towns - { - for(int yd=0; ydheight; ++yd) - { - for(int ch=0; chsecond.towns.size(); ++ch) - { - int deltaX = (k->second.towns[ch]->pos.x-xd)*(k->second.towns[ch]->pos.x-xd); - int deltaY = (k->second.towns[ch]->pos.y-yd)*(k->second.towns[ch]->pos.y-yd); - if(deltaX+deltaYsecond.towns[ch]->getSightDistance()*k->second.towns[ch]->getSightDistance()) - k->second.fogOfWarMap[xd][yd][k->second.towns[ch]->pos.z] = 1; - } - } - } - - //init visiting heroes - for(int l=0; lsecond.heroes.size();l++) - { - for(int m=0; msecond.towns.size();m++) - { - int3 vistile = k->second.towns[m]->pos; vistile.x--; //tile next to the entrance - if(vistile == k->second.heroes[l]->pos) - { - k->second.towns[m]->visitingHero = k->second.heroes[l]; - break; - } - } - } - } - - /****************************SCRIPTS************************************************/ - std::map > * skrypty = &cgi->state->objscr; //alias for easier access - /****************************C++ OBJECT SCRIPTS************************************************/ - std::map scripts; - CScriptCallback * csc = new CScriptCallback(); - csc->gs = cgi->state; - handleCPPObjS(&scripts,new CVisitableOPH(csc)); - handleCPPObjS(&scripts,new CVisitableOPW(csc)); - handleCPPObjS(&scripts,new CPickable(csc)); - handleCPPObjS(&scripts,new CMines(csc)); - handleCPPObjS(&scripts,new CTownScript(csc)); - handleCPPObjS(&scripts,new CHeroScript(csc)); - handleCPPObjS(&scripts,new CMonsterS(csc)); - handleCPPObjS(&scripts,new CCreatureGen(csc)); - //created map - - /****************************LUA OBJECT SCRIPTS************************************************/ - std::vector * lf = CLuaHandler::searchForScripts("scripts/lua/objects"); //files - for (int i=0; isize(); i++) - { - try - { - std::vector * temp = CLuaHandler::functionList((*lf)[i]); - CLuaObjectScript * objs = new CLuaObjectScript((*lf)[i]); - CLuaCallback::registerFuncs(objs->is); - //objs - for (int j=0; jsize(); j++) - { - int obid ; //obj ID - int dspos = (*temp)[j].find_first_of('_'); - obid = atoi((*temp)[j].substr(dspos+1,(*temp)[j].size()-dspos-1).c_str()); - std::string fname = (*temp)[j].substr(0,dspos); - if (skrypty->find(obid)==skrypty->end()) - skrypty->insert(std::pair >(obid,std::map())); - (*skrypty)[obid].insert(std::pair(fname,objs)); - } - delete temp; - }HANDLE_EXCEPTION - } - /****************************INITIALIZING OBJECT SCRIPTS************************************************/ - std::string temps("newObject"); - for (int i=0; iobjects.size(); i++) - { - //c++ scripts - if (scripts.find(map->objects[i]->ID) != scripts.end()) - { - map->objects[i]->state = scripts[map->objects[i]->ID]; - map->objects[i]->state->newObject(map->objects[i]); - } - else - { - map->objects[i]->state = NULL; - } - - // lua scripts - if(cgi->state->checkFunc(map->objects[i]->ID,temps)) - (*skrypty)[map->objects[i]->ID][temps]->newObject(map->objects[i]); - } - - delete lf; -} - int _tmain(int argc, _TCHAR* argv[]) -{ +{ /* + boost::asio::io_service io_service; + boost::system::error_code error = boost::asio::error::host_not_found; + tcp::socket socket(io_service); + tcp::resolver resolver(io_service); + tcp::resolver::query query("127.0.0.1", "3030"); + tcp::resolver::iterator endpoint_iterator = resolver.resolve(tcp::resolver::query("127.0.0.1", "3030")); + socket.connect(*endpoint_iterator, error); + + boost::array buf; + + size_t len = socket.read_some(boost::asio::buffer(buf), error); + + if (error == boost::asio::error::eof) + ; // Connection closed cleanly by peer. + else if (error) + throw boost::system::system_error(error); // Some other error. + + std::cout.write(buf.data(), len); + len = socket.read_some(boost::asio::buffer(buf), error); + std::cout.write(buf.data(), len);*/ + + srand ( time(NULL) ); CPG=NULL; atexit(SDL_Quit); @@ -330,7 +96,7 @@ int _tmain(int argc, _TCHAR* argv[]) { screen = SDL_SetVideoMode(800,600,24,SDL_SWSURFACE|SDL_DOUBLEBUF/*|SDL_FULLSCREEN*/); //initializing important global surface THC std::cout<<"\tInitializing screen: "<loadHeroAnim(animacje); THC std::cout<<"\tHero animations: "<playerColors.push_back(p); //red - p.r = 0x31; p.g = 0x52; p.b = 0xff; //blue - cgi->playerColors.push_back(p); //blue - p.r = 0x9c; p.g = 0x73; p.b = 0x52;//tan - cgi->playerColors.push_back(p);//tan - p.r = 0x42; p.g = 0x94; p.b = 0x29; //green - cgi->playerColors.push_back(p); //green - p.r = 0xff; p.g = 0x84; p.b = 0x0; //orange - cgi->playerColors.push_back(p); //orange - p.r = 0x8c; p.g = 0x29; p.b = 0xa5; //purple - cgi->playerColors.push_back(p); //purple - p.r = 0x09; p.g = 0x9c; p.b = 0xa5;//teal - cgi->playerColors.push_back(p);//teal - p.r = 0xc6; p.g = 0x7b; p.b = 0x8c;//pink - cgi->playerColors.push_back(p);//pink - p.r = 0x84; p.g = 0x84; p.b = 0x84;//gray - cgi->neutralColor = p;//gray - //colors initialized - //palette initialization - std::string pals = cgi->bitmaph->getTextFile("PLAYERS.PAL"); - int startPoint = 24; //beginning byte; used to read - for(int i=0; i<256; ++i) - { - SDL_Color col; - col.r = pals[startPoint++]; - col.g = pals[startPoint++]; - col.b = pals[startPoint++]; - col.unused = pals[startPoint++]; - playerColorPalette[i] = col; - } - //palette initialized - THC std::cout<<"Preparing players' colours: "<generaltexth = new CGeneralTextHandler; cgi->generaltexth->load(); @@ -435,8 +164,17 @@ int _tmain(int argc, _TCHAR* argv[]) THC std::cout<<"Initialization CPreGame (together): "<mush = mush; - cgi->scenarioOps = cpg->runLoop(); - THC tmh.getDif();pomtime.getDif(); + StartInfo *options = new StartInfo(cpg->runLoop()); + + cgi->dobjinfo = new CDefObjInfoHandler; + cgi->dobjinfo->load(); + THC std::cout<<"\tDef information handler: "<state = new CGameState(); + cgi->state->scenarioOps = options; + THC std::cout<<"\tGamestate: "<loadArtifacts(); cgi->arth = arth; @@ -462,20 +200,13 @@ int _tmain(int argc, _TCHAR* argv[]) cgi->objh = objh; THC std::cout<<"\tObject handler: "<dobjinfo = new CDefObjInfoHandler; - cgi->dobjinfo->load(); - THC std::cout<<"\tDef information handler: "<state = new CGameState(); - cgi->state->players = std::map(); - THC std::cout<<"\tGamestate: "<pathf = new CPathfinder(); THC std::cout<<"\tPathfinder: "<consoleh->cb = new CCallback(cgi->state,-1); cgi->consoleh->runConsole(); THC std::cout<<"\tCallback and console: "<ourScenSel->mapsel.ourMaps[cpg->ourScenSel->mapsel.selected].filename; std::cout<<"Opening map file: "<mh = mh; + + cgi->state->init(options,mapa,8); + + CMapHandler * mh = cgi->mh = new CMapHandler(); + THC std::cout<<"Initializing GameState (together): "<map = mapa; THC std::cout<<"Creating mapHandler: "<loadDefs(); @@ -503,18 +237,16 @@ int _tmain(int argc, _TCHAR* argv[]) mh->init(); THC std::cout<<"Initializing mapHandler (together): "<scenarioOps.playerInfos.size();i++) //initializing interfaces + for (int i=0; istate->scenarioOps->playerInfos.size();i++) //initializing interfaces { - if(!cgi->scenarioOps.playerInfos[i].human) - cgi->playerint.push_back(static_cast(CAIHandler::getNewAI(new CCallback(cgi->state,cgi->scenarioOps.playerInfos[i].color),"EmptyAI.dll"))); + if(!cgi->state->scenarioOps->playerInfos[i].human) + cgi->playerint.push_back(static_cast(CAIHandler::getNewAI(new CCallback(cgi->state,cgi->state->scenarioOps->playerInfos[i].color),"EmptyAI.dll"))); else { - cgi->state->currentPlayer=cgi->scenarioOps.playerInfos[i].color; - cgi->playerint.push_back(new CPlayerInterface(cgi->scenarioOps.playerInfos[i].color,i)); - ((CPlayerInterface*)(cgi->playerint[i]))->init(new CCallback(cgi->state,cgi->scenarioOps.playerInfos[i].color)); + cgi->state->currentPlayer=cgi->state->scenarioOps->playerInfos[i].color; + cgi->playerint.push_back(new CPlayerInterface(cgi->state->scenarioOps->playerInfos[i].color,i)); + ((CPlayerInterface*)(cgi->playerint[i]))->init(new CCallback(cgi->state,cgi->state->scenarioOps->playerInfos[i].color)); } } ///claculating FoWs for minimap diff --git a/CMessage.cpp b/CMessage.cpp index 0b0ccaf1e..e226c60e4 100644 --- a/CMessage.cpp +++ b/CMessage.cpp @@ -14,6 +14,7 @@ #include #include "CLua.h" #include "hch/CGeneralTextHandler.h" +#include "client/Graphics.h" SDL_Color tytulowy, tlo, zwykly ; SDL_Rect genRect(int hh, int ww, int xx, int yy); @@ -61,7 +62,7 @@ void CMessage::init() } for (int j=0;jourImages.size();j++) { - CSDL_Ext::blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i); + graphics->blueToPlayersAdv(bluePieces->ourImages[j].bitmap,i); piecesOfBox[i].push_back(bluePieces->ourImages[j].bitmap); } } diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 5288fd250..081930a09 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -2717,7 +2717,7 @@ CRecrutationWindow::CRecrutationWindow(const std::vector > &C amounts[i] = CGI->creh->creatures[Creatures[i].first].maxAmount(LOCPLINT->cb->getResourceAmount()); } SDL_Surface *hhlp = BitmapHandler::loadBitmap("TPRCRT.bmp"); - blueToPlayersAdv(hhlp,LOCPLINT->playerID); + graphics->blueToPlayersAdv(hhlp,LOCPLINT->playerID); bitmap = SDL_ConvertSurface(hhlp,screen->format,0); //na 8bitowej mapie by sie psulo SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255)); SDL_FreeSurface(hhlp); @@ -2884,7 +2884,7 @@ CCreInfoWindow::CCreInfoWindow pos.y = screen->h/2 - bitmap->h/2; pos.w = bitmap->w; pos.h = bitmap->h; - blueToPlayersAdv(bitmap,LOCPLINT->playerID); + graphics->blueToPlayersAdv(bitmap,LOCPLINT->playerID); SDL_SetColorKey(bitmap,SDL_SRCCOLORKEY,SDL_MapRGB(bitmap->format,0,255,255)); anim = new CCreaturePic(c); if(!type) anim->anim->setType(1); diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index d9f474935..94558ca8e 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -9,8 +9,7 @@ #include #include "hch\CDefHandler.h" #include - -extern SDL_Color playerColorPalette[256]; +#include "client\Graphics.h" SDL_Surface * CSDL_Ext::newSurface(int w, int h, SDL_Surface * mod) //creates new surface, with flags/format same as in surface given { @@ -403,45 +402,6 @@ SDL_Surface * CSDL_Ext::rotate03(SDL_Surface * toRot) } return ret; } - //converts surface to cursor -SDL_Cursor * CSDL_Ext::SurfaceToCursor(SDL_Surface *image, int hx, int hy) -{ - int w, x, y; - Uint8 *data, *mask, *d, *m, r, g, b; - Uint32 color; - SDL_Cursor *cursor; - - w = (image->w + 7) / 8; - data = (Uint8 *)alloca(w * image->h * 2); - if (data == NULL) - return NULL; - memset(data, 0, w * image->h * 2); - mask = data + w * image->h; - if (SDL_MUSTLOCK(image)) - SDL_LockSurface(image); - for (y = 0; y < image->h; y++) - { - d = data + y * w; - m = mask + y * w; - for (x = 0; x < image->w; x++) - { - color = CSDL_Ext::SDL_GetPixel(image, x, y); - if ((image->flags & SDL_SRCCOLORKEY) == 0 || color != image->format->colorkey) - { - SDL_GetRGB(color, image->format, &r, &g, &b); - color = (r + g + b) / 3; - m[x / 8] |= 128 >> (x & 7); - if (color < 128) - d[x / 8] |= 128 >> (x & 7); - } - } - } - if (SDL_MUSTLOCK(image)) - SDL_UnlockSurface(image); - cursor = SDL_CreateCursor(data, mask, w, image->h, hx, hy); - return cursor; -} - Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y, bool colorByte) { int bpp = surface->format->BytesPerPixel; @@ -471,7 +431,7 @@ Uint32 CSDL_Ext::SDL_GetPixel(SDL_Surface *surface, const int & x, const int & y return *(Uint32 *)p; default: - return 0; /* shouldn't happen, but avoids warnings */ + return 0; // shouldn't happen, but avoids warnings } } @@ -530,11 +490,6 @@ SDL_Surface * CSDL_Ext::alphaTransform(SDL_Surface *src) return src; } -SDL_Surface * CSDL_Ext::secondAlphaTransform(SDL_Surface * src, SDL_Surface * alpha) -{ - return copySurface(src); -} - int CSDL_Ext::blit8bppAlphaTo24bpp(SDL_Surface * src, SDL_Rect * srcRect, SDL_Surface * dst, SDL_Rect * dstRect) { static std::map st; @@ -732,128 +687,6 @@ void CSDL_Ext::update(SDL_Surface * what) if(what) SDL_UpdateRect(what, 0, 0, what->w, what->h); } - -void CSDL_Ext::blueToPlayers(SDL_Surface * sur, int player) -{ - if(sur->format->BitsPerPixel == 8) - { - for(int i=0; iformat->palette->ncolors; ++i) - { - SDL_Color * cc = sur->format->palette->colors+i; - if(cc->r==0 && cc->g==0 && cc->b==255) - { - cc->r = CGI->playerColors[player].r; - cc->g = CGI->playerColors[player].g; - cc->b = CGI->playerColors[player].b; - } - } - } - else if(sur->format->BitsPerPixel == 24) - { - for(int y=0; yh; ++y) - { - for(int x=0; xw; ++x) - { - Uint8* cp = (Uint8*)sur->pixels + y+sur->pitch + x*3; - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - { - if(cp[0]==0 && cp[1]==0 && cp[2]==255) - { - cp[0] = CGI->playerColors[player].r; - cp[1] = CGI->playerColors[player].g; - cp[2] = CGI->playerColors[player].b; - } - } - else - { - - if(cp[0]==255 && cp[1]==0 && cp[2]==0) - { - cp[0] = CGI->playerColors[player].b; - cp[1] = CGI->playerColors[player].g; - cp[2] = CGI->playerColors[player].r; - } - } - } - } - } -} - -void CSDL_Ext::blueToPlayersAdv(SDL_Surface * sur, int player, int mode, void* additionalInfo) -{ - if(player==1) //it is actually blue... - return; - if(sur->format->BitsPerPixel == 8) - { - for(int i=0; i<32; ++i) - { - sur->format->palette->colors[224+i] = playerColorPalette[32*player+i]; - } - } - else if(sur->format->BitsPerPixel == 24) //should never happen in general - { - for(int y=0; yh; ++y) - { - for(int x=0; xw; ++x) - { - Uint8* cp = (Uint8*)sur->pixels + y*sur->pitch + x*3; - if(SDL_BYTEORDER == SDL_BIG_ENDIAN) - { - if(cp[2]>cp[1] && cp[2]>cp[0]) - { - std::vector sort1; - sort1.push_back(cp[0]); - sort1.push_back(cp[1]); - sort1.push_back(cp[2]); - std::vector< std::pair > sort2; - sort2.push_back(std::make_pair(CGI->playerColors[player].r, &(cp[0]))); - sort2.push_back(std::make_pair(CGI->playerColors[player].g, &(cp[1]))); - sort2.push_back(std::make_pair(CGI->playerColors[player].b, &(cp[2]))); - std::sort(sort1.begin(), sort1.end()); - if(sort2[0].first>sort2[1].first) - std::swap(sort2[0], sort2[1]); - if(sort2[1].first>sort2[2].first) - std::swap(sort2[1], sort2[2]); - if(sort2[0].first>sort2[1].first) - std::swap(sort2[0], sort2[1]); - for(int hh=0; hh<3; ++hh) - { - (*sort2[hh].second) = (sort1[hh] + sort2[hh].first)/2.2; - } - } - } - else - { - if( - ((mode==0) && (cp[0]>cp[1]) && (cp[0]>cp[2])) || - ((mode==1) && (cp[2]<45) && (cp[0]>80) && (cp[1]<70) && ((cp[0]-cp[1])>40)) - ) - { - std::vector sort1; - sort1.push_back(cp[2]); - sort1.push_back(cp[1]); - sort1.push_back(cp[0]); - std::vector< std::pair > sort2; - sort2.push_back(std::make_pair(CGI->playerColors[player].r, &(cp[2]))); - sort2.push_back(std::make_pair(CGI->playerColors[player].g, &(cp[1]))); - sort2.push_back(std::make_pair(CGI->playerColors[player].b, &(cp[0]))); - std::sort(sort1.begin(), sort1.end()); - if(sort2[0].first>sort2[1].first) - std::swap(sort2[0], sort2[1]); - if(sort2[1].first>sort2[2].first) - std::swap(sort2[1], sort2[2]); - if(sort2[0].first>sort2[1].first) - std::swap(sort2[0], sort2[1]); - for(int hh=0; hh<3; ++hh) - { - (*sort2[hh].second) = (sort1[hh]*0.8 + sort2[hh].first)/2; - } - } - } - } - } - } -} void CSDL_Ext::drawBorder(SDL_Surface * sur, int x, int y, int w, int h, int3 color) { for(int i=0;iformat->BitsPerPixel==8) { if(player != 255) - *(sur->format->palette->colors+5) = CGI->playerColors[player]; + *(sur->format->palette->colors+5) = graphics->playerColors[player]; else - *(sur->format->palette->colors+5) = CGI->neutralColor; + *(sur->format->palette->colors+5) = *graphics->neutralColor; } } int readNormalNr (std::istream &in, int bytCon) @@ -897,15 +730,6 @@ int readNormalNr (std::istream &in, int bytCon) return ret; } -//void CSDL_Ext::fullAlphaTransform(SDL_Surface *& src) -//{ -// src = alphaTransform(src); -// //SDL_Surface * hlp2; -// //hlp2 = secondAlphaTransform(src, std32bppSurface); -// //SDL_FreeSurface(src); -// //src = hlp2; -//} - std::string CSDL_Ext::processStr(std::string str, std::vector & tor) { for (int i=0;(i & tor); //replaces %s in string diff --git a/SDL_rotozoom.cpp b/SDL_rotozoom.cpp deleted file mode 100644 index 2e36db595..000000000 --- a/SDL_rotozoom.cpp +++ /dev/null @@ -1,1231 +0,0 @@ -/* - - SDL_rotozoom.c - rotozoomer for 32bit or 8bit surfaces - - LGPL (c) A. Schiffler - -*/ -#include "stdafx.h" -#ifdef WIN32 -#include -#endif - -#include -#include - -#include "SDL_rotozoom.h" - -#define MAX(a,b) (((a) > (b)) ? (a) : (b)) - - -/* - - 32bit integer-factor averaging Shrinker - - Shrinks 32bit RGBA/ABGR 'src' surface to 'dst' surface. - -*/ - -int shrinkSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int factorx, int factory) -{ - int x, y, dx, dy, sgap, dgap, ra, ga, ba, aa; - int n_average; - tColorRGBA *sp, *osp, *oosp; - tColorRGBA *dp; - - /* - * Averaging integer shrink - */ - - /* Precalculate division factor */ - n_average = factorx*factory; - - /* - * Scan destination - */ - sp = (tColorRGBA *) src->pixels; - sgap = src->pitch - src->w * 4; - - dp = (tColorRGBA *) dst->pixels; - dgap = dst->pitch - dst->w * 4; - - for (y = 0; y < dst->h; y++) { - - osp=sp; - for (x = 0; x < dst->w; x++) { - - /* Trace out source box and accumulate */ - oosp=sp; - ra=ga=ba=aa=0; - for (dy=0; dy < factory; dy++) { - for (dx=0; dx < factorx; dx++) { - ra += sp->r; - ga += sp->g; - ba += sp->b; - aa += sp->a; - - sp++; - } // src dx loop - sp = (tColorRGBA *)((Uint8*)sp + (src->pitch - 4*factorx)); // next y - } // src dy loop - - // next box-x - sp = (tColorRGBA *)((Uint8*)oosp + 4*factorx); - - /* Store result in destination */ - dp->r = ra/n_average; - dp->g = ga/n_average; - dp->b = ba/n_average; - dp->a = aa/n_average; - - /* - * Advance destination pointer - */ - dp++; - } // dst x loop - - // next box-y - sp = (tColorRGBA *)((Uint8*)osp + src->pitch*factory); - - /* - * Advance destination pointers - */ - dp = (tColorRGBA *) ((Uint8 *) dp + dgap); - } // dst y loop - - return (0); -} - -/* - - 8bit integer-factor averaging Shrinker - - Shrinks 8bit Y 'src' surface to 'dst' surface. - -*/ - -int shrinkSurfaceY(SDL_Surface * src, SDL_Surface * dst, int factorx, int factory) -{ - int x, y, dx, dy, sgap, dgap, a; - int n_average; - Uint8 *sp, *osp, *oosp; - Uint8 *dp; - - /* - * Averaging integer shrink - */ - - /* Precalculate division factor */ - n_average = factorx*factory; - - /* - * Scan destination - */ - sp = (Uint8 *) src->pixels; - sgap = src->pitch - src->w; - - dp = (Uint8 *) dst->pixels; - dgap = dst->pitch - dst->w; - - for (y = 0; y < dst->h; y++) { - - osp=sp; - for (x = 0; x < dst->w; x++) { - - /* Trace out source box and accumulate */ - oosp=sp; - a=0; - for (dy=0; dy < factory; dy++) { - for (dx=0; dx < factorx; dx++) { - a += (*sp); - sp++; // next x - } // src dx loop - sp = (Uint8 *)((Uint8*)sp + (src->pitch - factorx)); // next y - } // src dy loop - - // next box-x - sp = (Uint8 *)((Uint8*)oosp + factorx); - - /* Store result in destination */ - *dp = a/n_average; - - /* - * Advance destination pointer - */ - dp++; - } // dst x loop - - // next box-y - sp = (Uint8 *)((Uint8*)osp + src->pitch*factory); - - /* - * Advance destination pointers - */ - dp = (Uint8 *)((Uint8 *)dp + dgap); - } // dst y loop - - return (0); -} - -/* - - 32bit Zoomer with optional anti-aliasing by bilinear interpolation. - - Zoomes 32bit RGBA/ABGR 'src' surface to 'dst' surface. - -*/ - -int zoomSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy, int smooth) -{ - int x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy, ex, ey, t1, t2, sstep; - tColorRGBA *c00, *c01, *c10, *c11; - tColorRGBA *sp, *csp, *dp; - int dgap; - - /* - * Variable setup - */ - if (smooth) { - /* - * For interpolation: assume source dimension is one pixel - */ - /* - * smaller to avoid overflow on right and bottom edge. - */ - sx = (int) (65536.0 * (float) (src->w - 1) / (float) dst->w); - sy = (int) (65536.0 * (float) (src->h - 1) / (float) dst->h); - } else { - sx = (int) (65536.0 * (float) src->w / (float) dst->w); - sy = (int) (65536.0 * (float) src->h / (float) dst->h); - } - - /* - * Allocate memory for row increments - */ - if ((sax = (int *) malloc((dst->w + 1) * sizeof(Uint32))) == NULL) { - return (-1); - } - if ((say = (int *) malloc((dst->h + 1) * sizeof(Uint32))) == NULL) { - free(sax); - return (-1); - } - - /* - * Precalculate row increments - */ - sp = csp = (tColorRGBA *) src->pixels; - dp = (tColorRGBA *) dst->pixels; - - if (flipx) csp += (src->w-1); - if (flipy) csp = (tColorRGBA*)( (Uint8*)csp + src->pitch*(src->h-1) ); - - csx = 0; - csax = sax; - for (x = 0; x <= dst->w; x++) { - *csax = csx; - csax++; - csx &= 0xffff; - csx += sx; - } - csy = 0; - csay = say; - for (y = 0; y <= dst->h; y++) { - *csay = csy; - csay++; - csy &= 0xffff; - csy += sy; - } - - dgap = dst->pitch - dst->w * 4; - - /* - * Switch between interpolating and non-interpolating code - */ - if (smooth) { - - /* - * Interpolating Zoom - */ - - /* - * Scan destination - */ - csay = say; - for (y = 0; y < dst->h; y++) { - /* - * Setup color source pointers - */ - c00 = csp; - c01 = csp; - c01++; - c10 = (tColorRGBA *) ((Uint8 *) csp + src->pitch); - c11 = c10; - c11++; - csax = sax; - for (x = 0; x < dst->w; x++) { - - /* - * Interpolate colors - */ - ex = (*csax & 0xffff); - ey = (*csay & 0xffff); - t1 = ((((c01->r - c00->r) * ex) >> 16) + c00->r) & 0xff; - t2 = ((((c11->r - c10->r) * ex) >> 16) + c10->r) & 0xff; - dp->r = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01->g - c00->g) * ex) >> 16) + c00->g) & 0xff; - t2 = ((((c11->g - c10->g) * ex) >> 16) + c10->g) & 0xff; - dp->g = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01->b - c00->b) * ex) >> 16) + c00->b) & 0xff; - t2 = ((((c11->b - c10->b) * ex) >> 16) + c10->b) & 0xff; - dp->b = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01->a - c00->a) * ex) >> 16) + c00->a) & 0xff; - t2 = ((((c11->a - c10->a) * ex) >> 16) + c10->a) & 0xff; - dp->a = (((t2 - t1) * ey) >> 16) + t1; - - /* - * Advance source pointers - */ - csax++; - sstep = (*csax >> 16); - c00 += sstep; - c01 += sstep; - c10 += sstep; - c11 += sstep; - /* - * Advance destination pointer - */ - dp++; - } - /* - * Advance source pointer - */ - csay++; - csp = (tColorRGBA *) ((Uint8 *) csp + (*csay >> 16) * src->pitch); - /* - * Advance destination pointers - */ - dp = (tColorRGBA *) ((Uint8 *) dp + dgap); - } - - } else { - - /* - * Non-Interpolating Zoom - */ - - csay = say; - for (y = 0; y < dst->h; y++) { - sp = csp; - csax = sax; - for (x = 0; x < dst->w; x++) { - /* - * Draw - */ - *dp = *sp; - /* - * Advance source pointers - */ - csax++; - sstep = (*csax >> 16); - if (flipx) sstep = -sstep; - sp += sstep; - /* - * Advance destination pointer - */ - dp++; - } - /* - * Advance source pointer - */ - csay++; - sstep = (*csay >> 16) * src->pitch; - if (flipy) sstep = -sstep; - csp = (tColorRGBA *) ((Uint8 *) csp + sstep); - - /* - * Advance destination pointers - */ - dp = (tColorRGBA *) ((Uint8 *) dp + dgap); - } - - } - - /* - * Remove temp arrays - */ - free(sax); - free(say); - - return (0); -} - -/* - - 8bit Zoomer without smoothing. - - Zoomes 8bit palette/Y 'src' surface to 'dst' surface. - -*/ - -int zoomSurfaceY(SDL_Surface * src, SDL_Surface * dst, int flipx, int flipy) -{ - Uint32 x, y, sx, sy, *sax, *say, *csax, *csay, csx, csy; - Uint8 *sp, *dp, *csp; - int dgap; - - /* - * Variable setup - */ - sx = (Uint32) (65536.0 * (float) src->w / (float) dst->w); - sy = (Uint32) (65536.0 * (float) src->h / (float) dst->h); - - /* - * Allocate memory for row increments - */ - if ((sax = (Uint32 *) malloc(dst->w * sizeof(Uint32))) == NULL) { - return (-1); - } - if ((say = (Uint32 *) malloc(dst->h * sizeof(Uint32))) == NULL) { - if (sax != NULL) { - free(sax); - } - return (-1); - } - - /* - * Precalculate row increments - */ - csx = 0; - csax = sax; - for (x = 0; x < dst->w; x++) { - csx += sx; - *csax = (csx >> 16); - csx &= 0xffff; - csax++; - } - csy = 0; - csay = say; - for (y = 0; y < dst->h; y++) { - csy += sy; - *csay = (csy >> 16); - csy &= 0xffff; - csay++; - } - - csx = 0; - csax = sax; - for (x = 0; x < dst->w; x++) { - csx += (*csax); - csax++; - } - csy = 0; - csay = say; - for (y = 0; y < dst->h; y++) { - csy += (*csay); - csay++; - } - - /* - * Pointer setup - */ - sp = csp = (Uint8 *) src->pixels; - dp = (Uint8 *) dst->pixels; - dgap = dst->pitch - dst->w; - - /* - * Draw - */ - csay = say; - for (y = 0; y < dst->h; y++) { - csax = sax; - sp = csp; - for (x = 0; x < dst->w; x++) { - /* - * Draw - */ - *dp = *sp; - /* - * Advance source pointers - */ - sp += (*csax); - csax++; - /* - * Advance destination pointer - */ - dp++; - } - /* - * Advance source pointer (for row) - */ - csp += ((*csay) * src->pitch); - csay++; - /* - * Advance destination pointers - */ - dp += dgap; - } - - /* - * Remove temp arrays - */ - free(sax); - free(say); - - return (0); -} - -/* - - 32bit Rotozoomer with optional anti-aliasing by bilinear interpolation. - - Rotates and zoomes 32bit RGBA/ABGR 'src' surface to 'dst' surface. - -*/ - -void transformSurfaceRGBA(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos, int flipx, int flipy, int smooth) -{ - int x, y, t1, t2, dx, dy, xd, yd, sdx, sdy, ax, ay, ex, ey, sw, sh; - tColorRGBA c00, c01, c10, c11; - tColorRGBA *pc, *sp; - int gap; - - /* - * Variable setup - */ - xd = ((src->w - dst->w) << 15); - yd = ((src->h - dst->h) << 15); - ax = (cx << 16) - (icos * cx); - ay = (cy << 16) - (isin * cx); - sw = src->w - 1; - sh = src->h - 1; - pc = (tColorRGBA*)dst->pixels; - gap = dst->pitch - dst->w * 4; - - /* - * Switch between interpolating and non-interpolating code - */ - if (smooth) { - for (y = 0; y < dst->h; y++) { - dy = cy - y; - sdx = (ax + (isin * dy)) + xd; - sdy = (ay - (icos * dy)) + yd; - for (x = 0; x < dst->w; x++) { - dx = (sdx >> 16); - dy = (sdy >> 16); - if ((dx >= -1) && (dy >= -1) && (dx < src->w) && (dy < src->h)) { - if ((dx >= 0) && (dy >= 0) && (dx < sw) && (dy < sh)) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - sp += dx; - c00 = *sp; - sp += 1; - c01 = *sp; - sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch); - sp -= 1; - c10 = *sp; - sp += 1; - c11 = *sp; - } else if ((dx == sw) && (dy == sh)) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - sp += dx; - c00 = *sp; - c01 = *sp; - c10 = *sp; - c11 = *sp; - } else if ((dx == -1) && (dy == -1)) { - sp = (tColorRGBA *) (src->pixels); - c00 = *sp; - c01 = *sp; - c10 = *sp; - c11 = *sp; - } else if ((dx == -1) && (dy == sh)) { - sp = (tColorRGBA *) (src->pixels); - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - c00 = *sp; - c01 = *sp; - c10 = *sp; - c11 = *sp; - } else if ((dx == sw) && (dy == -1)) { - sp = (tColorRGBA *) (src->pixels); - sp += dx; - c00 = *sp; - c01 = *sp; - c10 = *sp; - c11 = *sp; - } else if (dx == -1) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - c00 = *sp; - c01 = *sp; - c10 = *sp; - sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch); - c11 = *sp; - } else if (dy == -1) { - sp = (tColorRGBA *) (src->pixels); - sp += dx; - c00 = *sp; - c01 = *sp; - c10 = *sp; - sp += 1; - c11 = *sp; - } else if (dx == sw) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - sp += dx; - c00 = *sp; - c01 = *sp; - sp = (tColorRGBA *) ((Uint8 *) sp + src->pitch); - c10 = *sp; - c11 = *sp; - } else if (dy == sh) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - sp += dx; - c00 = *sp; - sp += 1; - c01 = *sp; - c10 = *sp; - c11 = *sp; - } - /* - * Interpolate colors - */ - ex = (sdx & 0xffff); - ey = (sdy & 0xffff); - t1 = ((((c01.r - c00.r) * ex) >> 16) + c00.r) & 0xff; - t2 = ((((c11.r - c10.r) * ex) >> 16) + c10.r) & 0xff; - pc->r = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01.g - c00.g) * ex) >> 16) + c00.g) & 0xff; - t2 = ((((c11.g - c10.g) * ex) >> 16) + c10.g) & 0xff; - pc->g = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01.b - c00.b) * ex) >> 16) + c00.b) & 0xff; - t2 = ((((c11.b - c10.b) * ex) >> 16) + c10.b) & 0xff; - pc->b = (((t2 - t1) * ey) >> 16) + t1; - t1 = ((((c01.a - c00.a) * ex) >> 16) + c00.a) & 0xff; - t2 = ((((c11.a - c10.a) * ex) >> 16) + c10.a) & 0xff; - pc->a = (((t2 - t1) * ey) >> 16) + t1; - } - sdx += icos; - sdy += isin; - pc++; - } - pc = (tColorRGBA *) ((Uint8 *) pc + gap); - } - } else { - for (y = 0; y < dst->h; y++) { - dy = cy - y; - sdx = (ax + (isin * dy)) + xd; - sdy = (ay - (icos * dy)) + yd; - for (x = 0; x < dst->w; x++) { - dx = (short) (sdx >> 16); - dy = (short) (sdy >> 16); - if (flipx) dx = (src->w-1)-dx; - if (flipy) dy = (src->h-1)-dy; - if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) { - sp = (tColorRGBA *) ((Uint8 *) src->pixels + src->pitch * dy); - sp += dx; - *pc = *sp; - } - sdx += icos; - sdy += isin; - pc++; - } - pc = (tColorRGBA *) ((Uint8 *) pc + gap); - } - } -} - -/* - - 8bit Rotozoomer without smoothing - - Rotates and zoomes 8bit palette/Y 'src' surface to 'dst' surface. - -*/ - -void transformSurfaceY(SDL_Surface * src, SDL_Surface * dst, int cx, int cy, int isin, int icos) -{ - int x, y, dx, dy, xd, yd, sdx, sdy, ax, ay, sw, sh; - tColorY *pc, *sp; - int gap; - - /* - * Variable setup - */ - xd = ((src->w - dst->w) << 15); - yd = ((src->h - dst->h) << 15); - ax = (cx << 16) - (icos * cx); - ay = (cy << 16) - (isin * cx); - sw = src->w - 1; - sh = src->h - 1; - pc = (tColorY*)dst->pixels; - gap = dst->pitch - dst->w; - /* - * Clear surface to colorkey - */ - memset(pc, (unsigned char) (src->format->colorkey & 0xff), dst->pitch * dst->h); - /* - * Iterate through destination surface - */ - for (y = 0; y < dst->h; y++) { - dy = cy - y; - sdx = (ax + (isin * dy)) + xd; - sdy = (ay - (icos * dy)) + yd; - for (x = 0; x < dst->w; x++) { - dx = (short) (sdx >> 16); - dy = (short) (sdy >> 16); - if ((dx >= 0) && (dy >= 0) && (dx < src->w) && (dy < src->h)) { - sp = (tColorY *) (src->pixels); - sp += (src->pitch * dy + dx); - *pc = *sp; - } - sdx += icos; - sdy += isin; - pc++; - } - pc += gap; - } -} - -/* - - rotozoomSurface() - - Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. - 'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1 - then the destination 32bit surface is anti-aliased. If the surface is not 8bit - or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. - -*/ - -#define VALUE_LIMIT 0.001 - - -/* Local rotozoom-size function with trig result return */ - -void rotozoomSurfaceSizeTrig(int width, int height, double angle, double zoomx, double zoomy, int *dstwidth, int *dstheight, - double *canglezoom, double *sanglezoom) -{ - double x, y, cx, cy, sx, sy; - double radangle; - int dstwidthhalf, dstheighthalf; - - /* - * Determine destination width and height by rotating a centered source box - */ - radangle = angle * (M_PI / 180.0); - *sanglezoom = sin(radangle); - *canglezoom = cos(radangle); - *sanglezoom *= zoomx; - *canglezoom *= zoomx; - x = width / 2; - y = height / 2; - cx = *canglezoom * x; - cy = *canglezoom * y; - sx = *sanglezoom * x; - sy = *sanglezoom * y; - - dstwidthhalf = MAX((int) - ceil(MAX(MAX(MAX(fabs(cx + sy), fabs(cx - sy)), fabs(-cx + sy)), fabs(-cx - sy))), 1); - dstheighthalf = MAX((int) - ceil(MAX(MAX(MAX(fabs(sx + cy), fabs(sx - cy)), fabs(-sx + cy)), fabs(-sx - cy))), 1); - *dstwidth = 2 * dstwidthhalf; - *dstheight = 2 * dstheighthalf; -} - - -/* Publically available rotozoom-size function */ - -void rotozoomSurfaceSizeXY(int width, int height, double angle, double zoomx, double zoomy, int *dstwidth, int *dstheight) -{ - double dummy_sanglezoom, dummy_canglezoom; - - rotozoomSurfaceSizeTrig(width, height, angle, zoomx, zoomy, dstwidth, dstheight, &dummy_sanglezoom, &dummy_canglezoom); -} - -/* Publically available rotozoom-size function */ - -void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth, int *dstheight) -{ - double dummy_sanglezoom, dummy_canglezoom; - - rotozoomSurfaceSizeTrig(width, height, angle, zoom, zoom, dstwidth, dstheight, &dummy_sanglezoom, &dummy_canglezoom); -} - -/* Publically available rotozoom function */ - -SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth) -{ - return rotozoomSurfaceXY(src, angle, zoom, zoom, smooth); -} - -/* Publically available rotozoom function */ - -SDL_Surface *rotozoomSurfaceXY(SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth) -{ - SDL_Surface *rz_src; - SDL_Surface *rz_dst; - double zoominv; - double sanglezoom, canglezoom, sanglezoominv, canglezoominv; - int dstwidthhalf, dstwidth, dstheighthalf, dstheight; - int is32bit; - int i, src_converted; - int flipx,flipy; - - /* - * Sanity check - */ - if (src == NULL) - return (NULL); - - /* - * Determine if source surface is 32bit or 8bit - */ - is32bit = (src->format->BitsPerPixel == 32); - if ((is32bit) || (src->format->BitsPerPixel == 8)) { - /* - * Use source surface 'as is' - */ - rz_src = src; - src_converted = 0; - } else { - /* - * New source surface is 32bit with a defined RGBA ordering - */ - rz_src = - SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - SDL_BlitSurface(src, NULL, rz_src, NULL); - src_converted = 1; - is32bit = 1; - } - - /* - * Sanity check zoom factor - */ - flipx = (zoomx<0); - if (flipx) zoomx=-zoomx; - flipy = (zoomy<0); - if (flipy) zoomy=-zoomy; - if (zoomx < VALUE_LIMIT) zoomx = VALUE_LIMIT; - if (zoomy < VALUE_LIMIT) zoomy = VALUE_LIMIT; - zoominv = 65536.0 / (zoomx * zoomx); - - /* - * Check if we have a rotozoom or just a zoom - */ - if (fabs(angle) > VALUE_LIMIT) { - - /* - * Angle!=0: full rotozoom - */ - /* - * ----------------------- - */ - - /* Determine target size */ - rotozoomSurfaceSizeTrig(rz_src->w, rz_src->h, angle, zoomx, zoomy, &dstwidth, &dstheight, &canglezoom, &sanglezoom); - - /* - * Calculate target factors from sin/cos and zoom - */ - sanglezoominv = sanglezoom; - canglezoominv = canglezoom; - sanglezoominv *= zoominv; - canglezoominv *= zoominv; - - /* Calculate half size */ - dstwidthhalf = dstwidth / 2; - dstheighthalf = dstheight / 2; - - /* - * Alloc space to completely contain the rotated surface - */ - rz_dst = NULL; - if (is32bit) { - /* - * Target surface is 32bit with source RGBA/ABGR ordering - */ - rz_dst = - SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32, - rz_src->format->Rmask, rz_src->format->Gmask, - rz_src->format->Bmask, rz_src->format->Amask); - } else { - /* - * Target surface is 8bit - */ - rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0); - } - - /* - * Lock source surface - */ - SDL_LockSurface(rz_src); - /* - * Check which kind of surface we have - */ - if (is32bit) { - /* - * Call the 32bit transformation routine to do the rotation (using alpha) - */ - transformSurfaceRGBA(rz_src, rz_dst, dstwidthhalf, dstheighthalf, - (int) (sanglezoominv), (int) (canglezoominv), - flipx, flipy, - smooth); - /* - * Turn on source-alpha support - */ - SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); - } else { - /* - * Copy palette and colorkey info - */ - for (i = 0; i < rz_src->format->palette->ncolors; i++) { - rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i]; - } - rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors; - /* - * Call the 8bit transformation routine to do the rotation - */ - transformSurfaceY(rz_src, rz_dst, dstwidthhalf, dstheighthalf, - (int) (sanglezoominv), (int) (canglezoominv)); - SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey); - } - /* - * Unlock source surface - */ - SDL_UnlockSurface(rz_src); - - } else { - - /* - * Angle=0: Just a zoom - */ - /* - * -------------------- - */ - - /* - * Calculate target size - */ - zoomSurfaceSize(rz_src->w, rz_src->h, zoomx, zoomy, &dstwidth, &dstheight); - - /* - * Alloc space to completely contain the zoomed surface - */ - rz_dst = NULL; - if (is32bit) { - /* - * Target surface is 32bit with source RGBA/ABGR ordering - */ - rz_dst = - SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32, - rz_src->format->Rmask, rz_src->format->Gmask, - rz_src->format->Bmask, rz_src->format->Amask); - } else { - /* - * Target surface is 8bit - */ - rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0); - } - - /* - * Lock source surface - */ - SDL_LockSurface(rz_src); - /* - * Check which kind of surface we have - */ - if (is32bit) { - /* - * Call the 32bit transformation routine to do the zooming (using alpha) - */ - zoomSurfaceRGBA(rz_src, rz_dst, flipx, flipy, smooth); - /* - * Turn on source-alpha support - */ - SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); - } else { - /* - * Copy palette and colorkey info - */ - for (i = 0; i < rz_src->format->palette->ncolors; i++) { - rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i]; - } - rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors; - /* - * Call the 8bit transformation routine to do the zooming - */ - zoomSurfaceY(rz_src, rz_dst, flipx, flipy); - SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey); - } - /* - * Unlock source surface - */ - SDL_UnlockSurface(rz_src); - } - - /* - * Cleanup temp surface - */ - if (src_converted) { - SDL_FreeSurface(rz_src); - } - - /* - * Return destination surface - */ - return (rz_dst); -} - -/* - - zoomSurface() - - Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. - 'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is 1 - then the destination 32bit surface is anti-aliased. If the surface is not 8bit - or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. - -*/ - -#define VALUE_LIMIT 0.001 - -void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight) -{ - /* - * Sanity check zoom factors - */ - if (zoomx < VALUE_LIMIT) { - zoomx = VALUE_LIMIT; - } - if (zoomy < VALUE_LIMIT) { - zoomy = VALUE_LIMIT; - } - - /* - * Calculate target size - */ - *dstwidth = (int) ((double) width * zoomx); - *dstheight = (int) ((double) height * zoomy); - if (*dstwidth < 1) { - *dstwidth = 1; - } - if (*dstheight < 1) { - *dstheight = 1; - } -} - -SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth) -{ - SDL_Surface *rz_src; - SDL_Surface *rz_dst; - int dstwidth, dstheight; - int is32bit; - int i, src_converted; - int flipx, flipy; - - /* - * Sanity check - */ - if (src == NULL) - return (NULL); - - /* - * Determine if source surface is 32bit or 8bit - */ - is32bit = (src->format->BitsPerPixel == 32); - if ((is32bit) || (src->format->BitsPerPixel == 8)) { - /* - * Use source surface 'as is' - */ - rz_src = src; - src_converted = 0; - } else { - /* - * New source surface is 32bit with a defined RGBA ordering - */ - rz_src = - SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - SDL_BlitSurface(src, NULL, rz_src, NULL); - src_converted = 1; - is32bit = 1; - } - - flipx = (zoomx<0); - if (flipx) zoomx = -zoomx; - flipy = (zoomy<0); - if (flipy) zoomy = -zoomy; - - /* Get size if target */ - zoomSurfaceSize(rz_src->w, rz_src->h, zoomx, zoomy, &dstwidth, &dstheight); - - /* - * Alloc space to completely contain the zoomed surface - */ - rz_dst = NULL; - if (is32bit) { - /* - * Target surface is 32bit with source RGBA/ABGR ordering - */ - rz_dst = - SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32, - rz_src->format->Rmask, rz_src->format->Gmask, - rz_src->format->Bmask, rz_src->format->Amask); - } else { - /* - * Target surface is 8bit - */ - rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0); - } - - /* - * Lock source surface - */ - SDL_LockSurface(rz_src); - /* - * Check which kind of surface we have - */ - if (is32bit) { - /* - * Call the 32bit transformation routine to do the zooming (using alpha) - */ - zoomSurfaceRGBA(rz_src, rz_dst, flipx, flipy, smooth); - /* - * Turn on source-alpha support - */ - SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); - } else { - /* - * Copy palette and colorkey info - */ - for (i = 0; i < rz_src->format->palette->ncolors; i++) { - rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i]; - } - rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors; - /* - * Call the 8bit transformation routine to do the zooming - */ - zoomSurfaceY(rz_src, rz_dst, flipx, flipy); - SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey); - } - /* - * Unlock source surface - */ - SDL_UnlockSurface(rz_src); - - /* - * Cleanup temp surface - */ - if (src_converted) { - SDL_FreeSurface(rz_src); - } - - /* - * Return destination surface - */ - return (rz_dst); -} - -SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory) -{ - SDL_Surface *rz_src; - SDL_Surface *rz_dst; - int dstwidth, dstheight; - int is32bit; - int i, src_converted; - - /* - * Sanity check - */ - if (src == NULL) - return (NULL); - - /* - * Determine if source surface is 32bit or 8bit - */ - is32bit = (src->format->BitsPerPixel == 32); - if ((is32bit) || (src->format->BitsPerPixel == 8)) { - /* - * Use source surface 'as is' - */ - rz_src = src; - src_converted = 0; - } else { - /* - * New source surface is 32bit with a defined RGBA ordering - */ - rz_src = - SDL_CreateRGBSurface(SDL_SWSURFACE, src->w, src->h, 32, 0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000); - SDL_BlitSurface(src, NULL, rz_src, NULL); - src_converted = 1; - is32bit = 1; - } - - /* Get size for target */ - dstwidth=rz_src->w/factorx; - while (dstwidth*factorx>rz_src->w) { dstwidth--; } - dstheight=rz_src->h/factory; - while (dstheight*factory>rz_src->h) { dstheight--; } - - /* - * Alloc space to completely contain the shrunken surface - */ - rz_dst = NULL; - if (is32bit) { - /* - * Target surface is 32bit with source RGBA/ABGR ordering - */ - rz_dst = - SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 32, - rz_src->format->Rmask, rz_src->format->Gmask, - rz_src->format->Bmask, rz_src->format->Amask); - } else { - /* - * Target surface is 8bit - */ - rz_dst = SDL_CreateRGBSurface(SDL_SWSURFACE, dstwidth, dstheight, 8, 0, 0, 0, 0); - } - - /* - * Lock source surface - */ - SDL_LockSurface(rz_src); - /* - * Check which kind of surface we have - */ - if (is32bit) { - /* - * Call the 32bit transformation routine to do the shrinking (using alpha) - */ - shrinkSurfaceRGBA(rz_src, rz_dst, factorx, factory); - /* - * Turn on source-alpha support - */ - SDL_SetAlpha(rz_dst, SDL_SRCALPHA, 255); - } else { - /* - * Copy palette and colorkey info - */ - for (i = 0; i < rz_src->format->palette->ncolors; i++) { - rz_dst->format->palette->colors[i] = rz_src->format->palette->colors[i]; - } - rz_dst->format->palette->ncolors = rz_src->format->palette->ncolors; - /* - * Call the 8bit transformation routine to do the shrinking - */ - shrinkSurfaceY(rz_src, rz_dst, factorx, factory); - SDL_SetColorKey(rz_dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, rz_src->format->colorkey); - } - /* - * Unlock source surface - */ - SDL_UnlockSurface(rz_src); - - /* - * Cleanup temp surface - */ - if (src_converted) { - SDL_FreeSurface(rz_src); - } - - /* - * Return destination surface - */ - return (rz_dst); -} diff --git a/SDL_rotozoom.h b/SDL_rotozoom.h deleted file mode 100644 index cc3b7720b..000000000 --- a/SDL_rotozoom.h +++ /dev/null @@ -1,117 +0,0 @@ - -/* - - SDL_rotozoom - rotozoomer - - LGPL (c) A. Schiffler - -*/ - -#ifndef _SDL_rotozoom_h -#define _SDL_rotozoom_h - -#include - -/* Set up for C function definitions, even when using C++ */ -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef M_PI -#define M_PI 3.141592654 -#endif - -#include "SDL.h" - -/* ---- Defines */ - -#define SMOOTHING_OFF 0 -#define SMOOTHING_ON 1 - -/* ---- Structures */ - - typedef struct tColorRGBA { - Uint8 r; - Uint8 g; - Uint8 b; - Uint8 a; - } tColorRGBA; - - typedef struct tColorY { - Uint8 y; - } tColorY; - - -/* ---- Prototypes */ - -#ifdef WIN32 -#ifdef BUILD_DLL -#define DLLINTERFACE __declspec(dllexport) -#else -#define DLLINTERFACE __declspec(dllimport) -#endif -#else -#define DLLINTERFACE -#endif - -/* - - rotozoomSurface() - - Rotates and zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. - 'angle' is the rotation in degrees. 'zoom' a scaling factor. If 'smooth' is 1 - then the destination 32bit surface is anti-aliased. If the surface is not 8bit - or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. - -*/ - - SDL_Surface *rotozoomSurface(SDL_Surface * src, double angle, double zoom, int smooth); - - SDL_Surface *rotozoomSurfaceXY - (SDL_Surface * src, double angle, double zoomx, double zoomy, int smooth); - -/* Returns the size of the target surface for a rotozoomSurface() call */ - - void rotozoomSurfaceSize(int width, int height, double angle, double zoom, int *dstwidth, - int *dstheight); - - void rotozoomSurfaceSizeXY - (int width, int height, double angle, double zoomx, double zoomy, - int *dstwidth, int *dstheight); - -/* - - zoomSurface() - - Zoomes a 32bit or 8bit 'src' surface to newly created 'dst' surface. - 'zoomx' and 'zoomy' are scaling factors for width and height. If 'smooth' is 1 - then the destination 32bit surface is anti-aliased. If the surface is not 8bit - or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. - -*/ - - SDL_Surface *zoomSurface(SDL_Surface * src, double zoomx, double zoomy, int smooth); - -/* Returns the size of the target surface for a zoomSurface() call */ - - void zoomSurfaceSize(int width, int height, double zoomx, double zoomy, int *dstwidth, int *dstheight); - - -/* - shrinkSurface() - - Shrinks a 32bit or 8bit 'src' surface ti a newly created 'dst' surface. - 'factorx' and 'factory' are the shrinking ratios (i.e. 2=1/2 the size, - 3=1/3 the size, etc.) The destination surface is antialiased by averaging - the source box RGBA or Y information. If the surface is not 8bit - or 32bit RGBA/ABGR it will be converted into a 32bit RGBA format on the fly. -*/ - - SDL_Surface *shrinkSurface(SDL_Surface * src, int factorx, int factory); - -/* Ends C function definitions when using C++ */ -#ifdef __cplusplus -} -#endif - -#endif /* _SDL_rotozoom_h */ diff --git a/client/Graphics.cpp b/client/Graphics.cpp index 02da2ebe8..db65b451b 100644 --- a/client/Graphics.cpp +++ b/client/Graphics.cpp @@ -2,7 +2,6 @@ #include "Graphics.h" #include "../hch/CDefHandler.h" #include "../hch/CObjectHandler.h" -//#include "../hch/CHeroHandler.h" #include "../SDL_Extensions.h" #include #include @@ -12,6 +11,8 @@ #include #include #include "../CThreadHelper.h" +#include "../CGameInfo.h" +#include "../hch/CLodHandler.h" using namespace boost::assign; using namespace CSDL_Ext; Graphics * graphics = NULL; @@ -30,7 +31,7 @@ SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh) { char * buf = new char[10]; SDL_Surface * ret = SDL_DisplayFormat(hInfo); - blueToPlayersAdv(hInfo,curh->tempOwner,1); + blueToPlayersAdv(hInfo,curh->tempOwner); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); printAt(curh->name,75,15,GEOR13,zwykly,ret); drawPrimarySkill(curh, ret); @@ -52,7 +53,7 @@ SDL_Surface * Graphics::drawHeroInfoWin(const CGHeroInstance * curh) SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh) { char * buf = new char[10]; - blueToPlayersAdv(tInfo,curh->tempOwner,1); + blueToPlayersAdv(tInfo,curh->tempOwner); SDL_Surface * ret = SDL_DisplayFormat(tInfo); SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); printAt(curh->name,75,15,GEOR13,zwykly,ret); @@ -82,6 +83,35 @@ SDL_Surface * Graphics::drawTownInfoWin(const CGTownInstance * curh) delete[] buf; return ret; } + +void Graphics::loadPaletteAndColors() +{ + std::string pals = CGI->bitmaph->getTextFile("PLAYERS.PAL"); + playerColorPalette = new SDL_Color[256]; + neutralColor = new SDL_Color; + playerColors = new SDL_Color[PLAYER_LIMIT]; + int startPoint = 24; //beginning byte; used to read + for(int i=0; i<256; ++i) + { + SDL_Color col; + col.r = pals[startPoint++]; + col.g = pals[startPoint++]; + col.b = pals[startPoint++]; + col.unused = pals[startPoint++]; + playerColorPalette[i] = col; + } + //colors initialization + int3 kolory[] = {int3(0xff,0,0),int3(0x31,0x52,0xff),int3(0x9c,0x73,0x52),int3(0x42,0x94,0x29), + int3(0xff,0x84,0x0),int3(0x8c,0x29,0xa5),int3(0x09,0x9c,0xa5),int3(0xc6,0x7b,0x8c)}; + for(int i=0;i<8;i++) + { + playerColors[i].r = kolory[i].x; + playerColors[i].g = kolory[i].y; + playerColors[i].b = kolory[i].z; + playerColors[i].unused = 0; + } + neutralColor->r = 0x84; neutralColor->g = 0x84; neutralColor->b = 0x84;//gray +} Graphics::Graphics() { slotsPos.push_back(std::pair(44,82)); @@ -95,6 +125,7 @@ Graphics::Graphics() CDefHandler *smi, *smi2; std::vector tasks; //preparing list of graphics to load + tasks += boost::bind(&Graphics::loadPaletteAndColors,this); tasks += boost::bind(&Graphics::loadHeroFlags,this); tasks += boost::bind(&Graphics::loadHeroPortraits,this); tasks += GET_SURFACE(hInfo,"HEROQVBK.bmp"); @@ -339,4 +370,80 @@ SDL_Surface * Graphics::getPic(int ID, bool fort, bool builded) pom--; return smallIcons->ourImages[pom].bitmap; } +} + +void Graphics::blueToPlayersAdv(SDL_Surface * sur, int player) +{ + if(player==1) //it is actually blue... + return; + if(sur->format->BitsPerPixel == 8) + { + for(int i=0; i<32; ++i) + { + sur->format->palette->colors[224+i] = playerColorPalette[32*player+i]; + } + } + else if(sur->format->BitsPerPixel == 24) //should never happen in general + { + for(int y=0; yh; ++y) + { + for(int x=0; xw; ++x) + { + Uint8* cp = (Uint8*)sur->pixels + y*sur->pitch + x*3; + if(SDL_BYTEORDER == SDL_BIG_ENDIAN) + { + if(cp[2]>cp[1] && cp[2]>cp[0]) + { + std::vector sort1; + sort1.push_back(cp[0]); + sort1.push_back(cp[1]); + sort1.push_back(cp[2]); + std::vector< std::pair > sort2; + sort2.push_back(std::make_pair(graphics->playerColors[player].r, &(cp[0]))); + sort2.push_back(std::make_pair(graphics->playerColors[player].g, &(cp[1]))); + sort2.push_back(std::make_pair(graphics->playerColors[player].b, &(cp[2]))); + std::sort(sort1.begin(), sort1.end()); + if(sort2[0].first>sort2[1].first) + std::swap(sort2[0], sort2[1]); + if(sort2[1].first>sort2[2].first) + std::swap(sort2[1], sort2[2]); + if(sort2[0].first>sort2[1].first) + std::swap(sort2[0], sort2[1]); + for(int hh=0; hh<3; ++hh) + { + (*sort2[hh].second) = (sort1[hh] + sort2[hh].first)/2.2; + } + } + } + else + { + if( + (/*(mode==0) && (cp[0]>cp[1]) && (cp[0]>cp[2])) || + ((mode==1) &&*/ (cp[2]<45) && (cp[0]>80) && (cp[1]<70) && ((cp[0]-cp[1])>40)) + ) + { + std::vector sort1; + sort1.push_back(cp[2]); + sort1.push_back(cp[1]); + sort1.push_back(cp[0]); + std::vector< std::pair > sort2; + sort2.push_back(std::make_pair(graphics->playerColors[player].r, &(cp[2]))); + sort2.push_back(std::make_pair(graphics->playerColors[player].g, &(cp[1]))); + sort2.push_back(std::make_pair(graphics->playerColors[player].b, &(cp[0]))); + std::sort(sort1.begin(), sort1.end()); + if(sort2[0].first>sort2[1].first) + std::swap(sort2[0], sort2[1]); + if(sort2[1].first>sort2[2].first) + std::swap(sort2[1], sort2[2]); + if(sort2[0].first>sort2[1].first) + std::swap(sort2[0], sort2[1]); + for(int hh=0; hh<3; ++hh) + { + (*sort2[hh].second) = (sort1[hh]*0.8 + sort2[hh].first)/2; + } + } + } + } + } + } } \ No newline at end of file diff --git a/client/VCMI_client.vcproj b/client/VCMI_client.vcproj index 7239c57ed..a5ee95d9b 100644 --- a/client/VCMI_client.vcproj +++ b/client/VCMI_client.vcproj @@ -41,6 +41,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="G:\vcmt\repa\include" + GeneratePreprocessedFile="0" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -304,10 +305,6 @@ RelativePath="..\CGameInterface.cpp" > - - @@ -384,10 +381,6 @@ RelativePath="..\SDL_framerate.cpp" > - - @@ -598,10 +591,6 @@ RelativePath="..\CGameInterface.h" > - - @@ -694,10 +683,6 @@ RelativePath="..\SDL_framerate.h" > - - diff --git a/global.h b/global.h index 17a8f6549..f49cddd6e 100644 --- a/global.h +++ b/global.h @@ -41,6 +41,8 @@ extern CGameInfo* CGI; #define LOGE(x) ; #endif +#define NAME_VER ("VCMI \"Altanatse\" 0.7") + const int F_NUMBER = 9; //factions (town types) quantity const int PLAYER_LIMIT = 8; //player limit per map const int HEROES_PER_TYPE=8; //amount of heroes of each type diff --git a/hch/CDefObjInfoHandler.cpp b/hch/CDefObjInfoHandler.cpp index 9474b1b27..fb51a6987 100644 --- a/hch/CDefObjInfoHandler.cpp +++ b/hch/CDefObjInfoHandler.cpp @@ -4,6 +4,7 @@ #include "../CGameInfo.h" #include "CLodHandler.h" #include +#include "../lib/VCMI_Lib.h" extern CLodHandler * bitmaph; bool CGDefInfo::isVisitable() { @@ -20,6 +21,7 @@ CGDefInfo::CGDefInfo() } void CDefObjInfoHandler::load() { + VLC->dobjinfo = this; nodrze ideki; std::istringstream inp(bitmaph->getTextFile("ZOBJCTS.TXT")); int objNumber; @@ -58,8 +60,8 @@ void CDefObjInfoHandler::load() } } - for(int yy=0; yy<2; ++yy) - inp>>dump; + for(int yy=0; yy<2; ++yy) //first - on which types of terrain object can be placed; + inp>>dump; //second -in which terrains' menus object in the editor will be available (?) inp>>nobj->id; inp>>nobj->subid; inp>>nobj->type; diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index dd5e65572..1a5550c02 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -3,6 +3,7 @@ #include "CHeroHandler.h" #include #include "CLodHandler.h" +#include "../lib/VCMI_Lib.h" extern CLodHandler * bitmaph; void loadToIt(std::string &dest, std::string &src, int &iter, int mode); CHeroHandler::~CHeroHandler() @@ -20,6 +21,7 @@ void CHeroHandler::loadPortraits() } void CHeroHandler::loadHeroes() { + VLC->heroh = this; int ID=0; std::string buf = bitmaph->getTextFile("HOTRAITS.TXT"); int it=0; diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index c1b29519c..1c4e63549 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -13,6 +13,7 @@ DLL_EXPORT void loadToIt(std::string &dest, std::string &src, int &iter, int mod extern CLodHandler * bitmaph; void CObjectHandler::loadObjects() { + VLC->objh = this; int ID=0; std::string buf = bitmaph->getTextFile("OBJNAMES.TXT"); int it=0; diff --git a/hch/CSpellHandler.cpp b/hch/CSpellHandler.cpp index d31dc73b2..244969e48 100644 --- a/hch/CSpellHandler.cpp +++ b/hch/CSpellHandler.cpp @@ -1,4 +1,4 @@ -#include "../stdafx.h" + #include "../stdafx.h" #include "CSpellHandler.h" #include "../CGameInfo.h" #include "CLodHandler.h" diff --git a/hch/CTownHandler.cpp b/hch/CTownHandler.cpp index 91943cd43..a2648587f 100644 --- a/hch/CTownHandler.cpp +++ b/hch/CTownHandler.cpp @@ -3,10 +3,13 @@ #include "CTownHandler.h" #include "CLodHandler.h" #include +#include "../lib/VCMI_Lib.h" extern CLodHandler * bitmaph; void loadToIt(std::string &dest, std::string &src, int &iter, int mode); CTownHandler::CTownHandler() -{} +{ + VLC->townh = this; +} CTownHandler::~CTownHandler() {} void CTownHandler::loadNames() diff --git a/lib/VCMI_Lib.h b/lib/VCMI_Lib.h index 2bbcdafa2..b569b6e7a 100644 --- a/lib/VCMI_Lib.h +++ b/lib/VCMI_Lib.h @@ -3,18 +3,18 @@ //class CMapHandler; class CArtHandler; -//class CHeroHandler; +class CHeroHandler; class CCreatureHandler; //class CAbilityHandler; //class CSpellHandler; //class CAmbarCendamo; //class CPreGameTextHandler; //class CBuildingHandler; -//class CObjectHandler; +class CObjectHandler; //class CMusicHandler; //class CSemiLodHandler; class CDefObjInfoHandler; -//class CTownHandler; +class CTownHandler; //class CGeneralTextHandler; //class CConsoleHandler; //class CPathfinder; @@ -31,18 +31,18 @@ class LibClasses public: //CGameState * state; CArtHandler * arth; - //CHeroHandler * heroh; + CHeroHandler * heroh; CCreatureHandler * creh; //CAbilityHandler * abilh; //CSpellHandler * spellh; //CMapHandler * mh; //CPreGameTextHandler * preth; //CBuildingHandler * buildh; - //CObjectHandler * objh; + CObjectHandler * objh; //CMusicHandler * mush; //CSemiLodHandler * sspriteh; CDefObjInfoHandler * dobjinfo; - //CTownHandler * townh; + CTownHandler * townh; //CGeneralTextHandler * generaltexth; //CConsoleHandler * consoleh; //CPathfinder * pathf; diff --git a/lib/VCMI_lib.vcproj b/lib/VCMI_lib.vcproj index 0d46c51af..0d1c12fb8 100644 --- a/lib/VCMI_lib.vcproj +++ b/lib/VCMI_lib.vcproj @@ -326,8 +326,6 @@ + + @@ -403,6 +405,10 @@ RelativePath="..\hch\CDefObjInfoHandler.h" > + + diff --git a/map.cpp b/map.cpp index 11a1f0e26..461867fcc 100644 --- a/map.cpp +++ b/map.cpp @@ -947,7 +947,6 @@ Mapa::Mapa(unsigned char * bufor) //////READING DEF INFO/////// int defAmount = readNormalNr(bufor,i); i+=4; defy.reserve(defAmount); - for (int idd = 0 ; iddmovement = -1; if(nhi->ID==34) heroes.push_back(nhi); - //else - // CGI->objh->objInstances.push_back(nhi); - break; } case CREATURES_DEF: @@ -1860,7 +1856,8 @@ Mapa::Mapa(unsigned char * bufor) nt->builded = 0; nt->destroyed = 0; nt->garrisonHero = NULL; - towns.push_back(nt); + if(nt->ID=98) + towns.push_back(nt); break; } case EDefType::PLAYERONLY_DEF: @@ -2290,4 +2287,13 @@ borderguardend: //map readed, bufor no longer needed delete[] bufor; bufor=NULL; +} +CGHeroInstance * Mapa::getHero(int ID, int mode) +{ + if (mode != 0) + throw new std::exception("gs->getHero: This mode is not supported!"); + for(int i=0; isubID == ID) + return heroes[i]; + return NULL; } \ No newline at end of file diff --git a/map.h b/map.h index 5c0f24b5f..3de6a6900 100644 --- a/map.h +++ b/map.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "global.h" class CGDefInfo; class CGObjectInstance; @@ -363,40 +364,6 @@ public: int firstOccurence; int nextOccurence; //after nextOccurance day event will occure; if it it 0, event occures only one time; }; -struct DLL_EXPORT Mapa -{ - Eformat version; // version of map Eformat - int twoLevel; // if map has underground level - int difficulty; // 0 easy - 4 impossible - int levelLimit; - bool areAnyPLayers; // if there are any playable players on map - std::string name; //name of map - std::string description; //and description - int height, width; - TerrainTile** terrain; - TerrainTile** undergroungTerrain; // used only if there is underground level - std::vector rumors; - std::vector disposedHeroes; - std::vector predefinedHeroes; - std::vector defy; // list of .def files - PlayerInfo players[8]; // info about players - std::vector teams; // teams[i] = team of player no i - LossCondition lossCondition; - EvictoryConditions victoryCondition; //victory conditions - CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard - int howManyTeams; - 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; - - Mapa(unsigned char * bufor); //creates map from decompressed .h3m data -}; class DLL_EXPORT CMapHeader { public: @@ -478,4 +445,40 @@ public: }; mapSorter(ESortBy es):sortBy(es){}; }; +struct DLL_EXPORT Mapa +{ + Eformat version; // version of map Eformat + int twoLevel; // if map has underground level + int difficulty; // 0 easy - 4 impossible + int levelLimit; + bool areAnyPLayers; // if there are any playable players on map + std::string name; //name of map + std::string description; //and description + int height, width; + TerrainTile** terrain; + TerrainTile** undergroungTerrain; // used only if there is underground level + std::vector rumors; + std::vector disposedHeroes; + std::vector predefinedHeroes; + std::vector defy; // list of .def files with definitions from .h3m (may be custom) + std::set defs; // other defInfos - for randomized objects, objects added or modified by script + PlayerInfo players[8]; // info about players + std::vector teams; // teams[i] = team of player no i + LossCondition lossCondition; + EvictoryConditions victoryCondition; //victory conditions + CspecificVictoryConidtions * vicConDetails; // used only if vistory conditions aren't standard + int howManyTeams; + 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; + + Mapa(unsigned char * bufor); //creates map from decompressed .h3m data + CGHeroInstance * getHero(int ID, int mode=0); +}; #endif //MAPD_H diff --git a/mapHandler.cpp b/mapHandler.cpp index ae9164a8f..fb8a40ca5 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -1,9 +1,8 @@ #include "stdafx.h" #include "mapHandler.h" -#include "SDL_rotozoom.h" #include "SDL_Extensions.h" #include "CGameInfo.h" -#include "stdlib.h" +#include #include "hch\CLodHandler.h" #include "hch\CDefObjInfoHandler.h" #include @@ -11,7 +10,6 @@ #include "CLua.h" #include "hch\CHeroHandler.h" #include "hch\CTownHandler.h" -#include "hch\CArtHandler.h" #include "client\Graphics.h" #include #include @@ -87,262 +85,10 @@ void alphaTransformDef(CGDefInfo * defInfo) for(int yy=0;yyhandler->ourImages.size();yy++) { defInfo->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(defInfo->handler->ourImages[yy].bitmap); - //SDL_Surface * bufs = CSDL_Ext::secondAlphaTransform(defInfo->handler->ourImages[yy].bitmap, alphaTransSurf); - //SDL_FreeSurface(defInfo->handler->ourImages[yy].bitmap); - //defInfo->handler->ourImages[yy].bitmap = bufs; defInfo->handler->alphaTransformed = true; } SDL_FreeSurface(alphaTransSurf); } -int CMapHandler::pickHero(int owner) -{ - int h; - if(usedHeroes.find(h = CGI->scenarioOps.getIthPlayersSettings(owner).hero)==usedHeroes.end() && h>=0) //we haven't used selected hero - { - usedHeroes.insert(h); - return h; - } - int f = CGI->scenarioOps.getIthPlayersSettings(owner).castle; - int i=0; - do //try to find free hero of our faction - { - i++; - h = CGI->scenarioOps.getIthPlayersSettings(owner).castle*HEROES_PER_TYPE*2+(rand()%(HEROES_PER_TYPE*2));//cgi->scenarioOps.playerInfos[pru].hero = cgi-> - } while((usedHeroes.find(h)!=usedHeroes.end()) && i<175); - if(i>174) //probably no free heroes - there's no point in further search, we'll take first free - { - for(int j=0; j CMapHandler::pickObject(CGObjectInstance *obj) -{ - switch(obj->ID) - { - case 65: //random artifact - return std::pair(5,(rand()%136)+7); //tylko sensowny zakres - na poczatku sa katapulty itp, na koncu specjalne i blanki - case 66: //random treasure artifact - return std::pair(5,CGI->arth->treasures[rand()%CGI->arth->treasures.size()]->id); - case 67: //random minor artifact - return std::pair(5,CGI->arth->minors[rand()%CGI->arth->minors.size()]->id); - case 68: //random major artifact - return std::pair(5,CGI->arth->majors[rand()%CGI->arth->majors.size()]->id); - case 69: //random relic artifact - return std::pair(5,CGI->arth->relics[rand()%CGI->arth->relics.size()]->id); - case 70: //random hero - { - return std::pair(34,pickHero(obj->tempOwner)); - } - case 71: //random monster - return std::pair(54,rand()%(CGI->creh->creatures.size())); - case 72: //random monster lvl1 - return std::pair(54,CGI->creh->levelCreatures[1][rand()%CGI->creh->levelCreatures[1].size()]->idNumber); - case 73: //random monster lvl2 - return std::pair(54,CGI->creh->levelCreatures[2][rand()%CGI->creh->levelCreatures[2].size()]->idNumber); - case 74: //random monster lvl3 - return std::pair(54,CGI->creh->levelCreatures[3][rand()%CGI->creh->levelCreatures[3].size()]->idNumber); - case 75: //random monster lvl4 - return std::pair(54,CGI->creh->levelCreatures[4][rand()%CGI->creh->levelCreatures[4].size()]->idNumber); - case 76: //random resource - return std::pair(79,rand()%7); //now it's OH3 style, use %8 for mithril - case 77: //random town - { - int align = ((CGTownInstance*)obj)->alignment, - f; - if(align>PLAYER_LIMIT-1)//same as owner / random - { - if(obj->tempOwner > PLAYER_LIMIT-1) - f = -1; //random - else - f = CGI->scenarioOps.getIthPlayersSettings(obj->tempOwner).castle; - } - else - { - f = CGI->scenarioOps.getIthPlayersSettings(align).castle; - } - if(f<0) f = rand()%CGI->townh->towns.size(); - return std::pair(98,f); - } - case 162: //random monster lvl5 - return std::pair(54,CGI->creh->levelCreatures[5][rand()%CGI->creh->levelCreatures[5].size()]->idNumber); - case 163: //random monster lvl6 - return std::pair(54,CGI->creh->levelCreatures[6][rand()%CGI->creh->levelCreatures[6].size()]->idNumber); - case 164: //random monster lvl7 - return std::pair(54,CGI->creh->levelCreatures[7][rand()%CGI->creh->levelCreatures[7].size()]->idNumber); - case 216: //random dwelling - { - int faction = rand()%F_NUMBER; - CCreGen2ObjInfo* info =(CCreGen2ObjInfo*)obj->info; - if (info->asCastle) - { - for(int i=0;iobjects.size();i++) - { - if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i])->identifier == info->identifier) - { - randomizeObject(map->objects[i]); //we have to randomize the castle first - faction = map->objects[i]->subID; - break; - } - else if(map->objects[i]->ID==98 && dynamic_cast(map->objects[i])->identifier == info->identifier) - { - faction = map->objects[i]->subID; - break; - } - } - } - else - { - while((!(info->castles[0]&(1<7) && (info->castles[1]&(1<<(faction-8)))) - break; - faction = rand()%F_NUMBER; - } - } - int level = ((info->maxLevel-info->minLevel) ? (rand()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel)); - int cid = CGI->townh->towns[faction].basicCreatures[level]; - for(int i=0;iobjh->cregens.size();i++) - if(CGI->objh->cregens[i]==cid) - return std::pair(17,i); - std::cout << "Cannot find a dwelling for creature "<(17,0); - } - case 217: - { - int faction = rand()%F_NUMBER; - CCreGenObjInfo* info =(CCreGenObjInfo*)obj->info; - if (info->asCastle) - { - for(int i=0;iobjects.size();i++) - { - if(map->objects[i]->ID==77 && dynamic_cast(map->objects[i])->identifier == info->identifier) - { - randomizeObject(map->objects[i]); //we have to randomize the castle first - faction = map->objects[i]->subID; - break; - } - else if(map->objects[i]->ID==98 && dynamic_cast(map->objects[i])->identifier == info->identifier) - { - faction = map->objects[i]->subID; - break; - } - } - } - else - { - while((!(info->castles[0]&(1<7) && (info->castles[1]&(1<<(faction-8)))) - break; - faction = rand()%F_NUMBER; - } - } - int cid = CGI->townh->towns[faction].basicCreatures[obj->subID]; - for(int i=0;iobjh->cregens.size();i++) - if(CGI->objh->cregens[i]==cid) - return std::pair(17,i); - std::cout << "Cannot find a dwelling for creature "<(17,0); - } - case 218: - { - CCreGen3ObjInfo* info =(CCreGen3ObjInfo*)obj->info; - int level = ((info->maxLevel-info->minLevel) ? (rand()%(info->maxLevel-info->minLevel)+info->minLevel) : (info->minLevel)); - int cid = CGI->townh->towns[obj->subID].basicCreatures[level]; - for(int i=0;iobjh->cregens.size();i++) - if(CGI->objh->cregens[i]==cid) - return std::pair(17,i); - std::cout << "Cannot find a dwelling for creature "<(17,0); - } - } - return std::pair(-1,-1); -} -void CMapHandler::randomizeObject(CGObjectInstance *cur) -{ - std::pair ran = pickObject(cur); - if(ran.first<0 || ran.second<0) //this is not a random object, or we couldn't find anything - { - if(cur->ID==98) //town - set def - { - CGTownInstance *t = dynamic_cast(cur); - if(t->hasCapitol()) - t->defInfo = capitols[t->subID]; - else if(t->hasFort()) - t->defInfo = CGI->dobjinfo->castles[t->subID]; - else - t->defInfo = villages[t->subID]; - if(!t->defInfo->handler) - { - t->defInfo->handler = CDefHandler::giveDef(t->defInfo->name); - t->defInfo->width = t->defInfo->handler->ourImages[0].bitmap->w/32; - t->defInfo->height = t->defInfo->handler->ourImages[0].bitmap->h/32; - alphaTransformDef(t->defInfo); - } - } - return; - } - else if(ran.first==34)//special code for hero - { - CGHeroInstance *h = dynamic_cast(cur); - if(!h) {std::cout<<"Wrong random hero at "<pos<ID = ran.first; - cur->subID = ran.second; - h->type = CGI->heroh->heroes[ran.second]; - 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 - { - CGTownInstance *t = dynamic_cast(cur); - if(!t) {std::cout<<"Wrong random town at "<pos<ID = ran.first; - cur->subID = ran.second; - t->town = &CGI->townh->towns[ran.second]; - if(t->hasCapitol()) - t->defInfo = capitols[t->subID]; - else if(t->hasFort()) - t->defInfo = CGI->dobjinfo->castles[t->subID]; - else - t->defInfo = villages[t->subID]; - if(!t->defInfo->handler) - { - t->defInfo->handler = CDefHandler::giveDef(t->defInfo->name); - t->defInfo->width = t->defInfo->handler->ourImages[0].bitmap->w/32; - t->defInfo->height = t->defInfo->handler->ourImages[0].bitmap->h/32; - alphaTransformDef(t->defInfo); - } - //CGI->townh->townInstances.push_back(t); - return; - } - //we have to replace normal random object - cur->ID = ran.first; - cur->subID = ran.second; - cur->defInfo = CGI->dobjinfo->gobjs[ran.first][ran.second]; - if(!cur->defInfo){std::cout<<"Missing def declaration for "<ID<<" "<subID<defInfo->handler) //if we have to load def - { - cur->defInfo->handler = CDefHandler::giveDef(cur->defInfo->name); - cur->defInfo->width = cur->defInfo->handler->ourImages[0].bitmap->w/32; - cur->defInfo->height = cur->defInfo->handler->ourImages[0].bitmap->h/32; - alphaTransformDef(cur->defInfo); - } - -} -void CMapHandler::randomizeObjects() -{ - CGObjectInstance * cur; - for(int no=0; noobjects.size(); ++no) - { - randomizeObject(map->objects[no]); - if(map->objects[no]->ID==26) - map->objects[no]->defInfo->handler=NULL; - } -} void CMapHandler::prepareFOWDefs() { fullHide = CDefHandler::giveDef("TSHRC.DEF"); @@ -399,43 +145,35 @@ void CMapHandler::prepareFOWDefs() // visibility[gg][jj] = true; //} - visibility.resize(CGI->mh->map->width, Woff); - for (int i=0-Woff;imh->map->height,Hoff); - } - for (int i=0-Woff; imh->map->height+Hoff; ++j) - { - visibility[i][j].resize(CGI->mh->map->twoLevel+1,0); - for(int k=0; kmh->map->twoLevel+1; ++k) - visibility[i][j][k]=true; - } - } + //visibility.resize(CGI->mh->map->width, Woff); + //for (int i=0-Woff;imh->map->height,Hoff); + //} + //for (int i=0-Woff; imh->map->height+Hoff; ++j) + // { + // visibility[i][j].resize(CGI->mh->map->twoLevel+1,0); + // for(int k=0; kmh->map->twoLevel+1; ++k) + // visibility[i][j][k]=true; + // } + //} - hideBitmap.resize(CGI->mh->map->width, Woff); - for (int i=0-Woff;imh->map->width); + for (int i=0;imh->map->height,Hoff); + hideBitmap[i].resize(CGI->mh->map->height); } - for (int i=0-Woff; imh->map->height+Hoff; ++j) + for (int j=0; jmh->map->height; ++j) { - hideBitmap[i][j].resize(CGI->mh->map->twoLevel+1,0); + hideBitmap[i][j].resize(CGI->mh->map->twoLevel+1); for(int k=0; kmh->map->twoLevel+1; ++k) hideBitmap[i][j][k] = rand()%fullHide->ourImages.size(); } } - - //visibility[6][7][1] = false; - //visibility[7][7][1] = false; - //visibility[6][8][1] = false; - //visibility[6][6][1] = false; - //visibility[5][8][1] = false; - //visibility[7][6][1] = false; - //visibility[6][9][1] = false; } void CMapHandler::roadsRiverTerrainInit() @@ -464,9 +202,6 @@ void CMapHandler::roadsRiverTerrainInit() } } - //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->mh->map->width; sizes.y = CGI->mh->map->height; sizes.z = CGI->mh->map->twoLevel+1; @@ -615,10 +350,6 @@ void CMapHandler::roadsRiverTerrainInit() } void CMapHandler::borderAndTerrainBitmapInit() { - //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 = CDefHandler::giveDef("EDG.DEF"); bord->notFreeImgs = true; for (int i=0-Woff; iwidth+Woff; i++) //jest po szerokości @@ -807,73 +538,59 @@ void CMapHandler::calculateBlockedPos() } } } +void processDef (CGDefInfo* def) +{ + def->handler=CDefHandler::giveDef(def->name); + def->width = def->handler->ourImages[0].bitmap->w/32; + def->height = def->handler->ourImages[0].bitmap->h/32; + CGDefInfo* pom = CGI->dobjinfo->gobjs[def->id][def->subid]; + if(pom) + { + pom->handler = def->handler; + pom->width = pom->handler->ourImages[0].bitmap->w/32; + pom->height = pom->handler->ourImages[0].bitmap->h/32; + } + else + std::cout << "\t\tMinor warning: lacking def info for " << def->id << " " << def->subid <<" " << def->name << std::endl; + if(!def->handler->alphaTransformed) + { + for(int yy=0; yyhandler->ourImages.size(); ++yy) + { + def->handler->ourImages[yy].bitmap = CSDL_Ext::alphaTransform(def->handler->ourImages[yy].bitmap); + def->handler->alphaTransformed = true; + } + } +} void CMapHandler::init() { timeHandler th; th.getDif(); - - ///loading defs from lod - for (int ir=0;irdefy.size();ir++) - { - map->defy[ir]->handler=CDefHandler::giveDef(map->defy[ir]->name); - map->defy[ir]->width = map->defy[ir]->handler->ourImages[0].bitmap->w/32; - map->defy[ir]->height = map->defy[ir]->handler->ourImages[0].bitmap->h/32; - CGDefInfo* pom = CGI->dobjinfo->gobjs[map->defy[ir]->id][map->defy[ir]->subid]; - if(pom) - { - pom->handler=map->defy[ir]->handler; - pom->width = pom->handler->ourImages[0].bitmap->w/32; - pom->height = pom->handler->ourImages[0].bitmap->h/32; - } - 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; - } - } + std::for_each(map->defy.begin(),map->defy.end(),processDef); //load h3m defs + std::for_each(map->defs.begin(),map->defs.end(),processDef); //and non-h3m defs THC std::cout<<"\tUnpacking and handling defs: "<>ccc; - for(int i=0;idobjinfo->castles[i%ccc]); - ifs >> n->name; - if (!(n->handler = CDefHandler::giveDef(n->name))) - std::cout << "Cannot open "<name<width = n->handler->ourImages[0].bitmap->w/32; - n->height = n->handler->ourImages[0].bitmap->h/32; - } - if(i>ccc; + //for(int i=0;idobjinfo->castles[i%ccc]); + // ifs >> n->name; + // if (!(n->handler = CDefHandler::giveDef(n->name))) + // std::cout << "Cannot open "<name<width = n->handler->ourImages[0].bitmap->w/32; + // n->height = n->handler->ourImages[0].bitmap->h/32; + // } + // if(iscenarioOps.playerInfos.size();i++) - { - if(CGI->scenarioOps.playerInfos[i].castle==-1) - { - int f; - do - { - f = rand()%F_NUMBER; - }while(!(map->players[CGI->scenarioOps.playerInfos[i].color].allowedFactions & 1<scenarioOps.playerInfos[i].castle = f; - } - } for(int i=0;iplayers[i].heroesNames.size();j++) @@ -884,15 +601,9 @@ void CMapHandler::init() std::cout<<"\tLoading town defs, picking random factions and heroes: "<defy.size(); ++h) //initializing loaded def handler's info - { - //std::string hlp = map->defy[h]->name; - //std::transform(hlp.begin(), hlp.end(), hlp.begin(), (int(*)(int))toupper); + for(int h=0; hdefy.size(); ++h) //initializing loaded def handler's info { CGI->mh->loadedDefs.insert(std::make_pair(map->defy[h]->name, map->defy[h]->handler)); - } std::cout<<"\tCollecting loaded def's handlers: "<players[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==RoE)) - { - int3 hpos = map->players[i].posOfMainTown; - hpos.x+=1;// hpos.y+=1; - int j; - for(j=0;jscenarioOps.playerInfos.size();j++) - if(CGI->scenarioOps.playerInfos[j].color==i) - break; - if(j==CGI->scenarioOps.playerInfos.size()) - continue; - int h; //= CGI->scenarioOps.playerInfos[j].hero; - //if(h<0) - h=pickHero(i); - CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,h,hpos,i); - nnn->defInfo->handler = graphics->flags1[0]; - map->heroes.push_back(nnn); - map->objects.push_back(nnn); - } - } + //for(int i=0;iplayers[i].generateHeroAtMainTown && map->players[i].hasMainTown) || (map->players[i].hasMainTown && map->version==RoE)) + // { + // int3 hpos = map->players[i].posOfMainTown; + // hpos.x+=1;// hpos.y+=1; + // int j; + // for(j=0;jstate->scenarioOps->playerInfos.size();j++) + // if(CGI->state->scenarioOps->playerInfos[j].color==i) + // break; + // if(j==CGI->state->scenarioOps->playerInfos.size()) + // continue; + // int h=pickHero(i); + // CGHeroInstance * nnn = (CGHeroInstance*)createObject(34,h,hpos,i); + // nnn->defInfo->handler = graphics->flags1[0]; + // map->heroes.push_back(nnn); + // map->objects.push_back(nnn); + // } + //} std::cout<<"\tGiving starting heroes: "< > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect) +SDL_Surface * CMapHandler::terrainRect(int x, int y, int dx, int dy, int level, unsigned char anim, std::vector< std::vector< std::vector > > & visibilityMap, bool otherHeroAnim, unsigned char heroAnim, SDL_Surface * extSurf, SDL_Rect * extRect) { if(!otherHeroAnim) heroAnim = anim; //the same, as it should be @@ -1200,250 +909,261 @@ SDL_Surface * CMapHandler::undTerrBitmap(int x, int y) return ttiles[x+Woff][y+Hoff][0].terbitmap[1]; } -SDL_Surface * CMapHandler::getVisBitmap(int x, int y, PseudoV< PseudoV< PseudoV > > & visibilityMap, int lvl) +SDL_Surface * CMapHandler::getVisBitmap(int x, int y, std::vector< std::vector< std::vector > > & visibilityMap, int lvl) { - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + int size = visibilityMap.size()-1; //is tile visible. arrangement: (like num keyboard) + bool d7 = (x>0 && y>0) ? visibilityMap[x-1][y-1][lvl] : 0, //789 + d8 = (y>0) ? visibilityMap[x][y-1][lvl] : 0, //456 + d9 = (y>0 && x0) ? visibilityMap[x-1][y][lvl] : 0, + d5 = visibilityMap[x][y][lvl], + d6 = (x0 && yourImages[hideBitmap[x][y][lvl]].bitmap; //fully hidden } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + else if(!d2 && !d6 && !d4 && !d8 && !d7 && d3 && !d9 && !d1) { return partialHide->ourImages[22].bitmap; //visible right bottom corner } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + else if(!d2 && !d6 && !d4 && !d8 && !d7 && !d3 && d9 && !d1) { return partialHide->ourImages[15].bitmap; //visible right top corner } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + else if(!d2 && !d6 && !d4 && !d8 && !d7 && !d3 && !d9 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[22].bitmap); //visible left bottom corner return partialHide->ourImages[34].bitmap; //visible left bottom corner } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + else if(!d2 && !d6 && !d4 && !d8 && d7 && !d3 && !d9 && !d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[15].bitmap); //visible left top corner return partialHide->ourImages[35].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + else if(!d2 && !d6 && !d4 && d8 && d7 && !d3 && d9 && !d1) { //return partialHide->ourImages[rand()%2].bitmap; //visible top return partialHide->ourImages[0].bitmap; //visible top } - else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + else if(d2 && !d6 && !d4 && !d8 && !d7 && d3 && !d9 && d1) { //return partialHide->ourImages[4+rand()%2].bitmap; //visble bottom return partialHide->ourImages[4].bitmap; //visble bottom } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + else if(!d2 && !d6 && d4 && !d8 && d7 && !d3 && !d9 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[2+rand()%2].bitmap); //visible left //return CSDL_Ext::rotate01(partialHide->ourImages[2].bitmap); //visible left return partialHide->ourImages[36].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + else if(!d2 && d6 && !d4 && !d8 && !d7 && d3 && d9 && !d1) { //return partialHide->ourImages[2+rand()%2].bitmap; //visible right return partialHide->ourImages[2].bitmap; //visible right } - else if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl]) + else if(d2 && d6 && !d4 && !d8 && !d7) { //return partialHide->ourImages[12+2*(rand()%2)].bitmap; //visible bottom, right - bottom, right; left top corner hidden return partialHide->ourImages[12].bitmap; //visible bottom, right - bottom, right; left top corner hidden } - else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + else if(!d2 && d6 && !d4 && d8 && !d1) { return partialHide->ourImages[13].bitmap; //visible right, right - top; left bottom corner hidden } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y+1][lvl]) + else if(!d2 && !d6 && d4 && d8 && !d3) { //return CSDL_Ext::rotate01(partialHide->ourImages[13].bitmap); //visible top, top - left, left; right bottom corner hidden return partialHide->ourImages[37].bitmap; } - else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y-1][lvl]) + else if(d2 && !d6 && d4 && !d8 && !d9) { //return CSDL_Ext::rotate01(partialHide->ourImages[12+2*(rand()%2)].bitmap); //visible left, left - bottom, bottom; right top corner hidden //return CSDL_Ext::rotate01(partialHide->ourImages[12].bitmap); //visible left, left - bottom, bottom; right top corner hidden return partialHide->ourImages[38].bitmap; } - else if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) + else if(d2 && d6 && d4 && d8) { return partialHide->ourImages[10].bitmap; //visible left, right, bottom and top } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && !d7 && d3 && d9 && !d1) { return partialHide->ourImages[16].bitmap; //visible right corners } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && !d3 && d9 && !d1) { return partialHide->ourImages[18].bitmap; //visible top corners } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && !d3 && !d9 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[16].bitmap); //visible left corners return partialHide->ourImages[39].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && !d7 && d3 && !d9 && d1) { //return CSDL_Ext::hFlip(partialHide->ourImages[18].bitmap); //visible bottom corners return partialHide->ourImages[40].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && !d7 && !d3 && d9 && d1) { return partialHide->ourImages[17].bitmap; //visible right - top and bottom - left corners } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && d3 && !d9 && !d1) { //return CSDL_Ext::hFlip(partialHide->ourImages[17].bitmap); //visible top - left and bottom - right corners return partialHide->ourImages[41].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && !d7 && d3 && d9 && d1) { return partialHide->ourImages[19].bitmap; //visible corners without left top } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && d3 && d9 && !d1) { return partialHide->ourImages[20].bitmap; //visible corners without left bottom } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && !d3 && d9 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[20].bitmap); //visible corners without right bottom return partialHide->ourImages[42].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && d3 && !d9 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[19].bitmap); //visible corners without right top return partialHide->ourImages[43].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && !d8 && d7 && d3 && d9 && d1) { return partialHide->ourImages[21].bitmap; //visible all corners only } - if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl]) + if(d2 && d6 && d4 && !d8) { return partialHide->ourImages[6].bitmap; //hidden top } - if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) + if(d2 && !d6 && d4 && d8) { return partialHide->ourImages[7].bitmap; //hidden right } - if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) + if(!d2 && d6 && d4 && d8) { return partialHide->ourImages[8].bitmap; //hidden bottom } - if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) + if(d2 && d6 && !d4 && d8) { //return CSDL_Ext::rotate01(partialHide->ourImages[7].bitmap); //hidden left return partialHide->ourImages[44].bitmap; } - if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl]) + if(!d2 && d6 && d4 && !d8) { return partialHide->ourImages[9].bitmap; //hidden top and bottom } - if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl]) + if(d2 && !d6 && !d4 && d8) { return partialHide->ourImages[29].bitmap; //hidden left and right } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && d8 && d3 && !d1) { return partialHide->ourImages[24].bitmap; //visible top and right bottom corner } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && d8 && !d3 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[24].bitmap); //visible top and left bottom corner return partialHide->ourImages[45].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && !d6 && !d4 && d8 && d3 && d1) { return partialHide->ourImages[33].bitmap; //visible top and bottom corners } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl]) + if(!d2 && !d6 && d4 && !d8 && !d3 && d9) { //return CSDL_Ext::rotate01(partialHide->ourImages[26].bitmap); //visible left and right top corner return partialHide->ourImages[46].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl]) + if(!d2 && !d6 && d4 && !d8 && d3 && !d9) { //return CSDL_Ext::rotate01(partialHide->ourImages[25].bitmap); //visible left and right bottom corner return partialHide->ourImages[47].bitmap; } - if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl]) + if(!d2 && !d6 && d4 && !d8 && d3 && d9) { return partialHide->ourImages[32].bitmap; //visible left and right corners } - if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y-1][lvl]) + if(d2 && !d6 && !d4 && !d8 && d7 && !d9) { //return CSDL_Ext::rotate01(partialHide->ourImages[30].bitmap); //visible bottom and left top corner return partialHide->ourImages[48].bitmap; } - if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y-1][lvl]) + if(d2 && !d6 && !d4 && !d8 && !d7 && d9) { return partialHide->ourImages[30].bitmap; //visible bottom and right top corner } - if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y-1][lvl]) + if(d2 && !d6 && !d4 && !d8 && d7 && d9) { return partialHide->ourImages[31].bitmap; //visible bottom and top corners } - if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && d6 && !d4 && !d8 && !d7 && d1) { return partialHide->ourImages[25].bitmap; //visible right and left bottom corner } - if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) + if(!d2 && d6 && !d4 && !d8 && d7 && !d1) { return partialHide->ourImages[26].bitmap; //visible right and left top corner } - if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + if(!d2 && d6 && !d4 && !d8 && d7 && d1) { //return CSDL_Ext::rotate01(partialHide->ourImages[32].bitmap); //visible right and left cornres return partialHide->ourImages[49].bitmap; } - if(visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl]) + if(d2 && d6 && !d4 && !d8 && d7) { return partialHide->ourImages[28].bitmap; //visible bottom, right - bottom, right; left top corner visible } - else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) + else if(!d2 && d6 && !d4 && d8 && d1) { return partialHide->ourImages[27].bitmap; //visible right, right - top; left bottom corner visible } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y+1][lvl]) + else if(!d2 && !d6 && d4 && d8 && d3) { //return CSDL_Ext::rotate01(partialHide->ourImages[27].bitmap); //visible top, top - left, left; right bottom corner visible return partialHide->ourImages[50].bitmap; } - else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x+1][y-1][lvl]) + else if(d2 && !d6 && d4 && !d8 && d9) { //return CSDL_Ext::rotate01(partialHide->ourImages[28].bitmap); //visible left, left - bottom, bottom; right top corner visible return partialHide->ourImages[51].bitmap; } //newly added - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible t and tr + else if(!d2 && !d6 && !d4 && d8 && !d7 && !d3 && d9 && !d1) //visible t and tr { return partialHide->ourImages[0].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible t and tl + else if(!d2 && !d6 && !d4 && d8 && d7 && !d3 && !d9 && !d1) //visible t and tl { return partialHide->ourImages[1].bitmap; } - else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible b and br + else if(d2 && !d6 && !d4 && !d8 && !d7 && d3 && !d9 && !d1) //visible b and br { return partialHide->ourImages[4].bitmap; } - else if(visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) //visible b and bl + else if(d2 && !d6 && !d4 && !d8 && !d7 && !d3 && !d9 && d1) //visible b and bl { return partialHide->ourImages[5].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible l and tl + else if(!d2 && !d6 && d4 && !d8 && d7 && !d3 && !d9 && !d1) //visible l and tl { return partialHide->ourImages[36].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && !visibilityMap[x+1][y][lvl] && visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && visibilityMap[x-1][y+1][lvl]) //visible l and bl + else if(!d2 && !d6 && d4 && !d8 && !d7 && !d3 && !d9 && d1) //visible l and bl { return partialHide->ourImages[36].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && !visibilityMap[x+1][y+1][lvl] && visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible r and tr + else if(!d2 && d6 && !d4 && !d8 && !d7 && !d3 && d9 && !d1) //visible r and tr { return partialHide->ourImages[2].bitmap; } - else if(!visibilityMap[x][y+1][lvl] && visibilityMap[x+1][y][lvl] && !visibilityMap[x-1][y][lvl] && !visibilityMap[x][y-1][lvl] && !visibilityMap[x-1][y-1][lvl] && visibilityMap[x+1][y+1][lvl] && !visibilityMap[x+1][y-1][lvl] && !visibilityMap[x-1][y+1][lvl]) //visible r and br + else if(!d2 && d6 && !d4 && !d8 && !d7 && d3 && !d9 && !d1) //visible r and br { return partialHide->ourImages[3].bitmap; } diff --git a/mapHandler.h b/mapHandler.h index 013e9a700..6fb8145ff 100644 --- a/mapHandler.h +++ b/mapHandler.h @@ -41,6 +41,18 @@ template class PseudoV public: int offset; std::vector inver; + PseudoV(){}; + PseudoV(std::vector &src, int offset, const T& fill) + { + inver.resize(Offset*2+rest); + offset=Offset; + for(int i=0; i > > visibility; //true means that pointed place is visible //not used now + std::vector< std::vector< std::vector > > visibility; //true means that pointed place is visible //not used now //std::vector< std::vector > undVisibility; //true means that pointed place is visible std::vector roadDefs; std::vector staticRiverDefs; std::vector defs; std::map loadedDefs; //pointers to loaded defs (key is filename, uppercase) - std::map villages, forts, capitols; std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type std::vector< std::string > battleHeroes; //battleHeroes[hero type] - name of def that has hero animation for battle - PseudoV< PseudoV< PseudoV > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile + std::vector > > hideBitmap; //specifies number of graphic that should be used to fully hide a tile void loadDefs(); char & visAccess(int x, int y); char & undVisAccess(int x, int y); SDL_Surface mirrorImage(SDL_Surface *src); //what is this?? - SDL_Surface * getVisBitmap(int x, int y, PseudoV< PseudoV< PseudoV > > & visibilityMap, int lvl); + SDL_Surface * getVisBitmap(int x, int y, std::vector< std::vector< std::vector > > & visibilityMap, int lvl); int getCost(int3 & a, int3 & b, const CGHeroInstance * hero); std::vector< std::string > getObjDescriptions(int3 pos); //returns desriptions of objects blocking given position @@ -105,7 +116,7 @@ public: void prepareFOWDefs(); void randomizeObjects(); - SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, PseudoV< PseudoV< PseudoV > > & visibilityMap = CGI->mh->visibility, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it + SDL_Surface * terrainRect(int x, int y, int dx, int dy, int level=0, unsigned char anim=0, std::vector< std::vector< std::vector > > & visibilityMap = CGI->mh->visibility, bool otherHeroAnim = false, unsigned char heroAnim = 0, SDL_Surface * extSurf = NULL, SDL_Rect * extRect = NULL); //if extSurf is specified, blit to it SDL_Surface * terrBitmap(int x, int y); SDL_Surface * undTerrBitmap(int x, int y); std::string getRandomizedDefName(CGDefInfo* di, CGObjectInstance * obj = NULL); //objinstance needed only for heroes and towns