// Unit Automation Handler.
// Worthless Bums 2013.


// Returns a list (SimSet) of a creature of the specified name.
function getMonsterNameList (%name)
{//echo("getMonsterNameList()");
	%monsterNameList = new SimSet();
	for (%i = 0; %i < $monsterList.getCount(); %i++)
	{
		%monster = $monsterList.getObject(%i);
		if (%monster.name $= %name)
		{
			%monsterNameList.add(%monster);
		}
	}
	return %monsterNameList;
}

// Execute enemy unit automations on move.
function executeEnemyUnitAutomationsOnMove ()
{//echo("executeEnemyUnitAutomationsOnMove()");
	/*
	// Brute automation.
	%monsterNameList = getMonsterNameList("Brute");
	%listLength = %monsterNameList.getCount();
	if (%listLength > 0)
	{
		for (%i = 0; %i < %listLength; %i++)
		{
			%monster = %monsterNameList.getObject(%i);
			if (%monster.isActive)
			{
				// Brute try to turn toward any player unit that moves!
				%direction = getDirectionBetweenPoints(%monster.xIndex, %monster.yIndex, $playerSquad[$activeCharacter].xIndex, $playerSquad[$activeCharacter].yIndex);
				setMonsterFacing(%direction, %monster);
			}
		}
	}
	*/
	
	// Ripsaw automation.
	%monsterNameList = getMonsterNameList("Ripsaw");
	%listLength = %monsterNameList.getCount();
	if (%listLength > 0)
	{
		for (%i = 0; %i < %listLength; %i++)
		{
			%monster = %monsterNameList.getObject(%i);
			if (%monster.isActive)
			{
				// Ripsaws try to turn toward any player unit that moves!
				%direction = getDirectionBetweenPoints(%monster.xIndex, %monster.yIndex, $playerSquad[$activeCharacter].xIndex, $playerSquad[$activeCharacter].yIndex);
				setMonsterFacing(%direction, %monster);
			}
		}
	}
	
	// Amputator automation.
	%monsterNameList = getMonsterNameList("Amputator");
	%listLength = %monsterNameList.getCount();
	if (%listLength > 0)
	{
		for (%i = 0; %i < %listLength; %i++)
		{
			%monster = %monsterNameList.getObject(%i);
			if (%monster.isActive)
			{
				// Amputators try to turn toward any player unit that moves!
				%direction = getDirectionBetweenPoints(%monster.xIndex, %monster.yIndex, $playerSquad[$activeCharacter].xIndex, $playerSquad[$activeCharacter].yIndex);
				setMonsterFacing(%direction, %monster);
			}
		}
	}
}