Files
RickGrymes 0eed170531 Overhaul robotics with hediff loadouts
Refactors robot customization from apparel/equipment to hediff-driven body part overlays, adds a reusable upgrade dialog, and expands DefOf support for Protectron, Securitron, Mr. Handy, and Sentry Bot variants. Introduces manual power toggling, robot bed assignment/power-down behavior, new control modes (including Securitron guard point and Mr. Handy role-based work modes), and AI checks that respect fuel/power state and pending upgrade bench calls. Also adds new radiant quest nodes, improves settlement tile fallback logic, updates several workbench sizes/textures, and adds additional trader backstories.
2026-07-19 00:57:55 -05:00

69 lines
1.9 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using RimWorld;
using Verse;
namespace FCP.Core.Robotics
{
public class RobotTierExtension : DefModExtension
{
public ResearchProjectDef researchPrerequisite;
public List<ThingDefCountClass> upgradeCost = new List<ThingDefCountClass>();
}
public class RobotUpgradeOption
{
public string category;
public string label;
public List<ThingDefCountClass> cost = new List<ThingDefCountClass>();
public string disabledReason;
public Action install;
public bool Enabled => disabledReason == null;
}
public static class RobotUpgradeUtility
{
public static bool CanAffordCost(Map map, List<ThingDefCountClass> cost)
{
foreach (ThingDefCountClass entry in cost)
{
if (map.resourceCounter.GetCount(entry.thingDef) < entry.count)
{
return false;
}
}
return true;
}
public static bool TryConsumeCost(Map map, List<ThingDefCountClass> cost)
{
if (!CanAffordCost(map, cost))
{
return false;
}
foreach (ThingDefCountClass entry in cost)
{
int remaining = entry.count;
foreach (Thing thing in map.listerThings.ThingsOfDef(entry.thingDef).ToList())
{
if (remaining <= 0)
{
break;
}
if (!thing.Spawned)
{
continue;
}
int consume = Math.Min(remaining, thing.stackCount);
thing.SplitOff(consume).Destroy();
remaining -= consume;
}
}
return true;
}
}
}