Best way to store a list of visited systems?

General discussion for players of Oolite.

Moderators: another_commander, winston

Post Reply
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2286
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Best way to store a list of visited systems?

Post 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?
User avatar
Eric Walch
Slightly Grand Rear Admiral
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?

Post 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
Post Reply