Ludeon Forums

RimWorld => Mods => Topic started by: Loconeko73 on December 05, 2018, 12:13:16 AM

Title: [mod idea] Worldmap road building
Post by: Loconeko73 on December 05, 2018, 12:13:16 AM
Hello fellow Rimworlders,

I was not an early adopter of Rimworld, and followed it for 3 years before I decided to jump in a few weeks ago. It's fair to say this game is everything I expected and more, I'm basically borderline addicted :P

I originally posted this in a Facebook group, but I think this forum is more adapted. Here's the idea : I'd love to be able to build roads on the planet map, like RimRoads did until 1.0 But it seems that mod is incompatible with 1.0 because of changes made to the way roads are managed. I have a fair bit of experience in programming, but not in C# and was wondering if any of you here would be interested in trying to join me for this purpose or if you know of another modder currently working on it.

Though I'm really trying to figure out everything I can by myself, I will run into problems I don't know how to solve. So if any one here can help and would like to see a worldmap road building mod, please reply to this post and let me know so we can start a discussion and hopefully a Github repo.

My rough roadmap for this mod is as follows :


Looking forward to your feedback.
Title: Re: [mod idea] Worldmap road building
Post by: 5thHorseman on December 05, 2018, 12:25:18 AM
It doesn't seem to be maintained, but RimRoads (https://ludeon.com/forums/index.php?topic=35907.0) does a lot of what you're asking for.
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on December 05, 2018, 01:01:29 AM
Thanks for your answer! Yes, I mentioned RimRoads in my post without a link, which might be why you missed it. That mod breaks in 1.0, so I'd like to try to make my own.
Title: Re: [mod idea] Worldmap road building
Post by: 5thHorseman on December 05, 2018, 03:59:37 AM
Oy I did. I read the first paragraph and then scanned the plan, and thought 'That sounds like Rimroads' which I guess makes sense :D

Sadly while I know some C, I'm nowhere near capable of doing anything for this.
Title: Re: [mod idea] Worldmap road building
Post by: Canute on December 05, 2018, 08:35:23 AM
You can spend jecrell a coffee, maybe visit him on Discord.
Then your chances for a faster update will increase.
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on December 05, 2018, 06:57:13 PM
Of course I could lobby to get RimRoads updated, but I also want to try my hand at modding. It's been ages since I learned a new language, so this sounds like a nice challenge !

For the moment, I can't even get the modding tutorial complete, so we're not off to wonderful beginnings  :P

But I appreciate any support !
Title: Re: [mod idea] Worldmap road building
Post by: Canute on December 06, 2018, 03:39:03 AM
Then you should visit him on discord, i think he will give you some support how to update his mod.
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on December 07, 2018, 02:31:14 AM
Thanks, Canute.

I don't think I'm ready to ask for help yet, as I haven't done my homework on a lot of topics that will pop up while I code this. For starters, C# is still very new to me, and I'm still discovering the depth of the RimWorld namespace ! I don't want to reach out to Jecrell & end up wasting his time.

But I have managed to create a skeleton mod with some test stuff that already show up in-game, so once I feel a bit more confident, I certainly will.

In any case, thanks a bunch for your interest  :)

Quote from: Canute on December 06, 2018, 03:39:03 AM
Then you should visit him on discord, i think he will give you some support how to update his mod.
Title: Re: [mod idea] Worldmap road building
Post by: Mehni on December 07, 2018, 05:07:06 AM
Why not attempt to update RimRoads instead?

No need to reinvent the wheel.
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on December 07, 2018, 05:19:50 AM
I thought I would try that initially, but I have read the code and I have no idea what's going on in there  ;D

So in order to learn at the same time, I'm starting from scratch. Maybe I'll end up updating RimRoads anyway once I get a better understanding of the whole modding process.

Quote from: Mehni on December 07, 2018, 05:07:06 AM
Why not attempt to update RimRoads instead?

No need to reinvent the wheel.
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on December 08, 2018, 09:39:17 AM
Quick update : I am actually slowly making progress, and finding the whole modding thing quite exciting  ;)

Let's see if I can get this done !
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on December 09, 2018, 08:52:12 PM

Hello everyone,

For those who have an interest in this project, and are willing to help, here is a quick update & a request :

I now have the ability to create & remove road construction sites on the world map, but I'm struggling to add content to them beyond what's already available in a default WorldObject. I assume I need to use a comp, but the tutorial on the topic is missing the part on how to use them ! If any modder out there reads this and can point me to some code that extends a WorldObject, that would be great. I have checked "Setup camp" already (interesting mod !) but it uses existing comp properties like timeout, not a custom one like what I want to do.

Any help appreciated.

For info, here is my goal to release the first beta :

- Give a caravan the ability to create a road construction site of a certain type (dirt road, stone road, asphalt road) [DONE]
- Give a caravan the ability to remove a road construction site [DONE]
- In the construction site, indicate to which neighbouring tile the road will go to [TO DO]
- In the construction site, save time & materials needed & already spent to complete the road (e.g. 2000 stones , 500 wood , 500 steel , 50 chemfuel , 6000 work) [TO DO]
- Give a caravan the ability to work on a construction site [TO DO]
- Create the road once work is complete [TO DO]

At the moment, my mod would not do a multi-tile road like what RimRoads does. I could add this later but it would involve picking more than just a neighbouring tile, as well as automatically moving the caravan when construction of one tile is done, which is harder. For a Beta, I think it's fine to build roads tile by tile.

Would love to hear some feedback.

Cheers !
Title: Re: [mod idea] Worldmap road building
Post by: Albion on December 10, 2018, 03:16:26 AM
I'm not exactly sure what you're trying to say but if you want to add an additional comp, all you need to do is create your own WorldObjectDef similar to the ones in the core and add some additional comps.
Make sure though that your custom objectDef gets created though.
Anyway, the major benefit of comps is that they have various methods that get called at different times so you can use them as a hook to inject your programming. Just check the base class and see what you can override.
Examples are: postSpawn or something that gets called after initial generation.
And most importantly: tick, which gets called every tick so you can check if certain conditions are met.
You can also check out the code from my Sparkling Worlds mod. I use some comp stuff for the psychic emitter event and a custom world object class for the doctor event.

Edit: the source code is available both on steam and the manual download. Check the events subfolder in the source folder.
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on December 10, 2018, 07:53:34 AM
Thanks, Albion !

I think I was way out of my league to try making custom comps from the get go. My issue was much more basic : I didn't understand what needed to go into the ExposeData() method in order to save properties of my custom WorldObjectDef. Now I have & I can save all the information I need about construction sites in the save file.

Comps will still be needed though, for exactly what you describe below : tick to allow me to complete the road once work is done.

In any case, thanks a bunch for taking the time to help a complete noob !  ;D
Title: Re: [mod idea] Worldmap road building
Post by: Kori on December 13, 2018, 02:26:34 PM
Good luck with your project, being able to build roads again would be very nice! :)
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on December 13, 2018, 09:10:57 PM
Greetings fellow Rimworlders,

As part of my attempt at a first mod, I have stumbled into a problem that boils down to lack of code toblatantly copy  get inspiration from.

It has to do with WorldObjectComp. ThingComp are well covered in Roxx Ploxx document here in the wiki (https://github.com/roxxploxx/RimWorldModGuide/wiki/SHORTTUTORIAL%3A-Things-and-ThingDef-and-Components) and this knowledge can quickly be tested by checking the many existing mods that use comps.

However, I've been unable to find any mod that uses a WorldObjectComp, and find it difficult to navigate through that class without a working example.

By any chance, does any of you know of such a mod ?

Thanks in advance
Title: Re: [mod idea] Worldmap road building
Post by: Mehni on December 14, 2018, 05:33:13 AM
https://github.com/Mehni/MoreFactionInteraction/tree/master/MoreFactionInteraction/World%20Incidents

At its core, there's not much difference between a WorldObjectComp and a ThingComp. There are about 15 methods you can override that provide a hook/functionality.

Vanilla also has a few WorldObjectComps. Use your decompiler to see what classes inherit from or use the WorldObjectComp class.
Title: Re: [mod idea] Worldmap road building
Post by: Albion on December 14, 2018, 06:05:27 AM
Yes like I already told you in an earlier post you can also look at my Sparkling Worlds code.
Specifically the events.cs which you can find here: https://gitlab.com/Albion/SparklingWorlds/tree/master/Source/SparklingWorlds%20Events/SparklingWorlds (https://gitlab.com/Albion/SparklingWorlds/tree/master/Source/SparklingWorlds%20Events/SparklingWorlds)
It contains a WorldObjectComp for my psychic emitter event.

The best way is to look at the base classes from the core and see which methods you want to override. The most imporant ones are the ones like Pre- or PostSpawn, PostDestroy and CompTick.
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on December 14, 2018, 08:30:06 PM
Thanks to you both. You're awesome  :)

I will check the mods you mentioned and hopefully that will put me on the right track.
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on December 15, 2018, 07:44:23 AM
Hi again.

This is it. I have a working proof of concept : buildable roads that survive saving & loading ! There are still many more hours ahead to iron out the details, but I'm now confident I will release this mod.

Thanks everyone for the amazing support & patience !
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on January 03, 2019, 11:22:09 PM
Roads of the Rim has been released on Steam. Feedback welcome !
Title: Re: [mod idea] Worldmap road building
Post by: Canute on January 04, 2019, 03:08:27 AM
Feedback: What is Steam, don't know such thing ! :-)
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on January 04, 2019, 09:04:22 PM
Quote from: Canute on January 04, 2019, 03:08:27 AM
Feedback: What is Steam, don't know such thing ! :-)

Steam ? Best thing that ever happened to PC gaming ;-)

You can also get the mod on GitHub : https://github.com/LocoNeko/RoadsOfTheRim (https://github.com/LocoNeko/RoadsOfTheRim)
Title: Re: [mod idea] Worldmap road building
Post by: Mehni on January 05, 2019, 10:47:16 AM
                else if (pawn.RaceProps.packAnimal)
                {
                    animalConstruction += (float)pawn.GetStatValue(StatDefOf.ConstructionSpeed) * (float)pawn.GetStatValue(StatDefOf.ConstructSuccessChance);
                }


https://github.com/LocoNeko/RoadsOfTheRim/blob/master/Source/RoadsOfTheRim/RoadsOfTheRim/WorldObjectComp_Caravan.cs#L99

I've never seen a muffalo with a trowel :P

Good job on the release tho.
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on January 07, 2019, 03:03:13 AM
Thanks for the feedback, Mehni!

About the pack animals, if you look a bit further, you'll see they only help, but don't work on their own.
Title: Re: [mod idea] Worldmap road building
Post by: Canute on January 07, 2019, 04:08:56 AM
Tamed bulldozer and earthmover ! :-)
Here my stegosaurus, you favoured snack
*Dino is happy and dance*
*stamp stamp stamp stamp*
dirt road finished.
Title: Re: [mod idea] Worldmap road building
Post by: Mehni on January 07, 2019, 04:43:41 AM
I'm just wondering why you'd use those stats. As far as I can see, both the ConstructionSpeed and ConstructionSuccessChance return 1 for pawns without a SkillTracker. Such as animals. Maybe I'm wrong though.

It's a nice touch -- but maybe you're better off using manipulation/sight instead :)
Title: Error on Upload
Post by: Comrade Corwin on January 07, 2019, 09:31:35 AM
I'm getting this error on upload:

XML error: <li><compClass>RoadsOfTheRim.WorldObjectComp_Caravan</compClass></li> doesn't correspond to any field in type WorldObjectDef. Context: <WorldObjectDef><defName>Caravan</defName><label>caravan</label><description>A group of traveling people.</description><worldObjectClass>Caravan</worldObjectClass><texture>World/WorldObjects/Caravan</texture><useDynamicDrawer>true</useDynamicDrawer><expandingIcon>true</expandingIcon><expandingIconTexture>World/WorldObjects/Expanding/Caravan</expandingIconTexture><expandingIconPriority>100</expandingIconPriority><expandMore>true</expandMore><allowCaravanIncidentsWhichGenerateMap>true</allowCaravanIncidentsWhichGenerateMap><IncidentTargetTags><li>Caravan</li></IncidentTargetTags><inspectorTabs><li>WITab_Caravan_Health</li><li>WITab_Caravan_Needs</li><li>WITab_Caravan_Gear</li><li>WITab_Caravan_Social</li><li>WITab_Caravan_Items</li></inspectorTabs><comps><li><compClass>MoreFactionInteraction.World_Incidents.WorldObjectComp_CaravanComp</compClass></li></comps><li><compClass>RoadsOfTheRim.WorldObjectComp_Caravan</compClass></li></WorldObjectDef>
Verse.Log:Error(String, Boolean)
Verse.DirectXmlToObject:ObjectFromXml(XmlNode, Boolean)
System.Reflection.MonoMethod:InternalInvoke(Object, Object[], Exception&)
System.Reflection.MonoMethod:Invoke(Object, BindingFlags, Binder, Object[], CultureInfo)
System.Reflection.MethodBase:Invoke(Object, Object[])
Verse.DirectXmlLoader:DefFromNode(XmlNode, LoadableXmlAsset)
Verse.LoadedModManager:ParseAndProcessXML(XmlDocument, Dictionary`2)
Verse.LoadedModManager:LoadAllActiveMods()
Verse.PlayDataLoader:DoPlayLoad()
Verse.PlayDataLoader:LoadAllPlayData(Boolean)
Verse.Root:<Start>m__1()
Verse.LongEventHandler:RunEventFromAnotherThread(Action)
Verse.LongEventHandler:<UpdateCurrentAsynchronousEvent>m__1()

I don't understand enough about coding in RimWorld to have any idea of the problem. Just thought I'd let you know what's up!
Title: Re: [mod idea] Worldmap road building
Post by: Canute on January 07, 2019, 10:42:58 AM
Comrade Corwin,
that's the right way, don't try to fix it by yourself, just report it to the mod author so he can fix it for all.
Title: Re: [mod idea] Worldmap road building
Post by: NazarDoe on January 07, 2019, 03:35:10 PM
Could you add a mapping of the required amount of resources without a caravan?
Title: Re: Error on Upload
Post by: Loconeko73 on January 08, 2019, 03:10:41 AM
Quote from: Comrade Corwin on January 07, 2019, 09:31:35 AM
I'm getting this error on upload:

XML error:

....

I don't understand enough about coding in RimWorld to have any idea of the problem. Just thought I'd let you know what's up!

Thanks for the bug report!

This error was fixed in the latest version of the mod (uploaded about 18 hours ago). Could you try uninstalling & reinstalling and let me know if you still get this?

Thanks!
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on January 08, 2019, 03:11:24 AM
Quote from: NazarDoe on January 07, 2019, 03:35:10 PM
Could you add a mapping of the required amount of resources without a caravan?

It's on my roadmap!
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on January 08, 2019, 03:15:18 AM
Quote from: Mehni on January 07, 2019, 04:43:41 AM
I'm just wondering why you'd use those stats. As far as I can see, both the ConstructionSpeed and ConstructionSuccessChance return 1 for pawns without a SkillTracker. Such as animals. Maybe I'm wrong though.

It's a nice touch -- but maybe you're better off using manipulation/sight instead :)

Thanks, Mehni. I really appreciate your feedback. To be honest, I just picked the first value that seemed to work, and made sure animals would never do more than double the work provided (sorry, no trowel-yielding muffalo!) I'll take a closer look at pack animals to see if I can find a value that makes more sense.

But construction for humans gives results I'm happy with.
Title: Re: [mod idea] Worldmap road building
Post by: Canute on January 09, 2019, 09:47:46 AM
Ok, i just took a first look at the road construction.
Basicly it is nice, but the resource need is heavy.
I want to build a stone road and need 1800 stones.
The regular map size is 300x300 tiles. So a road need to be 300 tiles long and 3 tile's wide.
300 * 3 * 4 stone blocks = 4800 blocks, so 1800 isn't that bad ! :-)

But when you want to build a longer road, your map will be abundand of stone sooner or later.

So my idea are, when the caravan run out of resources they should gather them from the local map and need 2-3 times the workamount.
Except Chemfuel, since this need to be manufactured.
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on January 10, 2019, 02:39:51 AM
Quote from: Canute on January 09, 2019, 09:47:46 AM
Ok, i just took a first look at the road construction.
Basicly it is nice, but the resource need is heavy.
I want to build a stone road and need 1800 stones.
The regular map size is 300x300 tiles. So a road need to be 300 tiles long and 3 tile's wide.
300 * 3 * 4 stone blocks = 4800 blocks, so 1800 isn't that bad ! :-)

But when you want to build a longer road, your map will be abundand of stone sooner or later.

So my idea are, when the caravan run out of resources they should gather them from the local map and need 2-3 times the workamount.
Except Chemfuel, since this need to be manufactured.

Canute, I like the way you think !

From the beginning, it was clear to me that costs are too high to be very practical (hence the 10% to 100% slider in the settings) but too low to be realistic.

There are 2 solutions that I can see : the first one is to get help from ally factions (already working on it)

The second one is to gather resources from your surroundings as you suggest, a la Syrchalis' "setupcamp" but only for roads. The idea then would be to implement the following (optional) feature:

- The ability to build stone & asphalt roads now requires research. (I think making dirt roads & path should be technology independent)
- Those technologies allow the player to craft construction kits & advanced construction kits that can be put into caravans. Those are heavy machines, requiring all the valuable stuff we Rimworlders love to hate (components, maybe advanced components, steel, etc)
- The kits provide resources in situ when used by caravans on construction sites. The amount of resources available can be based on the biome, the best miner in the caravan, etc. A kit is operated by one pawn (can't have more kits than pawns). Even chemfuel can be obtained, but just to make asphalt (in other words, the kits never give resources usable for any other purpose than road building)
- When this feature is enabled, resource costs become massive (in the tens of thousands) but because the kits provide resources and scale up with the number of pawns in the caravan, it just becomes a matter of time, which in turn can be offset by having many pawns in the caravan (road building is, after all, a team effort !)

This would achieve higher & more realistic material costs, as well as longer build time but would end up potentially quicker as long as the player properly invests in the construction kits & crews.

I have the feeling this could work, and pretty well !
Title: Re: [mod idea] Worldmap road building
Post by: Canute on January 10, 2019, 03:59:40 AM
- Basicly you only need special research for Asphalt road, since you build stone floor from the beginning.

- I would also suggest that Dirt road's don't need any resources, since you only trample on the path to harden the underground and remove vegetation.

- When you update Dirt road on Stone road, you would just need the half work.
- From Stone to Asphalt, half work, half resource need.

- You don't need to create extra map's ala setupcamp for resource gathering. That's too much micromanging i think. Just let the workamout increase if the constr. site don't got the nessesary resources.

- construction kits instead of resources, which provide x% of the road construction.

- building mashines would be nice too. Maybe create a robot animal (look at Android tiers mod for that) that need chemfuel and greatly enhance the workspeed on road build.
Title: Re: [mod idea] Worldmap road building
Post by: Deathend on January 24, 2019, 03:51:15 PM
since last upodate i get new maps devoid of plants and mountains/hills and i get a log full of the same error

inside that error apears this

Trying to get valid region at (110, 0, 118) but RegionAndRoomUpdater is disabled. The result may be incorrect.
Verse.Log:Warning(String, Boolean)
Verse.RegionGrid:GetValidRegionAt(IntVec3)
Verse.RegionAndRoomQuery:RegionAt(IntVec3, Map, RegionType)
Verse.RegionAndRoomQuery:RoomAt(IntVec3, Map, RegionType)
Verse.GridsUtility:GetRoom(IntVec3, Map, RegionType)
Verse.<TryFindCentralCell>c__AnonStorey1:<>m__0(IntVec3)
Verse.CellFinderLoose:TryFindRandomNotEdgeCellWith(Int32, Predicate`1, Map, IntVec3&)
Verse.CellFinderLoose:TryFindCentralCell(Map, Int32, Int32, Predicate`1)
RimWorld.GenStep_FindPlayerStartSpot:Generate(Map, GenStepParams)
Verse.MapGenerator:GenerateContentsIntoMap(IEnumerable`1, Map, Int32)
Verse.MapGenerator:GenerateMap_Patch0(IntVec3, MapParent, MapGeneratorDef, IEnumerable`1, Action`1)
Verse.Game:InitNewGame_Patch2(Object)
Verse.Root_Play:<Start>m__1()
Verse.LongEventHandler:RunEventFromAnotherThread(Action)
Verse.LongEventHandler:<UpdateCurrentAsynchronousEvent>m__1()
Title: Re: [mod idea] Worldmap road building
Post by: Loconeko73 on February 11, 2019, 04:34:46 AM
Sorry I've been mostly on Discord, not on the forum.

The error above has been corrected, and the mod is now out of Beta. Still being actively developed, though !

Anyone who tries it, please feel free to report issues, bugs or ideas. And if you feel like it, support me on ko-fi!  (https://ko-fi.com/loconeko73)
Title: Re: [mod idea] Worldmap road building
Post by: tensheapz on February 18, 2019, 05:00:02 AM
Firstly thanks for making a great mod!

I think the latest update (20 h ago) which was supposed to add Glitter roads broke a couple things:
- Wood cost now nonexistent for all road types (perhaps something to do with renaming Wood to WoodLog in code, but in the XML it is still called Wood)
- Work cost of everything seems to have by default been reduced down to 10% cost. It looks like existing games keep their previous effort value (for me it was 1, so under the new system means 10% cost)
Title: Re: [mod idea] Worldmap road building
Post by: Crestrisen on July 25, 2020, 11:04:51 PM
Praise you for making this mod. Such fantastic synergy with Set Up Camp, among others.

Quote from: tensheapz on February 18, 2019, 05:00:02 AMI think the latest update (20 h ago) which was supposed to add Glitter roads broke a couple things:
- Wood cost now nonexistent for all road types (perhaps something to do with renaming Wood to WoodLog in code, but in the XML it is still called Wood)

Exactly right. I've been gradually working on a custom version of 1.0.2408, and that was extremely helpful. I'm a total novice, but simply using Notepad++ to do a 'find in files' for all instances of wood in the RotR mod folder and replacing the ones used to define a resource with WoodLog fixed it. Huge thanks for mentioning that.