Jump to content

Kerbin Ocean Additions (icebergs) I AM OPEN TO MORE IDEAS TO ADD THE THE SEAS OF KERBIN


Recommended Posts

Okay, I have an Idea for a mod which adds in icebergs, they will work similar to asteroids but spawn in the ocean of Kerbin. I know how to make the part(s) and get them into the game, but I have no idea how to get them to spawn randomly but in the right place. Any one think they could tell me how I would go about doing that?

iceberg.jpg

Edited by JaffaFediration
Link to comment
Share on other sites

Try looking at the code for Custom Asteroids. This will be harder that you think, as all the asteroid spawner has to do is choose a random point in space and make a orbit there. You will have to make it so that your iceberg part:

Only spawns in water

Only spawns on Kerbin

Only spawns up north-ish

Spawns on the surface

Matches velocities with Kerbin

It will be a LOT of code.

Link to comment
Share on other sites

My suggestion would be to look at Contract Configurator's code for placing vessels at specific locations. The hardest part would be to ensure they only spawn in water, but if you only spawn them within, say, physics range of the active vessel then you can probably poll the PQS system and check if the terrain height is less than 0. You can quite easily check latitude and primary body. It actually shouldn't be very difficult or require much code.

Pseudo code:

During FixedUpdate() randomly decide whether you should try to spawn an iceberg.

Check that the active vessel's mainBody is Kerbin (compare names, for instance), and perhaps that the active vessel's altitude is < 2km or so. If not, cancel.

Pick a random location within a few km of the active vessel (add a random offset to the lat/lon of the active vessel).

Check the terrain height at that location. If < 0, spawn iceberg (using the Contract Configurator code). Else, cancel (or pick a new spot).

Repeat until you hit some internal limit of how many icebergs to spawn. To avoid issues with having a bunch of icebergs in the save file, I'd add a listener for the vessel unload event and destroy the iceberg rather than save it to persistence.

You'll need to test it a bunch, but it shouldn't be too difficult to implement.

Edit: Just to specifically address the concerns of the above poster, here is (one way) of handling the issues they present:

Only spawns in water

-Check the land height is less than 0

Only spawns on Kerbin

-check that the active vessel's mainBody is Kerbin

Only spawns up north-ish

-Check the active vessel latitude. Make sure the absolute value is greater than ~70 degrees (assuming you want north and south)

Spawns on the surface

-Set the iceberg's altitude to 0. Might need a slight offset. Testing will make that clear.

Matches velocities with Kerbin

-Set the vessel situation to landed or, better, splashed down. Orbits aren't calculated for those.

E2: If it wasn't clear, you'll very likely need a plugin for this.

Edited by magico13
Link to comment
Share on other sites

Would just like to say this is just awesomely useless :) In a good way, I swear! Once you've got the code and theory right it might make a very interesting thing to apply to Laythe or to some custom planets.

Link to comment
Share on other sites

I decided to try out coming up with a basic implementation of this. Definitely not working in a stable manner, but the linked code is a proof of concept. If you don't mind too much, I'm considering trying to make this idea into a "physical ground scatter" mod where physical ground scatter could happen, like icebergs in water, or rocks in the desert. Ideally it'd be easily modable so people could add their own scatter based on planet, biome, latitude, etc.

The code below will take whatever craft file is in GameData/PhysicalScatter/iceberg.craft and will spawn it directly below the active vessel when it's over water and below 1km. It spawns quite a few of them (up to 100) and doesn't seem to be removing them properly. Like I said, very much a buggy proof of concept. Note that it takes a craft file, not a part file. It's got code that's basically a direct copy of the code from Contract Configurator. I had to make a few changes, but not too many.

Since everything needs licenses, this will be under the MIT license, per Contract Configurator.

link

Link to comment
Share on other sites

Realistically though, he blatantly copies your code so "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software."

Link to comment
Share on other sites

Realistically though, he blatantly copies your code so "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software."

Well, I don't like the use of "blatantly copies" here, as that implies wrongdoing. As far as what he did being a substantial copy:


$ find source -name '*.cs' | xargs wc -l | tail -n 1
26941 total

$ find source -name 'SpawnVessel.cs' | xargs wc -l | tail -n 1
632 source/ContractConfigurator/ContractBehaviour/SpawnVessel.cs

Even if he did take the entire source file verbatim (he didn't, it was one function) that would be about ~2% of the source, which I really don't think is "substantial portions". So I would interpret that based on the license requirements, he can sublicense (ie. re-release under a different license) without including the copyright notice (but he did anyway, so it's really moot).

Link to comment
Share on other sites

If/when I actually go and make it into a more fully featured mod, there will be additional changes to that code. Even if there aren't, credit will be given where credit is due. KSP modding isn't a solo effort (especially with the lack of any documentation from Squad), so people share ideas and code all the time. Nightingale freely offered the source as an example, the license permits reuse, and we're all friends here. If I borrow code from somewhere, I'll make sure to include credit. If nightingale wasn't satisfied with the amount of attribution, I'd imagine I'd be contacted directly about that and we'd work something out :)

I typically go with GPLv3 for my licenses, as I like to ensure things stay free, but the MIT license is fine by me too. As long as others can learn from my code, and borrow code when they can't solve a problem themselves but I can, then I'm happy :D

Link to comment
Share on other sites

I will be making the models as soon as I can.

No rush from me. I'm back at work (sadly, the long weekend is over), so I won't be making as much progress during the week. I just wanted to see if I could come up with something as easily as I thought I could, and thankfully it played nicely and mostly worked right. I tend to be a somewhat slow modder and have a long time between releases of things :P

Link to comment
Share on other sites

Should I use a edited Potatroid .cfg since it is practically the same thing, also how could you make sure it "melted" or at least explode when it gets to hot?

The code I posted takes a .craft file, so ideally you'd load up the iceberg in the VAB by itself and save that as a single part "ship".

To have it "melt" at some temperature you'd have to play with the temperature values in the part config. I haven't done that before, but I imagine it isn't too difficult (there used to be a MaxTemp value but that may have changed in the new system).

You can copy the potatoroid for the part config if you want, but I don't actually know anything about making parts. The system I'm using for spawning them has nothing in common really with the asteroid spawning code (I mean, it might, but it's not directly derived from that code)

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...