From e025a43cb03c01c68d46be83a3bf442b945a667d Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Mon, 26 Jul 2010 23:20:21 +0000 Subject: [PATCH] - some fixes for Castle Gate and Hill Fort - removed unavailable in Hill Fort upgrades from cr_upgrade_list.txt - fixed bug in upgrading creatures - workaround to make VCMI work with Russian language files (possibly fixed 289) --- client/CCastleInterface.cpp | 12 ++++++------ client/CPlayerInterface.cpp | 2 ++ client/GUIClasses.cpp | 23 ++++++++++++++++++++--- client/GUIClasses.h | 3 ++- config/cr_upgrade_list.txt | 16 ---------------- hch/CHeroHandler.cpp | 8 +++++++- server/CGameHandler.cpp | 34 +++++++++++++++------------------- 7 files changed, 52 insertions(+), 46 deletions(-) diff --git a/client/CCastleInterface.cpp b/client/CCastleInterface.cpp index 9765addd9..3043a1618 100644 --- a/client/CCastleInterface.cpp +++ b/client/CCastleInterface.cpp @@ -726,6 +726,12 @@ void CCastleInterface::buildingClicked(int building) break; /*Inferno*/ case 3: //Castle Gate { + if (!town->visitingHero) + { + LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[126], std::vector(), soundBase::sound_todo); + break;//only visiting hero can use castle gates + } + std::vector availableTowns; std::vector Towns = LOCPLINT->cb->getTownsInfo(false); for(size_t i=0;iid);//add to the list } } - if (!town->visitingHero) - { - LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[126], std::vector(), soundBase::sound_todo); - break;//only visiting hero can use castle gates - } CPicture *titlePic = new CPicture (bicons->ourImages[building].bitmap, 0,0, false);//will be deleted by selection window GH.pushInt (new CObjectListWindow(availableTowns, titlePic, CGI->generaltexth->jktexts[40], CGI->generaltexth->jktexts[41], boost::bind (&CCastleInterface::castleTeleport, this, _1))); @@ -790,7 +791,6 @@ void CCastleInterface::castleTeleport(int where) { const CGTownInstance * dest = LOCPLINT->cb->getTownInfo(where, 1); LOCPLINT->cb->teleportHero(town->visitingHero, dest); - close();//close this window, interface with new town will be called by town::onVisit } void CCastleInterface::defaultBuildingClicked(int building) diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 46602a2d9..a807085d6 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -351,6 +351,8 @@ void CPlayerInterface::heroCreated(const CGHeroInstance * hero) } void CPlayerInterface::openTownWindow(const CGTownInstance * town) { + if (castleInt) + GH.popIntTotally(castleInt); castleInt = new CCastleInterface(town); GH.pushInt(castleInt); } diff --git a/client/GUIClasses.cpp b/client/GUIClasses.cpp index bfe53c3dc..a61f5e705 100644 --- a/client/GUIClasses.cpp +++ b/client/GUIClasses.cpp @@ -6031,7 +6031,7 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance *visitor, const CGObjectIn for (int i=0; iblock(currState[i] == -1); } currState[slotsCount] = getState(slotsCount); @@ -6079,8 +6079,9 @@ void CHillFortWindow::updateGarrisons() if (info.newID.size())//we have upgrades here - update costs for(std::set >::iterator it=info.cost[0].begin(); it!=info.cost[0].end(); it++) { - costs[i].insert(*it); - totalSumm[it->first] += it->second; + std::pair pair = std::make_pair(it->first, it->second * hero->getAmount(i) ); + costs[i].insert(pair); + totalSumm[pair.first] += pair.second; } } @@ -6089,6 +6090,7 @@ void CHillFortWindow::updateGarrisons() currState[i] = newState; upgrade[i]->setDef(getDefForSlot(i), false, true); upgrade[i]->block(currState[i] == -1); + upgrade[i]->hoverTexts[0] = getTextForSlot(i); } } @@ -6182,6 +6184,21 @@ std::string CHillFortWindow::getDefForSlot(int slot) } } +std::string CHillFortWindow::getTextForSlot(int slot) +{ + if ( !hero->getCreature(slot) )//we dont have creature here + return ""; + + std::string str = CGI->generaltexth->allTexts[318]; + int amount = hero->getAmount(slot); + if ( amount == 1 ) + boost::algorithm::replace_first(str,"%s",hero->getCreature(slot)->nameSing); + else + boost::algorithm::replace_first(str,"%s",hero->getCreature(slot)->namePl); + + return str; +} + int CHillFortWindow::getState(int slot) { if ( slot == slotsCount )//"Upgrade all" slot diff --git a/client/GUIClasses.h b/client/GUIClasses.h index b2ef76f66..372f0c99d 100644 --- a/client/GUIClasses.h +++ b/client/GUIClasses.h @@ -1153,7 +1153,8 @@ public: void activate(); void deactivate(); void showAll (SDL_Surface *to); - std::string getDefForSlot(int slot); + std::string getDefForSlot(int slot);//return def name for this slot + std::string getTextForSlot(int slot);//return hover text for this slot void makeDeal(int slot);//-1 for upgrading all creatures int getState(int slot); //-1 = no creature 0=can't upgrade, 1=upgraded, 2=can upgrade void updateGarrisons();//update buttons after garrison changes diff --git a/config/cr_upgrade_list.txt b/config/cr_upgrade_list.txt index eb186e305..601a14b4a 100644 --- a/config/cr_upgrade_list.txt +++ b/config/cr_upgrade_list.txt @@ -61,20 +61,4 @@ 114 129 115 123 130 131 -2 137 -3 137 -18 137 -19 137 -34 136 -35 136 -8 136 -9 136 -13 150 -27 151 -41 152 -55 153 -69 154 -83 155 -97 156 -111 157 131 15 \ No newline at end of file diff --git a/hch/CHeroHandler.cpp b/hch/CHeroHandler.cpp index 244dfc8b9..d9add225a 100644 --- a/hch/CHeroHandler.cpp +++ b/hch/CHeroHandler.cpp @@ -450,7 +450,13 @@ void CHeroHandler::loadHeroClasses() char name[BUFFER_SIZE+1]; str.get(name, BUFFER_SIZE, '\t'); hc->name = name; - str >> hc->aggression; + //workaround for locale issue (different localisations use different decimal separator) + int intPart,fracPart; + str >> intPart; + str.ignore();//ignore decimal separator + str >> fracPart; + hc->aggression = intPart + fracPart/100.0f; + str >> hc->initialAttack; str >> hc->initialDefence; str >> hc->initialPower; diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index aebde6ea5..f15950541 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -2794,39 +2794,35 @@ bool CGameHandler::upgradeCreature( ui32 objid, ui8 pos, ui32 upgID ) UpgradeInfo ui = gs->getUpgradeInfo(obj->getStack(pos)); int player = obj->tempOwner; int crQuantity = obj->slots[pos].count; + int newIDpos= vstd::findPos(ui.newID, upgID);//get position of new id in UpgradeInfo //check if upgrade is possible - if((ui.oldID<0 || !vstd::contains(ui.newID,upgID)) && complain("That upgrade is not possible!")) + if( (ui.oldID<0 || newIDpos == -1 ) && complain("That upgrade is not possible!")) { return false; } + //check if player has enough resources - for(int i=0;i >::iterator j=ui.cost[newIDpos].begin(); j!=ui.cost[newIDpos].end(); j++) { - for (std::set >::iterator j=ui.cost[i].begin(); j!=ui.cost[i].end(); j++) + if(gs->getPlayer(player)->resources[j->first] < j->second*crQuantity) { - if(gs->getPlayer(player)->resources[j->first] < j->second*crQuantity) - { - complain("Cannot upgrade, not enough resources!"); - return false; - } + complain("Cannot upgrade, not enough resources!"); + return false; } } - + //take resources - for(int i=0;i >::iterator j=ui.cost[newIDpos].begin(); j!=ui.cost[newIDpos].end(); j++) { - for (std::set >::iterator j=ui.cost[i].begin(); j!=ui.cost[i].end(); j++) - { - SetResource sr; - sr.player = player; - sr.resid = j->first; - sr.val = gs->getPlayer(player)->resources[j->first] - j->second*crQuantity; - sendAndApply(&sr); - } + SetResource sr; + sr.player = player; + sr.resid = j->first; + sr.val = gs->getPlayer(player)->resources[j->first] - j->second*crQuantity; + sendAndApply(&sr); } - + //upgrade creature SetGarrisons sg; sg.garrs[objid] = obj->getArmy();