1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-30 04:30:58 +02:00

Crash Site Arrakis

This commit is contained in:
Jayefuu 2021-01-03 15:35:53 +00:00
parent 745cc6a894
commit ad4591a13f
9 changed files with 272 additions and 9 deletions

View File

@ -141,6 +141,7 @@ aliens_killed=Aliens liberated
coins_earned=Coins earned
coins_spent=Coins spent
player_deaths=Player deaths
player_kills=Player_kills
player_console_chats=Player console chats
player_items_crafted=Player items crafted
player_distance_walked=Distance walked

View File

@ -0,0 +1,98 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local Toast = require 'features.gui.toast'
local Retailer = require 'features.retailer'
local Token = require 'utils.token'
local car_entities = {}
Global.register({car_entities = car_entities}, function(tbl)
car_entities = tbl.car_entities
end)
local function register_car(entity)
if not entity then
return
end
if not entity.valid then
return
end
if entity.name ~= 'car' then
return
end
car_entities[entity.unit_number] = entity
script.register_on_entity_destroyed(entity)
end
Event.add(defines.events.on_entity_destroyed, function(event)
car_entities[event.unit_number] = nil
end)
Event.add(defines.events.on_robot_built_entity, function(event)
register_car(event.created_entity)
end)
Event.add(defines.events.on_built_entity, function(event)
register_car(event.created_entity)
end)
Event.add(defines.events.on_entity_cloned, function(event)
register_car(event.destination)
end)
local turrets = {
['gun-turret'] = true,
['laser-turret'] = true,
['flamethrower-turret'] = true,
['artillery-turret'] = true
}
local function on_nth_tick()
for _, car in pairs(car_entities) do
if not car.valid or not car.get_driver() or car.speed ~= 0 then -- only allow cars to repair if they have a driver and are not moving
goto continue
end
local inv = car.get_inventory(defines.inventory.car_trunk)
local stack = inv.find_item_stack('repair-pack')
if not stack then
goto continue
end
-- Search for damaged entities and heal them
local surface = car.surface
local targets = surface.find_entities_filtered {position = car.position, radius = 20, force = "player"}
local repair_amount = 150
for i, entity in pairs(targets) do
if entity.unit_number and (entity.get_health_ratio() or 1) < 1 then
-- Rules for when car can repair:
-- if the damaged entity is a turret, the turret cooldown must be complete (entity.active == true) to help reduce turret creeping
-- if the damaged entity is not the car. Cars can heal other cars but not themselves.
-- if the damaged entity is not a character
-- if the entity is not moving. Vehicles must have a speed of 0, entities that can't move will be nil
if (entity ~= car and (entity.speed == 0 or entity.speed == nil) and entity.name ~= 'character' and not turrets[entity.name]) or (turrets[entity.name] and entity.active == true) then
surface.create_entity {
name = "electric-beam",
position = car.position,
source = car.position,
target = entity.position, -- use the position not the entity otherwise it will damage the entity
speed = 1,
duration = 20
}
local max_health = entity.prototype.max_health
if (max_health - entity.health) < repair_amount then
repair_amount = max_health - entity.health -- so that the player doesn't lose part of a repair pack partially healing an entity
end
entity.health = entity.health + repair_amount
stack.drain_durability(repair_amount)
goto continue -- break out because we only want to heal one entity
end
end
end
::continue::
end
end
Event.on_nth_tick(60, on_nth_tick)

View File

@ -0,0 +1,115 @@
-- This module starts spawning worms every 5 to 10 minutes (approx) when a roboport is placed.
-- Makes it necessary to defend roboports and limits the usefulness of large roboport networks
local Event = require 'utils.event'
local Global = require 'utils.global'
local Task = require 'utils.task'
local Token = require 'utils.token'
local set_timeout_in_ticks = Task.set_timeout_in_ticks
local min_worm_period_secs = 360 -- 6 minutes
local max_worm_period_secs = 1200 -- 20 minutes
local max_worm_spawn_radius = 30
local roboports = {}
Global.register({roboports = roboports}, function(tbl)
roboports = tbl.roboports
end)
local sandworms = {
['medium-worm-turret'] = {evo_min = 0.4, evo_max = 0.6},
['big-worm-turret'] = {evo_min = 0.6, evo_max = 0.9},
['behemoth-worm-turret'] = {evo_min = 0.9, evo_max = 1}
}
local sandworm_biters = {
['medium-worm-turret'] = {['small-biter'] = {min = 2.5, max = 3.5}, ['medium-biter'] = {min = 1.0, max = 2}},
['big-worm-turret'] = {
['small-biter'] = {min = 2.5, max = 4},
['medium-biter'] = {min = 1.5, max = 2.2},
['medium-spitter'] = {min = 1.5, max = 2.2}
},
['behemoth-worm-turret'] = {
['small-biter'] = {min = 4, max = 5.2},
['medium-biter'] = {min = 2.5, max = 3.8},
['big-biter'] = {min = 1.2, max = 2.4},
['big-spitter'] = {min = 1.2, max = 2.4}
}
}
local function spawn_sandworms(entity)
local evolution = game.forces["enemy"].evolution_factor
if evolution < 0.4 then
return
end
for index, worm_type in pairs(sandworms) do
-- Determine which worm type to spawn based on the evolution
if (evolution > worm_type.evo_min) and (evolution <= worm_type.evo_max) then
local s = entity.surface
local worm_type = index
local worm_position = {
entity.position.x + math.random(max_worm_spawn_radius * -1, max_worm_spawn_radius),
entity.position.y + math.random(max_worm_spawn_radius * -1, max_worm_spawn_radius)
}
worm_position = s.find_non_colliding_position(worm_type, worm_position, 5, 1)
s.create_entity {name = worm_type, position = worm_position, force = "enemy"}
-- For the appropriate worm for each evolution region, spawn some accompanying biters to attack the roboport
for worm, _ in pairs(sandworm_biters) do
if worm == worm_type then
for biters, data in pairs(sandworm_biters[worm]) do
local amount = math.random(data.min, data.max)
local extra_chance = amount % 1
if extra_chance > 0 then
if math.random(0,1) <= extra_chance then
amount = math.ceil(amount)
else
amount = math.floor(amount)
end
end
for _ = amount,1,-1 do
local pos = s.find_non_colliding_position(biters, worm_position, 5, 1)
local biter = s.create_entity {name = biters, position = pos, force = "enemy"}
biter.set_command({type = defines.command.attack, target = entity})
end
end
end
end
end
end
end
local worm_callback
worm_callback = Token.register(function(entity)
if entity then -- stops the callback if the roboport has been removed
spawn_sandworms(entity)
local callback_timer = math.random(min_worm_period_secs * 60, max_worm_period_secs * 60)
set_timeout_in_ticks(callback_timer, worm_callback, entity)
end
end)
local function start_worm_attacks(entity)
if not entity then
return
end
local callback_timer = math.random(min_worm_period_secs * 60, max_worm_period_secs * 60)
set_timeout_in_ticks(callback_timer, worm_callback, entity)
end
Event.add(defines.events.on_robot_built_entity, function(event)
if event.created_entity.name == 'roboport' then
start_worm_attacks(event.created_entity)
end
end)
Event.add(defines.events.on_built_entity, function(event)
if event.created_entity.name == 'roboport' then
start_worm_attacks(event.created_entity)
end
end)
Event.add(defines.events.on_entity_cloned, function(event)
if event.created_entity.name == 'roboport' then
start_worm_attacks(event.created_entity)
end
end)

View File

@ -0,0 +1,39 @@
require 'map_gen.maps.crash_site.features.sandworms'
require 'map_gen.maps.crash_site.features.repair_cars'
local ScenarioInfo = require 'features.gui.info'
local MGSP = require 'resources.map_gen_settings'
local config = {
scenario_name = 'crashsite-arrakis',
map_gen_settings = {
MGSP.sand_only,
MGSP.water_none,
MGSP.starting_area_very_low,
MGSP.ore_oil_none,
MGSP.enemy_none,
MGSP.tree_none,
MGSP.cliff_none,
{
property_expression_names = {
['control-setting:moisture:bias'] = '-0.500000'
},
autoplace_controls = {
trees = {
frequency = 6,
richness = 1,
size = 0.1666666716337204
}
}
}
}
}
local Scenario = require 'map_gen.maps.crash_site.scenario'
ScenarioInfo.set_map_name('Crashsite Arrakis')
ScenarioInfo.set_map_description('Capture outposts and defend against the biters. Even drier than desert, sandworms roam the desert and will attack roboports on sight.')
ScenarioInfo.add_map_extra_info(
'- Arrakis is even drier than crash site Desert.\n- Sandworms are attracted to the vibration caused by roboports and will spawn intermittently to neutralise this threat to their peace\n- Cars have repair beams\n- Outposts have enemy turrets defending them.\n- Outposts have loot and provide a steady stream of resources.\n- Outpost markets to purchase items and outpost upgrades.\n- Capturing outposts increases evolution.\n- Reduced damage by all player weapons, turrets, and ammo.\n- Biters have more health and deal more damage.\n- Biters and spitters spawn on death of entities.'
)
return Scenario.init(config)

View File

@ -1,4 +1,5 @@
local MGSP = require 'resources.map_gen_settings'
local ScenarioInfo = require 'features.gui.info'
local config = {
scenario_name = 'crashsite-desert',
@ -29,5 +30,10 @@ local config = {
}
local Scenario = require 'map_gen.maps.crash_site.scenario'
ScenarioInfo.set_map_name('Crashsite Desert')
ScenarioInfo.set_map_description('A desert version of Crash Site. Capture outposts and defend against the biters.')
ScenarioInfo.add_map_extra_info(
'- A desert version of Crash Site, with sandy terrain, scattered oases and few trees\n- Outposts have enemy turrets defending them.\n- Outposts have loot and provide a steady stream of resources.\n- Outpost markets to purchase items and outpost upgrades.\n- Capturing outposts increases evolution.\n- Reduced damage by all player weapons, turrets, and ammo.\n- Biters have more health and deal more damage.\n- Biters and spitters spawn on death of entities.'
)
return Scenario.init(config)

View File

@ -1,4 +1,5 @@
local MGSP = require 'resources.map_gen_settings'
local ScenarioInfo = require 'features.gui.info'
local config = {
scenario_name = 'crashsite',
@ -17,5 +18,10 @@ local config = {
}
local Scenario = require 'map_gen.maps.crash_site.scenario'
ScenarioInfo.set_map_name('Crashsite')
ScenarioInfo.set_map_description('Capture outposts and defend against the biters.')
ScenarioInfo.add_map_extra_info(
'- Outposts have enemy turrets defending them.\n- Outposts have loot and provide a steady stream of resources.\n- Outpost markets to purchase items and outpost upgrades.\n- Capturing outposts increases evolution.\n- Reduced damage by all player weapons, turrets, and ammo.\n- Biters have more health and deal more damage.\n- Biters and spitters spawn on death of entities.'
)
return Scenario.init(config)

View File

@ -1,5 +1,6 @@
local b = require 'map_gen.shared.builders'
local MGSP = require 'resources.map_gen_settings'
local ScenarioInfo = require 'features.gui.info'
local type = type
local water_tiles = b.water_tiles
@ -34,6 +35,11 @@ local config = {
}
local Scenario = require 'map_gen.maps.crash_site.scenario'
ScenarioInfo.set_map_name('Crashsite World')
ScenarioInfo.set_map_description('Capture outposts and defend against the biters.')
ScenarioInfo.add_map_extra_info(
'- A world map version of Crash Site\n- Outposts have enemy turrets defending them.\n- Outposts have loot and provide a steady stream of resources.\n- Outpost markets to purchase items and outpost upgrades.\n- Capturing outposts increases evolution.\n- Reduced damage by all player weapons, turrets, and ammo.\n- Biters have more health and deal more damage.\n- Biters and spitters spawn on death of entities.'
)
local crashsite = Scenario.init(config)
local function get_tile_name(tile)

View File

@ -1,7 +1,7 @@
require 'map_gen.maps.crash_site.blueprint_extractor'
require 'map_gen.maps.crash_site.events'
require 'map_gen.maps.crash_site.weapon_balance'
require 'map_gen.maps.crash_site.rocket_tanks'
require 'map_gen.maps.crash_site.features.rocket_tanks'
local b = require 'map_gen.shared.builders'
@ -11,7 +11,6 @@ local OutpostBuilder = require 'map_gen.maps.crash_site.outpost_builder'
local Token = require 'utils.token'
local Task = require 'utils.task'
local math = require 'utils.math'
local ScenarioInfo = require 'features.gui.info'
local table = require 'utils.table'
local RS = require 'map_gen.shared.redmew_surface'
local MGSP = require 'resources.map_gen_settings'
@ -48,13 +47,6 @@ local function control(config)
RS.set_map_gen_settings(map_gen_settings)
end
-- Comment out this block if you're getting scenario info from another source.
ScenarioInfo.set_map_name('Crashsite')
ScenarioInfo.set_map_description('Capture outposts and defend against the biters.')
ScenarioInfo.add_map_extra_info(
'- Outposts have enemy turrets defending them.\n- Outposts have loot and provide a steady stream of resources.\n- Outpost markets to purchase items and outpost upgrades.\n- Capturing outposts increases evolution.\n- Reduced damage by all player weapons, turrets, and ammo.\n- Biters have more health and deal more damage.\n- Biters and spitters spawn on death of entities.'
)
RedmewConfig.market.enabled = false
RedmewConfig.biter_attacks.enabled = false