Skip to content

Commit

Permalink
refactors project
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Jun 13, 2021
1 parent 15891b6 commit b7901e2
Show file tree
Hide file tree
Showing 17 changed files with 211 additions and 236 deletions.
Binary file removed 1.2/Assemblies/0Harmony.dll
Binary file not shown.
Binary file modified 1.2/Assemblies/0MultiplayerAPI.dll
Binary file not shown.
Binary file modified 1.2/Assemblies/AchtungMod.dll
Binary file not shown.
14 changes: 7 additions & 7 deletions Achtung.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30413.136
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Achtung", "Source\Achtung.csproj", "{8BD5A28F-96C4-43B4-907F-600AA0162F84}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Achtung", "Source\Achtung.csproj", "{8BD5A28F-96C4-43B4-907F-600AA0162F84}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
RimWorld 1.1|Any CPU = RimWorld 1.1|Any CPU
RimWorld 1.2|Any CPU = RimWorld 1.2|Any CPU
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8BD5A28F-96C4-43B4-907F-600AA0162F84}.RimWorld 1.1|Any CPU.ActiveCfg = RimWorld 1.1|Any CPU
{8BD5A28F-96C4-43B4-907F-600AA0162F84}.RimWorld 1.1|Any CPU.Build.0 = RimWorld 1.1|Any CPU
{8BD5A28F-96C4-43B4-907F-600AA0162F84}.RimWorld 1.2|Any CPU.ActiveCfg = RimWorld 1.2|Any CPU
{8BD5A28F-96C4-43B4-907F-600AA0162F84}.RimWorld 1.2|Any CPU.Build.0 = RimWorld 1.2|Any CPU
{8BD5A28F-96C4-43B4-907F-600AA0162F84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8BD5A28F-96C4-43B4-907F-600AA0162F84}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8BD5A28F-96C4-43B4-907F-600AA0162F84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8BD5A28F-96C4-43B4-907F-600AA0162F84}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
10 changes: 10 additions & 0 deletions LoadFolders.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<loadFolders>
<v1.1>
<li>/</li>
<li>1.1</li>
</v1.1>
<v1.2>
<li>/</li>
<li>1.2</li>
</v1.2>
</loadFolders>
135 changes: 75 additions & 60 deletions Source/Achtung.csproj
Original file line number Diff line number Diff line change
@@ -1,73 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<ProjectGuid>{8BD5A28F-96C4-43B4-907F-600AA0162F84}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AchtungMod</RootNamespace>
<AssemblyName>AchtungMod</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Optimize>true</Optimize>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TargetFramework>net472</TargetFramework>
<LangVersion>8.0</LangVersion>
<PlatformTarget>x64</PlatformTarget>
<OutputPath>..\1.2\Assemblies\</OutputPath>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<Version>3.1.7.0</Version>
<Copyright>© July, 2016</Copyright>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'RimWorld 1.1' ">
<OutputPath>..\1.1\Assemblies\</OutputPath>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugSymbols>false</DebugSymbols>
<Optimize>true</Optimize>
<DebugType>none</DebugType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'RimWorld 1.2'">
<OutputPath>..\1.2\Assemblies\</OutputPath>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<DefineConstants>RW12;TRACE;DEBUG</DefineConstants>
<Optimize>false</Optimize>
<DebugType>portable</DebugType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<Compile Include="Colonist.cs" />
<Compile Include="Controller.cs" />
<Compile Include="CrossPromotion.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="ModCounter.cs" />
<Compile Include="ForcedFloatMenuOption.cs" />
<Compile Include="ForcedJob.cs" />
<Compile Include="ForcedWork.cs" />
<Compile Include="JobDriver_CleanRoom.cs" />
<Compile Include="JobDriver_FightFire.cs" />
<Compile Include="JobDriver_Thoroughly.cs" />
<Compile Include="Main.cs" />
<Compile Include="MultiAction.cs" />
<Compile Include="MultiActions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Tools.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Lib.Harmony">
<Version>2.0.4</Version>
</PackageReference>
<PackageReference Include="RimWorld.MultiplayerAPI">
<Version>0.2.0</Version>
<PackageReference Include="Krafs.Rimworld.Ref" Version="1.2.2905" GeneratePathProperty="true" />
<PackageReference Include="Lib.Harmony" Version="2.0.4" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.NETCore.Platforms" Version="5.0.2" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies.net472" Version="1.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="RimWorld.MultiplayerAPI" Version="0.3.0" />
<PackageReference Include="TaskPubliciser" Version="1.0.3" />
</ItemGroup>
<Choose>
<When Condition=" '$(Configuration)' == 'RimWorld 1.1' ">
<ItemGroup>
<PackageReference Include="Krafs.Rimworld.Ref">
<Version>1.1.2654</Version>
</PackageReference>
</ItemGroup>
</When>
<When Condition=" '$(Configuration)' == 'RimWorld 1.2' ">
<ItemGroup>
<PackageReference Include="Krafs.Rimworld.Ref">
<Version>1.2.2753</Version>
</PackageReference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

<Target Name="MyCode" BeforeTargets="UpdateReferences">
<PropertyGroup>
<AssemblyCSharp>$(PkgKrafs_Rimworld_Ref)\ref\net472\Assembly-CSharp.dll</AssemblyCSharp>
<PubliciseOutputPath>$(PkgKrafs_Rimworld_Ref)\ref\net472\</PubliciseOutputPath>
<AssemblyCSharp_Publicised>$(PubliciseOutputPath)Assembly-CSharp_publicised.dll</AssemblyCSharp_Publicised>
</PropertyGroup>
<Message Importance="High" Text="Publicising Rimworld Assembly ..." />
<Publicise TargetAssemblyPath="$(AssemblyCSharp)" OutputPath="$(PubliciseOutputPath)" Condition="Exists('$(AssemblyCSharp)')" />
<Message Importance="High" Text="Replacing reference to un-publicised assemblies with publicised equivalents ..." />
<ItemGroup>
<Reference Include="$(AssemblyCSharp_Publicised)">
<SpecificVersion>false</SpecificVersion>
<HintPath>$(AssemblyCSharp_Publicised)</HintPath>
<Implicit>true</Implicit>
<Private>false</Private>
</Reference>
</ItemGroup>
</Target>

<Target Name="UpdateReferences" AfterTargets="ResolveLockFileReferences">
<Message Importance="High" Text="Remove References ..." />
<ItemGroup>
<Reference Remove="$(PkgKrafs_Rimworld_Ref)\ref\net472\Assembly-CSharp.dll" />
</ItemGroup>
</Target>

<PropertyGroup>
<PostBuildEvent>ModBuilder AssemblyVersion -file "$(TargetPath)" -save "$(ProjectName)-version"
ModBuilder XMLPut -file "$(SolutionDir)About\Manifest.xml" -xpath /Manifest/version -value "{{$(ProjectName)-version}}"
"$(ProjectDir)Install.bat" "$(ProjectDir)" "$(ProjectName)" "1.1 1.2 About Assemblies Languages Textures"</PostBuildEvent>
<PostBuildEvent>echo Postprocessing
where ModBuilder 2&gt; nul | find /i "ModBuilder.exe"
if not errorlevel 1 (
ModBuilder AssemblyVersion -file "$(MSBuildProjectDirectory)\$(OutputPath)$(AssemblyName).dll" -save "$(MSBuildProjectName)-version"
ModBuilder XMLPut -file "$(SolutionDir)About\Manifest.xml" -xpath /Manifest/version -value "{{$(MSBuildProjectName)-version}}"
)
if defined INSTALL_MOD (
"%INSTALL_MOD%" "$(Configuration)" "$(SolutionDir)" "$(MSBuildProjectName)" "1.1 1.2 About Assemblies Languages Textures" "LoadFolders.xml"
)
</PostBuildEvent>
<Company>Brrainz</Company>
<Authors>Andreas Pardeike</Authors>
<Description>Command your colonists like a boss!</Description>
<PackageProjectUrl>https://github.com/pardeike/Achtung2</PackageProjectUrl>
<RepositoryUrl>https://github.com/pardeike/Achtung2</RepositoryUrl>
</PropertyGroup>

</Project>
6 changes: 3 additions & 3 deletions Source/Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public static IEnumerable<FloatMenuOption> AchtungChoicesAtFor(Vector3 clickPos,

private static void DrawForcedJobs()
{
var forcedWork = Find.World.GetComponent<ForcedWork>();
var forcedWork = ForcedWork.Instance;
var map = Find.CurrentMap;
if (map == null || forcedWork == null)
return;
Expand Down Expand Up @@ -317,7 +317,7 @@ private static void DrawForcedJobs()
// .Where(t => t != null)
// .Do(thing => Tools.DebugPosition(thing.Position.ToVector3(), new Color(1f, 0f, 0f, 0.2f)));
//var forcedWork = Find.World.GetComponent<ForcedWork>();
//var forcedWork = ForcedWork.Instance;
//forcedWork.GetForbiddenLocations()
// .Do(cell => Tools.DebugPosition(cell.ToVector3(), new Color(0f, 0f, 1f, 0.2f)));
}*/
Expand Down Expand Up @@ -386,4 +386,4 @@ public bool HandleEvents()
return runOriginal;
}
}
}
}
4 changes: 2 additions & 2 deletions Source/ForcedFloatMenuOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ForcedMultiFloatMenuOption(string label) : base(label, null, MenuOptionPr

public override bool ForceAction()
{
var forcedWork = Find.World.GetComponent<ForcedWork>();
var forcedWork = ForcedWork.Instance;
var sharedCells = new List<IntVec3>();

var result = false;
Expand Down Expand Up @@ -157,7 +157,7 @@ public static bool ForceActionSynced(Pawn forcePawn, WorkGiver_Scanner forceWork
{
var cell = new IntVec3(x, 0, z);

var forcedWork = Find.World.GetComponent<ForcedWork>();
var forcedWork = ForcedWork.Instance;
forcedWork.Prepare(forcePawn);

var workgiverDefs = ForcedWork.GetCombinedDefs(forceWorkgiver);
Expand Down
17 changes: 6 additions & 11 deletions Source/ForcedJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,13 @@ public static int MaterialScore(LocalTargetInfo item)
if (TypeScores.TryGetValue(thing.def, out var n))
scoreThing = n;

var blueprint = thing as Blueprint_Build;
if (blueprint != null)
if (thing is Blueprint_Build blueprint)
{
if (TypeScores.TryGetValue(blueprint.def.entityDefToBuild, out n))
scoreBlueprint = n;
}

var frame = thing as Frame;
if (frame != null)
if (thing is Frame frame)
{
if (TypeScores.TryGetValue(frame.def.entityDefToBuild, out n))
scoreFrame = n;
Expand Down Expand Up @@ -170,9 +168,8 @@ public IEnumerable<LocalTargetInfo> GetSortedTargets(HashSet<int> planned)
.Select(target => target.item);
}

public bool IsForbiddenCell(Map map, IntVec3 cell)
public bool IsForbiddenCell(IntVec3 cell)
{
if (pawn.Map != map) return false;
return targets.Any(target => target.item.Cell == cell && target.IsBuilding());
}

Expand Down Expand Up @@ -211,7 +208,7 @@ public static bool ContinueJob(Pawn_JobTracker tracker, Job lastJob, Pawn pawn,
_ = lastJob;

if (pawn == null || pawn.IsColonist == false) return false;
var forcedWork = Find.World.GetComponent<ForcedWork>();
var forcedWork = ForcedWork.Instance;

var forcedJob = forcedWork.GetForcedJob(pawn);
if (forcedJob == null)
Expand Down Expand Up @@ -418,11 +415,9 @@ public bool IsBuilding()
{
if (item.HasThing == false) return false;
var thing = item.Thing;
var frame = thing as Frame;
if (frame != null)
if (thing is Frame frame)
return frame.def.entityDefToBuild == ThingDefOf.Wall;
var blueprint = thing as Blueprint_Build;
if (blueprint != null)
if (thing is Blueprint_Build blueprint)
return blueprint.def.entityDefToBuild == ThingDefOf.Wall;
return false;
}
Expand Down
37 changes: 25 additions & 12 deletions Source/ForcedWork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,23 @@ public class ForcedWork : WorldComponent
private int counter;

readonly HashSet<Pawn> preparing = new HashSet<Pawn>();
readonly Dictionary<Pawn, HashSet<IntVec3>> forbiddenLocations = new Dictionary<Pawn, HashSet<IntVec3>>();
//readonly Dictionary<Pawn, HashSet<IntVec3>> forbiddenLocations = new Dictionary<Pawn, HashSet<IntVec3>>();

public ForcedWork(World world) : base(world)
public ForcedWork(World world) : base(world) { }

static ForcedWork instance = null;
public static ForcedWork Instance
{
get
{
if (instance == null)
instance = Find.World.GetComponent<ForcedWork>();
return instance;
}
set
{
instance = value;
}
}

private static List<WorkGiverDef> AllWorkerDefs<T>() where T : class
Expand Down Expand Up @@ -159,37 +172,37 @@ public IEnumerable<ForcedJob> ForcedJobsForMap(Map map)

public bool IsForbiddenCell(Map map, IntVec3 cell)
{
var jobs = allForcedJobs.Values.SelectMany(forcedJobs => forcedJobs.jobs);
return jobs.Any(job => job.IsForbiddenCell(map, cell));
return ForcedJobsForMap(map)
.Any(job => job.IsForbiddenCell(cell));
}

public void AddForbiddenLocation(Pawn pawn, IntVec3 cell)
/*public void AddForbiddenLocation(Pawn pawn, IntVec3 cell)
{
if (forbiddenLocations.TryGetValue(pawn, out var cells) == false)
{
cells = new HashSet<IntVec3>();
forbiddenLocations.Add(pawn, cells);
}
_ = cells.Add(cell);
}
}*/

public void RemoveForbiddenLocations(Pawn pawn)
/*public void RemoveForbiddenLocations(Pawn pawn)
{
_ = forbiddenLocations.Remove(pawn);
}
}*/

public HashSet<IntVec3> GetForbiddenLocations()
/*public HashSet<IntVec3> GetForbiddenLocations()
{
var result = new HashSet<IntVec3>();
forbiddenLocations.Do(pair => result.UnionWith(pair.Value));
return result;
}
}*/

public bool IsForbiddenLocation(IntVec3 cell)
/*public bool IsForbiddenLocation(IntVec3 cell)
{
return forbiddenLocations
.Any(pair => pair.Value.Contains(cell));
}
}*/

public override void WorldComponentTick()
{
Expand Down
28 changes: 0 additions & 28 deletions Source/Install.bat

This file was deleted.

Loading

0 comments on commit b7901e2

Please sign in to comment.