Browse Source

- 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)

Ivan Savenko 15 years ago
parent
commit
e025a43cb0

+ 6 - 6
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<SComponent*>(), soundBase::sound_todo);
+								break;//only visiting hero can use castle gates
+							}
+							
 							std::vector <int> availableTowns;
 							std::vector <const CGTownInstance*> Towns = LOCPLINT->cb->getTownsInfo(false);
 							for(size_t i=0;i<Towns.size();i++)
@@ -737,11 +743,6 @@ void CCastleInterface::buildingClicked(int building)
 									availableTowns.push_back(t->id);//add to the list
 								}
 							}
-							if (!town->visitingHero)
-							{
-								LOCPLINT->showInfoDialog(CGI->generaltexth->allTexts[126], std::vector<SComponent*>(), 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)

+ 2 - 0
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);
 }

+ 20 - 3
client/GUIClasses.cpp

@@ -6031,7 +6031,7 @@ CHillFortWindow::CHillFortWindow(const CGHeroInstance *visitor, const CGObjectIn
 	for (int i=0; i<slotsCount; i++)
 	{
 		currState[i] = getState(i);
-		upgrade[i] = new AdventureMapButton("","",boost::bind(&CHillFortWindow::makeDeal, this, i), 107+i*76, 171, getDefForSlot(i));
+		upgrade[i] = new AdventureMapButton(getTextForSlot(i),"",boost::bind(&CHillFortWindow::makeDeal, this, i), 107+i*76, 171, getDefForSlot(i));
 		upgrade[i]->block(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<std::pair<int,int> >::iterator it=info.cost[0].begin(); it!=info.cost[0].end(); it++)
 				{
-					costs[i].insert(*it);
-					totalSumm[it->first] += it->second;
+					std::pair<int, int> 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

+ 2 - 1
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

+ 0 - 16
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

+ 7 - 1
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;

+ 15 - 19
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<ui.cost.size();i++)
+	for (std::set<std::pair<int,int> >::iterator j=ui.cost[newIDpos].begin(); j!=ui.cost[newIDpos].end(); j++)
 	{
-		for (std::set<std::pair<int,int> >::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<ui.cost.size();i++)
+	for (std::set<std::pair<int,int> >::iterator j=ui.cost[newIDpos].begin(); j!=ui.cost[newIDpos].end(); j++)
 	{
-		for (std::set<std::pair<int,int> >::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();