Selaa lähdekoodia

Fixed 313 & 314 :)

DjWarmonger 15 vuotta sitten
vanhempi
sitoutus
310a36c8d1
7 muutettua tiedostoa jossa 47 lisäystä ja 25 poistoa
  1. 1 1
      client/Client.h
  2. 12 3
      client/GUIClasses.cpp
  3. 6 4
      hch/CObjectHandler.cpp
  4. 1 1
      hch/CObjectHandler.h
  5. 1 1
      lib/IGameCallback.h
  6. 25 14
      server/CGameHandler.cpp
  7. 1 1
      server/CGameHandler.h

+ 1 - 1
client/Client.h

@@ -110,7 +110,7 @@ public:
 	void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb){};
 	void showThievesGuildWindow(int requestingObjId){};
 	void giveResource(int player, int which, int val){};
-	void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures) {};
+	void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures, bool remove) {};
 	void takeCreatures (int objid, TSlots creatures){};
 	void changeCreatureType (int objid, TSlot slot, TCreature creature){};
 	void showCompInfo(ShowInInfobox * comp){};

+ 12 - 3
client/GUIClasses.cpp

@@ -464,8 +464,8 @@ CGarrisonInt::CGarrisonInt(int x, int y, int inx, const Point &garsOffset,
 	:interx(inx), garOffset(garsOffset), surOffset(SurOffset), highlighted(NULL), sur(pomsur), splitting(false),
 	 smallIcons(smallImgs), removableUnits (_removableUnits), twoRows(_twoRows), oup(s1), odown(s2)
 {
-	ourUp =  s1?s1->tempOwner == LOCPLINT->playerID:false;
-	ourDown = s2?s2->tempOwner == LOCPLINT->playerID:false;
+	ourUp =  s1?(s1->tempOwner == LOCPLINT->playerID || s1->tempOwner == 254):false; //254 - neutral objects (pandora, banks)
+	ourDown = s2?(s2->tempOwner == LOCPLINT->playerID || s2->tempOwner == 254):false;
 	set1 = LOCPLINT->cb->getGarrison(s1);
 	set2 = LOCPLINT->cb->getGarrison(s2);
 	pos.x += x;
@@ -4418,9 +4418,18 @@ void CGarrisonWindow::show(SDL_Surface * to)
 	quit->show(to);
 	garr->show(to);
 
+	std::string title;
+	if (garr->odown->tempOwner == garr->oup->tempOwner)
+		title = CGI->generaltexth->allTexts[709];
+	else
+	{
+		title = CGI->generaltexth->allTexts[35];
+		boost::algorithm::replace_first(title, "%s", garr->oup->Slots().begin()->second.type->namePl);
+	}
+
 	blitAt(graphics->flags->ourImages[garr->odown->getOwner()].bitmap,pos.x+28,pos.y+124,to);
 	blitAt(graphics->portraitLarge[static_cast<const CGHeroInstance*>(garr->odown)->portrait],pos.x+29,pos.y+222,to);
-	printAtMiddle(CGI->generaltexth->allTexts[709],pos.x+275,pos.y+30,FONT_BIG,tytulowy,to);
+	printAtMiddle(title,pos.x+275,pos.y+30,FONT_BIG,tytulowy,to);
 }
 
 CGarrisonWindow::CGarrisonWindow( const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits )

+ 6 - 4
hch/CObjectHandler.cpp

@@ -4458,7 +4458,7 @@ void CGSeerHut::completeQuest (const CGHeroInstance * h) const //reward
 		{
 			CCreatureSet creatures;
 			creatures.setCreature (0, rID, rVal);
-			cb->giveCreatures (id, h,  creatures);
+			cb->giveCreatures (id, h, creatures,false);
 		}
 			break;
 		default:
@@ -5027,14 +5027,16 @@ void CGPandoraBox::giveContents( const CGHeroInstance *h, bool afterBattle ) con
 		iw.text.addReplacement (h->name);
 
 		cb->showInfoDialog(&iw);
-		cb->giveCreatures (id, h, ourArmy);
+		cb->giveCreatures (id, h, ourArmy, true);
+		//boost::bind(&CGPandoraBox::endBattle, this, h, _1)
 	}
 	if(!afterBattle && message.size())
 	{
 		iw.text << message;
 		cb->showInfoDialog(&iw);
 	}
-	cb->removeObject(id);
+	if (!creatures.Slots().size())
+		cb->removeObject(id); //only when we don't need to display garrison window
 }
 
 void CGPandoraBox::getText( InfoWindow &iw, bool &afterBattle, int text, const CGHeroInstance * h ) const
@@ -5905,7 +5907,7 @@ void CBank::endBattle (const CGHeroInstance *h, const BattleResult *result) cons
 			iw.text.addReplacement (loot.buildList());
 			iw.text.addReplacement (h->name);
 			cb->showInfoDialog(&iw);
-			cb->giveCreatures (id, h, ourArmy);
+			cb->giveCreatures (id, h, ourArmy, false);
 		}
 		cb->setObjProperty (id, 15, 0); //bc = NULL
 	}

+ 1 - 1
hch/CObjectHandler.h

@@ -223,7 +223,7 @@ public:
 	BattleInfo *battle; //set to the current battle, if engaged
 
 	void setArmy(const CCreatureSet &src);
-	CCreatureSet getArmy() const;
+	CCreatureSet& getArmy() const;
 	void randomizeArmy(int type);
 
 	//////////////////////////////////////////////////////////////////////////

+ 1 - 1
lib/IGameCallback.h

@@ -86,7 +86,7 @@ public:
 	virtual void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb) =0; //cb will be called when player closes garrison window
 	virtual void showThievesGuildWindow(int requestingObjId) =0;
 	virtual void giveResource(int player, int which, int val)=0;
-	virtual void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures) =0;
+	virtual void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures, bool remove) =0;
 	virtual void takeCreatures (int objid, TSlots creatures) =0;
 	virtual void changeCreatureType (int objid, TSlot slot, TCreature creature) =0;
 	virtual void showCompInfo(ShowInInfobox * comp)=0;

+ 25 - 14
server/CGameHandler.cpp

@@ -2140,30 +2140,41 @@ void CGameHandler::giveResource(int player, int which, int val)
 	sr.val = gs->players.find(player)->second.resources[which]+val;
 	sendAndApply(&sr);
 }
-void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures)
+void CGameHandler::giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures, bool remove)
 {
 	if (creatures.stacksCount() <= 0)
 		return;
 	CCreatureSet heroArmy = h->getArmy();
-	while (creatures.stacksCount())
+	std::set<int> takenSlots;
+	for (TSlots::const_iterator it = creatures.Slots().begin(); it != creatures.Slots().end(); it++)
 	{
-		int slot = heroArmy.getSlotFor(creatures.Slots().begin()->second.type->idNumber);
-		if (slot < 0)
-			break;
-		heroArmy.addToSlot(slot, creatures.slots.begin()->second);
-		creatures.slots.erase (creatures.slots.begin());
+		int slot = heroArmy.getSlotFor(it->second.type->idNumber);
+		if (slot >= 0)
+		{
+			heroArmy.addToSlot(slot, it->second); 	//move all matching creatures to hero's army
+			takenSlots.insert(it->first); //slot id
+		}
 	}
-	//move all matching creatures to hero's army
+	for (std::set<int>::iterator it = takenSlots.begin(); it != takenSlots.end(); it++)
+		creatures.eraseStack(*it); //delete them from used army
+
 	SetGarrisons sg;
 	sg.garrs[h->id] = heroArmy;
-	//garrisons need to be synchronized after this, even if object vanishes
 	sg.garrs[objid] = creatures;
 	sendAndApply (&sg);
 
-	if (creatures.stacksCount()) //show garrison window and let player pick remaining creatures
+	if (remove) //show garrison window and let player pick remaining creatures
 	{
-		showGarrisonDialog (objid, h->id, true, 0);
+		if (creatures.stacksCount()) //Pandora needs to exist until we close garrison window
+		{
+			showGarrisonDialog (objid, h->id, true, boost::bind(&CGameHandler::removeObject, this, objid));
+		}
+		else
+			removeObject(objid);
 	}
+	else if (creatures.stacksCount())
+		showGarrisonDialog (objid, h->id, true, 0);
+		
 }
 void CGameHandler::takeCreatures (int objid, TSlots creatures) //probably we could use ArmedInstance as well
 {
@@ -2658,8 +2669,8 @@ bool CGameHandler::arrangeStacks( si32 id1, si32 id2, ui8 what, ui8 p1, ui8 p2,
 
 	if(what==1) //swap
 	{
-		if ( (s1->tempOwner != player && S1.slots[p1].count)
-		  || (s2->tempOwner != player && S2.slots[p2].count))
+		if ( ((s1->tempOwner != player && s1->tempOwner != 254) && S1.slots[p1].count) //why 254??
+		  || ((s2->tempOwner != player && s2->tempOwner != 254) && S2.slots[p2].count))
 		{
 			complain("Can't take troops from another player!");
 			return false;
@@ -2676,7 +2687,7 @@ bool CGameHandler::arrangeStacks( si32 id1, si32 id2, ui8 what, ui8 p1, ui8 p2,
 	else if(what==2)//merge
 	{
 		if (( S1.slots[p1].type != S2.slots[p2].type && complain("Cannot merge different creatures stacks!"))
-			|| (s1->tempOwner != player && S2.slots[p2].count) && complain("Can't take troops from another player!"))
+		|| ((s1->tempOwner != player && s1->tempOwner != 254) && S2.slots[p2].count) && complain("Can't take troops from another player!"))
 			return false; 
 
 		S2.slots[p2].count += S1.slots[p1].count;

+ 1 - 1
server/CGameHandler.h

@@ -135,7 +135,7 @@ public:
 	void showGarrisonDialog(int upobj, int hid, bool removableUnits, const boost::function<void()> &cb);
 	void showThievesGuildWindow(int requestingObjId); //TODO: make something more general?
 	void giveResource(int player, int which, int val);
-	void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures);
+	void giveCreatures (int objid, const CGHeroInstance * h, CCreatureSet creatures, bool remove);
 	void takeCreatures (int objid, TSlots creatures);
 	void changeCreatureType (int objid, TSlot slot, TCreature creature);
 	void showCompInfo(ShowInInfobox * comp);