Adding an new event

Started by Frejoh466, September 21, 2018, 12:31:20 PM

Previous topic - Next topic

Frejoh466

So I don't like how the temperature is never a challenge, and no one wanted to spend time making a mod. So I'm now trying to make it my self.

So what I want is an event that adds or remove 50C from the temperature (like an coldsnap/heatwave that last longer). But all the tutorials I find are about adding items and not events. So this is what I have,

Climate change\Defs\GameConditionDefs\GameConditions_Misc.xml
<?xml version="1.0" encoding="utf-8" ?>
<Defs>
<GameConditionDef>
    <defName>ClimateChange</defName>
    <conditionClass>GameCondition_ClimateChange</conditionClass>
    <label>Climate Change</label>
    <canBePermanent>true</canBePermanent>
    <description>An extreme temperature change is happening.</description>
    <endMessage>Themperature back to normal.</endMessage>
    <exclusiveConditions>
      <li>HeatWave</li>
      <li>ColdSnap</li>
      <li>VolcanicWinter</li>
    </exclusiveConditions>
  </GameConditionDef>
</Defs>

I belive this is right, as ThingDefs is for items.

But then the Assemblies...

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

using RimWorld;
using Verse;

namespace ClimateChange : GameConditionDefs
{
    /// <summary>
    /// This is the main class for the Climate Change event.
    /// </summary>
    /// <author>Frejoh466</author>
    /// <permission>Usage of this code is ...</permission>
    ///
    public class GameCondition_ClimateChange
    {
        // Work variable
        private int counter = 0;                  // 60Ticks = 1s // 20000Ticks = 1 Day
        private Phase phase = Phase.offline;      // Actual phase
        private Phase phaseOld = Phase.active;    // Save-variable
    }
}


And I'm sure it is wrong, but if I could see how coldsnap/heatwave works I probably would be able to solve it, as this mod is just a more extreme version, eg. Longer and bigger temperature.

So I really haven't gotten anywhere, but if I could see how ludion did the events or a tutorial on how to add an event. Anyone know and example or tutorial for adding events?

Bobisme

I'm no good when it comes to modding, barely know a thing, though, as heat waves and cold snaps are already in the game isn't it possible to go into the preexisting code and increase durations and or temperatures? :)

Frejoh466

#2
Quote from: Bobisme on September 21, 2018, 12:40:41 PM
I'm no good when it comes to modding, barely know a thing, though, as heat waves and cold snaps are already in the game isn't it possible to go into the preexisting code and increase durations and or temperatures? :)

My first thought was to copy it and just change the values. But it seems like we can see anything but the .xml files, and those are just a small part of it.

Edit:
More reading and I found Assembly-CSharp.dll had all the game stuff in it, also the tutorial did mention this, but I had no clue what he said. So I will read the tutorial 10 more times again and see if I can understand how I should convert the thingdefs, so I can "connect" the .xml and C# code.

But this looks ok. And as easy as I thought the mod would be. But Right now I just get a blackscreen and have to kill the game in task manager.

namespace ClimateChange{
    public class GameCondition_ClimateChange : GameCondition{
        private const int LerpTicks = 12000;
        private const float MaxTempOffset = -50f;
        public override float TemperatureOffset(){
            return GameConditionUtility.LerpInOutValue(this, 12000f, -50f);
        }
    }
}


So the wall hitting continues.

jamaicancastle

The link between XML and C# is in this line right here:

<conditionClass>GameCondition_ClimateChange</conditionClass>

What this does is looks in the namespace "RimWorld" (or Verse) for a class "GameCondition_ClimateChange" that tells it how that particular condition works. However, your code is not in the namespace "RimWorld", it's in a namespace unique to your mod (which in this case appears to be "ClimateChange".) You need to signal this by putting the namespace first, then a period, then the class name, like so:

<conditionClass>ClimateChange.GameCondition_ClimateChange</conditionClass>

With that said, this shouldn't be a blackscreen issue from what I'm aware of. Make sure you're following the tutorial's instruction precisely when it comes to compiling and organizing your files. What should end up in the Assemblies folder is not the .csproj or source files, but a compiled .dll file with a name of your choosing. (It really doesn't matter what the name is.)

Finally, the reason the class looks so sparse in the C# code is because most of it is inherited. This line:

public class GameCondition_ClimateChange : GameCondition

means, essentially, "create a new class called GameCondition_ClimateChange, take everything from the class GameCondition, and stick it in that new class". Then you selectively overwrite a few details to create the specific effect you want. If Visual Studio's dependencies are set up correctly, the "using" directives at the top of the file (like "using RimWorld;") will allow it to automatically find GameCondition in the base game code.

Frejoh466

#4
The blackscreen was an Rimworld error, had to re-install the game. But I did manage to find the "<conditionClass>ClimateChange.GameCondition_ClimateChange</conditionClass>" and I have managed to build it and load the mod.

The problem now is debugging and see if it actually do something. I don't know how to spawn the event, it doesn't show up in the debugging menu, so either the mod doesn't exist in the game, or I need to add the event to the dubugg menu.

It says the mod is loaded in the game, but if it actually has the event it can load or not I don't know.

Edit:
Still not able to trigger the event, not sure why. If the incident exist it should add it to the list (as I found no indication that I should manually add it). The mod is also now just a copy of the cold snap.

Also removed the end "s" from <GameConditionDef>

EDIT2:
Think I found something with "IncidentWorker" And I managed to load the event now, so now I just need to change the settings and see if it works. So should be fine now.

EDIT3:
It's not fine. The game run the event code all the time (every tick?), so now the temperature changes from cold to hot all the time.

So if the game runs the code all the time I need to create, two different parts, one for hot weather and one for cold. Unless I find a way to create a variable that doesn't change every tick. So I need to find a way to fix that.

EDIT4:
I just copy pasted and called one cold and one hot, should be fine.