Skip to content

Commit

Permalink
Merge pull request #154 from RimWorldCCLTeam/development
Browse files Browse the repository at this point in the history
v0.14.2.1 - Small bugs stomped
  • Loading branch information
ForsakenShell authored Aug 12, 2016
2 parents f24c183 + 7b11fb4 commit fc2e84d
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 42 deletions.
11 changes: 5 additions & 6 deletions DLL_Project/Buildings/Building_AutomatedFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ public override void ExposeData()
var key = pair.Key.products[0].thingDef;
SetAllowed( pair.Key, pair.Value );
}
ResetAndReprogramHoppers();
//ResetAndReprogramHoppers();
currentRecipeCount = this.def.AllRecipes.Count;
}
}

Expand Down Expand Up @@ -395,7 +396,7 @@ public ThingFilter ResourceFilter
{
get
{
//Log.Message( string.Format( "{0}.ResourceFilter()", this.ThingID ) );
//Log.Message( string.Format( "{0}.ResourceFilter", this.ThingID ) );
if( def.AllRecipes.NullOrEmpty() )
{
CCL_Log.TraceMod(
Expand Down Expand Up @@ -478,13 +479,13 @@ public void SetAllowed( ThingDef thingDef, bool allowed

public void SetAllowed( RecipeDef recipeDef, bool allowed )
{
//Log.Message( string.Format( "{0}.SetAllowed( {1}, {2} )", this.ThingID, recipeDef == null ? "null" : recipeDef.defName, allowed ) );
var inAllowed = allowed;
var product = recipeDef.products[ 0 ].thingDef;
allowed &= (
( recipeDef.researchPrerequisite == null )||
( recipeDef.researchPrerequisite.IsFinished )
);
//Log.Message( string.Format( "{0}.SetAllowed( {1}, {2}->{3} )", this.ThingID, recipeDef.defName, inAllowed, allowed ) );
Allowances allowance;
if( productionAllowances.TryGetValue( product, out allowance ) )
{
Expand Down Expand Up @@ -883,15 +884,13 @@ public Thing TryProduceThingDef( ThingDef thingDef )
{
return (Thing) null;
}
List<ThingAmount> chosen = new List<ThingAmount>();
var chosen = new List<ThingAmount>();
if( !CompHopperUser.RemoveResourcesFromHoppers( recipe, chosen ) )
{
return null;
}
var thing = ThingMaker.MakeThing( thingDef );
thing.stackCount = recipe.products[0].count;
// A14: Changed thingClass meal to CompIngredients
// - Fluffy.
var ingredients = thing.TryGetComp<CompIngredients>();
if ( ingredients != null )
{
Expand Down
2 changes: 1 addition & 1 deletion DLL_Project/Classes/Static/HelpBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,7 @@ static HelpDef HelpForBiome( BiomeDef biomeDef, HelpCategoryDef category )
{
foreach( var disease in diseases )
{
var diseaseCommonality = ( biomeDef.CommonalityOfDisease( disease ) / biomeDef.diseaseMtbDays ) * GenDate.DaysPerYear;
var diseaseCommonality = biomeDef.CommonalityOfDisease( disease ) / ( biomeDef.diseaseMtbDays * GenDate.DaysPerYear );
defs.Add( disease.diseaseIncident );
chances.Add( diseaseCommonality.ToStringPercent() );
}
Expand Down
8 changes: 6 additions & 2 deletions DLL_Project/Detours/FoodUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ internal static float _FoodSourceOptimality( Pawn eater, Thing t,
if( t is Building_AutomatedFactory )
{
def = ((Building_AutomatedFactory)t).BestProduct( FoodSynthesis.IsMeal, FoodSynthesis.SortMeal );
if( def == null )
{
return FoodOptimalityUnusable;
}
}
else if( t is Building_NutrientPasteDispenser )
{
Expand All @@ -120,7 +124,7 @@ internal static float _FoodSourceOptimality( Pawn eater, Thing t,
switch( def.ingestible.preferability )
{
case FoodPreferability.NeverForNutrition:
return -9999999f;
return FoodOptimalityUnusable;
case FoodPreferability.DesperateOnly:
num -= 150f;
break;
Expand All @@ -130,7 +134,7 @@ internal static float _FoodSourceOptimality( Pawn eater, Thing t,
{
if( comp.Stage == RotStage.Dessicated )
{
return -9999999f;
return FoodOptimalityUnusable;
}
if(
( comp.Stage == RotStage.Fresh )&&
Expand Down
77 changes: 46 additions & 31 deletions DLL_Project/ThingComps/CompHopperUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ private class HopperSettingsAmount

public List<CompHopper> hoppers = new List<CompHopper>();
public StorageSettings settings = new StorageSettings();
public ThingCategoryDef categoryDef;
public ThingDef thingDef;
public int count;
public ThingCategoryDef fixedCategoryDef;
public ThingDef fixedThingDef;
public int fixedCount;
private int hoppersRequired = -1;

public HopperSettingsAmount( ThingDef thingDef, float count )
{
this.categoryDef = null;
this.thingDef = thingDef;
this.count = Mathf.CeilToInt( count );
this.fixedCategoryDef = null;
this.fixedThingDef = thingDef;
this.fixedCount = Mathf.CeilToInt( count );
}

public HopperSettingsAmount( ThingCategoryDef categoryDef, float count )
{
this.categoryDef = categoryDef;
this.thingDef = null;
this.count = Mathf.CeilToInt( count );
this.fixedCategoryDef = categoryDef;
this.fixedThingDef = null;
this.fixedCount = Mathf.CeilToInt( count );
}

public bool ShouldBeRefrigerated
Expand All @@ -50,21 +50,21 @@ public int HoppersRequired
if( hoppersRequired < 0 )
{
hoppersRequired = 0;
if( this.categoryDef != null )
if( this.fixedCategoryDef != null )
{
int largest = 0;
foreach( var thingDef in categoryDef.childThingDefs )
foreach( var thingDef in fixedCategoryDef.childThingDefs )
{
if( thingDef.stackLimit > largest )
{
largest = thingDef.stackLimit;
}
}
hoppersRequired = Mathf.Max( 1, Mathf.CeilToInt( (float) count / largest ) );
hoppersRequired = Mathf.Max( 1, Mathf.CeilToInt( (float) fixedCount / largest ) );
}
if( this.thingDef != null )
if( this.fixedThingDef != null )
{
hoppersRequired = Mathf.Max( 1, Mathf.CeilToInt( (float) count / thingDef.stackLimit ) );
hoppersRequired = Mathf.Max( 1, Mathf.CeilToInt( (float) fixedCount / fixedThingDef.stackLimit ) );
}
}
return hoppersRequired;
Expand All @@ -76,11 +76,11 @@ public static void AddToList( List<HopperSettingsAmount> list, Thin
int countNeeded = CountForThingDef( thingDef, baseCount, recipe );
for( int index = 0; index < list.Count; ++index )
{
if( list[ index ].thingDef == thingDef )
if( list[ index ].fixedThingDef == thingDef )
{
if( countNeeded > list[ index ].count )
if( countNeeded > list[ index ].fixedCount )
{
list[ index ] = new HopperSettingsAmount( list[ index ].thingDef, countNeeded );
list[ index ] = new HopperSettingsAmount( list[ index ].fixedThingDef, countNeeded );
}
return;
}
Expand All @@ -93,11 +93,11 @@ public static void AddToList( List<HopperSettingsAmount> list, Thin
int countNeeded = CountForCategoryDef( categoryDef, baseCount, recipe );
for( int index = 0; index < list.Count; ++index )
{
if( list[ index ].categoryDef == categoryDef )
if( list[ index ].fixedCategoryDef == categoryDef )
{
if( countNeeded > list[ index ].count )
if( countNeeded > list[ index ].fixedCount )
{
list[ index ] = new HopperSettingsAmount( list[ index ].categoryDef, countNeeded );
list[ index ] = new HopperSettingsAmount( list[ index ].fixedCategoryDef, countNeeded );
}
return;
}
Expand Down Expand Up @@ -160,6 +160,7 @@ public static int CountForCategoryDef( ThingCategoryDef categoryDe
private List<HopperSettingsAmount> hopperSettings = new List<HopperSettingsAmount>();

private bool settingsBuilt = false;
private bool gameWasJustLoaded = false;

#region Neighbouring Cell Enumeration

Expand Down Expand Up @@ -211,6 +212,15 @@ public override void PostSpawnSetup()
FindAndProgramHoppers();
}

public override void PostExposeData()
{
base.PostExposeData();
if( Scribe.mode == LoadSaveMode.PostLoadInit )
{
gameWasJustLoaded = true;
}
}

public override void PostDeSpawn()
{
//Log.Message( string.Format( "{0}.CompHopperUser.PostDeSpawn()", this.parent.ThingID ) );
Expand Down Expand Up @@ -463,13 +473,13 @@ private void BuildHopperSettings()
// Assign hopper settings filters from ingredients
foreach( var hopperSetting in hopperSettings )
{
if( hopperSetting.categoryDef != null )
if( hopperSetting.fixedCategoryDef != null )
{
hopperSetting.settings.filter.SetAllow( hopperSetting.categoryDef, true );
hopperSetting.settings.filter.SetAllow( hopperSetting.fixedCategoryDef, true );
}
if( hopperSetting.thingDef != null )
if( hopperSetting.fixedThingDef != null )
{
hopperSetting.settings.filter.SetAllow( hopperSetting.thingDef, true );
hopperSetting.settings.filter.SetAllow( hopperSetting.fixedThingDef, true );
}
}

Expand All @@ -491,7 +501,7 @@ private void BuildHopperSettings()
{
var settingA = hopperSettings[ index ];
if(
( settingA.categoryDef != null )&&
( settingA.fixedCategoryDef != null )&&
( settingA.settings.filter.AllowedDefCount > 1 )
)
{
Expand All @@ -502,12 +512,12 @@ private void BuildHopperSettings()
var settingB = hopperSettings[ index2 ];
if(
(
( settingB.categoryDef != null )&&
( settingA.categoryDef.ThisAndChildCategoryDefs.Contains( settingB.categoryDef ) )
( settingB.fixedCategoryDef != null )&&
( settingA.fixedCategoryDef.ThisAndChildCategoryDefs.Contains( settingB.fixedCategoryDef ) )
)||
(
( settingB.thingDef != null )&&
( settingA.categoryDef.DescendantThingDefs.Contains( settingB.thingDef ) )
( settingB.fixedThingDef != null )&&
( settingA.fixedCategoryDef.DescendantThingDefs.Contains( settingB.fixedThingDef ) )
)
)
{
Expand Down Expand Up @@ -536,7 +546,7 @@ private void BuildHopperSettings()
}
}
}
hopperSetting.count = largest;
hopperSetting.fixedCount = largest;
}

// Remove empty hopper settings from the list
Expand All @@ -550,7 +560,7 @@ private void BuildHopperSettings()
}

// Sort the hopper settings from most required ingredients to least
hopperSettings.Sort( ( x, y ) => ( x.count > y.count ? -1 : 1 ) );
hopperSettings.Sort( ( x, y ) => ( x.fixedCount > y.fixedCount ? -1 : 1 ) );

// Finalize hopper settings
for( int index = 0; index < hopperSettings.Count; ++index )
Expand Down Expand Up @@ -743,6 +753,11 @@ public void FindAndProgramHoppers()
// Rebuild the hopper settings
BuildHopperSettings();
}
if( gameWasJustLoaded )
{
gameWasJustLoaded = false;
return;
}
var hoppers = FindHoppers();
if( hoppers.NullOrEmpty() )
{
Expand Down
2 changes: 1 addition & 1 deletion DLL_Project/Version/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class Version
#region Instance Data

private static System.Version versionMin = new System.Version( "0.14.0" );
private const string versionCurrentInt = "0.14.2";
private const string versionCurrentInt = "0.14.2.1";

private static System.Version versionCurrent;

Expand Down
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.14.2
0.14.2.1

0 comments on commit fc2e84d

Please sign in to comment.