overriding classes - modding mineables in alpha 7 ??

Started by Duncan, October 02, 2014, 12:27:47 PM

Previous topic - Next topic

Duncan

It seems it is not possible to mod mineable minerals in alpha 7 despite new minerals being added. I read the code and it hinges on the Genstep_ScatterMineableChunks class. The addition of minerals to the map is hard coded by def name. I wrote the following modification to the class which would work if I could get the program to call it:


public class Genstep_ScatterMineableChunks_Test : Genstep_ScatterMineableChunks
    {
private static readonly IntRange ChunkSizeRange = new IntRange(20, 40);
protected override ThingDef RandomThingDefToScatter
{
get
{
float value = Rand.Value;
                if (value < 0.1)
                {
                    return ThingDef.Named("MineableTest");
                }
if (value < 0.03f)
{
return ThingDef.Named("MineableGold");
}
if (value < 0.06f)
{
return ThingDef.Named("MineablePlasteel");
}
if (value < 0.11f)
{
return ThingDef.Named("MineableSilver");
}
return ThingDef.Named("MineableMetal");
}
}
}


The problem is this class is not referenced in any xml I can find. I don't know how to override a class that is not referenced in xml. Is it possible to get the program to call Genstep_ScatterMineableChunks_Test instead of Genstep_ScatterMineableChunks?

This is a general issue with modding and I have not found a thread which answers this question, possibly because the answer is obvious to coders familiar with dlls which I am not. If it is not possible then what is the point of the new minerals at all? There is an xml file for them but if you delete anything it crashes the game and if you add anything it ignores it.

Duncan

I figured out the mineables problem, but not the overriding problem. It appears that Genstep_ScatterMineableChunks is called from Genstep_RocksFromGrid, and that is listed in the mapgen xml. The resulting mod can be found here

My guess is that without an xml reference it is not possible to override internal code.