UNPKG

@screeps/engine

Version:

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

78 lines (61 loc) 1.92 kB
'use strict'; var _ = require('lodash'), utils = require('../../../utils'), driver = utils.getDriver(), C = driver.constants; module.exports = function (spawn, intent, roomObjects, roomTerrain, bulk, bulkUsers, roomController, stats) { if (spawn.spawning) { return; } if (spawn.type != 'spawn') return; if (!utils.checkStructureAgainstController(spawn, roomObjects, roomController)) { return; } intent.body = intent.body.slice(0, C.MAX_CREEP_SIZE); var cost = utils.calcCreepCost(intent.body); var result = require('./_charge-energy')(spawn, roomObjects, cost, bulk, intent.energyStructures); if (!result) { return; } stats.inc('energyCreeps', spawn.user, cost); stats.inc('creepsProduced', spawn.user, intent.body.length); bulk.update(spawn, { spawning: { name: intent.name, needTime: C.CREEP_SPAWN_TIME * intent.body.length, remainingTime: C.CREEP_SPAWN_TIME * intent.body.length } }); var body = [], energyCapacity = 0; intent.body.forEach(function (i) { if (_.contains(C.BODYPARTS_ALL, i)) { body.push({ type: i, hits: 100 }); } if (i == C.CARRY) energyCapacity += C.CARRY_CAPACITY; }); var creep = { name: intent.name, x: spawn.x, y: spawn.y, body: body, energy: 0, energyCapacity: energyCapacity, type: 'creep', room: spawn.room, user: spawn.user, hits: body.length * 100, hitsMax: body.length * 100, spawning: true, fatigue: 0, notifyWhenAttacked: true }; if (spawn.tutorial) { creep.tutorial = true; } bulk.insert(creep); }; //# sourceMappingURL=../../../sourcemaps/processor/intents/spawns/create-creep.js.map