[Suggestion] Add better ship manipulation to PRPL

Started by kajacx, December 04, 2016, 06:28:41 AM

Previous topic - Next topic

kajacx

I am working on a map where players can merge their existing ships into a larger ship. However I am missing several PRPL functions to make it truly possible.

- The most important
The most needed right now is the ability to instantly build a ship. Otherwise, there is no point in mergings ships together, if you will have to wait 5 minutes for the merged ship to build. I can add the merged ship to ship inventory, but I need to automaticly (and isntantly) do these 5 steps:
  1. request building of the ship at a location
  2. build the command module [solved]
  3. build the rest of the hull [solved, kindof, might only work because SetShipEnergy is bugged]
  4. build the modules
  5. fill the ship with energy [solved]
The most important step in the second one, since it takes the longest time. I have tried both SETHULLBUILDRATEMOD and SETUNITISBUILDING but it didn't seem to do anything.

- The important
Next functions I would like are: GetShipModules and GetShipCommandLocation. First would return a list of all modules on a ship (with locations), the second one would return the location of the command module. Why is this important? Currently, the merging only works for my own ships, because there is no way (that i know of) to read module info of command lcoation from a ship with PRPL.
So if someone wants to re-use my code for merging ships, they need to rewrite large portions of the PRPL code, which is not great.

- The not so important
One more function I would like to see is support for mutable strings. I know this is asking for a lot, since it would require a new datatype to be implemented, but currently I do base64 encoding by adding one char at a time, which is slow as hell (quadratic complexity instead of linear). Or a base64encode function would work as well, but this is low-priority, I know there are more important issues at hand. [Solved by using the  "A B C D -> AB CD -> ABCD" concatenation scheme instead]

Finally I add how my merging of ships looks like currently:
Spoiler
[close]

Thanks for considering to implement these, I added the map I have, just move the ships you want merged to the highlighted area and hit Compile in level editor.
Why do work yourself, when you can write a program that will do the work for you.

GoodMorning

Good news: The CM can (probably, may be NYI) be insta-built, using <-Ship.CMCost ->Ship.CMBuiltAmt. I'm not sure if <-Ship.EnergyCap ->Ship.Energy is implemented. Creating ships is possible, thought I don't know slot-binding.

Hull- and module-building is impossible at the moment, I think, but could be useful.

SetHullBuildRateMod may affect the ship, or it may be specific to non-player ships (documentation pending). SetUnitIsBuilding does not affect ships, as ships are considered to be distinct from "units".

I think that mutable strings might be harder than PRPL commands for ship-plan editing directly. I doubt that either will become standard.

You might be able to raise efficiency a little by joining substrings, A B C D -> AB CD -> ABCD.
A narrative is a lightly-marked path to another reality.

kajacx

Thanks,  '<-id CONST_SHIP_CMBUILTAMT <-id GetShipCMCost SetShipAttribute'  works great at insta-building the command module.

I then proceeded to spam  '<-id 10000 SetShipEnergy' every frame for 3 seconds, it builds the hull almost instantly. (I didn't find where to get maximum energy, CONST_SHIP_ENERGYCAP doesn't seem to work yet). As for the modules, I don't mind if they don't get build instantly, this is already amazing!

"Creating ships is possible, thought I don't know slot-binding." Can you expand on that? I have a base64 encoded ship info (the same that you get from "PRPL data to clipboard" in ship editor), and add that ship to inventory via AddCustomShipToInventory.

For string concat, yes, "A B C D -> AB CD -> ABCD" would give n*log(n) complexity instead of n*n, I'll probably rewrite it.
Why do work yourself, when you can write a program that will do the work for you.

GoodMorning

I cannot recall if it is possible to build the ship from a slot. Ships can be created, and plans can be bound to a slot, but getting a ship built that is associated with a given slot...

I seem to have missed the word "about" in that sentence you quoted.
A narrative is a lightly-marked path to another reality.

GoodMorning

A narrative is a lightly-marked path to another reality.

kajacx

Thanks for the script.

"Ships can be created." What I wanted to ask is: How? How can ships be created? I haven't found anything. Can you create stock ships only, or custom ships as well? It could be helpful.
Why do work yourself, when you can write a program that will do the work for you.

GoodMorning

Hmm... The doc just went up, and now I am unsure that we can (yet) create ships.
A narrative is a lightly-marked path to another reality.

planetfall

Something else I was considering: AddShipToInventory that takes the UID of a ship on the map. If it's possible to delete a ship from the inventory while keeping it built on the map, it should be possible to put the control button back.

This would allow things like a larger inventory that can be scrolled with prpl buttons.

Another thing in this vein that would be nice would be the ability to make PRPL cores mimic the 3D and animated stuff from built-in units without having to add hundreds of custom images (emitters and the spinning ship spawner ring especially.) Would be useful for making custom-pattern emitters look "normal" and creating ship spawners that use custom modules. As it stands, spawners with custom modules need a watcher core that calls the (presumably expensive) GetAllShipsInRange every frame. The ability to spawn a ship and mimic the normal spawner's appearance, while maintaining a copy of the ship's UID for easy module spawning would make enemy custom ships more feasible (see also: abominable performance in Mutually Assured.)
Pretty sure I'm supposed to be banned, someone might want to get on that.

Quote from: GoodMorning on December 01, 2016, 05:58:30 PM"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.

GoodMorning

Well, I think that the PRPL ship API is still WIP and in need of cleanup. Hopefully this thread will give an indication of what will be desired.
A narrative is a lightly-marked path to another reality.

kajacx

QuoteThis would allow things like a larger inventory that can be scrolled with prpl buttons.

The is acctually a way to have arbitarly large fleet, I can't find the original post unfortunately, but I'll add the map save.
It's acctually surprisingly short, not even 30 lines, it just deletes the ship button in the ship inventory without deleting the ship in-game, and then adds a new button. (unlike my 1400+ lines abomination)
Why do work yourself, when you can write a program that will do the work for you.

planetfall

That was my own creation :)

However, it's only arbitrarily large if you don't mind being confined to 24 ship types and not having a button for each individually.
Pretty sure I'm supposed to be banned, someone might want to get on that.

Quote from: GoodMorning on December 01, 2016, 05:58:30 PM"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.

GoodMorning

Can we yet extract the serialized ship plan from a slot? If so, another part of this can be realised.
A narrative is a lightly-marked path to another reality.