UNPKG

@screeps/engine

Version:

This is a module for Screeps standalone server. See [main repository](https://github.com/screeps/screeps) for more info.

46 lines (36 loc) 1.37 kB
var utils = require('./../utils'), rooms = require('./rooms'), driver = utils.getRuntimeDriver(), C = driver.constants; var runtimeData, intents, register, globals; exports.make = function(_runtimeData, _intents, _register, _globals) { runtimeData = _runtimeData; intents = _intents; register = _register; globals = _globals; if(globals.Source) { return; } var data = (id) => { if(!runtimeData.roomObjects[id]) { throw new Error("Could not find an object with ID "+id); } return runtimeData.roomObjects[id]; }; var Source = register.wrapFn(function(id) { var _data = data(id); globals.RoomObject.call(this, _data.x, _data.y, _data.room, _data.effects); this.id = id; }); Source.prototype = Object.create(globals.RoomObject.prototype); Source.prototype.constructor = Source; utils.defineGameObjectProperties(Source.prototype, data, { energy: (o) => o.energy, energyCapacity: (o) => o.energyCapacity, ticksToRegeneration: (o) => o.nextRegenerationTime ? o.nextRegenerationTime - runtimeData.time : undefined }); Source.prototype.toString = register.wrapFn(function() { return `[source #${this.id}]`; }); Object.defineProperty(globals, 'Source', {enumerable: true, value: Source}); };