1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-04-17 11:46:41 +02:00

Merge pull request #2 from ComfyFactory/planet_prison_fix

planet prison fix
This commit is contained in:
Gerkiz 2021-03-21 23:33:45 +01:00 committed by GitHub
commit 77c4a13783
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 2616 additions and 2570 deletions

View File

@ -107,6 +107,9 @@ require 'modules.autostash'
--![[East VS West Survival PVP, where you breed biters with science flasks]]--
--require 'maps.biter_hatchery.main'
--![[Fight in a world where everyone are prisoners]]
--require 'maps.planet_prison'
--![[Chop trees to gain resources]]--
--require 'maps.choppy'
--require 'maps.choppy_dx'
@ -201,7 +204,6 @@ require 'modules.autostash'
--require 'maps.wave_defense'
--require 'maps.crossing'
--require 'maps.anarchy'
--require 'maps.planet_prison'
--require 'maps.blue_beach'
--require 'maps.nightfall'
--require 'maps.pitch_black.main'

File diff suppressed because it is too large Load Diff

View File

@ -1 +1 @@
return '{"blueprint":{"icons":[{"signal":{"type":"item","name":"crash-site-lab-repaired"},"index":1},{"signal":{"type":"item","name":"crash-site-generator"},"index":2}],"entities":[{"entity_number":1,"name":"crash-site-generator","position":{"x":3,"y":-3.5}},{"entity_number":2,"name":"crash-site-lab-repaired","position":{"x":-2,"y":-1}},{"entity_number":3,"name":"crash-site-chest-1","position":{"x":4,"y":-1}},{"entity_number":4,"name":"crash-site-chest-2","position":{"x":-3,"y":3}},{"entity_number":5,"name":"crash-site-assembling-machine-1-repaired","position":{"x":-2,"y":-5}}],"item":"blueprint","version":73019621376}}'
return '{"blueprint":{"icons":[{"signal":{"type":"item","name":"crash-site-lab-repaired"},"index":1}],"entities":[{"entity_number":2,"name":"crash-site-chest-1","position":{"x":4,"y":-1}},{"entity_number":3,"name":"crash-site-chest-2","position":{"x":-3,"y":3}}],"item":"blueprint","version":73019621376}}'

View File

@ -2,35 +2,35 @@ local public = {}
public.player_ship_loot = {
{
name = "piercing-rounds-magazine",
count = 35,
name = 'piercing-rounds-magazine',
count = 35
},
{
name = "grenade",
count = 2,
name = 'grenade',
count = 2
},
{
name = "submachine-gun",
count = 1,
name = 'submachine-gun',
count = 1
},
{
name = "light-armor",
count = 1,
name = 'light-armor',
count = 1
},
{
name = "iron-plate",
count = 30,
name = 'iron-plate',
count = 30
},
{
name = "copper-plate",
count = 10,
name = 'copper-plate',
count = 10
},
{
name = "raw-fish",
count = 2,
name = 'raw-fish',
count = 2
},
{
name = "small-lamp",
name = 'small-lamp',
count = 1
}
}
@ -204,20 +204,20 @@ public.permission_orbit = {
defines.input_action.upgrade_opened_blueprint,
defines.input_action.use_artillery_remote,
defines.input_action.use_item,
defines.input_action.wire_dragging,
defines.input_action.wire_dragging
}
public.self_explode = 60 * 60 * 10 -- time until main shipwreck explosion
public.claim_markers = {
"gun-turret",
"laser-turret",
"stone-wall",
'gun-turret',
'laser-turret',
'stone-wall'
}
public.claim_max_distance = 15
public.base_costs = {
["gun-turret"] = 1,
["laser-turret"] = 5,
["stone-wall"] = 0.1,
['gun-turret'] = 1,
['laser-turret'] = 5,
['stone-wall'] = 0.1
}
public.raid_costs = {
{
@ -225,14 +225,14 @@ public.raid_costs = {
chance = 300,
gear = {
{
weap = "shotgun",
ammo = "shotgun-shell",
armor = "light-armor"
weap = 'shotgun',
ammo = 'shotgun-shell',
armor = 'light-armor'
},
{
weap = "pistol",
ammo = "firearm-magazine",
armor = "light-armor"
weap = 'pistol',
ammo = 'firearm-magazine',
armor = 'light-armor'
}
}
},
@ -241,14 +241,14 @@ public.raid_costs = {
chance = 150,
gear = {
{
weap = "shotgun",
ammo = "shotgun-shell",
armor = "light-armor"
weap = 'shotgun',
ammo = 'shotgun-shell',
armor = 'light-armor'
},
{
weap = "pistol",
ammo = "firearm-magazine",
armor = "light-armor"
weap = 'pistol',
ammo = 'firearm-magazine',
armor = 'light-armor'
}
}
},
@ -257,14 +257,14 @@ public.raid_costs = {
chance = 100,
gear = {
{
weap = "shotgun",
ammo = "shotgun-shell",
armor = "light-armor"
weap = 'shotgun',
ammo = 'shotgun-shell',
armor = 'light-armor'
},
{
weap = "pistol",
ammo = "firearm-magazine",
armor = "light-armor"
weap = 'pistol',
ammo = 'firearm-magazine',
armor = 'light-armor'
}
}
},
@ -273,14 +273,14 @@ public.raid_costs = {
chance = 100,
gear = {
{
weap = "shotgun",
ammo = "shotgun-shell",
armor = "heavy-armor"
weap = 'shotgun',
ammo = 'shotgun-shell',
armor = 'heavy-armor'
},
{
weap = "pistol",
ammo = "firearm-magazine",
armor = "heavy-armor"
weap = 'pistol',
ammo = 'firearm-magazine',
armor = 'heavy-armor'
}
}
},
@ -289,507 +289,495 @@ public.raid_costs = {
chance = 100,
gear = {
{
weap = "shotgun",
ammo = "piercing-shotgun-shell",
armor = "heavy-armor"
weap = 'shotgun',
ammo = 'piercing-shotgun-shell',
armor = 'heavy-armor'
},
{
weap = "pistol",
ammo = "piercing-rounds-magazine",
armor = "heavy-armor"
weap = 'pistol',
ammo = 'piercing-rounds-magazine',
armor = 'heavy-armor'
}
}
}
},
}
public.wreck_loot = {
["iron-plate"] = {
['iron-plate'] = {
rare = 0.1,
count = { 20, 40 },
count = {20, 40}
},
["copper-plate"] = {
['copper-plate'] = {
rare = 0.1,
count = { 10, 30 },
count = {10, 30}
},
["empty-barrel"] = {
['empty-barrel'] = {
rare = 0.4,
count = { 1, 1},
count = {1, 1}
},
["copper-cable"] = {
['copper-cable'] = {
rare = 0.5,
count = { 5, 20 },
count = {5, 20}
},
["electronic-circuit"] = {
['electronic-circuit'] = {
rare = 0.6,
count = { 5, 20 },
count = {5, 20}
},
["firearm-magazine"] = {
['firearm-magazine'] = {
rare = 0.4,
count = { 1, 2 },
count = {1, 2}
},
["steel-plate"] = {
['steel-plate'] = {
rare = 0.8,
count = { 1, 5 },
count = {1, 5}
},
["explosives"] = {
['explosives'] = {
rare = 0.85,
count = { 1, 5 },
count = {1, 5}
},
["advanced-circuit"] = {
['advanced-circuit'] = {
rare = 0.9,
count = { 1, 5 },
count = {1, 5}
},
["processing-unit"] = {
['processing-unit'] = {
rare = 0.95,
count = { 1, 2 },
count = {1, 2}
},
["electric-engine-unit"] = {
['electric-engine-unit'] = {
rare = 0.95,
count = { 1, 1 },
count = {1, 1}
},
["battery"] = {
['battery'] = {
rare = 0.95,
count = { 1, 2 },
count = {1, 2}
},
["piercing-rounds-magazine"] = {
['piercing-rounds-magazine'] = {
rare = 0.99,
count = { 1, 2 },
},
count = {1, 2}
}
}
public.technologies = {
["military"] = true,
["artillery"] = false,
["artillery-shell-range-1"] = false,
["artillery-shell-speed-1"] = false,
["automation-3"] = false,
["battery-equipment"] = false,
["battery-mk2-equipment"] = false,
["belt-immunity-equipment"] = false,
["distractor"] = false,
["destroyer"] = false,
["discharge-defense-equipment"] = false,
["energy-shield-equipment"] = false,
["energy-shield-mk2-equipment"] = false,
["exoskeleton-equipment"] = false,
["explosive-rocketry"] = false,
["flamethrower"] = false,
["fusion-reactor-equipment"] = false,
["kovarex-enrichment-process"] = false,
["land-mine"] = false,
["logistics-3"] = false,
["military-4"] = false,
["modular-armor"] = false,
["night-vision-equipment"] = false,
["nuclear-fuel-reprocessing"] = false,
["nuclear-power"] = false,
["personal-laser-defense-equipment"] = false,
["personal-roboport-equipment"] = false,
["personal-roboport-mk2-equipment"] = false,
["power-armor"] = false,
["power-armor-mk2"] = false,
["refined-flammables-1"] = false,
["refined-flammables-2"] = false,
["refined-flammables-3"] = false,
["refined-flammables-4"] = false,
["refined-flammables-5"] = false,
["refined-flammables-6"] = false,
["refined-flammables-7"] = false,
["rocketry"] = false,
["solar-panel-equipment"] = false,
["stack-inserter"] = false,
["stronger-explosives-2"] = false,
["stronger-explosives-3"] = false,
["stronger-explosives-4"] = false,
["stronger-explosives-5"] = false,
["stronger-explosives-6"] = false,
["stronger-explosives-7"] = false,
["physical-projectile-damage-4"] = false,
["physical-projectile-damage-5"] = false,
["physical-projectile-damage-6"] = false,
["physical-projectile-damage-7"] = false,
["weapon-shooting-speed-4"] = false,
["weapon-shooting-speed-5"] = false,
["weapon-shooting-speed-6"] = false,
["energy-weapons-damage-1"] = false,
["energy-weapons-damage-2"] = false,
["energy-weapons-damage-3"] = false,
["energy-weapons-damage-4"] = false,
["energy-weapons-damage-5"] = false,
["energy-weapons-damage-6"] = false,
["energy-weapons-damage-7"] = false,
["laser-shooting-speed-2"] = false,
["laser-shooting-speed-3"] = false,
["laser-shooting-speed-4"] = false,
["laser-shooting-speed-5"] = false,
["laser-shooting-speed-6"] = false,
["laser-shooting-speed-7"] = false,
["follower-robot-count-2"] = false,
["follower-robot-count-3"] = false,
["follower-robot-count-4"] = false,
["follower-robot-count-5"] = false,
["follower-robot-count-6"] = false,
["follower-robot-count-7"] = false,
["tank"] = false,
["uranium-ammo"] = false,
["uranium-processing"] = false,
["atomic-bomb"] = false,
['military'] = true,
['artillery'] = false,
['artillery-shell-range-1'] = false,
['artillery-shell-speed-1'] = false,
['automation-3'] = false,
['battery-equipment'] = false,
['battery-mk2-equipment'] = false,
['belt-immunity-equipment'] = false,
['distractor'] = false,
['destroyer'] = false,
['discharge-defense-equipment'] = false,
['energy-shield-equipment'] = false,
['energy-shield-mk2-equipment'] = false,
['exoskeleton-equipment'] = false,
['explosive-rocketry'] = false,
['flamethrower'] = false,
['fusion-reactor-equipment'] = false,
['kovarex-enrichment-process'] = false,
['land-mine'] = false,
['logistics-3'] = false,
['military-4'] = false,
['modular-armor'] = false,
['night-vision-equipment'] = false,
['nuclear-fuel-reprocessing'] = false,
['nuclear-power'] = false,
['personal-laser-defense-equipment'] = false,
['personal-roboport-equipment'] = false,
['personal-roboport-mk2-equipment'] = false,
['power-armor'] = false,
['power-armor-mk2'] = false,
['refined-flammables-1'] = false,
['refined-flammables-2'] = false,
['refined-flammables-3'] = false,
['refined-flammables-4'] = false,
['refined-flammables-5'] = false,
['refined-flammables-6'] = false,
['refined-flammables-7'] = false,
['rocketry'] = false,
['solar-panel-equipment'] = false,
['stack-inserter'] = false,
['stronger-explosives-2'] = false,
['stronger-explosives-3'] = false,
['stronger-explosives-4'] = false,
['stronger-explosives-5'] = false,
['stronger-explosives-6'] = false,
['stronger-explosives-7'] = false,
['physical-projectile-damage-4'] = false,
['physical-projectile-damage-5'] = false,
['physical-projectile-damage-6'] = false,
['physical-projectile-damage-7'] = false,
['weapon-shooting-speed-4'] = false,
['weapon-shooting-speed-5'] = false,
['weapon-shooting-speed-6'] = false,
['energy-weapons-damage-1'] = false,
['energy-weapons-damage-2'] = false,
['energy-weapons-damage-3'] = false,
['energy-weapons-damage-4'] = false,
['energy-weapons-damage-5'] = false,
['energy-weapons-damage-6'] = false,
['energy-weapons-damage-7'] = false,
['laser-shooting-speed-2'] = false,
['laser-shooting-speed-3'] = false,
['laser-shooting-speed-4'] = false,
['laser-shooting-speed-5'] = false,
['laser-shooting-speed-6'] = false,
['laser-shooting-speed-7'] = false,
['follower-robot-count-2'] = false,
['follower-robot-count-3'] = false,
['follower-robot-count-4'] = false,
['follower-robot-count-5'] = false,
['follower-robot-count-6'] = false,
['follower-robot-count-7'] = false,
['tank'] = false,
['uranium-ammo'] = false,
['uranium-processing'] = false,
['atomic-bomb'] = false
}
public.merchant_offer = {
{
price = {
{
type = "item",
name = "iron-plate",
type = 'item',
name = 'iron-plate',
amount = 10
},
{
type = "item",
name = "advanced-circuit",
type = 'item',
name = 'advanced-circuit',
amount = 2
},
{
type = "item",
name = "battery",
type = 'item',
name = 'battery',
amount = 2
},
{
type = "item",
name = "small-lamp",
type = 'item',
name = 'small-lamp',
amount = 2
},
{
type = "item",
name = "copper-cable",
type = 'item',
name = 'copper-cable',
amount = 5
},
{
type = "item",
name = "steel-plate",
type = 'item',
name = 'steel-plate',
amount = 1
},
}
},
offer = {
type = "nothing",
effect_description = "Construct a GPS receiver"
type = 'nothing',
effect_description = 'Construct a GPS receiver'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 100
}
},
offer = {
type = "give-item",
item = "heavy-armor"
type = 'give-item',
item = 'heavy-armor'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 500
}
},
offer = {
type = "give-item",
item = "modular-armor"
type = 'give-item',
item = 'modular-armor'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 12000
}
},
offer = {
type = "give-item",
item = "power-armor"
type = 'give-item',
item = 'power-armor'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 100
}
},
offer = {
type = "give-item",
item = "night-vision-equipment"
type = 'give-item',
item = 'night-vision-equipment'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 70
}
},
offer = {
type = "give-item",
item = "battery-equipment"
type = 'give-item',
item = 'battery-equipment'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 700
}
},
offer = {
type = "give-item",
item = "battery-mk2-equipment"
type = 'give-item',
item = 'battery-mk2-equipment'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 1200
}
},
offer = {
type = "give-item",
item = "exoskeleton-equipment"
type = 'give-item',
item = 'exoskeleton-equipment'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 2500
}
},
offer = {
type = "give-item",
item = "fusion-reactor-equipment"
type = 'give-item',
item = 'fusion-reactor-equipment'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 200
}
},
offer = {
type = "give-item",
item = "personal-roboport-equipment"
type = 'give-item',
item = 'personal-roboport-equipment'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 400
}
},
offer = {
type = "give-item",
item = "personal-roboport-mk2-equipment"
type = 'give-item',
item = 'personal-roboport-mk2-equipment'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 90
}
},
offer = {
type = "give-item",
item = "solar-panel-equipment"
type = 'give-item',
item = 'solar-panel-equipment'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 300
}
},
offer = {
type = "give-item",
item = "energy-shield-equipment"
type = 'give-item',
item = 'energy-shield-equipment'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 2000
}
},
offer = {
type = "give-item",
item = "energy-shield-mk2-equipment"
type = 'give-item',
item = 'energy-shield-mk2-equipment'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 50
}
},
offer = {
type = "give-item",
item = "flamethrower-ammo"
type = 'give-item',
item = 'flamethrower-ammo'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 1
}
},
offer = {
type = "give-item",
item = "firearm-magazine"
type = 'give-item',
item = 'firearm-magazine'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 5
}
},
offer = {
type = "give-item",
item = "piercing-rounds-magazine"
type = 'give-item',
item = 'piercing-rounds-magazine'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 1000
}
},
offer = {
type = "unlock-recipe",
recipe = "flamethrower"
type = 'unlock-recipe',
recipe = 'flamethrower'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 50
}
},
offer = {
type = "give-item",
item = "defender-capsule"
type = 'give-item',
item = 'defender-capsule'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 200
}
},
offer = {
type = "give-item",
item = "distractor-capsule"
type = 'give-item',
item = 'distractor-capsule'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 250
}
},
offer = {
type = "give-item",
item = "destroyer-capsule"
type = 'give-item',
item = 'destroyer-capsule'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 70
}
},
offer = {
type = "unlock-recipe",
recipe = "filter-inserter"
},
type = 'unlock-recipe',
recipe = 'filter-inserter'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 100
}
},
offer = {
type = "unlock-recipe",
recipe = "stack-inserter"
},
type = 'unlock-recipe',
recipe = 'stack-inserter'
}
},
{
price = {
{
type = "item",
name = "coin",
type = 'item',
name = 'coin',
amount = 170
}
},
offer = {
type = "unlock-recipe",
recipe = "stack-filter-inserter"
},
},
{
price = {
{
type = "item",
name = "coin",
amount = 65000
type = 'unlock-recipe',
recipe = 'stack-filter-inserter'
}
},
offer = {
type = "give-item",
item = "computer"
}
},
}
public.manual = [[
public.manual =
[[
[font=heading-1]Planet Prison (1.1.0) - Manual[/font]
[font=default-bold]You did naughty things and was sent to this planet with a one way ticket. Once an industrial site, turned into non-hospitable planet due to pollution and war. Among other inmates, there are still bandits scavenging through the junk looking for rare items.

View File

@ -1,17 +1,15 @@
local public = {}
local _common = require(".common")
local _common = require('.common')
public.command = {
--[[
@param args nil
--]]
noop = 0,
--[[
@param args nil
--]]
seek_and_destroy_player = 1,
--[[
@param args = {
agents, // All movable agents
@ -25,16 +23,13 @@ public.command = {
init - Initialize the module.
--]]
public.init = function()
if global.this == nil then
global.this = {}
end
end
local function _get_direction(src, dest)
local src_x = _common.get_axis(src, "x")
local src_y = _common.get_axis(src, "y")
local dest_x = _common.get_axis(dest, "x")
local dest_y = _common.get_axis(dest, "y")
local src_x = _common.get_axis(src, 'x')
local src_y = _common.get_axis(src, 'y')
local dest_x = _common.get_axis(dest, 'x')
local dest_y = _common.get_axis(dest, 'y')
local step = {
x = nil,
@ -63,7 +58,7 @@ end
local function _move_to(ent, trgt, min_distance)
local state = {
walking = false,
walking = false
}
local distance = _common.get_distance(trgt.position, ent.position)
@ -102,10 +97,10 @@ local function _do_job_seek_and_destroy_player(surf)
end
local search_info = {
name = "character",
name = 'character',
position = player.character.position,
radius = 20,
force = "enemy",
force = 'enemy'
}
local ents = surf.find_entities_filtered(search_info)
@ -148,13 +143,13 @@ local function _do_job_attack_objects(surf, args)
position = agent.position,
radius = 15,
type = {
"projectile",
"beam"
'projectile',
'beam'
},
force = {
"enemy",
"player",
"neutral",
'enemy',
'player',
'neutral'
},
invert = true
}

View File

@ -1,12 +1,19 @@
local public = {}
local _common = require(".common")
local _common = require('.common')
local Global = require 'utils.global'
local Token = require 'utils.token'
local this = {}
Global.register(
this,
function(tbl)
this = tbl
end
)
public.init = function()
if global.this == nil then
global.this = {}
end
global.this._bps = {}
this._bps = {}
end
--[[
@ -20,7 +27,7 @@ public.push_blueprint = function(name, bp)
hook = nil,
refs = {}
}
global.this._bps[name] = entry
this._bps[name] = entry
end
--[[
@ -30,16 +37,18 @@ set_blueprint_hook - Set callback to a blueprint.
--]]
public.set_blueprint_hook = function(name, hook)
if name == nil then
log("bp.set_blueprint_hook: name is nil")
log('bp.set_blueprint_hook: name is nil')
return
end
if global.this._bps[name] == nil then
log("bp.set_blueprint_hook: unrecognized blueprint")
if this._bps[name] == nil then
log('bp.set_blueprint_hook: unrecognized blueprint')
return
end
global.this._bps[name].hook = hook
local token = Token.register(hook)
this._bps[name].hook = token
end
--[[
@ -48,13 +57,13 @@ get_references - Get all references of the blueprint on the map.
--]]
public.get_references = function(name)
if name == nil then
log("bp.get_references: name is nil")
log('bp.get_references: name is nil')
return {}
end
local object = global.this._bps[name]
local object = this._bps[name]
if object == nil then
log("bp.get_references: unrecognized blueprint")
log('bp.get_references: unrecognized blueprint')
return {}
end
@ -67,13 +76,13 @@ get_references - Gets opaque object representing bp references.
--]]
public.get_references = function(name)
if name == nil then
log("bp.get_references: name is nil")
log('bp.get_references: name is nil')
return
end
local object = global.this._bps[name]
local object = this._bps[name]
if object == nil then
log("bp.get_references: unrecognized blueprint")
log('bp.get_references: unrecognized blueprint')
return
end
@ -104,7 +113,6 @@ public.reference_get_timestamp = function(reference)
return reference.timestamp
end
--[[
unlink_references_filtered - Unlinks all references of blueprint on the map if they
meet the query rules.
@ -116,13 +124,13 @@ unlinked.
--]]
public.unlink_references_filtered = function(name, query)
if name == nil then
log("bp.get_references: name is nil")
log('bp.get_references: name is nil')
return
end
local object = global.this._bps[name]
local object = this._bps[name]
if object == nil then
log("bp.get_references: unrecognized blueprint")
log('bp.get_references: unrecognized blueprint')
return
end
@ -154,13 +162,13 @@ removed.
--]]
public.destroy_references_filtered = function(surf, name, query)
if name == nil then
log("bp.get_references: name is nil")
log('bp.get_references: name is nil')
return
end
local object = global.this._bps[name]
local object = this._bps[name]
if object == nil then
log("bp.get_references: unrecognized blueprint")
log('bp.get_references: unrecognized blueprint')
return
end
@ -180,7 +188,7 @@ public.destroy_references_filtered = function(surf, name, query)
local tiles = {}
for _, tile in pairs(ref.tiles) do
tile.name = "concrete"
tile.name = 'concrete'
table.insert(tiles, tile)
end
@ -200,7 +208,7 @@ public.destroy_references = function(surf, name)
public.destroy_references_filtered(surf, name, {})
end
global._bp_destroy_reference = function(surf, ref)
local _bp_destroy_reference = function(surf, ref)
for _, ent in pairs(ref.entities) do
if ent.valid then
ent.destroy()
@ -213,7 +221,7 @@ global._bp_destroy_reference = function(surf, ref)
goto continue
end
tile.name = "concrete"
tile.name = 'concrete'
table.insert(tiles, tile)
::continue::
end
@ -227,11 +235,11 @@ destroy_reference - Destroys reference of a blueprint at given surface.
@param reference - Any valid reference.
--]]
public.destroy_reference = function(surf, reference)
for _, meta in pairs(global.this._bps) do
for _, meta in pairs(this._bps) do
for i = 1, #meta.refs do
local ref = meta.refs[i]
if reference.id == ref.id then
global._bp_destroy_reference(surf, ref)
_bp_destroy_reference(surf, ref)
table.remove(meta.refs, i)
return
end
@ -247,8 +255,8 @@ local function _build_tiles(surf, point, tiles)
local _tile = {
name = tile.name,
position = {
x = get_axis(tile.position, "x") + get_axis(point, "x"),
y = get_axis(tile.position, "y") + get_axis(point, "y")
x = get_axis(tile.position, 'x') + get_axis(point, 'x'),
y = get_axis(tile.position, 'y') + get_axis(point, 'y')
}
}
table.insert(_tiles, _tile)
@ -258,7 +266,6 @@ local function _build_tiles(surf, point, tiles)
return _tiles
end
local function _build_entities(surf, point, entities, hook, args)
local _entities = {}
@ -266,10 +273,10 @@ local function _build_entities(surf, point, entities, hook, args)
for _, ent in pairs(entities) do
local ent_info = {
position = {
x = get_axis(ent.position, "x") + get_axis(point, "x"),
y = get_axis(ent.position, "y") + get_axis(point, "y")
x = get_axis(ent.position, 'x') + get_axis(point, 'x'),
y = get_axis(ent.position, 'y') + get_axis(point, 'y')
},
name = ent.name,
name = ent.name
}
local e = surf.create_entity(ent_info)
if not e or not e.valid then
@ -277,7 +284,8 @@ local function _build_entities(surf, point, entities, hook, args)
end
if hook then
hook(e, args)
local token = Token.get(hook)
token(e, args)
end
table.insert(_entities, e)
@ -296,18 +304,18 @@ build - Place blueprint at given point.
--]]
public.build = function(surf, name, point, args)
if surf == nil then
log("bp.build: surf is nil")
log('bp.build: surf is nil')
return
end
if name == nil then
log("bp.build: name is nil")
log('bp.build: name is nil')
return
end
local object = global.this._bps[name]
local object = this._bps[name]
if object == nil then
log("bp.set_blueprint_hook: unrecognized blueprint")
log('bp.set_blueprint_hook: unrecognized blueprint')
return
end
@ -315,7 +323,7 @@ public.build = function(surf, name, point, args)
entities = {},
tiles = {},
bb = nil,
timestamp = game.tick,
timestamp = game.tick
}
local bbs = {}
local tiles = object.bp.tiles
@ -325,9 +333,9 @@ public.build = function(surf, name, point, args)
table.insert(bbs, bb)
local query = {
name = "character",
name = 'character',
area = bb,
invert = true,
invert = true
}
for _, ent in pairs(surf.find_entities_filtered(query)) do
if ent.valid then
@ -343,9 +351,9 @@ public.build = function(surf, name, point, args)
table.insert(bbs, bb)
local query = {
name = "character",
name = 'character',
area = bb,
invert = true,
invert = true
}
for _, ent_found in pairs(surf.find_entities_filtered(query)) do
if not ent_found.valid then

View File

@ -1,5 +1,15 @@
local public = {}
local common = require(".common")
local common = require('.common')
local Global = require 'utils.global'
local this = {}
Global.register(
this,
function(tbl)
this = tbl
end
)
--[[
init - Initialize claim system.
@ -7,30 +17,26 @@ init - Initialize claim system.
@param max_distance - Maximal distance allowed between markers
--]]
public.init = function(names, max_distance)
if global.this == nil then
global.this = {}
end
if type(names) ~= "table" then
if type(names) ~= 'table' then
names = {names}
end
global.this._claims_info = {}
global.this._claims_visible_to = {}
global.this._claim_markers = names
global.this._claim_max_dist = max_distance
this._claims_info = {}
this._claims_visible_to = {}
this._claim_markers = names
this._claim_max_dist = max_distance
end
local function claim_new_claim(ent, deps)
local comm = deps.common
local point = {
{
x = comm.get_axis(ent.position, "x"),
y = comm.get_axis(ent.position, "y"),
x = comm.get_axis(ent.position, 'x'),
y = comm.get_axis(ent.position, 'y')
}
}
local claims = global.this._claims_info
local claims = this._claims_info
if claims[ent.force.name] == nil then
claims[ent.force.name] = {}
claims[ent.force.name].polygons = {}
@ -42,10 +48,10 @@ local function claim_new_claim(ent, deps)
end
local function claim_on_build_entity(ent, deps)
local max_dist = global.this._claim_max_dist
local max_dist = this._claim_max_dist
local force = ent.force.name
local comm = deps.common
local data = global.this._claims_info[force]
local data = this._claims_info[force]
if data == nil then
claim_new_claim(ent, deps)
@ -66,8 +72,8 @@ local function claim_on_build_entity(ent, deps)
in_range = true
point = {
x = comm.get_axis(ent.position, "x"),
y = comm.get_axis(ent.position, "y"),
x = comm.get_axis(ent.position, 'x'),
y = comm.get_axis(ent.position, 'y')
}
table.insert(points, point)
data.claims[i] = comm.get_convex_hull(points)
@ -83,7 +89,7 @@ local function claim_on_build_entity(ent, deps)
end
local function claims_in_markers(name)
for _, marker in pairs(global.this._claim_markers) do
for _, marker in pairs(this._claim_markers) do
if name == marker then
return true
end
@ -102,7 +108,7 @@ public.on_built_entity = function(ent)
end
local deps = {
common = common,
common = common
}
claim_on_build_entity(ent, deps)
end
@ -110,7 +116,7 @@ end
local function claim_on_entity_died(ent, deps)
local comm = deps.common
local force = ent.force.name
local data = global.this._claims_info[force]
local data = this._claims_info[force]
if data == nil then
return
end
@ -136,7 +142,7 @@ local function claim_on_entity_died(ent, deps)
end
if #data.claims == 0 then
global.this._claims_info[force] = nil
this._claims_info[force] = nil
end
end
@ -150,7 +156,7 @@ public.on_entity_died = function(ent)
end
local deps = {
common = common,
common = common
}
claim_on_entity_died(ent, deps)
end
@ -168,7 +174,7 @@ on_player_died - Event processing function
@param player - Player
--]]
public.on_player_died = function(player)
global.this._claims_info[player.name] = nil
this._claims_info[player.name] = nil
end
--[[
@ -176,16 +182,16 @@ get_claims - Get all claims data points for given force.
@param f_name - Force name.
--]]
public.get_claims = function(f_name)
if global.this._claims_info[f_name] == nil then
if this._claims_info[f_name] == nil then
return {}
end
return global.this._claims_info[f_name].claims
return this._claims_info[f_name].claims
end
local function claims_update_visiblity()
if #global.this._claims_visible_to == 0 then
for _, info in pairs(global.this._claims_info) do
if #this._claims_visible_to == 0 then
for _, info in pairs(this._claims_info) do
for _, id in pairs(info.polygons) do
if rendering.is_valid(id) then
rendering.set_visible(id, false)
@ -195,11 +201,11 @@ local function claims_update_visiblity()
return
end
for _, info in pairs(global.this._claims_info) do
for _, info in pairs(this._claims_info) do
for _, id in pairs(info.polygons) do
if rendering.is_valid(id) then
rendering.set_visible(id, true)
rendering.set_players(id, global.this._claims_visible_to)
rendering.set_players(id, this._claims_visible_to)
end
end
end
@ -210,13 +216,13 @@ set_visibility_to - Specifies who can see the claims and redraws.
@param name - Name of a player.
--]]
public.set_visibility_to = function(name)
for _, p in pairs(global.this._claims_visible_to) do
for _, p in pairs(this._claims_visible_to) do
if p == name then
return
end
end
table.insert(global.this._claims_visible_to, name)
table.insert(this._claims_visible_to, name)
claims_update_visiblity()
end
@ -225,10 +231,10 @@ remove_visibility_from - Remove the claim visibility from the player.
@param name - Name of a player.
--]]
public.remove_visibility_from = function(name)
for i = 1, #global.this._claims_visible_to do
local p = global.this._claims_visible_to[i]
for i = 1, #this._claims_visible_to do
local p = this._claims_visible_to[i]
if p == name then
table.remove(global.this._claims_visible_to, i)
table.remove(this._claims_visible_to, i)
claims_update_visiblity()
break
end

View File

@ -1,8 +1,18 @@
local public = {}
local Global = require 'utils.global'
local this = {}
Global.register(
this,
function(tbl)
this = tbl
end
)
public.init = function()
if global.this == nil then
global.this = {}
if this == nil then
this = {}
end
end
@ -12,11 +22,11 @@ rand_range - Return random integer within the range.
@param stop - Stop range.
--]]
public.rand_range = function(start, stop)
if not global.this.rng then
global.this.rng = game.create_random_generator()
if not this.rng then
this.rng = game.create_random_generator()
end
return global.this.rng(start, stop)
return this.rng(start, stop)
end
--[[

View File

@ -1,16 +1,23 @@
local public = {}
local _common = require(".common")
local _simplex = require(".simplex_noise")
local _common = require('.common')
local _simplex = require('.simplex_noise')
local Token = require 'utils.token'
local Global = require 'utils.global'
local this = {}
Global.register(
this,
function(tbl)
this = tbl
end
)
public.init = function()
if global.this == nil then
global.this = {}
end
global.this._grid = {}
global.this._exclusions = {}
global.this._layers = {}
global.this._collision_mask = {}
this._grid = {}
this._exclusions = {}
this._layers = {}
this._collision_mask = {}
_simplex.init()
end
--[[
@ -18,7 +25,7 @@ push_chunk - Pushes chunk position into a grid for later processing.
@param chunk - ChunkPosition
--]]
public.push_chunk = function(chunk)
table.insert(global.this._grid, chunk)
table.insert(this._grid, chunk)
end
--[[
@ -26,7 +33,7 @@ add_excluding_bounding_box - Pushes bounding box into exclusion list.
@param bb - BoundindBox.
--]]
public.push_excluding_bounding_box = function(bb)
table.insert(global.this._exclusions, bb)
table.insert(this._exclusions, bb)
end
--[[
@ -34,10 +41,10 @@ remove_ecluding_bounding_box - Removes bounding box from exclusion list.
@param bb - BoundingBox to get rid of.
--]]
public.remove_excluding_bounding_box = function(bb)
for i = 1, #global.this._exclusions do
local box = global.this._exclusions[i]
for i = 1, #this._exclusions do
local box = this._exclusions[i]
if box == bb then
table.remove(global.this._exclusions, i)
table.remove(this._exclusions, i)
break
end
end
@ -60,10 +67,10 @@ public.add_noise_layer = function(type, name, objects, elevation, resolution)
resolution = resolution,
cache = {},
hook = nil,
deps = nil,
deps = nil
}
table.insert(global.this._layers, layer)
table.insert(this._layers, layer)
end
--[[
@ -72,7 +79,7 @@ add_noise_layer_hook - Execute callback on created object.
@param hook - Callback that will be called with an object argument.
--]]
public.add_noise_layer_hook = function(name, hook)
for _, layer in pairs(global.this._layers) do
for _, layer in pairs(this._layers) do
if layer.name == name then
layer.hook = hook
break
@ -86,7 +93,7 @@ lua variable. This dependency then is injected into hook.
@param deps - Dependencies, any variable.
--]]
public.add_noise_layer_dependency = function(name, deps)
for _, layer in pairs(global.this._layers) do
for _, layer in pairs(this._layers) do
if layer.name == name then
layer.deps = deps
break
@ -99,7 +106,7 @@ set_collision_mask - Set which tiles should be ignored.
@param mask - Table of collision masks.
--]]
public.set_collision_mask = function(mask)
global.this._collision_mask = mask
this._collision_mask = mask
end
local function _do_job_tile(surf, layer)
@ -108,9 +115,24 @@ end
local function _do_job_entity(surf, layer)
local hook = layer.hook
if not hook then
return
end
local func = Token.get(hook)
if not func then
return
end
func = Token.get(func)
local deps = layer.deps
if not deps then
return
end
local func2 = Token.get(deps)
if not func2 then
return
end
for _, object in pairs(layer.cache) do
if object.name == "character" or object.name == "gun-turret" then
if object.name == 'character' or object.name == 'gun-turret' then
if not surf.can_place_entity(object) then
goto continue
end
@ -122,7 +144,7 @@ local function _do_job_entity(surf, layer)
end
if hook then
hook(ent, deps)
func(ent, func2)
end
::continue::
@ -132,20 +154,20 @@ end
local function _do_job(surf, x, y)
local point = {
x = x,
y = y,
y = y
}
for _, exclusion in pairs(global.this._exclusions) do
for _, exclusion in pairs(this._exclusions) do
if _common.point_in_bounding_box(point, exclusion) then
return
end
end
for _, layer in pairs(global.this._layers) do
for _, layer in pairs(this._layers) do
local ret = _simplex.get(point, layer.resolution)
if ret >= layer.elevation then
local tile = surf.get_tile(point)
for _, mask in pairs(global.this._collision_mask) do
for _, mask in pairs(this._collision_mask) do
if tile.collides_with(mask) then
goto continue
end
@ -159,7 +181,7 @@ local function _do_job(surf, x, y)
local object = {
name = object_name,
position = point,
position = point
}
table.insert(layer.cache, object)
@ -174,13 +196,13 @@ do_job - Do a single step propagation of a layers.
@param surf - LuaSurface, onto which action is taken.
--]]
public.do_job = function(surf)
if #global.this._grid <= 0 then
if #this._grid <= 0 then
return
end
local chunk = table.remove(global.this._grid)
local x = _common.get_axis(chunk, "x")
local y = _common.get_axis(chunk, "y")
local chunk = table.remove(this._grid)
local x = _common.get_axis(chunk, 'x')
local y = _common.get_axis(chunk, 'y')
chunk = {
left_top = {
@ -189,18 +211,18 @@ public.do_job = function(surf)
},
right_bottom = {
x = (x * 32) + 32,
y = (y * 32) + 32,
y = (y * 32) + 32
}
}
_common.for_bounding_box(surf, chunk, _do_job)
for _, layer in pairs(global.this._layers) do
for _, layer in pairs(this._layers) do
local cache = layer.cache
if #cache >= 1 then
if layer.type == "LuaTile" then
if layer.type == 'LuaTile' then
_do_job_tile(surf, layer)
elseif layer.type == "LuaEntity" then
elseif layer.type == 'LuaEntity' then
_do_job_entity(surf, layer)
end

View File

@ -1,12 +1,18 @@
local public = {}
local _global = require('utils.global')
local Global = require 'utils.global'
local Token = require 'utils.token'
local this = {}
Global.register(
this,
function(tbl)
this = tbl
end
)
public.init = function()
if global.this == nil then
global.this = {}
end
global.this.timers = {}
this.timers = {}
end
--[[
@ -16,16 +22,18 @@ set_timer - Sets a timer.
--]]
public.set_timer = function(left, hook)
local id = game.tick
local token = Token.register(hook)
local token2 = Token.register(left)
local entry = {
left = left,
hook_finish = hook,
left = token2,
hook_finish = token,
hook_update = nil,
deps = nil,
running = false,
last_update = 0,
last_update = 0
}
global.this.timers[id] = entry
this.timers[id] = entry
return id
end
@ -36,7 +44,8 @@ timers is updated.
@param hook - Hook that will be executed per update.
--]]
public.set_timer_on_update = function(id, hook)
global.this.timers[id].hook_update = hook
local token = Token.register(hook)
this.timers[id].hook_update = token
end
--[[
@ -45,7 +54,8 @@ set_timer_dependency - Adds dependency into user callback.
@param deps - Dependency of timer to add.
--]]
public.set_timer_dependency = function(id, deps)
global.this.timers[id].deps = deps
local token = Token.register(deps)
this.timers[id].deps = token
end
--[[
@ -53,8 +63,8 @@ set_timer_start - Sets the timer to run.
@param id - Id of a timer.
--]]
public.set_timer_start = function(id)
global.this.timers[id].running = true
global.this.timers[id].last_update = game.tick
this.timers[id].running = true
this.timers[id].last_update = game.tick
end
--[[
@ -62,14 +72,14 @@ kill_timer - Effectivly kills the timer.
@param id - Timer id.
--]]
public.kill_timer = function(id)
global.this.timers[id] = nil
this.timers[id] = nil
end
--[[
do_job - Execute timer logic within a tick.
--]]
public.do_job = function()
for id, entry in pairs(global.this.timers) do
for id, entry in pairs(this.timers) do
if entry.running == false then
goto continue
end
@ -89,7 +99,7 @@ public.do_job = function()
::premature_finish::
entry.hook_finish(entry.deps)
global.this.timers[id] = nil
this.timers[id] = nil
::continue::
end