Skip to content

Commit

Permalink
Code optimizations and cleanups, and overhauled marine commands.
Browse files Browse the repository at this point in the history
- Bumped minimum ZScript version from 4.7.0 to 4.8.0.
- Overhauled the friendly marine commands, now that my DONTFOLLOWPLAYERS flag is in GZDoom. The marines' commands are now finally split between a wandering command that actually makes them wander around without following the player, and a following command that makes them follow the player that triggered it (If the player is friendly). The stand still command now also makes marines go back to standing still instead of idling. The document file has more info on how the commands work
- Now that my SEEFRIENDLYMONSTERS flag has been added to GZDoom itself. RaveYard's player ally seeing code has been removed, simplifying the code and making it up to 80% faster, due to the reduced overhead of doing this functionality natively instead of through ZScript.
- The marines' NPC seeing range has been reduced from 8196 map units to 6144, and their player hearing range extended from 3072 to 4096. The player seeing range is still 8192 map units.
- Replaced the stupid If switch in the See state with just a single A_Chase call with CHF_DONTIDLE.
- Changed the target switching behavior of marines on turrets, this will hopefully stop them from not reacting to enemies.
- Removed YandereDev code from GrenadeAttackDecision() and SM_TurretUseDecision().
- Replaced all Distance3D calls with Distance3DSquared, this will hopefully provide performance improvements when doing distance checks, especially on the two aforementioned functions above.
- Updated credits and document.
  • Loading branch information
inkoalawetrust committed Jun 8, 2022
1 parent a025301 commit 4d4c2a9
Show file tree
Hide file tree
Showing 55 changed files with 238 additions and 315 deletions.
13 changes: 12 additions & 1 deletion Document.txt
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@ MISCELLANEOUS:
- When crouched, they use a different pain state, and will also play a crouched death animation if killed while in cover.
- Marines behind cover are a bit more accurate with their shooting, and when they are crouched down they will take 20% less damage, and get pushed back by damage less easily.

================|MARINE COMMANDS|================
Friendly marines can be commanded to do different things.
You can press use on them to cycle them through the following orders:

Wander: The marine will randomly wander around without following the player, and sometimes stay in place to look around.
Follow: The marine will follow the player that pressed use on him (If the player is friendly). Marines following a player are faster than when wandering, and will not stay in place.
Stand Still: The marine will stay in place, like when first spawned. After they finish searching for enemies, they go back to standing still instead of wandering.
Exit Turret: Only applicable for marines on turrets, makes the marine exit the turret.

Pressing use on a hostile marine will cause him to alert other nearby hostile marines.

================|USER VARIABLES|================
User variables allow an actor to be configured by the mapper through the editor on a per-actor basis, without requiring to modify the source code of the actor in any way.
If you don't know how to use and/or change the user variables of an actor, then click on this Imgur album to see how: https://imgur.com/a/IF9Ezo2
Expand All @@ -151,7 +162,7 @@ User_SearchTime: The amount of time the marine will try to look for his target b
- Default is 300. -1 makes the marine never give up persuit while the target is alive. And immediately go back to wandering once the target is dead.
User_GrenadeThreshold: How likely the marine is to throw a grenade, the lower the number, the more likely he is to throw one.
- Default is 240. -1 makes them always throw grenades, unless they would be caught in the blast. And 256 makes them never throw grenades.
User_DisobeyCommands: Friendly marines will not wander, stay in place, or leave turrets when the player presses use on them.
User_DisobeyCommands: Friendly marines will not wander, follow, stay in place, or leave turrets when the player presses use on them.
User_NoReload: Marines do not need to ever reload their gun.
User_NoCover: Marines do not take cover when attacking.
User_NoRifleDrop: Marines will never drop their rifles when killed.
Expand Down
286 changes: 82 additions & 204 deletions MarineFunctions.zsc

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Marine_Deaths.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Extend Class SmartMarine
Super.OnDestroy();
}

//The code related to the marine making the player die.
Override String GetObituary (Actor Victim, Actor Inflictor, Name MOD, Bool PlayerAttack)
{
If (MOD == "MarineHMG")
Expand Down
1 change: 0 additions & 1 deletion Marine_OtherActors.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ Class SmartMarineTurretMessage : SmartMarineStandingMessage
}
}

//This will be used in a future update, when GZDoom 4.8.0 comes out.
Class SmartMarineFollowingMessage : SmartMarineStandingMessage
{
States
Expand Down
62 changes: 35 additions & 27 deletions Marine_Turret.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ Extend Class SmartMarine
{
TurretSee:
MTUR BBBBBBBBBBBBBBBBBBBBBBBB 1 //The duration is so low so that the marine switches targets as fast as possible.
{
if(!bFriendly)
{
SM_UpdateTarget();
}

{
If (JustGotOnTurret)
{
JustGotOnTurret = False;
Expand Down Expand Up @@ -45,12 +40,25 @@ Extend Class SmartMarine

If (Target && Target.Health <= 0) Target = Null; //Remove dead targets.

If (Target) A_Chase (Null,"TurretFire",CHF_DONTMOVE|CHF_NODIRECTIONTURN);
Else SM_LookForTarget();
//If the target is in your line of sight, attack it normally, if not, go back to looking.
If (CheckIfTargetInLOS(160,JLOSF_CLOSENOFOV|JLOSF_DEADNOJUMP,6144,128)) A_Chase (Null,"TurretFire",CHF_DONTMOVE|CHF_NODIRECTIONTURN);
Else A_LookEx (0,0,8192,4096,160,"TurretFire");

Return State (Null);
}
MTUR B 0
{
//If you somehow have no turret pointer, meaning you aren't on a turret or that something is broken, then leave the turret.
If (!Turret)
{
LeaveTurret();
Return ResolveState ("Idle");
}
If (Random (0,256) > 230)
Angle = Turret.Angle + RandomPick(10,45,90,-10,-45,-90);

Return State (Null);
}
MTUR B 0 {If (Random (0,256) > 230) {Angle += RandomPick(45,90,-45,-90);}}
Loop;
TurretFire:
TNT1 A 0 A_JumpIf (SM_FindNearbyGrenade(),"LeaveAndRun");
Expand Down Expand Up @@ -87,7 +95,7 @@ Class TurretMarine : Actor
YScale 0.98;
Mass 100;
FastSpeed 14;
FriendlySeeBlocks 20;
FriendlySeeBlocks 48;
MaxTargetRange 8192;
MinMissileChance 100;
Tag "Marine NPC";
Expand All @@ -109,28 +117,30 @@ Class TurretMarine : Actor
+DontThrust;
+NoPain;
+AvoidHazards; //This ONLY works for crushing ceilings and NOTHING ELSE. So it's largely useless but I'm still adding it.
+SeeFriendlyMonsters;
}

Override Void Tick()
{
Super.Tick();

If (IsFrozen() || Health <= 0) {Return;} //Don't run the below code if frozen in time or dead.
//Don't run the below code if frozen in time or dead.
If (IsFrozen() || Health <= 0)
Return;

If (!bFriendly)
{
Species = "HostileSmartMarine";
}
Else
{
Species = "SmartMarine";
}
}

Override Void OnDestroy ()
{
Super.OnDestroy();
If (bKilled) Return;
//If you were killed before being removed, don't spawn a turret.
If (bKilled)
Return;

Actor Turret = Spawn ("SmartMarineMGTurret",Pos);
If (Turret) {Turret.Angle = Angle; Turret.Pitch = Pitch;}
}
Expand All @@ -151,6 +161,7 @@ Class TurretMarine : Actor

Override Void PostBeginPlay()
{
SpawnAngle = Angle;
If (!User_Color || User_Color ~== "") {Return;} //Don't run the code if User_Color is empty.

//Handles the random color choice that is performed if the color name given is "Random".
Expand All @@ -169,6 +180,7 @@ Class TurretMarine : Actor
Bool User_DisobeyCommands;
Bool User_NoRifleDrop;
String User_Color;
Double SpawnAngle;
States
{
Spawn:
Expand All @@ -179,19 +191,14 @@ Class TurretMarine : Actor
Return ResolveState ("LeaveTurret");
}

STM_LookForTarget();
A_LookEx (0,0,8192,4096,160,"AlertOtherMarines");
Return State (Null);
}
MTUR B 0 {If (Random (0,256) > 235) {Angle += RandomPick(45,90,-45,-90);}}
Loop;
See:
MTUR BBBBBBBBBBBBBBBBBBBBBBBB 1
{
if(!bFriendly)
{
STM_UpdateTarget();
}

//Have the marine run away from grenades about to explode.
If (STM_FindNearbyGrenade())
{
Expand All @@ -200,12 +207,13 @@ Class TurretMarine : Actor

If (Target && Target.Health <= 0) Target = Null; //Remove dead targets.

If (Target) A_Chase (Null,"TurretFire",CHF_DONTMOVE|CHF_NODIRECTIONTURN);
Else STM_LookForTarget();
//If the target is in your line of sight, attack it normally, if not, go back to looking for another.
If (CheckIfTargetInLOS(360,JLOSF_CLOSENOFOV|JLOSF_DEADNOJUMP,6144,128)) A_Chase (Null,"TurretFire",CHF_DONTMOVE|CHF_NODIRECTIONTURN);
Else A_LookEx (LOF_NOJUMP,0,8192,4096,160);

Return State (Null);
}
MTUR B 0 {If (Random (0,256) > 230) {Angle += RandomPick(45,90,-45,-90);}}
MTUR B 0 {If (Random (0,256) > 230) Angle = SpawnAngle + RandomPick(10,45,90,-10,-45,-90);}
Loop;
TurretFire:
TNT1 A 0 A_JumpIf (STM_FindNearbyGrenade(),"LeaveTurret");
Expand Down Expand Up @@ -306,7 +314,7 @@ Class SmartMarineMGTurret : Actor
//$Sprite MTURA1
Height 56;
ProjectilePassHeight 1; //Projectiles ignore the turret.
+INTERPOLATEANGLES;
+InterpolateAngles;
+Solid;
-Shootable;
}
Expand Down Expand Up @@ -335,7 +343,7 @@ Class SmartMarineMGTurret : Actor

// Remove gun
Let Gun = SmartMarineMGWeapon(Operator.FindInventory("SmartMarineMGWeapon"));
If(Gun) Gun.Disable();
If (Gun) Gun.Disable();

// Remove operator.
Operator = Null;
Expand Down
38 changes: 12 additions & 26 deletions Marine_UserVariables.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,18 @@ Extend Class SmartMarine
{
Super.PostBeginPlay();

If (User_RandomPersonality)
{
If (!User_SearchTime) User_SearchTime = 300*FRandom (-0.6,3.0);
If (!User_GrenadeThreshold) User_GrenadeThreshold = 240*FRandom (-0.25,2.0);
If (!User_RetreatAttempts) User_RetreatAttempts = Random (7,15);
If (!User_FearDistance) User_FearDistance = 2048*FRandom (0.75,2.0);
If (!User_TurretThreshold) User_TurretThreshold = 100*Frandom (0.5,1.5);
If (User_AlertRange == 0) User_AlertRange = 384;
If (User_EnemyAlertHearingRange == 0) User_EnemyAlertHearingRange = 1024;
If (User_DodgeRange == 0) User_DodgeRange = 384;
If (!User_MeleeChance) User_MeleeChance = 96*FRandom (0.5,2.5);
If (!User_Color || User_Color ~== "") User_Color = "Random";
User_RandomPersonality = False;
}
Else
{
If (User_SearchTime == 0) User_SearchTime = 300; //The amount of time the marine tries to chase it's target, after it has died or gone out of sight.
If (User_GrenadeThreshold == 0) User_GrenadeThreshold = 240; //Default threshold that needs to be reached or surpassed, for the marine to throw a grenade.
If (User_RetreatAttempts == 0) User_RetreatAttempts = 10; //Default amount of attempts the marine makes to run for cover to reload.
If (User_AlertRange == 0) User_AlertRange = 384; //Default range in which marines alert each other of enemies.
If (User_EnemyAlertHearingRange == 0) User_EnemyAlertHearingRange = 1024; //Default range in which marines can hear the alerts of enemy marines.
If (User_DodgeRange == 0) User_DodgeRange = 384; //Default range in which marines dodge projectiles.
If (User_MeleeChance == 0) User_MeleeChance = 96; //Default chance for the marine to try running away after hitting something with his rifles' stock.
If (User_TurretThreshold == 0) User_TurretThreshold = 100; //Default chance for the marine to use a turret.
If (User_FearDistance == 0) User_FearDistance = 2048; //The default distance the marines keeps from powerful enemies.
}
//The //$UserDefaultValue editor key is buggy, so this code still needs to be used.
If (User_SearchTime == 0) User_SearchTime = 300; //The amount of time the marine tries to chase it's target, after it has died or gone out of sight.
If (User_GrenadeThreshold == 0) User_GrenadeThreshold = 240; //Default threshold that needs to be reached or surpassed, for the marine to throw a grenade.
If (User_RetreatAttempts == 0) User_RetreatAttempts = 10; //Default amount of attempts the marine makes to run for cover to reload.
If (User_AlertRange == 0) User_AlertRange = 384; //Default range in which marines alert each other of enemies.
If (User_EnemyAlertHearingRange == 0) User_EnemyAlertHearingRange = 1024; //Default range in which marines can hear the alerts of enemy marines.
If (User_DodgeRange == 0) User_DodgeRange = 384; //Default range in which marines dodge projectiles.
If (User_MeleeChance == 0) User_MeleeChance = 96; //Default chance for the marine to try running away after hitting something with his rifles' stock.
If (User_TurretThreshold == 0) User_TurretThreshold = 100; //Default chance for the marine to use a turret.
If (User_FearDistance == 0) User_FearDistance = 2048; //The default distance the marines keeps from powerful enemies.

HandleRandomPersonalityMidGame();
HandleMarineColoring();
}

Expand Down Expand Up @@ -82,4 +67,5 @@ Extend Class SmartMarine
Bool User_RandomPersonality;
Bool User_NoRifleDrop;
String User_Color;

}
7 changes: 7 additions & 0 deletions SNDINFO
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Marine/Reload "Sounds/RifleReload.ogg"
Marine/Melee "Sounds/RifleHit.ogg"
Marine/PowerMelee "Sounds/RifleHitHard.ogg"
Marine/MeleeMiss "Sounds/RifleSwoosh.ogg"
Marine/Missile/Launch "Sounds/MissileShot.ogg"
Marine/Missile/Travel "Sounds/MissileMove.ogg"
Marine/Missile/Explode "Sounds/MissileBoom.ogg"

$Random Marine/Death
{
Expand Down Expand Up @@ -62,6 +65,10 @@ $Limit Marine/Melee 0
$Limit Marine/PowerMelee 0
$Limit Marine/MeleeMiss 0

$Limit Marine/Missile/Launch 0
$Limit Marine/Missile/Travel 0
$Limit Marine/Missile/Explode 0

$Limit VRifle/EmptyGun 0
$Limit VRifle/Zoomed 0
$Limit VRifle/Impact 2 512
Expand Down
Binary file added Sounds/MissileBoom.ogg
Binary file not shown.
Binary file added Sounds/MissileMove.ogg
Binary file not shown.
Binary file added Sounds/MissileShot.ogg
Binary file not shown.
Binary file added Sprites/Missile/Ground Blast/HBA3A0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/Ground Blast/HBA3B0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/Ground Blast/HBA3C0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/Ground Blast/HBA3D0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/Ground Blast/HBA3E0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/Ground Blast/HBA3F0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/Ground Blast/HBA3G0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/Ground Blast/HBA3H0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/Ground Blast/HBA3I0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/Ground Blast/HBA3J0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTA1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTA2A8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTA3A7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTA4A6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTA5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTB1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTB2B8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTB3B7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTB4B6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTB5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTC1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTC2C8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTC3C7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTC4C6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTC5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Sprites/Missile/MRCTD1.png
Binary file added Sprites/Missile/MRCTD2D8.png
Binary file added Sprites/Missile/MRCTD3D7.png
Binary file added Sprites/Missile/MRCTD4D6.png
Binary file added Sprites/Missile/MRCTD5.png
Binary file added Sprites/Missile/MRCTE1.png
Binary file added Sprites/Missile/MRCTE2E8.png
Binary file added Sprites/Missile/MRCTE3E7.png
Binary file added Sprites/Missile/MRCTE4E6.png
Binary file added Sprites/Missile/MRCTE5.png
Binary file added Sprites/Missile/MRCTF1.png
Binary file added Sprites/Missile/MRCTF2F8.png
Binary file added Sprites/Missile/MRCTF3F7.png
Binary file added Sprites/Missile/MRCTF4F6.png
Binary file added Sprites/Missile/MRCTF5.png
Binary file added Sprites/Missile/MRCTG1.png
Binary file added Sprites/Missile/MRCTH1.png
Binary file added Sprites/Missile/MRCTI1.png
Loading

0 comments on commit 4d4c2a9

Please sign in to comment.