2019-05-06 13:10:31 +02:00
-- Map by Kyte & MewMew
2019-05-05 16:17:33 +02:00
require " maps.wave_of_death.intro "
2019-05-06 01:40:46 +02:00
require " modules.biter_evasion_hp_increaser "
2019-05-07 23:38:14 +02:00
require " modules.custom_death_messages "
require " modules.dangerous_goods "
2019-05-05 16:17:33 +02:00
local event = require ' utils.event '
2019-05-08 19:02:27 +02:00
require ' utils.table '
2019-05-05 16:17:33 +02:00
local init = require " maps.wave_of_death.init "
local on_chunk_generated = require " maps.wave_of_death.terrain "
local ai = require " maps.wave_of_death.ai "
2019-05-06 13:10:31 +02:00
local game_status = require " maps.wave_of_death.game_status "
function soft_teleport ( player , destination )
local surface = game.surfaces [ " wave_of_death " ]
local pos = surface.find_non_colliding_position ( " character " , destination , 8 , 0.5 )
if not pos then player.teleport ( destination , surface ) end
player.teleport ( pos , surface )
end
2019-05-05 16:17:33 +02:00
2019-05-08 15:38:53 +02:00
local function spectate_button ( player )
if player.gui . top.spectate_button then return end
local button = player.gui . top.add ( { type = " button " , name = " spectate_button " , caption = " Spectate " } )
button.style . font = " default-bold "
button.style . font_color = { r = 0.0 , g = 0.0 , b = 0.0 }
button.style . minimal_height = 38
button.style . minimal_width = 38
button.style . top_padding = 2
button.style . left_padding = 4
button.style . right_padding = 4
button.style . bottom_padding = 2
end
local function create_spectate_confirmation ( player )
if player.gui . center.spectate_confirmation_frame then return end
local frame = player.gui . center.add ( { type = " frame " , name = " spectate_confirmation_frame " , caption = " Are you sure you want to spectate? This can not be undone. " } )
frame.style . font = " default "
frame.style . font_color = { r = 0.3 , g = 0.65 , b = 0.3 }
frame.add ( { type = " button " , name = " confirm_spectate " , caption = " Spectate " } )
frame.add ( { type = " button " , name = " cancel_spectate " , caption = " Cancel " } )
end
2019-05-10 12:57:53 +02:00
local button_colors = {
[ 1 ] = { r = 0.0 , g = 0.0 , b = 0.38 } ,
[ 2 ] = { r = 0.38 , g = 0.0 , b = 0.0 } ,
[ 3 ] = { r = 0.0 , g = 0.38 , b = 0.0 } ,
[ 4 ] = { r = 0.25 , g = 0.0 , b = 0.35 }
}
function create_lane_buttons ( player )
for i = 1 , 4 , 1 do
if player.gui . top [ " button_lane_ " .. i ] then player.gui . top [ " button_lane_ " .. i ] . destroy ( ) end
local caption = " Wave # " .. global.wod_lane [ i ] . current_wave - 1
if global.wod_lane [ i ] . game_lost == true then caption = " Out " end
local button = player.gui . top.add ( { type = " button " , name = " button_lane_ " .. i , caption = caption , tooltip = " Lane " .. i .. " stats " } )
button.style . font = " default-bold "
button.style . font_color = button_colors [ i ]
button.style . minimal_height = 38
button.style . minimal_width = 70
button.style . top_padding = 2
button.style . left_padding = 4
button.style . right_padding = 4
button.style . bottom_padding = 2
end
end
local function create_lane_info_frame ( player , lane_number )
end
2019-05-06 01:40:46 +02:00
local function autojoin_lane ( player )
local lowest_player_count = 256
2019-05-08 19:02:27 +02:00
local lane_number
local lane_numbers = { 1 , 2 , 3 , 4 }
table.shuffle_table ( lane_numbers )
for _ , number in pairs ( lane_numbers ) do
if # game.forces [ number ] . connected_players < lowest_player_count and global.wod_lane [ number ] . game_lost == false then
lowest_player_count = # game.forces [ number ] . connected_players
lane_number = number
2019-05-06 01:40:46 +02:00
end
end
2019-05-08 19:02:27 +02:00
2019-05-06 01:40:46 +02:00
player.force = game.forces [ lane_number ]
2019-05-06 13:10:31 +02:00
soft_teleport ( player , game.forces [ player.force . name ] . get_spawn_position ( game.surfaces [ " wave_of_death " ] ) )
2019-05-06 01:40:46 +02:00
player.insert ( { name = " pistol " , count = 1 } )
player.insert ( { name = " firearm-magazine " , count = 16 } )
2019-05-06 22:09:15 +02:00
player.insert ( { name = " iron-plate " , count = 128 } )
player.insert ( { name = " iron-gear-wheel " , count = 32 } )
2019-05-06 01:40:46 +02:00
end
2019-05-05 16:17:33 +02:00
local function on_player_joined_game ( event )
init ( )
2019-05-08 15:38:53 +02:00
2019-05-06 01:40:46 +02:00
local player = game.players [ event.player_index ]
2019-05-08 15:38:53 +02:00
spectate_button ( player )
2019-05-10 12:57:53 +02:00
create_lane_buttons ( player )
2019-05-28 13:30:10 +02:00
if global.lobby_active and # game.connected_players < 4 then
if game.tick ~= 0 then soft_teleport ( player , game.forces . player.get_spawn_position ( game.surfaces [ " wave_of_death " ] ) ) end
game.print ( " Waiting for " .. 4 - # game.connected_players .. " more players to join. " , { r = 0 , g = 170 , b = 0 } )
return
end
if global.lobby_active then
for _ , p in pairs ( game.connected_players ) do
autojoin_lane ( p )
end
global.lobby_active = false
return
end
2019-05-06 13:10:31 +02:00
if player.online_time == 0 then autojoin_lane ( player ) return end
if global.wod_lane [ tonumber ( player.force . name ) ] . game_lost == true then
player.character . die ( )
end
2019-05-05 16:17:33 +02:00
end
2019-05-06 10:34:52 +02:00
local function on_entity_damaged ( event )
ai.prevent_friendly_fire ( event )
end
2019-05-05 16:17:33 +02:00
local function on_entity_died ( event )
if not event.entity . valid then return end
ai.spawn_spread_wave ( event )
2019-05-06 13:10:31 +02:00
game_status.has_lane_lost ( event )
2019-05-05 16:17:33 +02:00
end
local function on_player_rotated_entity ( event )
ai.trigger_new_wave ( event )
end
local function on_tick ( event )
2019-05-06 01:40:46 +02:00
if game.tick % 300 ~= 0 then return end
2019-05-05 16:17:33 +02:00
2019-05-06 01:40:46 +02:00
for i = 1 , 4 , 1 do
2019-05-08 01:02:00 +02:00
game.forces [ i ] . chart ( game.surfaces [ " wave_of_death " ] , { { - 288 , - 420 } , { 352 , 64 } } )
2019-05-06 01:40:46 +02:00
end
2019-05-06 13:10:31 +02:00
game_status.restart_server ( )
2019-05-28 13:30:10 +02:00
if game.tick == 300 then
for _ , p in pairs ( game.connected_players ) do
soft_teleport ( p , game.forces . player.get_spawn_position ( game.surfaces [ " wave_of_death " ] ) )
end
end
2019-05-05 16:17:33 +02:00
end
2019-05-08 15:38:53 +02:00
local function on_gui_click ( event )
if not event then return end
if not event.element then return end
if not event.element . valid then return end
local player = game.players [ event.element . player_index ]
if event.element . name == " cancel_spectate " then player.gui . center [ " spectate_confirmation_frame " ] . destroy ( ) return end
if event.element . name == " confirm_spectate " then
player.gui . center [ " spectate_confirmation_frame " ] . destroy ( )
game.permissions . get_group ( " spectator " ) . add_player ( player )
2019-05-08 19:02:27 +02:00
if player.force . name == " player " then return end
2019-05-08 15:38:53 +02:00
player.force = game.forces . player
if player.character then player.character . die ( ) end
return
end
if event.element . name == " spectate_button " then
if player.gui . center [ " spectate_confirmation_frame " ] then
player.gui . center [ " spectate_confirmation_frame " ] . destroy ( )
else
create_spectate_confirmation ( player )
end
return
end
end
2019-05-10 12:57:53 +02:00
--Flamethrower Turret Nerf
local function on_research_finished ( event )
local research = event.research
local force_name = research.force . name
if research.name == " flamethrower " then
if not global.flamethrower_damage then global.flamethrower_damage = { } end
global.flamethrower_damage [ force_name ] = - 0.25
game.forces [ force_name ] . set_turret_attack_modifier ( " flamethrower-turret " , global.flamethrower_damage [ force_name ] )
game.forces [ force_name ] . set_ammo_damage_modifier ( " flamethrower " , global.flamethrower_damage [ force_name ] )
end
if string.sub ( research.name , 0 , 18 ) == " refined-flammables " then
global.flamethrower_damage [ force_name ] = global.flamethrower_damage [ force_name ] + 0.05
game.forces [ force_name ] . set_turret_attack_modifier ( " flamethrower-turret " , global.flamethrower_damage [ force_name ] )
game.forces [ force_name ] . set_ammo_damage_modifier ( " flamethrower " , global.flamethrower_damage [ force_name ] )
end
end
event.add ( defines.events . on_research_finished , on_research_finished )
2019-05-08 15:38:53 +02:00
event.add ( defines.events . on_gui_click , on_gui_click )
2019-05-05 16:17:33 +02:00
event.add ( defines.events . on_tick , on_tick )
event.add ( defines.events . on_chunk_generated , on_chunk_generated )
2019-05-06 10:34:52 +02:00
event.add ( defines.events . on_entity_damaged , on_entity_damaged )
2019-05-05 16:17:33 +02:00
event.add ( defines.events . on_entity_died , on_entity_died )
event.add ( defines.events . on_player_joined_game , on_player_joined_game )
event.add ( defines.events . on_player_rotated_entity , on_player_rotated_entity )