
	// A dumbed down version of a pinky, does NOT support fatalities and his damage type is Cut
	// uses Project Brutality's mean demon sprites
	
ACTOR StoneskinPinkyAttack: DemonAttack {
	DamageType Cut
}	

ACTOR StoneskinPinky: ZandronumDemon 17627
{
	//***Che radius, height and maxdropoffheight (n/a for flying ones) MUST be kept consistent with FBD_TrySpawn in FBD_CORE.acs!
	
	Monster
	
	// Project Brutality's Mean Demon (dark red) to shiny gray
	Translation "16:25=80:98", "26:37=99:111", "38:47=5:8", "208:223=99:111"
	
	Tag "$STONESKIN_PINKY" // Stoneskin Pinky
	Obituary "$STONESKIN_PINKY_O" // %o was mauled by a Stoneskin Pinky.
	Translation "16:47=99:111"
	Health 2000 // ten times as durable
	damagefactor "Ice", 7.0
	damagefactor "Fire", 7.0 // bonus for those familiar with D&D lore: that spell does not protect against elemental damage
	damagefactor "Flames", 7.0
	damagefactor "Electric", 7.0
	damagefactor "Slime", 7.0
	damagefactor "SSG", 2.0 // original has 50x
	PainChance 0 // he *only* flinches to elemental damage
	PainChance "Ice", 255
	PainChance "Fire", 200
	PainChance "Electric", 100
	PainChance "Slime", 200
	
	PainChance "Argent", 255
	DamageFactor "Argent", 1.0	
	PainChance "Taunt", 255
	DamageFactor "Taunt", 1.0		
	
	+NOEXTREMEDEATH
	+NOICEDEATH
	
	//$category "FBD Monsters"
	//$Sprite SAR2A1
	
	var int user_head_tid;
	var int user_sleeping;
	var int user_item_no;
	var int user_serverside_sfchk;
	
    Scale 1.1
	Height 56
	Radius 20
	Mass 400
    Speed 14
    FastSpeed 22
	DamageFactor "Explosive", 1.4
    damagefactor "Crush", 10.0
	damagefactor "Avoid", 0.0	damagefactor "GibRemoving", 0.0	damagefactor "TeleportRemover", 0.0
	DamageFactor "CauseSplash", 0.0 DamageFactor "CauseObjectsToSplashSlime", 0.0 DamageFactor "CauseObjectsToSplashNukage", 0.0
	DamageFactor "CauseObjectsToSplashBlood", 0.0 DamageFactor "CauseObjectsToSplashLava", 0.0
	
	damagefactor "Blood", 0.0 damagefactor "BlueBlood", 0.0 damagefactor "GreenBlood", 0.0
	+FLOORCLIP 
	-FASTER
	+SLIDESONWALLS
	+NEVERFAST
	SeeSound "demon/sight"
	PainSound "demon/pain"
	DeathSound "demon/death"
	ActiveSound "PINKIDL"
    BloodType "FBD_Blood", "FBD_SawBlood", "FBD_SawBlood"
	DamageType Eat
	MaxStepHeight 32
	MaxDropOffHeight 32
	MeleeRange 100
	DropItem "DemonStrengthRune" 25
	
	var int user_jump_power; // passed to A_ThrustThingZ, set via ACS call (scales with map gravity for EDAY Mars chapter)
	
	damagefactor "Bullet792", 1.2
	damagefactor "SniperBullet", 1.2 // must die in 3 shots (damage 60)
	
	damagefactor "Killme", 0.0 // AOE inflicted by captured marines
	
	damagefactor "ComeEatMeDemon", 0.0 // the only monster affected by this (AOE spammed by dead player's lower half, causes pinkies to come and eat it)
	
	BloodType "StoneBlood", "StoneBlood_Saw", "StoneBlood_Saw"
	

	//$Arg0 Caster (dispel on his death)
	//$Arg0Type 14

	/*
    0 = Integer (default)
    4 = Action special
    5 = Sector effect
    8 = Angle in degrees
    10 = XXRRGGBB color
    11 = Enum option
    12 = Enum bits
    13 = Sector tag
    14 = Thing tag
    15 = Linedef tag
    22 = Byte angle
    23 = Thing Radius
    24 = Thing Height
	*/	



	States
	{
		Spawn:
			SAR2 E 0 NODELAY ACS_NamedExecuteWithResult("FBD_RunMonster")
			SAR2 E 2 // jump power script can only decect EDAY on the second tic
			SAR2 E 0 A_SetUserVar("user_jump_power", CallAcs("AdjustJumpPowerForEDAYMarsChapter", 25))
			"----" A 0 A_JumpIf(args[0], "LinkToMaster")
			Goto Spawned
			
		Raise:
			Stop // cancel this stae, he should never be raiseable!
		
		LinkToMaster:
			"----" A 0 ACS_NamedExecuteWithResult("LinkStoneskinPinkyToCaster", args[0]) // keeps running, checking if that monster is alive. If not, dispels.
			// a hack to avoid unfortunate implications:
			"----" A 0 A_ChangeFlag("COUNTKILL", 0)
			Goto Spawned
		
		Pain.Ice:
			"----" A 20 A_Pain
			Goto See
		Pain:
			SAR2 H 4 A_Pain
			Goto SeeContinue

		Pain.Argent:

			TNT1 A 0
		
			TNT1 A 0 A_ClearTarget
			TNT1 A 0 HealThing(300)
			TNT1 A 0 ACS_NamedExecuteWithResult("DisplayArgentDischarge", 20, 48, 0)	
			
			TNT1 A 0 A_GiveInventory("ComeEatMeDemon", 1)
			TNT1 A 0 A_ChangeFlag("QUICKTORETALIATE", 1)
			TNT1 A 0 A_ChangeFlag("ALWAYSFAST", 1)
			TNT1 A 0 A_ChangeFlag("NEVERFAST", 0)
			
			SAR2 HHHH 8 A_Pain
			Goto SeeContinue

		Death:
		XDeath:
		DispelStoneSkin:
			// NEVER call A_NoBlocking
			TNT1 A 0
			TNT1 A 0 A_ChangeFlag("THRUACTORS", 1)			
			TNT1 A 0 A_SpawnItemEx ("StoneskinPinkyDeathSFX",0,0,0,0,0,0,0,SXF_NOCHECKPOSITION, 0)
			TNT1 A 0 A_SpawnItemEx ("FBD_BullDemon",0,0,0,velx,vely,velz,0,SXF_NOCHECKPOSITION | SXF_TRANSFERPOINTERS | SXF_TRANSFERSPECIAL | SXF_CLEARCALLERTID | SXF_ABSOLUTEVELOCITY, 0, tid)
			TNT1 A 0 A_ChangeFlag("COUNTKILL", 0)
			TNT1 A 0 A_ChangeFlag("SHOOTABLE", 0)
			TNT1 A 30
			Stop // be gone
			
		WaitTargetsFatalityOut:
			TNT1 A 0 A_PlaySound("demon/sight", CHAN_VOICE)
			SAR2 H 1 A_Jump(256, "WTF1", "WTF2", "WTF3", "WTFWander", "WTFWander", "WTFWander")
			Wait
		WTF1:
			SAR2 HHHH 12 A_SetAngle(angle + Random(-20,20))
			Goto See
		WTF2:
			SAR2 EEEEEE 9 A_SetAngle(angle + Random(-20,20))
			Goto See	
		WTF3:
			SAR2 EEEEEEE 6 
			Goto See	
		WTFWander:
			SAR2 AABBCCDDAABBCCDDAABBCCDD 2 A_Wander
			Goto See

		Spawned:	
			SAR2 EEEEEEEEEEE 10 A_Look
			Loop
			
		Forget:	
			TNT1 A 0 A_ClearTarget
			TNT1 A 0 A_TakeInventory("EnemyMemory", 15)
		SearchPlayer:
		Idle:
			
			SAR2 EE 10 A_Look
			TNT1 A 0 A_SetAngle(angle - 40)
			SAR2 EE 10 A_Look
			TNT1 A 0 A_SetAngle(angle + 40)
			SAR2 EE 10 A_Look
			
			
			SAR2 A 0 A_Wander
			SAR2 A 2 A_Look
			SAR2 A 0 A_Wander
			SAR2 A 2 A_Look
			SAR2 B 0 A_Wander
			SAR2 B 2 A_Look
			SAR2 B 0 A_Wander
			SAR2 B 2 A_Look
			SAR2 C 0 A_Wander
			SAR2 C 2 A_Look
			SAR2 C 0 A_Wander
			SAR2 C 2 A_Look
			SAR2 D 0 A_Wander
			SAR2 D 2 A_Look
			SAR2 D 0 A_Wander
			SAR2 D 2 A_Look
			
			TNT1 A 0 A_Jump(128, "SearchPlayer")
			
			SAR2 A 0 A_Wander
			SAR2 A 2 A_Look
			SAR2 A 0 A_Wander
			SAR2 A 2 A_Look
			SAR2 B 0 A_Wander
			SAR2 B 2 A_Look
			SAR2 B 0 A_Wander
			SAR2 B 2 A_Look
			SAR2 C 0 A_Wander
			SAR2 C 2 A_Look
			SAR2 C 0 A_Wander
			SAR2 C 2 A_Look
			SAR2 D 0 A_Wander
			SAR2 D 2 A_Look
			SAR2 D 0 A_Wander
			SAR2 D 2 A_Look
			
			Goto SearchPlayer
			
		See:
			TNT1 A 0 A_CheckSight("SeeNeverSeen")
		
		SeeContinue:
			TNT1 A 0
			
			TNT1 A 0 A_JumpIf(!user_sleeping, 3) // forgo the expensive sight check if already awake
			TNT1 A 0 A_CheckSight(2) // do not consider ourselves awake if none of the players can see us
			TNT1 A 0 A_SetUserVar("user_sleeping", 0)
			
			TNT1 A 0 A_JumpIfInventory("ComeEatMeDemon", 1, "EnragedSee")
			TNT1 A 0 A_CheckSight("SeeNoSee")
			//TNT1 A 0 A_SpawnItemEx("FootSep6", 0, 0, 30, 0, 0)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 17)
			SAR2 AA 2 A_Chase
			SAR2 BB 2 A_Chase
			//TNT1 A 0 A_SpawnItemEx("FootSep6", 0, 0, 30, 0, 0)
			SAR2 CC 2 A_Chase
			SAR2 DD 2 A_Chase
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "Idle")
			TNT1 A 0 A_JumpIfCloser(1000, "SeeContinue")
			TNT1 A 0 A_Jump(16, "Sprint")
			Loop
			
		SeeNoSee:
			//TNT1 A 0 A_SpawnItemEx("FootSep6", 0, 0, 30, 0, 0)
			SAR2 AA 2 A_Chase
			SAR2 BB 2 A_Chase
			SAR2 CC 2 A_Chase
			SAR2 DD 2 A_Chase
			TNT1 A 0 A_GiveInventory("EnemyMemory", 1)
			TNT1 A 0 A_JumpIfInventory("EnemyMemory", 15, "Forget")
			Goto See
			
		SeeNeverSeen:
			//TNT1 A 0 A_SpawnItemEx("FootSep6", 0, 0, 30, 0, 0)
			SAR2 AA 2 A_Chase("Melee", "")
			SAR2 BB 2 A_Chase
			SAR2 CC 2 A_Chase
			SAR2 DD 2 A_Chase
			Loop

		Pain.Taunt:	
			TNT1 A 0
			TNT1 A 0 HealThing(1)
			TNT1 A 0 A_JumpIfInventory("ComeEatMeDemon", 1, "EnragedSee")
			TNT1 A 0 A_PlaySound("demon/sight", CHAN_VOICE)
			SAR2 FGF 2 A_FaceTarget
			TNT1 A 0 A_GiveInventory("ComeEatMeDemon", 1)
			TNT1 A 0 A_ChangeFlag("QUICKTORETALIATE", 1)
			Goto EnragedSee
		Sprint: // 33% faster, a clone of EnragedSee
			SAR2 A 1 A_Chase("Melee", "")
			SAR2 A 2 A_Chase("Melee", "")
			SAR2 B 1 A_Chase("Melee", "")
			SAR2 B 2 A_Chase("Melee", "")
			SAR2 C 1 A_Chase("Melee", "")
			SAR2 C 2 A_Chase("Melee", "")
			SAR2 D 1 A_Chase("Melee", "")
			SAR2 D 2 A_Chase("Melee", "")
			TNT1 A 0 A_Jump(64, "See")
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "Idle")
			Loop			
			
		EnragedSee: // 25% faster
			TNT1 A 0 A_TakeInventory("EnemyMemory", 17)
			SAR2 A 1 A_Chase("Melee", "")
			SAR2 A 2 A_Chase("Melee", "")
			SAR2 B 1 A_Chase("Melee", "")
			SAR2 B 2 A_Chase("Melee", "")
			SAR2 C 1 A_Chase("Melee", "")
			SAR2 C 2 A_Chase("Melee", "")
			SAR2 D 1 A_Chase("Melee", "")
			SAR2 D 2 A_Chase("Melee", "")
			TNT1 A 0 A_FaceTarget
			TNT1 A 0 A_JumpIf(CallAcs("FBD_TargetIsInvisible"), "Idle")
			Loop
		
		Melee:
			TNT1 A 0
			TNT1 A 0 A_JumpIfInTargetInventory("GoFatality", 1, "WaitTargetsFatalityOut")
			TNT1 A 0 A_JumpIfCloser(70, "Bite")
			TNT1 A 0
			TNT1 A 0 A_PlaySound("demon/melee", CHAN_BODY)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 100)
			//TNT1 A 0 A_JumpIfInTargetInventory("ComeEatMeDemon", 1, "See")
			
			SAR2 G 5 A_FaceTarget
			SAR2 E 3 A_FaceTarget
			TNT1 A 0 ThrustThingZ(0,user_jump_power,0,1) // downscales in EDAY Mars maps!
			TNT1 A 0 A_Recoil(-10)
			SAR2 F 5 
			SAR2 GGG 4 A_CustomMissile("StoneskinPinkyAttack",40,0,0,2)
			TNT1 A 0 A_CustomMissile("StoneskinPinkyAttack",5,0,0,2)
			SAR2 G 6
			TNT1 A 0 A_JumpIfCloser(70, "Bite")
			Goto SeeContinue
			
		Bite:	
			SAR2 G 0 A_FaceTarget
			TNT1 A 0 A_PlaySound("demon/melee", CHAN_BODY)
			TNT1 A 0 A_Recoil(-15)
			TNT1 A 0 A_TakeInventory("EnemyMemory", 100)
			SAR2 E 6 A_FaceTarget
			SAR2 F 6 A_FaceTarget
			TNT1 A 0 A_CustomMissile("StoneskinPinkyAttack",40,0,0,2)
			SAR2 G 12 A_CustomMissile("StoneskinPinkyAttack",5,0,0,2)
			Goto SeeContinue
	}
}




			
ACTOR BasicEDAYParticleSFX
{
    Radius 0
    Height 0
    +NOTELEPORT
    +DONTSPLASH
	+MISSILE
	+FORCEXYBILLBOARD
    +CLIENTSIDEONLY
    +THRUACTORS
	-NOGRAVITY
}			
			
ACTOR StoneBloodParticle1: BasicEDAYParticleSFX
{
	+DOOMBOUNCE
	Gravity 0.8
	Scale 0.4
	BounceFactor 0.4
	Damage 0
	Speed 16
	Radius 2
	Height 2
	States
    {
		Spawn:
			FLRB KLMN 3
			Loop
		Death:
			FLRB K 1
			FLRB K -1
			Stop
    }
}

ACTOR StoneBloodParticle2: BasicEDAYParticleSFX
{
	+DOOMBOUNCE
	-NOGRAVITY
	+THRUACTORS
	Gravity 0.7
	Scale 0.2
	Damage 0
	+BOUNCEONACTORS
	Radius 2
	Height 2
	BounceFactor 0.4
	Speed 14
	States
    {
		Spawn:
			FLRB NMLK 3
			Loop
		Death:
			FLRB N 1
			FLRB N -1
			Stop
    }
}


ACTOR StoneBloodParticle3: StoneBloodParticle1
{

	Scale 0.4
	States
    {
		Spawn:
			FLRB ABCD 3
			Loop
		Death:
			FLRB E 1
			FLRB E -1
			Stop
    }
}



ACTOR StoneBloodParticle4: StoneBloodParticle1
{

	Scale 0.3
	-DOOMBOUNCE
	States
    {
		Spawn:
			FLRB FGHI 3
			Loop
		Death:
			FLRB J 1
			FLRB J -1
			Stop
    }
}

ACTOR StoneBloodSmoke: BasicEDAYParticleSFX
{
	-NOGRAVITY
	+DOOMBOUNCE
	BounceFactor 0.1
	Radius 1
	Height 1
	Alpha 0.4
	RenderStyle Translucent
	Scale 1.0
	Speed 2
	Gravity 0.1
    States
    {
		Spawn:
			TNT1 A 0 NODELAY A_SetScale(Random(0,1) ? 1.0 : -1.0, Random(0,1) ? 1.0 : -1.0)
			Goto Fly
		Fly:
			SMO3 Y 50
			SMO3 YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY 1 A_FadeOut(0.0125)
			Goto Death
		Death:
			SMO3 YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY 1 A_FadeOut(0.0125)
			Stop
    }
}

ACTOR StoneBlood
{
	-SHOOTABLE
	+THRUACTORS
	-ALLOWPARTICLES
	+NOBLOCKMAP
	+NOBLOODDECALS
	-BLOODSPLATTER
	+CLIENTSIDEONLY	
	states	{
		Spawn:
			TNT1 A 0
			TNT1 AA 0 A_CustomMissile ("StoneBloodParticle1", 0, 0, random (-60, 60), 2, random (-60,35))
			TNT1 AA 0 A_CustomMissile ("StoneBloodParticle2", 0, 0, random (-60, 60), 2, random (-60,35))
			TNT1 AA 0 A_CustomMissile ("StoneBloodParticle3", 0, 0, random (-60, 60), 2, random (-60,35))
			TNT1 AA 0 A_CustomMissile ("StoneBloodParticle4", 0, 0, random (-60, 60), 2, random (-60,35))			
			Stop
	}
}

ACTOR StoneBlood_Saw: StoneBlood
{
	states	{
		Spawn:
			TNT1 A 0
			TNT1 A 0 A_CustomMissile ("StoneBloodSmoke", 0, 0, random (0, 360), 2, random (10, 40))
			TNT1 A 0 A_CustomMissile ("StoneBloodParticle1", 0, 0, random (-60, 60), 2, random (-60,35))
			TNT1 A 0 A_CustomMissile ("StoneBloodParticle2", 0, 0, random (-60, 60), 2, random (-60,35))
			TNT1 A 0 A_CustomMissile ("StoneBloodParticle3", 0, 0, random (-60, 60), 2, random (-60,35))
			TNT1 A 0 A_CustomMissile ("StoneBloodParticle4", 0, 0, random (-60, 60), 2, random (-60,35))			
			Stop
	}
}

Actor StoneskinPinkyDeathSFX: BasicEDAYParticleSFX
{
	Speed 0
	+NOINTERACTION
	+NOCLIP
	States
	{
		Spawn:
			TNT1 A 1 
			TNT1 A 0 A_JumpIf(!CallAcs("FBD_RequestExpensiveSfx", 90), "Cheap") 
			TNT1 AAAA 0 A_CustomMissile ("StoneBloodParticle2", 0, 0, random (0, 360), 2, random (10, 40))
			TNT1 AAAA 0 A_CustomMissile ("StoneBloodParticle1", 0, 0, random (0, 360), 2, random (10, 40))
			TNT1 AAAA 0 A_CustomMissile ("StoneBloodParticle3", 0, 0, random (0, 360), 2, random (10, 40))
			TNT1 AAAA 0 A_CustomMissile ("StoneBloodParticle4", 0, 0, random (0, 360), 2, random (10, 40))
		Cheap:	
			TNT1 AAAAAA 0 A_CustomMissile ("StoneBloodSmoke", 0, 0, random (0, 360), 2, random (10, 40))
			TNT1 A 0 A_PlaySound("ROCKFAL2")
			TNT1 A 30
			Stop
	}
}

