Skip to content

Commit 7407650

Browse files
authored
Merge pull request #179 from cortex-command-community/balance-improvements
Balance improvements
2 parents 486f11a + fe5616b commit 7407650

15 files changed

+143
-332
lines changed

Data/Base.rte/Activities/BrainVsBrain.lua

Lines changed: 37 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ Add defender units by placing areas named:
1313
Activate fog of war during the build phase by adding areas:
1414
"Red Build Area" and "Green Build Area" where the players are allowed to build
1515
16-
17-
Don't place more doors and defenders and than the MOID limit can handle (a total of 16 defenders plus 4 doors equals about 144 of 255 avaliable IDs).
18-
1916
--]]
2017

2118
function BrainvsBrain:StartActivity(isNewGame)
@@ -474,20 +471,18 @@ function BrainvsBrain:UpdateActivity()
474471
self.spawnDelay = (40000 - self.Difficulty * 250) * rte.SpawnIntervalScale;
475472
end
476473

477-
if MovableMan:GetTeamMOIDCount(self.CPUTeam) < rte.AIMOIDMax * 3 / self:GetActiveCPUTeamCount() and MovableMan:IsActor(self.CPUBrain) then
478-
if obstacleHeight < 30 then
479-
self:CreateHeavyDrop(xPosLZ);
480-
elseif obstacleHeight < 90 then
481-
self:CreateMediumDrop(xPosLZ);
482-
elseif obstacleHeight < 180 then
483-
self:CreateLightDrop(xPosLZ);
484-
else
485-
self:CreateScoutDrop(xPosLZ);
474+
if obstacleHeight < 30 then
475+
self:CreateHeavyDrop(xPosLZ);
476+
elseif obstacleHeight < 90 then
477+
self:CreateMediumDrop(xPosLZ);
478+
elseif obstacleHeight < 180 then
479+
self:CreateLightDrop(xPosLZ);
480+
else
481+
self:CreateScoutDrop(xPosLZ);
486482

487-
-- This target is very difficult to reach: change target for the next attack
488-
self.AttackActor = nil;
489-
self.AttackPos = nil;
490-
end
483+
-- This target is very difficult to reach: change target for the next attack
484+
self.AttackActor = nil;
485+
self.AttackPos = nil;
491486
end
492487

493488
if self.AttackActor then
@@ -504,41 +499,36 @@ function BrainvsBrain:UpdateActivity()
504499
else
505500
self.AttackActor = nil;
506501

507-
if MovableMan:GetTeamMOIDCount(self.CPUTeam) < rte.AIMOIDMax * 3 / self:GetActiveCPUTeamCount() then
508-
-- Find an enemy actor to attack
509-
local Intruders = {};
510-
local intruder_tally = 0;
511-
for Act in MovableMan.Actors do
512-
if self.OnPlayerTeam[Act.Team] and (Act.ClassName == "AHuman" or Act.ClassName == "ACrab" or Act.ClassName == "Actor") and not SceneMan:IsUnseen(Act.Pos.X, Act.Pos.Y, self.CPUTeam) then
513-
local distance = 20 * (SceneMan:ShortestDistance(self.CPUBrain.Pos, Act.Pos, false).Largest / SceneMan.SceneWidth);
514-
table.insert(Intruders, {Act=Act, score=self.LZMap:SurfaceProximity(Act.Pos)+distance+math.random(300)});
515-
intruder_tally = intruder_tally + 1;
516-
end
502+
-- Find an enemy actor to attack
503+
local Intruders = {};
504+
local intruder_tally = 0;
505+
for Act in MovableMan.Actors do
506+
if self.OnPlayerTeam[Act.Team] and (Act.ClassName == "AHuman" or Act.ClassName == "ACrab" or Act.ClassName == "Actor") and not SceneMan:IsUnseen(Act.Pos.X, Act.Pos.Y, self.CPUTeam) then
507+
local distance = 20 * (SceneMan:ShortestDistance(self.CPUBrain.Pos, Act.Pos, false).Largest / SceneMan.SceneWidth);
508+
table.insert(Intruders, {Act=Act, score=self.LZMap:SurfaceProximity(Act.Pos)+distance+math.random(300)});
509+
intruder_tally = intruder_tally + 1;
517510
end
511+
end
518512

519-
if intruder_tally < 1 then
520-
self.spawnTimer:Reset();
521-
self.spawnDelay = 10000;
522-
else
523-
table.sort(Intruders, function(A, B) return A.score > B.score end); -- the nearest intruder last
524-
self.AttackActor = table.remove(Intruders).Act;
525-
self.AttackPos = Vector(self.AttackActor.Pos.X, self.AttackActor.Pos.Y);
526-
527-
528-
-- try bombing if no targets close to CPU brain
529-
if math.random() < self.bombChance and (SceneMan:ShortestDistance(self.CPUBrain.Pos, self.AttackPos, false).Largest/SceneMan.SceneWidth) > 0.2 then
530-
local bombPosX = self.LZMap:FindBombTarget(self.CPUTeam);
531-
if bombPosX then
532-
self.spawnTimer:Reset();
533-
self.spawnDelay = (10000 - self.Difficulty * 70) * rte.SpawnIntervalScale;
534-
self.bombChance = math.max(self.bombChance*0.9, 0.05);
535-
self:CreateBombDrop(bombPosX);
536-
end
537-
end
538-
end
539-
else
513+
if intruder_tally < 1 then
540514
self.spawnTimer:Reset();
541515
self.spawnDelay = 10000;
516+
else
517+
table.sort(Intruders, function(A, B) return A.score > B.score end); -- the nearest intruder last
518+
self.AttackActor = table.remove(Intruders).Act;
519+
self.AttackPos = Vector(self.AttackActor.Pos.X, self.AttackActor.Pos.Y);
520+
521+
522+
-- try bombing if no targets close to CPU brain
523+
if math.random() < self.bombChance and (SceneMan:ShortestDistance(self.CPUBrain.Pos, self.AttackPos, false).Largest/SceneMan.SceneWidth) > 0.2 then
524+
local bombPosX = self.LZMap:FindBombTarget(self.CPUTeam);
525+
if bombPosX then
526+
self.spawnTimer:Reset();
527+
self.spawnDelay = (10000 - self.Difficulty * 70) * rte.SpawnIntervalScale;
528+
self.bombChance = math.max(self.bombChance*0.9, 0.05);
529+
self:CreateBombDrop(bombPosX);
530+
end
531+
end
542532
end
543533
end
544534
end

Data/Base.rte/Activities/Harvester.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ function Harvester:UpdateActivity()
214214
end
215215

216216
--Spawn the AI.
217-
if self.CPUTeam ~= Activity.NOTEAM and self.enemySpawnTimer:LeftTillSimMS(self.enemySpawnTimeLimit) <= 0 and MovableMan:GetTeamMOIDCount(self.CPUTeam) <= rte.AIMOIDMax * 3 / self:GetActiveCPUTeamCount() then
217+
if self.CPUTeam ~= Activity.NOTEAM and self.enemySpawnTimer:LeftTillSimMS(self.enemySpawnTimeLimit) <= 0 then
218218
local ship, actorsInCargo;
219219

220220
if math.random() < 0.5 then

Data/Base.rte/Activities/KeepieUppie.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function KeepieUppie:UpdateActivity()
188188
end
189189

190190
--Spawn the AI.
191-
if self.CPUTeam ~= Activity.NOTEAM and self.enemySpawnTimer:LeftTillSimMS(self.enemySpawnTimeLimit) <= 0 and MovableMan:GetTeamMOIDCount(self.CPUTeam) <= rte.AIMOIDMax * 3 / self:GetActiveCPUTeamCount() then
191+
if self.CPUTeam ~= Activity.NOTEAM and self.enemySpawnTimer:LeftTillSimMS(self.enemySpawnTimeLimit) <= 0 then
192192
local ship, actorsInCargo;
193193

194194
if math.random() < 0.5 then

Data/Base.rte/Activities/Massacre.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ function Massacre:UpdateActivity()
210210
end
211211

212212
--Spawn the AI.
213-
if self.CPUTeam ~= Activity.NOTEAM and self.enemySpawnTimer:LeftTillSimMS(self.enemySpawnTimeLimit) <= 0 and MovableMan:GetTeamMOIDCount(self.CPUTeam) <= rte.AIMOIDMax * 3 / self:GetActiveCPUTeamCount() then
213+
if self.CPUTeam ~= Activity.NOTEAM and self.enemySpawnTimer:LeftTillSimMS(self.enemySpawnTimeLimit) <= 0 then
214214
local ship, actorsInCargo;
215215

216216
if math.random() < 0.5 then

Data/Base.rte/Activities/MetaFight.lua

Lines changed: 16 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ function MetaFight:StartActivity()
297297
-- Store initial defender team funds to prevent from overflow caused by AI gold cheat
298298
self.DefenderTeamInitialFunds = self:GetTeamFunds(defenderTeam);
299299

300-
-- Find out NativeCostMultiplier for defenders, it will be used when we'll have to sell excess actors if MOID limit was reached
300+
-- Find out NativeCostMultiplier for defenders, it will be used when we'll have to sell excess actors
301301
for metaPlayer = Activity.PLAYER_1, MetaMan.PlayerCount - 1 do
302302
if MetaMan:GetPlayer(metaPlayer).InGamePlayer == player then
303303
defenderTeamNativeCostMultiplier = MetaMan:GetPlayer(metaPlayer).NativeCostMultiplier;
@@ -531,8 +531,6 @@ function MetaFight:StartActivity()
531531
self.AI.AttackTarget = {};
532532
self.AI.AttackPos = {};
533533
self.AI.Defender = {};
534-
535-
self.AI.MOIDLimit = rte.AIMOIDMax * 3 / #CPUTeams;
536534
end
537535

538536
-- Clear data about actors controlled by external scripts. If scripts are active they'll grab their actors back
@@ -544,123 +542,6 @@ function MetaFight:StartActivity()
544542
for actor in MovableMan.AddedActors do
545543
actor:RemoveStringValue("ScriptControlled");
546544
end
547-
548-
-- Enforce the MOID limit by deleting and refunding native actors
549-
if defenderTeam then
550-
self.hasDefender = true;
551-
552-
-- Estimate the total MOIDFootprint of the defender's actors
553-
local defenderMOID = 0;
554-
for Act in MovableMan.AddedActors do
555-
if Act.ClassName == "ADoor" then
556-
--defenderMOID = defenderMOID + 2;
557-
elseif Act.Team == defenderTeam then
558-
defenderMOID = defenderMOID + 8;
559-
end
560-
end
561-
562-
-- Make sure there are enough free MOIDs to land AI units
563-
local ids = defenderMOID - rte.DefenderMOIDMax;
564-
if ids > 0 then
565-
local Prune = {};
566-
for Item in MovableMan.AddedItems do
567-
--table.insert(Prune, {MO=Item, score=Item:GetGoldValue(0, 1, defenderTeamNativeCostMultiplier)*0.5});
568-
table.insert(Prune, {MO=Item, score=0}); -- Let's try to always remove weapons if we need MOIDs
569-
end
570-
571-
for Act in MovableMan.AddedActors do
572-
if not Act:HasObjectInGroup("Brains") and not IsADoor(Act) then
573-
local value = Act:GetTotalValue(0, 1, defenderTeamNativeCostMultiplier);
574-
if Act.PlacedByPlayer == Activity.PLAYER_NONE then
575-
value = value * 0.5; -- This actor is left-over from previous battles
576-
end
577-
578-
-- Further reduce value if actors are damaged
579-
value = value * Act.Health/Act.MaxHealth;
580-
581-
-- Reduce value if actors are out of base
582-
if self.MetabaseArea then
583-
if not self.MetabaseArea:IsInside(Act.Pos) then
584-
value = value * 0.25;
585-
end
586-
end
587-
588-
-- Crippled actors and actors without weapons are first candidates to be removed
589-
if IsAHuman(Act) then
590-
local human = ToAHuman(Act);
591-
if human then
592-
local limbs = {human.FGArm, human.BGArm, human.FGLeg, human.BGLeg};
593-
for _, limb in pairs(limbs) do
594-
if limb == nil then
595-
value = value * 0.5;
596-
end
597-
end
598-
599-
if human:IsInventoryEmpty() and human.EquippedItem == nil and human.EquippedBGItem == nil then
600-
value = value * 0.5;
601-
end
602-
end
603-
end
604-
605-
-- Always remove crafts, left from previous battles
606-
if IsACRocket(Act) or IsACDropShip(Act) then
607-
value = 0;
608-
end
609-
610-
table.insert(Prune, {MO=Act, score=value});
611-
end
612-
end
613-
614-
-- Sort the table so we delete the cheapest object first
615-
table.sort(Prune, function(A, B) return A.score > B.score end);
616-
617-
local count = 0;
618-
local gold = 0;
619-
local badcount = 0;
620-
while true do
621-
local Object = table.remove(Prune);
622-
if Object then
623-
-- Stop if we have freed enough MOIDs and removed all 'bad' objects.
624-
if ids < 0 and Object.score > 0 then
625-
break;
626-
end
627-
628-
local MO = Object.MO;
629-
if MO:IsDevice() then
630-
ids = ids - 1;
631-
MO.ToDelete = true;
632-
count = count + 1;
633-
if Object.score == 0 then
634-
badcount = badcount + 1;
635-
end
636-
else
637-
-- deleting actors cause a crash -- weegee: No longer
638-
-- MO.Health = 0;
639-
MO.ToDelete = true;
640-
if MO.ClassName == "ADoor" then
641-
ids = ids - 2;
642-
else
643-
ids = ids - 8;
644-
end
645-
count = count + 1;
646-
if Object.score == 0 then
647-
badcount = badcount + 1;
648-
end
649-
end
650-
651-
gold = gold + MO:GetTotalValue(0, 1, defenderTeamNativeCostMultiplier);
652-
else
653-
break;
654-
end
655-
end
656-
657-
if (SettingsMan.PrintDebugInfo) then
658-
print ("DEBUG: Objects removed: "..count.." [ "..badcount.." ] - " .. gold.. "oz of gold refunded");
659-
end
660-
661-
self:ChangeTeamFunds(gold, defenderTeam); -- Refund the objects
662-
end
663-
end
664545
end
665546

666547
---------------------------------------------------------
@@ -1117,37 +998,30 @@ function MetaFight:UpdateActivity()
1117998
activeAITeams = activeAITeams + 1;
1118999
end
11191000
end
1120-
1121-
self.AI.MOIDLimit = rte.AIMOIDMax * 3 / activeAITeams;
11221001
end
11231002

11241003
if self.AI.spawnForPlayer then
11251004
local team = self:GetTeamOfPlayer(self.AI.spawnForPlayer);
11261005

1127-
if MovableMan:GetTeamMOIDCount(team) > self.AI.MOIDLimit then
1128-
self.AI.SpawnTimer:SetSimTimeLimitMS(2000);
1006+
if self:SearchLZ(self.AI.spawnForPlayer) then -- returns true when the search is complete. may or may not spawn a unit
11291007
self.AI.SpawnTimer:Reset();
1130-
else
1131-
if self:SearchLZ(self.AI.spawnForPlayer) then -- returns true when the search is complete. may or may not spawn a unit
1132-
self.AI.SpawnTimer:Reset();
1133-
1134-
-- find the next AI team (if any)
1135-
local oldPlayer = self.AI.spawnForPlayer;
1136-
self.AI.spawnForPlayer = nil;
1137-
for player = Activity.PLAYER_1, Activity.MAXPLAYERCOUNT - 1 do
1138-
if player > oldPlayer then
1139-
if self:PlayerActive(player) and not self:PlayerHuman(player) and self:GetPlayerBrain(player) and self.TeamAIActive[self:GetTeamOfPlayer(player)] then
1140-
self.AI.spawnForPlayer = player;
1141-
break;
1142-
end
1008+
1009+
-- find the next AI team (if any)
1010+
local oldPlayer = self.AI.spawnForPlayer;
1011+
self.AI.spawnForPlayer = nil;
1012+
for player = Activity.PLAYER_1, Activity.MAXPLAYERCOUNT - 1 do
1013+
if player > oldPlayer then
1014+
if self:PlayerActive(player) and not self:PlayerHuman(player) and self:GetPlayerBrain(player) and self.TeamAIActive[self:GetTeamOfPlayer(player)] then
1015+
self.AI.spawnForPlayer = player;
1016+
break;
11431017
end
11441018
end
1019+
end
11451020

1146-
if self.AI.spawnForPlayer then
1147-
self.AI.SpawnTimer:SetSimTimeLimitMS(1000);
1148-
else -- all AI teams have spawned, wait a little longer before we try to spawn troops again
1149-
self.AI.SpawnTimer:SetSimTimeLimitMS(6000);
1150-
end
1021+
if self.AI.spawnForPlayer then
1022+
self.AI.SpawnTimer:SetSimTimeLimitMS(1000);
1023+
else -- all AI teams have spawned, wait a little longer before we try to spawn troops again
1024+
self.AI.SpawnTimer:SetSimTimeLimitMS(6000);
11511025
end
11521026
end
11531027
else

Data/Base.rte/Activities/OneManArmy.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,9 @@ function OneManArmy:UpdateActivity()
298298
end
299299
end
300300
end
301-
local enemyMOIDCount = MovableMan:GetTeamMOIDCount(self.CPUTeam);
301+
302302
--Spawn the AI
303-
if self.CPUTeam ~= Activity.NOTEAM and self.enemySpawnTimer:LeftTillSimMS(self.enemySpawnTimeLimit) <= 0 and enemyMOIDCount < rte.AIMOIDMax then
303+
if self.CPUTeam ~= Activity.NOTEAM and self.enemySpawnTimer:LeftTillSimMS(self.enemySpawnTimeLimit) <= 0 and then
304304
local ship, actorsInCargo;
305305

306306
if math.random() < 0.5 then
@@ -415,7 +415,7 @@ function OneManArmy:UpdateActivity()
415415
end
416416

417417
self.enemySpawnTimer:Reset();
418-
self.enemySpawnTimeLimit = (self.baseSpawnTime * (1 + enemyMOIDCount * 0.1) + math.random(self.baseSpawnTime)) * rte.SpawnIntervalScale;
418+
self.enemySpawnTimeLimit = (self.baseSpawnTime + math.random(self.baseSpawnTime)) * rte.SpawnIntervalScale;
419419
end
420420
end
421421
end

Data/Base.rte/Activities/OneManArmyDiggers.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@ function OneManArmy:UpdateActivity()
267267
end
268268

269269
--Spawn the AI.
270-
if self.CPUTeam ~= Activity.NOTEAM and self.enemySpawnTimer:LeftTillSimMS(self.enemySpawnTimeLimit) <= 0 and MovableMan:GetTeamMOIDCount(self.CPUTeam) <= rte.AIMOIDMax * 3 / self:GetActiveCPUTeamCount() then
271-
270+
if self.CPUTeam ~= Activity.NOTEAM and self.enemySpawnTimer:LeftTillSimMS(self.enemySpawnTimeLimit) <= 0 then
272271
-- Set up the ship to deliver this stuff
273272
local ship = RandomACRocket("Any", self.CPUTechName);
274273
local actorsInCargo = math.min(ship.MaxPassengers, 2);

Data/Base.rte/Activities/OneManArmyZeroG.lua

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,7 @@ function OneManArmyZeroG:UpdateActivity()
340340
end
341341
end
342342

343-
local enemyMOIDCount = MovableMan:GetTeamMOIDCount(self.CPUTeam);
344-
if self.CPUTeam ~= Activity.NOTEAM and self.enemySpawnTimer:LeftTillSimMS(self.enemySpawnTimeLimit) <= 0 and enemyMOIDCount < rte.AIMOIDMax then
343+
if self.CPUTeam ~= Activity.NOTEAM and self.enemySpawnTimer:LeftTillSimMS(self.enemySpawnTimeLimit) <= 0 then
345344
for i = 1, math.random(1, 3) do
346345
local actor = RandomAHuman("Actors - Light", self.CPUTechName);
347346
if actor.ModuleID ~= PresetMan:GetModuleID(self.CPUTechName) then
@@ -368,8 +367,7 @@ function OneManArmyZeroG:UpdateActivity()
368367
end
369368

370369
self.enemySpawnTimer:Reset();
371-
local enemyMoidCountSpawnTimeMultiplier = self.isDiggersOnly and 1 or (1 + enemyMOIDCount * 0.05);
372-
self.enemySpawnTimeLimit = ((self.baseSpawnTime * enemyMoidCountSpawnTimeMultiplier) + math.random(self.baseSpawnTime)) * rte.SpawnIntervalScale;
370+
self.enemySpawnTimeLimit = (self.baseSpawnTime + math.random(self.baseSpawnTime)) * rte.SpawnIntervalScale;
373371
end
374372
end
375373
end

0 commit comments

Comments
 (0)