-
Notifications
You must be signed in to change notification settings - Fork 54
Libraries
The qlib libraries are all developed as part of the Quorum project. The global qlib object will load any of the qlib libraries.
This is a selection of interesting classes, but for a full list review the source code.
This library is used to track the last occurrence of a specific event (which is just a unique string).
qlib.events.getEventTime(event)qlib.events.recordEvent(event)qlib.events.getTimeSinceEvent(event)
The Genome project is used to add variance to different bots that are running the NPC code. An instance of Genome takes a string (such as the bot name) as a constructor argument which feeds into a Lehmer RNG (thus giving it repeatable results).
The trait function uses this to return phenotype data, which is represented as an integer and can be restricted to specific ranges. Traits are weighted towards the center of the range (a range of 0-9 will have a 66.82% change of being 4, 5, or 6 and a less than 10% chance of getting 1, 2, 8 or 9. This makes extreme traits less likely to occur (but still possible). Each trait also takes an expected value which will always be returned if the bot is named Quorum.
let myGenome = new Genome('Bob')
// Default result of five (for Quorum), returns anywhere between 1 and 9 weighted for 5.
myGenome.trait('aggression', 5, {range: 4})
myGenome.trait('aggression', 5, {min: 1, max: 9})The qlib.map.findRoute function acts just like the Game.map.findRoute except it uses the default Quorum room scoring functions (which penalizes hostile rooms).
The qlib.market functions supplement the existing market functions
-
qlib.market.getAveragePrice(resource, orderType)returns the rolling average price calculated over the last 37500 ticks. qlib.market.getOrdersByType(resource, orderType)-
qlib.market.getCurrentPrice(resource, orderType)returns the current price by calculating the order price after excluding the first 1000 units. qlib.market.sellImmediately(resource, room, quantity)qlib.market.buyImmediately(resource, room, quantity)-
qlib.market.getHighestMineralValue()returns the cost of the highest valued base mineral (typically catalyst but it doesn't make that assumption).
The qlib.notify library is a wrapper around the screeps-notify project. It is used to send notifications to the #quorum-logs channel from the main Quorum account. When run as a bot on private servers it is a null operation.
-
sos.lib.cache.get(label, opts)-
ttldefines how long the cached item should be used. By placing it in thegetfunction it can be adjusted based on the current system (for example, storingcostmatrixesand then extending their TTL when the room isn't visible).
-
-
sos.lib.cache.set(label, data, opts)-
persistpushes the object intoMemory. -
compressshrinks the object withlzstring. -
maxttlputs a final expiration date on the stored object.
-
-
sos.lib.cache.clear()empties the entire cache.
-
sos.lib.counter.get(group)returns an integer of increasing value with each call, starting with1. -
sos.lib.counter.set(group)overrides the current value with a supplied on. -
sos.lib.counter.reset(group)clears the specified counter.
-
sos.lib.getPriorityRunStats(priority)returns an object describing how often programs at the specified priority run. The object has three values-short(last 200 ticks),medium(last 1000 ticks),long(last 3000 ticks). A value of1means it runs every tick,2means every other tick, and increasing values represent larger gaps. This function returns floats as well as integers.
-
sos.lib.uuid.v4returns a UUID following thev4standard. This is a big ugly string. -
sos.lib.uuid.vsreturns a unique string that is guaranteed to be unique, even across shards.
There are other libraries in the thirdparty directory.
-
creeptalk- this is how the creeps talk. -
RoomVisualprovides extra visualizations (structures and speech bubbles).