What is the most efficient way to store a long list of systems the player has visited in mission variables? Is comparing two such lists (systems required to visit versus systems already visited) a trivial or difficult scripting task? Are there examples of mission OXPs that require the player to visit either (a) sequence of systems in particular order, or (b) a list of systems in any order?
Is there any interest in (or prior example of) a Customs Control OXP, that allows the player to carry controlled commodities without becoming an offender provided they stay on an approved route, but makes them a super-fugitive if they deviate from the correct route?
Best way to store a list of visited systems?
Moderators: winston, another_commander
- Wildeblood
- ---- E L I T E ----
- Posts: 2453
- Joined: Sat Jun 11, 2011 6:07 am
- Location: Western Australia
- Contact:
- Eric Walch
- Slightly Grand Rear Admiral
- Posts: 5536
- Joined: Sat Jun 16, 2007 3:48 pm
- Location: Netherlands
Re: Best way to store a list of visited systems?
Ahruman posted such a method years ago. I could not find his post, but stored his code on my disk. It comes down to create a missionvariable for each galaxy and store the visited systems as bits within that variable.
Note that this is old code and some handlers are renamed in current Oolite. However, current Oolite support JSON variables for storage. That might be even more efficient, but I have no experience with that. More about it you can find here
Code: Select all
this.clearAllBits = function()
{
this.bitmap = [0, 0, 0, 0, 0, 0, 0, 0, 0]
}
this.clearAllBits() // Initialize bitmap at startup
this.isBitSet = function(bit)
{
var index = Math.floor(bit / 30)
var bitID = bit % 30
return (this.bitmap[index] & (1 << bitID)) != 0
}
this.setBit = function(bit)
{
var index = Math.floor(bit / 30)
var bitID = bit % 30
this.bitmap[index] |= (1 << bitID)
}
this.clearBit = function(bit)
{
var index = Math.floor(bit / 30)
var bitID = bit % 30
this.bitmap[index] &= ~(1 << bitID)
}
this.saveBits = function()
{
for (var i = 0; i < 8; i++)
{
var key = "ups_bitmap_" + galaxyNumber + "_" + i
missionVariables[key] = this.bitmap[i]
}
}
this.loadBits = function()
{
for (var i = 0; i < 8; i++)
{
var key = "ups_bitmap_" + galaxyNumber + "_" + i
this.bitmap[i] = missionVariables[key]
}
}
this.reset = function()
{
this.loadBits()
}
this.playerEnteredNewGalaxy = function()
{
this.loadBits()
}
this.didExitWitchSpace = function()
{
if (!this.isBitSet(system.ID))
{
this.setBit(system.ID)
this.saveBits()
player.credits += 250
player.consoleMessage("Advert shown.")
}
}
UPS-Courier & DeepSpacePirates & others at the box and some older versions