Terrain Heat

Started by N00by95, December 07, 2019, 06:08:43 PM

Previous topic - Next topic

N00by95

Though it would be simple but can't get it to work I'm trying to make terrain to pump and draw heat, I'm working on a cheaty mod. this is the code that will not work.

<?xml version="1.0" encoding="utf-8" ?>
<Defs>

  <TerrainDef ParentName="FloorBase">
    <defName>CryonitelTile</defName>
    <label>cryonite tile</label>
    <renderPrecedence>240</renderPrecedence>
    <description>Cooling floors.</description>
    <texturePath>Stuff/CryonitelTile</texturePath>
    <statBases>
      <WorkToBuild>800</WorkToBuild>
         <Beauty>2</Beauty>
      <Cleanliness>0.4</Cleanliness>
    </statBases>
   <comps>
      <li Class="CompProperties_HeatPusher">
        <compClass>CompHeatPusherPowered</compClass>
        <heatPerSecond>-11</heatPerSecond>
      </li>
    </comps>
    <costList>
      <cryonite>7</cryonite>
    </costList>
    <constructEffect>ConstructMetal</constructEffect>
    <designationHotKey>Misc1</designationHotKey>
    <researchPrerequisites>
      <li>Smithing</li>
    </researchPrerequisites>
    <constructionSkillPrerequisite>3</constructionSkillPrerequisite>
  </TerrainDef>
 
  <TerrainDef ParentName="FloorBase">
    <defName>PyroniteTile</defName>
    <label>pyronite tile</label>
    <renderPrecedence>240</renderPrecedence>
    <description>Heating floors.</description>
    <texturePath>Stuff/PyroniteTile</texturePath>
    <statBases>
      <WorkToBuild>800</WorkToBuild>
         <Beauty>2</Beauty>
      <Cleanliness>0.4</Cleanliness>
    </statBases>
   <comps>
      <li Class="CompProperties_HeatPusher">
        <compClass>CompHeatPusherPowered</compClass>
        <heatPerSecond>11</heatPerSecond>
      </li>
    </comps>
    <costList>
      <pyronite>7</pyronite>
    </costList>
    <constructEffect>ConstructMetal</constructEffect>
    <designationHotKey>Misc1</designationHotKey>
    <researchPrerequisites>
      <li>Smithing</li>
    </researchPrerequisites>
    <constructionSkillPrerequisite>3</constructionSkillPrerequisite>
  </TerrainDef>

</Defs>

K

The problem with this approach is that floors aren't Things, they're Terrain. Only Things can have comps, so you won't be able to add a comp to terrain of any kind, including floors.

More than that, Terrain is fundamentally different from a Thing. When you make a ThingDef it defines a Thing, which is then instantiated in the game world. Terrain, on the other hand, is only ever a TerrainDef. It's never instantiated, presumably for performance reasons. Making this approach functional would require quite a bit of C# work since you'd have to rewrite the Terrain system to do what you want it to do.

If you are open to C#, then creating a "tracker" Map Component could accomplish this. Your tracker would have to track each piece of your custom terrain created, then add or remove heat as necessary each tick. Map Components can actually tick, unlike Terrains, so this would probably be the easiest way to do this.

LWM

Another approach would be to create an invisible, unselectable ThingWithComps that gets created when your terrain gets created....but the MapComponent sounds probably more reasonable.