Skip to content

Commit

Permalink
Version 1.0.9:
Browse files Browse the repository at this point in the history
Properly fixed the technology to include Bob's Science Pack 4 if bobtech is loaded.
Fixed that the mod's on_tick function wasn't getting re-registered when loading a saved game.
Added a remote interface to allow other mods to detect when an ion cannon is targeted.
  • Loading branch information
Suprcheese committed Apr 6, 2016
1 parent 2fdd8d8 commit 9cadcd2
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 20 deletions.
8 changes: 8 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ Version 1.0.8 - February 26, 2016
---------------------------------
Added Russian translation (thanks to apriori).
To increase performance, the on_tick function is now only registered upon first launching an ion cannon into orbit - there was no need to run this function in the early game before any ion cannons have been launched.


Version 1.0.9 - March 1, 2016
-----------------------------
Properly fixed the technology to include Bob's Science Pack 4 if bobtech is loaded.
Fixed that the mod's on_tick function wasn't getting re-registered when loading a saved game.
Added a remote interface to allow other mods to detect when an ion cannon is targeted.

20 changes: 18 additions & 2 deletions Readme.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Orbital Ion Cannon 1.0.8
Orbital Ion Cannon 1.0.9
========================

Version 1.0.8 was released February 26, 2016, was tested using Factorio v0.12.24, and was authored by Supercheese.
Version 1.0.9 was released March 1, 2016, was tested using Factorio v0.12.24, and was authored by Supercheese.

Do you have a large, late-game megabase and wish there were more cool things you could build? Do you wish you could do more with the rockets you launch than just increment a single number? Do you really hate biters? If so, then this mod is for you!
Build a giant ion cannon and launch it into orbit with a rocket, wait for it to charge up, and then you're ready to call down the thunder on those pesky aliens.
Expand All @@ -21,6 +21,22 @@ This mod also has configuration options available in config.lua. Here you may ad
-The minimum time between targeting multiple ion cannons


Modding Details:
----------------
This mod implements a custom event, on_ion_cannon_fired, which can function just like other lua events (https://wiki.factorio.com/index.php?title=Lua/Events).
In order to use this event in another mod, you should use the following code:

script.on_event(remote.call("orbital_ion_cannon", "on_ion_cannon_fired"), function(event)
...
end)

Where the ... can be any code of your choosing. The following variables are available when using this custom event:

event.force The force whose ion cannon is firing
event.player_index The player index of who fired the ion cannon
event.position The position the ion cannon is firing at


Credits:
--------

Expand Down
2 changes: 1 addition & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ionCannonExplosionDamage = 500
HeatupTimeMultiplier = 1

-- When designating an ion cannon target, perform a check to see if any friendly character is too close to the target zone.
-- It is recommended to disable this check if you are using the "Long Reach" mod, since a side effect of that mod causes the radius of this check to excessively increase.
-- It is strongly recommended to disable this check if you are using the "Long Reach" mod, since a side effect of that mod causes the radius of this check to excessively increase.
proximityCheck = true

-- The number of gameticks that must pass between designating consecutive ion cannon targets. There are 60 ticks per second, so the default 10 ticks would be 1/6th of a second.
Expand Down
42 changes: 34 additions & 8 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ require ("config")

script.on_init(function() On_Init() end)
script.on_configuration_changed(function() On_Init() end)
script.on_load(function() On_Load() end)

remote.add_interface("orbital_ion_cannon",
{
on_ion_cannon_fired = function() return getIonCannonFiredEventID() end
}
)

function On_Init()
getIonCannonFiredEventID()
if not global.IonCannonLaunched then
global.IonCannonLaunched = false
end
if not global.forces_ion_cannon_table then
global.forces_ion_cannon_table = {"player"}
global.forces_ion_cannon_table["player"] = {}
Expand All @@ -30,18 +41,29 @@ function On_Init()
global.goToFull[player.index] = true
end
end
if not global.IonCannonExists then
global.IonCannonExists = false
for i, force in pairs(game.forces) do
if global.forces_ion_cannon_table[force.name] and #global.forces_ion_cannon_table[force.name] > 0 then
global.IonCannonExists = true
script.on_event(defines.events.on_tick, process_tick)
break
end
for i, force in pairs(game.forces) do
if global.forces_ion_cannon_table[force.name] and #global.forces_ion_cannon_table[force.name] > 0 then
global.IonCannonLaunched = true
script.on_event(defines.events.on_tick, process_tick)
break
end
end
end

function On_Load()
getIonCannonFiredEventID()
if global.IonCannonLaunched then
script.on_event(defines.events.on_tick, process_tick)
end
end

function getIonCannonFiredEventID()
if not when_ion_cannon_fired then
when_ion_cannon_fired = script.generate_event_name()
end
return when_ion_cannon_fired
end

script.on_event(defines.events.on_force_created, function(event)
if not global.forces_ion_cannon_table then
On_Init()
Expand Down Expand Up @@ -295,6 +317,9 @@ script.on_event(defines.events.on_rocket_launched, function(event)
local force = event.rocket.force
if event.rocket.get_item_count("orbital-ion-cannon") > 0 then
table.insert(global.forces_ion_cannon_table[force.name], {ionCannonCooldownSeconds, 0})
if not global.IonCannonLaunched then
global.IonCannonLaunched = true
end
script.on_event(defines.events.on_tick, process_tick)
if #global.forces_ion_cannon_table[force.name] == 1 then
force.recipes["ion-cannon-targeter"].enabled = true
Expand Down Expand Up @@ -364,6 +389,7 @@ script.on_event(defines.events.on_put_item, function(event)
global.forces_ion_cannon_table[player.force.name][cannonNum][1] = ionCannonCooldownSeconds
global.forces_ion_cannon_table[player.force.name][cannonNum][2] = 0
messageForce({"time-to-ready-again" , cannonNum , ionCannonCooldownSeconds}, player.force)
game.raise_event(when_ion_cannon_fired, {force = player.force, player_index = event.player_index, position = TargetPosition}) -- Passes event.force, event.player_index, and event.position
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions data-updates.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if data.raw["tool"]["science-pack-4"] and enableBobUpdates then
data.raw["technology"]["orbital-ion-cannon"].unit.ingredients[5] = {"science-pack-4", 2}
end

if not data.raw["assembling-machine"]["assembling-machine-4"] then
data.raw["assembling-machine"]["assembling-machine-3"].ingredient_count = 8
end
4 changes: 0 additions & 4 deletions data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@ require("prototypes.items")
require("prototypes.entities")
require("prototypes.recipes")
require("prototypes.technologies")

if not data.raw["assembling-machine"]["assembling-machine-4"] then
data.raw["assembling-machine"]["assembling-machine-3"].ingredient_count = 8
end
2 changes: 1 addition & 1 deletion info.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Orbital Ion Cannon",
"version": "1.0.8",
"version": "1.0.9",
"title": "Orbital Ion Cannon",
"author": "Supercheese",
"homepage": "http://www.factorioforums.com/forum/viewtopic.php?f=93&t=17910",
Expand Down
4 changes: 0 additions & 4 deletions prototypes/technologies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ data:extend({
},
})

if data.raw["item"]["science-pack-4"] and enableBobUpdates then
data.raw["technology"]["orbital-ion-cannon"].unit.ingredients[4] = {"science-pack-4", 2}
end

if data.raw["item"]["bob-laser-turret-5"] and enableBobUpdates then
data.raw["technology"]["orbital-ion-cannon"].prerequisites = {"rocket-silo", "laser-turret-damage-6", "bob-laser-turrets-5"}
end
Expand Down

0 comments on commit 9cadcd2

Please sign in to comment.