[1.0] [WIP] Replimat - Distributed food replicator system

Started by sumghai, August 16, 2017, 05:39:21 AM

Previous topic - Next topic

sumghai

A small mod I started working on last weekend, which would add Star Trek-like food replicators to very late stage Spacer/Glitterworld colonies.

Download Playable WIP
Source on GitHub repository
Issue and Ideas tracker

Overview

The mod consists of four buildings and one item:

  • Replimat Terminal - Essentially an advanced version of the stock Nutrient Paste Dispenser that instead produces Fine Meals
  • Replimat Feedstock Tank - Holds organic feedstock for terminals; requires a hopper for raw food
  • Replimat Computer - (Optional) building that holds more advanced meal recipes
  • Replimat Conduit - Omnidirectional plumbling that transports feedstock from tanks to terminals
  • Isolinear Computing Module - High density data storage and processing device preprogrammed with a wide range of meal recipes, used to build Replicator computers; available from exotic goods traders

How the mod is intended to work:

  • Players start by researching Molecular Nutrient Resequencing, which unlocks the terminal, tank and conduit
  • Any number of terminals can be connected to any number of tanks via a network of conduits, and will always produce Fine Meals
  • Researching Advanced Molecular Nutrient Resequencing unlocks the Replimat Computer
  • Connecting the computer to any part of a Replimat network will allow the terminals to produce Lavish Meals
  • In addition, if other mods such as dismar's Vegetable Garden are also installed, the Computer could instead tell the terminals to generate a random food item from said mod

Progress so far

All the assets and in-game definitions for the buildings and items are pretty much finalized, other than minor tweaks such as shadows and damage decals. The conduit is already linkable.



I've also started laying the groundwork for the assembly that will power the mod; however, object-oriented programming has always been one of my weaknesses (my coding experience is geared towards microcontrollers), so I suspect I will be asking for lots of help in addition to deciphering the C# tutorials on the Rimworld wiki.

Remaining Tasks

  • Show existing and new conduit blueprints when the build conduit tool is selected
  • Make the conduit capable of transporting feedstock
  • Make the feedstock tank capable of storing feedstock
  • Make the feedstock tank take raw food from an adjacent hopper and converting it into feedstock
  • Make the terminals produce Fine Meals
  • Make the terminals drain X amount of feedstock when producing meals
  • Compatibility/integration with other food mods (may have to choose a subset of food items, will attempt to collaborate with the respective mod authors)

I'll do my best to keep everyone appraised of my progress and questions. In the meantime, questions, comments and advice are appreciated.

sumghai

Progress Report, 20 August 2017

Hadn't had much luck adapting dubwise56's pipe code from Dub's Bad Hygiene for use in my assembly with what little I know about object-oriented programming. His code was written for A17, but for some reason I'm getting large numbers of invalid method/class references even when duplicating his codebase in its entirety.

I've since corresponded with dubwise, and he is of the opinion that custom conduits are very difficult to code for. He did suggest to try running purely off the existing powernet, although I'm a bit uncomfortable with the idea that solid matter from the replimat feedstock tanks can someone get converted into pure energy and transmitted through power lines.

Then there's the problem that without custom replimat conduits, I wouldn't be able to make isolated replimat networks serving different food items for colonists and prisoners. A possible workaround (and feature enhancement) would be to add a Storage-like menu to each replimat terminal only when the replimat computer is connected to the same powernet, allowing each terminal to be customised to produce selected food items randomly, all while running off the same feedstock tanks. If the computer is destroyed, then the terminals go back to only making Simple/Fine Meals.

Thoughts, guys?

faltonico

There was an episode of the Start Trek: Enterprise in which a space station was using live humanoids as their computing cores to do really fast replication... i would love to find more uses for the pirates daring to hurt my colonist >=D

Regarding the issue with the conduits, i know as well because of him how hard it is to code, i think you could select the output from wherever you get the product, is there a need to make it so each tank or network gives different stuff? sorry i might not be getting the point here xD

alsoandanswer

Project seems solid, i'm gonna keep an eye on this.

good luck mister modder


"If I quote some smart guy, then therefore I should be smart myself!" -alsoandanswer

sumghai

Quote from: faltonico on August 20, 2017, 03:25:12 AMRegarding the issue with the conduits, i know as well because of him how hard it is to code, i think you could select the output from wherever you get the product, is there a need to make it so each tank or network gives different stuff? sorry i might not be getting the point here xD

I don't understand what you're trying to say here.

Progress Report, 22 August 2017

At Dubwise's advice, I've decided to abandon custom conduits, and instead pretend that the existing stock powernet also comes with a "hidden" organic matter pipeline. This will save some development time.

I've created a rudimentary Building_ReplimatTerminal class, which is essentially a copy (but not a subclass) of the stock Building_NutrientPasteDispenser with any code related to checking for adjacent hoppers removed; it was not possible to simply make it a subclass because Tynan has hardcoded the game to only look for the original Nutrient Dispenser class as part of its list of meal sources, so all custom subclasses will get ignored.

Anyway, for testing purposes I've made it so that the Replimat Terminal would (in theory) dispense free Fine Meals:


using Verse;
using Verse.Sound;
using RimWorld;

namespace Replimat
{
    public class Building_ReplimatTerminal : Building
    {
        public CompPowerTrader powerComp;

        public static int CollectDuration = 50;

        public bool CanDispenseNow
        {
            get
            {
                return this.powerComp.PowerOn; // TODO - Add condition to check if there is enough replicator feedstock
            }
        }

        public virtual ThingDef DispensableDef
        {
            get
            {
                return ThingDefOf.MealFine;
            }
        }

        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            this.powerComp = base.GetComp<CompPowerTrader>();
        }

        public virtual Thing TryDispenseFood()
        {
            if (!this.CanDispenseNow)
            {
                return null;
            }
           
            this.def.building.soundDispense.PlayOneShot(new TargetInfo(base.Position, base.Map, false));
            Thing thing2 = ThingMaker.MakeThing(ThingDefOf.MealFine, null);
            return thing2;
        }
    }
}


When I loaded this into the game, the Replimat Terminals were recognized as a meal source, but no pawn ever bothered using them (as expected above). Tracing backwards from the stock Nutrient Dispenser's TryDispenseFood() method, we see that it is called by a Toil called TakeMealFromDispenser(), which in turn is called by three different eating-related Job Drivers:


  • JobDriver_FoodDeliver - presumably delivering food to prisoners
  • JobDriver_FoodFeedPatient  - self-explanatory
  • JobDriver_Ingest - pawn feeding itself

Each of these JobDrivers again have explicit instructions to search for food from a pawn's own inventory, colony stockpiles and Nutrient Dispensers - anything any potential source will be ignored.

Dubwise and I are currently considering two ways to get the pawns to start treating ReplimatTerminals as a food source:

  • Use Harmony to insert additional references to ReplimatTerminal - this is the more difficult approach, but will allow us to use existing JobDrivers
  • Write a new set of JobDrivers specifically to have Pawns try getting food from ReplimatTerminals first before falling back on the original JobDrivers - possibly easier than using Harmony, but may result in lots of redundant code

As always, thoughts and feedback are appreciated.

Mitz

It's sad autism's an insult, then i must be an insult.
and my cat also must be an insult, as well as every other cat in the universe.
space cats.

sumghai

Progress Report, 24 August 2017

Something I forgot to mention in my last report was that, at Dubwise's suggestion, I've moved the Replimat Computer down to the same research project as the other Replimat buildings, and removing the now-empty advanced research project - the intention is to prevent the Terminals from working without the Computer. Consequently, this means that the Terminals should be able to produce all food items from the get-go, so I will need to create some sort of ITab GUI to allow players to pick and choose what food items each Terminal can offer at random (as well as having Copy and Paste Setting options for the sake of convenience).

Coming back to the plugin coding, I've decided to create my own copies of the stock eating JobDrivers and Toils, replacing references to Nutrient Dispensers with Replimat Terminals:

  • Toils_Ingest -> Toils_IngestReplimat
  • JobDriver_FoodDeliver -> JobDriver_FoodDeliverReplimat
  • JobDriver_FoodFeedPatient -> JobDriver_FoodFeedPatientReplimat
  • JobDriver_Ingest -> JobDriver_IngestReplimat

I haven't yet been able to actually defInject these new JobDrivers and Toils into the game, because I've encountered several "c_Iterator N not existing in current context" errors. As such, I would appreciate if someone could take a look at my source code here to see what I've missed.

sumghai

Progress Report, 26 August 2017

Turns out I dun goofed - I was running an old version of ILSpy used for Kerbal Space Program modding, instead of the recommended version that Zhentar maintains. Once this was sorted out, the code I extracted for the JobDrivers and Toils made more sense.

As always, Dubwise performed his wizardry, adding a new JobGiver_GetFoodReplimat and patching it into the think tree. Most importantly, a new utility class now puts Replimat Terminals above Nutrient Paste Dispensers in terms of priority.

At the present time, colonists will get Fine Meals from the Terminals for free; this will fixed later by requiring a connection to Replimat Feedstock Tanks.

Have a play around with the first cut of the plugin and tell us what you guys think!

sumghai

Progress Report, 28 August 2017

As a homage to characters in Star Trek who claim to be able to tell the difference between replicated and non-replicated food, colonists with a new "Sensitive Taster" trait will now complain every time they eat a meal from the Replimat Terminal:



The same colonists will eat a meal cooked normally without the negative thought.

Techgenius

Hello Sumghai. How playable is your mod currently? can I enable it in a normal playthrough and perhaps get a genuine substitute to the nutrient dispenser?

sumghai

Quote from: Techgenius on August 28, 2017, 04:56:59 PMHow playable is your mod currently? can I enable it in a normal playthrough and perhaps get a genuine substitute to the nutrient dispenser?

As mentioned in my earlier posts, the mod in it current state can already be used in a normal savegame to feed your colonists. At the moment they're getting their food for free, but this will be rectified in the final version.

The Replimat Terminals can be used on the same map as any cooking stove or Nutrient Paste Dispensers, so you could have colonists get Fine Meals from the Terminals, while your prisoners can only eat nutrient paste.

sumghai

Progress Report, 2 September 2017

Starting work on the next major feature - allowing players to choose what meal items are available from the Replimat Terminals.

At the moment, I have a blank inspector tab with some placeholder text, while the Terminals themselves now randomly picks an item to replicate from a list of all meals in the game's database. The final implementation would most likely involve:
- The inspector tab presenting a storage tab-like list of all the meals available in-game with the corresponding checkboxes
- Building_ReplimatTerminal receives a sublist of the player's choices
- Building_ReplimatTerminal picks a random item from the aforementioned sublist to replicate

I also pushed through a few bugfixes:
- Doctors can now feed patients with food from any Terminal
- Wardens can use the Terminal to feed incapacitated or leave food for healthy prisoners
- Prisoners can use the Terminals themselves to get food

A few smaller bugs have cropped up:
- When a colonist or prisoner uses the Terminal, the text in the inspector pane flickers rapidly through the various food choices, most likely due to the UI being redrawn constantly
- The WorkGiver for Wardens delivering food to prisoners occasionally throws up an error indicating that the warden has not been assigned a job, even though said warden successfully delivers food and moves on to the next job
- The Wardens also try to deliver food to the prisoners even when the latter have access to their own Terminal

sumghai

Progress Report, 8 September 2017

I haven't made much progress on the food selection menu inspector tab, nor was I able to fix the aforementioned bugs.

I did, however, add a couple of new incidents where any available Replimat Terminal could malfunction, either spilling nutrient feedstock slime or replicating large amounts of Kibble (a la ST:TNG episode "A Fistful of Datas"):



I originally planned to implement a Replimat-specific food poisoning incident as well, but I've put that idea on the backburner for now due to the complexity of hooking up the food poisoning hediff with a custom message and job drivers.

I'm wondering if I should switch track and look at getting the tanks and hoppers working instead.

Mitz

oh boy - now it is as dangerous as a idiot chef pawn...
It's sad autism's an insult, then i must be an insult.
and my cat also must be an insult, as well as every other cat in the universe.
space cats.

tiger33116

I'm keeping my eye on this it looks awesome. I would suggest two things. One get the basic components done first so hoppers to get feed stock, the tank to store it, and conduits to move it to the terminals. From there it's a base to really add events for using it. Luciferium laced food anyone? The second thing I would suggest is some type of scanner that allows the terminals to put specific meals out when used. This also could be expanded to get basic recourses or certain items at a very high feed stock cost or using a different type of feed stock. That could also have very interest events tied to it as well.