示例#1
0
 public static bool BMixFinishedStatus(bool foundAll, Thing billGiver, Bill bill)
 {
     if (foundAll)
     {
         if (billGiver is Pawn)
         {
             return(true);
         }
         if (IsValidForComp(billGiver))
         {
             //if (billGiver.TryGetComp<CompBestMix>().CurMode == "DIS")
             CompBestMix CBM = billGiver.TryGetComp <CompBestMix>();
             if (CBM != null)
             {
                 if (BMBillUtility.UseBMixMode(CBM, billGiver, bill) == "DIS")
                 {
                     return(true);
                 }
             }
             return(false);
         }
         else
         {
             return(true);
         }
     }
     return(false);
 }
示例#2
0
        public override void PostSpawnSetup(bool respawningAfterLoad)
        {
            base.PostSpawnSetup(respawningAfterLoad);

            if (CurMode == null)
            {
                CurMode = BMProps.DefaultMode;
            }

            if (respawningAfterLoad)
            {
                BMBillUtility.CheckBillBMValues(this, parent as Thing, BillBMModes);
            }
        }
 public static void AddBMGUI(float width, BillStack billstack, Bill bill)
 {
     if (!bill.recipe.IsSurgery)
     {
         //Color baseColor = new Color(1f, 0.7f, 0.7f, 0.7f);
         Color baseColor = Color.white;
         //float offset = Controller.Settings.BillBMPos;
         var       rectBM = new Rect(width - (24f + 150f), 0f, 24f, 24f);
         Texture2D BMTex  = BMBillUtility.GetBillBMTex(billstack.billGiver as Thing, bill);
         if (Widgets.ButtonImage(rectBM, BMTex, baseColor, baseColor * GenUI.SubtleMouseoverColor))
         {
             BMBillUtility.SetBillBMVal(billstack.billGiver as Thing, bill);
             SoundDefOf.Click.PlayOneShotOnCamera();
         }
     }
 }
示例#4
0
 // Debug
 internal static void BMixDebugList(List <Thing> list, Thing billGiver, IntVec3 rootCell, Bill bill)
 {
     if (Prefs.DevMode && Controller.Settings.DebugMaster && Controller.Settings.DebugSort)
     {
         var ignore = Controller.Settings.DebugIgnore;
         if (IsValidForComp(billGiver))
         {
             CompBestMix compBMix = billGiver.TryGetComp <CompBestMix>();
             if (compBMix != null)
             {
                 if (compBMix.BMixDebug)
                 {
                     if (list.Count > 0)
                     {
                         for (var i = 0; i < list.Count; i++)
                         {
                             Thing thing    = list[i];
                             var   debugMsg = MakeDebugString(i, thing, billGiver, rootCell, bill, BMBillUtility.UseBMixMode(compBMix, billGiver, bill));
                             Log.Message(debugMsg, ignore);
                         }
                     }
                 }
             }
         }
     }
 }
示例#5
0
        public static Comparison <Thing> GetBMixComparer(Thing billGiver, IntVec3 rootCell, Bill bill, out bool rnd)
        {
            rnd = false;
            var BMixMode       = "DIS";
            var BMixDebugBench = false;

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

            Comparison <Thing> comparison = null;

            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;
                    CompRottable t1comp = t1.TryGetComp <CompRottable>();
                    if (t1comp != null)
                    {
                        t1dtr = t1comp.TicksUntilRotAtCurrentTemp;
                    }
                    var          t2dtr  = maxdtr;
                    CompRottable 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 = ((float)(t2.MaxHitPoints - t2.HitPoints)) / ((float)Math.Max(1, t2.MaxHitPoints));
                    }
                    var value = 0f;
                    if (t1.def.useHitPoints)
                    {
                        value = ((float)(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 = ((float)t2.HitPoints) / ((float)Math.Max(1, t2.MaxHitPoints));
                    }
                    var value = 0f;
                    if (t1.def.useHitPoints)
                    {
                        value = ((float)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   = ((float)t2.def.stackLimit) / ((float)Math.Max(1, t2.stackCount));
                    var value = ((float)t1.def.stackLimit) / ((float)Math.Max(1, t1.stackCount));
                    return(num.CompareTo(value));
                };
                break;

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

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

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

            case "BTY":
                comparison = delegate(Thing t1, Thing t2)
                {
                    var num = t2.GetStatValue(StatDefOf.Beauty);
                    if ((t2.def?.stuffProps != null) && (t2.def?.stuffProps?.statOffsets != null))
                    {
                        if (t2.def.stuffProps.statOffsets.StatListContains(StatDefOf.Beauty))
                        {
                            num += t2.def.stuffProps.statOffsets.GetStatOffsetFromList(StatDefOf.Beauty);
                        }
                    }
                    var value = t1.GetStatValue(StatDefOf.Beauty);
                    if ((t1.def?.stuffProps != null) && (t1.def?.stuffProps?.statOffsets != null))
                    {
                        if (t1.def.stuffProps.statOffsets.StatListContains(StatDefOf.Beauty))
                        {
                            value += t1.def.stuffProps.statOffsets.GetStatOffsetFromList(StatDefOf.Beauty);
                        }
                    }
                    return(num.CompareTo(value));
                };
                break;

            case "UGY":
                comparison = delegate(Thing t1, Thing t2)
                {
                    var num = 0f - t2.GetStatValue(StatDefOf.Beauty);
                    if ((t2.def?.stuffProps != null) && (t2.def?.stuffProps?.statOffsets != null))
                    {
                        if (t2.def.stuffProps.statOffsets.StatListContains(StatDefOf.Beauty))
                        {
                            num -= t2.def.stuffProps.statOffsets.GetStatOffsetFromList(StatDefOf.Beauty);
                        }
                    }
                    var value = 0f - t1.GetStatValue(StatDefOf.Beauty);
                    if ((t1.def?.stuffProps != null) && (t1.def?.stuffProps?.statOffsets != null))
                    {
                        if (t1.def.stuffProps.statOffsets.StatListContains(StatDefOf.Beauty))
                        {
                            value -= t1.def.stuffProps.statOffsets.GetStatOffsetFromList(StatDefOf.Beauty);
                        }
                    }
                    return(num.CompareTo(value));
                };
                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;
                    StatDef protElectric = DefDatabase <StatDef> .GetNamed(ProtElectricStat, false);

                    if (protElectric != null)
                    {
                        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;
                    StatDef softness = DefDatabase <StatDef> .GetNamed(SoftnessStat, false);

                    if (softness != null)
                    {
                        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);
        }
示例#6
0
        public static bool BMixRegionIsInRange(Region r, Thing billGiver, Bill bill)
        {
            if (!Controller.Settings.IncludeRegionLimiter)
            {
                return(true);
            }

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

            CompBestMix 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
            Map map = billGiver?.Map;

            if (map != null)
            {
                RegionGrid regions = map?.regionGrid; // *
                if (regions != null)
                {
                    IntVec3 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 (regions.GetRegionAt_NoRebuild_InvalidAllowed(chkcell) == r) // * More direct check
                        {
                            var scaleToCell       = (float)(chkcell - billGiver.Position).LengthHorizontalSquared;
                            var scaleSearchRadius = (float)(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);
        }