// Handles Game Difficulty.
// Worthless Bums 2012.


// Returns an amount of monsters to initially spawn based on dungeon level.
// NOTE: This gets called twice for a load game. The first time should spawn a base (dungeon level = 1) amount of monsters.
//		 The second call will be the correct amount for the loaded dungeon level!
function getDungeonLevelSpawnCount ()
{//echo("getDungeonLevelSpawnCount()");
//echo("$dungeonLevel =" SPC $dungeonLevel);
	%spawnCount = 32;
	%spawnCount += $dungeonLevel * getRandom(0, 10);
	switch ($difficultyLevel)
	{
		case 0:	// Easy.
			%spawnCount += getRandom(0, 2);
		case 1:	// Normal.
			%spawnCount += getRandom(5, 10);
		case 2:	// Hard.
			%spawnCount += getRandom(10, 20);
		case 3:	// Brutal.
			%spawnCount += getRandom(20, 40);
	}
	return %spawnCount;
}
// Adjusts monster by difficulty level.
function adjustMonsterForDifficulty (%monster)
{//echo("adjustMonsterForDifficulty()");
	// Dispatch by difficulty level.
	// 0 is Easy.
	// 1 is Normal.
	switch ($difficultyLevel)
	{
		case 0:	// Adjust for "Easy" difficulty.
			// Cut health.
			%monster.currentHealth = mFloor(%monster.currentHealth/$easyDifficultyModifier);
			if (%monster.currentHealth <= 0)
			{
				%monster.currentHealth = 1;
			}
			%monster.maxHealth = mFloor(%monster.maxHealth/$easyDifficultyModifier);
			if (%monster.maxHealth <= 0)
			{
				%monster.maxHealth = 1;
			}
			// Reduce AP by 1.
			if (%monster.currentActionPoints > 1)
			{
				%monster.currentActionPoints--;
			}
			if (%monster.maximumActionPoints > 1)
			{
				%monster.maximumActionPoints--;
			}
			%monster.baseDamage = mFloor(%monster.baseDamage - $easyDifficultyModifier);
			%monster.baseMeleeDamage = mFloor(%monster.baseMeleeDamage - $easyDifficultyModifier);
			%monster.baseRangeDamage = mFloor(%monster.baseRangeDamage - $easyDifficultyModifier);
			%monster.attackModifier = %monster.attackModifier -= (5 * $easyDifficultyModifier);
			%monster.evasion = mFloor(%monster.evasion - 5 * $easyDifficultyModifier);
			%monster.currentHealth += $NewGamePlus;
			%monster.maxHealth = %monster.currentHealth;
			%monster.armorRating += $NewGamePlus;
			
		case 1: // Adjust for "Normal" difficulty.
			%monster.currentHealth += 10 * $NewGamePlus;
			%monster.maxHealth = %monster.currentHealth;
			%monster.armorRating += $NewGamePlus;
			%monster.currentActionPoints += 1;
			%monster.maximumActionPoints += 1;
			
		case 2: // Adjust for "Hard" difficulty.
			%monster.currentHealth += 20 * $NewGamePlus + getRandom(5, 10);
			if (%monster.name $= "Hulk"			||
				%monster.name $= "Revenant"		||
				%monster.name $= "Brainien"		||
				%monster.name $= "Gunship"		||
				%monster.name $= "Matrix"		||
				%monster.name $= "Patriarch")
			{
				%monster.currentHealth += getRandom(50, 100);
			}
			%monster.maxHealth = %monster.currentHealth;
			%monster.armorRating += 2 * $NewGamePlus + getRandom(2, 5);
			%monster.currentActionPoints += getRandom(0, $NewGamePlus);
			%monster.maximumActionPoints = %monster.currentActionPoints;
			
		case 3: // Adjust for "Brutal" difficulty.
			%monster.currentHealth += 30 * $NewGamePlus + getRandom(20, 60);
			if (%monster.name $= "Hulk"			||
				%monster.name $= "Revenant"		||
				%monster.name $= "Brainien"		||
				%monster.name $= "Gunship"		||
				%monster.name $= "Matrix"		||
				%monster.name $= "Patriarch")
			{
				%monster.currentHealth += getRandom(100, 300);
			}
			%monster.maxHealth = %monster.currentHealth;
			%monster.armorRating += 10 * $NewGamePlus + getRandom(5, 15);
			%monster.currentActionPoints += getRandom($NewGamePlus, $NewGamePlus + 4);
			%monster.maximumActionPoints = %monster.currentActionPoints;
	}
	return %monster;
}