[Klonan] [1.1.41] Vehicle weapon range is being ignored

This subforum contains all the issues which we already resolved.
Post Reply
Xorimuth
Filter Inserter
Filter Inserter
Posts: 623
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

[Klonan] [1.1.41] Vehicle weapon range is being ignored

Post by Xorimuth »

This is observable in vanilla but I came across it because I am trying to make different tiers of spidertrons have differently ranged cannons. It appears that this is not possible because of the following.

The tank cannon has range 25 (called "Range" on the cannon tooltip). The cannon shell has max_range 30 (called "Projectile range" on the shell tooltip). The shells are clearly travelling 30 tiles.

I'd expect projectiles to travel a distance equal to the minimum of the weapon's range and the ammo's max_range, so 25 in this case.
Screenshot 2021-09-23 at 22.54.13.png
Screenshot 2021-09-23 at 22.54.13.png (5.44 MiB) Viewed 4258 times
My mods
Content: Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Remote Configuration | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings

User avatar
boskid
Factorio Staff
Factorio Staff
Posts: 2227
Joined: Thu Dec 14, 2017 6:56 pm
Contact:

Re: [1.1.41] Vehicle weapon range is being ignored

Post by boskid »

This looks slightly more complicated than just "use lower of the 2".

Gun's AttackParameters define a range for a gun which is used to decide if you can shoot given target/position. It is however not used when you have an ammo item with ammo_type.target_type=="direction" as in this case you are not aiming at a given position nor given entity but you only show the general direction for the gun to shoot. After this the ammo being applied just do not care from what it was being shot. Extra case for this is that the cannon-projectile's prototype has direction_only which means even if you would change the ammo to have target_type="position" which will fix the "can shoot" check, the particle will still travel full distance from the ammo.

Changing cannon-shell to have ammo_type.target_type="position" and changing cannon-projectile to direction_only=false you would get your expected outcome by not allowing gun to shoot when the target is out of gun's range.

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5148
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [1.1.41] Vehicle weapon range is being ignored

Post by Klonan »

This is basically just a base game Lua prototype error,
Since all the projectiles in the base game have the max range of 30,
I will just change the range of the tank cannon to be the 30 as with the projectile, even though it actually makes no difference

There is nothing wrong with the logic in the game, projectiles can have a range different than the guns targeting range, there won't be any logic changes in that regard,
And all of this can be tweaked and fixed with mods,
The base game is just defining things in a poor way leading to confusion

Xorimuth
Filter Inserter
Filter Inserter
Posts: 623
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: [1.1.41] Vehicle weapon range is being ignored

Post by Xorimuth »

boskid wrote:
Wed Sep 29, 2021 9:00 am
This looks slightly more complicated than just "use lower of the 2".

Gun's AttackParameters define a range for a gun which is used to decide if you can shoot given target/position. It is however not used when you have an ammo item with ammo_type.target_type=="direction" as in this case you are not aiming at a given position nor given entity but you only show the general direction for the gun to shoot. After this the ammo being applied just do not care from what it was being shot. Extra case for this is that the cannon-projectile's prototype has direction_only which means even if you would change the ammo to have target_type="position" which will fix the "can shoot" check, the particle will still travel full distance from the ammo.

Changing cannon-shell to have ammo_type.target_type="position" and changing cannon-projectile to direction_only=false you would get your expected outcome by not allowing gun to shoot when the target is out of gun's range.
Thank you very much for the detailed explanation. I think that I got a bit lost amongst all the different prototypes/types (AmmoItem, AmmoType, Trigger, TriggerItem, TriggerDelivery, Projectile :? ) and didn't appreciate that there were so many different ways of doing it. Now I understand the differences between machine gun bullets, cannons and rockets it clears up some of the confusion I had whilst playing vanilla as well.

Changing the ammo_type.target_type from "direction" to "position" and setting ammo_type.clamp_position = true seems to keep the behaviour exactly as it was (you can aim beyond the range and it will just go to that range) except that it now clamps to the gun range instead of the projectile range - perfect!

I then change every cannon shell's action_delivery.max_range to be that of the largest gun range and set the projectile's direction_only=false (I'd likely have never found that if you hadn't mentioned it!) and all seems to be working how I wanted it!


I'm also doing the same for shotguns: interestingly shotgun-shell already has `clamp_position = true` despite `target_type = "direction"` (wiki says this has no effect)... it all works the same with the above modifications though, which is great!


I agree with Klonan - the game engine now seems fine, just some questionable choices in the base prototypes. Certainly the tank-cannon range mismatch is the most egregious, but I'm unsure why target_type = "direction" is ever actually useful (vs "position" and clamp_position=true).
My mods
Content: Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Remote Configuration | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings

Xorimuth
Filter Inserter
Filter Inserter
Posts: 623
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: [1.1.41] Vehicle weapon range is being ignored

Post by Xorimuth »

Xorimuth wrote:
Wed Sep 29, 2021 1:30 pm
I'm unsure why target_type = "direction" is ever actually useful (vs "position" and clamp_position=true).
Ok, I see a difference now - clamp_position works when you fire to a point beyond the gun range, but if you fire at a point less than the gun range then "direction" will still travel the full max_range of the ammo, whereas "position"+clamp_position will only travel to the cursor position.
My mods
Content: Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Remote Configuration | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings

Xorimuth
Filter Inserter
Filter Inserter
Posts: 623
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: [1.1.41] Vehicle weapon range is being ignored

Post by Xorimuth »

Xorimuth wrote:
Wed Sep 29, 2021 2:38 pm
Xorimuth wrote:
Wed Sep 29, 2021 1:30 pm
I'm unsure why target_type = "direction" is ever actually useful (vs "position" and clamp_position=true).
Ok, I see a difference now - clamp_position works when you fire to a point beyond the gun range, but if you fire at a point less than the gun range then "direction" will still travel the full max_range of the ammo, whereas "position"+clamp_position will only travel to the cursor position.
Errrrr, this behaviour is what I observed, but the docs disagree! "The gun will fire at the maximum range in the direction of the target position" - https://wiki.factorio.com/Types/AmmoType#clamp_position

I'd prefer the behaviour to change to match the docs, but one of them should certainly be changed.
My mods
Content: Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Remote Configuration | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5148
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [1.1.41] Vehicle weapon range is being ignored

Post by Klonan »

Xorimuth wrote:
Wed Sep 29, 2021 3:09 pm

Errrrr, this behaviour is what I observed, but the docs disagree! "The gun will fire at the maximum range in the direction of the target position" - https://wiki.factorio.com/Types/AmmoType#clamp_position

I'd prefer the behaviour to change to match the docs, but one of them should certainly be changed.
The behaviour is correct,
Its IF the position is too far away, the gun will fire at the max range

Xorimuth
Filter Inserter
Filter Inserter
Posts: 623
Joined: Sat Mar 02, 2019 9:39 pm
Contact:

Re: [1.1.41] Vehicle weapon range is being ignored

Post by Xorimuth »

Klonan wrote:
Wed Sep 29, 2021 4:28 pm
Xorimuth wrote:
Wed Sep 29, 2021 3:09 pm

Errrrr, this behaviour is what I observed, but the docs disagree! "The gun will fire at the maximum range in the direction of the target position" - https://wiki.factorio.com/Types/AmmoType#clamp_position

I'd prefer the behaviour to change to match the docs, but one of them should certainly be changed.
The behaviour is correct,
Its IF the position is too far away, the gun will fire at the max range
Fair enough, I see what you mean now.
My mods
Content: Freight Forwarding | Spidertron Patrols | Spidertron Enhancements | Power Overload
QoL: Factory Search | Remote Configuration | Module Inserter Simplified | Wire Shortcuts X | Ghost Warnings

User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5148
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: [Klonan] [1.1.41] Vehicle weapon range is being ignored

Post by Klonan »

For the next release the cannon range is set to 30,
It doesn't actually change any of the behavior, just to remove it as a possible point of confusion for players

Post Reply

Return to “Resolved Problems and Bugs”