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

Commit e7935ef

Browse files
authored
Merge pull request #28 from cortex-command-community/4zK-content
4zK's content update #1: Base.rte v0.1
2 parents f0400f4 + 08df53b commit e7935ef

File tree

294 files changed

+3872
-2571
lines changed

Some content is hidden

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

294 files changed

+3872
-2571
lines changed

Base.rte/AI/HumanAI.lua

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1-
21
dofile("Base.rte/Constants.lua")
3-
require("AI/NativeHumanAI") --dofile("Base.rte/Actors/AI/NativeHumanAI.lua")
2+
require("AI/NativeHumanAI")
3+
require("AI/HumanFunctions");
44

55
function Create(self)
6-
self.AI = NativeHumanAI:Create(self)
6+
self.AI = NativeHumanAI:Create(self);
7+
-- You can turn features on and off here
8+
self.armSway = true;
9+
self.automaticEquip = true;
10+
self.alternativeGib = true;
11+
self.visibleInventory = true;
712
end
13+
function Update(self)
814

15+
self.controller = self:GetController();
16+
17+
if self.alternativeGib then
18+
HumanFunctions.DoAlternativeGib(self);
19+
end
20+
if self.automaticEquip then
21+
HumanFunctions.DoAutomaticEquip(self);
22+
end
23+
if self.armSway then
24+
HumanFunctions.DoArmSway(self, 10); -- Argument: shove strength
25+
end
26+
if self.visibleInventory then
27+
HumanFunctions.DoVisibleInventory(self, false); -- Argument: whether to show all items
28+
end
29+
end
930
function UpdateAI(self)
10-
self.AI:Update(self)
31+
self.AI:Update(self);
1132
end
12-
1333
function Destroy(self)
14-
self.AI:Destroy(self)
15-
end
34+
self.AI:Destroy(self);
35+
end

Base.rte/AI/HumanBehaviors.lua

Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function HumanBehaviors.GetTeamShootingSkill(team)
2121
aimSkill = 1/(0.65/(3.0-math.exp(skill*0.01))) -- [1.36 .. 0.48]
2222
end
2323

24-
return aimSpeed, aimSkill
24+
return aimSpeed, aimSkill, skill
2525
end
2626

2727
function HumanBehaviors.SetShootingSkill()
@@ -35,10 +35,11 @@ function HumanBehaviors.GetShootingSkill()
3535
end
3636

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

4445
local FoundMO = Owner:LookForMOs(viewAngDeg, rte.grassID, false)
@@ -52,24 +53,24 @@ function HumanBehaviors.LookForTargets(AI, Owner)
5253
end
5354
end
5455

55-
-- brains spot targets by casting rays at all nearby enemy actors
56-
function HumanBehaviors.CheckEnemyLOS(AI, Owner)
56+
-- brains and snipers spot targets by casting rays at all nearby enemy actors
57+
function HumanBehaviors.CheckEnemyLOS(AI, Owner, Skill)
5758
if not AI.Enemies then -- add all enemy actors on our screen to a table and check LOS to them, one per frame
5859
AI.Enemies = {}
5960
for Act in MovableMan.Actors do
6061
if Act.Team ~= Owner.Team then
6162
if not AI.isPlayerOwned or not SceneMan:IsUnseen(Act.Pos.X, Act.Pos.Y, Owner.Team) then -- AI-teams ignore the fog
6263
local Dist = SceneMan:ShortestDistance(Owner.ViewPoint, Act.Pos, false)
63-
if (math.abs(Dist.X) - Act.Diameter < FrameMan.PlayerScreenWidth * 0.6) and
64-
(math.abs(Dist.Y) - Act.Diameter < FrameMan.PlayerScreenHeight * 0.6)
64+
if (math.abs(Dist.X) - Act.Diameter < FrameMan.PlayerScreenWidth * (0.4 + Skill * 0.005)) and
65+
(math.abs(Dist.Y) - Act.Diameter < FrameMan.PlayerScreenHeight * (0.4 + Skill * 0.005))
6566
then
6667
table.insert(AI.Enemies, Act)
6768
end
6869
end
6970
end
7071
end
7172

72-
return HumanBehaviors.LookForTargets(AI, Owner) -- cast rays like normal actors occasionally
73+
return HumanBehaviors.LookForTargets(AI, Owner, Skill) -- cast rays like normal actors occasionally
7374
else
7475
local Enemy = table.remove(AI.Enemies)
7576
if Enemy then
@@ -87,7 +88,7 @@ function HumanBehaviors.CheckEnemyLOS(AI, Owner)
8788
if Door and Door:IsAttached() then
8889
LookTarget = Door.Pos
8990
else
90-
return HumanBehaviors.LookForTargets(AI, Owner) -- this door is destroyed, cast rays like normal actors
91+
return HumanBehaviors.LookForTargets(AI, Owner, Skill) -- this door is destroyed, cast rays like normal actors
9192
end
9293
else
9394
LookTarget = Enemy.Pos
@@ -133,7 +134,7 @@ function HumanBehaviors.CheckEnemyLOS(AI, Owner)
133134
end
134135
else
135136
AI.Enemies = nil
136-
return HumanBehaviors.LookForTargets(AI, Owner) -- cast rays like normal actors occasionally
137+
return HumanBehaviors.LookForTargets(AI, Owner, Skill) -- cast rays like normal actors occasionally
137138
end
138139
end
139140
end
@@ -273,13 +274,14 @@ end
273274

274275
-- deprecated since B30. make sure we equip our preferred device if we have one. return true if we must run this function again to be sure
275276
function HumanBehaviors.EquipPreferredWeapon(AI, Owner)
276-
if AI.PlayerPreferredHD then
277-
Owner:EquipNamedDevice(AI.PlayerPreferredHD, true)
278-
elseif not Owner:EquipDeviceInGroup("Weapons - Primary", true) then
279-
Owner:EquipDeviceInGroup("Weapons - Secondary", true)
277+
if AI.squadShoot == false then
278+
if AI.PlayerPreferredHD then
279+
Owner:EquipNamedDevice(AI.PlayerPreferredHD, true)
280+
elseif not Owner:EquipDeviceInGroup("Weapons - Primary", true) then
281+
Owner:EquipDeviceInGroup("Weapons - Secondary", true)
282+
end
283+
return false
280284
end
281-
282-
return false
283285
end
284286

285287
-- deprecated since B30. make sure we equip a primary weapon if we have one. return true if we must run this function again to be sure
@@ -840,7 +842,7 @@ function HumanBehaviors.BrainSearch(AI, Owner, Abort)
840842
Owner:AddAIMOWaypoint(Brains[1])
841843
AI:CreateGoToBehavior(Owner)
842844
end
843-
else
845+
else -- lobotomy test
844846
local ClosestBrain
845847
local minDist = math.huge
846848
for _, Act in pairs(Brains) do
@@ -893,9 +895,10 @@ function HumanBehaviors.BrainSearch(AI, Owner, Abort)
893895
end
894896
end
895897

896-
Owner:ClearAIWaypoints()
897-
898-
if MovableMan:IsActor(ClosestBrain) then
898+
--Owner:ClearAIWaypoints() -- this part freezes the script when facing the opposing brain
899+
--
900+
if MovableMan:IsActor(ClosestBrain) then --
901+
Owner:ClearAIWaypoints() -- moving the function here fixes it (4zK)
899902
Owner:AddAIMOWaypoint(ClosestBrain)
900903
AI:CreateGoToBehavior(Owner)
901904
else
@@ -914,7 +917,7 @@ end
914917
function HumanBehaviors.WeaponSearch(AI, Owner, Abort)
915918
local minDist
916919
local Devices = {}
917-
local pickupDiggers = not Owner:HasObjectInGroup("Diggers")
920+
local pickupDiggers = not Owner:HasObjectInGroup("Tools - Diggers")
918921

919922
if AI.isPlayerOwned then
920923
minDist = 100 -- don't move player actors more than 4m
@@ -960,7 +963,7 @@ function HumanBehaviors.WeaponSearch(AI, Owner, Abort)
960963
elseif Item.ClassName == "TDExplosive" then
961964
score = waypoints * 1.4 -- avoid grenades if there are other weapons
962965
elseif Item:IsTool() then
963-
if pickupDiggers and Item:HasObjectInGroup("Diggers") then
966+
if pickupDiggers and Item:HasObjectInGroup("Tools - Diggers") then
964967
score = waypoints * 1.8 -- avoid diggers if there are other weapons
965968
else
966969
waypoints = minDist -- don't pick up
@@ -1061,7 +1064,7 @@ function HumanBehaviors.ToolSearch(AI, Owner, Abort)
10611064

10621065
local DevicesToPickUp = {}
10631066
for _, Item in pairs(Devices) do
1064-
if MovableMan:ValidMO(Item) and Item:HasObjectInGroup("Diggers") then
1067+
if MovableMan:ValidMO(Item) and Item:HasObjectInGroup("Tools - Diggers") then
10651068
-- estimate the walking distance to the item
10661069
local waypoints = SceneMan.Scene:CalculatePath(Owner.Pos, Item.Pos, false, 1)
10671070
if waypoints < minDist and waypoints > -1 then
@@ -1328,7 +1331,7 @@ function HumanBehaviors.GoToWpt(AI, Owner, Abort)
13281331
local Free = Vector()
13291332

13301333
-- only if we have a digging tool
1331-
if Waypoint.Type ~= "drop" and Owner:HasObjectInGroup("Diggers") then
1334+
if Waypoint.Type ~= "drop" and Owner:HasObjectInGroup("Tools - Diggers") then
13321335
local PathSegRay = SceneMan:ShortestDistance(PrevWptPos, Waypoint.Pos, false) -- detect material blocking the path and start digging through it
13331336
if AI.teamBlockState ~= Actor.BLOCKED and SceneMan:CastStrengthRay(PrevWptPos, PathSegRay, 4, Free, 2, rte.doorID, true) then
13341337
if SceneMan:ShortestDistance(Owner.Pos, Free, false).Magnitude < Owner.Height*0.4 then -- check that we're close enough to start digging
@@ -1672,6 +1675,9 @@ function HumanBehaviors.GoToWpt(AI, Owner, Abort)
16721675
else
16731676
nextLatMove = Actor.LAT_STILL
16741677
end
1678+
if not (Owner.FGLeg and Owner.BGLeg) and not AI.jump then
1679+
Owner:GetController():SetState(Controller.BODY_CROUCH,true) -- crawl if no legs
1680+
end
16751681
end
16761682
elseif ((CurrDist.X < -5 and Owner.HFlipped) or (CurrDist.X > 5 and not Owner.HFlipped)) and math.abs(Owner.Vel.X) < 1 then
16771683
-- no legs, jump forward
@@ -2001,7 +2007,11 @@ function HumanBehaviors.GoToWpt(AI, Owner, Abort)
20012007
if (AI.Target and AI.BehaviorName ~= "AttackTarget") or
20022008
(Owner.AIMode ~= Actor.AIMODE_SQUAD and (AI.BehaviorName == "ShootArea" or AI.BehaviorName == "FaceAlarm"))
20032009
then
2004-
AI.lateralMoveState = Actor.LAT_STILL
2010+
if Owner.aggressive then -- the aggressive behavior setting makes the AI pursue waypoint at all times
2011+
AI.lateralMoveState = nextLatMove
2012+
else
2013+
AI.lateralMoveState = Actor.LAT_STILL
2014+
end
20052015
if not AI.flying then
20062016
AI.jump = false
20072017
end
@@ -2306,7 +2316,7 @@ function HumanBehaviors.ShootTarget(AI, Owner, Abort)
23062316
aimTarget = Dist.AbsRadAngle
23072317
AI.canHitTarget = true
23082318
if Owner.InventorySize > 0 then -- we have more things in the inventory
2309-
if range < 60 and Owner:HasObjectInGroup("Diggers") then
2319+
if range < 60 and Owner:HasObjectInGroup("Tools - Diggers") then
23102320
AI:CreateHtHBehavior(Owner)
23112321
break
23122322
elseif Owner:EquipLoadedFirearmInGroup("Any", "Weapons - Explosive", true) then
@@ -2421,7 +2431,9 @@ function HumanBehaviors.ShootTarget(AI, Owner, Abort)
24212431
end
24222432

24232433
if AI.canHitTarget then
2424-
AI.lateralMoveState = Actor.LAT_STILL
2434+
if not Owner.aggressive then
2435+
AI.lateralMoveState = Actor.LAT_STILL
2436+
end
24252437
if not AI.flying then
24262438
AI.deviceState = AHuman.AIMING
24272439
end
@@ -2806,19 +2818,34 @@ function HumanBehaviors.AttackTarget(AI, Owner, Abort)
28062818
if not AI.Target or not MovableMan:ValidMO(AI.Target) then
28072819
break
28082820
end
2821+
-- use following sequence to attack either with a suited melee weapon or arms
2822+
local meleeDist = 0
2823+
local startPos = Vector(Owner.EyePos.X, Owner.EyePos.Y)
28092824

28102825
if Owner.EquippedItem then
2811-
if Owner.EquippedItem:HasObjectInGroup("Diggers") then -- attack with digger
2812-
local Dist = SceneMan:ShortestDistance(Owner.EquippedItem.Pos, AI.Target.Pos, false)
2813-
if Dist.Magnitude < 40 then
2814-
AI.Ctrl.AnalogAim = SceneMan:ShortestDistance(Owner.EyePos, AI.Target.Pos, false).Normalized
2815-
AI.fire = true
2816-
else
2817-
AI.fire = false
2818-
end
2819-
elseif not Owner:EquipDiggingTool(true) then
2820-
break
2826+
if Owner.EquippedItem:HasObjectInGroup("Tools - Diggers") or Owner.EquippedItem:HasObjectInGroup("Weapons - Melee") then
2827+
meleeDist = Owner.Radius + 25
2828+
startPos = Vector(Owner.EquippedItem.Pos.X, Owner.EquippedItem.Pos.Y)
2829+
end
2830+
elseif Owner.armSway then
2831+
if Owner.FGArm then
2832+
meleeDist = Owner.Radius + Owner.FGArm.Radius
2833+
startPos = Owner.FGArm.Pos
2834+
elseif Owner.BGArm then
2835+
meleeDist = Owner.Radius + Owner.BGArm.Radius
2836+
startPos = Owner.BGArm.Pos
28212837
end
2838+
end
2839+
if meleeDist > 0 then
2840+
local dist = SceneMan:ShortestDistance(startPos, AI.Target.Pos, false)
2841+
if dist.Magnitude < meleeDist then
2842+
AI.Ctrl.AnalogAim = SceneMan:ShortestDistance(Owner.EyePos, AI.Target.Pos, false).Normalized
2843+
AI.fire = true
2844+
else
2845+
AI.fire = false
2846+
end
2847+
else
2848+
break
28222849
-- else TODO: periodically look for weapons?
28232850
end
28242851
end
@@ -3070,7 +3097,9 @@ function HumanBehaviors.FaceAlarm(AI, Owner, Abort)
30703097
AI.AlarmPos = nil
30713098
for _ = 1, math.ceil(200/TimerMan.DeltaTimeMS) do
30723099
AI.deviceState = AHuman.AIMING
3073-
AI.lateralMoveState = Actor.LAT_STILL
3100+
if not Owner.aggressive then
3101+
AI.lateralMoveState = Actor.LAT_STILL
3102+
end
30743103
AI.Ctrl.AnalogAim = AlarmDist.Normalized
30753104
local _ai, _ownr, _abrt = coroutine.yield() -- wait until next frame
30763105
if _abrt then return true end

0 commit comments

Comments
 (0)