[MOD 0.12.16] Displaying range of turrets [v1.1.2]

Topics and discussion about specific mods
kds71
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm

[MOD 0.12.16] Displaying range of turrets [v1.1.2]

Post by kds71 » Wed Aug 12, 2015 12:06 pm

I finally updated my turret range probe mod to 0.12.x - sorry for the delay :)

Another mod inspired by a reddit post.

This mod adds an item that allows you to check range of a turret.
Since version 1.1.1 it works with any turret in a game (including modded turrets). Config file is not needed anymore and it was removed (thanks to Adil for the tip!).

Features:
  • adds a new technology called "turrets range probing" (requires electronics and turrets)
  • adds a new item, "turret probe" with recipe unlocked by this technology
How to use:
  • click on a turret with a turret probe in your hand to see a range of this turret
  • click elsewhere (still with a turret probe in your hand) to remove displayed range from the screen
  • you may click on several turrets in a row to see their range together (to check for overlapping etc.)
Screenshot
LIcense: Public Domain
Changelog
Downloads:
For Factorio 0.12.16 download v1.1.2 of this mod:
turrets-range_1.1.2.zip
(9.82 KiB) Downloaded 2739 times
For older versions of Factorio download v1.1.1:
turrets-range_1.1.1.zip
(9.82 KiB) Downloaded 857 times
Last edited by kds71 on Sun Nov 01, 2015 1:54 am, edited 5 times in total.

DOSorDIE
Fast Inserter
Fast Inserter
Posts: 227
Joined: Sat Oct 11, 2014 3:43 pm

Re: [MOD 0.12.1] Displaying range of turrets [v1.1.0]

Post by DOSorDIE » Wed Aug 12, 2015 12:52 pm

Great Mod ... but how can i disable/enabe ingame, but i dont need this all the time.

waduk
Filter Inserter
Filter Inserter
Posts: 346
Joined: Tue Feb 10, 2015 5:44 pm

Re: [MOD 0.12.1] Displaying range of turrets [v1.1.0]

Post by waduk » Thu Aug 13, 2015 5:31 am

So glad you update this, saw you update one of your mod in reddit post.

toudi
Burner Inserter
Burner Inserter
Posts: 10
Joined: Thu Jul 23, 2015 5:29 pm

Re: [MOD 0.12.1] Displaying range of turrets [v1.1.0]

Post by toudi » Thu Aug 13, 2015 5:52 am

Awesome, this should be in base game!

User avatar
Adil
Filter Inserter
Filter Inserter
Posts: 945
Joined: Fri Aug 15, 2014 8:36 pm

Re: [MOD 0.12.1] Displaying range of turrets [v1.1.0]

Post by Adil » Thu Aug 13, 2015 8:23 am

I humbly suggest the following code to make it work with any turret.

Code: Select all

game.onload(function()
    turret_ranges={};
    for name,p in pairs(game.entity_prototypes) do 
        if p.type=='electric-turret' or p.type=='ammo-turret' or p.type=='turret' then 
            turret_ranges[name]= p.turret_range
        end; 
    end
end)
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.

kds71
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm

Re: [MOD 0.12.1] Displaying range of turrets [v1.1.0]

Post by kds71 » Thu Aug 13, 2015 8:42 am

Wait, so there is a turret_range property that allows you to read the range of a turret? I couldn't find it anywhere, I have to check it out! Thanks for the tip.

Edit: Awesome, it worked! Uploading new version of the mod right now. I removed "turrets_range" variable, now my code looks like that:

Code: Select all

            if entity[1].type == "electric-turret" or entity[1].type == "ammo-turret" or entity[1].type == "turret" then
                found = true
                if entity[1].type == "electric-turret" then
                    turret_type = "laser"
                else
                    turret_type = "gun"
                end
                draw_turret_range(turret_type, entity[1].position.x, entity[1].position.y, entity[1].prototype.turret_range)
            end

orzelek
Smart Inserter
Smart Inserter
Posts: 3279
Joined: Fri Apr 03, 2015 10:20 am

Re: [MOD 0.12.1] Displaying range of turrets [v1.1.1]

Post by orzelek » Thu Aug 13, 2015 5:34 pm

The turret_range is a new addition in 0.12. And it's great for mod like this :D

Talguy
Fast Inserter
Fast Inserter
Posts: 103
Joined: Tue Apr 29, 2014 8:54 pm

Re: [MOD 0.12.1] Displaying range of turrets [v1.1.1]

Post by Talguy » Mon Aug 24, 2015 4:48 pm

Why not program it like this?

Code: Select all

        entity = game.get_surface(1).find_entities{{ pos.x, pos.y }, { pos.x, pos.y }}
        --if #entity > 0 then
            --if entity[1].type == "electric-turret" or entity[1].type == "ammo-turret" or entity[1].type == "turret" then
            if  #entity > 0 and entity[1].prototype.turret_range and entity[1].prototype.turret_range > 0 then
                --found = true
                if entity[1].type == "electric-turret" then
                    turret_type = "laser"
                else
                    turret_type = "gun"
                end
                draw_turret_range(turret_type, entity[1].position.x, entity[1].position.y, entity[1].prototype.turret_range)
            --end
        --end
		else
        --if not found then
            for i = 1, #global.turret_range_entities do
                global.turret_range_entities[i].destroy()
            end
            global.turret_range_entities = {}
        end
That way, other mods like Bobs mod (sniper turret) will be supported, because I think checking turret_range should be sufficient. Turret range should be a debug tool anyway.

Not sure if prototype.turret_range is auto set to 0 through a metatable __index, if so then prototype.turret_range > 0 is sufficient (otherwise attempt to compare number with nil)

Peter34
Smart Inserter
Smart Inserter
Posts: 1086
Joined: Mon Nov 10, 2014 12:44 pm

Re: [MOD 0.12.1] Displaying range of turrets [v1.1.1]

Post by Peter34 » Mon Aug 24, 2015 5:36 pm

Thanks for this mod!

WhiteHat101
Manual Inserter
Manual Inserter
Posts: 1
Joined: Fri Sep 18, 2015 3:37 am

Re: [MOD 0.12.1] Displaying range of turrets [v1.1.1]

Post by WhiteHat101 » Tue Sep 22, 2015 3:42 am

Hi, I love your mod concept, but I wasn't thrilled with the activation mechanism, so I've been trying different methods. I'm pretty happy with my mods to your mod, but I'll often get some client lag when it renders or un-renders a turret's range (It's creating/destroying ~100 entities per turret, I can't really blame the game for some stutter). My code renders nearby turrets; the lag becomes noticeable when I run down a wall of turrets, or past a cluster of turrets (easily, thousands of entities are created and then destroyed in a handful of seconds).

Might there be a way to render the range indicator with a single entity per turret?

Maybe a large custom sprite? Maybe something with the range indicator from power poles? Maybe we could tap into the range display used by grenades and bot capsules?
wip control.lua

Peter34
Smart Inserter
Smart Inserter
Posts: 1086
Joined: Mon Nov 10, 2014 12:44 pm

Re: [MOD 0.12.1] Displaying range of turrets [v1.1.1]

Post by Peter34 » Tue Sep 22, 2015 11:36 am

One thing I'm very concerned about is multiplayer compatability. It's all well and good to have a mod that works in SP, but coop MP is ultimately a thousand times more fun, and if a mod creates too much lag, it'll make MP impossible.

kds71
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm

Re: [MOD 0.12.1] Displaying range of turrets [v1.1.1]

Post by kds71 » Sun Nov 01, 2015 1:46 am

I just uploaded v1.1.2 of this mod, it is now compatible with Factorio v0.12.16. Sorry for the delay.
WhiteHat101 wrote:Might there be a way to render the range indicator with a single entity per turret?
The only thing that comes to my mind is to create multiple entity types - one for each range. The problem with this approach is that I want to support modded turrets as well, so basically it would require to create hundreds of entity types to make sure that all possible ranges are covered. I'll think about it.

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 1666
Joined: Thu Jun 12, 2014 3:05 am

Re: [MOD 0.12.16] Displaying range of turrets [v1.1.2]

Post by Ranakastrasz » Sun Jan 31, 2016 4:21 am

Would it be possible to make the item a modified grenade type item, such thar you can use it any range?
My Mods:
Modular Armor Revamp - V16
Pre-Fusion - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Mineable rock - Vanilla
Easy Refineries -V16
Rocket range - V15
Combat Revamp - Restin'
Shield Pulse - Working on

kds71
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm

Re: [MOD 0.12.16] Displaying range of turrets [v1.1.2]

Post by kds71 » Mon Feb 01, 2016 5:53 pm

Ranakastrasz wrote:Would it be possible to make the item a modified grenade type item, such thar you can use it any range?
I will have to look into it, but I think it is possible. I will try to do something about that and report back :)

starholme
Fast Inserter
Fast Inserter
Posts: 196
Joined: Tue Oct 21, 2014 7:25 pm

Re: [MOD 0.12.1] Displaying range of turrets [v1.1.1]

Post by starholme » Mon Feb 01, 2016 9:12 pm

WhiteHat101 wrote:Hi, I love your mod concept, but I wasn't thrilled with the activation mechanism, so I've been trying different methods. I'm pretty happy with my mods to your mod, but I'll often get some client lag when it renders or un-renders a turret's range (It's creating/destroying ~100 entities per turret, I can't really blame the game for some stutter). My code renders nearby turrets; the lag becomes noticeable when I run down a wall of turrets, or past a cluster of turrets (easily, thousands of entities are created and then destroyed in a handful of seconds).

Might there be a way to render the range indicator with a single entity per turret?

Maybe a large custom sprite? Maybe something with the range indicator from power poles? Maybe we could tap into the range display used by grenades and bot capsules?
wip control.lua
If you are concerned with the performance impact, best to limit the number of entities changed per tick. You'll have to play around to decide, but either one turret per tick, or x entities per tick.
I've not had time to look at the code, but with a few assumptions:
Entity creation queue - contains all entities that need to be added
Current entity queue - contains all entities already added
Entity destruction queue - contains all entities that need to be destroyed
Active turrets queue - all the turrets that 'should' be showing a range

Each tick:
Add turrets to turret queue that are now in range (Maybe only every 10 ticks or something, probably not required 'every' tick)
- Add entities to creation queue for these turrets
Remove turrets from turret queue that are out of range (Maybe only every 10 ticks or something, probably not required 'every' tick)
- Remove entities from creation queue for these turrets
- Move entities from current queue to destruction queue for these turrets
Starting with the oldest entities in the Destruction queue, remove X (Where X is some fine tuned number) entities, decrementing X
If X is not yet zero, starting with the newest entities in the creation queue, create X entities, move from the creation queue to the current queue

Essentially, newest turrets in range have priority on drawing ranges, oldest turrets have highest priority for removing ranges.

Zeblote
Filter Inserter
Filter Inserter
Posts: 972
Joined: Fri Oct 31, 2014 11:55 am

Re: [MOD 0.12.16] Displaying range of turrets [v1.1.2]

Post by Zeblote » Mon Feb 01, 2016 9:52 pm

Any way to make this a proper circle (like when you have a grenade equipped) and show only when hovering mouse over a turret?

kds71
Long Handed Inserter
Long Handed Inserter
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm

Re: [MOD 0.12.16] Displaying range of turrets [v1.1.2]

Post by kds71 » Tue Feb 02, 2016 8:55 pm

Zeblote wrote:Any way to make this a proper circle (like when you have a grenade equipped) ...
Yes, there is a way to make it a proper circle - but, as I said earlier in this thread that would require me to create hundreds of circle sprites with different sizes, because I can't just draw any circle on the screen - it must be stored in the sprite sheet. Anyway, I think I will try to just do that - these simple sprites shouldn't take too much disk space even if there are hundreds of them.
Zeblote wrote:... and show only when hovering mouse over a turret?
This is, unfortunatelly, not possible, since there is no event fired when you hover over turret (or any other entity in the game).

keyboardhack
Filter Inserter
Filter Inserter
Posts: 464
Joined: Sat Aug 23, 2014 11:43 pm

Re: [MOD 0.12.16] Displaying range of turrets [v1.1.2]

Post by keyboardhack » Tue Feb 02, 2016 9:21 pm

kds71 wrote:
Zeblote wrote:Any way to make this a proper circle (like when you have a grenade equipped) ...
Yes, there is a way to make it a proper circle - but, as I said earlier in this thread that would require me to create hundreds of circle sprites with different sizes, because I can't just draw any circle on the screen - it must be stored in the sprite sheet.
Not sure if this is what you are refering to or not but you can scale a sprite. Example

Code: Select all

{
	filename = "__modname__/path/to/image",
   width = 100,
	height = 100,
	scale = 2, --twice the size so it will be shown on screen as a 200x200 sprite
}
You could use this to scale up circles to match the size of a turrets range.
Waste of bytes : P

User avatar
Ranakastrasz
Smart Inserter
Smart Inserter
Posts: 1666
Joined: Thu Jun 12, 2014 3:05 am

Re: [MOD 0.12.16] Displaying range of turrets [v1.1.2]

Post by Ranakastrasz » Tue Feb 02, 2016 10:33 pm

keyboardhack wrote:
kds71 wrote:
Zeblote wrote:Any way to make this a proper circle (like when you have a grenade equipped) ...
Yes, there is a way to make it a proper circle - but, as I said earlier in this thread that would require me to create hundreds of circle sprites with different sizes, because I can't just draw any circle on the screen - it must be stored in the sprite sheet.
Not sure if this is what you are refering to or not but you can scale a sprite. Example

Code: Select all

{
	filename = "__modname__/path/to/image",
   width = 100,
	height = 100,
	scale = 2, --twice the size so it will be shown on screen as a 200x200 sprite
}
You could use this to scale up circles to match the size of a turrets range.
Unless you have one for each potential range, it won't work out so well for mods. It works great as is for Bob's mod Sniper turrets. You would want to have one for, like, 1 through 100 or something, which would be sufficient for any range you might reasonably expect to show up.
My Mods:
Modular Armor Revamp - V16
Pre-Fusion - V16
Large Chests - V16
Agent Orange - V16
Flare - V16
Mineable rock - Vanilla
Easy Refineries -V16
Rocket range - V15
Combat Revamp - Restin'
Shield Pulse - Working on

Zeblote
Filter Inserter
Filter Inserter
Posts: 972
Joined: Fri Oct 31, 2014 11:55 am

Re: [MOD 0.12.16] Displaying range of turrets [v1.1.2]

Post by Zeblote » Tue Feb 02, 2016 11:05 pm

Can you iterate over all turret prototypes in data-final-fixes and make sprites for the ranges that are used?

Post Reply

Return to “Mods”