Ammo range modification

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
spiro9
Inserter
Inserter
Posts: 23
Joined: Tue Jul 12, 2016 12:15 am
Contact:

Ammo range modification

Post by spiro9 »

I'm not sure if this has ever been discussed, nor if this was intentional or just oversight, but I've noticed there's no way to change an individual ammo item's set range, despite the fact that other ranges throughout the game can be configured with mods. Enabling ammo ranges to be tweaked alongside other ranges (turrets, guns, etc.), via mod config settings, technology upgrades, etc. might not be a common-use situation but it is something I'm running into as a definite need for a personal project, and I'm sure the Factorio modding community would find some special use for such an opening as well.

Especially with the expansion coming up and the threats posed to space platforms by asteroid chunks, it could be interesting to allow modders to play around with tech upgrades to make turret defenses on said platforms more effective at longer and longer ranges, on top of the bullet speed and damage tech upgrades either native to base game and/or added by mods.
But ultimately, it's up to the devs whether or not they wish to consider such a change in the codebase. I'd call it trivial if I hadn't taken a look at the data files for ammo for myself, and I can tell it might break some things to add an otherwise small feature, so even with the positives I don't necessarily anticipate this request will be approved, quite the contrary in fact...


At the very least, if any others are interested in something like this, might help to have the community's input, so it's worth putting this post up anyways.
Hi hungry, I'm dad!

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Ammo range modification

Post by Pi-C »

spiro9 wrote:
Mon Jan 15, 2024 11:30 am
… I've noticed there's no way to change an individual ammo item's set range, despite the fact that other ranges throughout the game can be configured with mods. Enabling ammo ranges to be tweaked alongside other ranges (turrets, guns, etc.), via mod config settings, technology upgrades, etc. …
You want to change the range during the control stage -- is that correct? A short search for "range" in the LuaApi description doesn't show any results for LuaEntity. Properties like "turret_range" or "radar_range" belong to LuaEntityPrototype and are read-only. You can modify these, but only on starting the game (during data stage).

In the data stage, you can modify the range of a gun or turret prototype by changing the value of its attack_parameters.range (this is a property of the BaseAttackParameters that all attack_parameters inherit). The AmmoItemPrototype doesn't allow for setting a fixed range, but you can set its ammo_type.range_modifier.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

User avatar
spiro9
Inserter
Inserter
Posts: 23
Joined: Tue Jul 12, 2016 12:15 am
Contact:

Re: Ammo range modification

Post by spiro9 »

Pi-C wrote:
Mon Jan 15, 2024 2:42 pm
You want to change the range during the control stage -- is that correct? ... Properties like "turret_range" or "radar_range" belong to LuaEntityPrototype and are read-only. You can modify these, but only on starting the game (during data stage).
Nope. I'm doing all of my changes in data-final-fixes specifically because I know I need to mess with the prototypes. The problem is that turret range settings only affect where the turret targets and fires on enemies, not how far the projectiles fire, and it's that latter point where my issue lay.

I'd like to be able to configure ammo ranges, because if you open up debug info and check the "effects" info in-game, you can see on firearm mags and cannon shells that the projectile ranges are limited, and no amount of messing with the max_range settings in ammo item declarations seems to have any effect whatsoever; they appear to be strictly limited to 30-35 on average. Having some way to override this seemingly hard-coded limitation would be a boon.
Hi hungry, I'm dad!

BraveCaperCat
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Ammo range modification

Post by BraveCaperCat »

Use ammo_type.range_modifier, as said by the first reply to your post.

User avatar
spiro9
Inserter
Inserter
Posts: 23
Joined: Tue Jul 12, 2016 12:15 am
Contact:

Re: Ammo range modification

Post by spiro9 »

BraveCaperCat wrote:
Mon Jan 15, 2024 10:59 pm
Use ammo_type.range_modifier, as said by the first reply to your post.
This does not fix the issue.
Hi hungry, I'm dad!

heyqule
Long Handed Inserter
Long Handed Inserter
Posts: 54
Joined: Sun Mar 05, 2017 1:35 am
Contact:

Re: Ammo range modification

Post by heyqule »

You can set the max range for the projectiles under action delivery.

https://lua-api.factorio.com/latest/typ ... ivery.html

Code: Select all

        attack_parameters = {
            ammo_type = {
                category = "laser",
                target_type = "entity",
                action = {
                    type = "direct",
                    action_delivery = {
                        type = "projectile",
                        projectile = "projectile-name',
                        starting_speed = 0.35,
                        max_range = attack_range * 1.5  <<<< This will set the max range of the projectile.
                    }
                }
            },
        }

User avatar
spiro9
Inserter
Inserter
Posts: 23
Joined: Tue Jul 12, 2016 12:15 am
Contact:

Re: Ammo range modification

Post by spiro9 »

heyqule wrote:
Tue Jan 16, 2024 3:23 am
You can set the max range for the projectiles under action delivery.

https://lua-api.factorio.com/latest/typ ... ivery.html

Code: Select all

        attack_parameters = {
            ammo_type = {
                category = "laser",
                target_type = "entity",
                action = {
                    type = "direct",
                    action_delivery = {
                        type = "projectile",
                        projectile = "projectile-name',
                        starting_speed = 0.35,
                        max_range = attack_range * 1.5  <<<< This will set the max range of the projectile.
                    }
                }
            },
        }
I'm already doing this:

Code: Select all

-- This mod overwhelms the game's handling of default & modded ammo types, which appear to be strictly range-limited to around a maximum of 30-50
-- However, there is no indication that this range-limit is hardcoded so much as a softcoded "suggestion" from which to build
-- Iterating over each and setting its range to something absurd should help in correcting this issue
-- Rather, in simpler terms, look through every single ammo item and check for a maximum range, then if one is found, set it to something like 1000 so ammo can fly forever >:D
for _, a in pairs(data.raw["ammo"]) do
	local t = a.ammo_type
	if t.action then
		for _, q in ipairs(t.action) do
			if q.action_delivery then
				if q.action_delivery.max_range then
					log("Before: " .. tostring(q.action_delivery.max_range))
					local c = q.action_delivery.max_range
					
					q.action_delivery.max_range = 1000
					log("After: " .. tostring(q.action_delivery.max_range))
					
					if c == q.action_delivery.max_range then
						log("Uh-oh! These are the same!")
					end
				end
			end
		end
	end
end
This code however has no effect despite logs confirming the change is being made in the data-final-fixes substage.

Amendment: it does appear to affect shotgun shells, but all other ammunition types are unaffected
Last edited by spiro9 on Tue Jan 16, 2024 8:45 am, edited 1 time in total.
Hi hungry, I'm dad!

User avatar
spiro9
Inserter
Inserter
Posts: 23
Joined: Tue Jul 12, 2016 12:15 am
Contact:

Re: Ammo range modification

Post by spiro9 »

BraveCaperCat wrote:
Tue Jan 16, 2024 8:43 am
spiro9 wrote:
Tue Jan 16, 2024 8:37 am
heyqule wrote:
Tue Jan 16, 2024 3:23 am
You can set the max range for the projectiles under action delivery.

https://lua-api.factorio.com/latest/typ ... ivery.html

Code: Select all

        attack_parameters = {
            ammo_type = {
                category = "laser",
                target_type = "entity",
                action = {
                    type = "direct",
                    action_delivery = {
                        type = "projectile",
                        projectile = "projectile-name',
                        starting_speed = 0.35,
                        max_range = attack_range * 1.5  <<<< This will set the max range of the projectile.
                    }
                }
            },
        }
Can you post your log?

I'm already doing this:

Code: Select all

-- This mod overwhelms the game's handling of default & modded ammo types, which appear to be strictly range-limited to around a maximum of 30-50
-- However, there is no indication that this range-limit is hardcoded so much as a softcoded "suggestion" from which to build
-- Iterating over each and setting its range to something absurd should help in correcting this issue
-- Rather, in simpler terms, look through every single ammo item and check for a maximum range, then if one is found, set it to something like 1000 so ammo can fly forever >:D
for _, a in pairs(data.raw["ammo"]) do
	local t = a.ammo_type
	if t.action then
		for _, q in ipairs(t.action) do
			if q.action_delivery then
				if q.action_delivery.max_range then
					log("Before: " .. tostring(q.action_delivery.max_range))
					local c = q.action_delivery.max_range
					
					q.action_delivery.max_range = 1000
					log("After: " .. tostring(q.action_delivery.max_range))
					
					if c == q.action_delivery.max_range then
						log("Uh-oh! These are the same!")
					end
				end
			end
		end
	end
end
This code however has no effect despite logs confirming the change is being made in the data-final-fixes substage.
factorio-current.log
Log.
(645.95 KiB) Downloaded 19 times
Hi hungry, I'm dad!

BraveCaperCat
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Ammo range modification

Post by BraveCaperCat »

spiro9 wrote:
Tue Jan 16, 2024 8:47 am
BraveCaperCat wrote:
Tue Jan 16, 2024 8:43 am
spiro9 wrote:
Tue Jan 16, 2024 8:37 am
heyqule wrote:
Tue Jan 16, 2024 3:23 am
You can set the max range for the projectiles under action delivery.

https://lua-api.factorio.com/latest/typ ... ivery.html

Code: Select all

        attack_parameters = {
            ammo_type = {
                category = "laser",
                target_type = "entity",
                action = {
                    type = "direct",
                    action_delivery = {
                        type = "projectile",
                        projectile = "projectile-name',
                        starting_speed = 0.35,
                        max_range = attack_range * 1.5  <<<< This will set the max range of the projectile.
                    }
                }
            },
        }
Can you post your log?

I'm already doing this:

Code: Select all

-- This mod overwhelms the game's handling of default & modded ammo types, which appear to be strictly range-limited to around a maximum of 30-50
-- However, there is no indication that this range-limit is hardcoded so much as a softcoded "suggestion" from which to build
-- Iterating over each and setting its range to something absurd should help in correcting this issue
-- Rather, in simpler terms, look through every single ammo item and check for a maximum range, then if one is found, set it to something like 1000 so ammo can fly forever >:D
for _, a in pairs(data.raw["ammo"]) do
	local t = a.ammo_type
	if t.action then
		for _, q in ipairs(t.action) do
			if q.action_delivery then
				if q.action_delivery.max_range then
					log("Before: " .. tostring(q.action_delivery.max_range))
					local c = q.action_delivery.max_range
					
					q.action_delivery.max_range = 1000
					log("After: " .. tostring(q.action_delivery.max_range))
					
					if c == q.action_delivery.max_range then
						log("Uh-oh! These are the same!")
					end
				end
			end
		end
	end
end
This code however has no effect despite logs confirming the change is being made in the data-final-fixes substage.
Log file.
Can you try this with just your mod and it's dependencies? then post that log if it still doesn't work. (there are a lot of different mods which don't seem to have any connection to your mod, some of them may be overwriting your changes)

User avatar
spiro9
Inserter
Inserter
Posts: 23
Joined: Tue Jul 12, 2016 12:15 am
Contact:

Re: Ammo range modification

Post by spiro9 »

My mod actually has zero dependencies. I run a check for other mods but there is no need for those mods to be present. The only reason I can think of regarding other mods overriding the behavior of mine is, my attempt to ensure my mod loads last by appending 'zzzzzz' was futile.
Hi hungry, I'm dad!

Pi-C
Smart Inserter
Smart Inserter
Posts: 1654
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Ammo range modification

Post by Pi-C »

spiro9 wrote:
Tue Jan 16, 2024 9:13 am
The only reason I can think of regarding other mods overriding the behavior of mine is, my attempt to ensure my mod loads last by appending 'zzzzzz' was futile.
It doesn't really make sense to use prefixes like "zzz" for making your mod load last. Other modders may also want to load last, so they might add a 'z' more … The best way is to add (optional) dependencies on the mods known to interfere with yours. Also, the multi-phase data stage is useful if everybody follows some guidelines:
  • data: Create the essential prototypes for your mod.
  • data-updates (optional): Create optional prototypes and adjust your essential prototypes depending on what the other mods have created.
  • data-final-fixes (optional): Make final adjustments to existing prototypes, but don't create new ones!
If you want to see whether any other mods have overwritten your changes, you can use the in-game prototype browser. You can use CTRL+SHIFT+E to open a GUI that provides access to all prototypes in the game, or you can hover your cursor over any entity, item, recipe etc. and type CTRL+SHIFT+F to directly open the view of its prototype. Also, when hovering the cursor over something, the description appearing on the right side of the display shows the order in which mods created/changed the prototype.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

BraveCaperCat
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Ammo range modification

Post by BraveCaperCat »

Pi-C wrote:
Tue Jan 16, 2024 11:11 am
spiro9 wrote:
Tue Jan 16, 2024 9:13 am
The only reason I can think of regarding other mods overriding the behavior of mine is, my attempt to ensure my mod loads last by appending 'zzzzzz' was futile.
It doesn't really make sense to use prefixes like "zzz" for making your mod load last. Other modders may also want to load last, so they might add a 'z' more … The best way is to add (optional) dependencies on the mods known to interfere with yours. Also, the multi-phase data stage is useful if everybody follows some guidelines:
  • data: Create the essential prototypes for your mod.
  • data-updates (optional): Create optional prototypes and adjust your essential prototypes depending on what the other mods have created.
  • data-final-fixes (optional): Make final adjustments to existing prototypes, but don't create new ones!
If you want to see whether any other mods have overwritten your changes, you can use the in-game prototype browser. You can use CTRL+SHIFT+E to open a GUI that provides access to all prototypes in the game, or you can hover your cursor over any entity, item, recipe etc. and type CTRL+SHIFT+F to directly open the view of its prototype. Also, when hovering the cursor over something, the description appearing on the right side of the display shows the order in which mods created/changed the prototype.
Or, Hidden Optional Dependencies!

Post Reply

Return to “Modding interface requests”