private void DropExcessIngredients(Storage storage) { TagBits search_tags = default(TagBits); search_tags.Or(ref keepAdditionalTags); for (int i = 0; i < recipe_list.Length; i++) { ComplexRecipe complexRecipe = recipe_list[i]; if (IsRecipeQueued(complexRecipe)) { ComplexRecipe.RecipeElement[] ingredients = complexRecipe.ingredients; foreach (ComplexRecipe.RecipeElement recipeElement in ingredients) { search_tags.SetTag(recipeElement.material); } } } for (int num = storage.items.Count - 1; num >= 0; num--) { GameObject gameObject = storage.items[num]; if (!((UnityEngine.Object)gameObject == (UnityEngine.Object)null)) { PrimaryElement component = gameObject.GetComponent <PrimaryElement>(); if (!((UnityEngine.Object)component == (UnityEngine.Object)null) && (!keepExcessLiquids || !component.Element.IsLiquid)) { KPrefabID component2 = gameObject.GetComponent <KPrefabID>(); if ((bool)component2 && !component2.HasAnyTags(ref search_tags)) { storage.Drop(gameObject, true); } } } } }
public override void Update() { TagBits forbid_tags = new TagBits(GetComponent <ConsumableConsumer>().forbiddenTags); Pickupable pickupable = Game.Instance.fetchManager.FindEdibleFetchTarget(GetComponent <Storage>(), ref edibleTagBits, ref TagBits.None, ref forbid_tags, 0f); bool flag = edibleInReachButNotPermitted; Edible x = null; bool flag2 = false; if ((Object)pickupable != (Object)null) { x = pickupable.GetComponent <Edible>(); flag2 = true; flag = false; } else { Pickupable x2 = Game.Instance.fetchManager.FindFetchTarget(GetComponent <Storage>(), ref edibleTagBits, ref TagBits.None, ref TagBits.None, 0f); flag = ((Object)x2 != (Object)null); } if ((Object)x != (Object)edible || hasEdible != flag2) { edible = x; hasEdible = flag2; edibleInReachButNotPermitted = flag; Trigger(86328522, edible); } }
public PickupTagKey(int hash, KPrefabID id) { this.hash = hash; bits = new TagBits(ref FetchManager.disallowedTagMask); // AndTagBits updates the argument! id.AndTagBits(ref bits); }
public static void Prefix( Storage destination, ref TagBits tag_bits, ref TagBits required_tags, ref TagBits forbid_tags, float required_amount) { if (!__DEBUG) { return; } // only display log messages for egg cracker errands if (!destination.ToString().Contains(__EGG_CRACKER_NAME)) { return; } string formatted_arguments = "\n\nFetch chore for egg cracker:"; formatted_arguments += "\nTag bits:\n" + string.Join <Tag>(",", (IEnumerable <Tag>)tag_bits.GetTagsVerySlow()); formatted_arguments += "\nRequired tags:\n" + string.Join <Tag>(",", (IEnumerable <Tag>)required_tags.GetTagsVerySlow()); formatted_arguments += "\nForbid tags:\n" + string.Join <Tag>(",", (IEnumerable <Tag>)forbid_tags.GetTagsVerySlow()); formatted_arguments += "\nRequired amount:\n" + required_amount.ToString(); formatted_arguments += "\n\n"; Debug.Log("Getting target for fetch chore:\n" + formatted_arguments); }
/// <summary> /// Applied before AndTagBits runs. /// </summary> internal static bool Prefix(KPrefabID __instance, ref TagBits ___tagBits, ref TagBits rhs) { __instance.UpdateTagBits(); TagBitOps.And(ref rhs, ref ___tagBits); return(false); }
/// <summary> /// Ands two sets of tag bits and replaces Tag Bits A with the result A & B. /// </summary> /// <param name="lhs">Tag Bits A.</param> /// <param name="rhs">Tag Bits B.</param> internal static void And(ref TagBits lhs, ref TagBits rhs) { ulong hibits = lhs.bits7; lhs.And(ref rhs); lhs.bits7 = TranspileAnd(hibits, rhs.bits7); }
public static TagBits MakeComplement(ref TagBits rhs) { TagBits result = new TagBits(ref rhs); result.Complement(); return(result); }
/// <summary> /// Initializes the tag bits. /// </summary> internal static void Init() { BASICALLY_IDLE = new TagBits(); BASICALLY_IDLE.SetTag(GameTags.Idle); BASICALLY_IDLE.SetTag(GameTags.RecoveringBreath); BASICALLY_IDLE.SetTag(GameTags.MakingMess); }
/// <summary> /// Complements a set of tag bits. /// </summary> /// <param name="bits">The bits to complement.</param> /// <returns>The complement of those bits.</returns> internal static TagBits Not(TagBits bits) { ulong hibits = bits.bits7; bits.Complement(); bits.bits7 = GetLowerBits(bits.bits7) | NotHighBits(hibits); return(bits); }
/// <summary> /// Ands two sets of tag bits and replaces Tag Bits A with the result A | B. /// </summary> /// <param name="lhs">Tag Bits A.</param> /// <param name="rhs">Tag Bits B.</param> internal static void Or(ref TagBits lhs, ref TagBits rhs) { ulong hibits = lhs.bits7; lhs.Or(ref rhs); // Box into a type to allow the fields to be changed lhs.bits7 = TranspileOr(hibits, rhs.bits7); }
/// <summary> /// Initializes the tag masks used for collision. /// </summary> internal static void Init() { COLLIDE_WITH = new TagBits(); COLLIDE_WITH.SetTag(GameTags.Creature); COLLIDE_WITH.SetTag(GameTags.Minion); COLLIDE_WITHOUT = new TagBits(); COLLIDE_WITHOUT.SetTag(GameTags.Dead); COLLIDE_WITHOUT.SetTag(GameTags.Dying); }
public void Xor(ref TagBits rhs) { bits0 ^= rhs.bits0; bits1 ^= rhs.bits1; bits2 ^= rhs.bits2; bits3 ^= rhs.bits3; bits4 ^= rhs.bits4; bits5 ^= rhs.bits5; }
public TagBits(ref TagBits other) { bits0 = other.bits0; bits1 = other.bits1; bits2 = other.bits2; bits3 = other.bits3; bits4 = other.bits4; bits5 = other.bits5; }
public void And(ref TagBits rhs) { bits0 &= rhs.bits0; bits1 &= rhs.bits1; bits2 &= rhs.bits2; bits3 &= rhs.bits3; bits4 &= rhs.bits4; bits5 &= rhs.bits5; }
public void UpdateTags(HandleVector <int> .Handle fetchable_handle) { Fetchable data = fetchables.GetData(fetchable_handle); TagBits rhs = new TagBits(ref disallowedTagMask); data.pickupable.KPrefabID.AndTagBits(ref rhs); data.tagBitsHash = rhs.GetHashCode(); fetchables.SetData(fetchable_handle, data); }
public void Or(ref TagBits rhs) { bits0 |= rhs.bits0; bits1 |= rhs.bits1; bits2 |= rhs.bits2; bits3 |= rhs.bits3; bits4 |= rhs.bits4; bits5 |= rhs.bits5; }
/// <summary> /// Complements a set of tag bits. /// </summary> /// <param name="bits">The bits to complement.</param> /// <returns>The complement of those bits.</returns> internal static TagBits Not(TagBits bits) { bits.Complement(); // Box into a type to allow the fields to be changed object localBits = bits; ulong hibits = FIFTH_BIT.Get(localBits); FIFTH_BIT.Set(localBits, GetLowerBits(hibits) | NotHighBits(hibits)); return((TagBits)localBits); }
/// <summary> /// Ands two sets of tag bits and replaces Tag Bits A with the result A & B. /// </summary> /// <param name="lhs">Tag Bits A.</param> /// <param name="rhs">Tag Bits B.</param> internal static void And(ref TagBits lhs, ref TagBits rhs) { TagBits bits = lhs; ulong hibits = FIFTH_BIT.Get(lhs); bits.And(ref rhs); // Box into a type to allow the fields to be changed object localBits = bits; FIFTH_BIT.Set(localBits, TranspileAnd(hibits, FIFTH_BIT.Get(rhs))); lhs = (TagBits)localBits; }
public Pickupable FindFetchTarget(Storage destination, ref TagBits tag_bits, ref TagBits required_tags, ref TagBits forbid_tags, float required_amount) { foreach (Pickup pickup in pickups) { Pickup current = pickup; if (IsFetchablePickup(current.pickupable, ref tag_bits, ref required_tags, ref forbid_tags, destination)) { return(current.pickupable); } } return(null); }
public bool Equals(PickupTagKey x, PickupTagKey y) { bool ret = false; if (x.hash == y.hash) { var bitsA = new TagBits(ref FetchManager.disallowedTagMask); var bitsB = new TagBits(ref FetchManager.disallowedTagMask); x.id.AndTagBits(ref bitsA); y.id.AndTagBits(ref bitsB); ret = bitsA.AreEqual(ref bitsB); } return(ret); }
public void UpdatePickups(PathProber path_prober, Navigator worker_navigator, GameObject worker_go) { GatherPickupablesWhichCanBePickedUp(worker_go); GatherReachablePickups(worker_navigator); finalPickups.Sort(ComparerIncludingPriority); if (finalPickups.Count > 0) { Pickup pickup = finalPickups[0]; TagBits rhs = new TagBits(ref disallowedTagMask); pickup.pickupable.KPrefabID.AndTagBits(ref rhs); int num = pickup.tagBitsHash; int num2 = finalPickups.Count; int num3 = 0; for (int i = 1; i < finalPickups.Count; i++) { bool flag = false; Pickup pickup2 = finalPickups[i]; TagBits rhs2 = default(TagBits); int tagBitsHash = pickup2.tagBitsHash; if (pickup.masterPriority == pickup2.masterPriority) { rhs2 = new TagBits(ref disallowedTagMask); pickup2.pickupable.KPrefabID.AndTagBits(ref rhs2); if (pickup2.tagBitsHash == num && rhs2.AreEqual(ref rhs)) { flag = true; } } if (flag) { num2--; } else { num3++; pickup = pickup2; rhs = rhs2; num = tagBitsHash; if (i > num3) { finalPickups[num3] = pickup2; } } } finalPickups.RemoveRange(num2, finalPickups.Count - num2); } }
public HandleVector <int> .Handle AddPickupable(Pickupable pickupable) { byte foodQuality = 5; Edible component = pickupable.GetComponent <Edible>(); if ((Object)component != (Object)null) { foodQuality = (byte)component.GetQuality(); } byte masterPriority = 0; Prioritizable prioritizable = null; if ((Object)pickupable.storage != (Object)null) { prioritizable = pickupable.storage.prioritizable; if ((Object)prioritizable != (Object)null) { PrioritySetting masterPriority2 = prioritizable.GetMasterPriority(); masterPriority = (byte)masterPriority2.priority_value; } } Rottable.Instance sMI = pickupable.GetSMI <Rottable.Instance>(); byte freshness = 0; if (!sMI.IsNullOrStopped()) { freshness = QuantizeRotValue(sMI.RotValue); } KPrefabID component2 = pickupable.GetComponent <KPrefabID>(); TagBits rhs = new TagBits(ref disallowedTagMask); component2.AndTagBits(ref rhs); HandleVector <int> .Handle handle = fetchables.Allocate(new Fetchable { pickupable = pickupable, foodQuality = foodQuality, freshness = freshness, masterPriority = masterPriority, tagBitsHash = rhs.GetHashCode() }); if (!sMI.IsNullOrStopped()) { rotUpdaters[handle] = sMI; } return(handle); }
/// <summary> /// Condenses the pickups. /// </summary> /// <param name="pickups">The pickups to condense down.</param> private void CondensePickups(List <Pickup> pickups) { int n = pickups.Count; Pickup prevPickup = pickups[0]; var tagBits = new TagBits(ref FetchManager.disallowedTagMask); prevPickup.pickupable.KPrefabID.AndTagBits(ref tagBits); int hash = prevPickup.tagBitsHash, last = n, next = 0; for (int i = 1; i < n; i++) { bool del = false; var pickup = pickups[i]; var newTagBits = default(TagBits); if (prevPickup.masterPriority == pickup.masterPriority) { newTagBits = new TagBits(ref FetchManager.disallowedTagMask); pickup.pickupable.KPrefabID.AndTagBits(ref newTagBits); if (pickup.tagBitsHash == hash && newTagBits.AreEqual(ref tagBits)) { // Identical to the previous item del = true; } } if (del) { // Skip last--; } else { // Keep and move down next++; prevPickup = pickup; tagBits = newTagBits; hash = pickup.tagBitsHash; if (i > next) { pickups[next] = pickup; } } } pickups.RemoveRange(last, n - last); }
public Pickupable FindEdibleFetchTarget(Storage destination, ref TagBits tag_bits, ref TagBits required_tags, ref TagBits forbid_tags, float required_amount) { Pickup pickup = default(Pickup); pickup.PathCost = ushort.MaxValue; pickup.foodQuality = 0; Pickup pickup2 = pickup; int num = 2147483647; foreach (Pickup pickup3 in pickups) { Pickup current = pickup3; if (IsFetchablePickup(current.pickupable, ref tag_bits, ref required_tags, ref forbid_tags, destination)) { int num2 = current.PathCost + (5 - current.foodQuality) * 50; if (num2 < num) { pickup2 = current; num = num2; } } } return(pickup2.pickupable); }
public static bool IsFetchablePickup(Pickupable pickupable, ref TagBits tag_bits, ref TagBits required_tags, ref TagBits forbid_tags, Storage destination) { return(IsFetchablePickup(pickupable.KPrefabID, pickupable.storage, pickupable.UnreservedAmount, ref tag_bits, ref required_tags, ref forbid_tags, destination)); }
public static void Postfix(FetchManager __instance, Storage destination, ref TagBits tag_bits, ref TagBits required_tags, ref TagBits forbid_tags, float required_amount, ref Pickupable __result) { // only do this for the egg cracker if (!destination.ToString().Contains(__EGG_CRACKER_NAME)) { return; } List <FetchManager.Pickup> pickup_list = pickupListRef(__instance); List <Pickupable> egg_list = new List <Pickupable>(); if (__DEBUG) { Debug.Log(String.Format("Number of pickupbables available: {0}", pickup_list.Count)); } // get a list of all the available eggs for this fetch order foreach (FetchManager.Pickup pickup in pickup_list) { if (__DEBUG) { string debug_output = "Checking item on list:\n"; debug_output += "Position:\n"; UnityEngine.Vector3 pos = pickup.pickupable.GetTargetPoint(); debug_output += String.Format("X: {0} Y: {1} Z: {2}\n", pos.x, pos.y, pos.z); debug_output += "\nTag bits:\n" + string.Join <Tag>(",", (IEnumerable <Tag>)tag_bits.GetTagsVerySlow()); // TODO: use below code taken from FetchManager.IsFetchablePickup() to log if each pickup is valid // pickup_id.HasAnyTags_AssumeLaundered(ref tag_bits) && pickup_id.HasAllTags_AssumeLaundered(ref required_tags) && !pickup_id.HasAnyTags_AssumeLaundered(ref forbid_tags) && (!((Object)source != (Object)null) || (source.ignoreSourcePriority || !destination.ShouldOnlyTransferFromLowerPriority || !(destination.masterPriority <= source.masterPriority)) && (destination.storageNetworkID == -1 || destination.storageNetworkID != source.storageNetworkID)); debug_output += "------\n\n"; Debug.Log(debug_output); } if (FetchManager.IsFetchablePickup(pickup.pickupable, ref tag_bits, ref required_tags, ref forbid_tags, destination)) { egg_list.Add(pickup.pickupable); } } if (egg_list.Count == 0) { __result = (Pickupable)null; } // sort the list of eggs by incubation in ascending order (lowest incubation first) int sort_egg_incubation(Pickupable x, Pickupable y) { double x_incubation = Math.Round((x.gameObject.GetAmounts().Get(Db.Get().Amounts.Incubation)).value, 5); double y_incubation = Math.Round((y.gameObject.GetAmounts().Get(Db.Get().Amounts.Incubation)).value, 5); return(x_incubation.CompareTo(y_incubation)); } // return the first egg in the list (least incubation) egg_list.Sort(sort_egg_incubation); if (__DEBUG) { string debug_output = "Sorted list of eggs:\n"; foreach (Pickupable p in egg_list) { debug_output += "Position:\n"; UnityEngine.Vector3 pos = p.GetTargetPoint(); debug_output += String.Format("X: {0} Y: {1} Z: {2}\n", pos.x, pos.y, pos.z); debug_output += String.Format("Incubation: {0}\n", Math.Round((p.gameObject.GetAmounts().Get(Db.Get().Amounts.Incubation)).value, 5)); debug_output += "------\n\n"; } Debug.Log(debug_output); } __result = egg_list[0]; }
public static Pickupable FindFetchTarget(List <Pickupable> pickupables, Storage destination, ref TagBits tag_bits, ref TagBits required_tags, ref TagBits forbid_tags, float required_amount) { foreach (Pickupable pickupable in pickupables) { if (IsFetchablePickup(pickupable, ref tag_bits, ref required_tags, ref forbid_tags, destination)) { return(pickupable); } } return(null); }
public bool HasAllTags_AssumeLaundered(ref TagBits search_tags) { return(tagBits.HasAll(ref search_tags)); }
public bool HasAllTags(ref TagBits search_tags) { UpdateTagBits(); return(tagBits.HasAll(ref search_tags)); }
public void AndTagBits(ref TagBits rhs) { UpdateTagBits(); rhs.And(ref tagBits); }