public static float CapacityLeft(LordJob_FormAndSendCaravan lordJob) { float num = CollectionsMassCalculator.MassUsageTransferables(lordJob.transferables, IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload, false, false); CaravanFormingUtility.tmpCaravanPawns.Clear(); for (int i = 0; i < lordJob.lord.ownedPawns.Count; i++) { Pawn pawn = lordJob.lord.ownedPawns[i]; CaravanFormingUtility.tmpCaravanPawns.Add(new ThingCount(pawn, pawn.stackCount)); } num += CollectionsMassCalculator.MassUsage(CaravanFormingUtility.tmpCaravanPawns, IgnorePawnsInventoryMode.IgnoreIfAssignedToUnload, false, false); float num2 = CollectionsMassCalculator.Capacity(CaravanFormingUtility.tmpCaravanPawns, null); CaravanFormingUtility.tmpCaravanPawns.Clear(); return(num2 - num); }
public void SetupPods() { // exit if status is not planned if (this.Status != ShipmentStatus.Planned) { Log.Error("Can't setup pods for not planned shipment: " + this.Status.ToString()); return; } List <TransferableOneWay> transferables = this.Transferables.ToList(); // find transporters List <CompLogisticTransporter> logTransporters = this.sender .TransportersForMassAndDistance(CollectionsMassCalculator.MassUsageTransferables(transferables, IgnorePawnsInventoryMode.Ignore), this.destination.map.Tile); Log.Message("Transporters found: " + logTransporters.Count); if (logTransporters.NullOrEmpty()) { Log.Message("No transporters found"); return; } // choose which ones to use logTransporters = logTransporters.GetRange(0, 1); // initialize them foreach (var transporter in logTransporters) { transporter.shipmentInProgress = this; } List <CompTransporter> transporters = logTransporters.Select(t => t.Transporter).ToList(); TransporterUtility.InitiateLoading(transporters); LogTransporterUtility.DistributeItems(transferables, transporters); this.Status = ShipmentStatus.InLoading; }
// RimWorld.CollectionsMassCalculator public static bool CapacityTransferables_PreFix(List <TransferableOneWay> transferables, ref float __result) { Cthulhu.Utility.DebugReport("Detour Called: CollectionMassCalc"); //List<ThingCount> tmpThingCounts bool detour = false; for (int i = 0; i < transferables.Count; i++) { if (transferables[i].HasAnyThing) { if (transferables[i].AnyThing.def.defName == "ROM_DarkYoung") { detour = true; break; } } } if (detour) { ((List <ThingCount>)AccessTools.Field(typeof(CollectionsMassCalculator), "tmpThingCounts").GetValue(null)).Clear(); for (int i = 0; i < transferables.Count; i++) { if (transferables[i].HasAnyThing) { if (transferables[i].AnyThing is Pawn || transferables[i].AnyThing.def.defName == "ROM_DarkYoung") { TransferableUtility.TransferNoSplit(transferables[i].things, transferables[i].CountToTransfer, delegate(Thing originalThing, int toTake) { ((List <ThingCount>)AccessTools.Field(typeof(CollectionsMassCalculator), "tmpThingCounts").GetValue(null)).Add(new ThingCount(originalThing, toTake)); }, false, false); } } } float result = CollectionsMassCalculator.Capacity(((List <ThingCount>)AccessTools.Field(typeof(CollectionsMassCalculator), "tmpThingCounts").GetValue(null))); ((List <ThingCount>)AccessTools.Field(typeof(CollectionsMassCalculator), "tmpThingCounts").GetValue(null)).Clear(); __result = result; return(false); } return(true); }
internal static float CapacityTransferables(List <TransferableOneWay> transferables) { Cthulhu.Utility.DebugReport("Detour Called: CollectionMassCalc"); GetTmpThingStackParts().Clear(); for (int i = 0; i < transferables.Count; i++) { if (transferables[i].HasAnyThing) { if (transferables[i].AnyThing is Pawn || transferables[i].AnyThing.def.defName == "CosmicHorror_DarkYoung") { TransferableUtility.TransferNoSplit(transferables[i].things, transferables[i].countToTransfer, delegate(Thing originalThing, int toTake) { GetTmpThingStackParts().Add(new ThingStackPart(originalThing, toTake)); }, false, false); } } } float result = CollectionsMassCalculator.Capacity(GetTmpThingStackParts()); GetTmpThingStackParts().Clear(); return(result); }
/// <summary> /// Только для своих объетков /// </summary> public static WorldObjectEntry GetWorldObjectEntry(WorldObject worldObject) { var worldObjectEntry = new WorldObjectEntry(); worldObjectEntry.Type = worldObject is Caravan ? WorldObjectEntryType.Caravan : WorldObjectEntryType.Base; worldObjectEntry.Tile = worldObject.Tile; worldObjectEntry.Name = worldObject.LabelCap; worldObjectEntry.LoginOwner = SessionClientController.My.Login; worldObjectEntry.FreeWeight = 999999; //определяем цену и вес var caravan = worldObject as Caravan; if (caravan != null) { var transferables = CalculateTransferables(caravan); List <ThingCount> stackParts = new List <ThingCount>(); for (int i = 0; i < transferables.Count; i++) { TransferableUtility.TransferNoSplit(transferables[i].things, transferables[i].MaxCount /*CountToTransfer*/, delegate(Thing originalThing, int toTake) { stackParts.Add(new ThingCount(originalThing, toTake)); }, false, false); } worldObjectEntry.FreeWeight = CollectionsMassCalculator.Capacity(stackParts) - CollectionsMassCalculator.MassUsage(stackParts, IgnorePawnsInventoryMode.Ignore, false, false); worldObjectEntry.MarketValue = 0f; worldObjectEntry.MarketValuePawn = 0f; for (int i = 0; i < stackParts.Count; i++) { int count = stackParts[i].Count; if (count > 0) { Thing thing = stackParts[i].Thing; if (thing is Pawn) { worldObjectEntry.MarketValuePawn += thing.MarketValue + WealthWatcher.GetEquipmentApparelAndInventoryWealth(thing as Pawn); } else { worldObjectEntry.MarketValue += thing.MarketValue * (float)count; } } } } else if (worldObject is Settlement) { var map = (worldObject as Settlement).Map; if (map != null) { worldObjectEntry.MarketValue = map.wealthWatcher.WealthTotal; worldObjectEntry.MarketValuePawn = 0; foreach (Pawn current in map.mapPawns.FreeColonists) { worldObjectEntry.MarketValuePawn += current.MarketValue; } //Loger.Log("Map things "+ worldObjectEntry.MarketValue + " pawns " + worldObjectEntry.MarketValuePawn); } } WorldObjectEntry storeWO; if (MyWorldObjectEntry.TryGetValue(worldObject.ID, out storeWO)) { //если серверу приходит объект без данного ServerId, значит это наш новый объект (кроме первого запроса, т.к. не было ещё загрузки) worldObjectEntry.ServerId = storeWO.ServerId; } return(worldObjectEntry); }
/// <summary> /// Только для своих объетков /// </summary> public static WorldObjectEntry GetWorldObjectEntry(WorldObject worldObject , PlayerGameProgress gameProgress , Dictionary <Map, List <Pawn> > cacheColonists) { var worldObjectEntry = new WorldObjectEntry(); worldObjectEntry.Type = worldObject is Caravan ? WorldObjectEntryType.Caravan : WorldObjectEntryType.Base; worldObjectEntry.Tile = worldObject.Tile; worldObjectEntry.Name = worldObject.LabelCap; worldObjectEntry.LoginOwner = SessionClientController.My.Login; worldObjectEntry.FreeWeight = 999999; //определяем цену и вес var caravan = worldObject as Caravan; if (caravan != null) { //Loger.Log("Client TestBagSD 002"); var transferables = CalculateTransferables(caravan); //Loger.Log("Client TestBagSD 003"); List <ThingCount> stackParts = new List <ThingCount>(); for (int i = 0; i < transferables.Count; i++) { TransferableUtility.TransferNoSplit(transferables[i].things, transferables[i].MaxCount /*CountToTransfer*/, delegate(Thing originalThing, int toTake) { stackParts.Add(new ThingCount(originalThing, toTake)); }, false, false); } //Loger.Log("Client TestBagSD 004"); worldObjectEntry.FreeWeight = CollectionsMassCalculator.Capacity(stackParts) - CollectionsMassCalculator.MassUsage(stackParts, IgnorePawnsInventoryMode.Ignore, false, false); //Loger.Log("Client TestBagSD 005"); worldObjectEntry.MarketValue = 0f; worldObjectEntry.MarketValuePawn = 0f; for (int i = 0; i < stackParts.Count; i++) { int count = stackParts[i].Count; if (count > 0) { Thing thing = stackParts[i].Thing; if (thing is Pawn) { worldObjectEntry.MarketValuePawn += thing.MarketValue + WealthWatcher.GetEquipmentApparelAndInventoryWealth(thing as Pawn); GameProgressAdd(gameProgress, thing as Pawn); } else { worldObjectEntry.MarketValue += thing.MarketValue * (float)count; } } } //Loger.Log("Client TestBagSD 006"); } else if (worldObject is Settlement) { //Loger.Log("Client TestBagSD 007"); var map = (worldObject as Settlement).Map; if (map != null) { //Loger.Log("Client TestBagSD 008"); try { DateTime lastForceRecount; if (!LastForceRecount.TryGetValue(map.uniqueID, out lastForceRecount)) { LastForceRecount.Add(map.uniqueID, DateTime.UtcNow.AddSeconds(new Random(map.uniqueID * 7).Next(0, 10))); } else if ((DateTime.UtcNow - lastForceRecount).TotalSeconds > 30) { LastForceRecount[map.uniqueID] = DateTime.UtcNow; ModBaseData.RunMainThread(() => { map.wealthWatcher.ForceRecount(); }); } worldObjectEntry.MarketValue = map.wealthWatcher.WealthTotal; } catch { Thread.Sleep(100); try { worldObjectEntry.MarketValue = map.wealthWatcher.WealthTotal; } catch { } } worldObjectEntry.MarketValuePawn = 0; //Loger.Log("Client TestBagSD 015"); List <Pawn> ps; if (!cacheColonists.TryGetValue(map, out ps)) { var mapPawnsA = new Pawn[map.mapPawns.AllPawnsSpawned.Count]; map.mapPawns.AllPawnsSpawned.CopyTo(mapPawnsA); ps = mapPawnsA.Where(p => p.Faction == Faction.OfPlayer && p.RaceProps.Humanlike).ToList(); cacheColonists[map] = ps; } //Loger.Log("Client TestBagSD 016"); foreach (Pawn current in ps) { worldObjectEntry.MarketValuePawn += current.MarketValue; GameProgressAdd(gameProgress, current); } //Loger.Log("Client TestBagSD 017"); //Loger.Log("Map things "+ worldObjectEntry.MarketValue + " pawns " + worldObjectEntry.MarketValuePawn); } } //Loger.Log("Client TestBagSD 018"); WorldObjectEntry storeWO; if (WorldObjectEntrys.TryGetValue(worldObject.ID, out storeWO)) { //если серверу приходит объект без данного ServerId, значит это наш новый объект (кроме первого запроса, т.к. не было ещё загрузки) worldObjectEntry.ServerId = storeWO.ServerId; } //Loger.Log("Client TestBagSD 019"); return(worldObjectEntry); }