Jump to content

Kerbal 4X: inventory and scavenging


SiriusSam

Recommended Posts

@passinglurker

I checked ExPL, but i haven't dabbled with the code yet. If they are open source then i will surely take some bits here and there :)

I don't know about such mods, but i have the feeling this won't be very complicated as long as we have some properly built ship models. then you just have to redirect them, paste some chutes on them and land them to recover .

I started building some alien temples in the editor, i think it could be fun to explore that kind of structure with your kerbal, looking for chests or detachable parts to bring back home ^^

Anyway.. let's not get carried away. I'm going to make the code as stable as i can, look for all the possible loopholes. And then the fun will begin :)

Link to comment
Share on other sites

@Chezburgar7300

So far the money isn't even refunded :)

This is very much WIP, but the first milestone will soon be reached.

My plan for resource is to have them recovered as well. I plan to display them as barrels in the inventory, with the quantity of the resource displayed.

I will get to that part when im done with the funds, the saving and i fix the 2 little loopholes that are left in the system.

Well, this officially has my attention. Hanging out for a later (hopefully) more feature packed release!

Link to comment
Share on other sites

Alright!

I think this is almost ready for release. Parts are stored / unstored as needed, funds work as intended, the inventory is saved in the savegames, and it is not possible to place more experimental parts than you have in store.

The only thing i need before releasing is to change the experimental missions to give 1 unit of the part that must be tested.

I sure wouldn't mind if EvilReeper has an opinion about how to get there :)

Edited by SiriusSam
Link to comment
Share on other sites

For tweakscale I see two possibilities:

1- I only store parts in one size, if a part is tweaked it will cost more when you unroll the ship, but the recovery price is unchanged. As a result you will pay extra, but recover a normal sized part. This is how it should behave right now (but i didn't try it yet).

2- Store items in multiple sizes. Then either :

  • create an additionnal icon for each sized part.. but this will put a LOT of icons in the list...
  • add more information inside the icon (0.65 : X, 1.25 : Y, 2.5 : Z...

If you can come up with something else, i'm all ears.

Link to comment
Share on other sites

Forsaken

I am using a clean install for now. But you are right, I have to take tweakscale into account.. or i won't be able to use it on my main save :)

And it can potentially wreck havok to the interface... so i think i'll do that next.

You may want to discuss with magico13, dev for this mod: http://forum.kerbalspaceprogram.com/threads/92377-0-24-2-Kerbal-Construction-Time-Release-v1-0-2-%289-3-14%29

His mod takes tweakscale parts into account and also maintains an inventory of recovered parts

Link to comment
Share on other sites

Alright!

I think this is almost ready for release. Parts are stored / unstored as needed, funds work as intended, the inventory is saved in the savegames, and it is not possible to place more experimental parts than you have in store.

The only thing i need before releasing is to change the experimental missions to give 1 unit of the part that must be tested.

I sure wouldn't mind if passinglurker has an opinion about how to get there :)

Well I'm not a code inclined person nor have a seen a mod do anything remotely similar to limiting experimental part spam sorry. though I think it would be more fun and forgiving if it gave you a randomized number instead of just one simply because then you have to find uses for the left overs(though there will still be times where you only get one and fail the contract because you lost it)

How do part test contracts work anyway? is it possible to have them give parts that are not on the tech tree at all?

as for tweak scale that's tricky perhaps the extra scales in stock should be displayed in the tweakable menu alongside the scale slider? for example the part catalog says you have a total of 5 basic jet engines you place the engine and right click to show the tweakable menu where it says you have 3 engines at the default scale. You then shrink the engine down to .625 and the tweakable menu displays that the remaining two engines in the inventory are in this scale? It would work for building, but it'd still be a pain to check your overall stock with :/

Edited by passinglurker
Link to comment
Share on other sites

For experimental parts, you can discourage part spam by simply multiplying the cost for any experimental part by a certain amount. Experimental parts should be expensive by their very nature, after all. You'd be less inclined to abuse a contract to test the nuclear engine if that engine cost 5x what it normally would.

Link to comment
Share on other sites

passinglurker

sorry.. i meant EvilReeper :sealed:

The limitation of parts is already there, you can't place more than you have in the inventory. Was quite a pain to make sure you don't go over the limit by duplicating with ALT or using symmetry.... but its done.

The problem now is just to find a way to give the initial few parts when a mission is picked. I'll start looking for a solution when the modde headache is gone :confused:

Link to comment
Share on other sites

@tweakScale: It's probably not good to rely on a fixed number of scales. TweakScale also supports continuous scaling, and the scaletypes are configurable. I sometimes use a 31cm scale for tiny things for example, and ultimately would like an Interface like procedural parts where you can build any diameter you like.

The same applies to mods like procedural parts/wings/fairings. Then there are parts with the firespitter texture/fuelswitch, firespitter also has procedural engines. There are KAS-Containers with stuff inside (probably not supporting tweakscale at all). So lots of open questions left. I would just start with simple stuff and test the basic mechanics and interfaces before coming to the tricky special cases.

Link to comment
Share on other sites

yes.. i think i'll stick to case #1 which is how the mod should behave now. I'll just make sure there is no exploits to generate money, i think this should be simple enough.

I started a new game and so far i can't find any edge cases i missed, but i probably need 1 week of testing to be sure.

Link to comment
Share on other sites

Forsaken:

Yes i've been magico's code a lot. But since his inventory is saved in a separate window i'm not sure his method would be compatible.

Then let's make it compatible ;)

I'm totally willing to work with you to try to find a way to make KCT and this compatible (and it would save me a lot of time since I have been considering overriding the stock recovery stuff and have part costs work like this, where you pay once for a part and then don't have to again). At the very least we need to ensure the two inventory systems remain synced, which should be easy enough to do [note: I have not looked at your code yet, so this is an assumption at this point]. KCT's inventory is stored as a Dictionary<string, int> which I can make public very easily.

I can see a major incompatibility if you are modifying the part costs to zero in the editor, as KCT uses the part costs for determining build time (which is then modified further if the part is in the inventory). If a vessel ended up costing 0 funds (because all the parts were in the inventory) then it wouldn't take any time to build (KCT still has those vessels take time, generally 1/10 of what they would be if they were new, but that amount is configurable). If you're making changes to the funds level after it's placed on the pad, then KCT will probably be fine with that (though the player may not be. KCT makes the player pay full price when they add the vessel to the build list, so they'd be paying too much at that time, only to be refunded partially at launch). In short, we'd have to do a bit of work.

KCT stores TweakScale parts separately by size (with the default size stored without size information for backwards compatibility) as name,size (ie. mk1pod,2.5 for a 2.5 meter mk1 command pod). You can do something different, as long as we can convert between them.

Also, a suggestion: Tie into StageRecovery's API so that players can add those parts to their inventories as well. KCT uses it if you need an example, and KCT uses the speed based recovery percentage as a sort of "damage" to have a chance of not recovering the part. You'd have to remove the funds that SR adds back to the player (easy to do, SR passes the exact amount through the API). KCT has a similar booster recovery code, but KCT doesn't currently have an API. For this to work I'd likely have to write one, which should be easy enough if I know what I need to open up.

Link to comment
Share on other sites

yes.. i think i'll stick to case #1 which is how the mod should behave now. I'll just make sure there is no exploits to generate money, i think this should be simple enough.

I started a new game and so far i can't find any edge cases i missed, but i probably need 1 week of testing to be sure.

just a thought but what about having a scaled part consume multiple or a fraction of a default part? for example say you had a 2 units of certain fuel tank in your inventory. if you scaled it up to have the same mass and capacity as two of thosefuel tanks then it will cost both the default tanks in your inventory. alternately if you scaled down to a tank of half the mass and capacity it would only take half a tank leaving you with 1.5 units in your inventory, and finally if you recovered a scaled part it would be broken down into however many of the default part it is made up of (so recovering the double scale tank from the example would yield two default ones and recovering the half scale tank would give you half a unit worth of fuel tank)

Link to comment
Share on other sites

Hi magico!

Sounds good to me. I also use a dictionnary<string,int> to store the items, and I don't modify the costs of parts: the parts that you own are refunded when the vessel is rolled out.

The thing is, if i use your inventory, there isn't much code left in my mod :) , so I'd propose you let me handle this part. Then we could have one DLL that only takes care of the inventory, on which we base both our mods. no worries, i will keep testing this until it is flawless (and of course you are welcome to make any suggestion about the sources, since i only started modding kerbal last week.. the part you need is in inventory.cs and its just one page).

If that is agreable to you, I will split my project in 2:

  • inventory.dll : takes care of saving/loading the inventory and making it accessible to other parts
  • KSP4X.dll: the rest of my mod.. (display quantities in the part's icons, retrieve parts when a vessel is rolled out, recover parts when a vessel is recovered).

If you want to use the icons and the recovery/rollout mecanics then it's almost all my mod, so there wouldn't be a need to split it so far. The only problem with displaying the numbers in the icons would be the tweakscale compatibility, but i think i found a good solution for that (and in this case I plan on using the same naming convention as you for the scale).

For Inventory.dll, I propose the following specs:

  • Dictionnary<string,int> Part : list of parts
  • Get(name) : retrieves quantity available
  • Add(name, qty) : adds a certain quantity of items to the ones in store (negative value to retrieve)
  • Set(name, qty) : sets the quantity for a part
  • Commit(ConfigNode) : persist inventory in the savegame
  • Rollback(ConfigNode) : reloads inventory from the savegame

Optionaly:

  • Store(Part) : store the part and all its children recursively
  • Retrieve(Part) : retrieve (adds -1 unit) the part and all its children recursively

Of course, the naming and specs are open to suggestion.

Edited by SiriusSam
Link to comment
Share on other sites

I just finished modifying the Experiment missions:

When you pick a mission where you have to test an experimental part, you are given 1 unit to test.

So if you succeed the mission AND the part hasn't been destroyed in the process, it will remain in your inventory and you can reuse it as long as you keep recovering it. This makes the tests a lot more exciting already, because you really want to keep the part alive.

I still have to remove the part when the mission is cancelled, but at least the mod is playable now. I have restarted a game and I haven't had any glitches so far.

Link to comment
Share on other sites

That sounds like a good solution also!

I figured out another way to make it work:

  • By default indicate the quantity of normal sized (100%) items in the list. If other sizes are available, display an indicator (could be just one dot for each available size)
  • Right click the icon to switch between available sizes

So far we have 3 different solutions for this problem

  • don't store the sizes, but make the player pay extra for bigger parts, and refund him for smaller ones
  • store tweaked parts as fractions or multiples
  • switch between available sizes by right clicking

We still have a bit of time to decide, because:

1-I plan on making a lot of testing before going to the next updates. the base of the mod should be flawless, otherwise all the rest will go to s**t..

2-err... I just put my hands on an Oculus DK2 with the dev kit... so I'm experimenting with it in Unity and its taking a bit of time :)

Edited by SiriusSam
Link to comment
Share on other sites

In general I like the idea of the split and each of us referencing one dll. I'd like to also have access to the code for that so we can both make changes if necessary (though I doubt it will need much changed once it's created). Would we each package the dll in with our primary dlls? In which case we need to ensure only one gets loaded and it's the latest one (Module Manager does this, so do a few other mods). Or we could have it be in a separate folder (like Firespitter) with only one version in the GameData and we each reference that one. Either way opens it up for use as an API for other mods to use (StageRecovery then could check for it and could add parts to the inventory instead of doing it the other way around)

I wonder if the recovery adding to the inventory should be a basic function of the inventory.dll so that each mod doesn't have to write their own and disable it when the mod detects another mod using the inventory (right now it's just KCT and K4X so KCT could disable its own, but if a third mod comes in then it gets more complicated and we have to have some sort of hierarchy). If that's built in then we don't have that issue. I'm not sure what to do about pulling parts out on rollout, since KCT doesn't remove parts then (and you can build vessels without using any inventory parts), so we'd likely need to come up with a better solution for that.

I personally don't like having to use "Add" with a negative number to take parts out (it isn't intuitive) so an Add and a Remove (while basically identical) is a good idea. Have it default to qty=1 when no quantity is given. I don't know how you're saving to the persistence, but I think it's best to save every time the persistence saves and load every time it loads. Each mod shouldn't have to tell the inventory to load or save. KCT works this way so I can help with that.

We should setup a github repo for this and come up with a "fancy" name (like Shared Inventory System) :P

edit: just saw the comment on StageRecovery/DebRefund. Like I mentioned in here, I can have StageRecovery work with this if it detects it (I can maybe write up a basic wrapper class so mods can use this only if they detect it). There's a few differences (but in practice they're very similar). There's a comparison on the Curse/Kerbal Stuff pages. StageRecovery has powered recovery (rocket based recovery), an editor helper, a less annoying window for displaying what's recovered, in-game settings menu, and others.

Edited by magico13
Link to comment
Share on other sites

Name

I was going for something silly like Epic Lootz, but maybe i can keep that for my questline. Shared Inventory System... that's a bit too unsilly but I guess it can't hurt to be srious from time to time.

DLL

I suppose i'd have to configure the automatic major/minor increments on build so modulemanager finds it? or is it based on the date?

By any means, both solutions work for me.

Persistence Load/Save

I use the game events onGameSave and onGameLoad. But so far those events always triggered a call to persistence load/save (i tracked it in the debugger, but maybe there are exceptions?)

I played around with the persistence thing but i found too many different tutorials doing it completely differently and when i finally got it working it turned out serializing dictionnaries wasn't really his thing.....

Since that's the only thing i had to save, I figured it would be much easier to write my own parser for the load and save function (and it was).

Rant apart, if there are more benefits to peristenceload/save, I'm all for it.

Recovery:

Its probably a bad idea to leave it on by default. But we could just leave a recovership() function without linking it to the gameEvent. This way it wouldn't be too painful to activate it if the mod needs it and it wouldn't need to be written by every modder.

Same for the rollout, although this one seems more natural by default.

Adding a remove function:

Done, with default parameter for quantity.

Source

Right now, the link is in the description and the code hosted on my homeserver.

I can setup an SVN, my machine is almost always on but i can't guarantee i won't have to reboot it (windows..) or that i'll never have a downtime.

So a github sounds like a good idea. I never used it yet (i usually use SVN), so let's figure it out!

Stagerecovery

Well this is a much needed feature, and since it appears you are the author of the mod i think this settles the question. :)

Edited by SiriusSam
Link to comment
Share on other sites

I'm gonna borrow how you responded since it seems functional

Name

I figure the backend that will be shared between our mods and hopefully other mods in the future should have a semi-serious name, but I'm up for something less than very serious :P It should be somewhat descriptive though.

DLL

I was mentioning Module Manager since it knows to only load the latest version of the module manager dll. I think a shared folder system (GameData/YourMod/YourDLL, GameData/InventoryMod/inventory.dll) would be easiest to implement, but it means users may overwrite a newer version of the inventory.dll (but it shouldn't change much anyway)

Persistence

Like I mentioned before, it should just automatically stay linked to the persistence, however you want to do that. I make my dictionaries into lists with alternating "name" and then "qty" so having 3 mk1pods would be mk1pod, 3, nextPartName, nextPartQty, etc How it ultimately works doesn't matter too much as long as it works.

Recovery

We can set it up so a mod has to request recovery to be active (and maybe the same for on rollout). Rollout isn't very trivial for KCT. I infact NEVER want to remove parts on rollout, but only when the ship is added to the build list (and then only some of them), while your mod will want to remove all the parts on rollout. The two combined will obviously not work properly, so we need to figure something out there.

Source

Github is really nice to use with Visual Studio. I also used SVN in the past for other projects as my Linux server has svn on it (and is running virtually 24/7. All my update checkers point to it). Github is also good for multiple people working on things at once, from what I hear.

StageRecovery

Getting SR to work with it will be easy once we've got it set up. I'll need to make it respect if recovery of ships should add parts to the inventory.

Events

I think there should be events called whenever something is added/removed/qty set in the inventory. I can set that up pretty easily and I don't know if people would really use it, but it feels appropriate.

Link to comment
Share on other sites

It's 1 am here so just a quick thing about the rollout:

Not all parts are removed from the inventory on rollout, but only the ones you currently have in store, the rest (negative values in the editor list) is purchased.

Maybe it would be useful to have a function that scans a ship and returns all the missing parts on one hand and the ones available in the inventory on the other.

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...