@@ -52,22 +52,38 @@ function BunkerBreach:StartActivity()
52
52
self .CPUSpawnTimer = Timer ();
53
53
self .CPUSpawnDelay = (40000 - self .difficultyRatio * 20000 ) * rte .SpawnIntervalScale ;
54
54
55
+ -- Set all actors in the scene to the defending team
55
56
for actor in MovableMan .AddedActors do
56
- -- Set all actors in the scene to the defending team
57
57
-- To-do: allow attackers to spawn near the brain?
58
58
if actor .Team ~= self .defenderTeam then
59
59
MovableMan :ChangeActorTeam (actor , self .defenderTeam );
60
60
end
61
61
end
62
- -- Add player brains
62
+
63
+ -- Clear wonky default scene launch text
63
64
for player = Activity .PLAYER_1 , Activity .MAXPLAYERCOUNT - 1 do
64
65
if self :PlayerActive (player ) and self :PlayerHuman (player ) then
65
- local team = self :GetTeamOfPlayer (player );
66
- local brain ;
67
- if team == self .attackerTeam then
68
- brain = self :CreateBrainBot (team );
66
+ FrameMan :ClearScreenText (self :ScreenOfPlayer (player ));
67
+ end
68
+ end
69
+
70
+ -- CPU team setup
71
+ if self .CPUTeam ~= - 1 then
72
+ self :SetTeamFunds (5000 * (0.5 + math.floor (self .difficultyRatio * 10 )/ 10 ), self .CPUTeam );
73
+ if (self .CPUTeam ~= self .defenderTeam ) then
74
+ self .CPUSpawnDelay = self .CPUSpawnDelay * 0.5 ;
75
+ end
76
+ self .playerTeam = self :OtherTeam (self .CPUTeam );
77
+ end
78
+
79
+
80
+ -- Add attacker brains for human attackers
81
+ if self .attackerTeam ~= self .CPUTeam then
82
+ for player = Activity .PLAYER_1 , Activity .MAXPLAYERCOUNT - 1 do
83
+ if self :PlayerActive (player ) and self :PlayerHuman (player ) and self :GetTeamOfPlayer (player ) == self .attackerTeam then
84
+ local attackingBrain = self :CreateBrainBot (self :GetTeamOfPlayer (player ));
85
+
69
86
local lzX = attackerLZ :GetRandomPoint ().X ;
70
-
71
87
if SceneMan .SceneWrapsX then
72
88
if lzX < 0 then
73
89
lzX = lzX + SceneMan .SceneWidth ;
@@ -77,87 +93,75 @@ function BunkerBreach:StartActivity()
77
93
else
78
94
lzX = math.max (math.min (lzX , SceneMan .SceneWidth - 50 ), 50 );
79
95
end
80
- brain .Pos = SceneMan :MovePointToGround (Vector (lzX , 0 ), brain .Radius * 0.5 , 3 );
81
- MovableMan :AddActor (brain );
96
+ attackingBrain .Pos = SceneMan :MovePointToGround (Vector (lzX , 0 ), attackingBrain .Radius * 0.5 , 3 );
82
97
83
- elseif team == self .defenderTeam then
84
- if SceneMan .Scene :HasArea (" Brain" ) then
85
- -- Remove any existing brains and prioritize the designated area
86
- for actor in MovableMan .Actors do
87
- if actor .Team == team and actor :IsInGroup (" Brains" ) then
88
- actor .ToDelete = true ;
89
- end
90
- end
91
- brain = self :CreateBrainBot (team );
92
- brain .Pos = SceneMan .Scene :GetOptionalArea (" Brain" ):GetCenterPoint ();
93
- MovableMan :AddActor (brain );
94
- else
95
- -- Look for brains among actors created by the deployments
96
- for actor in MovableMan .AddedActors do
97
- if actor .Team == team and actor :IsInGroup (" Brains" ) then
98
- if brain then
99
- actor .ToDelete = true ;
100
- else
101
- brain = actor ;
102
- end
103
- end
104
- end
105
- end
106
- self .defenderBrain = brain ;
98
+ MovableMan :AddActor (attackingBrain );
99
+ self :SetPlayerBrain (attackingBrain , player );
100
+ self :SetObservationTarget (attackingBrain .Pos , player );
101
+ self :SetLandingZone (attackingBrain .Pos , player );
107
102
end
108
- self :SetPlayerBrain (brain , player );
109
- self :SetObservationTarget (brain .Pos , player );
110
- self :SetLandingZone (brain .Pos , player );
111
103
end
112
104
end
113
105
114
- if self .CPUTeam ~= - 1 then
115
- self .CPUTechName = self :GetTeamTech (self .CPUTeam );
116
- self .CPUTechID = PresetMan :GetModuleID (self .CPUTechName );
117
- self :SetTeamFunds (5000 * (0.5 + math.floor (self .difficultyRatio * 10 )/ 10 ), self .CPUTeam );
118
- if self .CPUTeam == self .defenderTeam then
119
- local brain ;
120
- if SceneMan .Scene :HasArea (" Brain" ) then
121
- -- Remove any existing brains and prioritize the designated area
122
- for actor in MovableMan .Actors do
123
- if actor .Team == team and actor :IsInGroup (" Brains" ) then
124
- actor .ToDelete = true ;
125
- end
126
- end
127
- brain = self :CreateBrainBot (self .CPUTeam );
128
- brain .Pos = SceneMan .Scene :GetOptionalArea (" Brain" ):GetCenterPoint ();
129
- MovableMan :AddActor (brain );
130
- else
131
- -- Look for brains among actors created by the deployments
132
- for actor in MovableMan .AddedActors do
133
- if actor .Team == team and actor :IsInGroup (" Brains" ) then
134
- if brain then
135
- actor .ToDelete = true ;
136
- else
137
- brain = actor ;
138
- end
139
- end
106
+ -- Add defender brains, either using the Brain area or picking randomly from those created by deployments
107
+ if SceneMan .Scene :HasArea (" Brain" ) then
108
+ for actor in MovableMan .Actors do
109
+ if actor .Team == self .defenderTeam and actor :IsInGroup (" Brains" ) then
110
+ actor .ToDelete = true ;
111
+ end
112
+ end
113
+
114
+ self .defenderBrain = self :CreateBrainBot (self .defenderTeam );
115
+ self .defenderBrain .Pos = SceneMan .Scene :GetOptionalArea (" Brain" ):GetCenterPoint ();
116
+ MovableMan :AddActor (self .defenderBrain );
117
+ else
118
+ -- Pick the defender brain randomly from among those created by deployments, and delete the others and clean up some of their guards
119
+ local deploymentBrains = {};
120
+ for actor in MovableMan .AddedActors do
121
+ if actor .Team == self .defenderTeam and actor :IsInGroup (" Brains" ) then
122
+ deploymentBrains [# deploymentBrains + 1 ] = actor ;
123
+ end
124
+ end
125
+ local brainIndexToChoose = math.random (1 , # deploymentBrains );
126
+ self .defenderBrain = deploymentBrains [brainIndexToChoose ];
127
+ table.remove (deploymentBrains , brainIndexToChoose );
128
+
129
+ -- Delete brains that weren't the chosen one, and also randomly delete most of their guards
130
+ self .BrainChamber = SceneMan .Scene :GetOptionalArea (" Brain Chamber" );
131
+ for _ , unchosenDeploymentBrain in pairs (deploymentBrains ) do
132
+ unchosenDeploymentBrain .ToDelete = true ;
133
+ for actor in MovableMan .AddedActors do
134
+ if actor .Team == self .defenderTeam and math.random () < 0.75 and self .BrainChamber :IsInside (actor .Pos ) and (actor .ClassName == " AHuman" or actor .ClassName == " ACrab" ) and SceneMan :ShortestDistance (actor .Pos , self .defenderBrain .Pos , false ).Magnitude > 200 then
135
+ actor .ToDelete = true ;
140
136
end
141
137
end
142
- self .defenderBrain = brain ;
143
- else
144
- -- Start spawning attackers faster
145
- self .CPUSpawnDelay = self .CPUSpawnDelay * 0.5 ;
146
138
end
147
- self .playerTeam = self :OtherTeam (self .CPUTeam );
148
139
end
149
- --[[ To-do: figure out what this part is *actually* supposed to do
150
- if SceneMan.Scene:HasArea("Brain Chamber") then
151
- self.BrainChamber = SceneMan.Scene:GetOptionalArea("Brain Chamber");
152
- --Set all useless actors, i.e. those who should guard brain in the brain chamber but their brain is in another castle
153
- --to delete themselves, because otherwise they are most likely to stand there for the whole battle and waste MOs
154
- for actor in MovableMan.AddedActors do
155
- if not actor:HasObjectInGroup("Brains") and actor.Team == self.defenderTeam and self.BrainChamber:IsInside(actor.Pos) and (actor.ClassName == "AHuman" or actor.ClassName == "ACrab") then
156
- actor.ToDelete = true;
140
+
141
+ -- Make sure all human players have brains
142
+ if (self .defenderTeam ~= self .CPUTeam ) then
143
+ local playerDefenderBrainsAssignedCount = 0 ;
144
+ local brainToAssignToPlayer ;
145
+ for player = Activity .PLAYER_1 , Activity .MAXPLAYERCOUNT - 1 do
146
+ if self :PlayerActive (player ) and self :PlayerHuman (player ) and self :GetTeamOfPlayer (player ) == self .defenderTeam then
147
+ if playerDefenderBrainsAssignedCount == 0 then
148
+ brainToAssignToPlayer = self .defenderBrain ;
149
+ else
150
+ brainToAssignToPlayer = self :CreateBrainBot (self .defenderTeam );
151
+ brainToAssignToPlayer .Pos = self .defenderBrain .Pos + Vector (playerDefenderBrainsAssignedCount * 10 * self .defenderBrain .FlipFactor , 0 );
152
+ MovableMan :AddActor (brainToAssignToPlayer );
153
+ end
154
+
155
+ self :SwitchToActor (brainToAssignToPlayer , player , self .defenderTeam );
156
+ self :SetPlayerBrain (brainToAssignToPlayer , player );
157
+ self :SetObservationTarget (brainToAssignToPlayer .Pos , player );
158
+ self :SetLandingZone (brainToAssignToPlayer .Pos , player );
159
+
160
+ playerDefenderBrainsAssignedCount = playerDefenderBrainsAssignedCount + 1 ;
157
161
end
158
162
end
159
163
end
160
- ]] --
164
+
161
165
self .loadouts = {" Light" , " Heavy" , " Sniper" , " Engineer" , " Mecha" , " Turret" };
162
166
self .infantryLoadouts = {" Light" , " Heavy" , " Sniper" };
163
167
-- Add defending units in predefined areas
@@ -222,22 +226,26 @@ function BunkerBreach:UpdateActivity()
222
226
return
223
227
end
224
228
229
+ -- Check win conditions
225
230
if self .checkTimer :IsPastRealTimeLimit () then
226
- -- Check win conditions
227
231
self .checkTimer :Reset ();
228
232
229
233
if not MovableMan :IsActor (self .defenderBrain ) then
230
- local findBrain = MovableMan :GetUnassignedBrain (self .defenderTeam );
234
+ local findBrain = MovableMan :GetFirstBrainActor (self .defenderTeam );
231
235
if findBrain then
232
236
self .defenderBrain = findBrain ;
233
237
else
234
238
self .WinnerTeam = self .attackerTeam ;
235
- MovableMan :KillAllEnemyActors (self .attackerTeam );
239
+ for actor in MovableMan .Actors do
240
+ if actor .Team == self .defenderTeam then
241
+ actor .Status = Actor .INACTIVE ;
242
+ end
243
+ end
236
244
ActivityMan :EndActivity ();
237
245
return
238
246
end
239
247
else
240
- local players = 0 ;
248
+ local survivingAttackingPlayers = 0 ;
241
249
for player = Activity .PLAYER_1 , Activity .MAXPLAYERCOUNT - 1 do
242
250
if self :PlayerActive (player ) and self :PlayerHuman (player ) then
243
251
local team = self :GetTeamOfPlayer (player );
@@ -252,18 +260,23 @@ function BunkerBreach:UpdateActivity()
252
260
self :SetPlayerBrain (nil , player );
253
261
end
254
262
end
255
- if brain then
256
- players = players + 1 ;
263
+ if brain and team == self . attackerTeam and self . CPUTeam ~= self . attackerTeam then
264
+ survivingAttackingPlayers = survivingAttackingPlayers + 1 ;
257
265
self :SetObservationTarget (brain .Pos , player );
258
- else
266
+ elseif not brain then
259
267
self :ResetMessageTimer (player );
260
268
FrameMan :ClearScreenText (self :ScreenOfPlayer (player ));
261
269
FrameMan :SetScreenText (" Your brain has been destroyed!" , self :ScreenOfPlayer (player ), 2000 , - 1 , false );
262
270
end
263
271
end
264
272
end
265
- if players == 0 then
266
- self .WinnerTeam = self .CPUTeam ;
273
+ if self .CPUTeam ~= self .attackerTeam and survivingAttackingPlayers == 0 then
274
+ self .WinnerTeam = self .defenderTeam ;
275
+ for actor in MovableMan .Actors do
276
+ if actor .Team == self .attackerTeam then
277
+ actor .Status = Actor .INACTIVE ;
278
+ end
279
+ end
267
280
ActivityMan :EndActivity ();
268
281
return
269
282
end
@@ -358,7 +371,11 @@ function BunkerBreach:UpdateActivity()
358
371
end
359
372
end
360
373
elseif enemyCount < 1 then
361
- MovableMan :KillAllEnemyActors (self .playerTeam );
374
+ for actor in MovableMan .Actors do
375
+ if actor .Team ~= self .playerTeam then
376
+ actor .Status = Actor .INACTIVE ;
377
+ end
378
+ end
362
379
self .WinnerTeam = self .playerTeam ;
363
380
self :ClearObjectivePoints ();
364
381
ActivityMan :EndActivity ();
0 commit comments