function target resourceType amount if this my return ERR_NOT_OWNER if

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
}