actor martianbastard : archvile replaces archvile
{
	SeeSound "martian/see"
	PainSound "martian/pain"
	ActiveSound "martian/idle"
	DeathSound "martian/die"
	Obituary  "%o didn't take cover from the martian"
	states
	{
	See:
		VILE AABBCCDDEEFF 2 A_VileChase
		TNT1 A 0 a_jump (6,"IdleSpawnMiscreant")
		Loop
	Missile:
		TNT1 A 0
		TNT1 A 0 a_jump (80,"NewHat")
	VileFlames:
		VILE G 0 Bright A_VileStart
		TNT1 A 0 a_playsound ("martian/attack",0)
		VILE G 10 Bright A_FaceTarget
		VILE H 8 Bright A_VileTarget
		VILE IJKLMN 8 Bright A_FaceTarget
		VILE O 8 Bright A_VileAttack
		VILE P 20 Bright
		Goto See
	NewHat:
		TNT1 A 0
		TNT1 A 0 a_jumpifintargetinventory ("MiscreantToken",1,"VileFlames")
		TNT1 A 0 a_custommissile ("HatPlacer")
		VILE ONMLK 5 bright a_facetarget
		TNT1 A 0 a_playsound ("martian/attack",0)
		TNT1 A 0 a_jumpifinventory ("stoptargeting",1,"pain")
		VILE JI 4 bright a_jumpifinventory ("stoptargeting",1,"pain")
		TNT1 A 0 a_facetarget
		TNT1 A 0 a_jumpifinventory ("stoptargeting",1,"pain")
		TNT1 A 0 a_jumpiftargetinLOS ("GiveHat",0,0,0,0)
		goto pain
	GiveHat:
		VILE H 2 bright
		VILE G 7 bright a_givetotarget ("HatSignal",1)
		VILE G 20 
		goto see
	SpawnMiscreant:
		VILE ONMLK 5 bright a_facetarget
		TNT1 A 0 a_playsound ("martian/attack",0)
		VILE JIH 5 bright
		TNT1 A 0 a_facetarget
		VILE G 7 bright a_spawnitemex ("Miscreant",0,0,45,0,0,0,0,SXF_NOCHECKPOSITION)
		//VILE G 7 bright A_GiveInventory ("NewHatSpawner",1)
		VILE G 20 
		goto see
	IdleSpawnMiscreant:
		TNT1 A 0
		TNT1 A 0 A_JumpIf(CallACS("Malefactors_CubeLimit") == 1, "See")
		VILE ONMLK 6 bright a_facetarget
		TNT1 A 0 a_playsound ("martian/attack",0)
		VILE JIH 9 bright 
		TNT1 A 0 a_facetarget
		VILE G 7 bright a_spawnitemex ("Miscreant",0,0,45,0,0,0,0,SXF_NOCHECKPOSITION)
		//VILE G 7 bright A_GiveInventory ("NewHatSpawner",1)
		VILE G 40 
		goto see	
	Heal:
		VILE "[\]" 10 BRIGHT
		TNT1 A 0 a_jump (10,"SpawnMiscreant")
		Goto See
	Pain:
		VILE Q 5 a_giveinventory ("MartianFlinch",1)
		VILE Q 5 A_Pain
		Goto See
	Death.CALinkedBomb:
	Death.CALinked:
		TNT1 A 0
		TNT1 A 0 a_scream
		TNT1 A 0 a_noblocking
		TNT1 A 0 a_setscale (1.60,2)
		TNT1 A 0 a_stop
		TNT1 A 0 A_ChangeFlag ("THRUACTORS",1)
		TNT1 A 0 a_playsound ("Malefactors/LinkedHurt",0,0.80)
		TNT1 A 1 a_spawnitemex ("CALinkedKill",0,0,35)
		TNT1 A 0 a_playsound ("Malefactors/LinkedDeath",0,1,0,0.90)
		TNT1 A 2
		TNT1 A 3 ThrustThingZ (0,30,0,1)
		L1ST L 2
		L1ST L -1
		wait
	Death.CABladeBeam:
		TNT1 A 0
		TNT1 A 0 a_facetarget
		TNT1 A 0 a_scream
		TNT1 A 0 a_noblocking
		TNT1 A 0 a_spawnitemex ("MalefactorMartianTorso",0,0,49,random(-3,3),random(-3,3),random (1,2),0,SXF_NOCHECKPOSITION)
		TNT1 A 0 a_playsound ("Malefactors/BladeBeamDeath2",0,1,0,0.90)
		8D14 B random (45,50)
		TNT1 A 0 a_stopsound (CHAN_VOICE)
		TNT1 AAA 0 a_spawnitemex("FireDebris",0,0,random(3,8),random(-8,8),random(-7,7),random(6,7),0,SXF_NOCHECKPOSITION)
		TNT1 A 0 a_playsound ("Malefactors/BladeBeamExplosion",0,0.60,0)
		TNT1 A 0 A_SpawnItemEx("MonsterFireExplosion",0,0,30)
		stop
	}
}




actor MalefactorMartianTorso : MalefactorRiflemanTorso
{
	gravity 0.80
    States
    {
    Spawn:
		TNT1 A 0
		8D14 A 6
		TNT1 A 0 a_scalevelocity (0.30)
		8D14 A 6
		TNT1 A 0 a_scalevelocity (0.50)
		8D14 A 6
		TNT1 A 0 a_stop
		8D14 A 10
		TNT1 A 0 a_changeflag ("NOGRAVITY",0)
		TNT1 A 0 a_changeflag ("HEXENBOUNCE",0)
	Falling:
		8D14 A 1
		TNT1 A 0 A_CheckFloor ("Death")
		loop
    }
}


actor HatPlacer
{
	projectile
	renderstyle add
	alpha 0.80
	+SEEKERMISSILE
	+NOCLIP
	+THRUACTORS
	speed 1

	var int user_CubeTimer;
	states
	{
	spawn:
		TNT1 A 0
		TNT1 A 1 a_playsound ("Malefactors/CubeForm",0,1,0,0.8)
	SpawnLoop:
		TNT1 A 0 a_jumpifinventory ("MartianFlinch",1,"canceltarget",AAPTR_TARGET)
		TNT1 A 1 a_warp (AAPTR_TRACER,10,0,52,0,WARPF_NOCHECKPOSITION|WARPF_INTERPOLATE)
		TNT1 A 0 a_jumpifinventory ("MartianFlinch",1,"canceltarget",AAPTR_TARGET)
		TNT1 AA 0 a_spawnitemex ("spidercharge",Frandom(-4,4),Frandom(-4,4),1,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,0)
		TNT1 A 0 a_jumpif (user_CubeTimer >= 45, "Death")
		TNT1 A 0 a_setuservar("user_CubeTimer", user_CubeTimer+1)

		TNT1 A 0 a_jumpifinventory ("HatSignal", 1, "SpawnMiscreant",AAPTR_TRACER)
		TNT1 A 0 a_jumpiftargetinlos ("SpawnLoop",0)
		goto death
	death:
		TNT1 A 0
		TNT1 A 0 a_stopsound(CHAN_VOICE)
		TNT1 A 1 a_giveinventory ("stoptargeting",1,AAPTR_TARGET)
		stop
	canceltarget:
		TNT1 A 0
		TNT1 A 0 a_stopsound(CHAN_VOICE)
		TNT1 A 1
		stop		
	SpawnMiscreant:
		TNT1 A 0 a_stop
		TNT1 A 0 a_stopsound (CHAN_VOICE)
		TNT1 AAA 1 a_spawnitemex ("spidercharge",Frandom(-4,4),Frandom(-4,4),1,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,0)
		TNT1 AAA 1 a_spawnitemex ("spidercharge",Frandom(-4,4),Frandom(-4,4),1,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,0) 
		TNT1 A 0 a_playsound ("brain/spit",0,0.40)
		TNT1 A 1 a_spawnitemex ("Miscreant",0,0,3,0,0,0,0,SXF_NOCHECKPOSITION)
		stop
	}
}





//==========================================================================
//==========================================================================
//-----------------------------Miscreant------------------------------------
//==========================================================================
//==========================================================================

ACTOR Miscreant
{
	Health 100
	Radius 16
	Height 42
	Mass 50
	Speed 8
	PainChance 256
	Monster
	Bloodtype "CADustBlood"
	SeeSound "Miscreant/see"
	PainSound "Miscreant/pain"
	ActiveSound "Miscreant/idle"
	DeathSound "Miscreant/die"
	+FLOAT
	+NOGRAVITY
	+MISSILEMORE
	+DONTFALL
	+lookallaround
	+FORCEXYBILLBOARD
	+bright
	+FLOATBOB
	+DOHARMSPECIES
	+noblooddecals
	-solid
	-COUNTKILL
	Obituary  "%o fell victim to a Miscreant"

	var int user_CubeSpawned;
	states
	{
	spawn:
		TNT1 A 0
		TNT1 A 0 a_giveinventory ("MiscreantToken",1)
		TNT1 A 1 
		TNT1 A 0 a_jumpif (user_CubeSpawned >= 1, "Idle")
		TNT1 A 0 a_setuservar("user_CubeSpawned", user_CubeSpawned+1)
		TNT1 A 0 a_spawnitemex ("Teleportfog")
		TNT1 A 0 a_jump (30, "AnnounceProblems")
		YH11 DCBA 2
		YH11 DCCBBBAAAA 2
		YH11 ABCD 1 a_look
		goto idle
	AnnounceProblems:
		TNT1 A 0 a_playsound ("Miscreant/Spawn",CHAN_VOICE,1,0,0.90)
		YH11 DCBA 1
		YH11 DCBA 1
		YH11 DCBA 1
		YH11 DCBA 1
		YH11 DCBA 1
		YH11 DCBA 1
		YH11 DCBA 2
		YH11 DCBA 2
		YH11 DCBA 2
		YH11 DCBA 2
		YH11 DCBA 2
		YH11 DCBA 2
		YH11 DCCBBBAAAA 2
		YH11 DCCBBBAAAA 2
		YH11 ABCD 1 a_look
		goto idle
		
	Idle:
		TNT1 A 0
		TNT1 A 0 a_look
		TNT1 A 0 a_jump (30,"TauntPlayer")
		YH11 ABCD 4 a_wander
		loop
	TauntPlayer:
		TNT1 A 0
		YH11 A 1 a_playsound ("Miscreant/idle",CHAN_VOICE)
		goto idle
	See:
		YH11 ABCD 4 a_chase
		loop
	Missile:
		YH11 ABCD 4 
		YH11 ABCD 2
		TNT1 A 0 a_playsound ("Miscreant/Attack",CHAN_VOICE,1,0,0.60)
		YH11 ABCD 2 a_spawnitemex ("PuttiCharge",Frandom(-4,4),Frandom(-4,4),25,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,0)
		YH11 ABCD 2 a_spawnitemex ("PuttiCharge",Frandom(-4,4),Frandom(-4,4),25,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,0)
		YH11 ABCD 1 a_spawnitemex ("PuttiCharge",Frandom(-4,4),Frandom(-4,4),25,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,0)
		YH11 ABCD 1 a_spawnitemex ("PuttiCharge",Frandom(-4,4),Frandom(-4,4),25,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,0)
		YH11 ABCD 1 a_spawnitemex ("PuttiCharge",Frandom(-4,4),Frandom(-4,4),25,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,0)
		YH11 ABCD 1 a_spawnitemex ("PuttiCharge",Frandom(-4,4),Frandom(-4,4),25,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,0)
		YH11 ABCD 1 a_spawnitemex ("PuttiCharge",Frandom(-4,4),Frandom(-4,4),25,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,0)
		YH11 ABCD 1 a_spawnitemex ("PuttiCharge",Frandom(-4,4),Frandom(-4,4),25,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,Frandom(-100,100)/20.0,0)
		TNT1 A 0 a_facetarget
		TNT1 A 0 a_playsound ("vile/firestrt",0,1,0,0.70)
		TNT1 A 0 a_playsound ("Miscreant/Spit",0,1,0,0.70)
		YH11 A 1 a_custommissile ("BaronBall")
		TNT1 A 0 a_recoil (6)
		YH11 AABBBCCCCDDDDDD 1
		TNT1 A 0 a_scalevelocity (0.40)
		YH11 DD 3
		TNT1 A 0 a_stop
		YH11 DCBA 3 a_wander
		goto see
	Pain:
		TNT1 A 0
		YH11 A 1
		YH11 A 2
		TNT1 A 0 a_playsound ("Miscreant/Clang",0,0.80)
		YH11 A 7 a_pain
		YH11 A 1 a_fastchase
		YH11 A 2 a_fastchase
		YH11 ABCD 2
		goto see
	Death:
		TNT1 A 0
		TNT1 A 0 a_scream
		YH11 ABCD 1
		YH11 ABCD 1
		YH11 ABCD 1
		YH11 A 2 A_setscale (1.05)
		YH11 A 2 A_setscale (1.15)
		TNT1 A 0 a_stopsound (CHAN_VOICE)
		TNT1 A 0 A_SpawnItemEx("MonsterFireExplosion",0,0,20,0,0,0,0,SXF_NOCHECKPOSITION)
		TNT1 A 0 A_SpawnItemEx("MiscreantExplosion",0,0,20,0,0,0,0,SXF_NOCHECKPOSITION)
		TNT1 A 0 a_explode (20,150,1,0,40)
		TNT1 A 0 a_quake (5,20,0,300,0)
		TNT1 A 0 a_quake (3,20,0,1200,0)
		TNT1 A 0 a_setscale (1.30)
		TNT1 A 0 a_playsound ("weapons/rocklx",0,0.80,0,0.90)
		TNT1 A 30
		stop
	Death.CALinkedBomb:
	Death.CALinked:
		TNT1 A 0
		TNT1 A 0 a_changeflag ("nogravity",1)
		TNT1 A 0 a_scream
		YH11 ABCD 1
		YH11 ABCD 1
		YH11 ABCD 1
		YH11 A 2 A_setscale (1.05)
		YH11 A 2 A_setscale (1.15)
		TNT1 A 0 A_stopsound (CHAN_VOICE)
		TNT1 A 0 a_playsound ("Malefactors/LinkedHurt",0,0.80)
		TNT1 A 1 a_spawnitemex ("CALinkedKill",0,0,35)
		TNT1 A 0 a_playsound ("Malefactors/LinkedDeath",0,1,0,0.90)
		TNT1 A 2
		stop
	Death.CABladeBeam:
		TNT1 A 0
		TNT1 A 0 a_facetarget
		TNT1 A 0 a_scream
		TNT1 A 0 a_noblocking
		TNT1 A 0 A_changeflag ("FLOATBOB",0)
		TNT1 A 0 a_spawnitemex ("MalefactorCubeTop",0,0,10,random(-3,3),random(-3,3),random (1,2),0,SXF_NOCHECKPOSITION)
		TNT1 A 0 a_playsound ("Malefactors/BladeBeamDeath1",0,1,0,0.90)
		8D17 B random (1,2)
		TNT1 A 0 a_nogravity
		8D17 B 2 a_scalevelocity (0.40)
		8D17 B 2 
		8D17 B 2 a_scalevelocity (0.40)
		TNT1 A 0 a_stopsound (CHAN_VOICE)
		TNT1 A 0 a_stop
		8D17 B random (36,40)
		TNT1 A 0 a_gravity
		8D17 B 1 thrustthingz (0,1,0,0)
	HalfFalling:
		8D17 B 1 A_JumpIf(Abs(VelZ) <= 0.01, "SlicedStop")
		loop
	SlicedStop:
		TNT1 A 0
		TNT1 AAA 0 a_spawnitemex("FireDebris",0,0,random(3,8),random(-8,8),random(-7,7),random(6,7),0,SXF_NOCHECKPOSITION)
		TNT1 A 0 a_playsound ("Malefactors/BladeBeamExplosion",0,0.60,0)
		TNT1 A 1 A_SpawnItemEx("MonsterFireExplosion",0,0,30)
		stop
	}
}



actor PuttiCharge : cacocharge
{
	scale 0.30
	+bright
	states
	{
	spawn:
		TNT1 A 0
		TNT1 A 6
		TNT1 A 0 a_scalevelocity (-2)
		BAL7 C 5 
		goto death
	}
}


actor MalefactorCubeTop : MalefactorRiflemanTorso
{
	gravity 0.80
    States
    {
    Spawn:
		TNT1 A 0
		8D17 A 6
		TNT1 A 0 a_scalevelocity (0.30)
		8D17 A 6
		TNT1 A 0 a_scalevelocity (0.50)
		8D17 A 6
		TNT1 A 0 a_stop
		8D17 A 10
		TNT1 A 0 a_changeflag ("NOGRAVITY",0)
		TNT1 A 0 a_changeflag ("HEXENBOUNCE",0)
	Falling:
		8D17 A 1
		TNT1 A 0 A_CheckFloor ("Death")
		loop
    }
}

//==========================================================================
//==========================================================================
//==========================================================================
//Tokens
Actor MartianFlinch : Powerup
{
  Powerup.Duration 5
}


actor StopTargeting :  Powerup
{
  Powerup.Duration 5
}

Actor HatSignal : Powerup
{
  Powerup.Duration 15
}

actor MiscreantToken : inventory
{
	+UNDROPPABLE 
	-INVBAR
	inventory.maxamount 1
}
