RimWorld

RimWorld

35 ratings
Avoid Friendly Fire - 1.6
   
Award
Favorite
Favorited
Unfavorite
Mod, 1.6
File Size
Posted
Updated
2.197 MB
23 Jul @ 6:30pm
4 Aug @ 3:31pm
2 Change Notes ( view )

Subscribe to download
Avoid Friendly Fire - 1.6

Description
The Problem:
"Vasquez, look out! There's a zombie twenty feet behind you!"
"Why do you think I'm running for the barricades?!"
"Vasquez, I'm gonna shoot it!"
"But it's behind me, you psycho! Don't shoo-"
*Vasquez has died.*
"No! Vasquez! My boy! Not my son! How could this happen?! Who could have seen this coming!?"

Has nobody on the Rim ever heard of trigger discipline?!?
It took one big shambler horde for me to get tired of my pawns shooting each other so much, and so I dug this bad boy out of its shallow grave. A few hours of light electrotherapy and it's alive once more!

This is Avoid Friendly Fire, recompiled for 1.6. Significant optimizations have been made! In testing, I was able to maintain 60 TPS (~9ms/t) with 15 friendly pawns and 120 enemies.

Falconne indicated in the comments of the OG that they were unlisting it and essentially offered it up for anyone to fork or maintain. If Falconne wishes for this version to be removed, please contact me via a Steam DM or an issue on the fork's GitHub repo[github.com].

Similarly, if you run into bugs, errors, or strange behavior, please create an issue on the repo describing the problem.



BELOW THIS LINE LIES THE ORIGINAL MOD DESCRIPTION.

This mod has performance issues with lots of pawns. Unfortunately I don't have time to improve it, but the code is on Github if anyone can help.

Colonists with the option enabled will not take a shot if the projectile's path could hit a friendly or neutral pawn (taking into account miss radius). Drafted colonists will look for a target with a clean shot (or wait if there isn't one), while hunters will reposition themselves.

This should hopefully alleviate some of the micromanagement needed to stop ranged colonists shooting friendlies, without changing the way friendly fire works in the game or reducing its potency.


== Usage ==
Any colonist with an appropriate weapon will show an “Avoid Friendly Fire” toggle button when they are selected (which is On by default; you can toggle it off for individual colonists). With this On their AI will automatically do the right thing.

If you manually try to force a drafted colonist who is set to avoid friendly fire to shoot an enemy with a friendly in the way, you will see a "Cannot hit target" message as you would if LoS was blocked.

Shooters who are being blocked by friendlies (but would otherwise have a target) will have their name on the map and in the Colonist Bar be written in cyan. Likewise, the first friendly blocking any shooter will show up in green.

There is a setting in the Mod Options screen to always enable 'Avoid FF' status on a pawn when it's undrafted. If you tend to disable the 'Avoid FF' setting on pawns during combat, using this option will ensure it is always turned back on again before the next combat. This option is off by default.

== Shield Belts ==
Shooters will not worry about pawns wearing a shield belt with at least 10% power standing in the line of fire, so you can still use shielded infantry to attack while ranged troops continue to fire over them from behind. If the shield drops below 10% power while the pawn is still subject to friendly fire, then the shooters will stop. They will resume shooting after the shield gets above 10%.

This behaviour can be disabled from the mod options if needed.


== Targeting Overlay ==
If you use the game’s manual targeting button (the one with the B hotkey that then shows the weapons range), you will see a red overlay that appears from the shooter to where you point the mouse (see image). This overlay shows the potential “fire cone” from a standard ranged weapon in the game, from the shooter to a target under the mouse (miss radius depends on weapon and shooter skill). Any pawn within the red overlay could potentially be hit. This is purely a visual aid for planning and can be disabled from the Mod Settings menu if you don’t like it. Note that pawns within 4 tiles of the shooter do not receive friendly fire, so the overlay does not mark them red and the mod takes this into account when deciding if a shooter should stop. In the example image the shooter on the top right will not shoot the pirate on the bottom left because the colonist "Flip" could potentially get hit.


== Animals ==
By default the mod will also take into account animals with an assigned master and protect them from friendly fire, so you should be able to use and release trained animals without them getting shot. In the Mod Settings you can expand this to include all tamed colony animals, such as livestock, but this is off by default as it could be annoying and cause performance issues on slower machines.


== Notes ==
This mod can be added to an existing save.

This mod is compatible with the Combat Extended mod, however the more complex fire trajectory in CE may mean this mod may not be 100% effective at very long ranges.

It is an often requested feature to add FF avoidance to turrets. However I want my mods to be pure QoL changes and not affect the balance of the game. The improvised turrets are cheap and friendly fire is an intended weakness of them (as mentioned in their tooltip). I am happy for another mod that adds smarter, more expensive turrets to incorporate my code to provide that functionality.


== Current Limitations ==
* Does not support explosive weapons such as grenades and weapons such as miniguns with a large forced miss radius. They will be used as normal and you will need to micromanage them as before. These might be supported in the future.

* Will protect neutral pawns on your map, but not animals owned by them. E.g., if there are traders around during a raid, your colonists will avoid hitting them but not watch out for their animals. Should be fixed in the future.

* Only affects the AI of your colonists. Does not prevent the computer controlled factions shooting their own troops; that’s a hard problem.

* Only affects the AI of shooters, who will stop shooting when someone gets in the way. Nothing is done to stop undrafted pawns from wandering into the middle of battle; again a harder problem to solve.

Translations:
* Japanese by @Proxyer
* Traditional Chinese by @FantasyMusic
16 Comments
MatrixVirus 14 Aug @ 7:34pm 
work for vehicles from VVE?
PathToV1ctory  [author] 14 Aug @ 6:42pm 
@JimmSlimm
Thank you for the kind words, but the vast majority of this mod was done by the original author, Falconne. I have adopted it for maintenance, and only made some minor adjustments to try and optimize.

Those seem like good suggestions for optimizing it even further, thank you very much! I'll test them sometime soon.
JimmSlimm 14 Aug @ 2:35pm 
Hey, I just wanted to say that your mod is awesome, and I learned a lot from your code on GitHub while working on my own project.
To give something back, I found a couple of ways to optimize your GetFireCone function that should give a really nice performance boost.
Here's an image explaining the ideas: https://postimg.cc/sQy6GsKB
And here's the code changes you'd need: https://justpaste.it/6kn41
Jarrod 5 Aug @ 6:30pm 
@GetUrAssToMars I'm like 90% sure this *is* tied to the skill. There's a setting to make it *not* tied to the shooting skill.
GetUrAssToMars 5 Aug @ 8:38am 
It would be amazing if this could be somehow tied into the pawns ranged skill.
Jarrod 5 Aug @ 6:20am 
Yo bless you for the optimizations. It makes this work way better with the "search and destroy" mod which turned the game into a slideshow when you turned it on. Now it's smooth as butter.
PathToV1ctory  [author] 4 Aug @ 3:45pm 
V1.6.1 - Optimized logic for checking if it is safe for pawns to fire. Now checks the firecone for pawns, instead of checking if pawns are in the firecone.


In testing, this update made me able to maintain 60TPS (8-10ms/t) with 15 friendlies and 120 enemies in combat.
The previous version brought me down to <30TPS (well over 40ms/t) in a similar situation; less than half of the target TPS for 1x speed.
ObscureParticle 4 Aug @ 9:15am 
@Guedez, depends on the difficulty, at higher difficulties friendly fire is more likely to happen, and when you have high dmg weapons like lances or such, these can easily one shot a pawn, it's even an issue when you have multiple people hunting.
Guedez 4 Aug @ 5:27am 
Is this mod even needed? I feel like bullets barely ever hit friendlies at all. I have my pawns in a lazy circle formation and they shoot through each other with no issue. I see one friendly fire hit every 300 bullets or something
ObscureParticle 30 Jul @ 5:35pm 
Can I use this without HugsLib?