-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcontrol.lua
More file actions
49 lines (43 loc) · 1.8 KB
/
control.lua
File metadata and controls
49 lines (43 loc) · 1.8 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
local function onInit()
if settings.startup["startup-unlock-tech"].value then
for index, force in pairs(game.forces) do
force.technologies["automation"].researched = true
force.technologies["stone-wall"].researched = true
force.technologies["gun-turret"].researched = true
force.technologies["military"].researched = true
force.technologies["logistics"].researched = true
end
end
end
function onDeathHandler(event)
local entity = event.entity
local attackingForce = event.force
if(attackingForce == nil)then
return
end
if(attackingForce.current_research == nil) then
return
end
-- Do not reward destroying your own or neutral entities (like trees)
if(entity.force == attackingForce or entity.force.name == "neutral")then
return
end
local researchIngredientCount = 0
for index, ingredient in pairs(attackingForce.current_research.research_unit_ingredients) do
researchIngredientCount = researchIngredientCount + ingredient.amount
end
local researchUnitCost = researchIngredientCount * (attackingForce.current_research.research_unit_energy / 60 / (1 + attackingForce.laboratory_speed_modifier))
local researchTotalCost = researchUnitCost * attackingForce.current_research.research_unit_count
-- TODO: rename
local damageEffectScale = settings.startup["damage-effect-scale"].value / 100
local researchDelta = entity.prototype.max_health / (researchTotalCost * damageEffectScale) * (1 + attackingForce.laboratory_productivity_bonus)
local researchProgress = attackingForce.research_progress + researchDelta
if(researchProgress >= 1)then
attackingForce.research_progress = 0
attackingForce.current_research.researched = true
else
attackingForce.research_progress = researchProgress
end
end
script.on_init(onInit)
script.on_event(defines.events.on_entity_died, onDeathHandler)