This repository was archived by the owner on Jan 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfantry-mod.lua
More file actions
392 lines (334 loc) · 12.4 KB
/
infantry-mod.lua
File metadata and controls
392 lines (334 loc) · 12.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
-- OpenRA: Red Alert - InfantryMod v1.0.0-beta.1
-- Created by xy - March 2017
-- Check for new releases on https://github.com/xy2z/OpenRA.InfantryMod
--
-- Feel free to make your own InfantryMod map,
-- just add the rules.yaml and infantry-mod.lua files to your map.
-- Variables
points_to_win = 0
count_tick = 0
players = nil
teams = {}
objective_oil = {}
count_players = 0
count_teams = 0
game_completed = false
dead_players = {}
Team1ID = nil
Team1Players = {}
team1_controls = 0
team1_points = 0.0
Team2ID = nil
Team2Players = {}
team2_controls = 0
team2_points = 0.0
-- Variables for Oil derricks
all_oil_derricks = {}
-- Custom functions
function set_winner_team(team_id)
game_completed = true
Media.DisplayMessage("Congratulations to Team " .. team_id)
if team_id == Team1ID then
winner_team_players = Team1Players
else
winner_team_players = Team2Players
end
-- Go through all players in the team.
for key, player in pairs(players) do
if not player.IsNonCombatant then
-- Actual player (not a creep/neutral)
-- if player.Team == team_id then
if winner_team_players[player.InternalName] then
-- Media.DisplayMessage("Debug: Mission COMPLETED for: " .. player.Name .. " (Team " .. player.Team .. ") (objective_oil ID: " .. objective_oil[player.InternalName] .. ")")
player.MarkCompletedObjective(objective_oil[player.InternalName])
else
-- Mission failed.
-- Media.DisplayMessage("Debug: Mission failed for: " .. player.Name .. " (Team " .. player.Team .. ") (objective_oil ID: " .. objective_oil[player.InternalName] .. ")")
player.MarkFailedObjective(objective_oil[player.InternalName])
end
end
end
end
function round_decimals(number, digits)
shift = 10 ^ digits
return math.floor( number * shift + 0.5 ) / shift
end
-- Welcome message + Triggers
WorldLoaded = function()
players = Player.GetPlayers(nil)
-- Briefing
Media.DisplayMessage("Welcome Commanders!")
Media.DisplayMessage("Get points by capturing and controlling oil derricks.")
-- Media.DisplayMessage("Debug: Found " .. count_oil_derricks .. " oil derricks")
-- Get all oil derricks
neutral_player = Player.GetPlayer('Neutral')
all_oil_derricks = neutral_player.GetActorsByType('oilb')
-- all_oil_derricks = { Actor11, Actor15, Actor18, Actor19, Actor20, Actor32, Actor38 }
count_oil_derricks = 0
-- for key, oil in pairs(all_oil_derricks) do
Utils.Do(all_oil_derricks, function(actor)
-- Media.DisplayMessage("Found oil derrick")
count_oil_derricks = count_oil_derricks + 1
end)
-- Count players. Because if there's only 2 players teams doesn't need to be set.
for key, player in pairs(players) do
if not player.IsNonCombatant then
-- Add primary objective
objective_oil[player.InternalName] = player.AddPrimaryObjective("Capture oil derricks and get points to win.")
-- Count total players
count_players = count_players + 1
end
end
-- Set teams.
if count_players == 2 then
-- Teams doesn't matter if there's only 2 players (so players doesn't have to select team)
Team1ID = 1
Team2ID = 2
count_teams = 2
local i = 0
for key, player in pairs(players) do
if not player.IsNonCombatant then
i = i + 1
if i == 1 then
-- Media.DisplayMessage("1v1: Added player to team1: " .. player.Name .. " / " .. player.InternalName)
Team1Players[player.InternalName] = player
else
-- Media.DisplayMessage("1v1: Added player to team2: " .. player.Name .. " / " .. player.InternalName)
Team2Players[player.InternalName] = player
end
end
end
else
-- More than 2 players.
for key, player in pairs(players) do
if not player.IsNonCombatant then
-- Media.DisplayMessage("Debug: Objective added for " .. player.Name .. " id: " .. objective_oil[player.InternalName] .. " (InternalName: " .. player.InternalName .. ")")
if player.Team == 0 then
Media.DisplayMessage("Warning: Player is not assigned to any team: " .. player.Name)
end
-- Add the team to teams array/table.
if teams[player.Team] == nil then
count_teams = count_teams + 1
teams[player.Team] = 1
-- Set Team ID's
if Team1ID == nil then
Team1ID = player.Team
-- Media.DisplayMessage("Debug: Set Team1ID to " .. player.Team)
else
Team2ID = player.Team
-- Media.DisplayMessage("Debug: Set Team2ID to " .. player.Team)
end
end
-- Add team players
if player.Team == Team1ID then
Team1Players[player.InternalName] = player
-- Media.DisplayMessage("Debug: Team1Players: " .. player.Name)
elseif player.Team == Team2ID then
Team2Players[player.InternalName] = player
-- Media.DisplayMessage("Debug: Team2Players: " .. player.Name)
end
end
end
-- Check there's exactly 2 teams.
if not count_teams == 2 then
Media.DisplayMessage("Warning: There should be exactly 2 teams for this map to work. There's " .. count_teams .. " teams.")
end
-- Fix if no teams are set (so script doesn't crash)
if Team1ID == nil then
-- Media.DisplayMessage("Debug: Set Team1ID to 1 (was nil)")
Team1ID = 1
end
if Team2ID == nil then
-- Media.DisplayMessage("Debug: Set Team1ID to 2 (was nil)")
Team2ID = 2
end
end
-- Set points to win
points_to_win = 30 -- 1v1
if count_players >= 10 then
-- 5v5 or more.
points_to_win = 50
elseif count_players >= 8 then
-- 4v4
points_to_win = 45
elseif count_players >= 6 then
-- 3v3
points_to_win = 40
elseif count_players >= 4 then
-- 2v2
points_to_win = 35
end
-- Show points to win
if count_players == 2 then
Media.DisplayMessage("The first player to get " .. points_to_win .. " points wins! ")
else
Media.DisplayMessage("The first team to get " .. points_to_win .. " points wins! ")
end
-- Media.DisplayMessage("Debug: Team1 ID: " .. Team1ID)
-- Media.DisplayMessage("Debug: Team2 ID: " .. Team2ID)
-- Trigger for when barracks is killed/captured.
all_barracks = {}
Utils.Do(players, function(player)
if not player.IsNonCombatant then
-- all_barracks[player.InternalName] = player.GetActorsByType('barr')
tent = player.GetActorsByType('tent')
-- Media.DisplayMessage("DEBUG: Loaded barracks from player: " .. player.InternalName)
-- When barracks is destroyed or captured, or player surrendered.
Trigger.OnAllKilledOrCaptured(tent, function()
if game_completed then
do return end
end
-- Media.DisplayMessage('DEBUG: OnAllKilledOrCaptured from ' .. player.InternalName)
-- player.alive = false
dead_players[player.InternalName] = true
-- Get the players team players and check if all are dead.
all_players_in_team_dead = true
if count_players > 2 then
Utils.Do(players, function(team_player)
if not team_player.IsNonCombatant and team_player.Team == player.Team and not dead_players[team_player.InternalName] then
all_players_in_team_dead = false
-- Media.DisplayMessage("Debug: Team is not dead yet! Player is still alive: " .. team_player.Name)
end
end)
end
-- All players in the team are dead.
if all_players_in_team_dead then
-- Opposite team wins.
winner_team_id = 0
if player.Team == Team1ID then
winner_team_id = Team2ID
else
winner_team_id = Team1ID
end
set_winner_team(winner_team_id)
end
end)
end
end)
-- Triggers for oil derricks
-- for key, actor in pairs(all_oil_derricks) do
Utils.Do(all_oil_derricks, function(actor)
Trigger.OnCapture(actor, function(self, captor, oldOwner, newOwner)
if newOwner.Team == 0 then
Media.DisplayMessage(newOwner.Name .. " captured an oil derrick!")
else
Media.DisplayMessage(newOwner.Name .. " (Team " .. newOwner.Team .. ") captured an oil derrick!")
end
-- if newOwner.Team == Team1ID then
if Team1Players[newOwner.InternalName] then
-- Team 1 captured it.
team1_controls = team1_controls + 1
if Team2Players[oldOwner.InternalName] then
team2_controls = team2_controls - 1
end
else
-- Team 2 captured it.
team2_controls = team2_controls + 1
if Team1Players[oldOwner.InternalName] then
team1_controls = team1_controls - 1
end
end
end)
-- Oil derrick destroyed
Trigger.OnKilled(actor, function(self, killer)
if game_completed then
do return end
end
Media.DisplayMessage("An oil derrick has been destroyed!")
if self.Owner.InternalName == 'Neutral' then
-- Media.DisplayMessage("DEBUG: Oil derrick was not controlled by anyone!")
do return end
end
-- Minus 1 control point for the team who controlled the oil derrick.
-- if self.Owner.Team == Team1ID then
if Team1Players[self.Owner.InternalName] then
-- Team 1 lost an oil derrick.
-- Media.DisplayMessage("DEBUG: Oil derrick was controlled by " .. Team1ID)
team1_controls = team1_controls - 1
else
-- Team 2 lost an oil derrick.
-- Media.DisplayMessage("DEBUG: Oil derrick was controlled by " .. Team2ID)
team2_controls = team2_controls - 1
end
end)
end)
-- If all oil derricks are killed. Team with most points wins.
Trigger.OnAllKilled(all_oil_derricks, function()
if game_completed then
do return end
end
Media.DisplayMessage("All oil derricks have been destroyed! Team with most points wins.")
-- Media.DisplayMessage("DEBUG: team1: " .. team1_points .. " and team2: " .. team2_points)
if team1_points == team2_points then
-- Media.DisplayMessage("It's a draw! Points are equal.")
for key, player in pairs(players) do
if not player.IsNonCombatant then
player.MarkFailedObjective(objective_oil[player.InternalName])
end
end
elseif team1_points > team2_points then
-- Media.DisplayMessage("DEBUG: Team " .. Team1ID .. " wins with " .. team1_points .. " points! Congratulations! Team1ID")
set_winner_team(Team1ID)
else
-- Media.DisplayMessage("DEBUG: Team " .. Team2ID .. " wins with " .. team2_points .. " points! Congratulations! Team2ID")
set_winner_team(Team2ID)
end
end)
end
-- Count points for controlled oil derricks.
-- Show points status.
Tick = function()
-- Count points for captured oil derricks.
count_tick = count_tick + 1
if count_tick == 500 then
count_tick = 0 -- Reset tick counter
-- team1_points = team1_points + team1_controls
-- team2_points = team2_points + team2_controls
-- Count points: Loop through all oil derricks to see who controls it.
-- Utils.Do(all_oil_derricks, function(actor)
-- if not actor.IsDead and not actor.Owner.IsNonCombatant then
-- -- Media.DisplayMessage("Tick: Oil derrick belongs to " .. actor.Owner.Name .. " - Team " .. actor.Owner.Team)
-- -- if actor.Owner.Team == Team1ID then
-- if Team1Players[actor.Owner.InternalName] then
-- -- Team 1
-- team1_points = team1_points + 1
-- else
-- -- Team 2
-- team2_points = team2_points + 1
-- end
-- end
-- end)
-- Give points
team1_points = team1_points + round_decimals(round_decimals(team1_controls / count_oil_derricks, 1) * 1.5, 1)
team2_points = team2_points + round_decimals(round_decimals(team2_controls / count_oil_derricks, 1) * 1.5, 1)
-- Media.DisplayMessage("team1_points: " .. team1_points .. " AND team2_points: " .. team2_points)
-- Check if we have a winner.
if round_decimals(team1_points, 0) >= points_to_win then
-- Media.DisplayMessage("Congratulations to Team " .. Team1ID .. "!")
set_winner_team(Team1ID)
elseif round_decimals(team2_points, 0) >= points_to_win then
-- Media.DisplayMessage("Congratulations to Team " .. Team2ID .. "!")
set_winner_team(Team2ID)
end
-- Show status
if team1_points > 0 or team2_points > 0 then
if count_players == 2 then
-- Get player names.
local team1player_name
local team2player_name = 0
for key, player in pairs(Team1Players) do
team1player_name = player.Name
-- Media.DisplayMessage("Debug: Get player1 name: " .. team1player_name)
end
for key, player in pairs(Team2Players) do
team2player_name = player.Name
-- Media.DisplayMessage("Debug: Get player2 name: " .. team2player_name)
end
Media.DisplayMessage("STATUS: " .. team1player_name .. ": " .. round_decimals(team1_points, 0) .. "/" .. points_to_win .. " points | " .. team2player_name .. ": " .. round_decimals(team2_points, 0) .. "/" .. points_to_win .. " points.")
else
-- Teams (over 2 players)
Media.DisplayMessage("STATUS: Team " .. Team1ID .. ": " .. round_decimals(team1_points, 0) .. "/" .. points_to_win .. " points | Team " .. Team2ID .. ": " .. round_decimals(team2_points, 0) .. "/" .. points_to_win .. " points.")
end
end
end
end