///////////////////////////////////////////////////////////////////////////////
//	Land 10 Creature AI
//	~~~~~~~~~~~~~~~~~~~
//
//	Start date:			29.10.16			By:	Boxhead
//	Update date:		30.10.16			By: Boxhead
///////////////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------------------
//	Globals
//-----------------------------------------------------------------------------

global CreatureAttackPos[3]
global CreatureBuildPos[2]
global CreatureGathererPos[3]

//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------

begin script LC10_AICreature

start

	CreatureAttackPos[0] = marker at {1328.65,223.10,1572.31}//AztecPreTown
	CreatureAttackPos[1] = marker at {1786.61,206.64,1235.11}//AztecFirstTown
	CreatureAttackPos[2] = marker at {1475.16,237.17,754.29}//PlayerTown

	CreatureBuildPos[0] = marker at {1750.75,214.98,1174.86}//AztecFirstTown
	CreatureBuildPos[1] = marker at {878.06,397.12,1745.96}//AztecCapital

	CreatureGathererPos[0] = marker at {1295.24,268.56,1712.04}//AztecPreTown
	CreatureGathererPos[1] = marker at {1648.24,210.86,1024.51}//AztecFirstTown
	CreatureGathererPos[2] = marker at {797.33,402.87,1772.67}//AztecCapital

	LC10_EnemyCreature = create SCRIPT_OBJECT_TYPE_CREATURE CREATURE_TYPE_GORILLA at {766.17,404.48,1793.18}
	
	set creature LC10_EnemyCreature happiness to maximum
	set creature LC10_EnemyCreature CREATURE_SCRIPT_TRANSITIONAL_ATTRIBUTE_TYPE_SIZE 1.0
	
	set research ARTEFACT_CREATURE_MAGIC_TYPE_WATER available to RESEARCH_AVAILABILITY_RESEARCHED player 1
	set research ARTEFACT_CREATURE_MAGIC_TYPE_LIGHTNING available to RESEARCH_AVAILABILITY_RESEARCHED player 1
	set research ARTEFACT_CREATURE_MAGIC_TYPE_FIREBALL available to RESEARCH_AVAILABILITY_RESEARCHED player 1
	set research ARTEFACT_CREATURE_MAGIC_TYPE_HEAL available to RESEARCH_AVAILABILITY_RESEARCHED player 1
	set research ARTEFACT_CREATURE_ROLE_BUILDER_4 available to RESEARCH_AVAILABILITY_RESEARCHED player 1
	set research ARTEFACT_CREATURE_ROLE_GATHERER_4 available to RESEARCH_AVAILABILITY_RESEARCHED player 1
	set research ARTEFACT_CREATURE_ROLE_SOLDIER_4 available to RESEARCH_AVAILABILITY_RESEARCHED player 1

	set creature LC10_EnemyCreature CREATURE_SCRIPT_TRANSITIONAL_ATTRIBUTE_TYPE_SIZE 1.0
	STRENGTH of LC10_EnemyCreature = 0.9
	ALIGNMENT of LC10_EnemyCreature = -1.0
	FATNESS of LC10_EnemyCreature = 0.2

	disable LC10_EnemyCreature action availability LA_EAT with LO_PLAYER_VILLAGER
	disable LC10_EnemyCreature action availability LA_EAT with LO_PLAYER_PLATOON
	disable LC10_EnemyCreature action availability LA_EAT with LO_ROCKS
	disable LC10_EnemyCreature action availability LA_EAT with LO_TREES
	disable LC10_EnemyCreature action availability LA_EAT with LO_TOYS
	disable LC10_EnemyCreature action availability LA_EAT with LO_POO
	disable LC10_EnemyCreature action availability LA_EAT with LO_SPELL_ORBS
	disable LC10_EnemyCreature action availability LA_POO with LO_PLAYER_VILLAGER
	disable LC10_EnemyCreature action availability LA_POO with LO_PLAYER_PLATOON
	disable LC10_EnemyCreature action availability LA_POO with LO_PLAYER_DEFENCES
	disable LC10_EnemyCreature action availability LA_POO with LO_PLAYER_STORAGE_PIT
	disable LC10_EnemyCreature action availability LA_POO with LO_PLAYER_BUILDING
	disable LC10_EnemyCreature action availability LA_PLAY
	disable LC10_EnemyCreature action availability LA_WATER with LO_PLAYER_VILLAGER
	disable LC10_EnemyCreature action availability LA_WATER with LO_PLAYER_PLATOON
	disable LC10_EnemyCreature action availability LA_HEAL with LO_OPPONENT_PLATOON
	disable LC10_EnemyCreature action availability LA_ATTACK with LO_CREATURE_PEN
	disable LC10_EnemyCreature action availability LA_ATTACK with LO_ROCKS
	disable LC10_EnemyCreature action availability LA_ATTACK with LO_MINE
	disable LC10_EnemyCreature action availability LA_ATTACK with LO_ORE_ROCKS
	disable LC10_EnemyCreature action availability LA_ATTACK with LO_TREES
	disable LC10_EnemyCreature action availability LA_ATTACK with LO_FIELDS
	disable LC10_EnemyCreature action availability LA_ATTACK with LO_POO
	disable LC10_EnemyCreature action availability LA_ATTACK with LO_SPELL_ORBS

	teach LC10_EnemyCreature all
	
	set player 1 creature to LC10_EnemyCreature
	
	wait 50 seconds
	
	release LC10_EnemyCreature

	run background script LC10_CreatureLogic
	run background script LC10_CreatureThrowFireball

end script LC10_AICreature

begin script LC10_CreatureLogic

	Number = 0
	CreatureRollRoleTimer = create timer for 0 seconds

start

	Enemy_Creature_Attack_Delay = create timer for 900 seconds

begin loop

	if HEALTH of LC10_EnemyCreature == 0.00
		wait until HEALTH of LC10_EnemyCreature > 0.00
		HEALTH of LC10_EnemyCreature = 1.0
	end if

	if ENEMY_CREATURE_ALLOWED_TO_ATTACK == 1
		if PLAYER of AztecPreTown == 0 and HEALTH of LC10_EnemyCreature > 0.00
			if AztecPreTownAttackStarting == 1
				HEALTH of LC10_EnemyCreature = 1.0
				set creature LC10_EnemyCreature role to CR_SOLDIER radius 100 at {CreatureAttackPos[0]}
				wait until HEALTH of LC10_EnemyCreature == 0.00 or 1000 seconds
				ENEMY_CREATURE_ALLOWED_TO_ATTACK = 0
				AztecPreTownAttackStarting = 0
			end if
			
		elsif PLAYER of AztecFirstTown == 0 and HEALTH of LC10_EnemyCreature > 0.00
			if AztecFirstTownAttackStarting == 1
				HEALTH of LC10_EnemyCreature = 1.0
				set creature LC10_EnemyCreature role to CR_SOLDIER radius 100 at {CreatureAttackPos[1]}
				wait until HEALTH of LC10_EnemyCreature == 0.00 or 1000 seconds
				ENEMY_CREATURE_ALLOWED_TO_ATTACK = 0
				AztecFirstTownAttackStarting = 0
			end if
			
		elsif PLAYER of PlayerTown == 0 and HEALTH of LC10_EnemyCreature > 0.00
			HEALTH of LC10_EnemyCreature = 1.0
			set creature LC10_EnemyCreature role to CR_SOLDIER radius 100 at {CreatureAttackPos[2]}
			wait until HEALTH of LC10_EnemyCreature == 0.00 or 1000 seconds
			ENEMY_CREATURE_ALLOWED_TO_ATTACK = 0	
		end if
		
	//elsif ENEMY_CREATURE_BUILDER == 1 and not ENEMY_CREATURE_ALLOWED_TO_ATTACK == 1 and HEALTH of LC10_EnemyCreature > 0.00 and get CreatureRollRoleTimer time remaining <= 0
	//	if BuildWall1 == 1
	//		set creature LC10_EnemyCreature role to CR_BUILDER radius 250 at {CreatureBuildPos[0]}
	//		CreatureRollRoleTimer = create timer for 275 seconds
	//		
	//	elsif BuildWall2 == 1
	//		set creature LC10_EnemyCreature role to CR_BUILDER radius 250 at {CreatureBuildPos[1]}
	//		CreatureRollRoleTimer = create timer for 275 seconds
	//		
	//	end if
	
	elsif not ENEMY_CREATURE_ALLOWED_TO_ATTACK == 1 and HEALTH of LC10_EnemyCreature > 0.00 and get CreatureRollRoleTimer time remaining <= 0
		Number = number from 1 to 5
		if Number == 1 and PLAYER of AztecPreTown == 1
			set creature LC10_EnemyCreature role to CR_GATHERER radius 300 at {CreatureGathererPos[0]}
			CreatureRollRoleTimer = create timer for 360 seconds
			
		elsif Number == 2 and PLAYER of AztecFirstTown == 1
			set creature LC10_EnemyCreature role to CR_GATHERER radius 300 at {CreatureGathererPos[1]}
			CreatureRollRoleTimer = create timer for 360 seconds
			
		elsif Number >= 3 and PLAYER of AztecCapital == 1
			set creature LC10_EnemyCreature role to CR_GATHERER radius 300 at {CreatureGathererPos[2]}
			CreatureRollRoleTimer = create timer for 360 seconds
		
		end if
	end if
end loop

end script LC10_CreatureLogic

begin script LC10_CreatureThrowFireball

	CreatureFireBallTimer = create timer for 0 seconds
	Target = 0
	EnemyCreature = 0

start

begin loop

	Target = get wall segment nearest {EnemyCreature} radius 85
	if Target exists and PLAYER of Target == 0 and get CreatureFireBallTimer time remaining <= 0 and HEALTH of EnemyCreature > 0.05
		force LC10_EnemyCreature CREATURE_CAST_FIREBOMB_THROW Target at {Target}
		CreatureFireBallTimer = create timer for 45 seconds
		Target = 0
	end if

end loop

end script LC10_CreatureThrowFireball
