function (target, resourceType, amount) { if(!this.my) { return C.ERR_NOT_OWNER; } if(this.spawning) { return C.ERR_BUSY; } if(amount < 0) { return C.ERR_INVALID_ARGS; } if(!_.contains(C.RESOURCES_ALL, resourceType)) { return C.ERR_INVALID_ARGS; } if(!target || !target.id || (!register.spawns[target.id] && !register.powerCreeps[target.id] && !register.creeps[target.id] && !register.structures[target.id]) || (!data(target.id).store && (register.structures[target.id].structureType != 'controller')) || !(target instanceof globals.StructureSpawn) && !(target instanceof globals.Structure) && !(target instanceof globals.Creep) && !(target instanceof globals.PowerCreep) && !target.spawning) { register.assertTargetObject(target); return C.ERR_INVALID_TARGET; } if(resourceType == C.RESOURCE_ENERGY && register.structures[target.id] && register.structures[target.id].structureType == 'controller') { return this.upgradeController(target); } if(!register.structures[target.id] || !utils.capacityForResource(data(target.id), resourceType)) { return C.ERR_INVALID_TARGET; } if(!target.pos.isNearTo(this.pos)) { return C.ERR_NOT_IN_RANGE; } if(!data(this.id).store || !data(this.id).store[resourceType]) { return C.ERR_NOT_ENOUGH_RESOURCES; } const storedAmount = data(target.id).storeCapacityResource ? data(target.id).store[resourceType] : utils.calcResources(target); const targetCapacity = Math.max(0, data(target.id).storeCapacityResource && data(target.id).storeCapacityResource[resourceType] || (data(target.id).storeCapacity||0) - _.sum(data(target.id).storeCapacityResource)); if(!data(target.id).store || storedAmount >= targetCapacity) { return C.ERR_FULL; } if(!amount) { amount = Math.min(data(this.id).store[resourceType], targetCapacity - storedAmount); } if(data(this.id).store[resourceType] < amount) { return C.ERR_NOT_ENOUGH_RESOURCES; } if(!amount || (amount + storedAmount) > targetCapacity) { return C.ERR_FULL; } intents.set(this.id, 'transfer', {id: target.id, amount, resourceType}); return C.OK; }