CompProperties retrieveing List from XML

Started by Grim, February 24, 2020, 12:42:45 PM

Previous topic - Next topic

Grim

Hi there,

I'm currently working on a component for Pawnkinds that allow you to evolve them, I currently define an evolution like

 
<comps>
    <li Class="CompProperties_Evolvable">
      <killsToEvolve>1</killsToEvolve>
      <evolveToPawnKindDef>BiggerZergling</evolveToPawnKindDef>
    </li>
  </comps>


What I would like to do is be able to define it a little more like below so I can allow multiple evolutions and triggers to be define per Pawnkind.

I can't find any example of a mod doing similar, but there is a good chance I just didnt see it, I would like to know if its possible and if so, could someone point me where to look.

Thank you



 
<comps>
    <li Class="CompProperties_Evolvable">
       <li>
          <evolutionTriggerType>Stat_Kills_Human</evolutionTriggerType>
          <evolutionTrigger>10</evolutionTrigger>
          <evolveToPawnKindDef>BiggerZergling</evolveToPawnKindDef>
       </li>
       <li>
          <evolutionTriggerType>Stat_TimeOnFire</evolutionTriggerType>
          <evolutionTrigger>10</evolutionTrigger>
          <evolveToPawnKindDef>SomethingIronicallyFire</evolveToPawnKindDef>
       </li>
    </li>
  </comps>


Grim

#2
Hi,

Thank you for heads up, I have checked out your code where you define a FishDef and the accompanying XML but I can't make this apply to my situation as I don't want to define a new separate evolution for each kind, for example I need to be able to provide a list of a custom c# data class (below #2)

I tried to adapt to your method by creating a EvolutionDef : ThingDef with only a List<EvolutionData> as a member but the XML wouldnt parse (error was literally XML Parsing error), I have very likely misunderstood what I am doing.

<?xml version="1.0" encoding="utf-8"?>
<Defs>
<Zergling_Test.EvolutionDef>
<defName>EvolutionDefKillsAnimal</defName>
<evolutionTriggerType>Stats_Kills_Animal</evolutionTriggerType>
<evolutionTrigger>1</evolutionTrigger>
<evolveToPawnKindDef>BiggerZergling</evolveToPawnKindDef>
<regenerateWounds>true</regenerateWounds>
</Zergling_Test.EvolutionDef>
</Defs>

namespace Zergling_Test
{
    public class EvolutionDef : ThingDef
    {
        public List<EvolutionData> evoData;
    }
}



2#
   
public class EvolutionData
    {
        public string evolutionTriggerType;
        public int evolutionTrigger;
        public string evolveToPawnKindDef;
        public bool regenerateWounds;
    }

public class CompProperties_Evolvable : CompProperties
{
    public List<EvolutionData> evoData;

    /// <summary>
    /// These constructors aren't strictly required if the compClass is set in the XML.
    /// </summary>
    public CompProperties_Evolvable()
    {
        this.compClass = typeof(CompEvolvable);
    }
}



So then people not too familiar with programming but wanting to use the component can just specify in XML two seperate evolutions for this particular creature race by setting the trigger, the trigger amount and def of what to evolve into.


<comps>
    <li Class="CompProperties_Evolvable">
        <li>
          <evolutionTriggerType>"Stat_Kills_Animal"</evolutionTriggerType>
          <evolutionTrigger>1</evolutionTrigger>
          <evolveToPawnKindDef>"BiggerZergling"</evolveToPawnKindDef>
          <regenerateWounds>true</regenerateWounds>
        </li>
        <li>
          <evolutionTriggerType>"Stat_Kills_Mech"</evolutionTriggerType>
          <evolutionTrigger>100</evolutionTrigger>
          <evolveToPawnKindDef>"MEKAZergling"</evolveToPawnKindDef>
          <regenerateWounds>true</regenerateWounds>
        </li>
    </li>
  </comps>


Im wondering if I should add the component multiple times per creature evolution as a workaround until I understand how the game all ties together better.

As a side note, GeneticRim is one of my favourite mods thanks for that!

LWM

You need your <li> to be INSIDE something that's named.

So

<comps>
    <li Class="CompProperties_Evolvable">
      <evolutions>
       <li>
          <evolutionTriggerType>Stat_Kills_Human</evolutionTriggerType>
          <evolutionTrigger>10</evolutionTrigger>
          <evolveToPawnKindDef>BiggerZergling</evolveToPawnKindDef>
       </li>
       <li>
          <evolutionTriggerType>Stat_TimeOnFire</evolutionTriggerType>
          <evolutionTrigger>10</evolutionTrigger>
          <evolveToPawnKindDef>SomethingIronicallyFire</evolveToPawnKindDef>
       </li>
      </evolutions>
    </li>
  </comps>


And your compproperties will have:
List<Evolution> evolutions;
Then each Evolution will have those various bits you want.  HTH,  LWM