本文整理汇总了C#中Part.GetConnectedResources方法的典型用法代码示例。如果您正苦于以下问题:C# Part.GetConnectedResources方法的具体用法?C# Part.GetConnectedResources怎么用?C# Part.GetConnectedResources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Part
的用法示例。
在下文中一共展示了Part.GetConnectedResources方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetConnectedResources
public static List<PartResource> GetConnectedResources(Part part, String resourceName)
{
var resourceDef = PartResourceLibrary.Instance.GetDefinition(resourceName);
var resources = new List<PartResource>();
part.GetConnectedResources(resourceDef.id, resourceDef.resourceFlowMode, resources);
return resources;
}
示例2: fixedRequestResource
public static double fixedRequestResource(Part part, string resourcename, double resource_amount)
{
List<PartResource> prl = part.GetConnectedResources(resourcename).ToList();
List<Part> parts = new List<Part>();
ResourceFlowMode flow = PartResourceLibrary.Instance.GetDefinition(resourcename).resourceFlowMode;
prl = prl.Where(p => p.flowState == true).ToList();
double max_available = 0;
double spare_capacity = 0;
foreach (PartResource partresource in prl)
{
parts.Add(partresource.part);
max_available += partresource.amount;
spare_capacity += partresource.maxAmount - partresource.amount;
}
if (flow == ResourceFlowMode.ALL_VESSEL)
{ // use our code
double resource_left_to_draw = 0;
double total_resource_change = 0;
double res_ratio = 0;
if (resource_amount > 0)
{
resource_left_to_draw = Math.Min(resource_amount, max_available);
res_ratio = Math.Min(resource_amount / max_available,1);
}
else
{
resource_left_to_draw = Math.Max(-spare_capacity, resource_amount);
res_ratio = Math.Min(-resource_amount / spare_capacity,1);
}
if (double.IsNaN(res_ratio) || double.IsInfinity(res_ratio) || res_ratio == 0)
{
return 0;
}
else
{
foreach (PartResource local_part_resource in prl) {
if (resource_amount > 0) {
local_part_resource.amount = local_part_resource.amount - local_part_resource.amount * res_ratio;
total_resource_change += local_part_resource.amount * res_ratio;
}else{
local_part_resource.amount = local_part_resource.amount + (local_part_resource.maxAmount - local_part_resource.amount) * res_ratio;
total_resource_change -= (local_part_resource.maxAmount - local_part_resource.amount) * res_ratio;
}
}
}
return total_resource_change;
} else {
if (resource_amount > 0) {
return part.RequestResource(resourcename, Math.Min(resource_amount, max_available));
} else {
return part.RequestResource(resourcename, Math.Max(-spare_capacity, resource_amount));
}
}
}
示例3: getDemand
public static double getDemand(Part part, string name)
{
var res_set = new List<PartResource>();
var res_def = PartResourceLibrary.Instance.GetDefinition(name);
if (res_def == null) return 0;
part.GetConnectedResources(res_def.id, res_def.resourceFlowMode, res_set);
if (res_set == null) return 0;
return sumDemand(res_set);
}
示例4: GetSnackResource
public double GetSnackResource(Part p, double demand)
{
List<PartResource> resources = new List<PartResource>();
p.GetConnectedResources(snacksResource.id, ResourceFlowMode.ALL_VESSEL, resources);
double supplied = 0;
foreach (PartResource res in resources)
{
if (res.amount >= demand)
{
res.amount -= demand;
supplied += demand;
return supplied;
}
else
{
supplied += res.amount;
demand -= res.amount;
res.amount = 0;
}
}
return supplied;
}
示例5: fixedRequestResourceSpareCapacity
public static double fixedRequestResourceSpareCapacity(Part part, string resourcename)
{
return part.GetConnectedResources(resourcename).Sum(r => r.maxAmount - r.amount);
}
示例6: GetConnectedResources
// =====================================================================================================================================================
// Build Helper Functions
// Gets connected resources to a part. Note fuel lines are NOT reversible! Add flow going TO the constructing part!
private static List<PartResource> GetConnectedResources(Part part, String resourceName)
{
var resources = new List<PartResource>();
part.GetConnectedResources(PartResourceLibrary.Instance.GetDefinition(resourceName).id, resources);
return resources;
}
示例7: GetBattery
//tr.name.StartsWith(rotatorsName, StringComparison.Ordinal
/// <summary>Gets a battery. Names it "Jennifer" and gives it a good home.</summary>
/// <remarks>My father once played a game where he had to choose a mascot. He grabbed a dead battery and named it "Jennifer." That story never gets old. - Gaalidas</remarks>
public static float GetBattery(Part part)
{
PartResourceDefinition resourceDefinitions = PartResourceLibrary.Instance.GetDefinition("ElectricCharge");
var resources = new List<PartResource>();
//List<PartResource> resources = new List<PartResource>();
part.GetConnectedResources(resourceDefinitions.id, resourceDefinitions.resourceFlowMode, resources);
var ratio = (float)resources.Sum(r => r.amount) / (float)resources.Sum(r => r.maxAmount);
return ratio;
}
示例8: updateAvailableResourceCapacity
public void updateAvailableResourceCapacity(Part p)
{
p.GetConnectedResources(resourceDefID, ResourceFlowMode.ALL_VESSEL, cacheList);
emptyCapacity = Enumerable.Sum<PartResource>(cacheList, emptyFunc);
cacheList.Clear();
}
示例9: updateAvailableResource
public void updateAvailableResource(Part p)
{
p.GetConnectedResources(resourceDefID, ResourceFlowMode.ALL_VESSEL, cacheList);
foundAmount = Enumerable.Sum<PartResource>(cacheList, sumFunc);
cacheList.Clear();
}