Thanks to George for making the Wand of Wishing available. It has given me the idea to add a ship auto-upgrade feature to the Taipan GodShip mod. This will only apply when the player uses a non-god ship but will allow them to select a level and have items of that level auto-installed on the ship. A considerable time saving.
But I'm having a bit of trouble with the code.
This code creates a struct with level 10 item types for all the necessary items:
Code: Select all
(block Nil
(setq theStruct Nil)
(setq theLevel 10)
(setq theTypes (typFind (cat "'i=" theLevel)))
(setq categoryList (list 'weapon 'launcher 'reactor 'shields 'armor))
(enum categoryList theCategory
(setq theStruct
(structAppend theStruct
theCategory
(random (filter theTypes type (eq (typGetProperty type 'category) theCategory)))
)
)
)
)
What is needed is to check other levels until an item is found.
So check level 9 for reactors, if no reactors of level 9, check level 8, etc.
I've messed about with 'for' and 'loop' but can't quite work out a way of stopping the code when a reactor is found. Possibly it needs 'enumWhile' instead (or as well) but I've never used that function.
While I could do the extremely time-consuming trial and error thing, it would be better if someone would be kind enough to post some basic code, perhaps with a couple of comments, which could do this.
The requirement is for a reactor type of the desired level to be added to the struct, but if no reactors of that level exist then a reactor of the next level down. If there still isn't a reactor, continue through all levels down to level 1.
The other alternative is to get all the reactors and sort them by level, then select a reactor of the desired level or lower. I don't know which way would be better. Or if there is a better way?
Anyone got any ideas? Thanks.