From 95b3ad64d33f9b9367ee18a76033011527b5422f Mon Sep 17 00:00:00 2001 From: mateuszb Date: Wed, 1 Aug 2007 14:06:04 +0000 Subject: [PATCH] * choosing random towns * some minor bugfixes and improvements --- CAmbarCendamo.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++++ CCreatureHandler.cpp | 2 +- CGameInfo.h | 5 +++- CGameInterface.h | 7 ++++- CMT.cpp | 2 +- CPreGame.h | 16 +---------- StartInfo.h | 23 ++++++++++++++++ mapHandler.cpp | 4 +-- 8 files changed, 102 insertions(+), 21 deletions(-) create mode 100644 StartInfo.h diff --git a/CAmbarCendamo.cpp b/CAmbarCendamo.cpp index 6a012293a..b59a3a8a3 100644 --- a/CAmbarCendamo.cpp +++ b/CAmbarCendamo.cpp @@ -2011,6 +2011,17 @@ void CAmbarCendamo::processMap(std::vector & defsToUnpack) art4DefNumbers.push_back(-1); } + std::vector town0DefNames; //without fort + std::vector town0DefNumbers; + std::vector town1DefNames; //with fort + std::vector town1DefNumbers; + + for(int dd=0; dd<9; ++dd) + { + town1DefNames.push_back(CGI->dobjinfo->objs[dd+385].defName); + town1DefNumbers.push_back(-1); + } + //variables initialized for(int j=0; jobjh->objInstances.size(); ++j) { @@ -2449,6 +2460,59 @@ void CAmbarCendamo::processMap(std::vector & defsToUnpack) } break; } + case EDefType::TOWN_DEF: + { + if(curDef.bytes[16]==77) //random town + { + DefInfo nxt = curDef; + nxt.bytes[16] = 98; + if(((CCastleObjInfo*)CGI->objh->objInstances[j].info)->player==0xff) + { + nxt.bytes[20] = rand()%town1DefNames.size(); + } + else + { + if(CGI->scenarioOps.playerInfos[((CCastleObjInfo*)CGI->objh->objInstances[j].info)->player].castle>-1) + { + nxt.bytes[20] = CGI->scenarioOps.playerInfos[((CCastleObjInfo*)CGI->objh->objInstances[j].info)->player].castle; + } + else + { + nxt.bytes[20] = rand()%town1DefNames.size(); + } + } + if(town1DefNumbers[nxt.bytes[20]]!=-1) + { + CGI->objh->objInstances[j].defNumber = town1DefNumbers[nxt.bytes[20]]; + continue; + } + nxt.name = town1DefNames[nxt.bytes[20]]; + std::vector::iterator pit = std::find(CGameInfo::mainObj->dobjinfo->objs.begin(), CGameInfo::mainObj->dobjinfo->objs.end(), + nxt.name); + if(pit == CGameInfo::mainObj->dobjinfo->objs.end()) + { + nxt.isOnDefList = false; + } + else + { + nxt.printPriority = pit->priority; + nxt.isOnDefList = true; + } + map.defy.push_back(nxt); // add this def to the vector + defsToUnpack.push_back(nxt.name); + CGI->objh->objInstances[j].defNumber = map.defy.size()-1; + if(town1DefNumbers[nxt.bytes[20]]==-1) + { + town1DefNumbers[nxt.bytes[20]] = map.defy.size()-1; + } + } + //((CCastleObjInfo*)CGI->objh->objInstances[j].info) + break; + } } //end of main switch } //end of main loop + //for(int j=0; jobjh->objInstances.size(); ++j) //for creature dwellings on map (they are town type dependent) + //{ + // DefInfo curDef = map.defy[CGI->objh->objInstances[j].defNumber]; + //} } diff --git a/CCreatureHandler.cpp b/CCreatureHandler.cpp index 2566c24cb..eaf9ffee8 100644 --- a/CCreatureHandler.cpp +++ b/CCreatureHandler.cpp @@ -446,7 +446,7 @@ void CCreatureHandler::loadUnitAnimInfo(CCreature & unit, std::string & src, int void CCreatureHandler::loadUnitAnimations() { - std::ifstream inp("CREDEFS.TXT", std::ios::in | std::ios::binary); + std::ifstream inp("CREDEFS.TXT", std::ios::in | std::ios::binary); //this file is not in lod inp.seekg(0,std::ios::end); // na koniec int andame = inp.tellg(); // read length inp.seekg(0,std::ios::beg); // wracamy na poczatek diff --git a/CGameInfo.h b/CGameInfo.h index f076625b3..112b520da 100644 --- a/CGameInfo.h +++ b/CGameInfo.h @@ -1,6 +1,8 @@ #ifndef CGAMEINFO_H #define CGAMEINFO_H +#include "CPreGame.h" +#include "StartInfo.h" #include "CSpellHandler.h" #include "CAbilityHandler.h" #include "CCreaturehandler.h" @@ -16,8 +18,8 @@ #include "CTownHandler.h" #include "CGeneralTextHandler.h" #include "SDL.h" -#include +#include /* CGameInfo class for allowing different functions for modifying game informations @@ -43,6 +45,7 @@ public: CGeneralTextHandler * generaltexth; std::vector playerColors; SDL_Color neutralColor; + StartInfo scenarioOps; }; #endif //CGAMEINFO_H \ No newline at end of file diff --git a/CGameInterface.h b/CGameInterface.h index 59d5487b4..0028f268d 100644 --- a/CGameInterface.h +++ b/CGameInterface.h @@ -1,3 +1,6 @@ +#ifndef CGAMEINTERFACE_H +#define CGAMEINTERFACE_H + #include "SDL.h" #include "CDefHandler.h" #include "SDL_Extensions.h" @@ -59,4 +62,6 @@ class CPlayerInterface std::vector hoverable; std::vector keyinterested; void handleEvent(SDL_Event * sEvent); -}; \ No newline at end of file +}; + +#endif //CGAMEINTERFACE_H \ No newline at end of file diff --git a/CMT.cpp b/CMT.cpp index ef4c8e6ae..a608de4b8 100644 --- a/CMT.cpp +++ b/CMT.cpp @@ -284,7 +284,7 @@ int _tmain(int argc, _TCHAR* argv[]) //CSDL_Ext::blueToPlayersAdv(ll->piecesOfBox[0].ourImages[0].bitmap, 0); //SDL_SaveBMP(ll->piecesOfBox[0].ourImages[0].bitmap, "test2.bmp"); cpg->mush = mush; - cpg->runLoop(); + cgi->scenarioOps = cpg->runLoop(); THC tmh.getDif(); //////////////////////////////////////////////////////////////////////////////// lod testing diff --git a/CPreGame.h b/CPreGame.h index d9eb7cb5a..3686cae23 100644 --- a/CPreGame.h +++ b/CPreGame.h @@ -1,6 +1,7 @@ #ifndef CPREGAME_H #define CPREGAME_H #include "SDL.h" +#include "StartInfo.h" #include "CSemiDefHandler.h" #include "CSemiLodHandler.h" #include "CPreGameTextHandler.h" @@ -9,7 +10,6 @@ #include "CMusicHandler.h" class CPreGame; extern CPreGame * CPG; -enum Ebonus {brandom=-1,bartifact, bgold, bresource}; typedef void(CPreGame::*ttt)(); template class CGroup; @@ -105,20 +105,6 @@ public: CGroup():selected(NULL),type(0){}; }; -struct StartInfo -{ - struct PlayerSettings - { - int castle, hero, heroPortrait; //ID, if -1 then random, if -2 then none - std::string heroName; - Ebonus bonus; - Ecolor color; //from 0 - - int handicap;//0-no, 1-mild, 2-severe - std::string name; - }; - std::vector playerInfos; - int turnTime; //in minutes, 0=unlimited -}; class PreGameTab { public: diff --git a/StartInfo.h b/StartInfo.h new file mode 100644 index 000000000..726f29f94 --- /dev/null +++ b/StartInfo.h @@ -0,0 +1,23 @@ +#ifndef STARTINFO_H +#define STARTINFO_H + +#include "global.h" + +enum Ebonus {brandom=-1,bartifact, bgold, bresource}; + +struct StartInfo +{ + struct PlayerSettings + { + int castle, hero, heroPortrait; //ID, if -1 then random, if -2 then none + std::string heroName; + Ebonus bonus; + Ecolor color; //from 0 - + int handicap;//0-no, 1-mild, 2-severe + std::string name; + }; + std::vector playerInfos; + int turnTime; //in minutes, 0=unlimited +}; + +#endif \ No newline at end of file diff --git a/mapHandler.cpp b/mapHandler.cpp index 13391c4bf..537df1e6b 100644 --- a/mapHandler.cpp +++ b/mapHandler.cpp @@ -140,7 +140,7 @@ void CMapHandler::init() } if(cDir==8 || cDir==9) { - if(j-Hoff+1map.height && !(reader->map.terrain[i-Woff][j-Hoff+1].malle)) + if((j-Hoff+1map.height && !(reader->map.terrain[i-Woff][j-Hoff+1].malle)) || j-Hoff+1==reader->map.height) { roadBitmaps[i][j] = CSDL_Ext::hFlip(roadBitmaps[i][j]); roadBitmaps[i][j] = CSDL_Ext::alphaTransform(roadBitmaps[i][j]); @@ -222,7 +222,7 @@ void CMapHandler::init() } if(cDir==8 || cDir==9) { - if(j-Hoff+1map.height && !(reader->map.undergroungTerrain[i-Woff][j-Hoff+1].malle)) + if((j-Hoff+1map.height && !(reader->map.undergroungTerrain[i-Woff][j-Hoff+1].malle)) || j-Hoff+1==reader->map.height) { undRoadBitmaps[i][j] = CSDL_Ext::hFlip(undRoadBitmaps[i][j]); undRoadBitmaps[i][j] = CSDL_Ext::alphaTransform(undRoadBitmaps[i][j]);