foof
New Member
Posts: 31
|
Post by foof on Oct 15, 2016 15:48:34 GMT
If you want to share a ship that has custom modules you currently have to copy it and the custom modules manually out of the UserDesigns.txt file. The recipient has to do the same in reverse, this is a error-prone and cumbersome process. I thought this sounds like a job for Regular Expressions, my plan is to use a Python script that: 1. Loads the UserDesigns.TXT 2. Finds the custom ships 3. Create a dialog where you can choose the ships you want to export 4. Put the the ship plus all the needed custom modules into a single txt file 5. Let's the recipient add or remove custom ships and or modules to his UserDesign.txt 6. Make a nice GUI with ship/module previev Unfortunately I failed already at step 2 I first tried: re.findall(r"CraftBlueprint(.*?)CraftBlueprint",UserDesigns,re.DOTALL) #Figure out what I'm doing here But this has two problems first it excludes the "CraftBlueprint" string itself and second it does not catch the last ship. After three hours of googling and reading StackOverflow post I gave up. I just need a RegEx that says: "Select everything starting with CraftBlueprint until the next empty line" can't be that hard right? Edit: A couple of RegEx tutorials later: r"CraftBlueprint[\S\s]*?\n\n" did the trick
|
|
|
Post by nivik on Oct 18, 2016 20:36:20 GMT
Hmm. Interesting. I might take a look into this.
|
|
|
Post by ross128 on Oct 18, 2016 21:01:48 GMT
Hmm, I expect the really "fun" part will be looking up all the custom modules attached to the ship you want to import, and importing those too. For example, to import my MIRV drone carrier you'd need (among other things) the drone launchers and their ammo, which will require the drones, which will require the payload launchers and their ammo, which will require the MIRV warhead, which will require the nuke and rad-shield inside the warhead. On the bright side, at least the dependency tree won't loop back on itself. Once import tools are available though, I wouldn't be surprised if people simplified things using packages that share standardized parts, and people started settling on relatively well-optimized packages as a baseline (sort of a "before you start going wild in the module creator, download these to give yourself a head start" thing). It will be quite amusing to watch the chaos while that process shakes out though.
|
|
erin
Junior Member
Smash Mouth Plays From The Depths Of Hell As You Traverse A Deep, Rat-Infested Cave
Posts: 57
|
Post by erin on Oct 18, 2016 21:12:54 GMT
Agree. Some manner of subassembly sharing would be useful too at some point
|
|
|
Post by captinjoehenry on Oct 19, 2016 1:01:29 GMT
This would be amazing! I have no idea where to begin and this definitely strikes me as something that should be officially part of the game but failing that we need to make it ourselves.
|
|
foof
New Member
Posts: 31
|
Post by foof on Oct 19, 2016 10:38:33 GMT
Hmm, I expect the really "fun" part will be looking up all the custom modules attached to the ship you want to import, and importing those too. For example, to import my MIRV drone carrier you'd need (among other things) the drone launchers and their ammo, which will require the drones, which will require the payload launchers and their ammo, which will require the MIRV warhead, which will require the nuke and rad-shield inside the warhead. <Snip> Well this is exactly the reason why I'm working on a tool to do that, oh and you forgot custom materials and the other modable stuff. Would you (or anybody else) be so kind to upload your UserDesings.txt? I need some test data and creating multiple custom ships takes a lot of time better spend coding.
|
|
|
Post by beatle on Oct 19, 2016 11:57:56 GMT
This is a great idea, foof!
I was thinking about a tool with partially overlapping functions, but, at a first glance, it seamed to me that custom modules don't really have a way to definitely ID them and discern a new custom module from merely changed old one between multiple sessions of game. This would be much too limiting for the requirements I had. But maybe I was wrong and you have discovered something more on this?
In any case, ability to give custom names to user created modules would be a great feature for better management of parts and role playing purposes.
|
|
foof
New Member
Posts: 31
|
Post by foof on Oct 19, 2016 12:40:21 GMT
This is a great idea, foof! I was thinking about a tool with partially overlapping functions, but, at a first glance, it seamed to me that custom modules don't really have a way to definitely ID them and discern a new custom module from merely changed old one between multiple sessions of game. This would be much too limiting for the requirements I had. But maybe I was wrong and you have discovered something more on this? In any case, ability to give custom names to user created modules would be a great feature for better management of parts and role playing purposes. Well BlackBox weapons have custom names but adding the WeaponName entry to stock weapons doesn't change the displayed name, changing the name behind the *Modlue string is also ignored. I think I will, at least for the first version, put each module in a separate text file and then just diff them. If there are different versions of "1MW Laser" I will prompt the user to input a new name. Unless qswitched implements custom names for modules there is probably no other way then parsing all properties of the module, but that doesn't solve the issue of user-friendliness. But displaying the stats together with a screenshot (or rendered model) is a planned feature anyway
|
|
|
Post by 314159 on Oct 19, 2016 12:43:53 GMT
Well this is exactly the reason why I'm working on a tool to do that, oh and you forgot custom materials and the other modable stuff. Would you (or anybody else) be so kind to upload your UserDesings.txt? I need some test data and creating multiple custom ships takes a lot of time better spend coding. I have some prototype code for doing pretty much exactly that, which I now guess I won't continue since you seem to actually have the time to work on that :-) Here's my UserDesigns, anyways. It includes some designs by another user (who had posted the whole thing; I forgot their name but it does include the Count Flakula missile), and several other, posted, designs. Other than that, it's a pretty huge mess. UserDesignsTestMerge.txt (77.22 KB) There you go. Edit: The way I originally planned handling that was to check, for each module, whether another module existed. If so, check whether they're identical. If not, rename them such that each name is numbered consecutively and uniquely over two files. That's already finished, btw. Do you want the code?
|
|
foof
New Member
Posts: 31
|
Post by foof on Oct 19, 2016 13:49:53 GMT
I have some prototype code for doing pretty much exactly that, which I now guess I won't continue since you seem to actually have the time to work on that :-) Well I just foolishly disregard my other duties And please finish your project, I'm just an electrical engineer and my coding experience is very limited, this could take some time. Yes please, that would be helpful!
|
|
|
Post by nivik on Oct 19, 2016 14:27:53 GMT
Hmm, I expect the really "fun" part will be looking up all the custom modules attached to the ship you want to import, and importing those too. For example, to import my MIRV drone carrier you'd need (among other things) the drone launchers and their ammo, which will require the drones, which will require the payload launchers and their ammo, which will require the MIRV warhead, which will require the nuke and rad-shield inside the warhead. On the bright side, at least the dependency tree won't loop back on itself. Once import tools are available though, I wouldn't be surprised if people simplified things using packages that share standardized parts, and people started settling on relatively well-optimized packages as a baseline (sort of a "before you start going wild in the module creator, download these to give yourself a head start" thing). It will be quite amusing to watch the chaos while that process shakes out though. If the game can figure out which module is which, a tool can do it. :3 What I'd probably do -- if it were me -- is scrape all the modules and store them in a lookup table (map) by their name, then only print the modules you need into a file. Dependency resolution is going to be a search algorithm, though, because you can have modules that require ships, which also require modules, which might also require ships. IE: missile launching drones. Depth-first search would probably be easiest. Thankfully, you can search through and just flag what modules are needed, and then come back later to print those out to the file. You also need to identify stock modules and not duplicate them. So the rough algorithm would be: main() { getStockDesignsFromFileAndMarkAsStock() getUserDesignsFromFile()
flagDesignsUsedBy(shipName)
printFlaggedNonStockDesignsToFile() }
// depth-first search of a blueprint to flag its components or payload // returns nothing; assume isFlagged() and flag() functions act on a global-scope map/dictionary flagDesignsUsedBy(blueprint) { foreach(design in blueprint) { if(isFlagged(design) == false) { // will loop infinately if you don't check! foundAtLeastOneNewDesign = true flag(design) flagDesignsUsedBy(design) // recursive function call } } } I blocked out the recursive/depth-first search part of the algorithm, too, since I think that stuff is tricky if you don't have much exposure to it. I apologize in advance for underestimating folks if I'm wrong. :3 Also, take this with a grain of salt. I glossed over a lot of details and probably missed something important. This is a ten-minute outline, primarily focused around solving the problem of a lot of sub-drones, sub-missiles, etc.
|
|
|
Post by 314159 on Oct 19, 2016 16:04:44 GMT
Yes please, that would be helpful! There you go. def extract_modules_from_file(filename): txt = open(filename) lines = []
for line in txt: lines.append(line) modules = {} cur_item = [] is_module = False for line in lines: if line == '\r\n': if cur_item: module_name = cur_item[0].split(' ', 1) modules[module_name[1].strip()] = cur_item cur_item = [] else: cur_item.append(line) return modules
def identically_named_modules(modules): names = {} for k in modules.keys(): raw_name = k if k.split(" ")[-1].isdigit(): raw_name = string.join(k.split(" ")[:-1]) if raw_name in names: names[raw_name].append(k) else: names[raw_name] = [k] return names
def modules_in_order(modules): # Takes a list of the same basis module (p.ex. # ['5.00 kg Octogen Flak Bomb 2', '5.00 kg Octogen Flak Bomb']) # and returns them in order of their index, with no index being # equivalent to 1. # Important: Duplicate modules will be removed! module_dict = {} for m in modules: try: idx = int(m.split(" ")[-1]) except: idx = 1 module_dict[m] = idx return sorted(module_dict, key=module_dict.get)
def eliminate_duplicates(modules1, modules2): merged_modules1 = identically_named_modules(modules1) merged_modules2 = identically_named_modules(modules2) for m_base_name in merged_modules2.keys(): if m_base_name in merged_modules1: max_index = 1 for m_name in merged_modules1[m_base_name]: try: idx = int(m_name.split(" ")[-1]) max_index = max(idx, max_index) except: pass for m_name in reversed(modules_in_order( merged_modules2[m_base_name])): try: idx = int(m_name.split(" ")[-1]) idx += max_index new_name = string.join(m_name.split(" ")[:-1]) + " " + str(idx) except: idx = max_index + 1 new_name = m_name + " " + str(idx) m_name_idx = merged_modules2[m_base_name].index(m_name) merged_modules2[m_base_name][m_name_idx] = new_name # new name has been registered; now we need to # actually replace it in all occurrences for k in modules2.keys(): for j in range(len(modules2[k])): modules2[k][j] = string.replace(modules2[k][j], m_name + "\t", new_name + "\t") modules2[k][j] = string.replace(modules2[k][j], m_name + "\r\n", new_name + "\r\n") return modules1, modules2
It's all extremely primitive at the moment. What it's able to do is extract designs from a file and, given two such extracted lists (well, dictionaries), rename the modules therein to avoid duplicates. What it does not yet do is check if the design's a duplicate or not; or do the actual merging. Or is optimized. Or actually tested. What I'd probably do -- if it were me -- is scrape all the modules and store them in a lookup table (map) by their name, then only print the modules you need into a file. Dependency resolution is going to be a search algorithm, though, because you can have modules that require ships, which also require modules, which might also require ships. IE: missile launching drones. Depth-first search would probably be easiest. Agreed, for a larger project. Keeping a list of requirements, then exporting them plus (recursively) all others.
|
|
|
Post by shiolle on Oct 19, 2016 16:05:58 GMT
foof , could I ask what programming language you are using?
|
|
foof
New Member
Posts: 31
|
Post by foof on Oct 19, 2016 17:09:22 GMT
foof , could I ask what programming language you are using? Sure, I'm using Python plus RegEx. I already made a github and will publish the code when I it's ready and properly commented. But I also want to make executables with proper installers for CommerceOS, HipsterOS and HippieOS.
|
|
|
Post by Trev_lite on Oct 20, 2016 19:19:19 GMT
I hope we get a way to have ai fleet battles against other players fleets like in the game reassembly.
|
|