Skip to content

Commit

Permalink
New tokens, user_defaultorder type and code improvements.
Browse files Browse the repository at this point in the history
- Added the SM_IAmTheDanger inventory token, which can be given to actors used by other mods to make marines automatically fear them regardless of their health or size.
- Added the SM_DontWarnOthers inventory token, which can be given to actors used by other mods to make marines not alert each other if the target has this token. This was actually added as an attempt at fixing a bug, but I decided to keep it.
- Added MeleeState and MissileState values to the marines, to allow internal code to know that they DO have melee and ranged attacks.
- Updated the visual scale of the machine gun bullets to negate aspect ratio correction.
- Added a Stay order type for User_DefaultOrder.
- Updated some checks to not misidentify voodoo dolls as actual players.
- Moved the armor equipping from PostBeginPlay() to BeginPlay(), to allow for the marines to be harmed immediately after spawning with the armor absorbing the damage.
- Bumped the marines' alert range for other marines from 384 to 512.
  • Loading branch information
inkoalawetrust committed Dec 12, 2022
1 parent c5d5f18 commit 502f9f1
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Document.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ User_NoRifleDrop: Marines will never drop their rifles when killed.
User_RetreatAttempts: The amount of times the marine tries to run out of sight of his target, when he needs to reload.
- Default is 10. -1 makes the marine reload in the open, without trying to get behind cover at all.
User_AlertRange: The distance around which a marine will alert other marines on his side of a target.
- Default is 384 map units. -1 disables alerting entirely for this marine, but still allows them to hear the alerts of other marines.
- Default is 512 map units. -1 disables alerting entirely for this marine, but still allows them to hear the alerts of other marines.
User_Leader: If the marine also has a squad name specified, this tells the game that this marine should be the leader of that squad. Otherwise, it does nothing.
User_SquadName: The name of the squad the marine is in, if the squad has a leader, the marine will follow him around.
User_DodgeRange: The maximum range in which marines react to incoming projectiles.
Expand All @@ -223,7 +223,7 @@ User_Color: Can be used to give the marines different armor colors.
- Default is no translation, the available colors are Default, Gray, Red, White, Black, Blue, Yellow, Orange, Pink, Dark Green, Dark Red, and Random, which randomly picks any of the afformentioned colors.
User_DefaultOrder: Specifies if the marine should follow the player or wander around by default.
- By default, the marine looks for any friendly players in its' line of sight, if there are none, he will wonder by default, if there is one, he will follow them by default.
- The other two options are "follow" and "wander", which are fairly self explanatory.
- The other three options are "follow", "wander", and "stay", which are fairly self explanatory.
User_RandomPersonality: When on, it randomizes several user variables that could be considered aspects of the marines' personality, such as:
- User_SearchTime, User_GrenadeThreshold, User_TurretThreshold, User_RetreatAttempts, User_FearDistance, and User_Color.
- If any of those variables have any values besides their defaults, then they won't be randomized, so you can still for example have marines with random grenade and turret thresholds, but the same melee chance.
Expand Down
15 changes: 10 additions & 5 deletions MarineFunctions.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Mixin Class MarineFunctions
Mobj = FindTargets.Thing;

//If the found actor is a monster or player, is not your current target, is at or closer than the specified blast radius, has health over 10, and is hostile and visible to you.
If ((Mobj.bIsMonster || Mobj Is "PlayerPawn") && Mobj != Target && Mobj.Distance3DSquared (Target) <= BlastRadius*BlastRadius && Mobj.Health >= 10 && IsHostile (Mobj) && IsVisible (Mobj,False))
If ((Mobj.bIsMonster || Mobj.Player) && Mobj != Target && Mobj.Distance3DSquared (Target) <= BlastRadius*BlastRadius && Mobj.Health >= 10 && IsHostile (Mobj) && IsVisible (Mobj,False))
{
ThrowChance += 5; //Increment the chance variable.

Expand Down Expand Up @@ -449,8 +449,11 @@ Mixin Class MarineFunctions
Return;
}

//If the target is nearby, visible, and hostile, and has over 2500 health.
If (IsHostile (Target) && Distance3DSquared (Target) <= ((User_FearDistance*FRandom (1.01,1.25))*(User_FearDistance*FRandom (1.01,1.25))) && Target.SpawnHealth() >= 2000 && IsVisible (Target,True)
//If the target is marked as needing to be feared automatically.
If (Target.CountInv ("SM_IAmTheDanger") > 0

//Or the target is nearby, visible, and hostile, and has over 2500 health.
|| IsHostile (Target) && Distance3DSquared (Target) <= ((User_FearDistance*FRandom (1.01,1.25))*(User_FearDistance*FRandom (1.01,1.25))) && Target.SpawnHealth() >= 2000 && IsVisible (Target,True)

//Or if it is big enough and visible and close enough.
|| (Target.Height >= 80 && Target.Radius >= 72) && Distance3DSquared (Target) <= ((User_FearDistance*FRandom (1.01,1.25))*(User_FearDistance*FRandom (1.01,1.25))) && IsVisible (Target,True)
Expand Down Expand Up @@ -611,6 +614,8 @@ Mixin Class MarineFunctions

If ((Target && Goal && Target == Goal) && !GoingToTurret) Return; //Don't fuck things up by making other marines try and attack a patrol point. Or stoping them from going to a turret.

If (Target && Target.CountInv ("SM_DontWarnOthers") > 0) Return; //Don't warn other marines if the target has this token.

Actor PotentialMarine;
Bool FoundMarines;

Expand Down Expand Up @@ -782,7 +787,7 @@ Mixin Class MarineFunctions
{
If (User_EnemyAlertHearingRange == -1) Return; //Don't run this if the feature is turned off.

If (!Target)
If (!Target || Target && Target.CountInv ("SM_DontWarnOthers") <= 0)
{
Actor Mobj;
BlockThingsIterator ListenForEnemyMarines = BlockThingsIterator.Create (Self,HearingRadius);
Expand Down Expand Up @@ -884,7 +889,7 @@ Mixin Class MarineFunctions
Mobj = FindEnemies.Thing;

//If you found a monster or player, that is alive, hostile, close enough to you, and visible.
If ((Mobj.bIsMonster || Mobj Is "PlayerPawn") && Mobj.Health > 0 && IsHostile (Mobj) && Mobj.Distance3DSquared (Target) <= EnemyRadius*EnemyRadius && IsVisible (Mobj,False,params:MarineSight))
If ((Mobj.bIsMonster || Mobj.Player) && Mobj.Health > 0 && IsHostile (Mobj) && Mobj.Distance3DSquared (Target) <= EnemyRadius*EnemyRadius && IsVisible (Mobj,False,params:MarineSight))
{
Switch (Mobj.Health)
{
Expand Down
8 changes: 7 additions & 1 deletion Marine_OtherActors.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -468,4 +468,10 @@ Class SM_ImInDanger : Inventory
+Inventory.Untossable;
+Inventory.NoScreenFlash;
}
}
}

//Given to actors to mark them as needing to be feared by marines automatically, regardless of their size or health.
Class SM_IAmTheDanger : SM_ImInDanger{}

//Tells marines to not warn other marines if the actor has this token. Used to precent stuff such as the Military Vehicle Packs' SmartMarineWarningZone being targetted by marines.
Class SM_DontWarnOthers : SM_ImInDanger{}
2 changes: 2 additions & 0 deletions Marine_Squads.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ Extend Class SmartMarine
If (!(Master Is "SmartMarine"))
Return;

If (Target.CountInv ("SM_DontWarnOthers") > 0) Return; //Don't warn other marines if the target has this token.

If (Master && SmartMarine(Master).Squad)
SmartMarine(Master).Squad.AlertSquad(Self);
Else If (Squad && Squad.Leader == Self)
Expand Down
5 changes: 3 additions & 2 deletions Marine_Turret.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ class SmartMarineMGWeapon : Weapon

Override Void AttachToOwner (Actor Other)
{
If (!Legit) {Console.Printf ("%s",CheatMessages[Random(0,3)]);}
If (!Legit) Console.Printf ("%s",CheatMessages[Random(0,3)]);
Super.AttachToOwner (Other);
}

Expand Down Expand Up @@ -556,7 +556,8 @@ Class SmartMarineMGBullet : FastProjectile
Radius 4;
Height 8;
Speed 200;
Scale 0.2;
XScale 0.2;
YScale 0.166667; //0.2 / 1.2
DamageFunction (Random (40,50)/10); //A ripper damages an actor with a total radius of 64 MU, 10 times, hence dividing the random damage output by 10.
ProjectileKickback 8;
RipperLevel 3;
Expand Down
6 changes: 5 additions & 1 deletion Marine_UserVariables.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Extend Class SmartMarine
If (User_SearchTime == 0) User_SearchTime = 500; //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_AlertRange == 0) User_AlertRange = 512; //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_TurretThreshold == 0) User_TurretThreshold = 100; //Default chance for the marine to use a turret.
Expand Down Expand Up @@ -68,6 +68,10 @@ Extend Class SmartMarine
CurrentMarineOrder = ORDER_WANDER;
bDontFollowPlayers = True;
}
Else If (User_DefaultOrder ~== "Stay")
{
CurrentMarineOrder = ORDER_STANDSTILL;
}
}

Void HandleRandomPersonalityMidGame()
Expand Down
12 changes: 11 additions & 1 deletion ZScript.zsc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ MARINES AT THIS MICRO-INSTANT FOR YOU. HATE. HATE.*/
//I want to make more marines in the future, but to do that properly, I'll have to rewrite the code base for the 7th time, for my response to that, please refer to the above to do entry.
//Maybe add a secondary melee attack to the rifle weapon, like what the marines have. I'll need first person sprites of the rifle being swung though.
//Possibly make an actual API that mods can use, such as multiple services that can return if variables like OnTurret and Crouching are on.
//Fix a bug that makes marines take cover even behind hitscan and projectile blocking linedefs.

Class SmartMarine : Actor
{
Expand Down Expand Up @@ -63,11 +64,20 @@ Class SmartMarine : Actor
+SeeFriendlyMonsters; //No more ZScript code hacks.
}

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

GiveInventory ("GreenArmor",1); //Yep, the marines wear actual armor.
//The marine does not have a "Missile" and "Melee" state label, so these are needed for internal code such as the AvoidMelee flag to know that the marines DO have melee and ranged attacks.
MissileState = FindState ("DecideAttack"); //Would probably be better to conditionally change this based on what attack the marine is currently doing, with DecideAttack as a fallback, or something.
MeleeState = FindState ("RifleSmack");
}

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

GiveInventory ("GreenArmor",1); //Yep, the marines wear actual armor.
InitializeSquad();
SetUserVariableDefaults();
HandleRandomPersonalityMidGame();
Expand Down

0 comments on commit 502f9f1

Please sign in to comment.