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

Commit 895c93b

Browse files
authored
Merge pull request #91 from cortex-command-community/GI-251-ACraft-MaxMass-update
Gi 251 ACraft max mass update
2 parents b89c716 + 0e12e60 commit 895c93b

File tree

28 files changed

+388
-140
lines changed

28 files changed

+388
-140
lines changed

Base.rte/AI/HumanFunctions.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function HumanFunctions.DoAlternativeGib(actor)
2121
end
2222
if actor.detachImpulseLimit and actor.TravelImpulse.Magnitude > actor.detachImpulseLimit then
2323
local parts = {actor.BGLeg, actor.BGArm, actor.FGLeg, actor.FGArm, actor.Head}; --Priority order
24-
local impulsePoint = actor.Pos - actor.TravelImpulse/actor.Mass;
24+
local impulsePoint = actor.Pos - actor.TravelImpulse/(actor.Mass == 0 and 0.0001 or actor.Mass);
2525
local closestDist, detachLimb;
2626
--Pick the limb closest to the direction of impulse
2727
for _, limb in pairs(parts) do
@@ -35,7 +35,7 @@ function HumanFunctions.DoAlternativeGib(actor)
3535
end
3636
end
3737
if detachLimb then
38-
local limbImpulse = actor.TravelImpulse.Magnitude/detachLimb.Mass;
38+
local limbImpulse = actor.TravelImpulse.Magnitude/(detachLimb.Mass == 0 and 0.0001 or detachLimb.Mass);
3939
if limbImpulse > detachLimb.JointStrength then
4040
detachLimb.JointStrength = -1;
4141
if math.random() * limbImpulse > detachLimb.GibImpulseLimit then

Base.rte/Activities/BrainVsBrain.lua

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,12 @@ function BrainvsBrain:CreateHeavyDrop(xPosLZ)
537537
local Craft = RandomACDropShip("Craft", self.TechName[self.CPUTeam]) -- Pick a craft to deliver with
538538
if Craft then
539539
-- The max allowed weight of this craft plus cargo
540-
local craftMaxMass = Craft.MaxMass
540+
local craftMaxMass = Craft.MaxInventoryMass
541541
if craftMaxMass < 0 then
542542
craftMaxMass = math.huge
543543
elseif craftMaxMass < 1 then
544-
craftMaxMass = Craft.Mass + 400 -- MaxMass not defined
544+
Craft = RandomACDropShip("Craft", 0) -- MaxMass not defined
545+
craftMaxMass = Craft.MaxInventoryMass
545546
end
546547

547548
Craft.Team = self.CPUTeam
@@ -565,8 +566,11 @@ function BrainvsBrain:CreateHeavyDrop(xPosLZ)
565566

566567
Craft:AddInventoryItem(Passenger)
567568

568-
-- Stop adding actors when exceeding the weight limit
569-
if Craft.Mass > craftMaxMass then
569+
local inventoryMass = 0;
570+
for item in Craft.Inventory do
571+
inventoryMass = inventoryMass + item.Mass;
572+
end -- Stop adding actors when exceeding the weight limit
573+
if inventoryMass > craftMaxMass then
570574
break
571575
end
572576
end
@@ -593,11 +597,16 @@ function BrainvsBrain:CreateMediumDrop(xPosLZ)
593597

594598
if Craft then
595599
-- The max allowed weight of this craft plus cargo
596-
local craftMaxMass = Craft.MaxMass
600+
local craftMaxMass = Craft.MaxInventoryMass
597601
if craftMaxMass < 0 then
598602
craftMaxMass = math.huge
599603
elseif craftMaxMass < 1 then
600-
craftMaxMass = Craft.Mass + 400 -- MaxMass not defined
604+
if Craft.ClassName == "ACDropship" then
605+
Craft = RandomACDropShip("Craft", 0) -- MaxMass not defined
606+
else
607+
Craft = RandomACRocket("Craft", 0) -- MaxMass not defined
608+
end
609+
craftMaxMass = Craft.MaxInventoryMass
601610
end
602611

603612
Craft.Team = self.CPUTeam
@@ -621,8 +630,11 @@ function BrainvsBrain:CreateMediumDrop(xPosLZ)
621630

622631
Craft:AddInventoryItem(Passenger)
623632

624-
-- Stop adding actors when exceeding the weight limit
625-
if Craft.Mass > craftMaxMass then
633+
local inventoryMass = 0;
634+
for item in Craft.Inventory do
635+
inventoryMass = inventoryMass + item.Mass;
636+
end -- Stop adding actors when exceeding the weight limit
637+
if inventoryMass > craftMaxMass then
626638
break
627639
end
628640
end
@@ -649,11 +661,16 @@ function BrainvsBrain:CreateLightDrop(xPosLZ)
649661

650662
if Craft then
651663
-- The max allowed weight of this craft plus cargo
652-
local craftMaxMass = Craft.MaxMass
664+
local craftMaxMass = Craft.MaxInventoryMass
653665
if craftMaxMass < 0 then
654666
craftMaxMass = math.huge
655667
elseif craftMaxMass < 1 then
656-
craftMaxMass = Craft.Mass + 400 -- MaxMass not defined
668+
if Craft.ClassName == "ACDropship" then
669+
Craft = RandomACDropShip("Craft", 0) -- MaxMass not defined
670+
else
671+
Craft = RandomACRocket("Craft", 0) -- MaxMass not defined
672+
end
673+
craftMaxMass = Craft.MaxInventoryMass
657674
end
658675

659676
Craft.Team = self.CPUTeam
@@ -675,8 +692,11 @@ function BrainvsBrain:CreateLightDrop(xPosLZ)
675692

676693
Craft:AddInventoryItem(Passenger)
677694

678-
-- Stop adding actors when exceeding the weight limit
679-
if Craft.Mass > craftMaxMass then
695+
local inventoryMass = 0;
696+
for item in Craft.Inventory do
697+
inventoryMass = inventoryMass + item.Mass;
698+
end -- Stop adding actors when exceeding the weight limit
699+
if inventoryMass > craftMaxMass then
680700
break
681701
end
682702
end
@@ -703,11 +723,16 @@ function BrainvsBrain:CreateScoutDrop(xPosLZ)
703723

704724
if Craft then
705725
-- The max allowed weight of this craft plus cargo
706-
local craftMaxMass = Craft.MaxMass
726+
local craftMaxMass = Craft.MaxInventoryMass
707727
if craftMaxMass < 0 then
708728
craftMaxMass = math.huge
709729
elseif craftMaxMass < 1 then
710-
craftMaxMass = Craft.Mass + 400 -- MaxMass not defined
730+
if Craft.ClassName == "ACDropship" then
731+
Craft = RandomACDropShip("Craft", 0) -- MaxMass not defined
732+
else
733+
Craft = RandomACRocket("Craft", 0) -- MaxMass not defined
734+
end
735+
craftMaxMass = Craft.MaxInventoryMass
711736
end
712737

713738
Craft.Team = self.CPUTeam
@@ -729,8 +754,11 @@ function BrainvsBrain:CreateScoutDrop(xPosLZ)
729754

730755
Craft:AddInventoryItem(Passenger)
731756

732-
-- Stop adding actors when exceeding the weight limit
733-
if Craft.Mass > craftMaxMass then
757+
local inventoryMass = 0;
758+
for item in Craft.Inventory do
759+
inventoryMass = inventoryMass + item.Mass;
760+
end -- Stop adding actors when exceeding the weight limit
761+
if inventoryMass > craftMaxMass then
734762
break
735763
end
736764
end
@@ -749,11 +777,12 @@ function BrainvsBrain:CreateBombDrop(bombPosX)
749777
local Craft = RandomACDropShip("Craft", self.CPUTechID) -- Pick a craft to deliver with
750778
if Craft then
751779
-- The max allowed weight of this craft plus cargo
752-
local craftMaxMass = Craft.MaxMass
780+
local craftMaxMass = Craft.MaxInventoryMass
753781
if craftMaxMass < 0 then
754782
craftMaxMass = math.huge
755783
elseif craftMaxMass < 1 then
756-
craftMaxMass = Craft.Mass + 400 -- MaxMass not defined
784+
Craft = RandomACDropShip("Craft", 0) -- MaxMass not defined
785+
craftMaxMass = Craft.MaxInventoryMass
757786
end
758787

759788
Craft.AIMode = Actor.AIMODE_BOMB -- DropShips open doors at a high altitude in bomb mode
@@ -763,8 +792,11 @@ function BrainvsBrain:CreateBombDrop(bombPosX)
763792
for _ = 1, math.random(3, 6) do
764793
Craft:AddInventoryItem(RandomTDExplosive("Bombs - Payloads", self.CPUTechID))
765794

766-
-- Stop adding bombs when exceeding the weight limit
767-
if Craft.Mass > craftMaxMass then
795+
local inventoryMass = 0;
796+
for item in Craft.Inventory do
797+
inventoryMass = inventoryMass + item.Mass;
798+
end -- Stop adding actors when exceeding the weight limit
799+
if inventoryMass > craftMaxMass then
768800
break
769801
end
770802
end

Base.rte/Activities/BunkerBreach.lua

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,12 @@ function BunkerBreach:CreateHeavyDrop(xPosLZ)
477477
local Craft = RandomACDropShip("Craft", self.CPUTechName) -- Pick a craft to deliver with
478478
if Craft then
479479
-- The max allowed weight of this craft plus cargo
480-
local craftMaxMass = Craft.MaxMass
480+
local craftMaxMass = Craft.MaxInventoryMass
481481
if craftMaxMass < 0 then
482482
craftMaxMass = math.huge
483483
elseif craftMaxMass < 1 then
484-
craftMaxMass = Craft.Mass + 400 -- MaxMass not defined
484+
Craft = RandomACDropShip("Craft", 0) -- MaxMass not defined
485+
craftMaxMass = Craft.MaxInventoryMass
485486
end
486487

487488
Craft.Team = self.CPUTeam
@@ -504,9 +505,13 @@ function BunkerBreach:CreateHeavyDrop(xPosLZ)
504505
end
505506

506507
Craft:AddInventoryItem(Passenger)
507-
508+
509+
local inventoryMass = 0;
510+
for item in Craft.Inventory do
511+
inventoryMass = inventoryMass + item.Mass;
512+
end
508513
-- Stop adding actors when exceeding the weight limit
509-
if Craft.Mass > craftMaxMass then
514+
if inventoryMass > craftMaxMass then
510515
break
511516
end
512517
end
@@ -531,11 +536,16 @@ function BunkerBreach:CreateMediumDrop(xPosLZ)
531536

532537
if Craft then
533538
-- The max allowed weight of this craft plus cargo
534-
local craftMaxMass = Craft.MaxMass
539+
local craftMaxMass = Craft.MaxInventoryMass
535540
if craftMaxMass < 0 then
536541
craftMaxMass = math.huge
537542
elseif craftMaxMass < 1 then
538-
craftMaxMass = Craft.Mass + 400 -- MaxMass not defined
543+
if Craft.ClassName == "ACDropship" then
544+
Craft = RandomACDropShip("Craft", 0) -- MaxMass not defined
545+
else
546+
Craft = RandomACRocket("Craft", 0) -- MaxMass not defined
547+
end
548+
craftMaxMass = Craft.MaxInventoryMass
539549
end
540550

541551
Craft.Team = self.CPUTeam
@@ -559,8 +569,11 @@ function BunkerBreach:CreateMediumDrop(xPosLZ)
559569

560570
Craft:AddInventoryItem(Passenger)
561571

562-
-- Stop adding actors when exceeding the weight limit
563-
if Craft.Mass > craftMaxMass then
572+
local inventoryMass = 0;
573+
for item in Craft.Inventory do
574+
inventoryMass = inventoryMass + item.Mass;
575+
end -- Stop adding actors when exceeding the weight limit
576+
if inventoryMass > craftMaxMass then
564577
break
565578
end
566579
end
@@ -585,11 +598,16 @@ function BunkerBreach:CreateLightDrop(xPosLZ)
585598

586599
if Craft then
587600
-- The max allowed weight of this craft plus cargo
588-
local craftMaxMass = Craft.MaxMass
601+
local craftMaxMass = Craft.MaxInventoryMass
589602
if craftMaxMass < 0 then
590603
craftMaxMass = math.huge
591604
elseif craftMaxMass < 1 then
592-
craftMaxMass = Craft.Mass + 400 -- MaxMass not defined
605+
if Craft.ClassName == "ACDropship" then
606+
Craft = RandomACDropShip("Craft", 0) -- MaxMass not defined
607+
else
608+
Craft = RandomACRocket("Craft", 0) -- MaxMass not defined
609+
end
610+
craftMaxMass = Craft.MaxInventoryMass
593611
end
594612

595613
Craft.Team = self.CPUTeam
@@ -611,8 +629,11 @@ function BunkerBreach:CreateLightDrop(xPosLZ)
611629

612630
Craft:AddInventoryItem(Passenger)
613631

614-
-- Stop adding actors when exceeding the weight limit
615-
if Craft.Mass > craftMaxMass then
632+
local inventoryMass = 0;
633+
for item in Craft.Inventory do
634+
inventoryMass = inventoryMass + item.Mass;
635+
end -- Stop adding actors when exceeding the weight limit
636+
if inventoryMass > craftMaxMass then
616637
break
617638
end
618639
end
@@ -637,11 +658,16 @@ function BunkerBreach:CreateScoutDrop(xPosLZ)
637658

638659
if Craft then
639660
-- The max allowed weight of this craft plus cargo
640-
local craftMaxMass = Craft.MaxMass
661+
local craftMaxMass = Craft.MaxInventoryMass
641662
if craftMaxMass < 0 then
642663
craftMaxMass = math.huge
643664
elseif craftMaxMass < 1 then
644-
craftMaxMass = Craft.Mass + 400 -- MaxMass not defined
665+
if Craft.ClassName == "ACDropship" then
666+
Craft = RandomACDropShip("Craft", 0) -- MaxMass not defined
667+
else
668+
Craft = RandomACRocket("Craft", 0) -- MaxMass not defined
669+
end
670+
craftMaxMass = Craft.MaxInventoryMass
645671
end
646672

647673
Craft.Team = self.CPUTeam
@@ -663,8 +689,12 @@ function BunkerBreach:CreateScoutDrop(xPosLZ)
663689

664690
Craft:AddInventoryItem(Passenger)
665691

692+
local inventoryMass = 0;
693+
for item in Craft.Inventory do
694+
inventoryMass = inventoryMass + item.Mass;
695+
end
666696
-- Stop adding actors when exceeding the weight limit
667-
if Craft.Mass > craftMaxMass then
697+
if inventoryMass > craftMaxMass then
668698
break
669699
end
670700
end

Base.rte/Activities/Harvester.lua

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,25 @@ function Harvester:UpdateActivity()
186186
ship = RandomACRocket("Any", self.CPUTechName);
187187
actorsInCargo = math.min(ship.MaxPassengers, 2)
188188
end
189+
190+
-- The max allowed weight of this craft plus cargo
191+
local shipMaxMass = ship.MaxMass
192+
if shipMaxMass < 0 then
193+
shipMaxMass = math.huge
194+
elseif shipMaxMass < 1 then
195+
if Craft.ClassName == "ACDropship" then
196+
DeleteEntity(ship);
197+
Craft = RandomACDropShip("Craft", 0) -- MaxMass not defined
198+
else
199+
DeleteEntity(ship)
200+
Craft = RandomACRocket("Craft", 0) -- MaxMass not defined
201+
end
202+
shipMaxMass = ship.MaxInventoryMass
203+
end
204+
local totalInventoryMass = 0
189205

190206
ship.Team = self.CPUTeam;
191-
207+
192208
-- Set the ship up with a cargo of a few armed and equipped actors
193209
for i = 1, actorsInCargo do
194210
-- Get any Actor from the CPU's native tech
@@ -211,9 +227,10 @@ function Harvester:UpdateActivity()
211227
passenger.Team = self.CPUTeam;
212228

213229
-- Check that we can afford to buy and to carry the weight of this passenger
214-
if ship:GetTotalValue(0,3) + passenger:GetTotalValue(0,3) <= self:GetTeamFunds(self.CPUTeam) and (ship.Mass + passenger.Mass) <= ship.MaxMass then
230+
if ship:GetTotalValue(0,3) + passenger:GetTotalValue(0,3) <= self:GetTeamFunds(self.CPUTeam) and (passenger.Mass + totalInventoryMass) <= shipMaxMass then
215231
-- Yes we can; so add it to the cargo hold
216232
ship:AddInventoryItem(passenger);
233+
totalInventoryMass = totalInventoryMass + passenger.Mass
217234
passenger = nil;
218235
else
219236
-- Nope; just delete the nixed passenger and stop adding new ones

Base.rte/Activities/Massacre.lua

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,22 @@ function Massacre:UpdateActivity()
184184
end
185185

186186
ship.Team = self.CPUTeam;
187+
188+
-- The max allowed weight of this craft plus cargo
189+
local shipMaxMass = ship.MaxMass
190+
if shipMaxMass < 0 then
191+
shipMaxMass = math.huge
192+
elseif shipMaxMass < 1 then
193+
if Craft.ClassName == "ACDropship" then
194+
DeleteEntity(ship);
195+
Craft = RandomACDropShip("Craft", 0) -- MaxMass not defined
196+
else
197+
DeleteEntity(ship)
198+
Craft = RandomACRocket("Craft", 0) -- MaxMass not defined
199+
end
200+
shipMaxMass = ship.MaxInventoryMass
201+
end
202+
local totalInventoryMass = 0
187203

188204
-- Set the ship up with a cargo of a few armed and equipped actors
189205
for i = 1, actorsInCargo do
@@ -207,9 +223,10 @@ function Massacre:UpdateActivity()
207223
passenger.Team = self.CPUTeam;
208224

209225
-- Check that we can afford to buy and to carry the weight of this passenger
210-
if ship:GetTotalValue(0,3) + passenger:GetTotalValue(0,3) <= self:GetTeamFunds(self.CPUTeam) and (ship.Mass + passenger.Mass) <= ship.MaxMass then
226+
if ship:GetTotalValue(0,3) + passenger:GetTotalValue(0,3) <= self:GetTeamFunds(self.CPUTeam) and (passenger.Mass + totalInventoryMass) <= shipMaxMass then
211227
-- Yes we can; so add it to the cargo hold
212228
ship:AddInventoryItem(passenger);
229+
totalInventoryMass = totalInventoryMass + passenger.Mass
213230
passenger = nil;
214231
else
215232
-- Nope; just delete the nixed passenger and stop adding new ones

0 commit comments

Comments
 (0)