Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 4f0b037

Browse files
authored
Merge pull request #52 from cortex-command-community/4zk-content
4zK's content update #3: Base.rte v0.2
2 parents 0aca5ed + 3f246bc commit 4f0b037

File tree

191 files changed

+2679
-1243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

191 files changed

+2679
-1243
lines changed

Base.rte/AI/DropShipAI.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,13 @@ end
1010
function UpdateAI(self)
1111
self.AI:Update(self)
1212
end
13+
14+
function Update(self)
15+
--Re-orient the craft at 180 degrees to help rotational AI
16+
if self.RotAngle > math.pi then
17+
self.RotAngle = self.RotAngle - (math.pi * 2);
18+
end
19+
if self.RotAngle < -math.pi then
20+
self.RotAngle = self.RotAngle + (math.pi * 2);
21+
end
22+
end

Base.rte/AI/HumanAI.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ function Create(self)
1111
self.visibleInventory = true;
1212
end
1313
function Update(self)
14-
1514
self.controller = self:GetController();
1615

1716
if self.alternativeGib then
@@ -21,7 +20,7 @@ function Update(self)
2120
HumanFunctions.DoAutomaticEquip(self);
2221
end
2322
if self.armSway then
24-
HumanFunctions.DoArmSway(self, (self.Health / self.MaxHealth)); --Argument: shove strength
23+
HumanFunctions.DoArmSway(self, (self.Health/self.MaxHealth)); --Argument: shove strength
2524
end
2625
if self.visibleInventory then
2726
HumanFunctions.DoVisibleInventory(self, false); --Argument: whether to show all items

Base.rte/AI/HumanBehaviors.lua

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,14 @@ function HumanBehaviors.GetTeamShootingSkill(team)
99
end
1010

1111
local aimSpeed, aimSkill
12-
if skill < Activity.AVERAGESKILL then -- the AI shoot later and tracks the target slower
13-
aimSpeed = -0.025 * skill + 3.3 -- affects the delay before the shooting starts [3.30 .. 1.55]
14-
aimSkill = -0.011 * skill + 2.2 -- affects the precision of the shots [2.20 .. 1.43]
15-
elseif skill >= Activity.UNFAIRSKILL then
16-
aimSpeed = 0.05
17-
aimSkill = 0.05
12+
if skill >= Activity.UNFAIRSKILL then
13+
aimSpeed = 0.04
14+
aimSkill = 0.04
1815
else
1916
-- the AI shoot sooner and with slightly better precision
20-
aimSpeed = 1/(0.55/(2.9-math.exp(skill*0.01))) -- [1.42 .. 0.38]
21-
aimSkill = 1/(0.65/(3.0-math.exp(skill*0.01))) -- [1.36 .. 0.48]
17+
aimSpeed = 1/(0.65/(2.9-math.exp(skill*0.01)))
18+
aimSkill = 1/(0.75/(3.0-math.exp(skill*0.01)))
2219
end
23-
2420
return aimSpeed, aimSkill, skill
2521
end
2622

@@ -36,10 +32,10 @@ end
3632

3733
-- spot targets by casting a ray in a random direction
3834
function HumanBehaviors.LookForTargets(AI, Owner, Skill)
39-
local viewAngDeg = RangeRand(50, 120) * Owner.Perceptiveness * (0.5 + Skill / 200)
35+
local viewAngDeg = RangeRand(50, 120) * Owner.Perceptiveness * (0.5 + Skill/200)
4036
if AI.deviceState == AHuman.AIMING then
4137
AI.Ctrl:SetState(Controller.AIM_SHARP, true) -- reinforce sharp aim controller state to enable SharpLength in LookForMOs
42-
viewAngDeg = 15 * Owner.Perceptiveness + (Skill / 10)
38+
viewAngDeg = 15 * Owner.Perceptiveness + (Skill/10)
4339
end
4440

4541
local FoundMO = Owner:LookForMOs(viewAngDeg, rte.grassID, false)
@@ -84,6 +80,8 @@ function HumanBehaviors.CheckEnemyLOS(AI, Owner, Skill)
8480

8581
local LookTarget
8682
if Enemy.ClassName == "ADoor" then
83+
-- TO-DO: use explosive weapons on doors?
84+
8785
local Door = ToADoor(Enemy).Door
8886
if Door and Door:IsAttached() then
8987
LookTarget = Door.Pos
@@ -500,8 +498,7 @@ function HumanBehaviors.Sentry(AI, Owner, Abort)
500498
elseif AI.SentryFacing and Owner.HFlipped ~= AI.SentryFacing then
501499
Owner.HFlipped = AI.SentryFacing -- turn to the direction we have been order to guard
502500
break -- restart this behavior
503-
elseif math.random() < Owner.Perceptiveness then
504-
501+
elseif AI.Target == nil and math.random() < Owner.Perceptiveness then
505502
-- turn around occasionally if there is open space behind our back
506503
local backAreaRay = Vector(-math.random(FrameMan.PlayerScreenWidth/4, FrameMan.PlayerScreenWidth/2) * Owner.FlipFactor, 0):DegRotate(math.random(-25, 25) * Owner.Perceptiveness)
507504
if not SceneMan:CastStrengthRay(Owner.EyePos, backAreaRay, 10, Vector(), 10, rte.grassID, SceneMan.SceneWrapsX) then
@@ -1682,13 +1679,12 @@ function HumanBehaviors.GoToWpt(AI, Owner, Abort)
16821679
else
16831680
nextLatMove = Actor.LAT_STILL
16841681
end
1685-
if not (Owner.FGLeg and Owner.BGLeg) and not AI.jump then
1686-
Owner:GetController():SetState(Controller.BODY_CROUCH,true) -- crawl if no legs
1687-
end
16881682
end
16891683
elseif ((CurrDist.X < -5 and Owner.HFlipped) or (CurrDist.X > 5 and not Owner.HFlipped)) and math.abs(Owner.Vel.X) < 1 then
16901684
-- no legs, jump forward
16911685
AI.jump = true
1686+
elseif not AI.jump then
1687+
AI.proneState = AHuman.GOPRONE
16921688
end
16931689

16941690
if Waypoint.Type == "right" then
@@ -1821,7 +1817,7 @@ function HumanBehaviors.GoToWpt(AI, Owner, Abort)
18211817
local delta = SceneMan:ShortestDistance(Waypoint.Pos, FallPos, false).Magnitude - Facings[1].range
18221818
if delta < 1 then
18231819
AI.jump = false
1824-
elseif AI.flying or delta > 15 then
1820+
elseif AI.flying or delta > 25 then
18251821
AI.jump = true
18261822
nextAimAngle = Owner:GetAimAngle(false) * 0.5 + Facings[1].aim * 0.5 -- adjust jetpack nozzle direction
18271823
nextLatMove = Actor.LAT_STILL
@@ -2146,32 +2142,32 @@ function HumanBehaviors.GetProjectileData(Owner)
21462142

21472143
-- find muzzle velocity
21482144
PrjDat.vel = Weapon:GetAIFireVel()
2149-
21502145
-- half of the theoretical upper limit for the total amount of material strength this weapon can destroy in 250ms
2151-
PrjDat.pen = Weapon:GetAIPenetration() * math.max((Weapon.RateOfFire / 240), 1)
21522146

21532147
PrjDat.g = SceneMan.GlobalAcc.Y * 0.67 * Weapon:GetBulletAccScalar() -- underestimate gravity
21542148
PrjDat.vsq = PrjDat.vel^2 -- muzzle velocity squared
21552149
PrjDat.vqu = PrjDat.vsq^2 -- muzzle velocity quad
21562150
PrjDat.drg = 1 - Projectile.AirResistance * TimerMan.DeltaTimeSecs -- AirResistance is stored as the ini-value times 60
21572151
PrjDat.thr = math.min(Projectile.AirThreshold, PrjDat.vel)
2152+
PrjDat.pen = (Projectile.Mass * Projectile.Sharpness * PrjDat.vel) * PrjDat.drg
21582153

21592154
-- estimate theoretical max range with ...
21602155
local lifeTime = Weapon:GetAIBulletLifeTime()
21612156
if lifeTime < 1 then -- infinite life time
21622157
PrjDat.rng = math.huge
21632158
elseif PrjDat.drg < 1 then -- AirResistance
21642159
PrjDat.rng = 0
2165-
local threshold = PrjDat.thr * GetPPM() * TimerMan.DeltaTimeSecs -- AirThreshold in pixels/frame
2166-
local vel = PrjDat.vel * GetPPM() * TimerMan.DeltaTimeSecs -- muzzle velocity in pixels/frame
2160+
local threshold = PrjDat.thr * rte.PxTravelledPerFrame -- AirThreshold in pixels/frame
2161+
local vel = PrjDat.vel * rte.PxTravelledPerFrame -- muzzle velocity in pixels/frame
2162+
21672163
for _ = 0, math.ceil(lifeTime/TimerMan.DeltaTimeMS) do
21682164
PrjDat.rng = PrjDat.rng + vel
21692165
if vel > threshold then
21702166
vel = vel * PrjDat.drg
21712167
end
21722168
end
21732169
else -- no AirResistance
2174-
PrjDat.rng = PrjDat.vel * GetPPM() * TimerMan.DeltaTimeSecs * (lifeTime / TimerMan.DeltaTimeMS)
2170+
PrjDat.rng = PrjDat.vel * rte.PxTravelledPerFrame * (lifeTime / TimerMan.DeltaTimeMS)
21752171
end
21762172

21772173
-- Artificially decrease reported range to make sure AI
@@ -2633,9 +2629,9 @@ function HumanBehaviors.ThrowTarget(AI, Owner, Abort)
26332629
local scan = 0
26342630
local miss = 0 -- stop scanning after a few missed attempts
26352631
local AimPoint, Dist, MO, ID, rootID, LOS, aim
2636-
2632+
26372633
AI.TargetLostTimer:SetSimTimeLimitMS(1500)
2638-
2634+
26392635
while true do
26402636
if not MovableMan:ValidMO(AI.Target) then
26412637
break
@@ -2747,7 +2743,7 @@ function HumanBehaviors.ThrowTarget(AI, Owner, Abort)
27472743
aim = HumanBehaviors.GetGrenadeAngle(AimPoint, Vector(), Grenade.MuzzlePos, Grenade.MaxThrowVel)
27482744
if aim then
27492745
ThrowTimer:Reset()
2750-
aimTime = RangeRand(1000, 1200)
2746+
aimTime = RangeRand(900, 1100)
27512747
local maxAim = aim
27522748

27532749
-- try again with an average throw vel
@@ -2829,24 +2825,22 @@ function HumanBehaviors.AttackTarget(AI, Owner, Abort)
28292825
local meleeDist = 0
28302826
local startPos = Vector(Owner.EyePos.X, Owner.EyePos.Y)
28312827

2832-
if Owner.EquippedItem then
2833-
if Owner.EquippedItem:HasObjectInGroup("Tools - Diggers") or Owner.EquippedItem:HasObjectInGroup("Weapons - Melee") then
2834-
meleeDist = Owner.Radius + 25
2835-
startPos = Vector(Owner.EquippedItem.Pos.X, Owner.EquippedItem.Pos.Y)
2836-
end
2828+
if Owner:EquipDeviceInGroup("Tools - Diggers", true) or Owner:EquipDeviceInGroup("Weapons - Melee", true) then
2829+
meleeDist = Owner.Radius + 25
2830+
startPos = Vector(Owner.EquippedItem.Pos.X, Owner.EquippedItem.Pos.Y)
28372831
elseif Owner.armSway then
2838-
if Owner.FGArm then
2839-
meleeDist = Owner.Radius + Owner.FGArm.Radius
2840-
startPos = Owner.FGArm.Pos
2841-
elseif Owner.BGArm then
2842-
meleeDist = Owner.Radius + Owner.BGArm.Radius
2843-
startPos = Owner.BGArm.Pos
2832+
local arm = Owner.FGArm or Owner.BGArm
2833+
if arm then
2834+
meleeDist = arm.Radius + arm.Radius
2835+
startPos = arm.Pos
28442836
end
28452837
end
28462838
if meleeDist > 0 then
2847-
local dist = SceneMan:ShortestDistance(startPos, AI.Target.Pos, false)
2839+
local attackPos = (AI.Target.ClassName == "ADoor" and ToADoor(AI.Target).Door and ToADoor(AI.Target).Door:IsAttached()) and ToADoor(AI.Target).Door.Pos or AI.Target.Pos
2840+
local dist = SceneMan:ShortestDistance(startPos, attackPos, false)
28482841
if dist.Magnitude < meleeDist then
2849-
AI.Ctrl.AnalogAim = SceneMan:ShortestDistance(Owner.EyePos, AI.Target.Pos, false).Normalized
2842+
AI.lateralMoveState = Actor.LAT_STILL
2843+
AI.Ctrl.AnalogAim = SceneMan:ShortestDistance(Owner.EyePos, attackPos, false).Normalized
28502844
AI.fire = true
28512845
else
28522846
AI.fire = false

Base.rte/AI/HumanFunctions.lua

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@ HumanFunctions = {};
22

33
function HumanFunctions.DoAlternativeGib(actor)
44
--Detach limbs instead of regular gibbing
5-
if not actor.detachLimit then
6-
actor.detachLimit = actor.GibWoundLimit;
7-
actor.GibWoundLimit = actor.GibWoundLimit * 1.5;
8-
end
9-
if actor.WoundCount > actor.detachLimit then
10-
actor.detachLimit = actor.WoundCount + 1;
11-
local parts = {actor.BGArm, actor.BGLeg, actor.FGArm, actor.FGLeg, actor.Head}; --Piority order
12-
local mostWounds = -1;
13-
local detachLimb;
14-
--Pick the limb with most wounds and detach it
15-
for i = 1, #parts do
16-
local limb = parts[i];
17-
if limb and limb.WoundCount > mostWounds then
18-
detachLimb = limb;
19-
mostWounds = limb.WoundCount;
5+
if actor.detachLimit then
6+
if actor.WoundCount > actor.detachLimit then
7+
actor.detachLimit = actor.WoundCount + 1;
8+
local parts = {actor.BGArm, actor.BGLeg, actor.FGArm, actor.FGLeg, actor.Head}; --Priority order
9+
local mostWounds = -1;
10+
local detachLimb;
11+
--Pick the limb with most wounds and detach it
12+
for i = 1, #parts do
13+
local limb = parts[i];
14+
if limb and limb.WoundCount > mostWounds then
15+
detachLimb = limb;
16+
mostWounds = limb.WoundCount;
17+
end
18+
end
19+
if detachLimb then
20+
detachLimb.JointStrength = -1;
2021
end
2122
end
22-
if detachLimb then
23-
detachLimb.JointStrength = -1;
24-
end
23+
elseif actor.GibWoundLimit > 0 then
24+
actor.detachLimit = actor.GibWoundLimit;
25+
actor.GibWoundLimit = actor.GibWoundLimit * 1.5;
2526
end
2627
end
2728

@@ -39,20 +40,15 @@ function HumanFunctions.DoArmSway(actor, pushStrength)
3940
actor.lastAngle = aimAngle;
4041
actor.lastHandPos = {actor.Pos, actor.Pos};
4142
end
42-
if actor.controller:IsMouseControlled() then
43-
--Flail around if moving mouse too fast
44-
local mouseVec = Vector(actor.controller.MouseMovement.X, actor.controller.MouseMovement.Y):SetMagnitude(math.sqrt(actor.controller.MouseMovement.Magnitude));
45-
local ang = actor.lastAngle - aimAngle;
46-
47-
actor.AngularVel = actor.AngularVel - (2 * ang * actor.FlipFactor + mouseVec.Y * actor.FlipFactor /10) /math.sqrt(math.abs(actor.AngularVel) + 1);
48-
49-
actor.lastAngle = aimAngle;
50-
end
43+
--Flail around if aiming around too fast
44+
local angleMovement = actor.lastAngle - aimAngle;
45+
actor.AngularVel = actor.AngularVel - (2 * angleMovement * actor.FlipFactor)/(math.abs(actor.AngularVel)/10 + 1);
46+
actor.lastAngle = aimAngle;
5147
--Shove when unarmed
5248
if actor.controller:IsState(Controller.WEAPON_FIRE) and (actor.FGArm or actor.BGArm) and not (actor.EquippedItem or actor.EquippedBGItem) and actor.Status == Actor.STABLE then
53-
actor.AngularVel = actor.AngularVel /(actor.shoved and 1.3 or 3) + (aimAngle - actor.RotAngle * actor.FlipFactor - 1.57) * (actor.shoved and 0.3 or 3) * actor.FlipFactor /(1 + math.abs(actor.RotAngle));
49+
actor.AngularVel = actor.AngularVel/(actor.shoved and 1.3 or 3) + (aimAngle - actor.RotAngle * actor.FlipFactor - 1.57) * (actor.shoved and 0.3 or 3) * actor.FlipFactor/(1 + math.abs(actor.RotAngle));
5450
if not actor.shoved then
55-
actor.Vel = actor.Vel + Vector(2 /(1 + actor.Vel.Magnitude), 0):RadRotate(actor:GetAimAngle(true)) * math.abs(math.cos(actor:GetAimAngle(true)));
51+
actor.Vel = actor.Vel + Vector(2/(1 + actor.Vel.Magnitude), 0):RadRotate(actor:GetAimAngle(true)) * math.abs(math.cos(actor:GetAimAngle(true)));
5652
actor.shoved = true;
5753
end
5854
else
@@ -78,31 +74,31 @@ function HumanFunctions.DoArmSway(actor, pushStrength)
7874
if actor.controller:IsState(Controller.AIM_SHARP) then
7975
arm.IdleOffset = Vector(0, 1):RadRotate(aimAngle);
8076
else
81-
arm.IdleOffset = Vector(0, (armLength + arm.SpriteOffset.X) * 1.1):RadRotate(rotAng * actor.FlipFactor + 1.5 + (i /5));
77+
arm.IdleOffset = Vector(0, (armLength + arm.SpriteOffset.X) * 1.1):RadRotate(rotAng * actor.FlipFactor + 1.5 + (i/5));
8278
end
8379
if actor.shoved or (actor.EquippedItem and IsTDExplosive(actor.EquippedItem) and actor.controller:IsState(Controller.WEAPON_FIRE)) then
8480
arm.IdleOffset = Vector(armLength + (pushStrength * armLength), 0):RadRotate(aimAngle);
8581
local handVector = SceneMan:ShortestDistance(actor.lastHandPos[i], arm.HandPos, SceneMan.SceneWrapsX);
8682
--Diminish hand relocation vector to potentially prevent post-superhuman pushing powers
87-
handVector:SetMagnitude(handVector.Magnitude / (1 + handVector.Magnitude / 100));
83+
handVector:SetMagnitude(handVector.Magnitude/(1 + handVector.Magnitude/100));
8884
--Emphasize the first frames that signify contracted arm = highest potential energy
89-
local dots = math.sqrt(arm.Radius) / (1 + arm.Frame /arm.FrameCount);
85+
local dots = math.sqrt(arm.Radius)/(1 + arm.Frame/arm.FrameCount);
9086
local armStrength = (arm.Mass + arm.Material.StructuralIntegrity) * pushStrength;
9187
for i = 1, dots do
9288
local part = CreateMOPixel("Smack Particle Light");
93-
part.Pos = arm.HandPos - Vector(handVector.X/2, handVector.Y /2);
89+
part.Pos = arm.HandPos - Vector(handVector.X/2, handVector.Y/2);
9490
part.Vel = Vector(handVector.X, handVector.Y):RadRotate(RangeRand(-0.1, 0.1)) + Vector(0, -0.5);
9591
part.Mass = armStrength; part.Sharpness = math.random() * 0.1;
9692
part.Team = actor.Team; part.IgnoresTeamHits = true;
9793
MovableMan:AddParticle(part);
9894
end
9995
--Apply some additional forces if the travel vector of the moving hand is half an arms length
100-
if handVector.Magnitude > (armLength /2) then
96+
if handVector.Magnitude > (armLength/2) then
10197
local moCheck = SceneMan:GetMOIDPixel(arm.HandPos.X, arm.HandPos.Y)
10298
if moCheck ~= rte.NoMOID then
10399
local mo = MovableMan:GetMOFromID(MovableMan:GetMOFromID(moCheck).RootID);
104-
if mo and mo.Team ~= actor.Team and IsActor(mo) and actor.Mass > (mo.Mass / 2) then
105-
mo:AddForce(handVector * (actor.Mass / 2), Vector());
100+
if mo and mo.Team ~= actor.Team and IsActor(mo) and actor.Mass > (mo.Mass/2) then
101+
mo:AddForce(handVector * (actor.Mass/2), Vector());
106102
ToActor(mo).Status = Actor.UNSTABLE;
107103
end
108104
end
@@ -120,7 +116,6 @@ function HumanFunctions.DoVisibleInventory(actor, showAll)
120116
for i = 1, actor.InventorySize do
121117
local item = actor:Inventory();
122118
if item then
123-
local fixNum = actor.HFlipped and -1 or 0; --Fix offsets slightly when facing left
124119
if item.ClassName == "TDExplosive" then
125120
thrownCount = thrownCount + 1;
126121
elseif item.ClassName == "HDFirearm" or item.ClassName == "HeldDevice" then
@@ -131,7 +126,7 @@ function HumanFunctions.DoVisibleInventory(actor, showAll)
131126
local isFirearm = item.ClassName == "HeldDevice" and 0 or 1;
132127
local actorSize, itemSize = math.sqrt(actor.Radius), math.sqrt(item.Radius + math.abs(item.Mass));
133128

134-
fixNum = fixNum + item.Radius * 0.2 + math.sqrt(heldCount);
129+
local fixNum = item.Radius * 0.2 + math.sqrt(heldCount);
135130

136131
--Bigger actors carry weapons higher up, smaller weapons are carried lower down
137132
local drawPos = actor.Pos + Vector((-actorSize - fixNum) * actor.FlipFactor, -actorSize - itemSize + 1 + isFirearm * 3):RadRotate(actor.RotAngle);
@@ -141,11 +136,13 @@ function HumanFunctions.DoVisibleInventory(actor, showAll)
141136
local tallAng = ToMOSprite(item):GetSpriteWidth() > ToMOSprite(item):GetSpriteHeight() and 1.57 or 0;
142137

143138
local tilt = 0.3;
144-
local rotAng = actor.RotAngle + tallAng + (heldCount * tilt - itemCount * tilt + isFirearm /itemSize) /itemCount * actor.FlipFactor;
139+
local rotAng = actor.RotAngle + tallAng + (heldCount * tilt - itemCount * tilt + isFirearm/itemSize)/itemCount * actor.FlipFactor;
145140

146141
for player = Activity.PLAYER_1, Activity.MAXPLAYERCOUNT - 1 do
147-
if not SceneMan:IsUnseen(drawPos.X, drawPos.Y, ActivityMan:GetActivity():GetTeamOfPlayer(player)) then
148-
PrimitiveMan:DrawBitmapPrimitive(ActivityMan:GetActivity():ScreenOfPlayer(player), drawPos, item, rotAng, 0);
142+
143+
local screen = ActivityMan:GetActivity():ScreenOfPlayer(player);
144+
if screen ~= -1 and not SceneMan:IsUnseen(drawPos.X, drawPos.Y, ActivityMan:GetActivity():GetTeamOfPlayer(player)) then
145+
PrimitiveMan:DrawBitmapPrimitive(screen, drawPos, item, rotAng, 0);
149146
end
150147
end
151148
end

0 commit comments

Comments
 (0)