1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/maps/tank_conquest/tank_conquest.lua

1943 lines
65 KiB
Lua
Raw Normal View History

2021-03-24 21:14:55 +02:00
--luacheck: ignore
2021-03-24 17:46:00 +02:00
-- factorio scenario -- tank conquest -- xalpha made this --
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local blueprint_poi_base_json = require 'maps.tank_conquest.blueprint_poi_base_json'
local blueprint_poi_spot_one_json = require 'maps.tank_conquest.blueprint_poi_spot_one_json'
local blueprint_poi_spot_two_json = require 'maps.tank_conquest.blueprint_poi_spot_two_json'
local blueprint_poi_spot_three_json = require 'maps.tank_conquest.blueprint_poi_spot_three_json'
local blueprint_poi_fire_json = require 'maps.tank_conquest.blueprint_poi_fire_json'
local blueprint_poi_laser_json = require 'maps.tank_conquest.blueprint_poi_laser_json'
global.table_of_properties = {}
global.table_of_properties.required_number_of_players = 2
global.table_of_properties.countdown_in_seconds = 28800
global.table_of_properties.wait_in_seconds = 2
global.table_of_properties.size_of_the_battlefield = 2000
global.table_of_properties.amount_of_tickets = 800
global.table_of_properties.conquest_speed = 5
global.table_of_properties.acceleration_value = 0.05
global.table_of_properties.game_stage = 'lobby'
global.table_of_tanks = {}
global.table_of_scores = {}
global.table_of_spots = {}
global.table_of_spawns = {}
global.table_of_squads = {}
global.table_of_drawings = {}
global.table_of_delays = {}
local table_of_colors = {
squad = {r = 75, g = 155, b = 45},
team = {r = 65, g = 120, b = 200},
enemy = {r = 190, g = 55, b = 50},
neutral = {r = 77, g = 77, b = 77},
damage = {r = 255, g = 0, b = 255},
white = {r = 255, g = 255, b = 255}
}
local table_of_loots = {
{name = 'iron-ore', count = 50},
{name = 'copper-ore', count = 50},
{name = 'stone', count = 50},
{name = 'coal', count = 50},
{name = 'defender-capsule', count = 10},
{name = 'land-mine', count = 20},
{name = 'gun-turret', count = 5},
{name = 'piercing-rounds-magazine', count = 50},
{name = 'uranium-rounds-magazine', count = 10},
{name = 'combat-shotgun', count = 1},
{name = 'shotgun-shell', count = 20},
{name = 'piercing-shotgun-shell', count = 20},
{name = 'flamethrower', count = 1},
{name = 'flamethrower-ammo', count = 20},
{name = 'rocket-launcher', count = 1},
{name = 'rocket', count = 20},
{name = 'explosive-rocket', count = 10},
{name = 'atomic-bomb', count = 1},
{name = 'grenade', count = 20},
{name = 'cluster-grenade', count = 10},
{name = 'cannon-shell', count = 20},
{name = 'explosive-cannon-shell', count = 10},
{name = 'uranium-cannon-shell', count = 5},
{name = 'explosive-uranium-cannon-shell', count = 5},
{name = 'modular-armor', count = 1},
{name = 'power-armor', count = 1},
{name = 'power-armor-mk2', count = 1},
{name = 'exoskeleton-equipment', count = 1},
{name = 'battery-mk2-equipment', count = 1},
{name = 'energy-shield-equipment', count = 1},
{name = 'fusion-reactor-equipment', count = 1},
{name = 'solid-fuel', count = 20},
{name = 'rocket-fuel', count = 10},
{name = 'nuclear-fuel', count = 1},
{name = 'gate', count = 10},
{name = 'stone-wall', count = 20}
}
local table_of_slots = {
'stone-wall',
'gun-turret',
'wood',
'repair-pack',
'raw-fish',
'defender-capsule',
'rocket',
'explosive-rocket',
'atomic-bomb',
'flamethrower-ammo',
'land-mine',
'firearm-magazine',
'piercing-rounds-magazine',
'uranium-rounds-magazine',
'grenade',
'cluster-grenade',
'cannon-shell',
'explosive-cannon-shell',
'uranium-cannon-shell',
'explosive-uranium-cannon-shell'
}
local table_of_ores = {'iron-ore', 'copper-ore', 'stone', 'coal'}
local map_functions = require 'tools.map_functions'
local event = require 'utils.event'
local map_intro =
[[ - - - T A N K C O N Q U E S T - - -
When the round is running, the ticket overview is shown in the header. Your objective
is to defend your team's tickets and withdraw the tickets from the opposing team as
quickly as possible.
There are two ways to withdraw the tickets from the opposing team. First, by killing
the player and second, by taking the spots. A spot withdraw 0.05 tickets per second
from the opposing team.
The battlefield has two special features: First, there is a point of interest in the
north and south. And second, there are loot boxes scattered throughout the battlefield.
PvP battles and the conquest of the spots are the deciding factor to win the round.
The battlefield is created when at least two players are online.
There is no biter evolution from pollution, time or destruction.]]
2021-03-24 17:46:00 +02:00
local function draw_gui_intro_button(player)
if player.gui.top['draw_gui_intro_button'] then
return
end
2021-03-24 17:46:00 +02:00
local element_button = player.gui.top.add({type = 'sprite-button', name = 'draw_gui_intro_button', caption = '?', tooltip = 'Map Intro'})
2021-03-24 17:46:00 +02:00
element_button.style.width = 38
2021-03-24 17:46:00 +02:00
element_button.style.height = 38
2021-03-24 17:46:00 +02:00
element_button.style.font_color = {r = 0.5, g = 0.3, b = 0.99}
2021-03-24 17:46:00 +02:00
element_button.style.font = 'heading-1'
end
2021-03-24 17:46:00 +02:00
local function draw_gui_intro_frame(player)
if player.gui.center['draw_gui_intro_frame'] then
player.gui.center['draw_gui_intro_frame'].destroy()
end
2021-03-24 17:46:00 +02:00
local element_frame = player.gui.center.add({type = 'frame', name = 'draw_gui_intro_frame', direction = 'vertical'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame = element_frame.add({type = 'frame'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_frame.add({type = 'label', name = 'draw_gui_intro_content', caption = map_intro})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.top_padding = 15
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.single_line = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.font = 'heading-2'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.font_color = {r = 0.7, g = 0.6, b = 0.99}
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local function initialize_forces()
game.create_force('force_player_one')
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.create_force('force_player_two')
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.create_force('force_biter_one')
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.create_force('force_biter_two')
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.create_force('force_spectator')
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local force = game.forces.force_player_one
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_properties[force.name] == nil then
global.table_of_properties[force.name] = {name = force.name, enemy = 'force_player_two', icon = '', available_tickets = global.table_of_properties.amount_of_tickets}
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('force_biter_two', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('force_spectator', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_cease_fire('player', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local force = game.forces.force_player_two
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_properties[force.name] == nil then
global.table_of_properties[force.name] = {name = force.name, enemy = 'force_player_one', icon = '', available_tickets = global.table_of_properties.amount_of_tickets}
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('force_biter_one', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('force_spectator', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_cease_fire('player', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local force = game.forces['force_biter_one']
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('force_player_two', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('force_biter_two', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('force_spectator', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('player', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local force = game.forces['force_biter_two']
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('force_player_one', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('force_biter_one', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('force_spectator', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('player', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local force = game.forces.force_spectator
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_spawn_position({x = 0, y = 0}, game.surfaces.nauvis)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.technologies['toolbelt'].researched = true
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('force_player_one', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_friend('force_player_two', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_cease_fire('force_biter_one', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_cease_fire('force_biter_two', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_cease_fire('player', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_cease_fire('enemy', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local force = game.forces['player']
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_cease_fire('force_player_one', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_cease_fire('force_player_two', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_cease_fire('force_biter_one', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_cease_fire('force_biter_two', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
force.set_cease_fire('force_spectator', true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local spectator = game.permissions.create_group('permission_spectator')
2019-08-07 22:51:47 +02:00
2021-03-24 17:46:00 +02:00
for action_name, _ in pairs(defines.input_action) do
spectator.set_allows_action(defines.input_action[action_name], false)
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_definitions = {
defines.input_action.write_to_console,
defines.input_action.gui_click,
defines.input_action.gui_selection_state_changed,
defines.input_action.gui_checked_state_changed,
defines.input_action.gui_elem_changed,
defines.input_action.gui_text_changed,
defines.input_action.gui_value_changed,
defines.input_action.start_walking,
defines.input_action.open_kills_gui,
defines.input_action.toggle_show_entity_info
}
for _, define in pairs(table_of_definitions) do
spectator.set_allows_action(define, true)
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, force in pairs(game.forces) do
game.forces[force.name].technologies['artillery'].enabled = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.forces[force.name].technologies['artillery-shell-range-1'].enabled = false
2021-03-24 17:46:00 +02:00
game.forces[force.name].technologies['artillery-shell-speed-1'].enabled = false
2021-03-24 17:46:00 +02:00
game.forces[force.name].technologies['follower-robot-count-1'].researched = true
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.forces[force.name].technologies['atomic-bomb'].enabled = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.forces[force.name].set_turret_attack_modifier('flamethrower-turret', 4)
2021-03-24 17:46:00 +02:00
game.forces[force.name].set_turret_attack_modifier('laser-turret', 2)
2021-03-24 17:46:00 +02:00
game.forces[force.name].set_turret_attack_modifier('gun-turret', 4)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.forces[force.name].set_ammo_damage_modifier('cannon-shell', 1)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.forces[force.name].set_ammo_damage_modifier('grenade', 1)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.forces[force.name].research_queue_enabled = true
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.forces[force.name].friendly_fire = false
2021-03-24 17:46:00 +02:00
game.forces[force.name].share_chart = true
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
game.permissions.get_group('Default').set_allows_action(defines.input_action.grab_blueprint_record, false)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.permissions.get_group('Default').set_allows_action(defines.input_action.import_blueprint_string, false)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.permissions.get_group('Default').set_allows_action(defines.input_action.import_blueprint, false)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.forces['enemy'].evolution_factor = 0.4
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function initialize_surface()
game.map_settings.enemy_evolution.time_factor = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.map_settings.enemy_evolution.destroy_factor = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.map_settings.enemy_evolution.pollution_factor = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.map_settings.pollution.enabled = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.map_settings.enemy_expansion.enabled = true
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.map_settings.enemy_expansion.settler_group_min_size = 8
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.map_settings.enemy_expansion.settler_group_max_size = 16
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.map_settings.enemy_expansion.min_expansion_cooldown = 54000
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.map_settings.enemy_expansion.max_expansion_cooldown = 108000
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local map_gen_settings = {}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
map_gen_settings.width = global.table_of_properties.size_of_the_battlefield
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
map_gen_settings.height = global.table_of_properties.size_of_the_battlefield
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
map_gen_settings.seed = math.random(1, 2097152)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
map_gen_settings.water = 'none'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
map_gen_settings.starting_area = 'none'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
map_gen_settings.cliff_settings = {name = 'cliff', cliff_elevation_0 = 0, cliff_elevation_interval = 0}
2021-03-24 17:46:00 +02:00
map_gen_settings.autoplace_controls = {
['trees'] = {frequency = 'normal', size = 'normal', richness = 'normal'},
['coal'] = {frequency = 'very-high', size = 'very-low', richness = 'normal'},
['stone'] = {frequency = 'very-high', size = 'very-low', richness = 'normal'},
['copper-ore'] = {frequency = 'very-high', size = 'very-low', richness = 'normal'},
['uranium-ore'] = {frequency = 'very-high', size = 'very-low', richness = 'normal'},
['iron-ore'] = {frequency = 'very-high', size = 'very-low', richness = 'normal'},
['crude-oil'] = {frequency = 'very-high', size = 'very-low', richness = 'normal'},
['enemy-base'] = {frequency = 'normal', size = 'normal', richness = 'normal'}
}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
-- map_gen_settings.autoplace_settings = { entity = { treat_missing_as_default = false, settings = { frequency = 'none', size = 'none', richness = 'none' } }, decorative = { treat_missing_as_default = true, settings = { frequency = 'none', size = 'none', richness = 'none' } } }
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
-- map_gen_settings.default_enable_all_autoplace_controls = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if game.surfaces.tank_conquest == nil then
game.create_surface('tank_conquest', map_gen_settings)
else
rendering.clear()
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.surfaces.tank_conquest.clear()
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.surfaces.tank_conquest.map_gen_settings = map_gen_settings
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function draw_gui_button(player)
if player.gui.top['draw_gui_button'] then
player.gui.top['draw_gui_button'].destroy()
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
player.gui.top.add({type = 'sprite-button', name = 'draw_gui_button', sprite = 'item/tank', tooltip = 'MENU'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
-- player.gui.top.add( { type = 'sprite-button', name = 'draw_gui_button_score', sprite = 'item/heavy-armor', tooltip = 'SCORE' } )
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
-- player.gui.top.add( { type = 'sprite-button', name = 'draw_gui_button_squad', sprite = 'item/personal-roboport-equipment', tooltip = 'SQUAD' } )
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function draw_gui_status(player)
if player.gui.top['draw_gui_status'] then
player.gui.top['draw_gui_status'].destroy()
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_properties.game_stage ~= 'ongoing_game' then
return
end
2019-07-28 00:04:58 +02:00
2021-03-24 17:46:00 +02:00
if player.force.name == 'force_spectator' then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if #global.table_of_spots == 0 then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_frame = player.gui.top.add({type = 'frame', name = 'draw_gui_status', direction = 'horizontal'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.height = 38
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.margin = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.padding = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.left_padding = 20
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.right_padding = 20
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.vertical_align = 'center'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_progressbar = element_frame.add({type = 'progressbar', value = 100})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_progressbar.style.width = 125
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_progressbar.style.right_padding = 20
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_progressbar.style.top_padding = 10
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_progressbar.style.color = table_of_colors.team
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_frame.add({type = 'label', caption = math.floor(global.table_of_properties[player.force.name].available_tickets)})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.font_color = table_of_colors.white
2021-03-24 17:46:00 +02:00
local element_label = element_frame.add({type = 'label', caption = global.table_of_properties[player.force.name].icon})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.left_padding = 20
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.font_color = table_of_colors.white
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_frame.add({type = 'label', caption = seconds_to_clock(global.table_of_properties.countdown_in_seconds)})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.left_padding = 20
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.right_padding = 20
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.font_color = table_of_colors.white
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_frame.add({type = 'label', caption = global.table_of_properties[global.table_of_properties[player.force.name].enemy].icon})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.font_color = table_of_colors.white
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label =
element_frame.add({type = 'label', caption = math.floor(global.table_of_properties[global.table_of_properties[player.force.name].enemy].available_tickets)})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.left_padding = 20
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.font_color = table_of_colors.white
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_progressbar = element_frame.add({type = 'progressbar', value = 100})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_progressbar.style.width = 125
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_progressbar.style.left_padding = 20
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_progressbar.style.top_padding = 10
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_progressbar.style.color = table_of_colors.enemy
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, element_item in pairs(element_frame.children) do
element_item.style.font = 'heading-1'
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function draw_gui_spots(player)
if player.gui.top['draw_gui_spots'] then
player.gui.top['draw_gui_spots'].destroy()
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_properties.game_stage ~= 'ongoing_game' then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if player.force.name == 'force_spectator' then
return
end
2019-07-25 14:45:53 +02:00
2021-03-24 17:46:00 +02:00
if #global.table_of_spots == 0 then
return
end
2019-07-25 14:45:53 +02:00
2021-03-24 17:46:00 +02:00
local element_frame = player.gui.top.add({type = 'frame', name = 'draw_gui_spots', direction = 'horizontal'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.height = 38
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.margin = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.padding = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.vertical_align = 'center'
2021-03-24 17:46:00 +02:00
element_frame.style.horizontal_align = 'center'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, spot in pairs(global.table_of_spots) do
local element_label = element_frame.add({type = 'label', caption = spot.properties.name})
2019-07-25 14:45:53 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.width = 38
2019-07-25 14:45:53 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.height = 38
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.margin = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.padding = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.vertical_align = 'top'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.horizontal_align = 'center'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_label.style.font = 'heading-1'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local color = table_of_colors.white
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if player.force.name ~= 'force_spectator' then
color = table_of_colors.neutral
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if spot.properties.force.name == global.table_of_properties[player.force.name].name and spot.properties.value == 100 then
color = table_of_colors.team
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
if spot.properties.force.name == global.table_of_properties[player.force.name].enemy and spot.properties.value == 100 then
color = table_of_colors.enemy
end
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
element_label.style.font_color = color
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function draw_gui_menu(player)
if player.gui.center['draw_gui_menu'] then
player.gui.center['draw_gui_menu'].destroy()
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
local element_frame = player.gui.center.add({type = 'frame', name = 'draw_gui_menu', direction = 'vertical'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.padding = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.margin = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if game.permissions.get_group('Default').players[player.index] == nil then
element_frame.add({type = 'sprite-button', name = 'event_on_click_join', caption = 'JOIN'})
else
element_frame.add({type = 'sprite-button', name = 'event_on_click_lobby', caption = 'LOBBY'})
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, element_item in pairs(element_frame.children) do
element_item.style.padding = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.margin = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.minimal_width = 170
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.minimal_height = 170
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.font = 'heading-1'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.font_color = table_of_colors.white
end
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function draw_gui_score(player)
if player.gui.center['draw_gui_score'] then
player.gui.center['draw_gui_score'].destroy()
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_frame = player.gui.center.add({type = 'frame', name = 'draw_gui_score', direction = 'vertical'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.padding = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.margin = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.vertical_align = 'center'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.horizontal_align = 'center'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_table = element_frame.add({type = 'table', column_count = 14, draw_horizontal_lines = true})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_table.style.padding = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_table.style.top_padding = 5
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_table.style.left_padding = 10
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_table.style.bottom_padding = 5
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_table.style.margin = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_table.style.vertical_align = 'center'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_table.style.horizontal_align = 'center'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = global.table_of_properties[player.force.name].icon})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = '#'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = 'NAME'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = 'CLASS'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = 'K'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = 'D'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = 'POINTS'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = global.table_of_properties[global.table_of_properties[player.force.name].enemy].icon})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = '#'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = 'NAME'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = 'CLASS'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = 'K'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = 'D'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = 'POINTS'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for index = 1, 28 do
local element_label = element_table.add({type = 'label', caption = ''})
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
for _, element_item in pairs(element_table.children) do
element_item.style.padding = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.right_padding = 10
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.margin = 0
2019-07-27 23:19:37 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.vertical_align = 'center'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.font = 'heading-2'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.font_color = table_of_colors.white
end
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function draw_gui_squad(player)
if player.gui.left['draw_gui_squad'] then
player.gui.left['draw_gui_squad'].destroy()
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_properties.game_stage ~= 'ongoing_game' then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_frame = player.gui.left.add({type = 'frame', name = 'draw_gui_squad', direction = 'vertical'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.minimal_width = 50
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.padding = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.margin = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.top_margin = 5
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_frame.style.left_margin = 5
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_table = element_frame.add({type = 'table', column_count = 4})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_table.style.padding = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_table.style.margin = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for index = 1, 8 do
local element_label = element_table.add({type = 'label', caption = 'SQUAD ' .. index})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_button = element_table.add({type = 'sprite-button', name = 'aaa_' .. index, caption = 'JOIN'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_button.style.width = 50
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_button.style.height = 25
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = ''})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = ''})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = ''})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local element_label = element_table.add({type = 'label', caption = ''})
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, element_item in pairs(element_table.children) do
element_item.style.minimal_width = 50
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.padding = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.margin = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.vertical_align = 'center'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.horizontal_align = 'center'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.font = 'heading-2'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.font_color = table_of_colors.white
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function draw_gui_spawn(player)
if player.gui.center['draw_gui_spawn'] then
player.gui.center['draw_gui_spawn'].destroy()
end
2019-08-07 22:51:47 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_properties.game_stage ~= 'ongoing_game' then
return
end
2019-08-07 22:51:47 +02:00
2021-03-24 17:46:00 +02:00
local element_frame = player.gui.center.add({type = 'frame', name = 'draw_gui_spawn', direction = 'horizontal'})
2019-08-07 22:51:47 +02:00
2021-03-24 17:46:00 +02:00
local element_button = element_frame.add({type = 'button', name = 'event_on_click_spawn_base', caption = 'BASE'})
2019-08-07 22:51:47 +02:00
2021-03-24 17:46:00 +02:00
-- element_button.style.color = table_of_colors.damage
2019-08-07 22:51:47 +02:00
2021-03-24 17:46:00 +02:00
element_button.style.font_color = table_of_colors.white
2019-08-07 22:51:47 +02:00
2021-03-24 17:46:00 +02:00
for index, spot in pairs(global.table_of_spots) do
local element_button = element_frame.add({type = 'button', name = 'event_on_click_spawn_' .. index, caption = spot.properties.name})
2019-08-07 22:51:47 +02:00
2021-03-24 17:46:00 +02:00
-- element_button.enabled = false
2019-08-07 22:51:47 +02:00
2021-03-24 17:46:00 +02:00
local color = table_of_colors.neutral
2019-08-07 22:51:47 +02:00
2021-03-24 17:46:00 +02:00
-- if spot.properties.force.name == global.table_of_properties[ player.force.name ].name and spot.properties.value >= 50 then element_button.enabled = true end
2019-08-07 22:51:47 +02:00
2021-03-24 17:46:00 +02:00
if spot.properties.force.name == global.table_of_properties[player.force.name].name and spot.properties.value > 0 then
color = table_of_colors.team
2019-08-07 22:51:47 +02:00
end
2021-03-24 17:46:00 +02:00
if spot.properties.force.name == global.table_of_properties[player.force.name].enemy and spot.properties.value > 0 then
color = table_of_colors.enemy
2019-08-07 22:51:47 +02:00
end
2021-03-24 17:46:00 +02:00
element_button.style.font_color = color
2019-08-07 22:51:47 +02:00
end
2021-03-24 17:46:00 +02:00
for _, element_item in pairs(element_frame.children) do
element_item.style.width = 100
2019-08-18 20:26:43 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.height = 100
2019-08-18 20:26:43 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.padding = 0
2019-08-18 20:26:43 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.margin = 0
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.vertical_align = 'center'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.horizontal_align = 'center'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
element_item.style.font = 'heading-2'
end
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function create_a_tank(player)
player.insert({name = 'light-armor', count = 1})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
player.insert({name = 'submachine-gun', count = 1})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
player.insert({name = 'firearm-magazine', count = 50})
2021-03-24 17:46:00 +02:00
player.insert({name = 'raw-fish', count = 10})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
player.insert({name = 'explosive-cannon-shell', count = 5})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_entities = player.surface.find_entities_filtered({name = 'tank', force = player.force.name})
2019-07-25 20:19:03 +02:00
2021-03-24 17:46:00 +02:00
if #table_of_entities < #player.force.connected_players then
local position = player.surface.find_non_colliding_position('tank', player.position, 64, 4)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if not position then
position = {0, 0}
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
local entity = player.surface.create_entity({name = 'tank', position = position, force = player.force.name})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if not entity then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.minable = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.last_user = player.name
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.insert({name = 'wood', count = 50})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.insert({name = 'cannon-shell', count = 50})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.set_driver(player)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_tanks[player.index] = entity
end
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function create_a_base(force_name, base_position)
local surface = game.surfaces.tank_conquest
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_items = game.json_to_table(blueprint_poi_base_json)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, tile in pairs(table_of_items.blueprint.tiles) do
tile.position = {x = tile.position.x + base_position.x, y = tile.position.y + base_position.y + 10}
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
surface.set_tiles(table_of_items.blueprint.tiles, true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, object in pairs(table_of_items.blueprint.entities) do
object.force = game.forces[force_name]
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
object.position = {x = object.position.x + base_position.x, y = object.position.y + base_position.y + 10}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local entity = surface.create_entity(object)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if not entity then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if
object.name == 'infinity-chest' or object.name == 'substation' or object.name == 'big-electric-pole' or object.name == 'medium-electric-pole' or
object.name == 'inserter' or
object.name == 'accumulator' or
object.name == 'solar-panel' or
object.name == 'gun-turret'
then
entity.destructible = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.minable = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.rotatable = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.operable = false
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if object.name == 'wooden-chest' then
entity.destructible = false
2021-03-24 17:46:00 +02:00
entity.minable = false
2021-03-24 17:46:00 +02:00
entity.rotatable = false
end
2021-03-24 17:46:00 +02:00
if object.name == 'stone-wall' or object.name == 'gate' or object.name == 'land-mine' then
entity.destructible = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.minable = false
2019-07-24 19:42:27 +02:00
end
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function create_a_spot(spot_name, spot_position, spot_blueprint)
local surface = game.surfaces.tank_conquest
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local spot = {name = spot_name, position = spot_position, force = {name = 'neutral'}, value = 0, color = table_of_colors.white}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_positions = {}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for x = 1, 18 do
for y = 1, 18 do
table.insert(table_of_positions, {x = math.floor(spot.position.x + x - 9), y = math.floor(spot.position.y + y - 9)})
end
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_players = {}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local draw_spot_border =
rendering.draw_rectangle(
{
surface = surface,
target = spot.position,
color = spot.color,
left_top = {spot.position.x - 9, spot.position.y - 9},
right_bottom = {spot.position.x + 9, spot.position.y + 9},
width = 5,
filled = false,
draw_on_ground = true
}
)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local draw_spot_force =
rendering.draw_text({text = spot.force.name, surface = surface, target = {spot.position.x, spot.position.y + 0.5}, color = spot.color, scale = 5, alignment = 'center'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local draw_spot_value =
rendering.draw_text({text = spot.value, surface = surface, target = {spot.position.x, spot.position.y - 4}, color = spot.color, scale = 5, alignment = 'center'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local draw_spot_name =
rendering.draw_text({text = spot.name, surface = surface, target = {spot.position.x, spot.position.y - 2}, color = spot.color, scale = 5, alignment = 'center'})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_drawings = {name = draw_spot_name, value = draw_spot_value, force = draw_spot_force, border = draw_spot_border}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_properties = {name = spot.name, position = spot.position, value = spot.value, force = spot.force, color = spot.color}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_entities = {}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_items = game.json_to_table(spot_blueprint)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, tile in pairs(table_of_items.blueprint.tiles) do
tile.position = {x = tile.position.x + spot.position.x - 1, y = tile.position.y + spot.position.y - 1}
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
surface.set_tiles(table_of_items.blueprint.tiles, true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, object in pairs(table_of_items.blueprint.entities) do
object.force = 'enemy'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
object.position = {x = object.position.x + spot.position.x - 1, y = object.position.y + spot.position.y - 1}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local entity = surface.create_entity(object)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if not entity then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if object.name == 'infinity-chest' or object.name == 'substation' or object.name == 'inserter' or object.name == 'accumulator' or object.name == 'solar-panel' then
entity.destructible = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.minable = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.rotatable = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.operable = false
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if object.name == 'wooden-chest' then
entity.force = 'neutral'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.destructible = false
2021-03-24 17:46:00 +02:00
entity.minable = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.rotatable = false
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
if object.name == 'stone-wall' or object.name == 'gate' or object.name == 'land-mine' then
entity.minable = false
end
2021-03-24 17:46:00 +02:00
table.insert(table_of_entities, entity)
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
table.insert(
global.table_of_spots,
{properties = table_of_properties, drawings = table_of_drawings, players = table_of_players, positions = table_of_positions, entities = table_of_entities}
)
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function create_a_point_of_interest(poi_blueprint, poi_position)
local surface = game.surfaces.tank_conquest
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_items = game.json_to_table(poi_blueprint)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, tile in pairs(table_of_items.blueprint.tiles) do
tile.position = {x = tile.position.x + poi_position.x, y = tile.position.y + poi_position.y}
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
surface.set_tiles(table_of_items.blueprint.tiles, true)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, object in pairs(table_of_items.blueprint.entities) do
object.force = 'enemy'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
object.position = {x = object.position.x + poi_position.x, y = object.position.y + poi_position.y}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local entity = surface.create_entity(object)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if not entity then
return
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
if object.name == 'infinity-chest' or object.name == 'substation' or object.name == 'inserter' or object.name == 'accumulator' or object.name == 'solar-panel' then
entity.destructible = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.minable = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.rotatable = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.operable = false
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if object.name == 'wooden-chest' then
entity.force = 'neutral'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.destructible = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.minable = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.rotatable = false
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
if object.name == 'stone-wall' or object.name == 'gate' or object.name == 'land-mine' then
entity.minable = false
end
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function seconds_to_clock(seconds)
local seconds = tonumber(seconds)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if seconds <= 0 then
return '00:00:00'
else
local hours = string.format('%02.f', math.floor(seconds / 3600))
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local minutes = string.format('%02.f', math.floor(seconds / 60 - (hours * 60)))
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
seconds = string.format('%02.f', math.floor(seconds - hours * 3600 - minutes * 60))
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
return hours .. ':' .. minutes .. ':' .. seconds
end
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function draw_a_polygon(position, radius, angle, sides)
if not type(position) == 'table' then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if not type(radius) == 'number' then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if not type(angle) == 'number' then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if not type(sides) == 'number' then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_positions = {}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
table.insert(table_of_positions, {x = position.x, y = position.y})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for index = 1, sides + 1 do
local x = table_of_positions[1].x + (radius * math.cos(angle + (index + index - 1) * math.pi / sides))
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local y = table_of_positions[1].y + (radius * math.sin(angle + (index + index - 1) * math.pi / sides))
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
table.insert(table_of_positions, {x = x, y = y})
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
return table_of_positions
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function draw_circle_lobby(surface, spawn_diameter, spawn_position)
for x = -spawn_diameter, spawn_diameter do
for y = -spawn_diameter, spawn_diameter do
local tile_position = {x = spawn_position.x + x, y = spawn_position.y + y}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local distance_to_center = math.sqrt(tile_position.x ^ 2 + tile_position.y ^ 2)
2019-07-24 19:42:27 +02:00
local tile_name = false
if distance_to_center < spawn_diameter then
tile_name = 'deepwater'
2021-03-24 17:46:00 +02:00
if math.random(1, 48) == 1 then
surface.create_entity({name = 'fish', position = tile_position})
end
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
if distance_to_center < 9.5 then
tile_name = 'refined-concrete'
end
2021-03-24 17:46:00 +02:00
if distance_to_center < 7 then
tile_name = 'sand-1'
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if tile_name then
surface.set_tiles({{name = tile_name, position = tile_position}}, true)
end
2019-07-24 19:42:27 +02:00
end
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function event_on_click_join(player)
if global.table_of_properties.game_stage ~= 'ongoing_game' then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local surface = game.surfaces.tank_conquest
2021-03-24 17:46:00 +02:00
if not surface then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if not player.character then
return
end
2021-03-24 17:46:00 +02:00
game.permissions.get_group('Default').add_player(player)
2021-03-24 17:46:00 +02:00
if player.force.name == 'force_spectator' then
if #game.forces.force_player_one.connected_players == #game.forces.force_player_two.connected_players then
local table_of_forces = {'force_player_one', 'force_player_two'}
2021-03-24 17:46:00 +02:00
player.force = game.forces[table_of_forces[math.random(1, #table_of_forces)]]
elseif #game.forces.force_player_one.connected_players < #game.forces.force_player_two.connected_players then
player.force = game.forces.force_player_one
else
player.force = game.forces.force_player_two
end
2021-03-24 17:46:00 +02:00
end
2021-03-24 17:46:00 +02:00
local position = player.force.get_spawn_position(surface)
2021-03-24 17:46:00 +02:00
global.table_of_spawns[player.index] = position
2021-03-24 17:46:00 +02:00
if surface.is_chunk_generated(position) then
player.teleport(surface.find_non_colliding_position('character', position, 3, 0.5), surface)
else
player.teleport(position, surface)
end
2019-08-18 20:26:43 +02:00
2021-03-24 17:46:00 +02:00
player.character.destructible = true
2021-03-24 17:46:00 +02:00
player_icon_add(player)
2021-03-24 17:46:00 +02:00
create_a_tank(player)
2021-03-24 17:46:00 +02:00
-- draw_gui_spawn( player ) -- only for tests
2021-03-24 17:46:00 +02:00
for _, spot in pairs(global.table_of_spots) do
player.force.chart(
game.surfaces.tank_conquest,
{{x = spot.properties.position.x - 10, y = spot.properties.position.y - 10}, {x = spot.properties.position.x + 10, y = spot.properties.position.y + 10}}
)
end
2021-03-24 17:46:00 +02:00
game.print(player.name .. ' joined ' .. global.table_of_properties[player.force.name].icon)
end
2019-08-18 20:26:43 +02:00
2021-03-24 17:46:00 +02:00
function event_on_click_lobby(player)
local surface = game.surfaces.nauvis
2019-08-18 20:26:43 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_properties.game_stage == 'ongoing_game' then
surface = game.surfaces.tank_conquest
2019-08-18 20:26:43 +02:00
end
2021-03-24 17:46:00 +02:00
if not player.character then
return
end
2021-03-24 17:46:00 +02:00
game.permissions.get_group('permission_spectator').add_player(player)
2021-03-24 17:46:00 +02:00
player.force = game.forces.force_spectator
2021-03-24 17:46:00 +02:00
if global.table_of_tanks[player.index] ~= nil and global.table_of_tanks[player.index].valid then
global.table_of_tanks[player.index].clear_items_inside()
2021-03-24 17:46:00 +02:00
global.table_of_tanks[player.index].destroy()
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
global.table_of_tanks[player.index] = nil
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local position = {x = 0, y = 0}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_spawns[player.index] = position
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if surface.is_chunk_generated(position) then
player.teleport(surface.find_non_colliding_position('character', position, 3, 0.5), surface)
else
player.teleport(position, surface)
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
player.character.destructible = false
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
player_icon_remove(player)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
player.character.clear_items_inside()
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function event_on_click_spawn(player)
game.print('A')
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
function shuffle(table_of_items)
local length_of_items = #table_of_items
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for index = length_of_items, 1, -1 do
local random = math.random(length_of_items)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
table_of_items[index], table_of_items[random] = table_of_items[random], table_of_items[index]
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
return table_of_items
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local function on_init(surface)
game.surfaces.nauvis.clear()
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.surfaces.nauvis.map_gen_settings = {width = 1, height = 1}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.create_surface('tank_conquest', {width = 1, height = 1})
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
initialize_forces()
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
-- global.table_of_properties.game_stage = 'do_nothing'
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
event.on_init(on_init)
2021-03-24 17:46:00 +02:00
local function on_tick(event)
if game.tick % 30 == 0 and global.table_of_damages ~= nil then
for _, item in pairs(global.table_of_damages) do
item.surface.create_entity({name = 'flying-text', position = item.position, text = math.ceil(item.damage), color = table_of_colors.damage})
end
2021-03-24 17:46:00 +02:00
global.table_of_damages = nil
end
2021-03-24 17:46:00 +02:00
if game.tick % 60 == 0 then
if global.table_of_properties.game_stage == 'ongoing_game' then
for _, spot in pairs(global.table_of_spots) do
if spot.properties.value == 100 then
local enemy = global.table_of_properties[spot.properties.force.name].enemy
2021-03-24 17:46:00 +02:00
if global.table_of_properties[enemy].available_tickets >= 0 then
global.table_of_properties[enemy].available_tickets = global.table_of_properties[enemy].available_tickets - global.table_of_properties.acceleration_value
end
end
2021-03-24 17:46:00 +02:00
for _, player in pairs(game.connected_players) do
if player.force.name == spot.properties.force.name and spot.properties.value > 0 then
player.force.chart(
game.surfaces.tank_conquest,
{{x = spot.properties.position.x - 10, y = spot.properties.position.y - 10}, {x = spot.properties.position.x + 10, y = spot.properties.position.y + 10}}
)
end
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, player in pairs(spot.players) do
if spot.properties.force.name == 'neutral' and spot.properties.value == 0 then
spot.properties.force.name = player.force.name
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, entity in pairs(spot.entities) do
if entity.valid then
entity.force = player.force.name
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if entity.name == 'stone-wall' or entity.name == 'gate' or entity.name == 'land-mine' then
entity.minable = true
end
end
end
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
if spot.properties.force.name == 'neutral' or spot.properties.force.name == player.force.name and spot.properties.value < 100 then
spot.properties.value = spot.properties.value + 1 * global.table_of_properties.conquest_speed
end
2021-03-24 17:46:00 +02:00
if spot.properties.force.name ~= player.force.name and spot.properties.value > 0 then
spot.properties.value = spot.properties.value - 1 * global.table_of_properties.conquest_speed
end
2021-03-24 17:46:00 +02:00
if spot.properties.value == 0 then
spot.properties.force.name = 'neutral'
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local force_label = spot.properties.force.name
2019-08-05 20:02:47 +02:00
2021-03-24 17:46:00 +02:00
if force_label ~= 'neutral' then
force_label = global.table_of_properties[force_label].icon
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
rendering.set_text(spot.drawings.force, force_label)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
rendering.set_text(spot.drawings.value, spot.properties.value)
end
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_properties.countdown_in_seconds == 60 then
game.print('The round is in the hot phase, there are still 60 seconds left.')
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_properties.countdown_in_seconds >= 0 then
global.table_of_properties.countdown_in_seconds = global.table_of_properties.countdown_in_seconds - 1
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if
global.table_of_properties.countdown_in_seconds < 0 or global.table_of_properties.force_player_one.available_tickets < 0 or
global.table_of_properties.force_player_two.available_tickets < 0
then
if global.table_of_properties.force_player_one.available_tickets == global.table_of_properties.force_player_two.available_tickets then
game.print('The battle is over. The round ended in a draw.')
elseif global.table_of_properties.force_player_one.available_tickets > global.table_of_properties.force_player_two.available_tickets then
game.print('The battle is over. Force ' .. global.table_of_properties.force_player_one.icon .. ' has won the round.')
else
game.print('The battle is over. Force ' .. global.table_of_properties.force_player_two.icon .. ' has won the round.')
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.forces.force_spectator.set_spawn_position({x = 0, y = 0}, game.surfaces.nauvis)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_spots = {}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_properties.force_player_one.available_tickets = global.table_of_properties.amount_of_tickets
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_properties.force_player_two.available_tickets = global.table_of_properties.amount_of_tickets
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_properties.countdown_in_seconds = 28800
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_properties.wait_in_seconds = 30
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_properties.game_stage = 'lobby'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.print('You are now in the lobby, please make yourself comfortable, it continues immediately.')
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, player in pairs(game.connected_players) do
if player.gui.top['draw_gui_button'] then
player.gui.top['draw_gui_button'].destroy()
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if player.gui.top['draw_gui_status'] then
player.gui.top['draw_gui_status'].destroy()
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
if player.gui.top['draw_gui_spots'] then
player.gui.top['draw_gui_spots'].destroy()
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
-- if player.gui.left[ 'draw_gui_squad' ] then player.gui.left[ 'draw_gui_squad' ].destroy() end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
-- if player.gui.center[ 'draw_gui_menu' ] then player.gui.center[ 'draw_gui_menu' ].destroy() end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
-- draw_gui_score( player )
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
event_on_click_lobby(player)
2019-07-24 19:42:27 +02:00
end
end
2021-03-24 17:46:00 +02:00
for _, player in pairs(game.connected_players) do
draw_gui_status(player)
2019-08-05 20:02:47 +02:00
2021-03-24 17:46:00 +02:00
draw_gui_spots(player)
end
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_properties.game_stage == 'regenerate_facilities' then
table_of_ores = shuffle(table_of_ores)
2021-03-24 17:46:00 +02:00
local position = game.forces.force_spectator.get_spawn_position(game.surfaces.tank_conquest)
2021-03-24 17:46:00 +02:00
draw_circle_lobby(game.surfaces.tank_conquest, 28, position)
2021-03-24 17:46:00 +02:00
local position = game.forces.force_player_one.get_spawn_position(game.surfaces.tank_conquest)
2021-03-24 17:46:00 +02:00
map_functions.draw_noise_tile_circle({x = position.x - 50, y = 10}, 'water', game.surfaces.tank_conquest, math.random(8, 10))
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local radius, angle, sides = 10, 1, #table_of_ores
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_positions = draw_a_polygon({x = position.x - 50, y = 10}, radius, angle, sides)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for index = 1, #table_of_positions do
map_functions.draw_smoothed_out_ore_circle(table_of_positions[index + 1], table_of_ores[index], game.surfaces.tank_conquest, 15, 3000)
end
2021-03-24 17:46:00 +02:00
create_a_base('force_player_one', position)
2021-03-24 17:46:00 +02:00
local position = game.forces.force_player_two.get_spawn_position(game.surfaces.tank_conquest)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
map_functions.draw_noise_tile_circle({x = position.x + 50, y = 10}, 'water', game.surfaces.tank_conquest, math.random(8, 10))
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local radius, angle, sides = 10, 1, #table_of_ores
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_positions = draw_a_polygon({x = position.x + 50, y = 10}, radius, angle, sides)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for index = 1, #table_of_positions do
map_functions.draw_smoothed_out_ore_circle(table_of_positions[index + 1], table_of_ores[index], game.surfaces.tank_conquest, 15, 3000)
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
create_a_base('force_player_two', position)
2021-03-24 17:46:00 +02:00
local position = {x = 0, y = -500}
2021-03-24 17:46:00 +02:00
create_a_point_of_interest(blueprint_poi_laser_json, position)
2021-03-24 17:46:00 +02:00
local position = {x = 0, y = 500}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
create_a_point_of_interest(blueprint_poi_fire_json, position)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_blueprints = {blueprint_poi_spot_one_json, blueprint_poi_spot_two_json, blueprint_poi_spot_three_json}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_names = {'A', 'B', 'C', 'D', 'E', 'F', 'G'}
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local length_of_names = math.random(3, #table_of_names)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local position, radius, angle, sides = {x = 0, y = 0}, math.random(150, 250), math.random(0.1, 6.3), length_of_names
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_positions = draw_a_polygon(position, radius, angle, sides)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for index = 1, length_of_names do
create_a_spot(table_of_names[index], table_of_positions[index + 1], table_of_blueprints[math.random(1, #table_of_blueprints)])
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
game.print('A new battlefield was created. Make yourself comfortable, but be vigilant.')
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_properties.game_stage = 'ongoing_game'
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, player in pairs(game.connected_players) do
-- if player.gui.left[ 'draw_gui_squad' ] then player.gui.left[ 'draw_gui_squad' ].destroy() end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
-- if player.gui.center[ 'draw_gui_score' ] then player.gui.center[ 'draw_gui_score' ].destroy() end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if player.gui.center['draw_gui_menu'] then
player.gui.center['draw_gui_menu'].destroy()
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
draw_gui_button(player)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
event_on_click_join(player)
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_properties.game_stage == 'preparing_spawn_positions' then
game.forces.force_player_one.set_spawn_position({x = -500, y = 0}, game.surfaces.tank_conquest)
2021-03-24 17:46:00 +02:00
game.forces.force_player_two.set_spawn_position({x = 500, y = 0}, game.surfaces.tank_conquest)
2021-03-24 17:46:00 +02:00
game.forces.force_spectator.set_spawn_position({x = 0, y = 0}, game.surfaces.tank_conquest)
2021-03-24 17:46:00 +02:00
global.table_of_scores = {}
2021-03-24 17:46:00 +02:00
for _, player in pairs(game.connected_players) do
if player.character then
player.character.destroy()
2021-03-24 17:46:00 +02:00
player.character = nil
end
2021-03-24 17:46:00 +02:00
player.create_character()
end
2021-03-24 17:46:00 +02:00
global.table_of_properties.game_stage = 'regenerate_facilities'
end
if global.table_of_properties.game_stage == 'check_the_process_of_creating_the_map' then
if game.surfaces.tank_conquest.is_chunk_generated({x = 0, y = 0}) then
global.table_of_properties.game_stage = 'preparing_spawn_positions'
else
game.surfaces.tank_conquest.request_to_generate_chunks({0, 0}, 1)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.surfaces.tank_conquest.request_to_generate_chunks({-500, 0}, 1)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.surfaces.tank_conquest.request_to_generate_chunks({500, 0}, 1)
2021-03-24 17:46:00 +02:00
game.surfaces.tank_conquest.request_to_generate_chunks({0, -500}, 1)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.surfaces.tank_conquest.request_to_generate_chunks({0, 500}, 1)
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_properties.game_stage == 'regenerate_battlefield' and global.table_of_properties.wait_in_seconds == 0 then
initialize_surface()
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
game.surfaces.tank_conquest.force_generate_chunk_requests()
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_properties.game_stage = 'check_the_process_of_creating_the_map'
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_properties.game_stage == 'lobby' then
if #game.connected_players >= global.table_of_properties.required_number_of_players and global.table_of_properties.wait_in_seconds > 0 then
if global.table_of_properties.wait_in_seconds % 10 == 0 then
game.print('The round starts in ' .. global.table_of_properties.wait_in_seconds .. ' seconds.')
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
global.table_of_properties.wait_in_seconds = global.table_of_properties.wait_in_seconds - 1
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
if global.table_of_properties.wait_in_seconds == 0 then
global.table_of_properties.game_stage = 'regenerate_battlefield'
end
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if game.tick % 1800 == 0 then
if game.surfaces.tank_conquest ~= nil and #game.connected_players and #global.table_of_spots then
for _, player in pairs(game.connected_players) do
for _, spot in pairs(global.table_of_spots) do
if
player.force.is_chunk_charted(
game.surfaces.tank_conquest,
{x = math.floor(spot.properties.position.x / 32), y = math.floor(spot.properties.position.y / 32)}
)
then
local chart_tags =
player.force.find_chart_tags(
game.surfaces.tank_conquest,
{{spot.properties.position.x - 1, spot.properties.position.y - 1}, {spot.properties.position.x + 1, spot.properties.position.y + 1}}
)
if #chart_tags == 0 then
player.force.add_chart_tag(
game.surfaces.tank_conquest,
{icon = {type = 'virtual', name = 'signal-' .. spot.properties.name}, position = spot.properties.position}
)
end
end
end
end
end
2021-03-24 17:46:00 +02:00
end
2021-03-24 17:46:00 +02:00
if game.tick == 60 then
draw_circle_lobby(game.surfaces.nauvis, 28, {x = 0, y = 0})
2021-03-24 17:46:00 +02:00
for _, player in pairs(game.connected_players) do
if player.character == nil then
player.create_character()
end
end
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
event.add(defines.events.on_tick, on_tick)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local function on_gui_click(event)
local player = game.players[event.player_index]
2021-03-24 17:46:00 +02:00
if event.element.valid and event.element.name == 'draw_gui_intro_content' then
player.gui.center['draw_gui_intro_frame'].destroy()
return
end
2021-03-24 17:46:00 +02:00
if event.element.valid and event.element.name == 'draw_gui_intro_button' then
if player.gui.center['draw_gui_intro_frame'] then
player.gui.center['draw_gui_intro_frame'].destroy()
else
draw_gui_intro_frame(player)
end
2021-03-24 17:46:00 +02:00
end
2021-03-24 17:46:00 +02:00
if event.element.valid and event.element.name == 'draw_gui_button' then
if player.gui.center['draw_gui_menu'] then
player.gui.center['draw_gui_menu'].destroy()
else
draw_gui_menu(player)
end
2021-03-24 17:46:00 +02:00
end
2021-03-24 17:46:00 +02:00
if event.element.valid and event.element.name == 'event_on_click_score' then
if player.gui.center['draw_gui_score'] then
player.gui.center['draw_gui_score'].destroy()
else
draw_gui_score(player)
end
2021-03-24 17:46:00 +02:00
end
2021-03-24 17:46:00 +02:00
if event.element.valid and event.element.name == 'event_on_click_squad' then
if player.gui.left['draw_gui_squad'] then
player.gui.left['draw_gui_squad'].destroy()
else
draw_gui_squad(player)
end
2021-03-24 17:46:00 +02:00
end
2021-03-24 17:46:00 +02:00
if event.element.valid and event.element.name == 'event_on_click_lobby' then
global.table_of_delays[player.index] = game.tick
2021-03-24 17:46:00 +02:00
game.print(player.name .. ' is spectating')
2021-03-24 17:46:00 +02:00
event_on_click_lobby(player)
2021-03-24 17:46:00 +02:00
if player.gui.center['draw_gui_menu'] then
player.gui.center['draw_gui_menu'].destroy()
end
2021-03-24 17:46:00 +02:00
end
2021-03-24 17:46:00 +02:00
if event.element.valid and event.element.name == 'event_on_click_join' then
if game.tick - global.table_of_delays[player.index] < 3600 then
player.print('Not ready to return. Please wait ' .. 60 - (math.floor((game.tick - global.table_of_delays[player.index]) / 60)) .. ' seconds.')
else
global.table_of_delays[player.index] = nil
2021-03-24 17:46:00 +02:00
event_on_click_join(player)
2021-03-24 17:46:00 +02:00
if player.gui.center['draw_gui_menu'] then
player.gui.center['draw_gui_menu'].destroy()
end
end
end
2021-03-24 17:46:00 +02:00
if event.element.valid and event.element.name == 'event_on_click_spawn_1' then
event_on_click_spawn(player)
end
end
2021-03-24 17:46:00 +02:00
event.add(defines.events.on_gui_click, on_gui_click)
2021-03-24 17:46:00 +02:00
local function on_console_chat(event)
if not event.message then
return
end
2021-03-24 17:46:00 +02:00
if not event.player_index then
return
end
2021-03-24 17:46:00 +02:00
local player = game.players[event.player_index]
2021-03-24 17:46:00 +02:00
local color = {r = player.color.r * 0.6 + 0.35, g = player.color.g * 0.6 + 0.35, b = player.color.b * 0.6 + 0.35, a = 1}
2021-03-24 17:46:00 +02:00
if player.force.name == 'force_player_one' then
game.forces.force_player_two.print(global.table_of_properties[player.force.name].icon .. ' ' .. player.name .. ': ' .. event.message, color)
2021-03-24 17:46:00 +02:00
game.forces.force_spectator.print(global.table_of_properties[player.force.name].icon .. ' ' .. player.name .. ': ' .. event.message, color)
end
2021-03-24 17:46:00 +02:00
if player.force.name == 'force_player_two' then
game.forces.force_player_one.print(global.table_of_properties[player.force.name].icon .. ' ' .. player.name .. ': ' .. event.message, color)
2021-03-24 17:46:00 +02:00
game.forces.force_spectator.print(global.table_of_properties[player.force.name].icon .. ' ' .. player.name .. ': ' .. event.message, color)
end
2021-03-24 17:46:00 +02:00
if player.force.name == 'force_spectator' then
game.forces.force_player_one.print('(Spectator) ' .. player.name .. ': ' .. event.message, color)
2021-03-24 17:46:00 +02:00
game.forces.force_player_two.print('(Spectator) ' .. player.name .. ': ' .. event.message, color)
end
end
2021-03-24 17:46:00 +02:00
event.add(defines.events.on_console_chat, on_console_chat)
2021-03-24 17:46:00 +02:00
local function on_chunk_generated(event)
local chunk_position = {x = event.area.left_top.x, y = event.area.left_top.y}
2021-03-24 17:46:00 +02:00
for x = 0, 31 do
for y = 0, 31 do
local tile_position = {x = chunk_position.x + x, y = chunk_position.y + y}
2021-03-24 17:46:00 +02:00
if math.random(1, 3000) == 1 and event.surface.can_place_entity({name = 'wooden-chest', force = 'enemy', position = tile_position}) then
event.surface.create_entity({name = 'wooden-chest', force = 'enemy', position = tile_position})
end
end
end
2021-03-24 17:46:00 +02:00
end
2021-03-24 17:46:00 +02:00
event.add(defines.events.on_chunk_generated, on_chunk_generated)
2021-03-24 17:46:00 +02:00
local function on_entity_damaged(event)
if global.table_of_properties.game_stage ~= 'ongoing_game' then
return
end
2021-03-24 17:46:00 +02:00
if event.entity.name == 'wooden-chest' then
return
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
if not event.entity.unit_number then
return
end
2021-03-24 17:46:00 +02:00
if event.final_damage_amount < 1 then
return
end
2021-03-24 17:46:00 +02:00
if global.table_of_damages == nil then
global.table_of_damages = {}
end
2021-03-24 17:46:00 +02:00
if global.table_of_damages[event.entity.unit_number] == nil then
global.table_of_damages[event.entity.unit_number] = {surface = event.entity.surface, position = event.entity.position, damage = 0}
end
2021-03-24 17:46:00 +02:00
global.table_of_damages[event.entity.unit_number].damage = global.table_of_damages[event.entity.unit_number].damage + event.final_damage_amount
end
2021-03-24 17:46:00 +02:00
event.add(defines.events.on_entity_damaged, on_entity_damaged)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local function on_entity_died(event)
if global.table_of_properties.game_stage ~= 'ongoing_game' then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if event.entity.name == 'wooden-chest' and event.entity.force.name == 'enemy' then
local loot = table_of_loots[math.random(1, #table_of_loots)]
2021-03-24 17:46:00 +02:00
event.entity.surface.spill_item_stack(event.entity.position, loot, true)
2021-03-24 17:46:00 +02:00
event.entity.surface.create_entity({name = 'flying-text', position = event.entity.position, text = '+' .. loot.count .. ' ' .. loot.name, color = table_of_colors.white})
end
end
2021-03-24 17:46:00 +02:00
event.add(defines.events.on_entity_died, on_entity_died)
2021-03-24 17:46:00 +02:00
local function on_player_changed_position(event)
if global.table_of_properties.game_stage ~= 'ongoing_game' then
return
end
2021-03-24 17:46:00 +02:00
local player = game.players[event.player_index]
2021-03-24 17:46:00 +02:00
for spot_index, spot_item in pairs(global.table_of_spots) do
if global.table_of_spots[spot_index].players[player.index] ~= nil then
global.table_of_spots[spot_index].players[player.index] = nil
end
2021-03-24 17:46:00 +02:00
for _, position in pairs(spot_item.positions) do
if
math.floor(player.position.x) == position.x and math.floor(player.position.y) == position.y or
math.ceil(player.position.x) == position.x and math.ceil(player.position.y) == position.y
then
if global.table_of_spots[spot_index].players[player.index] == nil then
global.table_of_spots[spot_index].players[player.index] = player
2021-03-24 17:46:00 +02:00
break
end
end
end
2021-03-24 17:46:00 +02:00
if global.table_of_spots[spot_index].players[player.index] ~= nil then
break
end
end
2021-03-24 17:46:00 +02:00
end
2021-03-24 17:46:00 +02:00
event.add(defines.events.on_player_changed_position, on_player_changed_position)
2021-03-24 17:46:00 +02:00
local function on_player_respawned(event)
if global.table_of_properties.game_stage ~= 'ongoing_game' then
return
end
2021-03-24 17:46:00 +02:00
local player = game.players[event.player_index]
2021-03-24 17:46:00 +02:00
local surface = player.surface
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if player.gui.center['draw_gui_spawn'] then
player.gui.center['draw_gui_spawn'].destroy()
end
2019-08-18 20:26:43 +02:00
2021-03-24 17:46:00 +02:00
local position = global.table_of_spawns[player.index]
2019-08-07 22:51:47 +02:00
2021-03-24 17:46:00 +02:00
if surface.is_chunk_generated(position) then
player.teleport(surface.find_non_colliding_position('character', position, 3, 0.5), surface)
else
player.teleport(position, surface)
end
2019-08-18 20:26:43 +02:00
2021-03-24 17:46:00 +02:00
player_icon_add(player)
2019-08-18 20:26:43 +02:00
2021-03-24 17:46:00 +02:00
create_a_tank(player)
end
2019-07-25 16:40:02 +02:00
2021-03-24 17:46:00 +02:00
event.add(defines.events.on_player_respawned, on_player_respawned)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local function on_player_died(event)
if global.table_of_properties.game_stage ~= 'ongoing_game' then
return
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
local player = game.players[event.player_index]
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_spawns[player.index] = player.force.get_spawn_position(player.surface)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local table_of_entities = player.surface.find_entities_filtered({name = 'character-corpse'})
2021-03-24 17:46:00 +02:00
for _, entity in pairs(table_of_entities) do
entity.clear_items_inside()
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
entity.destroy()
end
2021-03-24 17:46:00 +02:00
-- draw_gui_spawn( player )
2021-03-24 17:46:00 +02:00
player_icon_remove(player)
2021-03-24 17:46:00 +02:00
if global.table_of_tanks[player.index] ~= nil and global.table_of_tanks[player.index].valid then
global.table_of_tanks[player.index].clear_items_inside()
2019-08-07 22:51:47 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_tanks[player.index].destroy()
end
2021-03-24 17:46:00 +02:00
global.table_of_tanks[player.index] = nil
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local force = global.table_of_properties[player.force.name]
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if force ~= nil and force.available_tickets > 0 then
force.available_tickets = force.available_tickets - 1
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, spot in pairs(global.table_of_spots) do
if spot.players[player.index] ~= nil then
spot.players[player.index] = nil
2019-07-25 20:19:03 +02:00
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local player_death_message = global.table_of_properties[player.force.name].icon .. ' ' .. player.name .. ' was killed.'
2021-03-24 17:46:00 +02:00
if event.cause and event.cause.valid then
if event.cause.name == 'character' then
player_death_message =
global.table_of_properties[player.force.name].icon ..
' ' .. player.name .. ' was killed by ' .. global.table_of_properties[event.cause.player.force.name].icon .. ' ' .. event.cause.player.name .. '.'
elseif event.cause.name == 'car' or event.cause.name == 'tank' or event.cause.name == 'train' then
local driver = event.cause.get_driver()
2021-03-24 17:46:00 +02:00
if driver.player then
player_death_message =
global.table_of_properties[player.force.name].icon ..
' ' .. player.name .. ' was killed with a vehicle by ' .. global.table_of_properties[driver.player.force.name].icon .. ' ' .. driver.player.name .. '.'
else
player_death_message = global.table_of_properties[player.force.name].icon .. ' ' .. player.name .. ' was killed by run over.'
end
2021-03-24 17:46:00 +02:00
elseif event.cause.name then
player_death_message = global.table_of_properties[player.force.name].icon .. ' ' .. player.name .. ' was killed by ' .. event.cause.name .. '.'
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, p in pairs(game.connected_players) do
if p.force.name ~= player.force.name and p.name ~= event.cause.player.name and p.name ~= driver.player.name then
p.print(player_death_message, table_of_colors.damage)
end
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
event.add(defines.events.on_player_died, on_player_died)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local function on_player_left_game(event)
if global.table_of_properties.game_stage ~= 'ongoing_game' then
return
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local player = game.players[event.player_index]
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
player_icon_remove(player)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if global.table_of_tanks[player.index] ~= nil and global.table_of_tanks[player.index].valid then
global.table_of_tanks[player.index].clear_items_inside()
2021-03-24 17:46:00 +02:00
global.table_of_tanks[player.index].destroy()
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_tanks[player.index] = nil
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_spawns[player.index] = nil
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
for _, spot in pairs(global.table_of_spots) do
if spot.players[player.index] ~= nil then
spot.players[player.index] = nil
end
2019-07-24 19:42:27 +02:00
end
2021-03-24 17:46:00 +02:00
end
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
event.add(defines.events.on_player_left_game, on_player_left_game)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local function on_player_joined_game(event)
local surface = game.surfaces.nauvis
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local player = game.players[event.player_index]
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
player.force = game.forces.force_spectator
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
draw_gui_intro_button(player)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
if player.online_time == 0 then
draw_gui_intro_frame(player)
2019-07-24 19:42:27 +02:00
2021-03-24 17:46:00 +02:00
local position = player.force.get_spawn_position(surface)
2021-03-24 17:46:00 +02:00
if surface.is_chunk_generated(position) then
player.teleport(surface.find_non_colliding_position('character', position, 3, 0.5), surface)
else
player.teleport(position, surface)
end
2021-03-24 17:46:00 +02:00
player.character.destructible = false
2021-03-24 17:46:00 +02:00
game.permissions.get_group('permission_spectator').add_player(player)
elseif player.surface.name == 'tank_conquest' then
player.character.clear_items_inside()
2021-03-24 17:46:00 +02:00
draw_gui_button(player)
2021-03-24 17:46:00 +02:00
event_on_click_join(player)
end
2021-03-24 17:46:00 +02:00
if player.online_time == 0 and global.table_of_properties.game_stage == 'ongoing_game' then
draw_gui_button(player)
2019-08-05 20:02:47 +02:00
2021-03-24 17:46:00 +02:00
draw_gui_menu(player)
2019-08-05 20:02:47 +02:00
end
2021-03-24 17:46:00 +02:00
for index, slot in pairs(table_of_slots) do
player.set_quick_bar_slot(index, slot)
2019-08-05 20:02:47 +02:00
end
2021-03-24 17:46:00 +02:00
end
event.add(defines.events.on_player_joined_game, on_player_joined_game)
function player_icon_add(player)
if global.table_of_drawings[player.index] == nil then
-- local icon = rendering.draw_circle( { target = player.character, target_offset = { x = 0, y = - 3.7 }, force = game.forces.force_player_one, surface = player.surface, color = table_of_colors.team, radius = 0.3, filled = true, only_in_alt_mode = false } )
-- local color = { r = player.color.r * 0.6 + 0.35, g = player.color.g * 0.6 + 0.35, b = player.color.b * 0.6 + 0.35, a = 1 }
local icon =
rendering.draw_text(
{
text = global.table_of_properties[player.force.name].icon,
target = player.character,
target_offset = {0, -3.7},
surface = player.surface,
color = table_of_colors.white,
scale = 2,
alignment = 'center'
}
)
global.table_of_drawings[player.index] = icon
end
end
2019-08-05 20:02:47 +02:00
2021-03-24 17:46:00 +02:00
function player_icon_change(player)
if global.table_of_drawings[player.index] ~= nil then
local icon = global.table_of_drawings[player.index]
end
end
2019-08-05 20:02:47 +02:00
2021-03-24 17:46:00 +02:00
function player_icon_remove(player)
if global.table_of_drawings[player.index] ~= nil then
rendering.destroy(global.table_of_drawings[player.index])
2019-08-05 20:02:47 +02:00
2021-03-24 17:46:00 +02:00
global.table_of_drawings[player.index] = nil
2019-08-05 20:02:47 +02:00
end
2021-03-24 17:46:00 +02:00
end