Chicken and egg mod

Started by Bloodquist, May 19, 2014, 07:16:54 AM

Previous topic - Next topic

Bloodquist

Hello everyone

I'm training a bit my modding skills so i ran across this forum. (English is NOT my native language. Please consider that when reading)

I wanted to do something easy to start (and mb give it later to the wiki) :

1) Create a new pawn : Chicken in herd (done)

2) Create a new Resource : Egg (done)

3) Have these egg be eatable but give AteRawFood tought (done)

4) Add bill to cookStove to make a meal (done)

5) Lay eggs

6) Allow Chicken Pasture

7) Make them reproduce

Well it's a good start isnt it ?

So basically for now, i have some herds of chicken spawning, egg used as resource (god mode). I searched across the forums how to add eggs as food. They're now treaten as rawResources
<storeCategories>
        <li>ResourcesRaw</li>
</storeCategories>


So 1st question : what's the tag for sorting my eggs into Store -> Foods -> raw -> vegetarian ?

i tried
FoodRawVegetarian
RawFoodVegetarian
RawVegetarianFood
VegetarianRawFood

EDIT : it is PlantFoodRaw :)
none of these seems to work x/

For the AteRawFood thought i did :

<eatenDirectThought>AteRawFood</eatenDirectThought>

I got an xml Warning since it doesnt exist (anymore ?) I stole this tag from another mod :s.


At least i didnt find how i'm supposed to add a bill to the cook stove. I guess when my eggs would be considered as a food source (a meal source) they should be taken by my Chef to cook some meal. But i tried to create my own "EggStove" which can cook Egg into an omelette.

It works indeed but that doesnt sound really logic. Can someone confirm the previous fact. (if egg is a raw food source, they'll be taken into the actual cookStove ?

EDIT well since i resolve my first problem i can confirme that my eggs are perfectly cooked !

Thanks for any help :)

it sill remains the AteRawFood thought, any help ?

For the breeding i dove into the Muffalo Breeding mode so i shouldn't need tons of help (i hope anyway).

Joretap0

#1
Look at "RimWorld\Mods\Core\Defs\ThingDefs\meal.xml" for all meal description,  and "Resources.xml" for raw foods, you'll find a lot of answer here.

For cooking stove recipe, you must override the "CookStove" that you'll find in "RimWorld\Mods\Core\Defs\ThingDefs\building_furniture.xml". Just copy it to your mod and add you're recipes, but it will be incompatible with other mods overriding the cook stove.

For food effect, i recommand you to add new thought, look here : "RimWorld\Mods\Core\Defs\ThoughtDefs"

For laying eggs, breeding, and other non existent function in vanilla game, it's really harder, cause you'll need to create your own class in C#.
My Mods : Dresser | Inventory Panel | Cannibal
Sorry for my english ;)

Bloodquist

Wow thanks a lot ! I found out many helpful things indeed !

For the cookstove i edited my post and it does work already after figuring out the "PlantRawFood" for my egg Resources.

Yes i know that i need to do my own class and make a .dll :) C# is not the problem. My lack of knowledge of already existent class is :)

Bloodquist

#3
Hi guys.

I struggling for something which looks like easy.

I have a ThinkTreeDef for my chickens name ChickenHerd (see code below). It is inspired from HerbivoreHerd (used for muffalo in Core). I added 2 new jobs : Breeding and Egging. (dunno if the word "egging" exists, but you get the idea).


<?xml version="1.0" encoding="utf-8" ?>
<ThinkTrees>
  <ThinkTreeDef>
    <defName>ChickenHerd</defName>
    <thinkRoot Class="AI.ThinkNode_Priority">
      <subNodes>
        <li Class="AI.ThinkNode_Subtree">
          <treeDef>BurningResponse</treeDef>
        </li>
        <li Class="AI.ThinkNode_Subtree">
          <treeDef>Psychotic</treeDef>
        </li>
        <li Class="AI.ThinkNode_Subtree">
          <treeDef>SelfDefense</treeDef>
        </li>
<!-- <li Class="AI.JobGiver_Birth, ChickenBreeding"/> -->
<li Class="AI.JobGiver_Egging, ChickenBreeding"/>
        <li Class="AI.ThinkNode_SatisfyNeeds"/>
        <li Class="AI.JobGiver_Breeding, ChickenBreeding"/>
        <li Class="AI.JobGiver_WanderHerd"/>
        <li Class="AI.JobGiver_IdleError"/>
      </subNodes>
    </thinkRoot>
  </ThinkTreeDef>
</ThinkTrees>

And here is my ThingDef for my chicken.


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

<ThingDef Name="BasePawn" Abstract="True">
<eType>Pawn</eType>
<thingClass>Pawn</thingClass>
<category>Pawn</category>
<selectable>true</selectable>
<tickerType>Normal</tickerType>
<altitudeLayer>Pawn</altitudeLayer>
<useStandardHealth>false</useStandardHealth>
<flammability>1.0</flammability>
<hasTooltip>true</hasTooltip>
<bulletImpactSound>BulletImpactFlesh</bulletImpactSound>
<inspectorTabs>
<li>UI.ITab_Pawn_Thoughts</li>
<li>UI.ITab_Pawn_Needs</li>
<li>UI.ITab_Pawn_Prisoner</li>
<li>UI.ITab_Pawn_Character</li>
</inspectorTabs>
<drawGUIOverlay>true</drawGUIOverlay>
</ThingDef>



<!-- ============================ Animals ========================== -->


<ThingDef ParentName="BasePawn" Name="BaseAnimal" Abstract="True">
<race>
<hasStory>false</hasStory>
<needsRest>false</needsRest>
<minFoodQuality>Plant</minFoodQuality>
<isFlesh>true</isFlesh>
<hasGenders>true</hasGenders>
</race>
</ThingDef>


<ThingDef ParentName="BaseAnimal">
<defName>Chicken</defName>
<label>Chicken</label>
<maxHealth>35</maxHealth>
<overdraw>false</overdraw>
<targetHitChanceFactor>0.8</targetHitChanceFactor>
<race>
<thinkTree>ChickenHerd</thinkTree>
<walkSpeed>0.8</walkSpeed>
<meleeDamage>6</meleeDamage>
<hungerThreshold>80</hungerThreshold>
<bodySize>0.3</bodySize>
</race>
</ThingDef>

</ThingDefs>


The problem is that these chicken dont move nor do nothing at all, in fact. In the inspector they have no <curJob>. Well they have one but set to null.

Ok i found that's coming from my C# class below :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;

namespace AI
{
    public class JobGiver_Egging : ThinkNode_JobGiver
    {
        protected override Job TryGiveTerminalJob(Pawn pawn)
        {
            var chicken = pawn as Chicken;

            Debug.LogError(pawn.ToString());

            if (chicken == null)
                return null;

            if (chicken.Pregnancy == null || !chicken.Pregnancy.IsDue)
                return null;
            return new Job(DefDatabase<JobDef>.GetNamed("Egging"));
        }
    }
}


The cast var chicken = pawn as Chicken returns null, because it's not doable. So ok.
A sample of my output_log

Chicken_Chicken21963

(Filename: C:/BuildAgent/work/d3d49558e4d408f4/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 53)

Chicken_Chicken21964

(Filename: C:/BuildAgent/work/d3d49558e4d408f4/artifacts/StandalonePlayerGenerated/UnityEngineDebug.cpp Line: 53)


There is my Chicken.cs


using System;
using System.Linq;
using AI;

public class Chicken : Pawn
{
    //private readonly Breeder breeder;
    public Pregnancy Pregnancy;
    public AgeTicker AgeTicker;

    public Chicken()
    {
        AgeTicker = new AgeTicker(this);
    }

    public Pawn Mother { get; set; }

    public override void Tick()
    {
        base.Tick();

        if (Pregnancy != null)
            Pregnancy.Tick();

        if (AgeTicker != null)
            AgeTicker.Tick();
    }

    public override string GetInspectString()
    {
        return base.GetInspectString()
            + (IsPregnant() ? "Pregnant\r\n" + (Pregnancy.OverDue ? "Over due\r\n" : "") : "");
    }

    public void SetPregnant()
    {
        Pregnancy = new Pregnancy(this);
    }

    public bool IsPregnant()
    {
        return Pregnancy != null;
    }
}


This is where i'm lost for now. How could it not be cast. The class should be found

Thank you all :)