[C#] How to code in incident to spawn pawns and make them attack.

Started by Deon, January 08, 2017, 03:51:45 AM

Previous topic - Next topic

Deon

Hello. I blatantly wrote to  Jecrell to ask about this, but I would like to ask here too.
A new modder here, I studied XML of the game already so I have no issue adding things into the game, but I need to learn how to make incidents now to make somewhat interesting mods.

My first one is aliens/predator mod, so it does need some coding to add the features like alien attacks and predator spawning.


I am currently struggling with basic stuff: how to spawn a pack of pawns of some kind and make them attack the colony through an incident.

If I understand correctly, from what I've seen in Jecrells' code, I need:
1) Make a variable for a PawnKind which find the PawnKind from XML:
varKind = PawnKindDef.Named("Xenomorph");
2) Make a variable for a faction to assign the pawn to:
varFac = Find.FactionManager.FirstFactionOfDef(FactionDef.Named("Aliens"));
3) Make a variable out of PawnGenerator class to get the pawn itself:
varPawn = PawnGenerator.GeneratePawn(varKind, varFac);

Now I just need to force it to find a suitable spawn location and spawnpawns there.


public override bool TryExecute(IncidentParms parms)
{
       <variable declaration>
       FindSpawnLoc(parms); // locate where to spawn creatures
       SpawnAliens(parms); // call the function to spawn the aliens
}


This is where I run into issues.
Jecrell seems to use:
iwLoc       = CellFinder.RandomClosewalkCellNear(parms.spawnCenter, 8);
https://ludeon.com/forums/index.php?topic=26373.msg266952#msg266952

However my compiler complains that CellFinder.RandomClosewalkCellNear needs 3 parameters and "map" is missing from those.
Can someone help me to figure out why it works for Jecrell and my compiler does not work with it? I can find the definition of this in the metadata:
public static IntVec3 RandomClosewalkCellNear(IntVec3 root, Map map, int radius);

So there seems to be 3 parameters. I have no idea how to get the "Map" to pass to it. Am I doing something completely wrong? I hope that my concern is understood :). Thank you in advance.


P.S. A secondary question would be how to make the pawns of a "manhunter" type. I assume there's a simple variable you can flick, but I could not find where to look for it. Is there a "full source code" somewhere I can look up?

RawCode

A16 implemented ability to load and run multiple maps at once, for this reason, you need to pass map object.

i suggest you to check how vanilla implemented raids, instead of basing your code on outdated stuff found somewhere.

scuba156


ison

In most cases Find.VisibleMap is not what you're looking for. If it's used for anything other than drawing then it's very likely that your mod will break as soon as a new map is created. Here you need to get the map reference from the IncidentParms: var map = (Map)parms.target;

Deon

Quote from: ison on January 08, 2017, 09:29:29 AM
In most cases Find.VisibleMap is not what you're looking for. If it's used for anything other than drawing then it's very likely that your mod will break as soon as a new map is created. Here you need to get the map reference from the IncidentParms: var map = (Map)parms.target;
Thanks, already figured it out today. I just need to look into AI writing to make a custom intelligence/lord for my pawns now. This forum and Discord for modders are very helpful.