RimWorld

RimWorld

Vanilla Furniture Expanded - Security
Shield generators fail to protect against drop pod raids (with code explanation) [now fixed]
Shield generators don't activate until there is an active threat on the map, satisfying the condition GenHostility.AnyHostileActiveThreatTo(MapHeld, Faction) in your BuildingShield.cs. Drop pod raids don't seem to satisfy this until after the pods have landed and opened, spawning the hostiles they contain into the map (who fulfil the condition). This means that drop pod attacks drop right through the shields without activating them. Specifically the line in BuildingShield.cs:

active = ParentHolder is Map && CanFunction && (Find.World.GetComponent<WorldArtilleryTracker>().bombardingWorldObjects.Any() || GenHostility.AnyHostileActiveThreatTo(MapHeld, Faction) || Map.listerThings.ThingsOfDef(RimWorld.ThingDefOf.Tornado).Any());

looks like it needs another OR condition that checks for drop-pod raids (or raids in general, as the case may be if that's easier) so that these attacks satisfy the condition prior to their successful landing (so that like all other raid types they cause the shields to power up at the instant they begin).

Map.listerThings.ThingsOfDef(RimWorld.ThingDefOf.DropPodIncoming).Any()
should find incoming drop pods, but I think you'd need an extra condition with it to determine their intent/contents instead of .Any() and as a newcomer to the rimworld source I don't know enough to find it. It may also be the case that waiting for the dropping pods to exist on the map doesn't give the shields time to power up (or is not the most efficient approach), in which case you might be better off looking for the existence of the raid itself as the condition (but again, I'm too new to know where I'd find it). From taking a look, I think you can call the pod and get the data of the pawns inside (who could then be checked for hostility) but again, not sure if this is the best way. Still, I've been modding long enough to know that if you're going to ask things of someone it's best to offer everything you can to make that workload smaller.

There may well be a better way to do all this than any of what I've posted, but it seems like it isn't the intended behaviour to have shields capable of offering some defence versus drop pods but on a practical level unable to do so.
Last edited by LT General Apathy; 14 Oct, 2019 @ 1:06pm
< >
Showing 1-15 of 27 comments
LT General Apathy 30 Sep, 2019 @ 4:37pm 
Having had a bit more of a play, adding || Map.listerThings.ThingsOfDef(RimWorld.ThingDefOf.DropPodIncoming).Any() in the conditions *does* cause shields to power on when drop pods are launched into the map (friendly *or* hostile), but *does not* let the shield stop them, as they still drop right through.

I'm starting to wonder if maybe I'm being served an older version of the mod from the steam workshop, as looking at Building_Shield.cs I see no mention of drop pods, DropPodIncoming, or any way the code would affect them.

Double edit:

found where the code is supposed to affect the SkyFallers in the Harmony patches. I'm wondering if the utter lack of effect the shields have is an incompatibility with another mod. That said, checking for incoming drop pods (and a timer that keeps the shields up 15 ticks after whatever turned them on has passed) utterly cover the issues with the shield activation through drop pod attacks.
Last edited by LT General Apathy; 1 Oct, 2019 @ 11:11am
Final post - the problem is entirely with the shields turning on in time. The method chosen to intercept drop pods requires the shield being on *before* the pod is incoming so that it intercepts the DropPodIncoming's placement, which is not possible with the way the power-on conditions are scripted as changing the code so that shields are always on results in pods being correctly blocked.

For proper function, either the method of interception needs to be changed or some changes need to be made to the detection of drop pod raids. I'd suggest the former, as the current method also provides no feedback that a raid is occurring or that a drop pod was successfully blocked beyond shield depletion.
+1 this is kinda important
Further update: instantly destroying the drop pods as they are spawned suppresses the raid notification for the attack even if some pods survive, and killed enemy pawns are not properly logged (as they simply cease to exist when the pod is destroyed). This can be resolved by looping over the contents of the pod and manually killing each pawn.

Honestly, looking at the implementation of other shield mods I'm not sure the point of the drop-pod process being hooked was a wise choice. Hooking into the process at spawnsetup means you're interrupting the creation process of the pods, which means they never come into being if the shield is capable of stopping them. Which unfortunately messes with raid instantiation and alerts, and causes shields to erase pods from existence rather than block them.

This is also the root of the issue with drop pod raids not being intercepted - the raid doesn't start until the pods are placed, so if the shield turns on in response to the raid it will *never* turn on in time as once they're spawned the shield can't touch them. Looking at other shield mods, it looks like they patch the Tick function for the drop pod that updates their motion and height so that it checks if they're in a shield's zone when they reach a certain height and performs the interaction then. This seems like a sensible way to do things, so I'm having a go at putting together a method like this for my own satisfaction. If there's any interest in merging this into the actual mod (or just having someone more familiar with rimworld glance at my code and steal all the good bits) please contact me and I'll be happy to share.
Last edited by LT General Apathy; 3 Oct, 2019 @ 1:24pm
Originally posted by LT General Apathy:
Further update: instantly destroying the drop pods as they are spawned suppresses the raid notification for the attack even if some pods survive, and killed enemy pawns are not properly logged (as they simply cease to exist when the pod is destroyed). This can be resolved by looping over the contents of the pod and manually killing each pawn.

Honestly, looking at the implementation of other shield mods I'm not sure the point of the drop-pod process being hooked was a wise choice. Hooking into the process at spawnsetup means you're interrupting the creation process of the pods, which means they never come into being if the shield is capable of stopping them. Which unfortunately messes with raid instantiation and alerts, and causes shields to erase pods from existence rather than block them.

This is also the root of the issue with drop pod raids not being intercepted - the raid doesn't start until the pods are placed, so if the shield turns on in response to the raid it will *never* turn on in time as once they're spawned the shield can't touch them. Looking at other shield mods, it looks like they patch the Tick function for the drop pod that updates their motion and height so that it checks if they're in a shield's zone when they reach a certain height and performs the interaction then. This seems like a sensible way to do things, so I'm having a go at putting together a method like this for my own satisfaction. If there's any interest in merging this into the actual mod (or just having someone more familiar with rimworld glance at my code and steal all the good bits) please contact me and I'll be happy to share.
Big thanks for doing this btw :)
Last edited by NachoToast is now playing RimWor; 3 Oct, 2019 @ 2:30pm
Originally posted by NachoToast:
Big thanks for doing this btw :)

I literally can't help myself. I have modded pretty much every game I've ever played, maybe this will be one of the tiny handful where my effort goes to some greater use.
Update - I have a working proof of concept, inspired by the Frontier Developments shield mod's method of patching the pod's tick instead of its creation. I want to test it more to ensure it's all working as intended, but it seems to be a drastic improvement so if I can get it nailed down and properly tested I'll try to contact Oskar/the VFE team and see if they're interested.

It correctly lets pods spawn (and so not interrupting the raid setup so you get a notification), checks them when they get to a certain height, deals damage to the shield, kills the occupants and deletes their inventory, and *then* destroys the pod. I'm working on an IFF check (looping through the pod and checking if any of the contained pawns count as active threats) so you can drop through your own shields and they won't vapourise friendly faction drop pod backup.

I'll also look at some audiovisual feedback and maybe a UI message.
Last edited by LT General Apathy; 5 Oct, 2019 @ 9:14am
Originally posted by LT General Apathy:
Update - I have a working proof of concept, inspired by the Frontier Developments shield mod's method of patching the pod's tick instead of its creation. I want to test it more to ensure it's all working as intended, but it seems to be a drastic improvement so if I can get it nailed down and properly tested I'll try to contact Oskar/the VFE team and see if they're interested.

It correctly lets pods spawn (and so not interrupting the raid setup so you get a notification), checks them when they get to a certain height, deals damage to the shield, kills the occupants and deletes their inventory, and *then* destroys the pod. I'm working on an IFF check (looping through the pod and checking if any of the contained pawns count as active threats) so you can drop through your own shields and they won't vapourise friendly faction drop pod backup.

I'll also look at some audiovisual feedback and maybe a UI message.
If you need anything in terms of testing and bug finding I'd be happy to help out.
LT General Apathy 7 Oct, 2019 @ 12:24pm 
Originally posted by NachoToast:
If you need anything in terms of testing and bug finding I'd be happy to help out.

It might be a good idea to have someone else try this out to make sure I'm not ignoring anything. Drop me a message and I'll shoot you a compiled version of the changed code.
Krausladen 11 Oct, 2019 @ 2:05pm 
Why not just add a modified roof type to the generator field that forces drop pods outside the radius?
Krausladen 11 Oct, 2019 @ 2:17pm 
Look at the XML code of a mountain roof type that disables the drop pods, and use that mechanic on the tiles within the generator field while still enabling the outdoor effects.

If you wanted to take it to the next level, theoretically a shield generator field would interrupt light from the sun, so crops within an activated generator field wouldn't grow as quickly as they are not getting the same light energy as they would be without a generator field - but this is just way out there though and besides the point.

I'm not experienced, but I don't think forcing the drop pods outside of the radius of the generator would be as hard as you make it seem.
LT General Apathy 11 Oct, 2019 @ 2:44pm 
Originally posted by Krausladen:
Why not just add a modified roof type to the generator field that forces drop pods outside the radius?
Because then they'd be always-on, have no way to be depleted by repeated strikes, and a bunch of other issues. Working around *that* set of issues would require a bunch of code to add/remove roofs to areas, remember which roofs were there originally, support any custom roof types people have and so on. Essentially a whole bunch of coding work, and if I'm going to do a bunch of coding work I'm going to do it the cleaner way rather than having to do a workaround for an issue I can fix in the source code.

Honestly, compared to the implementation that already exists it just sounds painful to create and maintain, and doesn't seem to offer much.

Originally posted by Krausladen:
Look at the XML code of a mountain roof type that disables the drop pods, and use that mechanic on the tiles within the generator field while still enabling the outdoor effects.
[...]
I'm not experienced, but I don't think forcing the drop pods outside of the radius of the generator would be as hard as you make it seem.
It's not about forcing them outside the radius, and if I were to do that this isn't how I'd do it because working round the issue in XML like that is always going to be slower than doing it in code, it'd be much easier to just scan the radius around the shield generator when it's on and move any incoming pods away rather than messing around with fake roofs. The way they're set up at the moment; however, is that they're supposed to destroy incoming pods the same way they do incoming munitions and I don't want to change that.

This also maintains the game mechanics and balance, shields aren't an "I win" button against drop pod raids jumping into your base, they're a way to mitigate the power of these raids by thinning them out without removing them entirely. The raid still happens, though if you've invested inordinate resources in defending exactly the right point it can be stopped quite quickly.

Originally posted by Krausladen:
If you wanted to take it to the next level, theoretically a shield generator field would interrupt light from the sun, so crops within an activated generator field wouldn't grow as quickly as they are not getting the same light energy as they would be without a generator field - but this is just way out there though and besides the point.

Shields are only on during raids, unless you're being raided for a week at a time and have the power supply to keep your shields up that whole time (and also don't just turn them off) it'd never be an issue.

Besides, I've already got it written the neat C#-only way now and I'm 99% sure it works consistently like it was originally intended, which was my aim.
Jgta4444 12 Oct, 2019 @ 10:40pm 
Hello there, can i have copy of modified dll?Thanks
Last edited by Jgta4444; 12 Oct, 2019 @ 10:40pm
LT General Apathy 13 Oct, 2019 @ 6:55am 
Originally posted by Jgta4444:
Hello there, can i have copy of modified dll?Thanks
I'd prefer not to be distributing an unfinished patch to someone else's mod via their own steam workshop page, it seems pretty rude. If you're interested in helping me test it then let me know, but if you'd just like to play with the changes I'd advise waiting. Either my changes or someone else's will fix this at some point.
Jgta4444 13 Oct, 2019 @ 11:53pm 
Originally posted by LT General Apathy:
Originally posted by Jgta4444:
Hello there, can i have copy of modified dll?Thanks
I'd prefer not to be distributing an unfinished patch to someone else's mod via their own steam workshop page, it seems pretty rude. If you're interested in helping me test it then let me know, but if you'd just like to play with the changes I'd advise waiting. Either my changes or someone else's will fix this at some point.

Okay, i'm just concerned that mod devs focused on writing new mods, and that can take a while...guess i'm just will use Frontier Shields
< >
Showing 1-15 of 27 comments
Per page: 1530 50