Refuelable object not consuming fuel

Started by Manofdusk, July 20, 2018, 01:39:59 AM

Previous topic - Next topic

Manofdusk

 I've been working on a different mod today and got it (mostly) running. It's a type of soil that needs to be "refueled" with compost (I had to categorize it as a production building because you can't refuel a terrain type  :'( )

The problem is that I can't get it to actually consume the fuel.


<ThingDef ParentName="BuildingBase">
<defName>CompostEnrichment</defName>

<label>compost enrichment</label>

<description>Soil enriched by compost. Must be replenished.</description>

<thingClass>Building_PlantGrower</thingClass>


<graphicData>

<texPath>Things/Building/Production/SoilRichCompost</texPath>

<graphicClass>Graphic_Single</graphicClass>

<drawSize>(1,1)</drawSize>



</graphicData>

<altitudeLayer>FloorEmplacement</altitudeLayer>

<passability>Standable</passability>

<pathCost>2</pathCost>

<constructEffect>ConstructDirt</constructEffect>



<statBases>

<WorkToBuild>70</WorkToBuild>

<Cleanliness>-2</Cleanliness>

</statBases>

<size>(1,1)</size>


<costList>

<Compost>5</Compost>

</costList>

<fertility>2</fertility>


<building>

<defaultPlantToGrow>PlantPotato</defaultPlantToGrow>

<sowTag>Ground</sowTag>

</building>

<tickerType>Rare</tickerType>


<comps>


<li Class="CompProperties_Refuelable">

<fuelConsumptionRate>0.10</fuelConsumptionRate>

<fuelCapacity>5.0</fuelCapacity>


<fuelFilter>


<thingDefs>

<li>Compost</li>

</thingDefs>

</fuelFilter>

<destroyOnNoFuel>true</destroyOnNoFuel>

</li>



</comps>


<terrainAffordanceNeeded>Heavy</terrainAffordanceNeeded>

<designationCategory>Production</designationCategory>

</ThingDef>


any ideas on how to get it to consume fuel?

Mehni


Knight

Have you made your own C# class? In your .XML it says that your thingClass is Building_PlantGrower.cs so I'm assuming you have...In this C# class you'll need to do a few things:

Directly inside of the class you'll need to define
private CompRefuelable refuelComp = null; refuelComp can be any variable name of your choice.

Next you'll need to edit/create a SpawnSetup override with the following:
public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            refuelComp = base.GetComp<CompRefuelable>(); // This is the part you need to take note of
        }


Finally, in your Tick() override and after any other code you've got, you'll need to add:
refuelComp.ConsumeFuel(Float [Amount]);

For example, if you'd like the building to consume 1 fuel every Tick then that'd become:
refuelComp.ConsumeFuel(1f);

Hope this helps. If you've not made your own C# class then I don't know and ignore everything I just said haha.

Manofdusk

 Nope, I'm not advanced enough to figure out how to make C# classes yet. The PlantGrower class is from the Hydroponics basin (I basically fused Hydroponics with the Campfire :P)

However, I'd very much like to learn how to do my own C# classes :P