Browse Source

Give hero move points at day of visiting stable, fixes #2598

Piotr Wójcik 8 years ago
parent
commit
e3992de50e
3 changed files with 19 additions and 3 deletions
  1. 3 2
      lib/NetPacks.h
  2. 9 1
      lib/NetPacksLib.cpp
  3. 7 0
      lib/mapObjects/CGTownInstance.cpp

+ 3 - 2
lib/NetPacks.h

@@ -276,16 +276,17 @@ struct SetMana : public CPackForClient
 
 struct SetMovePoints : public CPackForClient
 {
-	SetMovePoints(){val = 0;}
+	SetMovePoints(){val = 0; absolute=true;}
 	void applyCl(CClient *cl);
 	DLL_LINKAGE void applyGs(CGameState *gs);
 
 	ObjectInstanceID hid;
 	si32 val;
+	bool absolute;
 
 	template <typename Handler> void serialize(Handler &h, const int version)
 	{
-		h & val & hid;
+		h & val & hid & absolute;
 	}
 };
 

+ 9 - 1
lib/NetPacksLib.cpp

@@ -206,7 +206,15 @@ DLL_LINKAGE void SetMana::applyGs(CGameState *gs)
 DLL_LINKAGE void SetMovePoints::applyGs(CGameState *gs)
 {
 	CGHeroInstance *hero = gs->getHero(hid);
-	hero->movement = val;
+
+	assert(hero);
+
+	if(absolute)
+		hero->movement = val;
+	else
+		hero->movement += val;
+
+	vstd::amax(hero->movement, 0); //not less than 0
 }
 
 DLL_LINKAGE void FoWChange::applyGs(CGameState *gs)

+ 7 - 0
lib/mapObjects/CGTownInstance.cpp

@@ -1302,6 +1302,13 @@ void COPWBonus::onHeroVisit (const CGHeroInstance * h) const
 					gb.bonus = Bonus(Bonus::ONE_WEEK, Bonus::LAND_MOVEMENT, Bonus::OBJECT, 600, 94, VLC->generaltexth->arraytxt[100]);
 					gb.id = heroID.getNum();
 					cb->giveHeroBonus(&gb);
+
+					SetMovePoints mp;
+					mp.val = 600;
+					mp.absolute = false;
+					mp.hid = heroID;
+					cb->setMovePoints(&mp);
+
 					iw.text << VLC->generaltexth->allTexts[580];
 					cb->showInfoDialog(&iw);
 				}