Fire seeking/mortar targetting with C#

Started by Master Bucketsmith, August 12, 2016, 07:26:48 AM

Previous topic - Next topic

Master Bucketsmith

Hey, so, I've made a little mod about a firefoam mortar. It works.

Now, I'm wondering if some C# whizzkid could figure out a way for an automated version to automatically seek fire and target it.
I'm not worried about the balancing of it yet, I just want to know if it's gonna be possible at all. :D

robotguy4

If I were going to do this, I'd probably first either look into how the base game codes the improvised turret. That, or try to borrow code from the expanded vanilla turrets mod.

Got any C# experience?

Master Bucketsmith

I do not.

I think the hard part is making some sort of routine that reacts to fires spawning, usable as 'targeting' for mortars.

CallMeDio

From what I learned reading the source I think (not 100% sure but around 90% sure), that fire is not a object on itself, it is a property added to objects like grass,trees, walls, etc... on JobGiver_FireStartingSpree you can see it looks all objects in the map for "potentialTargets" doing something like
Region region;
            if (!CellFinder.TryFindClosestRegionWith(pawn.Position.GetRegion(), TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), (Region candidateRegion) => !candidateRegion.IsForbiddenEntirely(pawn), 100, out region))
            {
                return null;
            }
            JobGiver_FireStartingSpree.potentialTargets.Clear();
            List<Thing> allThings = region.ListerThings.AllThings;


Maybe you can do something like this to get all objects on the map and then from the list of all objects you can do a loop to get all that are on fire and for those you can aim at that object or its location based on the way that the mortars aim at enemies, but this time on the objects that are on fire.
Looking forward to see that mortar working, I think it doesn't make much sense to have a explosive that can put out fires and having to carry it manually to the middle of hell to activate instead of just making a bomb of it and throwing there. Keep it up.  :)
QuoteYou may need a rubber duck.  Also, try some caveman debugging.

Released mods: No Mood Loss on Prisoner Sold or Died

Master Bucketsmith

Quote from: CallMeDio on August 13, 2016, 09:20:36 PM
From what I learned reading the source I think (not 100% sure but around 90% sure), that fire is not a object on itself, it is a property added to objects like grass,trees, walls, etc... on JobGiver_FireStartingSpree you can see it looks all objects in the map for "potentialTargets" doing something like
Region region;
            if (!CellFinder.TryFindClosestRegionWith(pawn.Position.GetRegion(), TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), (Region candidateRegion) => !candidateRegion.IsForbiddenEntirely(pawn), 100, out region))
            {
                return null;
            }
            JobGiver_FireStartingSpree.potentialTargets.Clear();
            List<Thing> allThings = region.ListerThings.AllThings;


Maybe you can do something like this to get all objects on the map and then from the list of all objects you can do a loop to get all that are on fire and for those you can aim at that object or its location based on the way that the mortars aim at enemies, but this time on the objects that are on fire.
Looking forward to see that mortar working, I think it doesn't make much sense to have a explosive that can put out fires and having to carry it manually to the middle of hell to activate instead of just making a bomb of it and throwing there. Keep it up.  :)
Hmm that's useful, thank you. I'm absolute newbie at C# and coding is novice level from years back so I'll try my best.
Wont continiously checking for fire on the map become a performance drain?