diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f652b45 --- /dev/null +++ b/.gitignore @@ -0,0 +1,299 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +**/Properties/launchSettings.json + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Typescript v1 declaration files +typings/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# CodeRush +.cr/ + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs diff --git a/About/About.xml b/About/About.xml new file mode 100644 index 0000000..79ce445 --- /dev/null +++ b/About/About.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="utf-8"?> +<ModMetaData> + <name>Dismiss Trader</name> + <author>Mehni</author> + <targetVersion>0.18.0</targetVersion> + <description>Dismiss traders with the click of a button.</description> + <url>https://ludeon.com/forums/index.php?topic=35832.0</url> +</ModMetaData> \ No newline at end of file diff --git a/About/Preview.png b/About/Preview.png new file mode 100644 index 0000000..586eab3 Binary files /dev/null and b/About/Preview.png differ diff --git a/Assemblies/0Harmony.dll b/Assemblies/0Harmony.dll new file mode 100644 index 0000000..904f049 Binary files /dev/null and b/Assemblies/0Harmony.dll differ diff --git a/Assemblies/Dismiss_Trader.dll b/Assemblies/Dismiss_Trader.dll new file mode 100644 index 0000000..5510cd7 Binary files /dev/null and b/Assemblies/Dismiss_Trader.dll differ diff --git a/Defs/DismissalJob.xml b/Defs/DismissalJob.xml new file mode 100644 index 0000000..e785fee --- /dev/null +++ b/Defs/DismissalJob.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="utf-8" ?> + +<Defs> + <JobDef> + <defName>DismissTrader</defName> + <driverClass>Dismiss_Trader.JobDriver_DismissTrader</driverClass> + <reportString>dismissing TargetA.</reportString> + </JobDef> +</Defs> \ No newline at end of file diff --git a/Dismiss_Trader.sln b/Dismiss_Trader.sln new file mode 100644 index 0000000..c21b4c6 --- /dev/null +++ b/Dismiss_Trader.sln @@ -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}") = "Dismiss_Trader", "Source\Dismiss_Trader.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 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..17a3183 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 Mehni + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/Languages/English/Keyed/TraderDismissal.xml b/Languages/English/Keyed/TraderDismissal.xml new file mode 100644 index 0000000..6e891ac --- /dev/null +++ b/Languages/English/Keyed/TraderDismissal.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8" ?> +<LanguageData> + + <GETOUT>Dismiss trader</GETOUT> + +</LanguageData> \ No newline at end of file diff --git a/Source/Dismiss_Trader.cs b/Source/Dismiss_Trader.cs new file mode 100644 index 0000000..b5580c5 --- /dev/null +++ b/Source/Dismiss_Trader.cs @@ -0,0 +1,69 @@ +using System; +using RimWorld; +using Verse; +using Harmony; +using System.Collections; +using System.Collections.Generic; +using System.Reflection.Emit; +using System.Linq; +using System.Reflection; +using UnityEngine; +using Verse.AI; + +namespace Dismiss_Trader +{ + [StaticConstructorOnStartup] + public class HarmonyPatches + { + static HarmonyPatches() + { + HarmonyInstance harmony = HarmonyInstance.Create("mehni.rimworld.traderdismissal.main"); + + harmony.Patch(AccessTools.Method(typeof(FloatMenuMakerMap), "AddHumanlikeOrders"), null, + new HarmonyMethod(typeof(HarmonyPatches), nameof(FloatMenuMakerMap_AddHumanlikeOrdersToDismissTraders_PostFix))); + } + + private static void FloatMenuMakerMap_AddHumanlikeOrdersToDismissTraders_PostFix(ref Vector3 clickPos, ref Pawn pawn, ref List<FloatMenuOption> opts) + { + foreach (LocalTargetInfo target in GenUI.TargetsAt(clickPos, TargetingParameters.ForTrade(), true)) + { + Pawn localpawn = pawn; + LocalTargetInfo dest = target; + if (!pawn.CanReach(dest, PathEndMode.OnCell, Danger.Deadly, false, TraverseMode.ByPawn)) return; + else if (pawn.skills.GetSkill(SkillDefOf.Social).TotallyDisabled) return; + else + { + Pawn pTarg = (Pawn)dest.Thing; + Action action4 = delegate + { + Job job = new Job(TraderDismissalJobDefs.DismissTrader, pTarg) + { + playerForced = true + }; + localpawn.jobs.TryTakeOrderedJob(job, JobTag.Misc); + }; + string str = string.Empty; + if (pTarg.Faction != null) + { + str = " (" + pTarg.Faction.Name + ")"; + } + string label = "GETOUT".Translate(new object[] + { + pTarg.LabelShort + ", " + pTarg.TraderKind.label + }) + str; + Action action = action4; + MenuOptionPriority priority2 = MenuOptionPriority.InitiateSocial; + Thing thing = dest.Thing; + opts.Add(FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption(label, action, priority2, null, thing, 0f, null, null), pawn, pTarg, "ReservedBy")); + } + } + return; + } + } + + [DefOf] + public class TraderDismissalJobDefs + { + public static JobDef DismissTrader; + } +} \ No newline at end of file diff --git a/Source/Dismiss_Trader.csproj b/Source/Dismiss_Trader.csproj new file mode 100644 index 0000000..90139d9 --- /dev/null +++ b/Source/Dismiss_Trader.csproj @@ -0,0 +1,78 @@ +<?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>Dismiss_Trader</RootNamespace> + <AssemblyName>Dismiss_Trader</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>..\Assemblies\</OutputPath> + <DefineConstants> + </DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <Reference Include="0Harmony"> + <HintPath>..\..\..\..\..\..\..\..\Users\Maniak\Documents\RimWorld Mods\0Harmony.dll</HintPath> + </Reference> + <Reference Include="Assembly-CSharp"> + <HintPath>..\..\..\RimWorldWin_Data\Managed\Assembly-CSharp.dll</HintPath> + <Private>False</Private> + </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" /> + <Reference Include="UnityEngine"> + <HintPath>..\..\..\RimWorldWin_Data\Managed\UnityEngine.dll</HintPath> + <Private>False</Private> + </Reference> + <None Include="..\About\About.xml"> + <SubType>Designer</SubType> + </None> + <None Include="..\About\Preview.png" /> + <None Include="..\Defs\**" /> + <None Include="..\Languages\**" /> + <None Include="..\Patches\**" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Dismiss_Trader.cs" /> + <Compile Include="JobDriver_DismissTrader.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> + </PostBuildEvent> + </PropertyGroup> +</Project> \ No newline at end of file diff --git a/Source/JobDriver_DismissTrader.cs b/Source/JobDriver_DismissTrader.cs new file mode 100644 index 0000000..37fda8e --- /dev/null +++ b/Source/JobDriver_DismissTrader.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using RimWorld; +using Verse; +using Verse.AI; +using UnityEngine; +using Verse.AI.Group; + +namespace Dismiss_Trader +{ + class JobDriver_DismissTrader : JobDriver + { + private Pawn Trader + { + get + { + return (Pawn)base.TargetThingA; + } + } + + public override bool TryMakePreToilReservations() + { + return this.pawn.Reserve(this.Trader, this.job, 1, -1, null); + } + + //approach: find Lord transition that is the regular time-out and add another (very short) Trigger_TicksPassed. That'll then fire, and the traders will leave. + + //other (failed) approaches: + //- inheriting from LordJob_TradeWithColony and overriding the stategraph. Set a bool in the job, which works as a trigger. Still seems like the "correct" and OOP approach, but I suck at C# + //- adding new LordToil_ExitMapAndEscortCarriers() & telling the lord to jump to it. (lord null, somehow not registered in graph?) + //- Outright removing the lord. Works, but also removes the traderflag, defending at exit and the group behaviour. Bad. + //- transpile all the things! (ain't noone got time for that) + protected override IEnumerable<Toil> MakeNewToils() + { + this.FailOnDespawnedOrNull(TargetIndex.A); + yield return Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch).FailOn(() => !this.Trader.CanTradeNow); + Toil trade = new Toil(); + trade.initAction = delegate + { + Pawn actor = trade.actor; + if (this.Trader.CanTradeNow) + { + Lord lord = Trader.GetLord(); + List<Transition> transitions = lord.Graph.transitions.ToList(); + for (int i = 0; i < transitions.Count; i++) + { + if (i == 7) + { + transitions[i].triggers.Add(new Trigger_TicksPassed(20)); + } + } + } + }; + yield return trade; + } + } +} diff --git a/Source/Properties/AssemblyInfo.cs b/Source/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..bc5476d --- /dev/null +++ b/Source/Properties/AssemblyInfo.cs @@ -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("Dismiss_Trader")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Dismiss_Trader")] +[assembly: AssemblyCopyright("Copyright © Mehni 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("0.18.0.1")] +[assembly: AssemblyFileVersion("0.18.0.1")]