Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
LocoNeko authored Dec 11, 2018
1 parent 110eba0 commit 5bcad56
Show file tree
Hide file tree
Showing 27 changed files with 545 additions and 0 deletions.
10 changes: 10 additions & 0 deletions About/About.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>

<ModMetaData>
<name>Roads of the Rim</name>
<author>Loconeko</author>
<targetVersion>1.0.2026</targetVersion>
<description>V0.1
This mod adds the ability to build roads on the world map
</description>
</ModMetaData>
Binary file added About/Preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Assemblies/0Harmony.dll
Binary file not shown.
Binary file added Assemblies/RoadsOfTheRim.dll
Binary file not shown.
Binary file added Assemblies/RoadsOfTheRim.pdb
Binary file not shown.
31 changes: 31 additions & 0 deletions Defs/RoadBuildableDefs/RoadBuildableDefs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<RoadsOfTheRim.RoadBuildableDef>
<defName>RoadsOfTheRim_DirtPath</defName>
<label>Dirt path</label>
<movementCostMultiplier>0.75</movementCostMultiplier>
<workNeeded>60000</workNeeded>
</RoadsOfTheRim.RoadBuildableDef>

<RoadsOfTheRim.RoadBuildableDef>
<defName>RoadsOfTheRim_DirtRoad</defName>
<label>Dirt road</label>
<movementCostMultiplier>0.6</movementCostMultiplier>
<workNeeded>120000</workNeeded>
</RoadsOfTheRim.RoadBuildableDef>

<RoadsOfTheRim.RoadBuildableDef>
<defName>RoadsOfTheRim_StoneRoad</defName>
<label>Stone road</label>
<movementCostMultiplier>0.5</movementCostMultiplier>
<workNeeded>180000</workNeeded>
</RoadsOfTheRim.RoadBuildableDef>

<RoadsOfTheRim.RoadBuildableDef>
<defName>RoadsOfTheRim_AsphaltRoad</defName>
<label>Asphalt road</label>
<movementCostMultiplier>0.4</movementCostMultiplier>
<workNeeded>360000</workNeeded>
</RoadsOfTheRim.RoadBuildableDef>

</Defs>
24 changes: 24 additions & 0 deletions Defs/WorldObjectDefs/WorldObjects.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<Defs>
<WorldObjectDef>
<defName>RoadConstructionSite</defName>
<label>road construction site</label>
<description>The site of a road under construction</description>
<worldObjectClass>RoadsOfTheRim.RoadConstructionSite</worldObjectClass>
<texture>World/WorldObjects/ConstructionSite</texture>
<useDynamicDrawer>true</useDynamicDrawer>
<expandingIcon>true</expandingIcon>
<expandingIconTexture>World/WorldObjects/Expanding/ConstructionSite</expandingIconTexture>
<expandingIconPriority>200</expandingIconPriority>
<!--
<comps>
<li Class="RoadsOfTheRim.CompProperties_RoadsOfTheRimConstructionSite" />
</comps>
-->
<!--
<inspectorTabs>
<li>RoadsOfTheRim.WITab_RoadConstructionSite</li>
</inspectorTabs>
-->
</WorldObjectDef>
</Defs>
14 changes: 14 additions & 0 deletions Languages/English/Keyed/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>

<RoadsOfTheRim>Roads of the Rim</RoadsOfTheRim>
<RoadsOfTheRimAddConstructionSite>Construct</RoadsOfTheRimAddConstructionSite>
<RoadsOfTheRimAddConstructionSiteDescription>Create road construction site</RoadsOfTheRimAddConstructionSiteDescription>
<RoadsOfTheRimRemoveConstructionSite>Cancel construction</RoadsOfTheRimRemoveConstructionSite>
<RoadsOfTheRimRemoveConstructionSiteDescription>Remove road construction site</RoadsOfTheRimRemoveConstructionSiteDescription>
<RoadsOfTheRimSettingsCategoryLabel>Roads of the Rim</RoadsOfTheRimSettingsCategoryLabel>
<RoadsOfTheRimSettingsBaseEffort>Base multiplier to road building costs</RoadsOfTheRimSettingsBaseEffort>
<RoadsOfTheRimSettingsOverrideCosts>Override standard movement multipliers [NOT IMPLEMENTED]</RoadsOfTheRimSettingsOverrideCosts>
<RoadsOfTheRimBuildConstructionSiteAlreadyHere>There is already a construction site here</RoadsOfTheRimBuildConstructionSiteAlreadyHere>
<RoadsOfTheRimBuildConstructionSiteNotAlreadyHere>There is no construction site here</RoadsOfTheRimBuildConstructionSiteNotAlreadyHere>
</LanguageData>
39 changes: 39 additions & 0 deletions Patches/patches.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8" ?>
<Patch>
<Operation Class="PatchOperationReplace">
<xpath>*/RoadDef[defName = "DirtPath"]/movementCostMultiplier</xpath>
<value>
<movementCostMultiplier>0.75</movementCostMultiplier>
</value>
</Operation>

<Operation Class="PatchOperationReplace">
<xpath>*/RoadDef[defName = "DirtRoad"]/movementCostMultiplier</xpath>
<value>
<movementCostMultiplier>0.6</movementCostMultiplier>
</value>
</Operation>

<Operation Class="PatchOperationReplace">
<xpath>*/RoadDef[defName = "StoneRoad"]/movementCostMultiplier</xpath>
<value>
<movementCostMultiplier>0.5</movementCostMultiplier>
</value>
</Operation>

<Operation Class="PatchOperationReplace">
<xpath>*/RoadDef[defName = "AncientAsphaltRoad"]/movementCostMultiplier</xpath>
<value>
<movementCostMultiplier>0.4</movementCostMultiplier>
</value>
</Operation>

<Operation Class="PatchOperationReplace">
<xpath>*/RoadDef[defName = "AncientAsphaltHighway"]/movementCostMultiplier</xpath>
<value>
<movementCostMultiplier>0.4</movementCostMultiplier>
</value>
</Operation>


</Patch>
17 changes: 17 additions & 0 deletions Source/RoadsOfTheRim/RoadsOfTheRim.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RoadsOfTheRim", "RoadsOfTheRim\RoadsOfTheRim.csproj", "{6EB5555F-F9BD-4955-A180-82BE2ECB5ED7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6EB5555F-F9BD-4955-A180-82BE2ECB5ED7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6EB5555F-F9BD-4955-A180-82BE2ECB5ED7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6EB5555F-F9BD-4955-A180-82BE2ECB5ED7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6EB5555F-F9BD-4955-A180-82BE2ECB5ED7}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
210 changes: 210 additions & 0 deletions Source/RoadsOfTheRim/RoadsOfTheRim/ModMain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
using Harmony;
using System.Xml;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using Verse;
using System.Reflection;
using RimWorld.Planet;
using Verse.Sound;
using UnityEngine;

namespace RoadsOfTheRim
{
public class RoadsOfTheRimSettings : ModSettings
{
/* Mod setting : the basic effort needed to build a road must be between 1 and 10 */
public const int MinBaseEffort = 1;
public const int DefaultBaseEffort = 5;
public const int MaxBaseEffort = 10;
public static int BaseEffort = DefaultBaseEffort;
public static bool OverrideCosts = true;

public override void ExposeData()
{
base.ExposeData();
Scribe_Values.Look<int>(ref BaseEffort, "BaseEffort", DefaultBaseEffort, true);
Scribe_Values.Look<bool>(ref OverrideCosts, "OverrideCosts", true, true);
}
}

public class RoadsOfTheRim : Mod
{
public static RoadsOfTheRimSettings settings;

public RoadsOfTheRim(ModContentPack content) : base(content)
{
settings = GetSettings<RoadsOfTheRimSettings>();
var harmony = HarmonyInstance.Create("Loconeko.Rimworld.RoadsOfTheRim");
/* Patching the Caravan's Gizmos to add "BuildRoad" */
MethodInfo method = typeof(Caravan).GetMethod("GetGizmos");
HarmonyMethod prefix = null;
HarmonyMethod postfix = new HarmonyMethod(typeof(RoadsOfTheRim).GetMethod("GetGizmosPostfix")); ;
harmony.Patch(method, prefix, postfix, null);

//Log.Message("[RoadsOfTheRim] Loaded");
}

public override string SettingsCategory() => "RoadsOfTheRimSettingsCategoryLabel".Translate();

public override void DoSettingsWindowContents(Rect rect)
{
Listing_Standard listing_Standard = new Listing_Standard();
listing_Standard.Begin(rect);
listing_Standard.Label("RoadsOfTheRimSettingsBaseEffort".Translate() + ": " + RoadsOfTheRimSettings.BaseEffort);
listing_Standard.Gap();
RoadsOfTheRimSettings.BaseEffort = (int)listing_Standard.Slider((float)RoadsOfTheRimSettings.BaseEffort, (float)RoadsOfTheRimSettings.MinBaseEffort, (float)RoadsOfTheRimSettings.MaxBaseEffort);
listing_Standard.Gap();
listing_Standard.CheckboxLabeled("RoadsOfTheRimSettingsOverrideCosts".Translate() + ": ", ref RoadsOfTheRimSettings.OverrideCosts);
listing_Standard.End();
settings.Write();
}

public static void GetGizmosPostfix(ref IEnumerable<Gizmo> __result, Caravan __instance)
{
__result = __result.Concat(new Gizmo[] { AddConstructionSite(__instance) })
.Concat(new Gizmo[] { RemoveConstructionSite(__instance) });
// TO DO next one should be : work on road which will cost time and ressource and eventually ends up with the road built
}

public static Command AddConstructionSite(Caravan caravan)
{
Command_Action command_Action = new Command_Action();
command_Action.defaultLabel = "RoadsOfTheRimAddConstructionSite".Translate();
command_Action.defaultDesc = "RoadsOfTheRimAddConstructionSiteDescription".Translate();
command_Action.icon = ContentFinder<Texture2D>.Get("UI/Commands/AddConstructionSite", true);
command_Action.action = delegate ()
{
/* Go through all the RoadBuildableDefs and show them in a float menu when creating construction site*/
List<FloatMenuOption> list = new List<FloatMenuOption>();
foreach (RoadBuildableDef thisRoadBuildableDef in DefDatabase<RoadBuildableDef>.AllDefs)
{
list.Add(new FloatMenuOption(
thisRoadBuildableDef.label + " (movement :" + thisRoadBuildableDef.movementCostMultiplier + ")",
delegate ()
{
SoundStarter.PlayOneShotOnCamera(SoundDefOf.Tick_High, null);
CreateConstructionSite(caravan, thisRoadBuildableDef);
}
));
}

if (list.Count > 0)
{
FloatMenu floatMenu = new FloatMenu(list);
floatMenu.vanishIfMouseDistant = true;
Find.WindowStack.Add(floatMenu);
}
};
// Test when the AddConstructionSite action should be disabled
// - Check whether there's already a construction site here
// - TO DO : Check whether there's already a road here
bool ConstructionSiteAlreadyHere = false;
try
{
ConstructionSiteAlreadyHere = Find.WorldObjects.AnyWorldObjectOfDefAt(DefDatabase<WorldObjectDef>.GetNamed("RoadConstructionSite", true), caravan.Tile);
}
catch
{

}
if (ConstructionSiteAlreadyHere)
{
command_Action.Disable("RoadsOfTheRimBuildConstructionSiteAlreadyHere".Translate());
}
return command_Action;
}

public static Command RemoveConstructionSite(Caravan caravan)
{
Command_Action command_Action = new Command_Action();
command_Action.defaultLabel = "RoadsOfTheRimRemoveConstructionSite".Translate();
command_Action.defaultDesc = "RoadsOfTheRimRemoveConstructionSiteDescription".Translate();
command_Action.icon = ContentFinder<Texture2D>.Get("UI/Commands/RemoveConstructionSite", true);
command_Action.action = delegate ()
{
SoundStarter.PlayOneShotOnCamera(SoundDefOf.CancelMode, null);
DeleteConstructionSite(caravan);
};
// Test when the RemoveConstructionSite action should be disabled
// Check whether there's already a construction site here
bool ConstructionSiteAlreadyHere = false;
try
{
ConstructionSiteAlreadyHere = Find.WorldObjects.AnyWorldObjectOfDefAt(DefDatabase<WorldObjectDef>.GetNamed("RoadConstructionSite", true), caravan.Tile);
}
catch
{

}
if (!ConstructionSiteAlreadyHere)
{
command_Action.Disable("RoadsOfTheRimBuildConstructionSiteNotAlreadyHere".Translate());
}
return command_Action;
}

/*
* Creates a road construction site on the world map, where the Caravan is.
* The site will track the amount of work already done
* The site is considered the "From" tile and is linked to one neighbouring tile : the toTile
* later : The Caravan must provide the material
* later : The Caravan also has a construction score based on number of people, construction skills, animals
*/
public static void CreateConstructionSite(Caravan caravan, RoadBuildableDef roadBuildableDef)
{
WorldGrid worldGrid = Find.WorldGrid;
RoadConstructionSite constructionSite = (RoadConstructionSite)WorldObjectMaker.MakeWorldObject(DefDatabase<WorldObjectDef>.GetNamed("RoadConstructionSite", true));
constructionSite.Tile = caravan.Tile;
constructionSite.roadToBuild = roadBuildableDef;
/* TO DO : Instead of placing the construction site directly, make the player pick a target tile
* One way to do it : as soon as the roadToBuild is selected, show a little dot in every neighbouring tile. Clicking on the dot is what will create the construction site
*/
constructionSite.toTile = null;
List<int> neighbouringTiles = new List<int>();
Find.WorldGrid.GetTileNeighbors(caravan.Tile, neighbouringTiles);
Find.WorldObjects.Add(constructionSite);


/* TO DO : create the road on the world map. Use WorldGrid ?
Useful : RoutePlannerWaypoint allows you to point and click on the map to find a path
CaravanTile.potentialRoads.Add(); ?
WorldGrid.OverlayRoad (int fromTile, int toTile, RoadDef roadDef)
Find.WorldGrid.OverlayRoad; ?
Find.World.renderer.RegenerateAllLayersNow();
*/
/*
**Test : first, simply make a road to the nearest neighbour**
int toTile = worldGrid.FindMostReasonableAdjacentTileForDisplayedPathCost(caravan.Tile);
RoadDef roadDef = worldGrid.GetRoadDef(caravan.Tile , toTile);
RoadDef roadDef2 = worldGrid.GetRoadDef(caravan.Tile, toTile, false);
Tile tile = worldGrid[caravan.Tile];
Tile tile2 = worldGrid[toTile];
if (roadDef2 != null)
{
tile.potentialRoads.RemoveAll((Tile.RoadLink rl) => rl.neighbor == toTile);
tile2.potentialRoads.RemoveAll((Tile.RoadLink rl) => rl.neighbor == caravan.Tile);
}
if (tile.potentialRoads == null) { tile.potentialRoads = new List<Tile.RoadLink>(); }
if (tile2.potentialRoads == null) { tile2.potentialRoads = new List<Tile.RoadLink>(); }
tile.potentialRoads.Add(new Tile.RoadLink
{
neighbor = toTile,
road = roadDef
});
tile2.potentialRoads.Add(new Tile.RoadLink
{
neighbor = caravan.Tile,
road = roadDef
});
Find.World.renderer.RegenerateAllLayersNow();
*/
}

public static void DeleteConstructionSite(Caravan caravan)
{
Find.WorldObjects.Remove(Find.WorldObjects.WorldObjectOfDefAt(DefDatabase<WorldObjectDef>.GetNamed("RoadConstructionSite", true), caravan.Tile));
}
}
}
26 changes: 26 additions & 0 deletions Source/RoadsOfTheRim/RoadsOfTheRim/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Reflection;
using System.Runtime.CompilerServices;

// Information about this assembly is defined by the following attributes.
// Change them to the values specific to your project.

[assembly: AssemblyTitle("RoadsOfTheRim")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.

[assembly: AssemblyVersion("1.0.*")]

// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.

//[assembly: AssemblyDelaySign(false)]
//[assembly: AssemblyKeyFile("")]
15 changes: 15 additions & 0 deletions Source/RoadsOfTheRim/RoadsOfTheRim/RoadBuildableDef.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using RimWorld;
using RimWorld.Planet;
using UnityEngine;
using Verse;

namespace RoadsOfTheRim
{
public class RoadBuildableDef : Def
{
public float movementCostMultiplier=1;
public int workNeeded=0;
}
}
Loading

0 comments on commit 5bcad56

Please sign in to comment.