Beispiel #1
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            if (RefuelComps != null)
            {
                base.SpawnSetup(map, respawningAfterLoad);
                return;
            }

            tempComps.Clear();

            foreach (var comp in base.AllComps)
            {
                if (comp is CompRefuelableMulti s)
                {
                    tempComps.Add(s);
                }
            }

            RefuelComps = new CompRefuelableMulti[tempComps.Count];
            for (int i = 0; i < RefuelComps.Length; i++)
            {
                RefuelComps[i] = tempComps[i];
                if (RefuelComps[i].Id == 0)
                {
                    Log.Error($"A CompRefuelableSpecial on this {LabelCap} has default 'id' value of 0. Please change it to a unique ID.");
                }
            }

            tempComps.Clear();

            //Log.Message($"RefuelComps: {RefuelComps.Length}");
            if (RefuelComps == null || RefuelComps.Length == 0)
            {
                Log.Error($"Missing refuel comps on this {this.LabelCap}.");
                MissingComps = true;
            }

            base.SpawnSetup(map, respawningAfterLoad);
        }
Beispiel #2
0
        public override void Tick()
        {
            base.Tick();

            tick++;

            // Re-shuffle the components to trick rimworld into accepting multiple refuelable comps.
            bool shouldShuffle = ShuffleInterval <= 0 || tick % ShuffleInterval == 0;

            if (!shouldShuffle)
            {
                return;
            }
            if (RefuelComps == null)
            {
                return;
            }

            CompRefuelableMulti toPutFirst = null;
            float lowest = float.MaxValue;

            foreach (var s in RefuelComps)
            {
                float priority = GetFuelPriority(s);

                if (priority >= lowest)
                {
                    continue;
                }

                if (MeetsRefuelCondition(s))
                {
                    lowest     = priority;
                    toPutFirst = s;
                }
            }

            if (toPutFirst == null)
            {
                return;
            }

            int targetPos = 0;

            for (int i = 0; i < AllComps.Count; i++)
            {
                var c = AllComps[i];

                if (c == toPutFirst)
                {
                    return; // It is already in first place.
                }
                if (c is CompRefuelableConditional)
                {
                    // Needs to go before other refuel comps.
                    targetPos = i;
                    break;
                }
            }

            base.AllComps.Remove(toPutFirst);
            base.AllComps.Insert(targetPos, toPutFirst); // This makes rimworld treat this as 'THE' refuelable comp, even though there are others.
        }
Beispiel #3
0
 public virtual float GetFuelPriority(CompRefuelableMulti s)
 {
     return(s.FuelPriority);
 }
Beispiel #4
0
 public virtual bool MeetsRefuelCondition(CompRefuelableMulti s)
 {
     return(s.FuelPercentOfMax < 0.99999f);
 }