Skip to content

Commit

Permalink
Merge pull request #101 from RimWorldCCLTeam/development
Browse files Browse the repository at this point in the history
API Additions & Bugs Bashed
  • Loading branch information
ForsakenShell committed Jun 2, 2016
2 parents 6806691 + 566c208 commit 6ad7ad0
Show file tree
Hide file tree
Showing 28 changed files with 345 additions and 228 deletions.
14 changes: 14 additions & 0 deletions DLL_Project/Classes/Static/CCL_Widgets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,19 @@ public static string StringJoin( this IEnumerable<string> enmumerable, string se
{
return String.Join( seperator, enmumerable.ToArray() );
}

public static bool ImageButton( Rect canvas, Texture2D tex, string altString, string tip = "" )
{
if( !tip.NullOrEmpty() )
{
TooltipHandler.TipRegion( canvas, tip );
}
if( tex == null )
{
return Widgets.TextButton( canvas, altString, false, true );
}
return Widgets.ImageButton( canvas, tex );
}

}
}
28 changes: 28 additions & 0 deletions DLL_Project/Classes/Static/XML_Helper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Xml;

namespace CommunityCoreLibrary
{

public static class XML_Helper
{

// TODO: Move this method to an extension class (question, under what though?)
public static bool HasChildNode( this XmlNode xmlNode, string childNode )
{
var xmlEnumerator = xmlNode.ChildNodes.GetEnumerator();
while( xmlEnumerator.MoveNext() )
{
var node = (XmlNode) xmlEnumerator.Current;
if( node.Name == childNode )
{ // Node exists
return true;
}
}
// Node doesn't exist
return false;
}

}

}
2 changes: 2 additions & 0 deletions DLL_Project/CommunityCoreLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@
<Compile Include="Extensions\Listing_Standard_Extensions.cs" />
<Compile Include="Detours\PostLoadInitter.cs" />
<Compile Include="Detours\BiomeDef.cs" />
<Compile Include="Classes\Static\XML_Helper.cs" />
<Compile Include="Detours\SocialProperness.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
2 changes: 1 addition & 1 deletion DLL_Project/Controller/Controller_MainMonoBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ internal static void RestartRimWorld()
{
arguements += " ";
}
arguements += args[ index ];
arguements += "\"" + args[ index ] + "\"";
}
#if DEVELOPER
Log.Message( "Restarting RimWorld:\n" + commandLine + " " + arguements );
Expand Down
47 changes: 1 addition & 46 deletions DLL_Project/Defs/ModHelperDef/ThingDefAvailability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,12 @@ public bool Inject( ModHelperDef def )
bool setResearch = availabilitySet.researchPrerequisites != null;

bool menuHidden = false;
DesignationCategoryDef newCategory = null;
List<ResearchProjectDef> research = null;

if( setMenuHidden )
{
menuHidden = availabilitySet.menuHidden.ToLower() == "true" ? true : false;
}
if( setDesignation )
{
newCategory = availabilitySet.designationCategory == "None"
? null
: DefDatabase<DesignationCategoryDef>.GetNamed( availabilitySet.designationCategory );
}
if(
( setResearch )&&
( availabilitySet.researchPrerequisites.Count > 0 )
Expand All @@ -174,45 +167,7 @@ public bool Inject( ModHelperDef def )
}
if( setDesignation )
{
DesignationCategoryDef oldCategory = null;
Designator_Build oldDesignator = null;
if( target.designationCategory != availabilitySet.designationCategory )
{
// Only change if it's actually changed
if(
( !target.designationCategory.NullOrEmpty() )&&
( target.designationCategory != "None" )
)
{
oldCategory = DefDatabase<DesignationCategoryDef>.GetNamed( target.designationCategory );
oldDesignator = (Designator_Build) oldCategory.resolvedDesignators.FirstOrDefault( d => (
( d is Designator_Build )&&
( ( d as Designator_Build ).PlacingDef == (BuildableDef) target )
) );
}
if( newCategory == null )
{
if( oldCategory != null )
{
oldCategory.resolvedDesignators.Remove( oldDesignator );
}
}
else
{
Designator_Build newDesignator = null;
if( oldDesignator != null )
{
oldCategory.resolvedDesignators.Remove( oldDesignator );
newDesignator = oldDesignator;
}
else
{
newDesignator = (Designator_Build) Activator.CreateInstance( typeof( Designator_Build ), new System.Object[] { (BuildableDef) target } );
}
newCategory.resolvedDesignators.Add( newDesignator );
}
target.designationCategory = availabilitySet.designationCategory;
}
target.ChangeDesignationCategory( availabilitySet.designationCategory );
}
if( setResearch )
{
Expand Down
7 changes: 4 additions & 3 deletions DLL_Project/Detours/FoodUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal static Thing _BestFoodSourceFor( Pawn getter, Pawn eater, bool fullDisp
}
}

if( dispenserValidator.getter.RaceProps.ToolUser )
if( getter.RaceProps.ToolUser )
{
// Try to find a working nutrient paste dispenser or food sythesizer
var validatorPredicate = new Predicate<Thing>( dispenserValidator.Validate );
Expand Down Expand Up @@ -118,9 +118,10 @@ internal static Thing _BestFoodSourceFor( Pawn getter, Pawn eater, bool fullDisp
dispenserValidator.meal.def = null;
dispenserValidator.meal.score = FoodOptimalityUnusable;
}

// Now find the best/closest dispenser
var dispenser = GenClosest.ClosestThingReachable(
dispenserValidator.getter.Position,
getter.Position,
ThingRequest.ForUndefined(),
PathEndMode.InteractionCell,
TraverseParms.For(
Expand All @@ -131,7 +132,7 @@ internal static Thing _BestFoodSourceFor( Pawn getter, Pawn eater, bool fullDisp
dispensers,
-1,
true );

if( dispenser != null )
{
// Found a dispenser/synthesizer and it's better than the spawned meal
Expand Down
20 changes: 10 additions & 10 deletions DLL_Project/Detours/JobGiver_GetFood.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal static Job _TryGiveTerminalJob( this JobGiver_GetFood obj, Pawn pawn )
{
return obj.IngestJob( pawn, foodInInventory );
}
CompRottable comp = foodInInventory.TryGetComp<CompRottable>();
var comp = foodInInventory.TryGetComp<CompRottable>();
if(
( comp != null )&&
( comp.TicksUntilRotAtCurrentTemp < 30000 )
Expand All @@ -44,7 +44,7 @@ internal static Job _TryGiveTerminalJob( this JobGiver_GetFood obj, Pawn pawn )
}
}
ThingDef foodDef;
Thing bestFoodSource = FoodUtility.BestFoodSourceFor( pawn, pawn, false, out foodDef );
var bestFoodSource = FoodUtility.BestFoodSourceFor( pawn, pawn, false, out foodDef );
if(
( foodInInventory != null )&&
(
Expand Down Expand Up @@ -91,8 +91,8 @@ internal static Job _TryGiveTerminalJob( this JobGiver_GetFood obj, Pawn pawn )
}
else
{
ISlotGroupParent hopperSgp = hopper as ISlotGroupParent;
Job job = HopperFillFoodJob( pawn, hopperSgp, bestFoodSource );
var hopperSgp = hopper as ISlotGroupParent;
var job = HopperFillFoodJob( pawn, hopperSgp, bestFoodSource );
if( job != null )
{
return job;
Expand All @@ -106,21 +106,21 @@ internal static Job _TryGiveTerminalJob( this JobGiver_GetFood obj, Pawn pawn )
}
}
}
Pawn prey = bestFoodSource as Pawn;
var prey = bestFoodSource as Pawn;
if( prey != null )
{
Job predatorHunt = new Job( JobDefOf.PredatorHunt, prey );
var predatorHunt = new Job( JobDefOf.PredatorHunt, prey );
predatorHunt.killIncappedTarget = true;
return predatorHunt;
}
Job ingestJob = new Job( JobDefOf.Ingest, bestFoodSource );
var ingestJob = new Job( JobDefOf.Ingest, bestFoodSource );
ingestJob.maxNumToCarry = FoodUtility.WillEatStackCountOf( pawn, foodDef );
return ingestJob;
}

internal static Job HopperFillFoodJob( Pawn pawn, ISlotGroupParent hopperSgp, Thing parent )
{
Building building = hopperSgp as Building;
var building = hopperSgp as Building;
if(
( !pawn.CanReserveAndReach(
( TargetInfo )building.Position,
Expand All @@ -132,8 +132,8 @@ internal static Job HopperFillFoodJob( Pawn pawn, ISlotGroupParent hopperSgp, Th
{
return (Job) null;
}
ThingDef resourceDef = (ThingDef) null;
Thing firstItem = building.Position.GetFirstItem();
ThingDef resourceDef = null;
var firstItem = building.Position.GetFirstItem();
if( firstItem != null )
{
if(
Expand Down
28 changes: 28 additions & 0 deletions DLL_Project/Detours/SocialProperness.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;

using RimWorld;
using Verse;

namespace CommunityCoreLibrary.Detour
{

internal static class _SocialProperness
{

internal static bool _IsSociallyProper( this Thing t, Pawn p, bool forPrisoner, bool animalsCare = false )
{
if(
( !animalsCare )&&
( !p.RaceProps.Humanlike )||
( !t.def.socialPropernessMatters )
)
{
return true;
}
var intVec3 = !t.def.hasInteractionCell ? t.Position : t.InteractionCell;
return( forPrisoner == intVec3.IsInPrisonCell() );
}

}

}
48 changes: 48 additions & 0 deletions DLL_Project/Extensions/ThingDef_Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,54 @@ public static List<JoyGiverDef> GetJoyGiverDefsUsing( this ThingDef thingDef
return joyGiverDefs;
}

public static bool ChangeDesignationCategory( this ThingDef thingDef, string newCategory )
{
if( string.IsNullOrEmpty( newCategory ) )
{ // Invalid category
return false;
}
if( thingDef.designationCategory == newCategory )
{ // Already this category
return true;
}
DesignationCategoryDef newCategoryDef =
newCategory == "None"
? null
: DefDatabase<DesignationCategoryDef>.GetNamed( newCategory, false );
DesignationCategoryDef oldCategory = null;
Designator_Build oldDesignator = null;
if(
( !thingDef.designationCategory.NullOrEmpty() )&&
( thingDef.designationCategory != "None" )
)
{
oldCategory = DefDatabase<DesignationCategoryDef>.GetNamed( thingDef.designationCategory );
oldDesignator = (Designator_Build) oldCategory.resolvedDesignators.FirstOrDefault( d => (
( d is Designator_Build )&&
( ( d as Designator_Build ).PlacingDef == (BuildableDef) thingDef )
) );
}
if( oldCategory != null )
{
oldCategory.resolvedDesignators.Remove( oldDesignator );
}
if( newCategoryDef != null )
{
Designator_Build newDesignator = null;
if( oldDesignator != null )
{
newDesignator = oldDesignator;
}
else
{
newDesignator = (Designator_Build) Activator.CreateInstance( typeof( Designator_Build ), new System.Object[] { (BuildableDef) thingDef } );
}
newCategoryDef.resolvedDesignators.Add( newDesignator );
}
thingDef.designationCategory = newCategory;
return true;
}

#endregion

#region Lists of affected data
Expand Down
Loading

0 comments on commit 6ad7ad0

Please sign in to comment.