Stupid Newbie Question

I am trying to write a plugin that will load a text file with a list of bodies along with political affiliations, and proceed to find said bodies in the currently loaded sector and change their PoliticalAffiliation property as per the file.

My problem is what key to use to locate the desired body object in the sector.

The Sector.GetSystem(integer) method needs an int argument, does this mean that for each change I have to iterate through GetSystem(), check the Body.Name property (or something) to find a match, then change the Body.PoliticalAffiliation property as desired? There does not seem to be a way to look up bodies by their UABI, not that the UABI is easily accessible.

I could export the entire sector into an XML file with XMLExport.AstroScript, write a Python program to parse it and forcibly change the political affiliation, then import it into AstroSynthesis via XMLImport.AstroScript. But that just seems to be a round about way to perform the task.

What I am trying to do is create a map with multiple interstellar empires, with ownership of each system defined by which "empire center" is the closest.
http://www.projectrho.com/public_html/rocket/stellarempire.php#ascubemap

Comments

  • edited March 31

    Every body has an IDString property, which is the UABI. This looks like its missing in the docs. Its actually a property of an ancestor class, which is probably why it was missed in the docs.

    For ex:

    sector = GetCurrentSector()
    b = sector.GetSystem( 0)   'these are 0 based
    MsgBox b.IDString
    

    There's no lookup by UABI, so you'd have to iterate each body (and their children if not just working with root bodies).

    Alternatively, you can write to the AstroDB file directly using Python, as the AstroDB file is an SQLite database. You can then use SQL to make the changes to the database.

    for ex:

    update bodies set political_affiliation = "some empire" 
          where id_string = "{E24A5F72-253A-4CEF-B8D0-4DA156E6E839}"
    
  • Here's a sample using recursion to find a body by UABI. This was a quick hack, so may not be the most efficient.

    #plugin     UABI Finder
    #author     NBOS
    #desc       Finds a body by UABI using recursion
    
    
    Dim WasFound, FoundBody
    Dim s
    
    sector = GetCurrentSector()
    
    
    s = "{F82527A3-F773-45D9-A134-D7CC24580069}"
    FindByUABI s
    
    If WasFound Then
        MsgBox FoundBody.Name
    End If
    
    
    Sub FindByUABI( uabi)
    
        Dim i, n
        WasFound = false
        n = sector.SystemCount()
        For i = 1 to n 
            b = sector.GetSystem( i -1)
    
            If b.IDString = uabi Then
                FoundBody = b
                WasFound = true
                Exit Sub
            End If
    
            FindInChildren b, uabi
            If WasFound Then
                Exit Sub
            End If
        Next
    End Sub
    
    
    Sub FindInChildren( p, uabi)
        Dim i, n
        Dim b
        n = p.ChildrenCount()
        For i = 1 to n
            b = p.GetChild( i-1)
            If b.IDString = uabi Then
                FoundBody = b
                WasFound = true
                Exit Sub
            End If
        Next
    
        For i = 1 to n
            b = p.GetChild( i-1)
            FindInChildren b, uabi
            If WasFound Then
                Exit Sub
            End If
        Next        
    End Sub
    
  • Thank you! I'll give it a go.

Leave a Comment