Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endgame Combat > turret replacement ends on_built_entity events #77

Closed
Kovus opened this issue Jul 31, 2018 · 1 comment
Closed

Endgame Combat > turret replacement ends on_built_entity events #77

Kovus opened this issue Jul 31, 2018 · 1 comment

Comments

@Kovus
Copy link

Kovus commented Jul 31, 2018

When rangeboost is researched, then Endgame Combat will do a replace upon placing turrets. When it does this, no other mods are able to get an event about the original entity (because it's gone) or the new entity.

I'd request that Endgame Combat generates an event, script_raised_built being an ideal candidate, providing updated versions of the same parameters that on_built_entity utilizes. I'd suggest the below patch:

From 79c76e4d6245ba9a19caf4a01da851ea4939c65e Mon Sep 17 00:00:00 2001
From: Kovus <kovus@soulless.wtf>
Date: Wed, 25 Jul 2018 10:28:32 -0500
Subject: [PATCH] Raise event when quickly replacing turrets that are placed.

This lets other mods watch for the script_raised_built event and (with proper checks on data content) respond accordingly.
---
 control.lua | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/control.lua b/control.lua
index 79ac35d..129d5c0 100644
--- a/control.lua
+++ b/control.lua
@@ -146,6 +146,7 @@ local function trackNewTurret(egcombat, turret)
 
 		--game.print("Adding " .. turret.name .. " @ " .. turret.position.x .. ", " .. turret.position.y .. " for " .. force.name .. " to turret table; size=" .. #egcombat.placed_turrets[force.name])
 	end
+	return turret
 end
 
 local function reloadRangeTech()
@@ -504,7 +505,16 @@ local function onEntityAdded(event)
     end
 	
 	if (entity.type == "ammo-turret" or entity.type == "electric-turret" or entity.type == "fluid-turret") then
-		trackNewTurret(egcombat, entity)
+		local orig_name = entity.name
+		local turret = trackNewTurret(egcombat, entity)
+		if turret.name ~= orig_name then
+			script.raise_event(defines.events.script_raised_built, {
+				mod_name = "EndgameCombat",
+				created_entity = turret,
+				player_index = event.player_index,
+				stack = event.stack,
+			})
+		end
 		return
 	end
 end
-- 
2.17.1

If you are approving of this code, then it might be easiest to accept the PR ReikaKalseki/EndgameCombat#3 .

@ReikaKalseki
Copy link
Owner

Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants