mr_mouflon
Recruit
Howdy all,
I've been fiddling around trying to add new wanderers via xml. I'm not quite there yet but I figured I ought to share what I've found and see if anyone knows how to get me over the line. It seems like it should be possible only with XMLs, at least I'm hoping so since that's about as far as my script kiddy skills will take me...
So! I copied and modified entries from the Sandbox Module's spspecialcharacters.xml, wanderer_strings.xml and SandBoxCore's spnpccharactertemplates.xml (which may have had a point to it? I don't understand the difference between sandbox and sandboxcore, if I'm honest).
Plugged everything in, hey presto after a few dozen attempts the new wanderers do appear in the encyclopedia, and seem to exist to the given specification. But whenever I go to the town they're shown as being in, there's nothing there. Other wanderers will appear in the tavern as usual, but not the ones I added. Any clues? I'm guessing there's some loose end NPCCharacter entry somewhere that the mobs need to fully initialize so they can appear in the flesh?
In the meantime, I've poked around the dlls with dnSpy and discovered how the game populates itself with wanderers. For those interested!
At the start of a new game, it grabs all the valid NPC templates with the occupation 'Wanderer' (there are tons of unfinished/unused ones in the files, deactivated by commenting out "isTemplate=true")
Once it has them all, it counts them up then does this maths:
So it divides 25 by the number of templates and clamps the result between 0.33 and 1, then goes through every template and spawns them based on that probability. I infer: if there are 25 or fewer templates, all of them will spawn; if there is an arbitrarily large number of templates, one third of them will spawn. Presumably there are other barriers in place to stop it getting too silly.
There's also a system to spawn new companions as the campaign progresses. There are some hard-coded numbers here:
Although that TargetCompanionNumber I can't find referenced anywhere else, not sure where that leads.
Incidentally - when you look at binaries with dnSpy, that's not how the code was actually written, is it? Some of this stuff is impenetrable, I can only imagine a mind that works with this many layers of efficiency.
Anyway, that's all for now. I'll keep chewing at it and post what I find. Any insights from the more educated would be most appreciated.!
I've been fiddling around trying to add new wanderers via xml. I'm not quite there yet but I figured I ought to share what I've found and see if anyone knows how to get me over the line. It seems like it should be possible only with XMLs, at least I'm hoping so since that's about as far as my script kiddy skills will take me...
So! I copied and modified entries from the Sandbox Module's spspecialcharacters.xml, wanderer_strings.xml and SandBoxCore's spnpccharactertemplates.xml (which may have had a point to it? I don't understand the difference between sandbox and sandboxcore, if I'm honest).
Plugged everything in, hey presto after a few dozen attempts the new wanderers do appear in the encyclopedia, and seem to exist to the given specification. But whenever I go to the town they're shown as being in, there's nothing there. Other wanderers will appear in the tavern as usual, but not the ones I added. Any clues? I'm guessing there's some loose end NPCCharacter entry somewhere that the mobs need to fully initialize so they can appear in the flesh?
In the meantime, I've poked around the dlls with dnSpy and discovered how the game populates itself with wanderers. For those interested!
At the start of a new game, it grabs all the valid NPC templates with the occupation 'Wanderer' (there are tons of unfinished/unused ones in the files, deactivated by commenting out "isTemplate=true")
Once it has them all, it counts them up then does this maths:
Code:
int count = this._companionTemplates.Count;
float num5 = MathF.Clamp(25f / (float)count, 0.33f, 1f);
foreach (CharacterObject companionTemplate in this._companionTemplates)
{
if (MBRandom.RandomFloat < num5)
{
this.CreateCompanion(companionTemplate);
}
So it divides 25 by the number of templates and clamps the result between 0.33 and 1, then goes through every template and spawns them based on that probability. I infer: if there are 25 or fewer templates, all of them will spawn; if there is an arbitrarily large number of templates, one third of them will spawn. Presumably there are other barriers in place to stop it getting too silly.
There's also a system to spawn new companions as the campaign progresses. There are some hard-coded numbers here:
Code:
private float _randomCompanionSpawnFrequencyInWeeks = 6f;
private float _companionSpawnCooldownForSettlementInWeeks = 6f;
private const float TargetCompanionNumber = 25f;
Although that TargetCompanionNumber I can't find referenced anywhere else, not sure where that leads.
Incidentally - when you look at binaries with dnSpy, that's not how the code was actually written, is it? Some of this stuff is impenetrable, I can only imagine a mind that works with this many layers of efficiency.
Anyway, that's all for now. I'll keep chewing at it and post what I find. Any insights from the more educated would be most appreciated.!