mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-06 00:23:49 +02:00
Update tank_conquest.lua
Captured spots are now visible on the map. Troubleshooting the GUI. Integration of a Map Intro.
This commit is contained in:
parent
917eadb4d3
commit
c40d59c443
@ -27,7 +27,7 @@
|
||||
|
||||
global.table_of_properties.conquest_speed = 5
|
||||
|
||||
global.table_of_properties.acceleration_value = 0.1
|
||||
global.table_of_properties.acceleration_value = 0.05
|
||||
|
||||
global.table_of_properties.game_stage = 'lobby'
|
||||
|
||||
@ -45,6 +45,63 @@
|
||||
|
||||
local event = require 'utils.event'
|
||||
|
||||
local map_intro = [[
|
||||
|
||||
- - - T A N K C O N Q U E S T - - -
|
||||
|
||||
Your objective is to defend your team's tickets and withdraw the tickets from the
|
||||
other team as quickly as possible.
|
||||
|
||||
PvP battles and the conquest of the spots are the deciding factor to win the round.
|
||||
|
||||
Each force has a number of tickets. Per conquered spot, 0.05 tickets are deducted
|
||||
per second. If a player loses his life, 1 ticket is deducted from his own force.
|
||||
|
||||
There is no biter evolution from pollution, time or destruction.
|
||||
]]
|
||||
|
||||
local function draw_gui_map_intro_button( player )
|
||||
|
||||
if player.gui.top[ 'map_intro_button' ] then return end
|
||||
|
||||
local element_button = player.gui.top.add( { type = 'sprite-button', caption = '?', name = 'map_intro_button', tooltip = 'Map Intro' } )
|
||||
|
||||
element_button.style.font_color = { r = 0.5, g = 0.3, b = 0.99 }
|
||||
|
||||
element_button.style.font = 'heading-1'
|
||||
|
||||
element_button.style.minimal_height = 38
|
||||
|
||||
element_button.style.minimal_width = 38
|
||||
|
||||
element_button.style.top_padding = 1
|
||||
|
||||
element_button.style.left_padding = 1
|
||||
|
||||
element_button.style.right_padding = 1
|
||||
|
||||
element_button.style.bottom_padding = 1
|
||||
|
||||
end
|
||||
|
||||
local function draw_gui_map_intro( player )
|
||||
|
||||
if player.gui.center[ 'map_intro_frame' ] then player.gui.center[ 'map_intro_frame' ].destroy() end
|
||||
|
||||
local element_frame = player.gui.center.add { type = 'frame', name = 'map_intro_frame', direction = 'vertical' }
|
||||
|
||||
local element_frame = element_frame.add { type = 'frame' }
|
||||
|
||||
local element_label = element_frame.add { type = 'label', caption = map_intro, name = 'map_intro_text' }
|
||||
|
||||
element_label.style.single_line = false
|
||||
|
||||
element_label.style.font = 'heading-2'
|
||||
|
||||
element_label.style.font_color = { r = 0.7, g = 0.6, b = 0.99 }
|
||||
|
||||
end
|
||||
|
||||
local function initialize_forces()
|
||||
|
||||
game.create_force( 'force_player_one' )
|
||||
@ -385,17 +442,11 @@
|
||||
|
||||
element_frame.style.margin = 0
|
||||
|
||||
local element_table = element_frame.add{ type = 'table', column_count = 2 }
|
||||
if player.force.name ~= 'force_spectator' then element_frame.add{ type = 'sprite-button', name = 'event_on_click_lobby', caption = 'LOBBY' } end
|
||||
|
||||
element_table.style.padding = 0
|
||||
if player.force.name == 'force_spectator' then element_frame.add{ type = 'sprite-button', name = 'event_on_click_join', caption = 'JOIN' } end
|
||||
|
||||
element_table.style.margin = 0
|
||||
|
||||
if player.force.name == 'force_spectator' then element_table.add{ type = 'sprite-button', name = 'event_on_click_join', caption = 'JOIN' } end
|
||||
|
||||
if player.force.name ~= 'force_spectator' then element_table.add{ type = 'sprite-button', name = 'event_on_click_lobby', caption = 'LOBBY' } end
|
||||
|
||||
for _, element_item in pairs( element_table.children ) do
|
||||
for _, element_item in pairs( element_frame.children ) do
|
||||
|
||||
element_item.style.padding = 0
|
||||
|
||||
@ -583,6 +634,8 @@
|
||||
|
||||
entity.minable = false
|
||||
|
||||
entity.last_user = player.name
|
||||
|
||||
entity.insert( { name = 'wood', count = 50 } )
|
||||
|
||||
entity.insert( { name = 'cannon-shell', count = 50 } )
|
||||
@ -863,7 +916,9 @@
|
||||
|
||||
end
|
||||
|
||||
local function event_on_click_join( player )
|
||||
function event_on_click_join( player )
|
||||
|
||||
if global.table_of_properties.game_stage ~= 'ongoing_game' then return end
|
||||
|
||||
local surface = game.surfaces[ 'tank_conquest' ]
|
||||
|
||||
@ -871,8 +926,6 @@
|
||||
|
||||
if not player.character then return end
|
||||
|
||||
if global.table_of_properties.game_stage ~= 'ongoing_game' then return end
|
||||
|
||||
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' }
|
||||
@ -893,8 +946,6 @@
|
||||
|
||||
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
|
||||
|
||||
player.character.destructible = true
|
||||
|
||||
game.permissions.get_group( 'Default' ).add_player( player.name )
|
||||
|
||||
game.print( player.name .. ' joined ' .. global.table_of_properties[ player.force.name ].icon )
|
||||
@ -905,6 +956,8 @@
|
||||
|
||||
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
|
||||
|
||||
player.character.destructible = true
|
||||
|
||||
end
|
||||
|
||||
function event_on_click_lobby( player )
|
||||
@ -919,9 +972,11 @@
|
||||
|
||||
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
|
||||
|
||||
game.permissions.get_group( 'permission_spectator' ).add_player( player.name )
|
||||
|
||||
player.character.destructible = false
|
||||
|
||||
game.permissions.get_group( 'permission_spectator' ).add_player( player.name )
|
||||
player.character.clear_items_inside()
|
||||
|
||||
end
|
||||
|
||||
@ -963,6 +1018,8 @@
|
||||
|
||||
end
|
||||
|
||||
for _, player in pairs( game.connected_players ) do if player.force.name == spot.properties.force.name and spot.properties.value == 100 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
|
||||
|
||||
for _, player in pairs( spot.players ) do
|
||||
|
||||
if spot.properties.force.name == 'neutral' and spot.properties.value == 0 then
|
||||
@ -1001,6 +1058,8 @@
|
||||
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
@ -1073,7 +1132,7 @@
|
||||
|
||||
create_a_base( 'force_player_two', position )
|
||||
|
||||
local position = { x = 0, y = -350 }
|
||||
local position = { x = 0, y = - 350 }
|
||||
|
||||
create_a_point_of_interest( blueprint_poi_laser_json, position )
|
||||
|
||||
@ -1093,6 +1152,10 @@
|
||||
|
||||
for index = 1, length_of_names do create_a_spot( table_of_names[ index ], table_of_positions[ index ], table_of_blueprints[ math.random( 1, #table_of_blueprints ) ] ) end
|
||||
|
||||
game.print( 'A new battlefield was created. Make yourself comfortable, but be vigilant.' )
|
||||
|
||||
global.table_of_properties.game_stage = 'ongoing_game'
|
||||
|
||||
for _, player in pairs( game.connected_players ) do
|
||||
|
||||
-- if player.gui.left[ 'draw_gui_squad' ] then player.gui.left[ 'draw_gui_squad' ].destroy() end
|
||||
@ -1107,13 +1170,11 @@
|
||||
|
||||
end
|
||||
|
||||
global.table_of_properties.game_stage = 'ongoing_game'
|
||||
|
||||
end
|
||||
|
||||
if global.table_of_properties.game_stage == 'preparing_spawn_positions' then
|
||||
|
||||
local position = { x = -500, y = 50 }
|
||||
local position = { x = - 500, y = 50 }
|
||||
|
||||
game.forces[ 'force_player_one' ].set_spawn_position( position, game.surfaces[ 'tank_conquest' ] )
|
||||
|
||||
@ -1149,8 +1210,6 @@
|
||||
|
||||
game.surfaces[ 'tank_conquest' ].request_to_generate_chunks( { 0, 0 }, 15 )
|
||||
|
||||
game.print( 'A new battlefield was created.' )
|
||||
|
||||
global.table_of_properties.game_stage = 'preparing_spawn_positions'
|
||||
|
||||
end
|
||||
@ -1181,7 +1240,7 @@
|
||||
|
||||
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 } } )
|
||||
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
|
||||
|
||||
@ -1209,7 +1268,7 @@
|
||||
|
||||
local function on_entity_damaged( event )
|
||||
|
||||
if global.table_of_properties.game_stage == 'lobby' then return end
|
||||
if global.table_of_properties.game_stage ~= 'ongoing_game' then return end
|
||||
|
||||
if not event.entity.unit_number then return end
|
||||
|
||||
@ -1225,11 +1284,45 @@
|
||||
|
||||
event.add( defines.events.on_entity_damaged, on_entity_damaged )
|
||||
|
||||
local function on_player_respawned( event )
|
||||
local function on_player_changed_position( event )
|
||||
|
||||
if global.table_of_properties.game_stage ~= 'ongoing_game' then return end
|
||||
|
||||
local player = game.players[ event.player_index ]
|
||||
|
||||
if player.surface.name == 'nauvis' then return end
|
||||
for spot_index, spot_item in pairs( global.table_of_spots ) do
|
||||
|
||||
if global.table_of_spots[ spot_index ].players[ event.player_index ] ~= nil then global.table_of_spots[ spot_index ].players[ event.player_index ] = nil end
|
||||
|
||||
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[ event.player_index ] == nil then
|
||||
|
||||
global.table_of_spots[ spot_index ].players[ event.player_index ] = player
|
||||
|
||||
break
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if global.table_of_spots[ spot_index ].players[ event.player_index ] ~= nil then break end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
event.add( defines.events.on_player_changed_position, on_player_changed_position )
|
||||
|
||||
local function on_player_respawned( event )
|
||||
|
||||
if global.table_of_properties.game_stage ~= 'ongoing_game' then return end
|
||||
|
||||
local player = game.players[ event.player_index ]
|
||||
|
||||
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' }
|
||||
|
||||
@ -1241,6 +1334,8 @@
|
||||
|
||||
local function on_player_died( event )
|
||||
|
||||
if global.table_of_properties.game_stage ~= 'ongoing_game' then return end
|
||||
|
||||
local player = game.players[ event.player_index ]
|
||||
|
||||
if global.table_of_tanks[ player.index ] ~= nil and global.table_of_tanks[ player.index ].valid then
|
||||
@ -1273,85 +1368,27 @@
|
||||
|
||||
event.add( defines.events.on_player_died, on_player_died )
|
||||
|
||||
local function on_player_changed_position( event )
|
||||
local function on_player_left_game( event )
|
||||
|
||||
if global.table_of_properties.game_stage == 'lobby' then return end
|
||||
if global.table_of_properties.game_stage ~= 'ongoing_game' then return end
|
||||
|
||||
local player = game.players[ event.player_index ]
|
||||
|
||||
for spot_index, spot_item in pairs( global.table_of_spots ) do
|
||||
if global.table_of_tanks[ player.index ] ~= nil and global.table_of_tanks[ player.index ].valid then
|
||||
|
||||
if global.table_of_spots[ spot_index ].players[ event.player_index ] ~= nil then global.table_of_spots[ spot_index ].players[ event.player_index ] = nil end
|
||||
global.table_of_tanks[ player.index ].clear_items_inside()
|
||||
|
||||
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[ event.player_index ] == nil then
|
||||
|
||||
global.table_of_spots[ spot_index ].players[ event.player_index ] = player
|
||||
|
||||
break
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if global.table_of_spots[ spot_index ].players[ event.player_index ] ~= nil then break end
|
||||
global.table_of_tanks[ player.index ].destroy()
|
||||
|
||||
end
|
||||
|
||||
global.table_of_tanks[ player.index ] = nil
|
||||
|
||||
for _, spot in pairs( global.table_of_spots ) do if spot.players[ event.player_index ] ~= nil then spot.players[ event.player_index ] = nil end end
|
||||
|
||||
end
|
||||
|
||||
event.add( defines.events.on_player_changed_position, on_player_changed_position )
|
||||
|
||||
local function on_gui_click( event )
|
||||
|
||||
if not event.element then return end
|
||||
|
||||
if not event.element.valid then return end
|
||||
|
||||
local player = game.players[ event.player_index ]
|
||||
|
||||
if 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
|
||||
|
||||
end
|
||||
|
||||
if 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
|
||||
|
||||
end
|
||||
|
||||
if 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
|
||||
|
||||
end
|
||||
|
||||
if event.element.name == 'event_on_click_join' then
|
||||
|
||||
event_on_click_join( player )
|
||||
|
||||
if player.gui.center[ 'draw_gui_menu' ] then player.gui.center[ 'draw_gui_menu' ].destroy() end
|
||||
|
||||
end
|
||||
|
||||
if event.element.name == 'event_on_click_lobby' then
|
||||
|
||||
event_on_click_lobby( player )
|
||||
|
||||
if player.gui.center[ 'draw_gui_menu' ] then player.gui.center[ 'draw_gui_menu' ].destroy() end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
event.add( defines.events.on_gui_click, on_gui_click )
|
||||
event.add( defines.events.on_player_left_game, on_player_left_game )
|
||||
|
||||
local function on_player_joined_game( event )
|
||||
|
||||
@ -1361,8 +1398,12 @@
|
||||
|
||||
player.force = game.forces.force_spectator
|
||||
|
||||
draw_gui_map_intro_button( player )
|
||||
|
||||
if player.online_time == 0 then
|
||||
|
||||
draw_gui_map_intro( player )
|
||||
|
||||
local position = player.force.get_spawn_position( surface )
|
||||
|
||||
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
|
||||
@ -1371,8 +1412,6 @@
|
||||
|
||||
game.permissions.get_group( 'permission_spectator' ).add_player( player.name )
|
||||
|
||||
player.print( 'Info: Each force has a number of tickets. Per conquered spot, 0.1 tickets are deducted per second. If a player loses his life, 1 ticket is deducted from his own force.' )
|
||||
|
||||
end
|
||||
|
||||
if global.table_of_properties.game_stage ~= 'lobby' then
|
||||
@ -1387,20 +1426,54 @@
|
||||
|
||||
event.add( defines.events.on_player_joined_game, on_player_joined_game )
|
||||
|
||||
local function on_player_left_game( event )
|
||||
local function on_gui_click( event )
|
||||
|
||||
local player = game.players[ event.player_index ]
|
||||
|
||||
if global.table_of_tanks[ player.index ] ~= nil and global.table_of_tanks[ player.index ].valid then
|
||||
if event.element.valid and event.element.name == 'close_map_intro_frame' then player.gui.center[ 'map_intro_frame' ].destroy() return end
|
||||
|
||||
global.table_of_tanks[ player.index ].clear_items_inside()
|
||||
if event.element.valid and event.element.name == 'map_intro_text' then player.gui.center[ 'map_intro_frame' ].destroy() return end
|
||||
|
||||
global.table_of_tanks[ player.index ].destroy()
|
||||
if event.element.valid and event.element.name == 'map_intro_button' then
|
||||
|
||||
if player.gui.center[ 'map_intro_frame' ] then player.gui.center[ 'map_intro_frame' ].destroy() else draw_gui_map_intro( player ) end
|
||||
|
||||
end
|
||||
|
||||
global.table_of_tanks[ player.index ] = nil
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
end
|
||||
|
||||
if event.element.valid and event.element.name == 'event_on_click_lobby' then
|
||||
|
||||
event_on_click_lobby( player )
|
||||
|
||||
if player.gui.center[ 'draw_gui_menu' ] then player.gui.center[ 'draw_gui_menu' ].destroy() end
|
||||
|
||||
end
|
||||
|
||||
if event.element.valid and event.element.name == 'event_on_click_join' then
|
||||
|
||||
event_on_click_join( player )
|
||||
|
||||
if player.gui.center[ 'draw_gui_menu' ] then player.gui.center[ 'draw_gui_menu' ].destroy() end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
event.add( defines.events.on_player_left_game, on_player_left_game )
|
||||
event.add( defines.events.on_gui_click, on_gui_click )
|
||||
|
Loading…
Reference in New Issue
Block a user