From e46d411643738f3846e3d64b9c3ab928e7bc0a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Mon, 18 Feb 2008 21:14:28 +0000 Subject: [PATCH] * mostly done town infobox * town daily income is properly calculated * minor not done stuff --- CAdvmapInterface.cpp | 8 ++++++- CCallback.cpp | 15 +++++++++++++ CCallback.h | 1 + CCastleInterface.cpp | 6 ++---- CCastleInterface.h | 3 +-- CConsoleHandler.cpp | 1 + CPlayerInterface.cpp | 49 +++++++++++++++++++++++++++++++++++++++++- CPlayerInterface.h | 16 +++++++++++--- hch/CObjectHandler.cpp | 37 +++++++++++++++++++++++++++++++ hch/CObjectHandler.h | 4 ++++ 10 files changed, 129 insertions(+), 11 deletions(-) diff --git a/CAdvmapInterface.cpp b/CAdvmapInterface.cpp index b3a00fee5..b05925e62 100644 --- a/CAdvmapInterface.cpp +++ b/CAdvmapInterface.cpp @@ -671,7 +671,12 @@ void CInfoBar::draw(const CGObjectInstance * specific) { if(LOCPLINT->heroWins.find(specific->subID)!=LOCPLINT->heroWins.end()) blitAt(LOCPLINT->heroWins[specific->subID],pos.x,pos.y); - + } + else if (specific->ID == 98) + { + const CGTownInstance * t = static_cast(specific); + if(LOCPLINT->townWins.find(t->identifier)!=LOCPLINT->townWins.end()) + blitAt(LOCPLINT->townWins[t->identifier],pos.x,pos.y); } //SDL_Surface * todr = LOCPLINT->infoWin(specific); @@ -1006,6 +1011,7 @@ void CAdvMapInt::selectionChanged() terrain.currentPath = NULL; townList.draw(); heroList.draw(); + infoBar.draw(NULL); } void CAdvMapInt::centerOn(int3 on) { diff --git a/CCallback.cpp b/CCallback.cpp index 946a6ab30..898cf347b 100644 --- a/CCallback.cpp +++ b/CCallback.cpp @@ -351,6 +351,21 @@ bool CCallback::isVisible(int3 pos, int Player) return gs->players[Player].fogOfWarMap[pos.x][pos.y][pos.z]; } +std::vector < const CGTownInstance *> CCallback::getTownsInfo(bool onlyOur) +{ + std::vector < const CGTownInstance *> ret = std::vector < const CGTownInstance *>(); + for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) + { + for (int j=0;j<(*i).second.towns.size();j++) + { + if ( ( isVisible((*i).second.towns[j]->pos,player) ) || (*i).first==player) + { + ret.push_back((*i).second.towns[j]); + } + } + } // for ( std::map::iterator i=gs->players.begin() ; i!=gs->players.end();i++) + return ret; +} std::vector < const CGHeroInstance *> CCallback::getHeroesInfo(bool onlyOur) { std::vector < const CGHeroInstance *> ret = std::vector < const CGHeroInstance *>(); diff --git a/CCallback.h b/CCallback.h index 9b238a67c..f439129d2 100644 --- a/CCallback.h +++ b/CCallback.h @@ -75,6 +75,7 @@ public: int getResourceAmount(int type); int howManyHeroes(); const CGTownInstance * getTownInfo(int val, bool mode); //mode = 0 -> val = serial; mode = 1 -> val = ID + std::vector < const CGTownInstance *> getTownsInfo(bool onlyOur=true); int howManyTowns(); std::vector < std::string > getObjDescriptions(int3 pos); //returns descriptions of objects at pos in order from the lowest to the highest std::vector < const CGHeroInstance *> getHeroesInfo(bool onlyOur=true); diff --git a/CCastleInterface.cpp b/CCastleInterface.cpp index 8af9d937f..2c955e1a7 100644 --- a/CCastleInterface.cpp +++ b/CCastleInterface.cpp @@ -160,7 +160,6 @@ CCastleInterface::CCastleInterface(const CGTownInstance * Town, bool Activate) cityBg = CGI->bitmaph->loadBitmap(getBgName(Town->subID)); hall = CGI->spriteh->giveDef("ITMTL.DEF"); fort = CGI->spriteh->giveDef("ITMCL.DEF"); - bigTownPic = CGI->spriteh->giveDef("ITPT.DEF"); flag = CGI->spriteh->giveDef("CREST58.DEF"); townlist = new CTownList(3,&genRect(128,48,744,414),744,414,744,526); exit = new AdventureMapButton @@ -262,7 +261,6 @@ CCastleInterface::~CCastleInterface() delete split; delete hall; delete fort; - delete bigTownPic; delete flag; delete garr; delete townlist; @@ -343,7 +341,7 @@ void CCastleInterface::showAll(SDL_Surface * to) //print name and income CSDL_Ext::printAt(town->name,85,389,GEOR13,zwykly,to); char temp[10]; - itoa(town->income,temp,10); + itoa(town->dailyIncome(),temp,10); CSDL_Ext::printAtMiddle(temp,195,442,GEOR13,zwykly,to); //blit town icon @@ -352,7 +350,7 @@ void CCastleInterface::showAll(SDL_Surface * to) pom += F_NUMBER*2; if(town->builded >= MAX_BUILDING_PER_TURN) pom++; - blitAt(bigTownPic->ourImages[pom].bitmap,15,387,to); + blitAt(LOCPLINT->bigTownPic->ourImages[pom].bitmap,15,387,to); //flag if(town->getOwner() * townlist; diff --git a/CConsoleHandler.cpp b/CConsoleHandler.cpp index 54f45bf88..58ae6676c 100644 --- a/CConsoleHandler.cpp +++ b/CConsoleHandler.cpp @@ -65,6 +65,7 @@ int internalFunc(void * callback) { SDL_Surface * temp = LOCPLINT->infoWin(NULL); blitAtWR(temp,605,389); + SDL_FreeSurface(temp); break; } case 'T': //test rect diff --git a/CPlayerInterface.cpp b/CPlayerInterface.cpp index 10b1340c7..79025efe3 100644 --- a/CPlayerInterface.cpp +++ b/CPlayerInterface.cpp @@ -739,6 +739,8 @@ CPlayerInterface::CPlayerInterface(int Player, int serial) human=true; hInfo = CGI->bitmaph->loadBitmap("HEROQVBK.bmp"); SDL_SetColorKey(hInfo,SDL_SRCCOLORKEY,SDL_MapRGB(hInfo->format,0,255,255)); + tInfo = CGI->bitmaph->loadBitmap("TOWNQVBK.bmp"); + SDL_SetColorKey(tInfo,SDL_SRCCOLORKEY,SDL_MapRGB(tInfo->format,0,255,255)); slotsPos.push_back(std::pair(44,82)); slotsPos.push_back(std::pair(80,82)); slotsPos.push_back(std::pair(116,82)); @@ -755,6 +757,9 @@ CPlayerInterface::CPlayerInterface(int Player, int serial) morale30 = CGI->spriteh->giveDefEss("IMRL30.DEF"); morale42 = CGI->spriteh->giveDefEss("IMRL42.DEF"); morale82 = CGI->spriteh->giveDefEss("IMRL82.DEF"); + halls = CGI->spriteh->giveDefEss("ITMTLS.DEF"); + forts = CGI->spriteh->giveDefEss("ITMCLS.DEF"); + bigTownPic = CGI->spriteh->giveDefEss("ITPT.DEF"); } void CPlayerInterface::init(ICallback * CB) @@ -769,6 +774,12 @@ void CPlayerInterface::init(ICallback * CB) SDL_Surface * pom = infoWin(hh[i]); heroWins.insert(std::pair(hh[i]->subID,pom)); } + std::vector tt = cb->getTownsInfo(false); + for(int i=0;i(tt[i]->identifier,pom)); + } } void CPlayerInterface::yourTurn() { @@ -1403,7 +1414,34 @@ SDL_Surface * CPlayerInterface::drawHeroInfoWin(const CGHeroInstance * curh) SDL_Surface * CPlayerInterface::drawTownInfoWin(const CGTownInstance * curh) { - return NULL; + char * buf = new char[10]; + SDL_Surface * ret = SDL_DisplayFormat(tInfo); + SDL_SetColorKey(ret,SDL_SRCCOLORKEY,SDL_MapRGB(ret->format,0,255,255)); + blueToPlayersAdv(ret,playerID,1); + printAt(curh->name,75,15,GEOR13,zwykly,ret); + + int pom = curh->fortLevel() - 1; if(pom<0) pom = 3; + blitAt(halls->ourImages[curh->hallLevel()].bitmap,77,42,ret); + blitAt(forts->ourImages[pom].bitmap,115,42,ret); + itoa(curh->dailyIncome(),buf,10); + printAtMiddle(buf,167,70,GEORM,zwykly,ret); + for (std::map >::const_iterator i=curh->garrison.slots.begin(); i!=curh->garrison.slots.end();i++) + { + blitAt(CGI->creh->smallImgs[(*i).second.first->idNumber],slotsPos[(*i).first].first+1,slotsPos[(*i).first].second+1,ret); + itoa((*i).second.second,buf,10); + printAtMiddle(buf,slotsPos[(*i).first].first+17,slotsPos[(*i).first].second+39,GEORM,zwykly,ret); + } + + //blit town icon + pom = curh->subID*2; + if (!curh->hasFort()) + pom += F_NUMBER*2; + if(curh->builded >= MAX_BUILDING_PER_TURN) + pom++; + blitAt(bigTownPic->ourImages[pom].bitmap,13,13,ret); + + delete[] buf; + return ret; } void CPlayerInterface::openTownWindow(const CGTownInstance * town) @@ -1424,6 +1462,9 @@ SDL_Surface * CPlayerInterface::infoWin(const CGObjectInstance * specific) //spe case 34: return drawHeroInfoWin(dynamic_cast(specific)); break; + case 98: + return drawTownInfoWin(dynamic_cast(specific)); + break; default: return NULL; break; @@ -1725,6 +1766,12 @@ void CPlayerInterface::garrisonChanged(const CGObjectInstance * obj) } else if (obj->ID == 98) //town { + const CGTownInstance * tt; + if(tt = dynamic_cast(obj)) + { + SDL_FreeSurface(heroWins[tt->identifier]); + heroWins[tt->identifier] = infoWin(tt); + } } } void CPlayerInterface::showComp(SComponent comp) diff --git a/CPlayerInterface.h b/CPlayerInterface.h index f89cdb60a..10e33e1e7 100644 --- a/CPlayerInterface.h +++ b/CPlayerInterface.h @@ -148,6 +148,15 @@ public: void close(); CSelWindow(){}; }; + +class CRClickPopup : public IShowable, public ClickableR +{ + virtual void activate()=0; + virtual void deactivate()=0; + virtual void close()=0; + virtual void show()=0; +}; + class SComponent : public ClickableR { public: @@ -257,12 +266,13 @@ public: std::vector timeinterested; std::vector objsToBlit; - SDL_Surface * hInfo; + SDL_Surface * hInfo, *tInfo; std::vector > slotsPos; CDefEssential *luck22, *luck30, *luck42, *luck82, - *morale22, *morale30, *morale42, *morale82; + *morale22, *morale30, *morale42, *morale82, + *halls, *forts, *bigTownPic; std::map heroWins; - //std::map townWins; + std::map townWins; //overloaded funcs from Interface void yourTurn(); diff --git a/hch/CObjectHandler.cpp b/hch/CObjectHandler.cpp index af447345c..9c92892d4 100644 --- a/hch/CObjectHandler.cpp +++ b/hch/CObjectHandler.cpp @@ -224,6 +224,43 @@ int CGTownInstance::getSightDistance() const //returns sight distance { return 10; } +int CGTownInstance::fortLevel() const //0 - none, 1 - fort, 2 - citadel, 3 - castle +{ + if((builtBuildings.find(9))!=builtBuildings.end()) + return 3; + if((builtBuildings.find(8))!=builtBuildings.end()) + return 2; + if((builtBuildings.find(7))!=builtBuildings.end()) + return 1; + return 0; +} +int CGTownInstance::hallLevel() const // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol +{ + if ((builtBuildings.find(13))!=builtBuildings.end()) + return 3; + if ((builtBuildings.find(12))!=builtBuildings.end()) + return 2; + if ((builtBuildings.find(11))!=builtBuildings.end()) + return 1; + if ((builtBuildings.find(10))!=builtBuildings.end()) + return 0; + return -1; +} +int CGTownInstance::dailyIncome() const +{ + int ret = 0; + if ((builtBuildings.find(26))!=builtBuildings.end()) + ret+=5000; + if ((builtBuildings.find(13))!=builtBuildings.end()) + ret+=4000; + else if ((builtBuildings.find(12))!=builtBuildings.end()) + ret+=2000; + else if ((builtBuildings.find(11))!=builtBuildings.end()) + ret+=1000; + else if ((builtBuildings.find(10))!=builtBuildings.end()) + ret+=500; + return ret; +} bool CGTownInstance::hasFort() const { return (builtBuildings.find(7))!=builtBuildings.end(); diff --git a/hch/CObjectHandler.h b/hch/CObjectHandler.h index b17ceb332..eee948bd2 100644 --- a/hch/CObjectHandler.h +++ b/hch/CObjectHandler.h @@ -394,6 +394,10 @@ public: std::vector possibleSpells, obligatorySpells, availableSpells; int getSightDistance() const; //returns sight distance + + int fortLevel() const; //0 - none, 1 - fort, 2 - citadel, 3 - castle + int hallLevel() const; // -1 - none, 0 - village, 1 - town, 2 - city, 3 - capitol + bool hasFort() const; bool hasCapitol() const; int dailyIncome() const;