-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathterran_controls.lua
180 lines (153 loc) · 5.39 KB
/
terran_controls.lua
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
---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by heyqule.
--- DateTime: 12/5/2024 12:33 AM
---
local String = require("__erm_libs__/stdlib/string")
local gui = require("__enemyracemanager__/gui/army_control_window")
local CustomAttacks = require("__erm_terran__/scripts/custom_attacks")
local RaceSettingsHelper = require("__enemyracemanager__/lib/helper/race_settings_helper")
local populations = {
["battlecruiser"] = 5,
["marine"] = 1,
["firebat"] = 1,
["ghost"] = 1,
["siege_tank"] = 3,
["wraith"] = 2,
["goliath"] = 2,
["valkyrie"] = 2,
["science_vessel"] = 2,
["vulture"] = 2,
['spidermine'] = 0,
}
local refresh_data = function()
-- Register Army Units
for _, prototype in pairs(prototypes.get_entity_filtered({{filter = "type", type = "unit"}})) do
local nameToken = String.split(prototype.name, "--")
if nameToken[1] == MOD_NAME and populations[nameToken[2]] then
remote.call("enemyracemanager","army_units_register", prototype.name, populations[nameToken[2]]);
end
end
-- Register Command Center
for _, prototype in pairs(prototypes.get_entity_filtered({{filter = "type", type = "radar"}})) do
local nameToken = String.split(prototype.name, "--")
if nameToken[1] == MOD_NAME then
remote.call("enemyracemanager","army_command_center_register", prototype.name);
end
end
-- Register Auto Deployers
for _, prototype in pairs(prototypes.get_entity_filtered({{filter = "type", type = "assembling-machine"}})) do
local nameToken = String.split(prototype.name, "--")
if nameToken[1] == MOD_NAME then
remote.call("enemyracemanager","army_deployer_register", prototype.name);
end
end
end
local addRaceSettings = function()
local race_settings = remote.call("enemyracemanager", "get_race", MOD_NAME)
if race_settings == nil then
race_settings = {}
end
race_settings.race = race_settings.race or MOD_NAME
race_settings.timed_units = {
spidermine=true,
}
RaceSettingsHelper.process_unit_spawn_rate_cache(race_settings)
remote.call("enemyracemanager", "register_race", race_settings)
-- reload local cache
CustomAttacks.get_race_settings(MOD_NAME, true)
end
local adjust_color = function(player_index)
local color = game.players[player_index].color
local max_strength = 0.5
if color.r > max_strength or color.g > max_strength or color.b > max_strength then
color.r = color.r * max_strength
color.g = color.g * max_strength
color.b = color.b * max_strength
end
local force = game.players[player_index].force
force.custom_color = color
end
local on_console_command = function(event)
if event.command == "color" and game.players[event.player_index].admin then
adjust_color(event.player_index)
end
end
local on_player_created = function(event)
if storage.new_color_change ~= false and game.players[event.player_index].admin then
adjust_color(event.player_index)
storage.new_color_change = true
end
end
local attack_functions = {
[SELF_DESTRUCT_ATTACK] = function(args)
CustomAttacks.process_self_destruct(args)
end,
[TIME_TO_LIVE_DIED] = function(args)
CustomAttacks.process_time_to_live_unit_died(args)
end,
[TIME_TO_LIVE_CREATED] = function(args)
CustomAttacks.process_time_to_live_unit_created(args)
end,
[GHOST_ATOMIC_SEQUENCE] = function(args)
CustomAttacks.add_nuke_to_queue(args)
end,
[CANCEL_GHOST_ATOMIC_SEQUENCE] = function(args)
CustomAttacks.cancel_nuke_from_queue(args)
end,
[BUNKER_SPAWN_MARINE] = function(args)
CustomAttacks.spawn_marine(args)
end,
[BUNKER_SPAWN_MARINE] = function(args)
CustomAttacks.spawn_marine(args)
end,
[ASTEROID_KILL] = function(args)
CustomAttacks.asteroid_aoe(args)
end
}
local on_script_trigger_effect = function(event)
if attack_functions[event.effect_id] and
(ASTEROID_KILL == event.effect_id or
CustomAttacks.valid(event, MOD_NAME)
)
then
attack_functions[event.effect_id](event)
end
end
local init_globals = function()
--- Used for ghost"s nuke launch tracking, data structure
--- storage.nuke_tracker[unit.unit_number] = {
--- entity = entity
--- launched_tick = event.tick
--- drawing = target_drawing
--- }
storage.nuke_tracker = storage.nuke_tracker or {}
storage.nuke_tracker_total = storage.nuke_tracker_total or 0
--- use for CustomAttack.asteroid_aoe
storage.asteroid_next_unit_check = storage.asteroid_next_unit_check or {}
end
local TerranControl = {}
TerranControl.on_init = function(event)
refresh_data()
addRaceSettings()
storage.new_color_change = false
init_globals()
end
TerranControl.on_configuration_changed = function(event)
refresh_data()
addRaceSettings()
init_globals()
end
TerranControl.events = {
---
--- Cap max color to belong 66% to avoid opaque color mask.
---
[defines.events.on_console_command] = on_console_command,
[defines.events.on_player_created] = on_player_created,
[defines.events.on_script_trigger_effect] = on_script_trigger_effect
}
TerranControl.on_nth_tick = {
[903] = CustomAttacks.clear_time_to_live_units,
[93] = CustomAttacks.spawn_nuke
}
return TerranControl