Skip to content

Commit

Permalink
Merge pull request #3 from alycecil/ThinkNode
Browse files Browse the repository at this point in the history
Thinknodes - Base
  • Loading branch information
jecrell authored Nov 3, 2018
2 parents 49e8dba + 31c7423 commit e8d1212
Show file tree
Hide file tree
Showing 8 changed files with 297 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Source/AllModdingComponents/ThinkNodes.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2009
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThinkNodes", "ThinkNodes\ThinkNodes.csproj", "{D7D21B4A-1DA7-41D8-B202-C58CA8FA62AA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D7D21B4A-1DA7-41D8-B202-C58CA8FA62AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7D21B4A-1DA7-41D8-B202-C58CA8FA62AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7D21B4A-1DA7-41D8-B202-C58CA8FA62AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7D21B4A-1DA7-41D8-B202-C58CA8FA62AA}.Release|Any CPU.Build.0 = Release|Any CPU
{DE5B7748-333A-428F-BCA9-4DB67FB289A3}.Debug|Any CPU.ActiveCfg = Release|x86
{DE5B7748-333A-428F-BCA9-4DB67FB289A3}.Release|Any CPU.ActiveCfg = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {28CF9A73-5333-4EB3-BFCC-3FBEDDA19200}
EndGlobalSection
EndGlobal
41 changes: 41 additions & 0 deletions Source/AllModdingComponents/ThinkNodes/JobGiver_Capture.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using RimWorld;
using Verse;
using Verse.AI;

namespace ThinkNodes
{
public class JobGiver_Capture : ThinkNode_JobGiver
{
private float targetAcquireRadius;

protected override Job TryGiveJob(Pawn pawn)
{
bool Validator(Thing t)
{
Pawn pawn3 = (Pawn) t;
if (pawn3 == null) return false;
var hostileTo = pawn3.Faction == null || pawn3.Faction.HostileTo(Faction.OfPlayer) || pawn3.Faction.def.hidden;
return pawn3.Downed && hostileTo && !pawn3.InBed() && pawn.CanReserve(pawn3) && !pawn3.IsForbidden(pawn);
}

Pawn victim = (Pawn)GenClosest.ClosestThingReachable(pawn.Position, pawn.Map,
ThingRequest.ForGroup(ThingRequestGroup.Pawn), PathEndMode.OnCell, TraverseParms.For(pawn),
targetAcquireRadius, Validator);
if (victim == null)
{
return null;
}

Building_Bed buildingBed = RestUtility.FindBedFor(victim, pawn, true, false) ??
RestUtility.FindBedFor(victim, pawn, true, false, true);
if (buildingBed == null)
{
return null;
}

var job = new Job(JobDefOf.Capture, victim, buildingBed) {count = 1};

return job;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using RimWorld;
using Verse;
using Verse.AI;

namespace ThinkNodes
{
public class JobGiver_GoToClosestThingDef : ThinkNode_JobGiver
{
Danger maxDanger = Verse.Danger.Some;
ThingDef thingDef = ThingDefOf.PartySpot;

protected override Job TryGiveJob(Pawn pawn)
{
var thing = ThingToDo(pawn);

if (thing != null)
{
if (!thing.Position.IsValid)
return (Job) null;
if (!pawn.CanReach((LocalTargetInfo) thing.Position, PathEndMode.ClosestTouch, maxDanger))
{
return (Job) null;
}

if (IntVec3Utility.DistanceTo(thing.Position, pawn.Position) < 10f)
{
return null;
}

return new Job(JobDefOf.Goto, (LocalTargetInfo) thing.Position)
{
locomotionUrgency = LocomotionUrgency.Sprint
};
}
else
return null;
}

private Thing ThingToDo(Pawn pawn)
{
ThingDef singleDef = WhatDef();

var thingRequest = ThingRequest.ForDef(singleDef);
Thing closestPosition = ClosestPosition(pawn, thingRequest);
return closestPosition;
}

private Thing ClosestPosition(Pawn pawn, ThingRequest thingRequest)
{
return GenClosest.ClosestThingReachable(pawn.Position, pawn.Map,
thingRequest, PathEndMode.Touch,
Danger(pawn),
200f);
}

private TraverseParms Danger(Pawn pawn)
{
return TraverseParms.For(pawn, maxDanger);
}

protected virtual ThingDef WhatDef()
{
return thingDef;
}
}
}
36 changes: 36 additions & 0 deletions Source/AllModdingComponents/ThinkNodes/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ThinkNodes")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ThinkNodes - JecsTools")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d7d21b4a-1da7-41d8-b202-c58ca8fa62aa")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Linq;
using Verse;
using Verse.AI;

namespace ThinkNodes
{
public class ThinkNode_ConditionalHediff : ThinkNode_Conditional
{
public string hediffDef;

protected override bool Satisfied(Pawn pawn)
{
if (pawn.Drafted) return false;
foreach (var unused in pawn.health.hediffSet.hediffs.Where(x => x.def.defName.EqualsIgnoreCase(hediffDef)))
{
return true;
}

return false;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Collections.Generic;
using Verse;
using Verse.AI;

namespace ThinkNodes
{
public class ThinkNodeConditionalWorkTypes : ThinkNode_Conditional
{
private List<WorkTypeDef> workTypeDefs = new List<WorkTypeDef>();

protected override bool Satisfied(Pawn pawn)
{
foreach (var _def in workTypeDefs)
{
if (pawn.IsColonist && (pawn?.workSettings?.WorkIsActive(_def) ?? false))
return true;
}


return false;
}
}
}
76 changes: 76 additions & 0 deletions Source/AllModdingComponents/ThinkNodes/ThinkNodes.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D7D21B4A-1DA7-41D8-B202-C58CA8FA62AA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ThinkNodes</RootNamespace>
<AssemblyName>ThinkNodes</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>false</DebugSymbols>
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Assemblies\</OutputPath>
<DefineConstants>
</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\ThinkNodes - Release\Assemblies\</OutputPath>
<DefineConstants>
</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp, Version=1.0.6864.30166, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\..\..\..\RimWorldWin64_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<None Include="..\About\**" />
<None Include="..\Defs\**" />
<None Include="..\Languages\**" />
<None Include="..\Patches\**" />
</ItemGroup>
<ItemGroup>
<Compile Include="JobGiver_Capture.cs" />
<Compile Include="JobGiver_GoToClosestThingDef.cs" />
<Compile Include="ThinkNode_ConditionalHediff.cs" />
<Compile Include="ThinkNode_ConditionalWorkTypesDef.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
<PropertyGroup>
<StartAction>Program</StartAction>
<StartProgram>$(SolutionDir)..\..\RimWorldWin.exe</StartProgram>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>echo F|xcopy "$(ProjectDir)..\About\About-$(ConfigurationName).xml" "$(TargetDir)..\About\About.xml" /C /Y /K /Q /D
IF /I "$(ConfigurationName)" == "Release"; echo F|xcopy "$(ProjectDir)..\About\Preview.png" "$(TargetDir)..\About\Preview.png" /S /C /Y /K /Q /D
IF /I "$(ConfigurationName)" == "Release"; xcopy "$(ProjectDir)..\Assemblies" "$(TargetDir)..\Assemblies" /S /C /Y /K /I /Q /D
IF /I "$(ConfigurationName)" == "Release"; xcopy "$(ProjectDir)..\Defs" "$(TargetDir)..\Defs" /S /C /Y /K /I /Q /D
IF /I "$(ConfigurationName)" == "Release"; xcopy "$(ProjectDir)..\Patches" "$(TargetDir)..\Patches" /S /C /Y /K /I /Q /D
IF /I "$(ConfigurationName)" == "Release"; xcopy "$(ProjectDir)..\Languages" "$(TargetDir)..\Languages" /S /C /Y /K /I /Q /D
IF /I "$(ConfigurationName)" == "Release"; xcopy "$(ProjectDir)..\Sounds" "$(TargetDir)..\Sounds" /S /C /Y /K /I /Q /D
IF /I "$(ConfigurationName)" == "Release"; xcopy "$(ProjectDir)..\Textures" "$(TargetDir)..\Textures" /S /C /Y /K /I /Q /D
IF /I "$(ConfigurationName)" == "Release"; IF EXIST "$(ProjectDir)..\LICENSE"; copy "$(ProjectDir)..\LICENSE" "$(TargetDir)..\LICENSE" /Y</PostBuildEvent>
</PropertyGroup>
</Project>
6 changes: 6 additions & 0 deletions Source/JecsTools.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PawnShields", "AllModdingCo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompBalloon", "AllModdingComponents\CompBalloon\CompBalloon.csproj", "{CE293DBE-D76A-4F24-A086-42051996698D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ThinkNodes", "AllModdingComponents\ThinkNodes\ThinkNodes.csproj", "{D7D21B4A-1DA7-41D8-B202-C58CA8FA62AA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -111,6 +113,10 @@ Global
{CE293DBE-D76A-4F24-A086-42051996698D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CE293DBE-D76A-4F24-A086-42051996698D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CE293DBE-D76A-4F24-A086-42051996698D}.Release|Any CPU.Build.0 = Release|Any CPU
{D7D21B4A-1DA7-41D8-B202-C58CA8FA62AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D7D21B4A-1DA7-41D8-B202-C58CA8FA62AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D7D21B4A-1DA7-41D8-B202-C58CA8FA62AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D7D21B4A-1DA7-41D8-B202-C58CA8FA62AA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit e8d1212

Please sign in to comment.