From b65f1dae0fc7386c8b4da5f1b6ce15124a21c66d Mon Sep 17 00:00:00 2001 From: mateuszb Date: Mon, 16 Jul 2007 10:03:54 +0000 Subject: [PATCH] function to set palyer's color on flags, small improvements in CHeroHandler (e.g. removing nodrze and initializing hero's classes) --- CAmbarCendamo.cpp | 10 +++--- CHeroHandler.cpp | 76 +++++++++++++++++++++++++++++++++++----------- CHeroHandler.h | 9 ++++-- SDL_Extensions.cpp | 10 ++++++ SDL_Extensions.h | 1 + 5 files changed, 80 insertions(+), 26 deletions(-) diff --git a/CAmbarCendamo.cpp b/CAmbarCendamo.cpp index 92857e750..d8505508d 100644 --- a/CAmbarCendamo.cpp +++ b/CAmbarCendamo.cpp @@ -293,9 +293,9 @@ void CAmbarCendamo::deh3m() if((i-ist)*8+yy < CGameInfo::mainObj->heroh->heroes.size()) { if(c == (c|((unsigned char)intPow(2, yy)))) - CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy].isAllowed = true; + CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy]->isAllowed = true; else - CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy].isAllowed = false; + CGameInfo::mainObj->heroh->heroes[(i-ist)*8+yy]->isAllowed = false; } } } @@ -564,7 +564,7 @@ void CAmbarCendamo::deh3m() spec->bytes[2] = bufor[i]; ++i; spec->bytes[3] = bufor[i]; ++i; spec->player = bufor[i]; ++i; - spec->type = &(CGameInfo::mainObj->heroh->heroes[readNormalNr(i, 1)]); ++i; + spec->type = CGameInfo::mainObj->heroh->heroes[readNormalNr(i, 1)]; ++i; bool isName = bufor[i]; ++i; //true if hero has nonstandard name if(isName) { @@ -978,7 +978,7 @@ void CAmbarCendamo::deh3m() case 8: { int heroType = bufor[i]; ++i; - spec->m8hero = &(CGameInfo::mainObj->heroh->heroes[heroType]); + spec->m8hero = CGameInfo::mainObj->heroh->heroes[heroType]; int limit = readNormalNr(i); i+=4; if(limit == ((int)0xffffffff)) { @@ -1629,7 +1629,7 @@ void CAmbarCendamo::deh3m() case 8: { int heroType = bufor[i]; ++i; - spec->m8hero = &(CGameInfo::mainObj->heroh->heroes[heroType]); + spec->m8hero = CGameInfo::mainObj->heroh->heroes[heroType]; int limit = readNormalNr(i); i+=4; if(limit == ((int)0xffffffff)) { diff --git a/CHeroHandler.cpp b/CHeroHandler.cpp index 9061c0f00..fb8f276bb 100644 --- a/CHeroHandler.cpp +++ b/CHeroHandler.cpp @@ -14,9 +14,40 @@ void CHeroHandler::loadHeroes() inp>>dump; } inp.ignore(); + int numberOfCurrentClassHeroes = 0; + int currentClass = 0; + int additHero = 0; + EHeroClasses addTab[12]; + addTab[0] = HERO_KNIGHT; + addTab[1] = HERO_WITCH; + addTab[2] = HERO_KNIGHT; + addTab[3] = HERO_WIZARD; + addTab[4] = HERO_RANGER; + addTab[5] = HERO_BARBARIAN; + addTab[6] = HERO_DEATHKNIGHT; + addTab[7] = HERO_WARLOCK; + addTab[8] = HERO_KNIGHT; + addTab[9] = HERO_WARLOCK; + addTab[10] = HERO_BARBARIAN; + addTab[11] = HERO_DEMONIAC; + while(!inp.eof()) { - CHero nher; + CHero * nher = new CHero; + if(currentClass<18) + { + nher->heroType = (EHeroClasses)currentClass; + ++numberOfCurrentClassHeroes; + if(numberOfCurrentClassHeroes==8) + { + numberOfCurrentClassHeroes = 0; + ++currentClass; + } + } + else + { + nher->heroType = addTab[additHero++]; + } std::string base; char * tab = new char[500]; int iit = 0; @@ -27,6 +58,7 @@ void CHeroHandler::loadHeroes() loadSpecialAbilities(); loadBiographies(); loadHeroClasses(); + initHeroClasses(); inp.close(); return; } @@ -34,13 +66,13 @@ void CHeroHandler::loadHeroes() { ++iit; } - nher.name = base.substr(0, iit); + nher->name = base.substr(0, iit); ++iit; for(int i=iit; ilow1stack = atoi(base.substr(iit, i).c_str()); iit=i+1; break; } @@ -49,7 +81,7 @@ void CHeroHandler::loadHeroes() { if(base[i]==(char)(10) || base[i]==(char)(9)) { - nher.high1stack = atoi(base.substr(iit, i).c_str()); + nher->high1stack = atoi(base.substr(iit, i).c_str()); iit=i+1; break; } @@ -59,13 +91,13 @@ void CHeroHandler::loadHeroes() { ++ipom; } - nher.refType1stack = base.substr(iit, ipom-iit); + nher->refType1stack = base.substr(iit, ipom-iit); iit=ipom+1; for(int i=iit; ilow2stack = atoi(base.substr(iit, i-iit).c_str()); iit=i+1; break; } @@ -74,7 +106,7 @@ void CHeroHandler::loadHeroes() { if(base[i]==(char)(10) || base[i]==(char)(9)) { - nher.high2stack = atoi(base.substr(iit, i-iit).c_str()); + nher->high2stack = atoi(base.substr(iit, i-iit).c_str()); iit=i+1; break; } @@ -84,13 +116,13 @@ void CHeroHandler::loadHeroes() { ++ipom; } - nher.refType2stack = base.substr(iit, ipom-iit); + nher->refType2stack = base.substr(iit, ipom-iit); iit=ipom+1; for(int i=iit; ilow3stack = atoi(base.substr(iit, i-iit).c_str()); iit=i+1; break; } @@ -99,13 +131,13 @@ void CHeroHandler::loadHeroes() { if(base[i]==(char)(10) || base[i]==(char)(9)) { - nher.high3stack = atoi(base.substr(iit, i-iit).c_str()); + nher->high3stack = atoi(base.substr(iit, i-iit).c_str()); iit=i+1; break; } } - nher.refType3stack = base.substr(iit, base.size()-iit); - nher.ID=ID++; + nher->refType3stack = base.substr(iit, base.size()-iit); + nher->ID=ID++; heroes.push_back(nher); delete[500] tab; } @@ -138,11 +170,11 @@ void CHeroHandler::loadSpecialAbilities() { ++iit; } - heroes[whHero].bonusName = base.substr(0, iit); + heroes[whHero]->bonusName = base.substr(0, iit); ++iit; iitBef=iit; - if(heroes[whHero].bonusName == std::string("Ogry")) + if(heroes[whHero]->bonusName == std::string("Ogry")) { char * tab2 = new char[500]; inp.getline(tab2, 500); @@ -154,7 +186,7 @@ void CHeroHandler::loadSpecialAbilities() { ++iit; } - heroes[whHero].shortBonus = base.substr(iitBef, iit-iitBef); + heroes[whHero]->shortBonus = base.substr(iitBef, iit-iitBef); ++iit; iitBef=iit; @@ -162,7 +194,7 @@ void CHeroHandler::loadSpecialAbilities() { ++iit; } - heroes[whHero].longBonus = base.substr(iitBef, iit-iitBef); + heroes[whHero]->longBonus = base.substr(iitBef, iit-iitBef); ++whHero; delete [500] tab; } @@ -189,7 +221,7 @@ void CHeroHandler::loadBiographies() if(buf[i]=='\r') break; } - heroes[q].biography = buf.substr(befi, i-befi); + heroes[q]->biography = buf.substr(befi, i-befi); i+=2; } } @@ -344,7 +376,7 @@ void CHeroHandler::loadHeroClasses() hc->proKnowledge[1] = atoi(buf.substr(befi, i-befi).c_str()); ++i; - CHero kkk = heroes[0]; + //CHero kkk = heroes[0]; for(int dd=0; ddabilh->abilities.size(); ++dd) { @@ -374,3 +406,11 @@ void CHeroHandler::loadHeroClasses() heroClasses.push_back(hc); } } + +void CHeroHandler::initHeroClasses() +{ + for(int gg=0; ggheroClass = heroClasses[heroes[gg]->heroType]; + } +} diff --git a/CHeroHandler.h b/CHeroHandler.h index ba39e8182..0dcd6da55 100644 --- a/CHeroHandler.h +++ b/CHeroHandler.h @@ -4,10 +4,11 @@ #include #include #include "CCreatureHandler.h" -#include "nodrze.h" class CHeroClass; +enum EHeroClasses {HERO_KNIGHT, HERO_CLERIC, HERO_RANGER, HERO_DRUID, HREO_ALCHEMIST, HERO_WIZARD, HERO_DEMONIAC, HERO_HERETIC, HERO_DEATHKNIGHT, HERO_NECROMANCER, HERO_WARLOCK, HERO_OVERLORD, HERO_BARBARIAN, HERO_BATTLEMAGE, HERO_BEASTMASTER, HERO_WITCH, HERO_PLANESWALKER, HERO_ELEMENTALIST}; + class CHero { public: @@ -19,7 +20,8 @@ public: std::string biography; //biography, of course bool isAllowed; //true if we can play with this hero (depends on map) CHeroClass * heroClass; - bool operator<(CHero& drugi){if (ID < drugi.ID) return true; else return false;} + EHeroClasses heroType; //hero class + //bool operator<(CHero& drugi){if (ID < drugi.ID) return true; else return false;} }; class CHeroClass @@ -48,12 +50,13 @@ public: class CHeroHandler { public: - nodrze heroes; //było nodrze + std::vector heroes; //było nodrze std::vector heroClasses; void loadHeroes(); void loadSpecialAbilities(); void loadBiographies(); void loadHeroClasses(); + void initHeroClasses(); }; diff --git a/SDL_Extensions.cpp b/SDL_Extensions.cpp index 4d310ec82..bec78a3ec 100644 --- a/SDL_Extensions.cpp +++ b/SDL_Extensions.cpp @@ -581,3 +581,13 @@ void CSDL_Ext::blueToPlayersAdv(SDL_Surface * sur, int player) } } +void CSDL_Ext::setPlayerColor(SDL_Surface * sur, int player) +{ + if(sur->format->BitsPerPixel==8) + { + if(player != -1) + *(sur->format->palette->colors+5) = CGameInfo::mainObj->playerColors[player]; + else + *(sur->format->palette->colors+5) = CGameInfo::mainObj->neutralColor; + } +} \ No newline at end of file diff --git a/SDL_Extensions.h b/SDL_Extensions.h index 08ab53160..0cccb260d 100644 --- a/SDL_Extensions.h +++ b/SDL_Extensions.h @@ -24,6 +24,7 @@ namespace CSDL_Ext void update(SDL_Surface * what = ekran); //updates whole surface (default - main screen) void blueToPlayers(SDL_Surface * sur, int player); //simple color substitution void blueToPlayersAdv(SDL_Surface * sur, int player); //substitute blue color by another one, makes it nicer keeping nuances + void setPlayerColor(SDL_Surface * sur, int player); //sets correct color of flags; -1 for neutral }; #endif // SDL_EXTENSIONS_H \ No newline at end of file