Skip to content

Commit

Permalink
Update 4
Browse files Browse the repository at this point in the history
  • Loading branch information
ReikaKalseki committed Sep 18, 2018
1 parent 453f6bd commit 0860fcd
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 40 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
@@ -0,0 +1,5 @@
---------------------------------------------------------------------------------------------------
Version: 1.0.148
Date: Sep 18 2018
- Now increases laboratory speed as well
---------------------------------------------------------------------------------------------------
165 changes: 125 additions & 40 deletions control.lua
Expand Up @@ -5,22 +5,14 @@ function initGlobal(force)
if not global.creative then
global.creative = {}
end

if not global.creative.cachedRefills then
global.creative.cachedRefills = {}
end
end

initGlobal(false)

script.on_load(function()

end)

script.on_init(function()
initGlobal(true)
end)

script.on_configuration_changed(function()
initGlobal(true)
end)

local function prepareTerrain()
local r = Config.radius
game.forces.neutral.chart(game.surfaces.nauvis, {{-r, -r}, {r, r}}) --generate the area
Expand All @@ -36,6 +28,11 @@ local function prepareTerrain()
end
end
game.surfaces[1].set_tiles(tiles)

for _,force in pairs(game.forces) do
local r = Config.radius
force.chart(game.surfaces.nauvis, {{-r, -r}, {r, r}})
end
end

local function preparePlayers()
Expand All @@ -52,28 +49,48 @@ local function initMap()
preparePlayers()
end

local function convertGhostsNear(player)
local ghosts = player.surface.find_entities_filtered{type = {"entity-ghost", "tile-ghost"}, area = box}
for _,entity in pairs(ghosts) do
if entity.type == "entity-ghost" then
convertGhostToRealEntity(player, entity)
elseif entity.type == "tile-ghost" then
entity.revive()
script.on_load(function()
commands.add_command("initCreative", {"cmd.init-creative-help"}, function(event)
if game.players[event.player_index].admin then
game.print("EasyCreative: Initializing creative mode.")
initMap()
end
end
end

script.on_event(defines.events.on_tick, function(event)
if event.tick%20 ~= 0 then return end
end)

if #game.players > 0 then
local player = game.players[math.random(1, #game.players)]
if player.cheat_mode then
convertGhostsNear(player)
commands.add_command("initMap", {"cmd.init-map-help"}, function(event)
if game.players[event.player_index].admin then
game.print("EasyCreative: Preparing creative terrain.")
prepareTerrain()
end
end
end)

commands.add_command("initPlayer", {"cmd.init-player-help"}, function(event)
if game.players[event.player_index].admin then
game.print("EasyCreative: Initializing creative mode for player " .. game.players[event.player_index].name)
initPlayer(game.players[event.player_index])
initForce(game.players[event.player_index].force, true)
end
end)

commands.add_command("refill", {"cmd.refill-help"}, function(event)
if game.players[event.player_index].admin then
local entity = game.players[event.player_index].selected
if entity then
local item = getRefilledItem(entity)
if item then
game.print("EasyCreative: Marking entity " .. entity.name .. " @ " .. entity.position.x .. ", " .. entity.position.y .. " for refill with " .. item.display)
table.insert(global.creative.cachedRefills, {entity = entity, item = item})
else
game.print("EasyCreative: Entity is empty!")
end
else
game.print("EasyCreative: No entity selected!")
end
end
end)
end)

--[[
script.on_event(defines.events.on_console_command, function(event)
if event.command == "c" and string.find(event.parameters, "initCreative") then
game.print("EasyCreative: Initializing creative mode.")
Expand All @@ -88,28 +105,87 @@ script.on_event(defines.events.on_console_command, function(event)
initPlayer(game.players[event.player_index])
initForce(game.players[event.player_index].force, true)
end
if event.command == "c" and string.find(event.parameters, "refill") then
local entity = game.players[event.player_index].selected
if entity then
local item = getRefilledItem(entity)
if item then
game.print("EasyCreative: Marking entity " .. entity.name .. " @ " .. entity.position.x .. ", " .. entity.position.y .. " for refill with " .. item.display)
table.insert(global.creative.cachedRefills, {entity = entity, item = item})
else
game.print("EasyCreative: Entity is empty!")
end
else
game.print("EasyCreative: No entity selected!")
end
end
end)
--]]
script.on_event(defines.events.on_player_joined_game, function(event)
initPlayer(game.players[event.player_index])
initForce(game.players[event.player_index].force)
script.on_init(function()
initGlobal(true)
end)
script.on_configuration_changed(function()
initGlobal(true)
end)
local function convertGhostsNear(player)
local ghosts = player.surface.find_entities_filtered{type = {"entity-ghost", "tile-ghost"}, area = box}
for _,entity in pairs(ghosts) do
if entity.type == "entity-ghost" then
convertGhostToRealEntity(player, entity)
elseif entity.type == "tile-ghost" then
entity.revive()
end
end
end
script.on_event(defines.events.on_tick, function(event)
if event.tick%20 ~= 0 then return end
local creative = global.creative
if #game.players > 0 then
local player = game.players[math.random(1, #game.players)]
if player.cheat_mode then
convertGhostsNear(player)
end
end
if event.tick%120 == 0 and creative.cachedRefills and #creative.cachedRefills > 0 then
for i,entry in ipairs(creative.cachedRefills) do
if entry.entity.valid then
local item = entry.item
if item.type == "item" then
entry.entity.insert({name = item.name, count = 1000000})
else
entry.entity.fluidbox[1] = {name = item.name, amount = 1000000}
end
else
table.remove(creative.cachedRefills, i)
end
end
end
end)
script.on_event(defines.events.on_marked_for_deconstruction, function(event)
local entity = event.entity
if event.player_index then
local player = game.players[event.player_index]
if player.cheat_mode then
local items = entity.prototype.mineable_properties.products and entity.prototype.mineable_properties.products or {}
for _,item in pairs(items) do
if item.type ~= "fluid" and player.get_item_count(item.name) == 0 then
player.insert({name = item.name, count = 1})
if entity.type ~= "item-entity" then
local items = entity.prototype.mineable_properties.products and entity.prototype.mineable_properties.products or {}
for _,item in pairs(items) do
if item.type ~= "fluid" and (game.item_prototypes[item.name].place_result or game.item_prototypes[item.name].place_as_tile_result) and player.get_item_count(item.name) == 0 then
player.insert({name = item.name, count = 1})
end
end
script.raise_event(defines.events.on_pre_player_mined_item, {entity=entity, player_index=event.player_index, tick=game.tick, name="on_pre_player_mined_item", creative=true, buffer = {}})
end
entity.destroy()
end
end
script.raise_event(defines.events.on_pre_player_mined_item, {entity=entity, player_index=event.player_index, tick=game.tick, name="on_pre_player_mined_item", creative=true, buffer = {}})
entity.destroy()
end)
script.on_event(defines.events.on_built_entity, function(event)
Expand All @@ -132,13 +208,22 @@ script.on_event(defines.events.on_player_mined_entity, function(event)
if player and player.cheat_mode then
for i = 1,#event.buffer do
local item = event.buffer[i]
if player.get_item_count(item.name) > 0 then
if player.get_item_count(item.name) > 0 or not(item.prototype.place_result or item.prototype.place_as_tile_result) then
event.buffer.remove({name = item.name, count = item.count})
end
end
end
end)
script.on_event(defines.events.on_technology_effects_reset, function(event)
initForce(event.force)
local flag = false
for _,player in pairs(event.force.players) do
if player.cheat_mode then
flag = true
break
end
end
if flag then
initForce(event.force)
end
end)
16 changes: 16 additions & 0 deletions functions.lua
Expand Up @@ -22,6 +22,7 @@ function initForce(force, full)
force.character_reach_distance_bonus = force.character_reach_distance_bonus+20
force.character_build_distance_bonus = force.character_build_distance_bonus+20
force.character_build_distance_bonus = force.character_build_distance_bonus+20
force.laboratory_speed_modifier = force.laboratory_speed_modifier*10
end

function convertGhostToRealEntity(player, ghost)
Expand All @@ -36,4 +37,19 @@ function convertGhostToRealEntity(player, ghost)
script.raise_event(defines.events.on_put_item, {position=repl.position, player_index=player.index, shift_build=false, built_by_moving=false, direction=repl.direction, revive=true})
script.raise_event(defines.events.on_built_entity, {created_entity=repl, player_index=player.index, tick=game.tick, name="on_built_entity", revive=true})
end
end

function getRefilledItem(entity)
if entity.fluidbox and #entity.fluidbox > 0 and entity.fluidbox[1] then
return {type = "fluidbox", name = entity.fluidbox[1].name, display = "fluid: " .. entity.fluidbox[1].name}
end
local inv = entity.get_inventory(defines.inventory.cargo_wagon)
if inv then
for i = 1,#inv do
if inv[i] and inv[i].valid_for_read then
return {type = "item", name = inv[i].name, display = "item: " .. inv[i].name}
end
end
end
return nil
end

0 comments on commit 0860fcd

Please sign in to comment.