new A_ChangeVelocity flag

Remember, just because you request it, that doesn't mean you'll get it.

Moderator: GZDoom Developers

Ultimate Freedoomer
Posts: 218
Joined: Fri Jan 30, 2015 10:32 pm
Location: Pittman Center
Contact:

new A_ChangeVelocity flag

Post by Ultimate Freedoomer »

Hi. I've noticed that CVF_RELATIVE only affects X & Y axes. Because of this, I've come up with a new flag for it: "CVF_VIEWPITCHZ". Basically, this would make the z axis of the calling actor's velocity be relative to the spawning actor's current view angle. Example: This is a custom Strife Grenade Launcher that replicates the vanilla version's functionality (outside of the whole "fire-mode toggle is an alt-fire rather than a sister weapon" thing & using a planned-but-cut feature from the vanilla version of this weapon) using non-restricted functions. A_FireGrenade's upward projectile angle system & peculiar projectile z-velocity system is replicated using an A_ChangeVelocity call in the projectile's spawn state. A_FireGrenade's "trigonometry from the player's current viewpitch"-based pitch determination system is replicated in the grenade actor via the CVF_VIEWPITCHZ flag:

Code: Select all

ACTOR InvFlag : Inventory
{
	+UNDROPPABLE
	+INVENTORY.PERSISTENTPOWER
	Inventory.Amount 1
	Inventory.MaxAmount 1
	Inventory.InterHubAmount 1
	States
	{
	Spawn:
		TNT1 A 1
		Fail
	}
}

ACTOR GrenadePhosMode : InvFlag
{
}

ACTOR GrenadeGasMode : InvFlag
{
}

ACTOR SimpleStrifeGrenadeLauncher : StrifeWeapon replaces StrifeGrenadeLauncher
{
	+NOALERT
	+WEAPON.AMMO_CHECKBOTH
	+FLOORCLIP
	+NoAutoAim
	Weapon.SelectionOrder 2400
	ConversationID 195, 189, 193
	Weapon.SisterWeapon "StrifeGasGrenadeLauncher"
	Weapon.AmmoType1 "HEGrenadeRounds"
	Weapon.AmmoUse1 1
	Weapon.AmmoGive1 12
	Weapon.AmmoType2 "PhosphorusGrenadeRounds"
	Weapon.AmmoUse2 1
	Weapon.AmmoGive2 0
	Inventory.Icon "GRNDA0"
	Tag "$TAG_GLAUNCHER1" // "Grenade Launcher"
	Inventory.PickupMessage "$TXT_GLAUNCHER" // "You picked up the Grenade launcher."
	States
	{
	Select:
		TNT1 A 0 A_JumpIfInventory("GrenadePhosMode",1,"SelectPhos")
		TNT1 A 0 A_JumpIfInventory("GrenadeGasMode",1,"SelectGas")
	SelectHiEx:
		GREN A 1 A_Raise
		Loop
	SelectPhos:
		GREN D 1 A_Raise
		Loop
	SelectGas:
		GREN G 1 A_Raise
		Loop
	Deselect:
		TNT1 A 0 A_JumpIfInventory("GrenadePhosMode",1,"DeselectPhos")
		TNT1 A 0 A_JumpIfInventory("GrenadeGasMode",1,"DeSelectGas")
	DeselectHiEx:
		GREN A 1 A_Lower
		Loop
	DeselectPhos:
		GREN D 1 A_Lower
		Loop
	DeSelectGas:
		GREN G 1 A_Lower
		Loop
	Ready:
		TNT1 A 0 A_JumpIfInventory("GrenadePhosMode",1,"ReadyPhos")
		TNT1 A 0 A_JumpIfInventory("GrenadeGasMode",1,"ReadyGas")
	ReadyHiEx:
		GREN A 1 A_WeaponReady(WRF_ALLOWRELOAD)
		Loop
	ReadyPhos:
		GREN D 1 A_WeaponReady(WRF_ALLOWRELOAD)
		Loop
	ReadyGas:
		GREN G 1 A_WeaponReady(WRF_ALLOWRELOAD)
		Loop
	Fire:
		TNT1 A 0 A_JumpIfInventory("GrenadePhosMode",1,"FirePhos")
		TNT1 A 0 A_JumpIfInventory("GrenadeGasMode",1,"FireGas")
	FireHiEx:
		TNT1 A 0 A_JumpIfInventory("HEGrenadeRounds",2,2)
		Goto Click
		TNT1 A 0 A_AlertMonsters
		GREN A 5
		{
		A_GunFlash("FlashHiExR");
		A_FireProjectile("CustomHEGrenade",-4,0,0,0,0,0);
		A_TakeInventory("HEGrenadeRounds",1,TIF_NOTAKEINFINITE,AAPTR_DEFAULT);
		}
		GREN B 10
		GREN A 5
		{
		A_GunFlash("FlashHiExL");
		A_FireProjectile("CustomHEGrenade",4,0,0,0,0,0);
		A_TakeInventory("HEGrenadeRounds",1,TIF_NOTAKEINFINITE,AAPTR_DEFAULT);
		}
		GREN C 10
		TNT1 A 0 A_ReFire("FireHiEx")
		Goto Ready
	FirePhos:
		TNT1 A 0 A_JumpIfInventory("PhosphorusGrenadeRounds",2,2)
		Goto Click
		TNT1 A 0 A_AlertMonsters
		GREN D 5
		{
		A_GunFlash("FlashPhosR");
		A_FireProjectile("CustomPhosphorusGrenade",4,0,0,0,0,0);
		A_TakeInventory("PhosphorusGrenadeRounds",1,TIF_NOTAKEINFINITE,AAPTR_DEFAULT);
		}
		GREN E 10
		GREN D 5
		{
		A_GunFlash("FlashPhosL");
		A_FireProjectile("CustomPhosphorusGrenade",-4,0,0,0,0,0);
		A_TakeInventory("PhosphorusGrenadeRounds",1,TIF_NOTAKEINFINITE,AAPTR_DEFAULT);
		}
		GREN F 10
		TNT1 A 0 A_ReFire("FirePhos")
		Goto Ready
	FireGas:
		TNT1 A 0 A_JumpIfInventory("GasGrenadeRounds",2,2)
		Goto Click
		TNT1 A 0 A_AlertMonsters
		GREN G 5
		{
		A_GunFlash("FlashGasR");
		A_FireProjectile("GasGrenade",4,0,0,0,0,0);
		A_TakeInventory("GasGrenadeRounds",1,TIF_NOTAKEINFINITE,AAPTR_DEFAULT);
		}
		GREN H 10
		GREN G 5
		{
		A_GunFlash("FlashGasL");
		A_FireProjectile("GasGrenade",-4,0,0,0,0,0);
		A_TakeInventory("GasGrenadeRounds",1,TIF_NOTAKEINFINITE,AAPTR_DEFAULT);
		}
		GREN I 10
		TNT1 A 0 A_ReFire("FireGas")
		Goto Ready
	Altfire:
		TNT1 A 0 A_PlaySound("switches/normbutn",CHAN_WEAPON)
		TNT1 A 0 A_JumpIfInventory("GrenadePhosMode",1,"SwitchToGas")
		TNT1 A 0 A_JumpIfInventory("GrenadeGasMode",1,"SwitchToHiEx")
		SwitchToPhos:
		TNT1 A 0 A_GiveInventory("GrenadePhosMode",1)
		TNT1 A 0 A_Print("Grenade Type:\nPhosphor")
		SwitchToPhos_Hold:
		GREN D 1 A_WeaponReady(WRF_NOSECONDARY|WRF_NOSWITCH)
		TNT1 A 0 A_Refire("SwitchToPhos_Hold")
		Goto Ready
	SwitchToGas:
		TNT1 A 0 A_TakeInventory("GrenadePhosMode",1)
		TNT1 A 0 A_GiveInventory("GrenadeGasMode",1)
		TNT1 A 0 A_Print("Grenade Type:\nGas")
		SwitchToGas_Hold:
		GREN G 1 A_WeaponReady(WRF_NOSECONDARY|WRF_NOSWITCH)
		TNT1 A 0 A_Refire("SwitchToGas_Hold")
		Goto Ready
	SwitchToHiEx:
		TNT1 A 0 A_TakeInventory("GrenadeGasMode",1)
		TNT1 A 0 A_Print("Grenade Type:\nHi-Explosive")
	SwitchToHiEx_Hold:
		GREN A 1 A_WeaponReady(WRF_NOSECONDARY|WRF_NOSWITCH)
		TNT1 A 0 A_Refire("SwitchToHiEx_Hold")
		Goto Ready
	FlashHiExR:
		GREF A 5 Bright A_Light(1)
		Goto LightDone
	FlashHiExL:
		GREF B 5 Bright A_Light(2)
		Goto LightDone
	FlashPhosR:
		GREF C 5 Bright A_Light(1)
		Goto LightDone
	FlashPhosL:
		GREF D 5 Bright A_Light(2)
		Goto LightDone
	FlashGasR:
		GREF E 5 Bright A_Light(1)
		Goto LightDone
	FlashGasL:
		GREF F 5 Bright A_Light(2)
		Goto LightDone
	Click:
		TNT1 A 0
		Goto Ready
	Spawn:
		GRND A -1
		Stop
	}
}

ACTOR StrifeGasGrenadeLauncher : SimpleStrifeGrenadeLauncher
{
	-WEAPON.AMMO_OPTIONAL
	Weapon.SisterWeapon "SimpleStrifeGrenadeLauncher"
	Weapon.AmmoType "GasGrenadeRounds"
	Weapon.AmmoUse 1
	Weapon.AmmoGive 0
}

ACTOR CustomHEGrenade replaces HEGrenade
{
	Speed 15
	Radius 13
	Height 13
	Mass 20
	Damage 1
	ReactionTime 30
	Projectile
	-NOGRAVITY
	+STRIFEDAMAGE
	+BOUNCEONACTORS
	+EXPLODEONWATER
	MaxStepHeight 4
	BounceType "Doom"
	BounceFactor 0.5
	BounceCount 2
	SeeSound "weapons/hegrenadeshoot"
	DeathSound "weapons/hegrenadebang"
	Obituary "$OB_MPSTRIFEGRENADE" // "%o was inverted by %k's H-E grenade."
	States
	{
	Spawn:
		TNT1 A 0 A_ChangeVelocity(0,0,(-clamp(tan(Pitch), -5, 5)) * Speed + 8, CVF_VIEWPITCHZ|CVF_REPLACE)
		SpawnLoop:
		GRAP AB 3 A_Countdown
		Loop
	Death:
		BNG4 A 0 Bright A_NoGravity
		BNG4 A 0 Bright A_SetRenderStyle(1, STYLE_Normal)
		BNG4 A 2 Bright A_Explode(192, 192, 0|XF_HURTSOURCE, 1)
		BNG4 BCDEFGHIJKLMN 3 Bright
		Stop
	}
}

ACTOR CustomPhosphorousGrenade replaces PhosphorousGrenade
{
	Speed 15
	Radius 13
	Height 13
	Mass 20
	Damage 1
	ReactionTime 40
	Projectile
	-NOGRAVITY
	+STRIFEDAMAGE
	+BOUNCEONACTORS
	+EXPLODEONWATER
	BounceType "Doom"
	MaxStepHeight 4
	BounceFactor 0.5
	BounceCount 2
	SeeSound "weapons/phgrenadeshoot"
	DeathSound "weapons/phgrenadebang"
	Obituary "$OB_MPPHOSPHOROUSGRENADE" // "%o took a flame bath in %k's phosphorous pyre."
	States
	{
	Spawn:
		TNT1 A 0 A_ChangeVelocity(0,0,(-clamp(tan(Pitch), -5, 5)) * Speed + 8, CVF_VIEWPITCHZ|CVF_REPLACE)
		SpawnLoop:
		GRIN AB 3 A_Countdown
		Loop
	Death:
		BNG3 A 2 A_SpawnItemEx("PhosphorousFire")
		Stop
	}
}

ACTOR GasGrenade
{
	Speed 20
	Radius 13
	Height 13
	Mass 50
	Damage 1
	ReactionTime 30
	Projectile
	-NOGRAVITY
	+STRIFEDAMAGE
	+BOUNCEONACTORS
	-EXPLODEONWATER
	MaxStepHeight 4
	BounceType "Doom"
	BounceFactor 0.5
	BounceCount 2
	SeeSound "weapons/hegrenadeshoot"
	DeathSound "world/glassbreak"
	Obituary "$OB_MPSTRIFEGRENADE" // "%o was inverted by %k's H-E grenade."
	States
	{
	Spawn:
		TNT1 A 0 A_ChangeVelocity(0,0,(-clamp(tan(Pitch), -5, 5)) * Speed + 8, CVF_VIEWPITCHZ|CVF_REPLACE)
		SpawnLoop:
		GASG BC 3 A_Countdown
		Loop
	Death:
		TNT1 AAA 0 A_SpawnDebris("GlassJunk")
		BALL ABCDE 3
		TNT1 A 0 A_SpawnitemEx("AcidCloud",random(-25,25),random(-25,25))
		TNT1 A 0 A_SpawnitemEx("AcidCloud",random(-25,25),random(-25,25))
		TNT1 A 0 A_SpawnitemEx("AcidCloud",random(-25,25),random(-25,25))
		Stop
	}
}

ACTOR AcidCloud
{
	-NOGRAVITY
	+FLOORHUGGER
	ReactionTime 50
	DamageType PoisonCloud
	+NOBLOCKMAP
	+FLOORCLIP
	+NOTELEPORT
	+NODAMAGETHRUST
	+DONTSPLASH
	+FOILINVUL
	+CANBLAST
	+BLOODLESSIMPACT
	+BLOCKEDBYSOLIDACTORS
	RenderStyle Add
	Alpha 0.6
	Obituary "$OB_MPPHOSPHOROUSGRENADE" // "%o took a flame bath in %k's phosphorous pyre."
	States
	{
	Spawn:
		GASC A 5
		GASC B 5
		GASC C 5
		GASC D 5
		TNT1 A 0 A_SetSolid
		CloudLoop:
		GASC EFGH 5
		{
		A_Explode(4,40);
		A_SetFloatBobPhase(-1);
		}
		TNT1 A 0 A_Countdown
		Loop
	Death:
		TNT1 A 0 A_UnsetSolid
		Gasc DCBA 5 Bright
		Stop
	}
}
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: new A_ChangeVelocity flag

Post by Matt »

A_ChangeVelocity(cos(pitch),0,-sin(pitch),CVF_RELATIVE)

I know it would be faster if it were native but trying to remember the specific formatting (is the z value ignored? added? what if it's not CVF_RELATIVE?) would be more mentally taxing for the modder than this seems to be for the computer...
Ultimate Freedoomer
Posts: 218
Joined: Fri Jan 30, 2015 10:32 pm
Location: Pittman Center
Contact:

Re: new A_ChangeVelocity flag

Post by Ultimate Freedoomer »

Matt wrote:A_ChangeVelocity(cos(pitch),0,-sin(pitch),CVF_RELATIVE)

I know it would be faster if it were native but trying to remember the specific formatting (is the z value ignored? added? what if it's not CVF_RELATIVE?) would be more mentally taxing for the modder than this seems to be for the computer...
I just thought of something: why doesn't CVF_RELATIVE affect the z axis, anyway? To take into account the issue of using CVF_VIEWPITCHZ without CVF_RELATIVE, I suggest a second new flag for this function: CVF_RELATIVEALL. Basically, this would combine CVF_VIEWPITCHZ & CVF_RELATIVE into 1 flag, so modders can decide which of the 3 to use based on which axis velocity they want to make relative (or which they modified), so if the z value is unaffected in the a_changevelocity call, the modder can just use CVF_RELATIVE; if the z value was changed but the X value &/or the Y value are unaffected, the modder can just use CVF_VIEWPITCHZ; while if both the z value & the x value &/or the y value were changed, the modder can just use CVF_RELATIVEALL.
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: new A_ChangeVelocity flag

Post by Matt »

I can see the following possiblities:

Given:
Actor pitch -10 (10 degrees upwards)
Current velocity (0,0,5)
A_ChangeVelocity(12,0,30,CVF_RELATIVEALL)


The 30 could be interpreted as either:

1. Stacks absolutely with the forward movement indicated by X, so the final is 5-sin(-10)*12+30

2. Made relative to the pitch, giving us 5-sin(-10)*12+cos(-10)*30 (or whatever the right answer is, I don't trust myself to math right now) while forward horizontal movement is also added - basically like a rocket firing off at an angle

Either way it should clearly be one or the other (and my own preference would be 2 since that's the one that's a buttload harder to do "by hand").
Post Reply

Return to “Feature Suggestions [GZDoom]”