Page 1 of 1
Best way to store a list of visited systems?
Posted: Mon Jul 04, 2011 7:35 am
by Wildeblood
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?
Re: Best way to store a list of visited systems?
Posted: Mon Jul 04, 2011 10:30 am
by Eric Walch
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.
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.")
}
}
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