Skip to content

Commit

Permalink
Merge pull request #152 from RimWorldCCLTeam/development
Browse files Browse the repository at this point in the history
v0.14.2 - Get your outfit ready!
  • Loading branch information
ForsakenShell authored Aug 10, 2016
2 parents 5c8fc06 + 055d7b9 commit f24c183
Show file tree
Hide file tree
Showing 94 changed files with 3,275 additions and 146 deletions.
6 changes: 1 addition & 5 deletions DLL_Project/Classes/ListableOption_MainMenuDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,7 @@ public ListableOption_MainMenu( MainMenuDef def ) : base( def.label, def.menuWor

public override float DrawOption( Vector2 pos, float width )
{
label = menuDef.label;
if( !string.IsNullOrEmpty( menuDef.labelKey ) )
{
label = menuDef.labelKey.Translate();
}
label = menuDef.Label;
float height = Mathf.Max( minHeight, Text.CalcHeight( label, width ) );
GUI.color = menuDef.menuWorker.Color;
if( Widgets.ButtonText( new Rect( pos.x, pos.y, width, height ), label, true, true ) )
Expand Down
9 changes: 9 additions & 0 deletions DLL_Project/CommunityCoreLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@
<ItemGroup>
<Compile Include="Classes\InputField.cs" />
<Compile Include="Classes\Static\CCL_Widgets.cs" />
<Compile Include="Defs\OutfitDef.cs" />
<Compile Include="Defs\BackstoryDef.cs" />
<Compile Include="Defs\NameDef.cs" />
<Compile Include="Defs\PawnBioDef.cs" />
<Compile Include="Detours\OutfitDatabase.cs" />
<Compile Include="Extensions\BackstoryDefExt.cs" />
<Compile Include="Extensions\BiomeDef_Extensions.cs" />
<Compile Include="Extensions\DesignationCategoryDef_Extensions.cs" />
Expand Down Expand Up @@ -287,6 +289,10 @@
<Compile Include="Detours\PageUtility.cs" />
<Compile Include="SpecialInjectors\PostLoadInjectorTest.cs" />
<Compile Include="Detours\ModLister.cs" />
<Compile Include="MainMenus\MainMenu_ReviewScenario.cs" />
<Compile Include="ThinkNodes\ThinkNode_PrioritySorter_SubtreesByTag.cs" />
<Compile Include="Detours\Pawn_RelationsTracker.cs" />
<Compile Include="Detours\VersionControl.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 All @@ -304,4 +310,7 @@
<None Include="SubControllers\SubControllerOrderingReference.txt" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Folder Include="ThinkNodes\" />
</ItemGroup>
</Project>
8 changes: 8 additions & 0 deletions DLL_Project/Controller/Controller_MainMonoBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ internal static void PreLoad()
InjectionsOk &= Detours.TryDetourFromTo( RimWorld_MainMenuDrawer_DoMainMenuButtons, CCL_MainMenuDrawer_DoMainMenuButtons );
}

// Detour RimWorld.VersionControl.DrawInfoInCorner
if( InjectionsOk )
{
MethodInfo RimWorld_VersionControl_DrawInfoInCorner = typeof( VersionControl ).GetMethod( "DrawInfoInCorner", BindingFlags.Static | BindingFlags.Public );
MethodInfo CCL_VersionControl_DrawInfoInCorner = typeof( Detour._VersionControl ).GetMethod( "_DrawInfoInCorner", BindingFlags.Static | BindingFlags.NonPublic );
InjectionsOk &= Detours.TryDetourFromTo( RimWorld_VersionControl_DrawInfoInCorner, CCL_VersionControl_DrawInfoInCorner );
}

// Detour Verse.PostLoadInitter.DoAllPostLoadInits
/*
if( InjectionsOk )
Expand Down
14 changes: 13 additions & 1 deletion DLL_Project/Defs/MainMenuDef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,19 @@ public class MainMenuDef : Def

#endregion

public override void PostLoad()
public virtual string Label
{
get
{
if( string.IsNullOrEmpty( labelKey ) )
{
return label;
}
return labelKey.Translate();
}
}

public override void PostLoad()
{
base.PostLoad();

Expand Down
27 changes: 27 additions & 0 deletions DLL_Project/Defs/OutfitDef.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Verse;
using CommunityCoreLibrary.Detour;

namespace CommunityCoreLibrary
{

public class OutfitDef : Def
{
#region XML Data

public ThingFilter filter = new ThingFilter();

#endregion

public static OutfitDef Named(string defName)
{
return DefDatabase<OutfitDef>.GetNamed(defName);
}

public override void ResolveReferences()
{
base.ResolveReferences();

_OutfitDatabase.OutfitDefs.Add(this);
}
}
}
55 changes: 55 additions & 0 deletions DLL_Project/Detours/OutfitDatabase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using RimWorld;
using System.Collections.Generic;
using Verse;

namespace CommunityCoreLibrary.Detour
{
internal static class _OutfitDatabase
{
public static List<OutfitDef> OutfitDefs = new List<OutfitDef>();

internal static void _GenerateStartingOutfits(this OutfitDatabase outfitDatabase)
{
outfitDatabase.MakeNewOutfit().label = "Anything";

Outfit outfit = outfitDatabase.MakeNewOutfit();
outfit.label = "Nothing";
outfit.filter.SetDisallowAll();

Outfit outfit1 = outfitDatabase.MakeNewOutfit();
outfit1.label = "Worker";
outfit1.filter.SetDisallowAll();
foreach (ThingDef allDef in DefDatabase<ThingDef>.AllDefs)
{
if (allDef.apparel != null && allDef.apparel.defaultOutfitTags != null && allDef.apparel.defaultOutfitTags.Contains("Worker"))
outfit1.filter.SetAllow(allDef, true);
}

Outfit outfit2 = outfitDatabase.MakeNewOutfit();
outfit2.label = "Soldier";
outfit2.filter.SetDisallowAll();
foreach (ThingDef allDef in DefDatabase<ThingDef>.AllDefs)
{
if (allDef.apparel != null && allDef.apparel.defaultOutfitTags != null && allDef.apparel.defaultOutfitTags.Contains("Soldier"))
outfit2.filter.SetAllow(allDef, true);
}

Outfit outfit3 = outfitDatabase.MakeNewOutfit();
outfit3.label = "Nudist";
outfit3.filter.SetDisallowAll();
foreach (ThingDef allDef in DefDatabase<ThingDef>.AllDefs)
{
if (allDef.apparel != null && !allDef.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Legs) && !allDef.apparel.bodyPartGroups.Contains(BodyPartGroupDefOf.Torso))
outfit3.filter.SetAllow(allDef, true);
}

// do my stuff here
foreach (OutfitDef outfitDef in OutfitDefs)
{
Outfit newOutfit = outfitDatabase.MakeNewOutfit();
newOutfit.label = outfitDef.label;
newOutfit.filter = outfitDef.filter;
}
}
}
}
173 changes: 173 additions & 0 deletions DLL_Project/Detours/Pawn_RelationsTracker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
using System.Reflection;
using System.Linq;

using RimWorld;
using Verse;
using UnityEngine;

namespace CommunityCoreLibrary.Detour
{

internal static class _Pawn_RelationsTracker
{

internal static LifeStageDef MechanoidFullyFormed = DefDatabase<LifeStageDef>.GetNamed( "MechanoidFullyFormed" );

internal static FieldInfo _pawn;

internal static Pawn GetPawn( this Pawn_RelationsTracker _this )
{
if( _pawn == null )
{
_pawn = typeof( Pawn_RelationsTracker ).GetField( "pawn", BindingFlags.Instance | BindingFlags.NonPublic );
if( _pawn == null )
{
Log.ErrorOnce( "Unable to reflect Pawn_RelationsTracker.pawn!", 0x12348765 );
}
}
return (Pawn)_pawn.GetValue( _this );
}

internal static bool PawnsAreValidMatches( Pawn pawn1, Pawn pawn2 )
{
/*
Log.Message(
string.Format(
"PawnsAreValidMatches( {0}, {1} )\n\t{0} is human like: {2}\n\t{1} is human like: {3}\n\t{0} gender: {4}\n\t{1} gender: {5}\n\t{0} is gay: {6}\n\t{1} is gay: {7}\n\t{0} PawnKindDef: {8}\n\t{1} PawnKindDef: {9}",
pawn1.LabelShort,
pawn2.LabelShort,
pawn1.RaceProps.Humanlike,
pawn2.RaceProps.Humanlike,
pawn1.gender,
pawn2.gender,
pawn1.story.traits.HasTrait(TraitDefOf.Gay),
pawn2.story.traits.HasTrait(TraitDefOf.Gay),
pawn1.kindDef.defName,
pawn2.kindDef.defName
) );
*/
if(
( !pawn1.RaceProps.Humanlike )||
(
( pawn1.RaceProps.Humanlike )&&
( !pawn2.RaceProps.Humanlike )
)||
( pawn1 == pawn2 )||
( pawn1.RaceProps.fleshType != FleshType.Normal )||
( pawn2.RaceProps.fleshType != FleshType.Normal )
/*||
(
( !pawn1.RaceProps.lifeStageAges.NullOrEmpty() )&&
( pawn1.RaceProps.lifeStageAges.Any( stage => stage.def == MechanoidFullyFormed ) )
)||
(
( !pawn2.RaceProps.lifeStageAges.NullOrEmpty() )&&
( pawn2.RaceProps.lifeStageAges.Any( stage => stage.def == MechanoidFullyFormed ) )
)*/
)
{
return false;
}
return true;
}

internal static float _CompatibilityWith( this Pawn_RelationsTracker _this, Pawn otherPawn )
{
var pawn = _this.GetPawn();
if( !PawnsAreValidMatches( pawn, otherPawn ) )
{
return 0f;
}
return Mathf.Clamp( GenMath.LerpDouble( 0.0f, 20f, 0.45f, -0.45f, Mathf.Abs( pawn.ageTracker.AgeBiologicalYearsFloat - otherPawn.ageTracker.AgeBiologicalYearsFloat ) ), -0.45f, 0.45f) + _this.ConstantPerPawnsPairCompatibilityOffset( otherPawn.thingIDNumber );
}

internal static float _AttractionTo( this Pawn_RelationsTracker _this, Pawn otherPawn )
{
var pawn = _this.GetPawn();

if( !PawnsAreValidMatches( pawn, otherPawn ) )
{
return 0f;
}
float num = 1f;
float num2 = 1f;
float ageBiologicalYearsFloat = pawn.ageTracker.AgeBiologicalYearsFloat;
float ageBiologicalYearsFloat2 = otherPawn.ageTracker.AgeBiologicalYearsFloat;
if( pawn.gender == Gender.Male )
{
if(
( pawn.RaceProps.Humanlike )&&
( pawn.story.traits.HasTrait( TraitDefOf.Gay ) )
)
{
if( otherPawn.gender == Gender.Female )
{
return 0f;
}
}
else if( otherPawn.gender == Gender.Male )
{
return 0f;
}
num2 = GenMath.FlatHill( 16f, 20f, ageBiologicalYearsFloat, ageBiologicalYearsFloat + 15f, ageBiologicalYearsFloat2 );
}
else if( pawn.gender == Gender.Female )
{
if(
( pawn.RaceProps.Humanlike )&&
( pawn.story.traits.HasTrait( TraitDefOf.Gay ) )
)
{
if( otherPawn.gender == Gender.Male )
{
return 0f;
}
}
else if( otherPawn.gender == Gender.Female )
{
num = 0.15f;
}
if( ageBiologicalYearsFloat2 < ageBiologicalYearsFloat - 10f )
{
return 0f;
}
if( ageBiologicalYearsFloat2 < ageBiologicalYearsFloat - 3f )
{
num2 = Mathf.InverseLerp( ageBiologicalYearsFloat - 10f, ageBiologicalYearsFloat - 3f, ageBiologicalYearsFloat2 ) * 0.2f;
}
else
{
num2 = GenMath.FlatHill( 0.2f, ageBiologicalYearsFloat - 3f, ageBiologicalYearsFloat, ageBiologicalYearsFloat + 10f, ageBiologicalYearsFloat + 40f, 0.1f, ageBiologicalYearsFloat2 );
}
}
float num3 = 1f;
num3 *= Mathf.Lerp( 0.2f, 1f, otherPawn.health.capacities.GetEfficiency( PawnCapacityDefOf.Talking ) );
num3 *= Mathf.Lerp( 0.2f, 1f, otherPawn.health.capacities.GetEfficiency( PawnCapacityDefOf.Manipulation ) );
num3 *= Mathf.Lerp( 0.2f, 1f, otherPawn.health.capacities.GetEfficiency( PawnCapacityDefOf.Moving ) );
float num4 = 1f;
foreach( PawnRelationDef current in pawn.GetRelations( otherPawn ) )
{
num4 *= current.attractionFactor;
}
int num5 = 0;
if( otherPawn.RaceProps.Humanlike )
{
num5 = otherPawn.story.traits.DegreeOfTrait( TraitDefOf.Beauty );
}
float num6 = 1f;
if( num5 < 0 )
{
num6 = 0.3f;
}
else if( num5 > 0 )
{
num6 = 2.3f;
}
float num7 = Mathf.InverseLerp( 15f, 18f, ageBiologicalYearsFloat );
float num8 = Mathf.InverseLerp( 15f, 18f, ageBiologicalYearsFloat2 );
return num * num2 * num3 * num4 * num7 * num8 * num6;
}

}

}
Loading

0 comments on commit f24c183

Please sign in to comment.