mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-05-13 21:56:29 +02:00
WIP
This commit is contained in:
parent
fa53e9bd9f
commit
922d57161c
@ -1,6 +1,9 @@
|
||||
--local Collapse = require "modules.collapse"
|
||||
local Collapse = require "modules.collapse"
|
||||
local Immersive_cargo_wagons = require "modules.immersive_cargo_wagons.main"
|
||||
local Terrain = require 'maps.mountain_race.terrain'
|
||||
local Team = require 'maps.mountain_race.team'
|
||||
local Global = require 'utils.global'
|
||||
local Server = require 'utils.server'
|
||||
|
||||
local mountain_race = {}
|
||||
Global.register(
|
||||
@ -14,7 +17,7 @@ local function on_chunk_generated(event)
|
||||
local surface = event.surface
|
||||
if surface.index ~= 1 then return end
|
||||
local left_top = event.area.left_top
|
||||
if left_top.y >= mountain_race.playfield_height or left_top.y < mountain_race.playfield_height * -1 or left_top.x < -64 then
|
||||
if left_top.y >= mountain_race.playfield_height or left_top.y < mountain_race.playfield_height * -1 or left_top.x < 0 then
|
||||
Terrain.draw_out_of_map_chunk(surface, left_top)
|
||||
return
|
||||
end
|
||||
@ -24,37 +27,147 @@ local function on_entity_damaged(event)
|
||||
end
|
||||
|
||||
local function on_entity_died(event)
|
||||
local entity = event.entity
|
||||
if not entity then return end
|
||||
if not entity.valid then return end
|
||||
if entity.name == "locomotive" then
|
||||
if entity == mountain_race.locomotives.north then
|
||||
mountain_race.victorious_team = "south"
|
||||
mountain_race.gamestate = "game_over"
|
||||
return
|
||||
end
|
||||
if entity == mountain_race.locomotives.south then
|
||||
mountain_race.victorious_team = "north"
|
||||
mountain_race.gamestate = "game_over"
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function on_player_joined_game(event)
|
||||
local player = game.players[event.player_index]
|
||||
|
||||
if game.tick == 0 then
|
||||
if player.character then
|
||||
if player.character.valid then
|
||||
player.character.destroy()
|
||||
end
|
||||
end
|
||||
player.character = nil
|
||||
player.set_controller({type=defines.controllers.god})
|
||||
return
|
||||
end
|
||||
|
||||
Team.setup_player(mountain_race, player)
|
||||
end
|
||||
|
||||
local function init(mountain_race)
|
||||
if game.ticks_played % 60 ~= 30 then return end
|
||||
game.print("game resetting..")
|
||||
|
||||
Immersive_cargo_wagons.reset()
|
||||
|
||||
Collapse.set_kill_entities(true)
|
||||
Collapse.set_speed(1)
|
||||
Collapse.set_amount(4)
|
||||
Collapse.set_max_line_size(mountain_race.border_width + mountain_race.playfield_height * 2)
|
||||
Collapse.set_surface(surface)
|
||||
Collapse.set_position({0, 0})
|
||||
Collapse.set_direction("east")
|
||||
|
||||
game.reset_time_played()
|
||||
|
||||
mountain_race.clone_x = 0
|
||||
|
||||
Team.configure_teams(mountain_race)
|
||||
|
||||
game.print("rerolling terrain..")
|
||||
mountain_race.gamestate = "reroll_terrain"
|
||||
end
|
||||
|
||||
local function prepare_terrain(mountain_race)
|
||||
if game.ticks_played % 30 ~= 0 then return end
|
||||
Terrain.clone_south_to_north(mountain_race)
|
||||
|
||||
if mountain_race.clone_x < 4 then return end
|
||||
game.print("preparing spawn..")
|
||||
mountain_race.gamestate = "prepare_spawn"
|
||||
end
|
||||
|
||||
local function prepare_spawn(mountain_race)
|
||||
if game.ticks_played % 60 ~= 0 then return end
|
||||
Terrain.generate_spawn(mountain_race, "north")
|
||||
Terrain.generate_spawn(mountain_race, "south")
|
||||
game.print("spawning players..")
|
||||
mountain_race.gamestate = "spawn_players"
|
||||
end
|
||||
|
||||
local function spawn_players(mountain_race)
|
||||
if game.ticks_played % 60 ~= 0 then return end
|
||||
for _, player in pairs(game.players) do
|
||||
player.force = game.forces.player
|
||||
end
|
||||
for _, player in pairs(game.connected_players) do
|
||||
Team.setup_player(mountain_race, player)
|
||||
end
|
||||
|
||||
mountain_race.reset_counter = mountain_race.reset_counter + 1
|
||||
local message = "Mountain race #" .. mountain_race.reset_counter .. " has begun!"
|
||||
game.print(message, {255, 155, 0})
|
||||
Server.to_discord_bold(table.concat{'*** ', message, ' ***'})
|
||||
mountain_race.gamestate = "game_in_progress"
|
||||
end
|
||||
|
||||
|
||||
|
||||
local function game_in_progress(mountain_race)
|
||||
local tick = game.tick
|
||||
local tick = game.ticks_played
|
||||
if tick % 120 == 0 then
|
||||
Terrain.clone_south_to_north(mountain_race)
|
||||
end
|
||||
end
|
||||
|
||||
local function game_over(mountain_race)
|
||||
local tick = game.ticks_played
|
||||
if tick % 60 ~= 0 then return end
|
||||
|
||||
if not mountain_race.reset_countdown then
|
||||
mountain_race.reset_countdown = 10
|
||||
local message = "Team " .. mountain_race.victorious_team .. " has won the race!"
|
||||
game.print(message, {255, 155, 0})
|
||||
Server.to_discord_bold(table.concat{'*** ', message, ' ***'})
|
||||
return
|
||||
end
|
||||
|
||||
mountain_race.reset_countdown = mountain_race.reset_countdown - 1
|
||||
if mountain_race.reset_countdown <= 0 then
|
||||
mountain_race.gamestate = "init"
|
||||
mountain_race.reset_countdown = nil
|
||||
end
|
||||
end
|
||||
|
||||
local gamestates = {
|
||||
["init"] = init,
|
||||
["game_in_progress"] = game_in_progress,
|
||||
["reroll_terrain"] = Terrain.reroll_terrain,
|
||||
["prepare_terrain"] = prepare_terrain,
|
||||
["prepare_spawn"] = prepare_spawn,
|
||||
["spawn_players"] = spawn_players,
|
||||
["game_in_progress"] = game_in_progress,
|
||||
["game_over"] = game_over,
|
||||
}
|
||||
|
||||
local function on_tick()
|
||||
--Terrain.mirror_queue(mountain_race)
|
||||
gamestates[mountain_race.gamestate](mountain_race)
|
||||
end
|
||||
|
||||
local function on_init()
|
||||
mountain_race.gamestate = "game_in_progress"
|
||||
mountain_race.reset_counter = 0
|
||||
mountain_race.gamestate = "init"
|
||||
mountain_race.border_width = 4
|
||||
mountain_race.border_half_width = mountain_race.border_width * 0.5
|
||||
mountain_race.playfield_height = 128
|
||||
mountain_race.clone_x = -3
|
||||
mountain_race.locomotives = {}
|
||||
Team.init_teams()
|
||||
end
|
||||
|
||||
|
||||
|
79
maps/mountain_race/team.lua
Normal file
79
maps/mountain_race/team.lua
Normal file
@ -0,0 +1,79 @@
|
||||
local Public = {}
|
||||
local math_random = math.random
|
||||
|
||||
local starting_items = {['iron-plate'] = 32, ['iron-gear-wheel'] = 16, ['stone'] = 20, ['pistol'] = 1, ['firearm-magazine'] = 16}
|
||||
|
||||
function Public.init_teams()
|
||||
game.create_force("north")
|
||||
game.create_force("south")
|
||||
game.create_force("spectator")
|
||||
game.forces.spectator.set_friend("north", true)
|
||||
game.forces.spectator.set_friend("south", true)
|
||||
end
|
||||
|
||||
function Public.configure_teams(mountain_race)
|
||||
for _, force_name in pairs({"north", "south"}) do
|
||||
local force = game.forces[force_name]
|
||||
force.reset()
|
||||
force.share_chart = true
|
||||
force.research_queue_enabled = true
|
||||
force.technologies["artillery"].enabled = false
|
||||
force.technologies["artillery-shell-range-1"].enabled = false
|
||||
force.technologies["artillery-shell-speed-1"].enabled = false
|
||||
force.technologies["land-mine"].enabled = false
|
||||
end
|
||||
game.forces.north.set_friend("spectator", true)
|
||||
game.forces.south.set_friend("spectator", true)
|
||||
|
||||
local y = mountain_race.playfield_height * 0.5 + mountain_race.border_half_width
|
||||
|
||||
game.forces.north.set_spawn_position({32, y * -1}, game.surfaces.nauvis)
|
||||
game.forces.south.set_spawn_position({32, y}, game.surfaces.nauvis)
|
||||
end
|
||||
|
||||
function Public.teleport_player_to_spawn(player)
|
||||
local surface = game.surfaces.nauvis
|
||||
local position
|
||||
position = surface.find_non_colliding_position("character", player.force.get_spawn_position(surface), 48, 1)
|
||||
if not position then position = player.force.get_spawn_position(surface) end
|
||||
player.teleport(position, surface)
|
||||
end
|
||||
|
||||
local function assign_force_to_player(player)
|
||||
if #game.forces.south.connected_players > #game.forces.north.connected_players then
|
||||
player.force = game.forces.north
|
||||
return
|
||||
end
|
||||
if #game.forces.north.connected_players > #game.forces.south.connected_players then
|
||||
player.force = game.forces.south
|
||||
return
|
||||
end
|
||||
if math_random(1, 2) == 1 then
|
||||
player.force = game.forces.south
|
||||
else
|
||||
player.force = game.forces.north
|
||||
end
|
||||
end
|
||||
|
||||
function Public.setup_player(mountain_race, player)
|
||||
if player.force.name == "player" then
|
||||
assign_force_to_player(player)
|
||||
player.print("You have been assigned to team " .. player.force.name .. "!")
|
||||
|
||||
if player.character then
|
||||
if player.character.valid then
|
||||
player.character.destroy()
|
||||
end
|
||||
end
|
||||
player.character = nil
|
||||
player.set_controller({type=defines.controllers.god})
|
||||
player.create_character()
|
||||
for item, amount in pairs(starting_items) do
|
||||
player.insert({name = item, count = amount})
|
||||
end
|
||||
|
||||
Public.teleport_player_to_spawn(player)
|
||||
end
|
||||
end
|
||||
|
||||
return Public
|
@ -1,4 +1,8 @@
|
||||
local Public = {}
|
||||
local math_random = math.random
|
||||
local Immersive_cargo_wagons = require "modules.immersive_cargo_wagons.main"
|
||||
|
||||
local wagon_raffle = {"cargo-wagon", "cargo-wagon", "cargo-wagon", "locomotive", "fluid-wagon"}
|
||||
|
||||
local function draw_border(surface, left_x, height)
|
||||
local tiles = {}
|
||||
@ -50,4 +54,84 @@ function Public.draw_out_of_map_chunk(surface, left_top)
|
||||
surface.set_tiles(tiles, true)
|
||||
end
|
||||
|
||||
function Public.generate_spawn(mountain_race, force_name)
|
||||
local force = game.forces[force_name]
|
||||
local surface = game.surfaces.nauvis
|
||||
local p = force.get_spawn_position(surface)
|
||||
|
||||
local v = {{0,0}, {1,0}, {0,1}, {1,1}}
|
||||
local teams = {
|
||||
["north"] = {75, 75, 255},
|
||||
["south"] = {255, 65, 65},
|
||||
}
|
||||
|
||||
for x = 0, 32, 2 do
|
||||
surface.create_entity({name = 'straight-rail', position = {p.x + x, p.y}, direction = 2, force = force_name})
|
||||
for k, tile in pairs(surface.find_tiles_filtered({area = {{p.x + x, p.y}, {p.x + x + 2, p.y + 2}}})) do
|
||||
if tile.collides_with("resource-layer") then surface.set_tiles({{name = "landfill", position = tile.position}}, true) end
|
||||
end
|
||||
end
|
||||
|
||||
local entity = surface.create_entity({name = 'locomotive', position = {p.x + 6, p.y}, force = force_name, direction = 2})
|
||||
|
||||
entity.color = teams[force_name]
|
||||
|
||||
rendering.draw_text({
|
||||
text = string.upper(force_name),
|
||||
surface = surface,
|
||||
target = entity,
|
||||
target_offset = {0, -3},
|
||||
color = teams[force_name],
|
||||
scale = 2,
|
||||
font = "default-game",
|
||||
alignment = "center",
|
||||
scale_with_zoom = false,
|
||||
})
|
||||
|
||||
mountain_race.locomotives[force_name] = entity
|
||||
|
||||
local wagon = Immersive_cargo_wagons.register_wagon(entity)
|
||||
wagon.entity_count = 999
|
||||
end
|
||||
|
||||
function Public.reroll_terrain(mountain_race)
|
||||
if game.ticks_played % 60 ~= 0 then return end
|
||||
|
||||
for _, player in pairs(game.connected_players) do
|
||||
if player.character then
|
||||
if player.character.valid then
|
||||
player.character.destroy()
|
||||
end
|
||||
end
|
||||
player.character = nil
|
||||
player.set_controller({type=defines.controllers.god})
|
||||
end
|
||||
|
||||
local surface = game.surfaces.nauvis
|
||||
local mgs = surface.map_gen_settings
|
||||
mgs.seed = math_random(1, 99999999)
|
||||
mgs.water = 1
|
||||
mgs.starting_area = 1
|
||||
mgs.terrain_segmentation = 2
|
||||
mgs.cliff_settings = {cliff_elevation_interval = 0, cliff_elevation_0 = 0}
|
||||
mgs.autoplace_controls = {
|
||||
["coal"] = {frequency = 8, size = 0.7, richness = 0.5,},
|
||||
["stone"] = {frequency = 8, size = 0.7, richness = 0.5,},
|
||||
["copper-ore"] = {frequency = 8, size = 0.7, richness = 0.75,},
|
||||
["iron-ore"] = {frequency = 8, size = 0.7, richness = 1,},
|
||||
["uranium-ore"] = {frequency = 5, size = 0.5, richness = 0.5,},
|
||||
["crude-oil"] = {frequency = 5, size = 1, richness = 1,},
|
||||
["trees"] = {frequency = math.random(4, 32) * 0.1, size = math.random(4, 16) * 0.1, richness = math.random(1, 10) * 0.1},
|
||||
["enemy-base"] = {frequency = 0, size = 0, richness = 0}
|
||||
}
|
||||
surface.map_gen_settings = mgs
|
||||
surface.clear(false)
|
||||
for chunk in surface.get_chunks() do
|
||||
surface.delete_chunk({chunk.x, chunk.y})
|
||||
end
|
||||
|
||||
game.print("preparing terrain..")
|
||||
mountain_race.gamestate = "prepare_terrain"
|
||||
end
|
||||
|
||||
return Public
|
Loading…
x
Reference in New Issue
Block a user