Browse Source

- death stare works identically to H3
- gcc warnings fix

Ivan Savenko 13 years ago
parent
commit
7ce9e95525
2 changed files with 15 additions and 12 deletions
  1. 2 2
      lib/CBattleCallback.h
  2. 13 10
      server/CGameHandler.cpp

+ 2 - 2
lib/CBattleCallback.h

@@ -36,10 +36,10 @@ protected:
 	int player; // -1 gives access to all information, otherwise callback provides only information "visible" for player
 
 	CCallbackBase(CGameState *GS, int Player)
-		: gs(GS), player(Player), battle(nullptr)
+		: battle(nullptr), gs(GS), player(Player)
 	{}
 	CCallbackBase()
-		: gs(NULL), player(-1), battle(nullptr)
+		: battle(nullptr), gs(nullptr), player(-1)
 	{}
 	
 	void setBattle(const BattleInfo *B);

+ 13 - 10
server/CGameHandler.cpp

@@ -5257,17 +5257,20 @@ void CGameHandler::handleAfterAttackCasting( const BattleAttack & bat )
 
 	if (attacker->hasBonusOfType(Bonus::DEATH_STARE)) // spell id 79
 	{
+		// mechanics of Death Stare as in H3:
+		// each gorgon have 10% chance to kill (counted separately in H3) -> poisson distribution
+		// maximum amount that can be killed is (1 + gorgons / 5 ), rounded up
+
 		int staredCreatures = 0;
-		double mean = attacker->count * attacker->valOfBonuses(Bonus::DEATH_STARE, 0) / 100;
-		if (mean >= 1)
-		{
-			boost::poisson_distribution<int, double> p((int)mean);
-			boost::mt19937 rng;
-			boost::variate_generator<boost::mt19937&, boost::poisson_distribution<int, double> > dice (rng, p);
-			staredCreatures += dice();
-		}
-		if (((int)(mean * 100)) < rand() % 100) //fractional chance for one last kill
-			++staredCreatures;
+		double mean = double(attacker->count * attacker->valOfBonuses(Bonus::DEATH_STARE, 0)) / 100;
+
+		boost::poisson_distribution<> p(mean);
+		boost::mt19937 rng(rand());
+		boost::variate_generator<boost::mt19937&, boost::poisson_distribution<> > dice (rng, p);
+		staredCreatures += dice();
+
+		int maxToKill = 1 + (attacker->count + 4) / 5;
+		vstd::amin(staredCreatures, maxToKill);
 
 		staredCreatures += attacker->type->level * attacker->valOfBonuses(Bonus::DEATH_STARE, 1);
 		if (staredCreatures)