コード例 #1
0
    public static bool BMixFinishedStatus(bool foundAll, Thing billGiver, Bill bill)
    {
        if (!foundAll)
        {
            return(false);
        }

        if (billGiver is Pawn)
        {
            return(true);
        }

        if (!IsValidForComp(billGiver))
        {
            return(true);
        }

        //if (billGiver.TryGetComp<CompBestMix>().CurMode == "DIS")
        var CBM = billGiver.TryGetComp <CompBestMix>();

        if (CBM == null)
        {
            return(false);
        }

        if (BMBillUtility.UseBMixMode(CBM, billGiver, bill) == "DIS")
        {
            return(true);
        }

        return(false);
    }
コード例 #2
0
    // Debug
    internal static void BMixDebugList(List <Thing> list, Thing billGiver, IntVec3 rootCell, Bill bill)
    {
#if !DEBUG
        if (!Prefs.DevMode || !Controller.Settings.DebugMaster || !Controller.Settings.DebugSort)
        {
            return;
        }
#endif
        if (!IsValidForComp(billGiver))
        {
            return;
        }

        var compBMix = billGiver.TryGetComp <CompBestMix>();
        if (compBMix == null)
        {
            return;
        }

        if (!compBMix.BMixDebug)
        {
            return;
        }

        if (list.Count <= 0)
        {
            return;
        }

        for (var i = 0; i < list.Count; i++)
        {
            var thing    = list[i];
            var debugMsg = MakeDebugString(i, thing, billGiver, rootCell, bill,
                                           BMBillUtility.UseBMixMode(compBMix, billGiver, bill));
            Log.Message(debugMsg);
        }
    }
コード例 #3
0
    public static Comparison <Thing> GetBMixComparer(Thing billGiver, IntVec3 rootCell, Bill bill, out bool rnd)
    {
        rnd = false;
        var BMixMode = "DIS";

        if (IsValidForComp(billGiver))
        {
            var compBM = billGiver.TryGetComp <CompBestMix>();
            if (compBM != null)
            {
                //BMixMode = compBM.CurMode;
                BMixMode = BMBillUtility.UseBMixMode(compBM, billGiver, bill);
            }
        }

        Comparison <Thing> comparison;

        switch (BMixMode)
        {
        case "DIS":
            comparison = delegate(Thing t1, Thing t2)
            {
                float num   = (t1.Position - rootCell).LengthHorizontalSquared;
                float value = (t2.Position - rootCell).LengthHorizontalSquared;
                return(num.CompareTo(value));
            };
            break;

        case "DTR":
            comparison = delegate(Thing t1, Thing t2)
            {
                float maxdtr = 72000000;
                var   t1dtr  = maxdtr;
                var   t1comp = t1.TryGetComp <CompRottable>();
                if (t1comp != null)
                {
                    t1dtr = t1comp.TicksUntilRotAtCurrentTemp;
                }

                var t2dtr  = maxdtr;
                var t2comp = t2.TryGetComp <CompRottable>();
                if (t2comp != null)
                {
                    t2dtr = t2comp.TicksUntilRotAtCurrentTemp;
                }

                var num   = t1dtr;
                var value = t2dtr;
                return(num.CompareTo(value));
            };
            break;

        case "HPT":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num = 0f;
                if (t2.def.useHitPoints)
                {
                    num = (t2.MaxHitPoints - t2.HitPoints) / (float)Math.Max(1, t2.MaxHitPoints);
                }

                var value = 0f;
                if (t1.def.useHitPoints)
                {
                    value = (t1.MaxHitPoints - t1.HitPoints) / (float)Math.Max(1, t1.MaxHitPoints);
                }

                return(num.CompareTo(value));
            };
            break;

        case "RHP":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num = 0f;
                if (t2.def.useHitPoints)
                {
                    num = t2.HitPoints / (float)Math.Max(1, t2.MaxHitPoints);
                }

                var value = 0f;
                if (t1.def.useHitPoints)
                {
                    value = t1.HitPoints / (float)Math.Max(1, t1.MaxHitPoints);
                }

                return(num.CompareTo(value));
            };
            break;

        case "VLC":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = 0f - t2.MarketValue;
                var value = 0f - t1.MarketValue;
                return(num.CompareTo(value));
            };
            break;

        case "VLE":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = t2.MarketValue;
                var value = t1.MarketValue;
                return(num.CompareTo(value));
            };
            break;

        case "TMP":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = t2.AmbientTemperature;
                var value = t1.AmbientTemperature;
                return(num.CompareTo(value));
            };
            break;

        case "FRZ":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = 0f - t2.AmbientTemperature;
                var value = 0f - t1.AmbientTemperature;
                return(num.CompareTo(value));
            };
            break;

        case "BIT":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = t2.def.stackLimit / (float)Math.Max(1, t2.stackCount);
                var value = t1.def.stackLimit / (float)Math.Max(1, t1.stackCount);
                return(num.CompareTo(value));
            };
            break;

        case "MST":
            comparison = delegate(Thing t1, Thing t2)
            {
                var thing2Amount = GetStockAmount(t2, billGiver, bill);
                var thing1Amount = GetStockAmount(t1, billGiver, bill);
                return(thing2Amount.CompareTo(thing1Amount));
            };
            break;

        case "LST":
            comparison = delegate(Thing t1, Thing t2)
            {
                var thing1Amount = GetStockAmount(t1, billGiver, bill);
                var thing2Amount = GetStockAmount(t2, billGiver, bill);
                return(thing1Amount.CompareTo(thing2Amount));
            };
            break;

        case "RND":
            comparison = delegate
            {
                var num   = RNDFloat();
                var value = RNDFloat();
                return(num.CompareTo(value));
            };
            rnd = true;
            break;

        case "BTY":
            comparison = delegate(Thing t1, Thing t2)
            {
                var thing1Beauty = t1.GetStatValue(StatDefOf.Beauty);
                var thing2Beauty = t2.GetStatValue(StatDefOf.Beauty);

                if (t1.def?.stuffProps?.statFactors != null)
                {
                    if (t1.def.stuffProps.statFactors.StatListContains(StatDefOf.Beauty))
                    {
                        thing1Beauty += t1.def.stuffProps.statFactors.GetStatOffsetFromList(StatDefOf.Beauty);
                    }
                }

                if (t2.def?.stuffProps?.statFactors == null)
                {
                    return(thing2Beauty.CompareTo(thing1Beauty));
                }

                if (t2.def.stuffProps.statFactors.StatListContains(StatDefOf.Beauty))
                {
                    thing2Beauty += t2.def.stuffProps.statFactors.GetStatOffsetFromList(StatDefOf.Beauty);
                }

                return(thing2Beauty.CompareTo(thing1Beauty));
            };
            break;

        case "UGY":
            comparison = delegate(Thing t1, Thing t2)
            {
                var thing2Beauty = t2.GetStatValue(StatDefOf.Beauty);
                if (t2.def?.stuffProps?.statFactors != null)
                {
                    if (t2.def.stuffProps.statFactors.StatListContains(StatDefOf.Beauty))
                    {
                        thing2Beauty += t2.def.stuffProps.statFactors.GetStatOffsetFromList(StatDefOf.Beauty);
                    }
                }

                var thing1Beauty = t1.GetStatValue(StatDefOf.Beauty);
                if (t1.def?.stuffProps?.statFactors == null)
                {
                    return(thing1Beauty.CompareTo(thing2Beauty));
                }

                if (t1.def.stuffProps.statFactors.StatListContains(StatDefOf.Beauty))
                {
                    thing1Beauty += t1.def.stuffProps.statFactors.GetStatOffsetFromList(StatDefOf.Beauty);
                }

                return(thing1Beauty.CompareTo(thing2Beauty));
            };
            break;

        case "HVY":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = t2.GetStatValue(StatDefOf.Mass);
                var value = t1.GetStatValue(StatDefOf.Mass);
                return(num.CompareTo(value));
            };
            break;

        case "LGT":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = 0f - t2.GetStatValue(StatDefOf.Mass);
                var value = 0f - t1.GetStatValue(StatDefOf.Mass);
                return(num.CompareTo(value));
            };
            break;

        case "FLM":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = t2.GetStatValue(StatDefOf.Flammability);
                var value = t1.GetStatValue(StatDefOf.Flammability);
                return(num.CompareTo(value));
            };
            break;

        case "PTB":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = t2.GetStatValue(StatDefOf.StuffPower_Armor_Blunt);
                var value = t1.GetStatValue(StatDefOf.StuffPower_Armor_Blunt);
                return(num.CompareTo(value));
            };
            break;

        case "PTS":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = t2.GetStatValue(StatDefOf.StuffPower_Armor_Sharp);
                var value = t1.GetStatValue(StatDefOf.StuffPower_Armor_Sharp);
                return(num.CompareTo(value));
            };
            break;

        case "PTH":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = t2.GetStatValue(StatDefOf.StuffPower_Armor_Heat);
                var value = t1.GetStatValue(StatDefOf.StuffPower_Armor_Heat);
                return(num.CompareTo(value));
            };
            break;

        case "PTE":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = 0f;
                var value = 0f;
                if (protElectric == null)
                {
                    return(num.CompareTo(value));
                }

                num   = t2.GetStatValue(protElectric);
                value = t1.GetStatValue(protElectric);

                return(num.CompareTo(value));
            };
            break;

        case "INH":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = t2.GetStatValue(StatDefOf.StuffPower_Insulation_Heat);
                var value = t1.GetStatValue(StatDefOf.StuffPower_Insulation_Heat);
                return(num.CompareTo(value));
            };
            break;

        case "INC":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = t2.GetStatValue(StatDefOf.StuffPower_Insulation_Cold);
                var value = t1.GetStatValue(StatDefOf.StuffPower_Insulation_Cold);
                return(num.CompareTo(value));
            };
            break;

        case "SOF":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = 0f;
                var value = 0f;
                if (softness == null)
                {
                    return(num.CompareTo(value));
                }

                num   = t2.GetStatValue(softness);
                value = t1.GetStatValue(softness);

                return(num.CompareTo(value));
            };
            break;

        case "WSP":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = t2.GetStatValue(StatDefOf.SharpDamageMultiplier);
                var value = t1.GetStatValue(StatDefOf.SharpDamageMultiplier);
                return(num.CompareTo(value));
            };
            break;

        case "WBT":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = t2.GetStatValue(StatDefOf.BluntDamageMultiplier);
                var value = t1.GetStatValue(StatDefOf.BluntDamageMultiplier);
                return(num.CompareTo(value));
            };
            break;

        case "NUL":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = 0f - t2.GetStatValue(StatDefOf.Nutrition);
                var value = 0f - t1.GetStatValue(StatDefOf.Nutrition);
                return(num.CompareTo(value));
            };
            break;

        case "NUH":
            comparison = delegate(Thing t1, Thing t2)
            {
                var num   = t2.GetStatValue(StatDefOf.Nutrition);
                var value = t1.GetStatValue(StatDefOf.Nutrition);
                return(num.CompareTo(value));
            };
            break;

        default:
            comparison = delegate(Thing t1, Thing t2)
            {
                float num   = (t1.Position - rootCell).LengthHorizontalSquared;
                float value = (t2.Position - rootCell).LengthHorizontalSquared;
                return(num.CompareTo(value));
            };
            break;
        }

        return(comparison);
    }
コード例 #4
0
    public static bool BMixRegionIsInRange(Region r, Thing billGiver, Bill bill)
    {
        if (!Controller.Settings.IncludeRegionLimiter)
        {
            return(true);
        }

        if (!IsValidForComp(billGiver))
        {
            return(true);
        }

        var compBMix = billGiver.TryGetComp <CompBestMix>();

        if (compBMix != null)
        {
            //if (compBMix.CurMode == "DIS")
            if (BMBillUtility.UseBMixMode(compBMix, billGiver, bill) == "DIS")
            {
                return(true);
            }
        }
        else
        {
            return(true);
        }

        /*
         * List<IntVec3> cells = r?.Cells.ToList<IntVec3>();
         * if ((cells != null) && (cells.Count > 0))
         * {
         *  foreach (IntVec3 cell in cells)
         *  {
         *      if (((float)((cell - billGiver.Position).LengthHorizontalSquared)) < ((float)(bill.ingredientSearchRadius * bill.ingredientSearchRadius)))
         *      {
         *          return true;
         *      }
         *  }
         * }
         */

        // optimised to region corners
        var map = billGiver?.Map;

        var regions = map?.regionGrid; // *

        if (regions == null)
        {
            return(false);
        }

        var chkcell = IntVec3.Zero;

        for (var i = 0; i < 4; i++)
        {
            switch (i)
            {
            case 0:
                chkcell = new IntVec3(r.extentsClose.minX, 0, r.extentsClose.minZ);
                break;

            case 3:
                chkcell = new IntVec3(r.extentsClose.minX, 0, r.extentsClose.maxZ);
                break;

            case 2:
                chkcell = new IntVec3(r.extentsClose.maxX, 0, r.extentsClose.minZ);
                break;

            case 1:
                chkcell = new IntVec3(r.extentsClose.maxX, 0, r.extentsClose.maxZ);
                break;
            }

            //if (chkcell.GetRegion(map) == r)
            if (!Equals(regions.GetRegionAt_NoRebuild_InvalidAllowed(chkcell), r))
            {
                continue;
            }

            var scaleToCell       = (float)(chkcell - billGiver.Position).LengthHorizontalSquared;
            var scaleSearchRadius = bill.ingredientSearchRadius * bill.ingredientSearchRadius;
            if (Controller.Settings.UseRadiusLimit)
            {
                var RadiusLimit = (float)Controller.Settings.RadiusLimit;
                var scaleLimit  = RadiusLimit * RadiusLimit;
                if (scaleLimit < scaleSearchRadius)
                {
                    scaleSearchRadius = scaleLimit;
                }
            }

            if (scaleToCell <= scaleSearchRadius)
            {
                return(true);
            }
        }

        return(false);
    }