Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel-125 committed Mar 26, 2021
1 parent f44cd1a commit 0d4e3f7
Show file tree
Hide file tree
Showing 20 changed files with 121 additions and 22 deletions.
2 changes: 1 addition & 1 deletion GameData/WildBlueIndustries/Snacks/License.txt
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 - 2016 Troy Gruetzmacher
Copyright (c) 2014 - 2021 Michael Billard (Angel-125) & Troy Gruetzmacher

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
23 changes: 23 additions & 0 deletions GameData/WildBlueIndustries/Snacks/LifeSupportResources/Air.txt
Expand Up @@ -91,6 +91,29 @@ STORAGE_TEMPLATE
//When a part with crew capacity is loaded in the editor and it lacks this resource,
//or when a vessel is loaded into the scene and its parts with crew capacity lack this resource,
//add it to the part. Doesn�t apply to kerbals going on EVA. Use SNACKS_EVA_RESOURCE for that.
SNACKS_PART_RESOURCE
{
name = FreshAir

resourceName = FreshAir

// How many units per day that will be consumed. Overrides amount and maxAmount.
// unitsPerDay = 1

// Specifies how many days of life support to provide.
// daysLifeSupport = 2

// Overriden by unitsPerDay and daysLifeSupport if they're > 0
amount = 16
maxAmount = 16

//If true (which is the default), then unitsPerDay and daysLifeSupport added are multiplied by the part's crew capacity.
isPerKerbal = true
}

//When a kerbal goes on EVA, take this resource along and remove a corresponding amount from the vessel.
//NOTE: Snacks is a special case since we have game settings that affect snacks per meal and meals per day.
//So for these values, the SNACKS_EVA_RESOURCE config will reflect the game settings. This config node is provided as an example.
SNACKS_EVA_RESOURCE
{
resourceName = FreshAir
Expand Down
Expand Up @@ -44,6 +44,8 @@ RESOURCE_DEFINITION:NEEDS[SnacksStress]

SNACKS_PART_RESOURCE:NEEDS[SnacksStress]
{
name = HydrazineVodka

resourceName = HydrazineVodka
amount = 17
maxAmount = 17
Expand Down
Expand Up @@ -28,7 +28,17 @@ RESOURCE_DEFINITION
//add it to the part. Doesn’t apply to kerbals going on EVA. Use SNACKS_EVA_RESOURCE for that.
SNACKS_PART_RESOURCE
{
name = Snacks

resourceName = Snacks

// How many units per day that will be consumed. Overrides amount and maxAmount.
// unitsPerDay = 3

// Specifies how many days of life support to provide.
// daysLifeSupport = 2

// Overriden by unitsPerDay and daysLifeSupport if they're > 0
amount = 200
maxAmount = 200
Expand All @@ -38,7 +48,7 @@ SNACKS_PART_RESOURCE
//If a part has at least one part module on the capacityAffectingModules list then multiply resource amount and max amount by this multiplier.
capacityMultiplier = 0.25

//If true (which is the default), then amount and maxAmount added are multiplied by the part's crew capacity.
//If true (which is the default), then unitsPerDay and daysLifeSupport added are multiplied by the part's crew capacity.
isPerKerbal = true
}
Expand Down
Expand Up @@ -463,7 +463,7 @@ SNACKS_EVENT

//AmountPerDay will be translated into: AmountPerDay / seconds per homeworld day
//This will override AmountPerSecond if it is defined in the node.
AmountPerDay = 2.5
AmountPerDay = 2
}
}
}
Expand Down Expand Up @@ -507,7 +507,7 @@ SNACKS_EVENT

//AmountPerDay will be translated into: AmountPerDay / seconds per homeworld day
//This will override AmountPerSecond if it is defined in the node.
AmountPerDay = 2.5
AmountPerDay = 2
}
}
}
Expand Down Expand Up @@ -551,7 +551,7 @@ SNACKS_EVENT

//AmountPerDay will be translated into: AmountPerDay / seconds per homeworld day
//This will override AmountPerSecond if it is defined in the node.
AmountPerDay = 2.5
AmountPerDay = 2
}
}
}
Expand Down Expand Up @@ -595,7 +595,7 @@ SNACKS_EVENT

//AmountPerDay will be translated into: AmountPerDay / seconds per homeworld day
//This will override AmountPerSecond if it is defined in the node.
AmountPerDay = 2
AmountPerDay = 1.5
}
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -26,7 +26,7 @@ PART:NEEDS[SnacksFreshAir]
TechRequired = survivability
entryCost = 5400
cost = 50
category = Utility
category = Cargo
subcategory = 0
title = Solid Oxium Candle System (SOCS)
manufacturer = ACME Corporation
Expand Down Expand Up @@ -111,6 +111,13 @@ PART:NEEDS[SnacksFreshAir]
}
}

MODULE
{
name = ModuleCargoPart
packedVolume = 20
stackableQuantity = 2
}

RESOURCE
{
name = SOCSFuel
Expand Down
Binary file modified GameData/WildBlueIndustries/Snacks/Plugin/SnacksUtils.dll
Binary file not shown.
Binary file modified GameData/WildBlueIndustries/Snacks/Plugin/SnacksUtils.pdb
Binary file not shown.
6 changes: 6 additions & 0 deletions GameData/WildBlueIndustries/Snacks/Readme.txt
Expand Up @@ -23,6 +23,12 @@ Copy the files in the zip folder over to GameData/Snacks

REVISION HISTORY

1.27

- Added the ability to store the SOCS Oxium Candle as a cargo part.
- SNACKS_PART_RESOURCE now supports unitsPerDay and daysLifeSupport. They specify the number of units per day that is consumed (per kerbal), and the number of days of life support to add to the part, respectively. If they're specified, then amount and maxAmount are ignored.
- Fixed missing resource infos in the editor's part display window.

1.26.1

- Fixed issue where the PAW would flicker whenever adjusting settings on another part.
Expand Down
4 changes: 2 additions & 2 deletions GameData/WildBlueIndustries/Snacks/Snacks.version
Expand Up @@ -11,8 +11,8 @@
"VERSION":
{
"MAJOR":1,
"MINOR":26,
"PATCH":1
"MINOR":27,
"PATCH":0
},
"KSP_VERSION_MIN":
{
Expand Down
2 changes: 1 addition & 1 deletion License.txt
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2014 - 2016 Troy Gruetzmacher
Copyright (c) 2014 - 2021 Michael Billard (Angel-125) & Troy Gruetzmacher

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions Notes/Snacks.version
Expand Up @@ -12,12 +12,12 @@
{
"MAJOR":1,
"MINOR":26,
"PATCH":0
"PATCH":1
},
"KSP_VERSION_MIN":
{
"MAJOR":1,
"MINOR":11,
"PATCH":0
"PATCH":2
}
}
42 changes: 34 additions & 8 deletions Snacks/ResourceClasses/SnacksPartResource.cs
Expand Up @@ -52,6 +52,17 @@ public class SnacksPartResource
/// </summary>
public double maxAmount;

/// <summary>
/// How many units per day that will be consumed. Overrides amount and maxAmount.
/// For Snacks, this is dynamically calculated based on game settings for Snacks per meal and meals per day.
/// </summary>
public double unitsPerDay;

/// <summary>
/// Specifies how many days of life support to provide.
/// </summary>
public double daysLifeSupport;

/// <summary>
/// Parts with at least one of the modules on this list affect the part's capacity to store the resource (their equipment takes up additional space, for instance).
/// </summary>
Expand Down Expand Up @@ -100,6 +111,10 @@ public static List<SnacksPartResource> LoadPartResources()
float.TryParse(node.GetValue("capacityMultiplier"), out partResource.capacityMultiplier);
if (node.HasValue("isPerKerbal"))
bool.TryParse(node.GetValue("isPerKerbal"), out partResource.isPerKerbal);
if (node.HasValue("unitsPerDay"))
double.TryParse(node.GetValue("unitsPerDay"), out partResource.unitsPerDay);
if (node.HasValue("daysLifeSupport"))
double.TryParse(node.GetValue("daysLifeSupport"), out partResource.daysLifeSupport);

partResourceList.Add(partResource);
}
Expand All @@ -109,8 +124,8 @@ public static List<SnacksPartResource> LoadPartResources()
{
partResource = new SnacksPartResource();
partResource.resourceName = SnacksProperties.SnacksResourceName;
partResource.amount = 200;
partResource.maxAmount = 200;
partResource.unitsPerDay = SnacksProperties.SnacksPerMeal * SnacksProperties.MealsPerDay;
partResource.daysLifeSupport = 2;
partResource.capacityAffectingModules = "ModuleCommand";
partResource.capacityMultiplier = 0.25f;
partResourceList.Add(partResource);
Expand All @@ -124,7 +139,7 @@ public static List<SnacksPartResource> LoadPartResources()
/// If the part with crew capacity doesn't have the resource, then add it.
/// </summary>
/// <param name="part"></param>
public bool addResourcesIfNeeded(Part part)
public bool addResourcesIfNeeded(Part part, AvailablePart availablePart = null)
{
if (part == null)
return false;
Expand Down Expand Up @@ -154,15 +169,15 @@ public bool addResourcesIfNeeded(Part part)
else if (HighLogic.LoadedSceneIsEditor)
{
if (part.Resources.Contains(resourceName))
partMaxAmount = part.Resources[resourceName].amount;
return false;
}
if (partMaxAmount > 0)
return false;

//Now add the resource.
//Determine how many units to add. If the part has any module on the capacity list, then we use the capacity modifier.
unitsToAdd = amount;
maxUnitsToAdd = maxAmount;
unitsToAdd = unitsPerDay > 0 ? unitsPerDay * daysLifeSupport : amount;
maxUnitsToAdd = unitsPerDay > 0 ? unitsToAdd : maxAmount;
if (isPerKerbal)
{
unitsToAdd *= part.CrewCapacity;
Expand All @@ -183,6 +198,17 @@ public bool addResourcesIfNeeded(Part part)

//Add the resource.
part.Resources.Add(def.name, unitsToAdd, maxUnitsToAdd, true, true, false, true, PartResource.FlowMode.Both);
Debug.Log(string.Format("[SnacksPartResource] - Added Amt: {0:n2} Max: {1:n2} of {2:s} to {3:s}", unitsToAdd, maxUnitsToAdd, resourceName, part.partInfo.title));

if (availablePart != null)
{
AvailablePart.ResourceInfo resourceInfo = new AvailablePart.ResourceInfo();
resourceInfo.resourceName = resourceName;
resourceInfo.displayName = def.displayName;
resourceInfo.info = string.Format("Amount: {0:n1}\nMass: {1:n3}\nCost: {2:n1}", unitsToAdd, def.density * unitsToAdd, def.unitCost * unitsToAdd);
availablePart.resourceInfos.Add(resourceInfo);
}

return true;
}

Expand Down Expand Up @@ -224,8 +250,8 @@ public void addResourcesIfNeeded(Vessel vessel)
continue;

//Determine how many units to add. If the part has any module on the capacity list, then we use the capacity modifier.
unitsToAdd = amount;
maxUnitsToAdd = maxAmount;
unitsToAdd = unitsPerDay > 0 ? unitsPerDay * daysLifeSupport : amount;
maxUnitsToAdd = unitsPerDay > 0 ? unitsToAdd : maxAmount;
if (!isPerKerbal)
{
unitsToAdd *= part.CrewCapacity;
Expand Down
16 changes: 15 additions & 1 deletion Snacks/SettingsAndScenario/SnacksScenario.cs
Expand Up @@ -913,6 +913,7 @@ public override void OnAwake()
snapshotMap = new Dictionary<Vessel, VesselSnackshot>();
bodyVesselCountMap = new Dictionary<int, int>();
initializeEventLists();
onGameSettingsApplied();
}

public void Start()
Expand Down Expand Up @@ -1370,7 +1371,7 @@ private void onEditorStarted()
partPrefab = PartLoader.LoadedPartsList[index].partPrefab;
if (partPrefab.isKerbalEVA() || partPrefab.isVesselEVA || partPrefab.CrewCapacity == 0 || PartLoader.LoadedPartsList[index].TechHidden)
continue;
snacksPartResources[resourceIndex].addResourcesIfNeeded(partPrefab);
snacksPartResources[resourceIndex].addResourcesIfNeeded(partPrefab, PartLoader.LoadedPartsList[index]);
}
}
}
Expand Down Expand Up @@ -1438,6 +1439,19 @@ private void onGameSettingsApplied()
{
resourceProcessors[index].OnGameSettingsApplied();
}

count = snacksPartResources.Count;
SnacksPartResource resource = null;
for (int index = 0; index < count; index++)
{
resource = snacksPartResources[index];
if (resource.resourceName == SnacksProperties.SnacksResourceName)
break;
}
if (resource != null)
{
resource.unitsPerDay = SnacksProperties.SnacksPerMeal * SnacksProperties.MealsPerDay;
}
}

private void onVesselLoaded(Vessel vessel)
Expand Down
Binary file modified Snacks/bin/Debug/SnacksUtils.dll
Binary file not shown.
Binary file modified Snacks/bin/Debug/SnacksUtils.pdb
Binary file not shown.
13 changes: 12 additions & 1 deletion Snacks/bin/Debug/xmldoc2md.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified Snacks/obj/Debug/SnacksUtils.dll
Binary file not shown.
Binary file modified Snacks/obj/Debug/SnacksUtils.pdb
Binary file not shown.

0 comments on commit 0d4e3f7

Please sign in to comment.