2018-11-07 21:27:42 +02:00
-- fish defense -- by mewmew --
2018-11-02 23:37:58 +02:00
local event = require ' utils.event '
require " maps.fish_defense_map_intro "
require " maps.fish_defense_kaboomsticks "
2018-11-03 19:16:59 +02:00
require " maps.tools.teleporters "
2018-11-07 22:48:03 +02:00
local map_functions = require " maps.tools.map_functions "
2018-11-02 23:37:58 +02:00
local math_random = math.random
local insert = table.insert
2018-11-07 21:27:42 +02:00
local wave_interval = 5400
2018-11-02 23:37:58 +02:00
2018-11-03 19:16:59 +02:00
local function shuffle ( tbl )
local size = # tbl
for i = size , 1 , - 1 do
local rand = math.random ( size )
tbl [ i ] , tbl [ rand ] = tbl [ rand ] , tbl [ i ]
end
return tbl
end
local function spill_loot ( position )
local chest_raffle = { }
2018-11-07 21:27:42 +02:00
local chest_loot = {
2018-11-03 19:16:59 +02:00
{ { name = " slowdown-capsule " , count = math_random ( 4 , 8 ) } , weight = 1 , evolution_min = 0.3 , evolution_max = 0.7 } ,
2018-11-07 21:27:42 +02:00
{ { name = " poison-capsule " , count = math_random ( 4 , 8 ) } , weight = 3 , evolution_min = 0.3 , evolution_max = 1 } ,
2018-11-03 19:16:59 +02:00
{ { name = " uranium-cannon-shell " , count = math_random ( 8 , 16 ) } , weight = 5 , evolution_min = 0.6 , evolution_max = 1 } ,
{ { name = " cannon-shell " , count = math_random ( 8 , 16 ) } , weight = 5 , evolution_min = 0.4 , evolution_max = 0.7 } ,
{ { name = " explosive-uranium-cannon-shell " , count = math_random ( 8 , 16 ) } , weight = 5 , evolution_min = 0.6 , evolution_max = 1 } ,
{ { name = " explosive-cannon-shell " , count = math_random ( 8 , 16 ) } , weight = 5 , evolution_min = 0.4 , evolution_max = 0.8 } ,
{ { name = " shotgun " , count = 1 } , weight = 2 , evolution_min = 0.0 , evolution_max = 0.2 } ,
{ { name = " shotgun-shell " , count = math_random ( 16 , 32 ) } , weight = 5 , evolution_min = 0.0 , evolution_max = 0.2 } ,
{ { name = " combat-shotgun " , count = 1 } , weight = 3 , evolution_min = 0.3 , evolution_max = 0.8 } ,
{ { name = " piercing-shotgun-shell " , count = math_random ( 16 , 32 ) } , weight = 10 , evolution_min = 0.2 , evolution_max = 1 } ,
{ { name = " flamethrower " , count = 1 } , weight = 3 , evolution_min = 0.3 , evolution_max = 0.6 } ,
{ { name = " flamethrower-ammo " , count = math_random ( 8 , 16 ) } , weight = 5 , evolution_min = 0.3 , evolution_max = 1 } ,
{ { name = " rocket-launcher " , count = 1 } , weight = 3 , evolution_min = 0.2 , evolution_max = 0.6 } ,
2018-11-07 21:27:42 +02:00
{ { name = " rocket " , count = math_random ( 8 , 16 ) } , weight = 5 , evolution_min = 0.2 , evolution_max = 0.7 } ,
2018-11-03 19:16:59 +02:00
{ { name = " explosive-rocket " , count = math_random ( 8 , 16 ) } , weight = 5 , evolution_min = 0.3 , evolution_max = 1 } ,
{ { name = " land-mine " , count = math_random ( 8 , 16 ) } , weight = 5 , evolution_min = 0.2 , evolution_max = 0.7 } ,
{ { name = " grenade " , count = math_random ( 8 , 16 ) } , weight = 5 , evolution_min = 0.0 , evolution_max = 0.5 } ,
{ { name = " cluster-grenade " , count = math_random ( 8 , 16 ) } , weight = 5 , evolution_min = 0.4 , evolution_max = 1 } ,
{ { name = " firearm-magazine " , count = math_random ( 16 , 48 ) } , weight = 5 , evolution_min = 0 , evolution_max = 0.3 } ,
{ { name = " piercing-rounds-magazine " , count = math_random ( 16 , 48 ) } , weight = 5 , evolution_min = 0.1 , evolution_max = 0.8 } ,
{ { name = " uranium-rounds-magazine " , count = math_random ( 16 , 48 ) } , weight = 5 , evolution_min = 0.5 , evolution_max = 1 } ,
{ { name = " railgun " , count = 1 } , weight = 1 , evolution_min = 0.2 , evolution_max = 1 } ,
{ { name = " railgun-dart " , count = math_random ( 16 , 32 ) } , weight = 3 , evolution_min = 0.2 , evolution_max = 0.7 } ,
{ { name = " defender-capsule " , count = math_random ( 8 , 16 ) } , weight = 2 , evolution_min = 0.0 , evolution_max = 0.7 } ,
{ { name = " distractor-capsule " , count = math_random ( 8 , 16 ) } , weight = 2 , evolution_min = 0.2 , evolution_max = 1 } ,
{ { name = " destroyer-capsule " , count = math_random ( 8 , 16 ) } , weight = 2 , evolution_min = 0.3 , evolution_max = 1 } ,
2018-11-07 21:27:42 +02:00
--{{name = "atomic-bomb", count = 1}, weight = 1, evolution_min = 0.3, evolution_max = 1},
{ { name = " light-armor " , count = 1 } , weight = 3 , evolution_min = 0 , evolution_max = 0.1 } ,
2018-11-03 19:16:59 +02:00
{ { name = " heavy-armor " , count = 1 } , weight = 3 , evolution_min = 0.1 , evolution_max = 0.3 } ,
{ { name = " modular-armor " , count = 1 } , weight = 2 , evolution_min = 0.2 , evolution_max = 0.6 } ,
{ { name = " power-armor " , count = 1 } , weight = 2 , evolution_min = 0.4 , evolution_max = 1 } ,
--{{name = "power-armor-mk2", count = 1}, weight = 1, evolution_min = 0.9, evolution_max = 1},
{ { name = " battery-equipment " , count = 1 } , weight = 2 , evolution_min = 0.3 , evolution_max = 0.7 } ,
{ { name = " battery-mk2-equipment " , count = 1 } , weight = 2 , evolution_min = 0.6 , evolution_max = 1 } ,
{ { name = " belt-immunity-equipment " , count = 1 } , weight = 1 , evolution_min = 0.3 , evolution_max = 1 } ,
{ { name = " solar-panel-equipment " , count = math_random ( 1 , 4 ) } , weight = 5 , evolution_min = 0.3 , evolution_max = 0.8 } ,
{ { name = " discharge-defense-equipment " , count = 1 } , weight = 1 , evolution_min = 0.5 , evolution_max = 0.8 } ,
{ { name = " energy-shield-equipment " , count = math_random ( 1 , 2 ) } , weight = 2 , evolution_min = 0.3 , evolution_max = 0.8 } ,
{ { name = " energy-shield-mk2-equipment " , count = 1 } , weight = 2 , evolution_min = 0.7 , evolution_max = 1 } ,
{ { name = " exoskeleton-equipment " , count = 1 } , weight = 1 , evolution_min = 0.3 , evolution_max = 1 } ,
{ { name = " fusion-reactor-equipment " , count = 1 } , weight = 1 , evolution_min = 0.5 , evolution_max = 1 } ,
{ { name = " night-vision-equipment " , count = 1 } , weight = 1 , evolution_min = 0.3 , evolution_max = 0.8 } ,
{ { name = " personal-laser-defense-equipment " , count = 1 } , weight = 2 , evolution_min = 0.5 , evolution_max = 1 } ,
{ { name = " exoskeleton-equipment " , count = 1 } , weight = 1 , evolution_min = 0.3 , evolution_max = 1 } ,
2018-11-07 21:27:42 +02:00
2018-11-06 01:07:35 +02:00
{ { name = " iron-gear-wheel " , count = math_random ( 25 , 50 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.3 } ,
2018-11-03 19:16:59 +02:00
{ { name = " copper-cable " , count = math_random ( 50 , 100 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.3 } ,
2018-11-06 01:07:35 +02:00
{ { name = " engine-unit " , count = math_random ( 8 , 16 ) } , weight = 2 , evolution_min = 0.1 , evolution_max = 0.5 } ,
{ { name = " electric-engine-unit " , count = math_random ( 8 , 16 ) } , weight = 2 , evolution_min = 0.4 , evolution_max = 0.8 } ,
{ { name = " battery " , count = math_random ( 25 , 50 ) } , weight = 2 , evolution_min = 0.3 , evolution_max = 0.8 } ,
{ { name = " advanced-circuit " , count = math_random ( 25 , 50 ) } , weight = 3 , evolution_min = 0.4 , evolution_max = 1 } ,
{ { name = " electronic-circuit " , count = math_random ( 25 , 50 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.4 } ,
{ { name = " processing-unit " , count = math_random ( 25 , 50 ) } , weight = 3 , evolution_min = 0.7 , evolution_max = 1 } ,
{ { name = " explosives " , count = math_random ( 40 , 50 ) } , weight = 5 , evolution_min = 0.0 , evolution_max = 1 } ,
2018-11-03 19:16:59 +02:00
{ { name = " lubricant-barrel " , count = math_random ( 4 , 10 ) } , weight = 1 , evolution_min = 0.3 , evolution_max = 0.5 } ,
{ { name = " rocket-fuel " , count = math_random ( 4 , 10 ) } , weight = 2 , evolution_min = 0.3 , evolution_max = 0.7 } ,
{ { name = " computer " , count = 2 } , weight = 1 , evolution_min = 0 , evolution_max = 1 } ,
{ { name = " steel-plate " , count = math_random ( 25 , 75 ) } , weight = 2 , evolution_min = 0.1 , evolution_max = 0.3 } ,
{ { name = " nuclear-fuel " , count = 1 } , weight = 2 , evolution_min = 0.7 , evolution_max = 1 } ,
2018-11-07 21:27:42 +02:00
2018-11-03 19:16:59 +02:00
{ { name = " burner-inserter " , count = math_random ( 8 , 16 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.1 } ,
{ { name = " inserter " , count = math_random ( 8 , 16 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.4 } ,
2018-11-07 21:27:42 +02:00
{ { name = " long-handed-inserter " , count = math_random ( 8 , 16 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.4 } ,
2018-11-03 19:16:59 +02:00
{ { name = " fast-inserter " , count = math_random ( 8 , 16 ) } , weight = 3 , evolution_min = 0.1 , evolution_max = 1 } ,
2018-11-07 21:27:42 +02:00
{ { name = " filter-inserter " , count = math_random ( 8 , 16 ) } , weight = 1 , evolution_min = 0.2 , evolution_max = 1 } ,
2018-11-03 19:16:59 +02:00
{ { name = " stack-filter-inserter " , count = math_random ( 4 , 8 ) } , weight = 1 , evolution_min = 0.4 , evolution_max = 1 } ,
2018-11-07 21:27:42 +02:00
{ { name = " stack-inserter " , count = math_random ( 4 , 8 ) } , weight = 3 , evolution_min = 0.3 , evolution_max = 1 } ,
2018-11-03 19:16:59 +02:00
{ { name = " small-electric-pole " , count = math_random ( 16 , 24 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.3 } ,
{ { name = " medium-electric-pole " , count = math_random ( 8 , 16 ) } , weight = 3 , evolution_min = 0.2 , evolution_max = 1 } ,
{ { name = " big-electric-pole " , count = math_random ( 4 , 8 ) } , weight = 3 , evolution_min = 0.3 , evolution_max = 1 } ,
{ { name = " substation " , count = math_random ( 2 , 4 ) } , weight = 3 , evolution_min = 0.5 , evolution_max = 1 } ,
{ { name = " wooden-chest " , count = math_random ( 16 , 24 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.2 } ,
{ { name = " iron-chest " , count = math_random ( 4 , 8 ) } , weight = 3 , evolution_min = 0.1 , evolution_max = 0.4 } ,
2018-11-07 21:27:42 +02:00
{ { name = " steel-chest " , count = math_random ( 4 , 8 ) } , weight = 3 , evolution_min = 0.3 , evolution_max = 1 } ,
2018-11-03 19:16:59 +02:00
{ { name = " small-lamp " , count = math_random ( 16 , 32 ) } , weight = 3 , evolution_min = 0.1 , evolution_max = 0.3 } ,
{ { name = " rail " , count = math_random ( 25 , 50 ) } , weight = 3 , evolution_min = 0.1 , evolution_max = 0.6 } ,
{ { name = " assembling-machine-1 " , count = math_random ( 2 , 4 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.3 } ,
{ { name = " assembling-machine-2 " , count = math_random ( 2 , 4 ) } , weight = 3 , evolution_min = 0.2 , evolution_max = 0.8 } ,
{ { name = " assembling-machine-3 " , count = math_random ( 1 , 2 ) } , weight = 3 , evolution_min = 0.5 , evolution_max = 1 } ,
{ { name = " accumulator " , count = math_random ( 4 , 8 ) } , weight = 3 , evolution_min = 0.4 , evolution_max = 1 } ,
{ { name = " offshore-pump " , count = math_random ( 1 , 3 ) } , weight = 2 , evolution_min = 0.0 , evolution_max = 0.1 } ,
{ { name = " beacon " , count = math_random ( 1 , 2 ) } , weight = 3 , evolution_min = 0.7 , evolution_max = 1 } ,
{ { name = " boiler " , count = math_random ( 4 , 8 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.3 } ,
{ { name = " steam-engine " , count = math_random ( 2 , 4 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.5 } ,
{ { name = " steam-turbine " , count = math_random ( 1 , 2 ) } , weight = 2 , evolution_min = 0.6 , evolution_max = 1 } ,
--{{name = "nuclear-reactor", count = 1}, weight = 1, evolution_min = 0.6, evolution_max = 1},
{ { name = " centrifuge " , count = math_random ( 1 , 2 ) } , weight = 1 , evolution_min = 0.6 , evolution_max = 1 } ,
{ { name = " heat-pipe " , count = math_random ( 4 , 8 ) } , weight = 2 , evolution_min = 0.5 , evolution_max = 1 } ,
{ { name = " heat-exchanger " , count = math_random ( 2 , 4 ) } , weight = 2 , evolution_min = 0.5 , evolution_max = 1 } ,
{ { name = " arithmetic-combinator " , count = math_random ( 8 , 16 ) } , weight = 1 , evolution_min = 0.1 , evolution_max = 1 } ,
{ { name = " constant-combinator " , count = math_random ( 8 , 16 ) } , weight = 1 , evolution_min = 0.1 , evolution_max = 1 } ,
{ { name = " decider-combinator " , count = math_random ( 8 , 16 ) } , weight = 1 , evolution_min = 0.1 , evolution_max = 1 } ,
2018-11-07 21:27:42 +02:00
{ { name = " power-switch " , count = math_random ( 1 , 2 ) } , weight = 1 , evolution_min = 0.1 , evolution_max = 1 } ,
2018-11-03 19:16:59 +02:00
{ { name = " programmable-speaker " , count = math_random ( 4 , 8 ) } , weight = 1 , evolution_min = 0.1 , evolution_max = 1 } ,
{ { name = " green-wire " , count = math_random ( 25 , 55 ) } , weight = 1 , evolution_min = 0.1 , evolution_max = 1 } ,
{ { name = " red-wire " , count = math_random ( 25 , 55 ) } , weight = 1 , evolution_min = 0.1 , evolution_max = 1 } ,
{ { name = " chemical-plant " , count = math_random ( 1 , 3 ) } , weight = 3 , evolution_min = 0.3 , evolution_max = 1 } ,
{ { name = " burner-mining-drill " , count = math_random ( 2 , 4 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.2 } ,
2018-11-07 21:27:42 +02:00
{ { name = " electric-mining-drill " , count = math_random ( 2 , 4 ) } , weight = 3 , evolution_min = 0.2 , evolution_max = 0.6 } ,
2018-11-03 19:16:59 +02:00
{ { name = " express-transport-belt " , count = math_random ( 25 , 75 ) } , weight = 3 , evolution_min = 0.5 , evolution_max = 1 } ,
2018-11-07 21:27:42 +02:00
{ { name = " express-underground-belt " , count = math_random ( 4 , 8 ) } , weight = 3 , evolution_min = 0.5 , evolution_max = 1 } ,
2018-11-03 19:16:59 +02:00
{ { name = " express-splitter " , count = math_random ( 2 , 4 ) } , weight = 3 , evolution_min = 0.5 , evolution_max = 1 } ,
{ { name = " fast-transport-belt " , count = math_random ( 25 , 75 ) } , weight = 3 , evolution_min = 0.2 , evolution_max = 0.7 } ,
{ { name = " fast-underground-belt " , count = math_random ( 4 , 8 ) } , weight = 3 , evolution_min = 0.2 , evolution_max = 0.7 } ,
{ { name = " fast-splitter " , count = math_random ( 2 , 4 ) } , weight = 3 , evolution_min = 0.2 , evolution_max = 0.3 } ,
{ { name = " transport-belt " , count = math_random ( 25 , 75 ) } , weight = 3 , evolution_min = 0 , evolution_max = 0.3 } ,
{ { name = " underground-belt " , count = math_random ( 4 , 8 ) } , weight = 3 , evolution_min = 0 , evolution_max = 0.3 } ,
2018-11-07 21:27:42 +02:00
{ { name = " splitter " , count = math_random ( 2 , 4 ) } , weight = 3 , evolution_min = 0 , evolution_max = 0.3 } ,
2018-11-03 19:16:59 +02:00
--{{name = "oil-refinery", count = math_random(2,4)}, weight = 2, evolution_min = 0.3, evolution_max = 1},
{ { name = " pipe " , count = math_random ( 30 , 50 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.3 } ,
{ { name = " pipe-to-ground " , count = math_random ( 4 , 8 ) } , weight = 1 , evolution_min = 0.2 , evolution_max = 0.5 } ,
{ { name = " pumpjack " , count = math_random ( 1 , 3 ) } , weight = 1 , evolution_min = 0.3 , evolution_max = 0.8 } ,
{ { name = " pump " , count = math_random ( 1 , 2 ) } , weight = 1 , evolution_min = 0.3 , evolution_max = 0.8 } ,
{ { name = " solar-panel " , count = math_random ( 2 , 4 ) } , weight = 3 , evolution_min = 0.4 , evolution_max = 0.9 } ,
{ { name = " electric-furnace " , count = math_random ( 2 , 4 ) } , weight = 3 , evolution_min = 0.5 , evolution_max = 1 } ,
{ { name = " steel-furnace " , count = math_random ( 4 , 8 ) } , weight = 3 , evolution_min = 0.2 , evolution_max = 0.7 } ,
2018-11-07 21:27:42 +02:00
{ { name = " stone-furnace " , count = math_random ( 8 , 16 ) } , weight = 3 , evolution_min = 0.0 , evolution_max = 0.1 } ,
2018-11-03 19:16:59 +02:00
{ { name = " radar " , count = math_random ( 1 , 2 ) } , weight = 1 , evolution_min = 0.1 , evolution_max = 0.3 } ,
{ { name = " rail-signal " , count = math_random ( 8 , 16 ) } , weight = 2 , evolution_min = 0.2 , evolution_max = 0.8 } ,
2018-11-07 21:27:42 +02:00
{ { name = " rail-chain-signal " , count = math_random ( 8 , 16 ) } , weight = 2 , evolution_min = 0.2 , evolution_max = 0.8 } ,
2018-11-03 19:16:59 +02:00
{ { name = " stone-wall " , count = math_random ( 25 , 75 ) } , weight = 1 , evolution_min = 0.1 , evolution_max = 0.5 } ,
{ { name = " gate " , count = math_random ( 4 , 8 ) } , weight = 1 , evolution_min = 0.1 , evolution_max = 0.5 } ,
{ { name = " storage-tank " , count = math_random ( 1 , 4 ) } , weight = 3 , evolution_min = 0.3 , evolution_max = 0.6 } ,
{ { name = " train-stop " , count = math_random ( 1 , 2 ) } , weight = 1 , evolution_min = 0.2 , evolution_max = 0.7 } ,
--{{name = "express-loader", count = math_random(1,3)}, weight = 1, evolution_min = 0.5, evolution_max = 1},
--{{name = "fast-loader", count = math_random(1,3)}, weight = 1, evolution_min = 0.2, evolution_max = 0.7},
--{{name = "loader", count = math_random(1,3)}, weight = 1, evolution_min = 0.0, evolution_max = 0.5},
2018-11-07 21:27:42 +02:00
{ { name = " lab " , count = math_random ( 1 , 2 ) } , weight = 2 , evolution_min = 0.0 , evolution_max = 0.1 }
2018-11-03 19:16:59 +02:00
}
2018-11-07 21:27:42 +02:00
2018-11-03 19:16:59 +02:00
for _ , t in pairs ( chest_loot ) do
for x = 1 , t.weight , 1 do
if t.evolution_min <= game.forces . enemy.evolution_factor and t.evolution_max >= game.forces . enemy.evolution_factor then
table.insert ( chest_raffle , t [ 1 ] )
end
2018-11-07 21:27:42 +02:00
end
2018-11-03 19:16:59 +02:00
end
2018-11-07 21:27:42 +02:00
2018-11-03 19:16:59 +02:00
local loot = chest_raffle [ math.random ( 1 , # chest_raffle ) ]
game.surfaces [ 1 ] . spill_item_stack ( position , loot , true )
2018-11-07 21:27:42 +02:00
2018-11-03 19:16:59 +02:00
end
2018-11-06 01:07:35 +02:00
local function create_wave_gui ( player )
if player.gui . top [ " fish_defense_waves " ] then player.gui . top [ " fish_defense_waves " ] . destroy ( ) end
2018-11-07 02:50:14 +02:00
local frame = player.gui . top.add ( { type = " frame " , name = " fish_defense_waves " } )
frame.style . maximal_height = 38
2018-11-07 21:27:42 +02:00
2018-11-07 02:50:14 +02:00
local wave_count = 0
2018-11-07 21:27:42 +02:00
if global.wave_count then wave_count = global.wave_count / 2 end
2018-11-07 02:50:14 +02:00
local label = frame.add ( { type = " label " , caption = " Wave: " .. wave_count } )
label.style . font_color = { r = 0.88 , g = 0.88 , b = 0.88 }
2018-11-07 21:27:42 +02:00
label.style . font = " default-listbox "
2018-11-07 02:50:14 +02:00
label.style . left_padding = 4
2018-11-07 21:27:42 +02:00
label.style . right_padding = 4
2018-11-07 02:50:14 +02:00
label.style . font_color = { r = 0.33 , g = 0.66 , b = 0.9 }
2018-11-07 21:27:42 +02:00
-- local next_level_progress = ((game.tick % wave_interval) / (wave_interval / 100)) * 0.01
2018-11-07 02:50:14 +02:00
local next_level_progress = game.tick % wave_interval / wave_interval
2018-11-06 01:07:35 +02:00
2018-11-07 21:27:42 +02:00
2018-11-07 02:50:14 +02:00
local progressbar = frame.add ( { type = " progressbar " , value = next_level_progress } )
progressbar.style . minimal_width = 120
progressbar.style . maximal_width = 120
progressbar.style . top_padding = 10
2018-11-07 21:27:42 +02:00
2018-11-02 23:37:58 +02:00
end
2018-11-07 02:50:14 +02:00
--local function increase_difficulty()
--if game.map_settings.enemy_expansion.max_expansion_cooldown < 7200 then return end
2018-11-07 21:27:42 +02:00
--game.map_settings.enemy_expansion.max_expansion_cooldown = game.map_settings.enemy_expansion.max_expansion_cooldown - 3600
2018-11-07 02:50:14 +02:00
--end
2018-11-03 19:16:59 +02:00
local function get_biters ( )
local surface = game.surfaces [ 1 ]
2018-11-07 21:27:42 +02:00
local biters_found = { }
for x = 256 , 8000 , 32 do
2018-11-03 19:16:59 +02:00
if not surface.is_chunk_generated ( { math.ceil ( x / 32 , 0 ) , 0 } ) then return biters_found end
local area = {
2018-11-07 21:27:42 +02:00
left_top = { x = x , y = - 1024 } ,
right_bottom = { x = x + 32 , y = 1024 }
2018-11-03 19:16:59 +02:00
}
local entities = surface.find_entities_filtered ( { area = area , type = " unit " , limit = global.wave_count } )
for _ , entity in pairs ( entities ) do
if # biters_found > global.wave_count then break end
insert ( biters_found , entity )
end
if # biters_found >= global.wave_count then return biters_found end
2018-11-07 21:27:42 +02:00
end
2018-11-03 19:16:59 +02:00
end
2018-11-06 01:07:35 +02:00
local function get_group_coords ( )
end
2018-11-03 19:16:59 +02:00
local function biter_attack_wave ( )
2018-11-02 23:37:58 +02:00
if not global.market then return end
2018-11-07 21:27:42 +02:00
2018-11-02 23:37:58 +02:00
local surface = game.surfaces [ 1 ]
if not global.wave_count then
2018-11-07 21:27:42 +02:00
global.wave_count = 2
2018-11-02 23:37:58 +02:00
else
2018-11-07 21:27:42 +02:00
global.wave_count = global.wave_count + 2
2018-11-02 23:37:58 +02:00
end
2018-11-07 21:27:42 +02:00
if game.forces . enemy.evolution_factor > 0.9 then
if not global.endgame_modifier then
global.endgame_modifier = 0.01
game.print ( " Endgame enemy evolution reached. Biter damage is rising... " , { r = 0.7 , g = 0.1 , b = 0.1 } )
else
global.endgame_modifier = global.endgame_modifier + 0.01
end
end
--game.print("Wave " .. tostring(global.wave_count / 2) .. " incoming!", {r = 0.9, g = 0.05, b = 0.4})
local group_coords = {
{ spawn = { x = 256 , y = 0 } , target = { x = 0 , y = 0 } }
2018-11-03 19:16:59 +02:00
}
2018-11-07 21:27:42 +02:00
local number_of_groups = 1
if global.wave_count > 50 then
group_coords = {
{ spawn = { x = 256 , y = - 160 } , target = { x = 0 , y = - 64 } } ,
{ spawn = { x = 256 , y = - 128 } , target = { x = 0 , y = - 64 } } ,
{ spawn = { x = 256 , y = - 96 } , target = { x = 0 , y = - 48 } } ,
{ spawn = { x = 256 , y = - 64 } , target = { x = 0 , y = - 32 } } ,
{ spawn = { x = 256 , y = - 32 } , target = { x = 0 , y = - 16 } } ,
{ spawn = { x = 256 , y = 0 } , target = { x = 0 , y = 0 } } ,
{ spawn = { x = 256 , y = 32 } , target = { x = 0 , y = 16 } } ,
{ spawn = { x = 256 , y = 64 } , target = { x = 0 , y = 32 } } ,
{ spawn = { x = 256 , y = 96 } , target = { x = 0 , y = 48 } } ,
{ spawn = { x = 256 , y = 128 } , target = { x = 0 , y = 64 } } ,
{ spawn = { x = 256 , y = 160 } , target = { x = 0 , y = 64 } }
}
number_of_groups = math.ceil ( global.wave_count / 50 , 0 )
if number_of_groups > # group_coords then number_of_groups = # group_coords end
end
group_coords = shuffle ( group_coords )
local biters = get_biters ( )
local max_group_size = math.ceil ( global.wave_count / number_of_groups , 0 )
if max_group_size > 200 then max_group_size = 200 end
local biter_counter = 0
local biter_attack_groups = { }
for i = 1 , number_of_groups , 1 do
if biter_counter > global.wave_count then break end
biter_attack_groups [ i ] = surface.create_unit_group ( { position = group_coords [ i ] . spawn } )
for x = 1 , max_group_size , 1 do
biter_counter = biter_counter + 1
if biter_counter > global.wave_count then break end
if not biters [ biter_counter ] then break end
biter_attack_groups [ i ] . add_member ( biters [ biter_counter ] )
2018-11-03 19:16:59 +02:00
end
2018-11-07 21:27:42 +02:00
if number_of_groups == 1 then
biter_attack_groups [ i ] . set_command ( { type = defines.command . attack , target = global.market , distraction = defines.distraction . by_enemy } )
else
2018-11-06 01:07:35 +02:00
if math_random ( 1 , 6 ) == 1 then
2018-11-07 21:27:42 +02:00
biter_attack_groups [ i ] . set_command ( { type = defines.command . attack , target = global.market , distraction = defines.distraction . by_enemy } )
2018-11-03 19:16:59 +02:00
else
2018-11-07 21:27:42 +02:00
biter_attack_groups [ i ] . set_command ( { type = defines.command . attack_area , destination = group_coords [ i ] . target , radius = 12 , distraction = defines.distraction . by_anything } )
2018-11-03 19:16:59 +02:00
end
end
end
2018-11-07 21:27:42 +02:00
--for _, group in pairs(biter_attack_groups) do
--if math_random(1,6) == 1 then
--group.set_command({type=defines.command.attack , target=global.market, distraction=defines.distraction.by_enemy})
--else
--group.set_command({type=defines.command.attack_area, destination={x = group.position.x - 268, y = group.position.y}, radius=12, distraction=defines.distraction.by_anything})
--end
--end
2018-11-02 23:37:58 +02:00
end
local function is_game_lost ( )
if global.market then return end
2018-11-07 21:27:42 +02:00
2018-11-02 23:37:58 +02:00
for _ , player in pairs ( game.connected_players ) do
2018-11-07 02:50:14 +02:00
if player.gui . left [ " fish_defense_game_lost " ] then return end
2018-11-06 01:07:35 +02:00
local f = player.gui . left.add ( { type = " frame " , name = " fish_defense_game_lost " , caption = " The fish market was destroyed! ;_; " } )
f.style . font_color = { r = 0.6 , g = 0.05 , b = 0.9 }
2018-11-02 23:37:58 +02:00
f.add ( { type = " label " , caption = " It survived for " .. math.ceil ( ( ( global.market_age / 60 ) / 60 ) , 0 ) .. " minutes. " } )
2018-11-03 19:16:59 +02:00
for _ , player in pairs ( game.connected_players ) do
2018-11-07 02:50:14 +02:00
player.play_sound { path = " utility/game_lost " , volume_modifier = 1 }
2018-11-03 19:16:59 +02:00
end
2018-11-02 23:37:58 +02:00
end
2018-11-07 21:27:42 +02:00
game.map_settings . enemy_expansion.enabled = true
game.map_settings . enemy_expansion.max_expansion_distance = 15
game.map_settings . enemy_expansion.settler_group_min_size = 15
game.map_settings . enemy_expansion.settler_group_max_size = 30
game.map_settings . enemy_expansion.min_expansion_cooldown = 600
game.map_settings . enemy_expansion.max_expansion_cooldown = 600
2018-11-02 23:37:58 +02:00
end
2018-11-06 01:07:35 +02:00
local biter_building_inhabitants = { }
biter_building_inhabitants [ 1 ] = { { " small-biter " , 8 , 16 } }
biter_building_inhabitants [ 2 ] = { { " small-biter " , 12 , 24 } }
biter_building_inhabitants [ 3 ] = { { " small-biter " , 8 , 16 } , { " medium-biter " , 1 , 2 } }
biter_building_inhabitants [ 4 ] = { { " small-biter " , 4 , 8 } , { " medium-biter " , 4 , 8 } }
biter_building_inhabitants [ 5 ] = { { " small-biter " , 3 , 5 } , { " medium-biter " , 8 , 12 } }
biter_building_inhabitants [ 6 ] = { { " small-biter " , 3 , 5 } , { " medium-biter " , 5 , 7 } , { " big-biter " , 1 , 2 } }
biter_building_inhabitants [ 7 ] = { { " medium-biter " , 6 , 8 } , { " big-biter " , 3 , 5 } }
biter_building_inhabitants [ 8 ] = { { " medium-biter " , 2 , 4 } , { " big-biter " , 6 , 8 } }
biter_building_inhabitants [ 9 ] = { { " medium-biter " , 2 , 3 } , { " big-biter " , 7 , 9 } }
biter_building_inhabitants [ 10 ] = { { " big-biter " , 4 , 8 } , { " behemoth-biter " , 3 , 4 } }
2018-11-07 02:50:14 +02:00
local function damage_entities_in_radius ( position , radius , damage )
local entities_to_damage = game.surfaces [ 1 ] . find_entities_filtered ( { area = { { position.x - radius , position.y - radius } , { position.x + radius , position.y + radius } } } )
for _ , entity in pairs ( entities_to_damage ) do
if entity.health then
if entity.force . name ~= " enemy " then
if entity.name == " player " then
entity.damage ( damage , " enemy " )
else
entity.health = entity.health - damage
if entity.health <= 0 then entity.die ( " enemy " ) end
2018-11-07 21:27:42 +02:00
end
2018-11-07 02:50:14 +02:00
end
end
end
end
2018-11-02 23:37:58 +02:00
local function on_entity_died ( event )
2018-11-03 19:16:59 +02:00
if event.entity . force.name == " enemy " then
if math_random ( 1 , 150 ) == 1 then
spill_loot ( event.entity . position )
end
2018-11-07 21:27:42 +02:00
2018-11-06 01:07:35 +02:00
if event.entity . name == " biter-spawner " or event.entity . name == " spitter-spawner " then
2018-11-07 21:27:42 +02:00
local e = math.ceil ( game.forces . enemy.evolution_factor * 10 , 0 )
for _ , t in pairs ( biter_building_inhabitants [ e ] ) do
2018-11-06 01:07:35 +02:00
for x = 1 , math.random ( t [ 2 ] , t [ 3 ] ) , 1 do
2018-11-07 21:27:42 +02:00
local p = event.entity . surface.find_non_colliding_position ( t [ 1 ] , event.entity . position , 6 , 1 )
2018-11-06 01:07:35 +02:00
if p then event.entity . surface.create_entity { name = t [ 1 ] , position = p } end
end
end
end
2018-11-07 21:27:42 +02:00
2018-11-06 01:07:35 +02:00
if event.entity . name == " medium-biter " then
event.entity . surface.create_entity ( { name = " explosion " , position = event.entity . position } )
2018-11-07 21:27:42 +02:00
local damage = 25
if global.endgame_modifier then damage = 25 + math.ceil ( ( global.endgame_modifier * 50 ) , 0 ) end
damage_entities_in_radius ( event.entity . position , 1 , damage )
2018-11-06 01:07:35 +02:00
end
2018-11-07 21:27:42 +02:00
2018-11-06 01:07:35 +02:00
if event.entity . name == " big-biter " then
event.entity . surface.create_entity ( { name = " uranium-cannon-shell-explosion " , position = event.entity . position } )
2018-11-07 21:27:42 +02:00
local damage = 50
if global.endgame_modifier then damage = 50 + math.ceil ( ( global.endgame_modifier * 100 ) , 0 ) end
damage_entities_in_radius ( event.entity . position , 2 , damage )
2018-11-06 01:07:35 +02:00
end
2018-11-07 21:27:42 +02:00
2018-11-03 19:16:59 +02:00
return
end
2018-11-07 21:27:42 +02:00
2018-11-02 23:37:58 +02:00
if event.entity == global.market then
global.market = nil
global.market_age = game.tick
is_game_lost ( )
end
end
local function on_entity_damaged ( event )
2018-11-07 02:50:14 +02:00
if event.cause then
if event.cause . name == " big-spitter " then
local surface = event.cause . surface
local area = { { event.entity . position.x - 3 , event.entity . position.y - 3 } , { event.entity . position.x + 3 , event.entity . position.y + 3 } }
if surface.count_entities_filtered ( { area = area , name = " small-biter " , limit = 3 } ) < 3 then
local pos = surface.find_non_colliding_position ( " small-biter " , event.entity . position , 3 , 1 )
surface.create_entity ( { name = " small-biter " , position = pos } )
end
end
2018-11-07 21:27:42 +02:00
if event.cause . name == " behemoth-spitter " then
local surface = event.cause . surface
local area = { { event.entity . position.x - 3 , event.entity . position.y - 3 } , { event.entity . position.x + 3 , event.entity . position.y + 3 } }
if surface.count_entities_filtered ( { area = area , name = " medium-biter " , limit = 3 } ) < 3 then
local pos = surface.find_non_colliding_position ( " medium-biter " , event.entity . position , 3 , 1 )
surface.create_entity ( { name = " medium-biter " , position = pos } )
end
end
2018-11-07 02:50:14 +02:00
if event.cause . force.name == " enemy " then
2018-11-07 21:27:42 +02:00
if global.endgame_modifier then
event.entity . health = event.entity . health - ( event.final_damage_amount * global.endgame_modifier )
end
2018-11-07 02:50:14 +02:00
end
end
2018-11-07 21:27:42 +02:00
2018-11-02 23:37:58 +02:00
if event.entity . name == " market " then
if event.cause . force.name == " enemy " then return end
event.entity . health = event.entity . health + event.final_damage_amount
end
2018-11-07 21:27:42 +02:00
2018-11-02 23:37:58 +02:00
end
local function on_player_joined_game ( event )
local player = game.players [ event.player_index ]
2018-11-07 21:27:42 +02:00
2018-11-02 23:37:58 +02:00
if not global.fish_defense_init_done then
local surface = game.surfaces [ 1 ]
2018-11-07 21:27:42 +02:00
2018-11-07 02:50:14 +02:00
game.map_settings . enemy_expansion.enabled = false
2018-11-07 21:27:42 +02:00
2018-11-06 01:07:35 +02:00
game.map_settings . enemy_evolution.destroy_factor = 0.008
2018-11-07 22:48:03 +02:00
game.map_settings . enemy_evolution.time_factor = 0.00005
2018-11-02 23:37:58 +02:00
game.map_settings . enemy_evolution.pollution_factor = 0.000015
2018-11-07 21:27:42 +02:00
game.forces [ " player " ] . technologies [ " artillery-shell-range-1 " ] . enabled = false
2018-11-02 23:37:58 +02:00
game.forces [ " player " ] . technologies [ " artillery-shell-speed-1 " ] . enabled = false
game.forces [ " player " ] . technologies [ " artillery " ] . enabled = false
2018-11-07 21:27:42 +02:00
2018-11-02 23:37:58 +02:00
game.forces . player.set_ammo_damage_modifier ( " shotgun-shell " , 0.5 )
2018-11-07 21:27:42 +02:00
2018-11-02 23:37:58 +02:00
local pos = surface.find_non_colliding_position ( " market " , { 0 , 0 } , 50 , 1 )
global.market = surface.create_entity ( { name = " market " , position = pos , force = " player " } )
global.market . minable = false
global.market . add_market_item ( { price = { { " coal " , 3 } } , offer = { type = ' give-item ' , item = " raw-fish " , count = 1 } } )
2018-11-07 21:27:42 +02:00
2018-11-06 01:07:35 +02:00
local radius = 512
game.forces . player.chart ( game.players [ 1 ] . surface , { { x = - 1 * radius , y = - 1 * radius } , { x = radius , y = radius } } )
2018-11-07 21:27:42 +02:00
2018-11-07 22:48:03 +02:00
surface.create_entity ( { name = " electric-beam " , position = { 160 , - 95 } , source = { 160 , - 95 } , target = { 160 , 96 } } )
2018-11-02 23:37:58 +02:00
global.fish_defense_init_done = true
end
2018-11-07 21:27:42 +02:00
2018-11-02 23:37:58 +02:00
if player.online_time < 1 then
player.insert ( { name = " pistol " , count = 1 } )
2018-11-06 01:07:35 +02:00
player.insert ( { name = " iron-axe " , count = 1 } )
player.insert ( { name = " raw-fish " , count = 3 } )
player.insert ( { name = " firearm-magazine " , count = 32 } )
player.insert ( { name = " grenade " , count = 3 } )
player.insert ( { name = " iron-plate " , count = 32 } )
player.insert ( { name = " light-armor " , count = 1 } )
2018-11-02 23:37:58 +02:00
if global.show_floating_killscore then global.show_floating_killscore [ player.name ] = true end
end
2018-11-07 21:27:42 +02:00
2018-11-06 01:07:35 +02:00
if global.wave_count then create_wave_gui ( player ) end
2018-11-07 21:27:42 +02:00
2018-11-02 23:37:58 +02:00
is_game_lost ( )
end
local map_height = 96
2018-11-07 22:48:03 +02:00
2018-11-02 23:37:58 +02:00
local function on_chunk_generated ( event )
local surface = game.surfaces [ 1 ]
local area = event.area
local left_top = area.left_top
2018-11-07 21:27:42 +02:00
2018-11-02 23:37:58 +02:00
local entities = surface.find_entities_filtered ( { area = area , force = " enemy " } )
for _ , entity in pairs ( entities ) do
entity.destroy ( )
2018-11-07 22:48:03 +02:00
end
if left_top.x >= - 160 and left_top.x < 160 then
local entities = surface.find_entities_filtered ( { area = area , type = " resource " } )
for _ , entity in pairs ( entities ) do
entity.destroy ( )
end
--[[
local tiles = { }
for x = 0 , 31 , 1 do
for y = 0 , 31 , 1 do
local pos = { x = left_top.x + x , y = left_top.y + y }
local tile = surface.get_tile ( pos )
if tile.name == " deepwater " or tile.name == " water " then
insert ( tiles , { name = " grass-1 " , position = pos } )
end
end
end
surface.set_tiles ( tiles , true )
] ]
2018-11-02 23:37:58 +02:00
end
2018-11-07 22:48:03 +02:00
if left_top.x >= 256 then
if not global.spawn_ores_generated then
map_functions.draw_smoothed_out_ore_circle ( { x = - 64 , y = - 64 } , " copper-ore " , surface , 15 , 2500 )
map_functions.draw_smoothed_out_ore_circle ( { x = - 64 , y = - 32 } , " iron-ore " , surface , 15 , 2500 )
map_functions.draw_smoothed_out_ore_circle ( { x = - 64 , y = 32 } , " coal " , surface , 15 , 1500 )
map_functions.draw_smoothed_out_ore_circle ( { x = - 64 , y = 64 } , " stone " , surface , 15 , 1500 )
global.spawn_ores_generated = true
end
end
2018-11-02 23:37:58 +02:00
local tiles = { }
2018-11-07 21:27:42 +02:00
local hourglass_center_piece_length = 64
2018-11-07 22:48:03 +02:00
2018-11-07 21:27:42 +02:00
for x = 0 , 31 , 1 do
for y = 0 , 31 , 1 do
2018-11-07 02:50:14 +02:00
local pos = { x = left_top.x + x , y = left_top.y + y }
if pos.y >= map_height then
if pos.y > pos.x - hourglass_center_piece_length and pos.x > 0 then
insert ( tiles , { name = " out-of-map " , position = pos } )
end
if pos.y > ( pos.x + hourglass_center_piece_length ) * - 1 and pos.x <= 0 then
insert ( tiles , { name = " out-of-map " , position = pos } )
end
2018-11-07 21:27:42 +02:00
end
2018-11-07 02:50:14 +02:00
if pos.y < map_height * - 1 then
if pos.y < ( pos.x - hourglass_center_piece_length ) * - 1 and pos.x > 0 then
insert ( tiles , { name = " out-of-map " , position = pos } )
end
if pos.y < pos.x + hourglass_center_piece_length and pos.x <= 0 then
insert ( tiles , { name = " out-of-map " , position = pos } )
end
2018-11-02 23:37:58 +02:00
end
end
end
2018-11-07 21:27:42 +02:00
2018-11-02 23:37:58 +02:00
surface.set_tiles ( tiles , false )
2018-11-07 21:27:42 +02:00
if left_top.x < 160 then return end
2018-11-03 19:16:59 +02:00
local entities = surface.find_entities_filtered ( { area = area , type = " tree " } )
for _ , entity in pairs ( entities ) do
entity.destroy ( )
end
2018-11-07 21:27:42 +02:00
2018-11-03 19:16:59 +02:00
local entities = surface.find_entities_filtered ( { area = area , type = " cliff " } )
for _ , entity in pairs ( entities ) do
entity.destroy ( )
end
2018-11-07 21:27:42 +02:00
2018-11-07 02:50:14 +02:00
local entities = surface.find_entities_filtered ( { area = area , type = " resource " } )
for _ , entity in pairs ( entities ) do
surface.create_entity ( { name = " uranium-ore " , position = entity.position , amount = math_random ( 200 , 8000 ) } )
entity.destroy ( )
end
2018-11-07 21:27:42 +02:00
2018-11-07 02:50:14 +02:00
local tiles = { }
2018-11-07 21:27:42 +02:00
for x = 0 , 31 , 1 do
for y = 0 , 31 , 1 do
2018-11-02 23:37:58 +02:00
local pos = { x = left_top.x + x , y = left_top.y + y }
2018-11-07 21:27:42 +02:00
2018-11-07 02:50:14 +02:00
local tile = surface.get_tile ( pos )
if tile.name ~= " out-of-map " then
insert ( tiles , { name = " dirt-6 " , position = pos } )
end
2018-11-07 21:27:42 +02:00
2018-11-07 02:50:14 +02:00
if left_top.x > 256 and math_random ( 1 , 32 ) == 1 then
2018-11-02 23:37:58 +02:00
if surface.can_place_entity ( { name = " biter-spawner " , force = " enemy " , position = pos } ) then
if math_random ( 1 , 4 ) == 1 then
surface.create_entity ( { name = " spitter-spawner " , force = " enemy " , position = pos } )
else
surface.create_entity ( { name = " biter-spawner " , force = " enemy " , position = pos } )
end
end
end
end
end
2018-11-07 02:50:14 +02:00
surface.set_tiles ( tiles , true )
2018-11-07 21:27:42 +02:00
2018-11-07 02:50:14 +02:00
local decorative_names = { }
for k , v in pairs ( game.decorative_prototypes ) do
if v.autoplace_specification then
decorative_names [ # decorative_names + 1 ] = k
2018-11-06 01:07:35 +02:00
end
2018-11-07 21:27:42 +02:00
end
surface.regenerate_decorative ( decorative_names , { { x = math.floor ( event.area . left_top.x / 32 ) , y = math.floor ( event.area . left_top.y / 32 ) } } )
2018-11-02 23:37:58 +02:00
end
2018-11-07 02:50:14 +02:00
local build_limit_radius = 64
2018-11-02 23:37:58 +02:00
local function on_built_entity ( event )
2018-11-07 02:50:14 +02:00
if " flamethrower-turret " == event.created_entity . name then
2018-11-02 23:37:58 +02:00
event.created_entity . die ( )
2018-11-07 02:50:14 +02:00
return
end
2018-11-07 21:27:42 +02:00
2018-11-07 02:50:14 +02:00
if event.created_entity . name == " gun-turret " then
local surface = event.created_entity . surface
local area = { { event.created_entity . position.x - build_limit_radius , event.created_entity . position.y - build_limit_radius } , { event.created_entity . position.x + build_limit_radius , event.created_entity . position.y + build_limit_radius } }
local turrets_count_in_area = surface.count_entities_filtered ( { area = area , name = " gun-turret " , limit = 3 } )
2018-11-07 21:27:42 +02:00
2018-11-07 02:50:14 +02:00
if turrets_count_in_area <= 2 then
surface.create_entity ( { name = " flying-text " , position = event.created_entity . position , text = turrets_count_in_area .. " / 2 Turrets built in area " , color = { r = 0.98 , g = 0.66 , b = 0.22 } } )
2018-11-07 21:27:42 +02:00
else
2018-11-07 02:50:14 +02:00
surface.create_entity ( { name = " flying-text " , position = event.created_entity . position , text = " Too many turrets in area " , color = { r = 0.82 , g = 0.11 , b = 0.11 } } )
if event.player_index then
local player = game.players [ event.player_index ]
event.created_entity . destroy ( )
player.insert ( { name = " gun-turret " , count = 1 } )
if global.score then
if global.score [ player.force . name ] then
if global.score [ player.force . name ] . players [ player.name ] then
global.score [ player.force . name ] . players [ player.name ] . built_entities = global.score [ player.force . name ] . players [ player.name ] . built_entities - 1
end
end
end
return
else
event.created_entity . die ( )
return
2018-11-07 21:27:42 +02:00
end
2018-11-07 02:50:14 +02:00
end
end
2018-11-07 21:27:42 +02:00
2018-11-07 02:50:14 +02:00
if event.created_entity . name == " laser-turret " then
local surface = event.created_entity . surface
local area = { { event.created_entity . position.x - build_limit_radius , event.created_entity . position.y - build_limit_radius } , { event.created_entity . position.x + build_limit_radius , event.created_entity . position.y + build_limit_radius } }
local turrets_count_in_area = surface.count_entities_filtered ( { area = area , name = " laser-turret " , limit = 2 } )
2018-11-07 21:27:42 +02:00
2018-11-07 02:50:14 +02:00
if turrets_count_in_area <= 1 then
surface.create_entity ( { name = " flying-text " , position = event.created_entity . position , text = turrets_count_in_area .. " / 1 Turrets built in area " , color = { r = 0.98 , g = 0.66 , b = 0.22 } } )
2018-11-07 21:27:42 +02:00
else
2018-11-07 02:50:14 +02:00
surface.create_entity ( { name = " flying-text " , position = event.created_entity . position , text = " Too many turrets in area " , color = { r = 0.82 , g = 0.11 , b = 0.11 } } )
if event.player_index then
local player = game.players [ event.player_index ]
event.created_entity . destroy ( )
player.insert ( { name = " laser-turret " , count = 1 } )
if global.score then
if global.score [ player.force . name ] then
if global.score [ player.force . name ] . players [ player.name ] then
global.score [ player.force . name ] . players [ player.name ] . built_entities = global.score [ player.force . name ] . players [ player.name ] . built_entities - 1
end
end
end
return
else
event.created_entity . die ( )
return
2018-11-07 21:27:42 +02:00
end
2018-11-07 02:50:14 +02:00
end
2018-11-02 23:37:58 +02:00
end
end
local function on_robot_built_entity ( event )
on_built_entity ( event )
end
local function on_tick ( )
2018-11-07 21:27:42 +02:00
if game.tick % 30 == 0 then
2018-11-07 02:50:14 +02:00
if global.market then
2018-11-07 21:27:42 +02:00
for _ , player in pairs ( game.connected_players ) do
create_wave_gui ( player )
2018-11-07 02:50:14 +02:00
end
end
2018-11-02 23:37:58 +02:00
end
2018-11-07 21:27:42 +02:00
2018-11-07 02:50:14 +02:00
if game.tick % wave_interval == wave_interval - 1 then
2018-11-02 23:37:58 +02:00
biter_attack_wave ( )
2018-11-07 21:27:42 +02:00
end
2018-11-02 23:37:58 +02:00
end
2018-11-07 02:50:14 +02:00
local function on_player_changed_position ( event )
local player = game.players [ event.player_index ]
if player.position . x >= 160 then
player.teleport ( { player.position . x - 1 , player.position . y } , game.surfaces [ 1 ] )
2018-11-07 21:27:42 +02:00
if player.position . y > map_height or player.position . y < map_height * - 1 then
player.teleport ( { player.position . x , 0 } , game.surfaces [ 1 ] )
end
2018-11-07 02:50:14 +02:00
if player.character then
2018-11-07 21:27:42 +02:00
player.character . health = player.character . health - 25
player.character . surface.create_entity ( { name = " water-splash " , position = player.position } )
if player.character . health <= 0 then player.character . die ( " enemy " ) end
2018-11-07 02:50:14 +02:00
end
end
end
2018-11-02 23:37:58 +02:00
event.add ( defines.events . on_tick , on_tick )
2018-11-07 02:50:14 +02:00
event.add ( defines.events . on_player_changed_position , on_player_changed_position )
2018-11-02 23:37:58 +02:00
event.add ( defines.events . on_built_entity , on_built_entity )
event.add ( defines.events . on_robot_built_entity , on_robot_built_entity )
event.add ( defines.events . on_entity_died , on_entity_died )
event.add ( defines.events . on_entity_damaged , on_entity_damaged )
event.add ( defines.events . on_chunk_generated , on_chunk_generated )
2018-11-07 21:27:42 +02:00
event.add ( defines.events . on_player_joined_game , on_player_joined_game )