While I am waiting for my download, I will demonstrate a way to add randomly chosen 2-way gate links in a given topology structure.
First of all, I created a blank system element to put the <OnGlobalTopologyCreated> event in. This will be called in the beginning of the game, when the topology has been prepared, before the player enters Eridani.
Code: Select all
<SystemType UNID="&ssTopoMaster;">
<Events>
<OnGlobalTopologyCreated>
</OnGlobalTopologyCreated>
</Events>
</SystemType>
First it is time to set up some variables for the process:
Code: Select all
(block (minBase maxBase sysList gateList rand levelOffsetMax)
(setq minBase 5)
(setq maxBase 25)
(setq levelOffsetMax 3)
(setq rand (random minBase maxBase))
(dbgLog "Number of Links to be made: " rand)
Next get a list of the systems using filter:
Code: Select all
(setq sysList (filter (sysGetNodes) sysID (sysHasAttribute sysID "goodLinks")))
There is much more that could be done for linking through filters. Say you wanted to have a the nodes divided? Say a set for the origin and a set for the destination. You could simply produce two lists in this manner, with the attribute in the nodeID to distinguish them.
Next it is time to start making some links. 'rand' was created to define the number of links to be made, so now the link process will simply repeat that many times in a (for:
Code: Select all
(for i 1 rand
(block (linkA offSet linkB gatesA gateNameA gatesB gateNameB levelA gateSeed)
(setq linkA (random sysList))
(setq levelA (sysGetLevel linkA))
(setq offSet (random 0 levelOffSetMax))
Next the destination is chosen, which refers to another function to return it.
Code: Select all
(setq linkB (topoGetTargetFiltered sysList linkA levelA offSet))
In the next step a count of the gates is found for each system to help uniquely name the gate to be created and the names for the gates are made. The destination node uses an existing gate in gateSeed, so the destination node must have at least one gate. After the names are made, the stargate links are added.
Code: Select all
(setq gatesA (count (sysGetStargates linkA)))
(setq gatesB (count (sysGetStarGates linkB)))
(setq gateSeed (item (sysGetStargates linkB) 0))
(setq gateNameA (cat "RandGate" gatesA))
(setq gateNameB (cat "RandGate" gatesB))
(sysAddStargateTopology linkA gateNameA linkB gateSeed)
(sysAddStargateTopology linkB gateNameB linkA gateNameA)
;(dbgLog "used Seed: " gateSeed)
;(dbgLog (cat linkA " added " gateNameA " linked " linkB " with gate " gateNameB))
)
);end main iteration
Code: Select all
(dbgLog "Sucessfully Completed Randomizing.")
)
Code: Select all
(setq topoGetTargetFiltered (lambda (sysList linkA levelA offSet)
(block (targetList target)
;start building the targetList
(setq targetList (filter sysList sysID (eq (sysGetLevel sysID) levelA)))
(if (geq offSet 1)
(block nil
(setq targetList (filter sysList sysID (leq (sysGetLevel sysID) (add levelA offSet))))
(setq targetList (filter targetList sysID (geq (sysGetLevel sysID) (subtract levelA offSet))))
(dbgLog (count targetList) " nodes targetted")
)
);end if
(setq target (topoPickATarget targetList linkA))
)
))
Here is the quick filter for the actual nodeID now that the targetList is ready:
Code: Select all
(setq topoPickATarget (lambda (targetList linkA)
(block (linkID)
(setq linkID (random targetList))
(if (eq linkID linkA)
(setq linkID (topoPickATarget targetList linkA))
)
linkID
)
))
The grand result of those two little functions is to return a single nodeID that becomes the destination in linkB of the event block.
When applied to a linear topology, this can produce an interwoven network by adding extra links that create loops.
When applied to a topology that is built from segments with loops and complex networks the results can be very interesting.
One really cool effect was to tie together smaller rootNode anchored sections by adjusting the script to target a different set of attributes between each link, and assinging those to the segments- in addition to the level, a check for the attributes was made and the target list filtered to create a bridge between two independent network areas.
Any ideas on improving this script? Questions?