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

These mods are not game-changing, but enhance the gameplay by helping you with useful functions.
Mods like showing the current game-time, keep track over your resources, rail-laying...

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

Postby 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
Image


LIcense: Public Domain

Changelog
v1.1.1
  • removed config.lua file - it is not longer needed, turret ranges are read in the runtime
v1.1.0
  • updated to work with Factorio 0.12.x
v1.0.0
  • stable (hopefully) release of the mod
  • range of turret no longer disappears when clicking on another turret, allowing to see range of more than one turret at once
  • electric turrets now have different color of range circle than ammo turrets
v0.0.3
  • fixed a bug related to saving and reloading the game while turret range is visible
  • exposed turret list and their ranges to config file
  • added support for DyTech and MoMods turrets
v0.0.2
  • removed GUI buttons
  • added item "turret probe" and recipe and technology for this item; instead of clicking on GUI button you have to click with the probe on a turret
v0.0.1
  • initial release


Downloads:
For Factorio 0.12.16 download v1.1.2 of this mod:
turrets-range_1.1.2.zip
(9.82 KiB) Downloaded 2579 times

For older versions of Factorio download v1.1.1:
turrets-range_1.1.1.zip
(9.82 KiB) Downloaded 799 times
Last edited by kds71 on Sun Nov 01, 2015 1:54 am, edited 5 times in total.
kds71
Long Handed Inserter
Long Handed Inserter
 
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm
Location: Wrocław, Poland

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

Postby 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.
DOSorDIE
Fast Inserter
Fast Inserter
 
Posts: 218
Joined: Sat Oct 11, 2014 3:43 pm

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

Postby waduk » Thu Aug 13, 2015 5:31 am

So glad you update this, saw you update one of your mod in reddit post.
waduk
Filter Inserter
Filter Inserter
 
Posts: 327
Joined: Tue Feb 10, 2015 5:44 pm

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

Postby toudi » Thu Aug 13, 2015 5:52 am

Awesome, this should be in base game!
toudi
Burner Inserter
Burner Inserter
 
Posts: 9
Joined: Thu Jul 23, 2015 5:29 pm

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

Postby 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.
User avatar
Adil
Filter Inserter
Filter Inserter
 
Posts: 906
Joined: Fri Aug 15, 2014 8:36 pm

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

Postby 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
kds71
Long Handed Inserter
Long Handed Inserter
 
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm
Location: Wrocław, Poland

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

Postby 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
orzelek
Smart Inserter
Smart Inserter
 
Posts: 2278
Joined: Fri Apr 03, 2015 10:20 am

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

Postby 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)
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]

Postby Peter34 » Mon Aug 24, 2015 5:36 pm

Thanks for this mod!
Peter34
Smart Inserter
Smart Inserter
 
Posts: 1002
Joined: Mon Nov 10, 2014 12:44 pm
Location: Europe

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

Postby 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
https://gist.github.com/whitehat101/be022e8e93daf5f2c4cb
I intend to properly release a mod in the relatively near future. Just a few more features, but if that doesn't come to pass... For Science, here is the control.lua that I've been playing with that can be dropped into the v1.1.1 turrets-range mod.

Currently, the mod renders all turret ranges: within 5 units of every player, or if a player has selected (mouse hover) a turret.
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]

Postby 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.
Peter34
Smart Inserter
Smart Inserter
 
Posts: 1002
Joined: Mon Nov 10, 2014 12:44 pm
Location: Europe

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

Postby 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.
kds71
Long Handed Inserter
Long Handed Inserter
 
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm
Location: Wrocław, Poland

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

Postby 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?
User avatar
Ranakastrasz
Filter Inserter
Filter Inserter
 
Posts: 999
Joined: Thu Jun 12, 2014 3:05 am

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

Postby 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 :)
kds71
Long Handed Inserter
Long Handed Inserter
 
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm
Location: Wrocław, Poland

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

Postby 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
https://gist.github.com/whitehat101/be022e8e93daf5f2c4cb
I intend to properly release a mod in the relatively near future. Just a few more features, but if that doesn't come to pass... For Science, here is the control.lua that I've been playing with that can be dropped into the v1.1.1 turrets-range mod.

Currently, the mod renders all turret ranges: within 5 units of every player, or if a player has selected (mouse hover) a turret.


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.
starholme
Fast Inserter
Fast Inserter
 
Posts: 196
Joined: Tue Oct 21, 2014 7:25 pm

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

Postby 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?
Zeblote
Filter Inserter
Filter Inserter
 
Posts: 832
Joined: Fri Oct 31, 2014 11:55 am

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

Postby 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).
kds71
Long Handed Inserter
Long Handed Inserter
 
Posts: 91
Joined: Fri Mar 06, 2015 12:27 pm
Location: Wrocław, Poland

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

Postby 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
keyboardhack
Filter Inserter
Filter Inserter
 
Posts: 413
Joined: Sat Aug 23, 2014 11:43 pm

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

Postby 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.
User avatar
Ranakastrasz
Filter Inserter
Filter Inserter
 
Posts: 999
Joined: Thu Jun 12, 2014 3:05 am

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

Postby 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?
Zeblote
Filter Inserter
Filter Inserter
 
Posts: 832
Joined: Fri Oct 31, 2014 11:55 am

Next

Return to Helper mods

Who is online

Users browsing this forum: No registered users and 6 guests