ResearchMod help needed

Started by skullywag, March 01, 2015, 04:54:43 PM

Previous topic - Next topic

skullywag

Hey guys,

Can someone help me get a working ResearchMod for my omniturrets mod, currently im doing it in a not to nice way and it seems to have some strange effect sometimes of turning all my turrets into miniguns (pistol shoots at a silly rate).

So to what im after, I want to loop over the def database and pick out all ranged weapons that have the <building><turretBurstCooldownTicks> (customly added by me in this mod) and then reduce it somewhat. Any help would be massively appreciated.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Famous Shoes

Are you saying you've got a custom XML element in a ThingDef and have the engine processing that and are able to access it in code? If so, I'd very much like to know how that's done.

But, on to your request: I'm still figuring a lot of things, but if you clarify what you're after and the problem you're having, I'll certainly pitch in if I can.

skullywag

checkout the vanilla gun turret cooling research, you just add a class in the research def, simples. You know we can add our own dlls right?
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

mipen

I might be wrong, but I believe that the research mod method is called more than once, so if you -= the burst cooldown count, then it will continue to decrease. You could try adding a bool check at the beginning of the method to check if it has been done before. If it has, then do nothing. You can add the Saveable interface to save the value of the bool

skullywag

ahhh that would explain it, Tynan just sets the burst count to 4 so it doesnt matter, im reducing the cooldown so as you state it just keeps dropping. Thanks Mipen no idea how i didnt see that its pretty obvious now youve said it. OK so mystery 1 solved, anyone have any clues on how I can select the defs im after and make that change to all guns that supply the cooldown tag.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

Famous Shoes

@skullywag Thanks, I do see that. What I'm asking about is how you added custom XML to a ThingDef and how you're accessing that in code; if I understand that I might be able help with some code iterate those defs (not to mention solve the problem I'm trying to work on in my particular mod. :) )

skullywag

thats not what im doing here really ive added tag that isnt usually on weapons but exists on things. But what youre asking for is possible theres some tutorials (old ones) around here somewhere, it involved adding class=MyNamespace.MyClass to the def (where you out names and parents.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

mipen

#7
So you just want to search through all defs and pick out the ones that have that tag on them? I assume you also want it to only take weapons, otherwise it would affect any turret in the game.

You could try:

                List<ThingDef> list = (
                    from t in DefDatabase<ThingDef>.AllDefsListForReading
                    where t.category == EntityCategory.Item && t.building != null && t.building.turretBurstCooldownTicks > 0
                    select t).ToList();
                foreach(var c in list)
                {
                    c.building.turretBurstCooldownTicks -= 5;
                }


That should find everything that is an item and has turretBurstCooldownTicks on it. You could also test the thingClass for a specific class if you wanted to do it that way

skullywag

#8
Well theres an interesting quirk....i had something similar to what you put above (without some of the error checking...i need to be better at that..) and it wouldnt work, i tried yours and nope still no go...then i tried ACTUALLY researching the darned thing and not hitting the debug do all research button, that sucker dont work right....*sigh*, works fine...now just need to add the run once var in there and save the state and it should be good. Thanks Mipen, I might raise this as a bug as I would assume it should run all the research code, but as its a dev tool option...its not major.

edit - so no save needed, on loading a game it will rerun the researchmod from scratch, so it picks up my bool for runonce and just does it again, so all done works perfectly, heres the code I had in the end:
using System;
using System.Linq;
using System.Collections.Generic;
namespace Verse
{
public static class OmniResearchModsSpecial
{
        public static bool runonce;
        public static void OmniTurretCooling()
        {
            if (runonce == false)
            {
                List<ThingDef> list = (
                        from t in DefDatabase<ThingDef>.AllDefsListForReading
                        where t.category == EntityCategory.Item && t.building != null && t.building.turretBurstCooldownTicks > 0
                        select t).ToList();
                foreach (var c in list)
                {
                    c.building.turretBurstCooldownTicks -= 10;
                }
            }
            runonce = true;
        }
    }
}
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

mipen

But won't this cause the number to be reduced every time the game is loaded?

skullywag

Yes if the research is complete. Which is correct as loading the game will reset the def. So you need to reapply the change. Its how core works for the turret.
Skullywag modded to death.
I'd never met an iterator I liked....until Zhentar saved me.
Why Unity5, WHY do you forsake me?

mipen