Ticket #1089: qbot_full_serialize.patch
File qbot_full_serialize.patch, 50.5 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/simulation/ai/common-api-v2/base.js
4 4 return; 5 5 6 6 // Make some properties non-enumerable, so they won't be serialised 7 Object.defineProperty(this, "_player", {value: settings.player, enumerable: false}); 8 Object.defineProperty(this, "_templates", {value: settings.templates, enumerable: false}); 9 Object.defineProperty(this, "_derivedTemplates", {value: {}, enumerable: false}); 7 // Object.defineProperty(this, "_player", {value: settings.player, enumerable: false}); 8 // Object.defineProperty(this, "_templates", {value: settings.templates, enumerable: false}); 9 // Object.defineProperty(this, "_derivedTemplates", {value: {}, enumerable: false}); 10 this._player = settings.player; 11 this._templates = settings.templates; 12 this._derivedTemplates = {}; 10 13 11 14 this._entityMetadata = {}; 12 15 … … 17 20 this.turn = 0; 18 21 } 19 22 20 //Return a simple object (using no classes etc) that will be serialized21 //into saved games22 BaseAI.prototype.Serialize = function()23 {24 var rawEntities = {};25 26 for (var id in this._entities)27 {28 rawEntities[id] = this._entities[id]._entity;29 }30 31 return {32 _rawEntities: rawEntities,33 _entityMetadata: this._entityMetadata,34 };35 36 // TODO: ought to get the AI script subclass to serialize its own state37 };38 39 //Called after the constructor when loading a saved game, with 'data' being40 //whatever Serialize() returned41 BaseAI.prototype.Deserialize = function(data)42 {43 var rawEntities = data._rawEntities;44 this._entityMetadata = data._entityMetadata;45 this._entities = {}46 47 for (var id in rawEntities)48 {49 this._entities[id] = new Entity(this, rawEntities[id]);50 }51 52 // TODO: ought to get the AI script subclass to deserialize its own state53 };54 55 23 // Components that will be disabled in foundation entity templates. 56 24 // (This is a bit yucky and fragile since it's the inverse of 57 25 // CCmpTemplateManager::CopyFoundationSubset and only includes components … … 306 274 return undefined; 307 275 return metadata[key]; 308 276 } 277 278 Engine.RegisterSerializablePrototype("BaseAI", BaseAI.prototype); -
binaries/data/mods/public/simulation/ai/common-api-v2/entity.js
452 452 }, 453 453 }); 454 454 455 Engine.RegisterSerializablePrototype("Entity", Entity.prototype); 456 Engine.RegisterSerializablePrototype("EntityTemplate", EntityTemplate.prototype); 457 -
binaries/data/mods/public/simulation/ai/common-api-v2/entitycollection.js
8 8 // Compute length lazily on demand, since it can be 9 9 // expensive for large collections 10 10 this._length = undefined; 11 Object.defineProperty(this, "length", {12 get: function () {13 if (this._length === undefined)14 {15 this._length = 0;16 for (var id in entities)17 ++this._length;18 }19 return this._length;20 }21 });22 11 } 23 12 13 // Add custom getter on the prototype so the serializer doesn't lose it 14 // TODO: why don't we just use .getLength() instead of hiding this? 15 Object.defineProperty(EntityCollection.prototype, "length", { 16 get: function () { 17 if (this._length === undefined) 18 { 19 this._length = 0; 20 for (var id in this._entities) 21 ++this._length; 22 } 23 return this._length; 24 } 25 }); 26 24 27 EntityCollection.prototype.toIdArray = function() 25 28 { 26 29 var ret = []; … … 67 70 return new EntityCollection(this._ai, ret); 68 71 }; 69 72 70 EntityCollection.prototype.filter = function(filter , thisp)73 EntityCollection.prototype.filter = function(filter) 71 74 { 72 if (typeof(filter) == "function")73 filter = {"func": filter, "dynamicProperties": []};74 75 75 var ret = {}; 76 76 for (var id in this._entities) 77 77 { 78 78 var ent = this._entities[id]; 79 if (filter. func.call(thisp, ent, id, this))79 if (filter.test(ent)) 80 80 ret[id] = ent; 81 81 } 82 82 … … 160 160 var passesFilters = true; 161 161 for each (var filter in this._filters) 162 162 { 163 passesFilters = passesFilters && filter. func(ent);163 passesFilters = passesFilters && filter.test(ent); 164 164 } 165 165 166 166 if (passesFilters) … … 198 198 { 199 199 return this._UID; 200 200 }; 201 202 Engine.RegisterSerializablePrototype("EntityCollection", EntityCollection.prototype); -
binaries/data/mods/public/simulation/ai/common-api-v2/filters.js
1 var Filters = { 2 byType: function(type){ 3 return {"func" : function(ent){ 4 return ent.templateName() === type; 5 }, 6 "dynamicProperties": []}; 7 }, 1 // TODO: Some of these can use inheritance 2 3 function FilterByType(type) 4 { 5 this.type = type; 6 this.dynamicProperties = []; 7 } 8 FilterByType.prototype.test = function(ent) 9 { 10 return ent.templateName() === this.type; 11 }; 12 Engine.RegisterSerializablePrototype("FilterByType", FilterByType.prototype); 13 14 function FilterByClass(cls) 15 { 16 this.cls = cls; 17 this.dynamicProperties = []; 18 } 19 FilterByClass.prototype.test = function(ent) 20 { 21 return ent.hasClass(this.cls); 22 }; 23 Engine.RegisterSerializablePrototype("FilterByClass", FilterByClass.prototype); 24 25 function FilterByClassesAnd(clsList) 26 { 27 this.clsList = clsList; 28 this.dynamicProperties = []; 29 } 30 FilterByClassesAnd.prototype.test = function(ent) 31 { 32 var ret = true; 33 for (var i in this.clsList){ 34 ret = ret && ent.hasClass(this.clsList[i]); 35 } 36 return ret; 37 }; 38 Engine.RegisterSerializablePrototype("FilterByClassesAnd", FilterByClassesAnd.prototype); 39 40 function FilterByClassesOr(clsList) 41 { 42 this.clsList = clsList; 43 this.dynamicProperties = []; 44 } 45 FilterByClassesOr.prototype.test = function(ent) 46 { 47 var ret = false; 48 for (var i in this.clsList){ 49 ret = ret || ent.hasClass(this.clsList[i]); 50 } 51 return ret; 52 }; 53 Engine.RegisterSerializablePrototype("FilterByClassesOr", FilterByClassesOr.prototype); 54 55 function FilterByMetadata(key, value) 56 { 57 this.key = key; 58 this.value = value; 59 this.dynamicProperties = "metadata." + key; 60 } 61 FilterByMetadata.prototype.test = function(ent) 62 { 63 return (ent.getMetadata(this.key) == this.value); 64 }; 65 Engine.RegisterSerializablePrototype("FilterByMetadata", FilterByMetadata.prototype); 66 67 function FilterAnd(filter1, filter2) 68 { 69 this.filter1 = filter1; 70 this.filter2 = filter2; 71 this.dynamicProperties = filter1.dynamicProperties.concat(filter2.dynamicProperties); 72 } 73 FilterAnd.prototype.test = function(ent) 74 { 75 return this.filter1.test(ent) && this.filter2.test(ent); 76 }; 77 Engine.RegisterSerializablePrototype("FilterAnd", FilterAnd.prototype); 78 79 function FilterOr(filter1, filter2) 80 { 81 this.filter1 = filter1; 82 this.filter2 = filter2; 83 this.dynamicProperties = filter1.dynamicProperties.concat(filter2.dynamicProperties); 84 } 85 FilterOr.prototype.test = function(ent) 86 { 87 return this.filter1.test(ent) || this.filter2.test(ent); 88 }; 89 Engine.RegisterSerializablePrototype("FilterOr", FilterOr.prototype); 90 91 function FilterNot(filter) 92 { 93 this.filter = filter; 94 this.dynamicProperties = filter.dynamicProperties; 95 } 96 FilterNot.prototype.test = function(ent) 97 { 98 return !this.filter.test(ent); 99 }; 100 Engine.RegisterSerializablePrototype("FilterNot", FilterNot.prototype); 101 102 function FilterByOwner(owner) 103 { 104 this.owner = owner; 105 this.dynamicProperties = ["owner"]; 106 } 107 FilterByOwner.prototype.test = function(ent) 108 { 109 return (ent.owner() === this.owner); 110 }; 111 Engine.RegisterSerializablePrototype("FilterByOwner", FilterByOwner.prototype); 8 112 9 byClass: function(cls){ 10 return {"func" : function(ent){ 11 return ent.hasClass(cls); 12 }, 13 "dynamicProperties": []}; 14 }, 113 function FilterByNotOwner(owner) 114 { 115 this.owner = owner; 116 this.dynamicProperties = ["owner"]; 117 } 118 FilterByNotOwner.prototype.test = function(ent) 119 { 120 return (ent.owner() !== this.owner); 121 }; 122 Engine.RegisterSerializablePrototype("FilterByNotOwner", FilterByNotOwner.prototype); 15 123 16 byClassesAnd: function(clsList){ 17 return {"func" : function(ent){ 18 var ret = true; 19 for (var i in clsList){ 20 ret = ret && ent.hasClass(clsList[i]); 21 } 22 return ret; 23 }, 24 "dynamicProperties": []}; 25 }, 26 27 byClassesOr: function(clsList){ 28 return {"func" : function(ent){ 29 var ret = false; 30 for (var i in clsList){ 31 ret = ret || ent.hasClass(clsList[i]); 32 } 33 return ret; 34 }, 35 "dynamicProperties": []}; 36 }, 124 function FilterByOwners(owners) 125 { 126 this.owners = owners; 127 this.dynamicProperties = ["owner"]; 128 } 129 FilterByOwners.prototype.test = function(ent) 130 { 131 for (var i in this.owners){ 132 if (ent.owner() == +this.owners[i]){ 133 return true; 134 } 135 } 136 return false; 137 }; 138 Engine.RegisterSerializablePrototype("FilterByOwners", FilterByOwners.prototype); 37 139 38 byMetadata: function(key, value){ 39 return {"func" : function(ent){ 40 return (ent.getMetadata(key) == value); 41 }, 42 "dynamicProperties": ['metadata.' + key]}; 43 }, 140 function FilterByTrainingQueue() 141 { 142 this.dynamicProperties = ["trainingQueue"]; 143 } 144 FilterByTrainingQueue.prototype.test = function(ent) 145 { 146 return ent.trainingQueue(); 147 }; 148 Engine.RegisterSerializablePrototype("FilterByTrainingQueue", FilterByTrainingQueue.prototype); 149 150 function FilterIsSoldier() 151 { 152 this.dynamicProperties = []; 153 } 154 FilterIsSoldier.prototype.test = function(ent) 155 { 156 var filter = new FilterByClassesOr(["CitizenSoldier", "Super"]); 157 return filter.test(ent); 158 }; 159 Engine.RegisterSerializablePrototype("FilterIsSoldier", FilterIsSoldier.prototype); 160 161 function FilterIsIdle() 162 { 163 this.dynamicProperties = ["idle"]; 164 } 165 FilterIsIdle.prototype.test = function(ent) 166 { 167 return ent.isIdle(); 168 }; 169 Engine.RegisterSerializablePrototype("FilterIsIdle", FilterIsIdle.prototype); 170 171 function FilterIsFoundation() 172 { 173 this.dynamicProperties = []; 174 } 175 FilterIsFoundation.prototype.test = function(ent) 176 { 177 return ent.foundationProgress() !== undefined; 178 }; 179 Engine.RegisterSerializablePrototype("FilterIsFoundation", FilterIsFoundation.prototype); 180 181 function FilterByDistance(startPoint, dist) 182 { 183 this.startPoint = startPoint; 184 this.dist = dist; 185 this.dynamicProperties = ["position"]; 186 } 187 FilterByDistance.prototype.test = function(ent) 188 { 189 if (ent.position() === undefined) 190 return false; 191 else 192 return (SquareVectorDistance(this.startPoint, ent.position()) < this.dist*this.dist); 193 }; 194 Engine.RegisterSerializablePrototype("FilterByDistance", FilterByDistance.prototype); 195 196 // Distance filter with no auto updating, use with care 197 function FilterByStaticDistance(startPoint, dist) 198 { 199 this.startPoint = startPoint; 200 this.dist = dist; 201 this.dynamicProperties = []; 202 } 203 FilterByStaticDistance.prototype.test = function(ent) 204 { 205 if (!ent.position()) 206 return false; 207 else 208 return (SquareVectorDistance(this.startPoint, ent.position()) < this.dist*this.dist); 209 }; 210 Engine.RegisterSerializablePrototype("FilterByStaticDistance", FilterByStaticDistance.prototype); 211 212 function FilterIsDropsite(resourceType) 213 { 214 this.resourceType = resourceType; 215 this.dynamicProperties = []; 216 } 217 FilterIsDropsite.prototype.test = function(ent) 218 { 219 return (ent.resourceDropsiteTypes() && ent.resourceDropsiteTypes().indexOf(this.resourceType) !== -1); 220 } 221 Engine.RegisterSerializablePrototype("FilterIsDropsite", FilterIsDropsite.prototype); 222 223 function FilterByResource(resourceType) 224 { 225 this.resourceType = resourceType; 226 this.dynamicProperties = [/*"resourceSupplyAmount", */"owner", "metadata.inaccessible", "metadata.full"]; 227 } 228 FilterByResource.prototype.test = function(ent) 229 { 230 var type = ent.resourceSupplyType(); 231 if (!type) 232 return false; 233 var amount = ent.resourceSupplyMax(); 234 if (!amount) 235 return false; 44 236 45 and: function(filter1, filter2){ 46 return {"func": function(ent){ 47 return filter1.func(ent) && filter2.func(ent); 48 }, 49 "dynamicProperties": filter1.dynamicProperties.concat(filter2.dynamicProperties)}; 50 }, 237 // Skip targets that are too hard to hunt 238 if (ent.isUnhuntable()) 239 return false; 51 240 52 or: function(filter1, filter2){ 53 return {"func" : function(ent){ 54 return filter1.func(ent) || filter2.func(ent); 55 }, 56 "dynamicProperties": filter1.dynamicProperties.concat(filter2.dynamicProperties)}; 57 }, 241 // And don't go for the bloody fish! TODO: better accessibility checks 242 if (ent.hasClass("SeaCreature")) 243 return false; 58 244 59 not: function(filter){ 60 return {"func": function(ent){ 61 return !filter.func(ent); 62 }, 63 "dynamicProperties": filter.dynamicProperties}; 64 }, 245 // Don't go for floating treasures since we won't be able to reach them and it kills the pathfinder. 246 if (ent.templateName() == "other/special_treasure_shipwreck_debris" || 247 ent.templateName() == "other/special_treasure_shipwreck" ) 248 return false; 65 249 66 byOwner: function(owner){ 67 return {"func" : function(ent){ 68 return (ent.owner() === owner); 69 }, 70 "dynamicProperties": ['owner']}; 71 }, 250 // Don't gather enemy farms 251 if (!ent.isOwn() && ent.owner() !== 0) 252 return false; 72 253 73 byNotOwner: function(owner){ 74 return {"func" : function(ent){ 75 return (ent.owner() !== owner); 76 }, 77 "dynamicProperties": ['owner']}; 78 }, 254 if (ent.getMetadata("inaccessible") === true) 255 return false; 79 256 80 byOwners: function(owners){ 81 return {"func" : function(ent){ 82 for (var i in owners){ 83 if (ent.owner() == +owners[i]){ 84 return true; 85 } 86 } 87 return false; 88 }, 89 "dynamicProperties": ['owner']}; 90 }, 257 // too many workers trying to gather from this resource 258 if (ent.getMetadata("full") === true) 259 return false; 91 260 92 byTrainingQueue: function(){ 93 return {"func" : function(ent){ 94 return ent.trainingQueue(); 95 }, 96 "dynamicProperties": ['trainingQueue']}; 97 }, 98 99 isSoldier: function(){ 100 return {"func" : function(ent){ 101 return Filters.byClassesOr(["CitizenSoldier", "Super"])(ent); 102 }, 103 "dynamicProperties": []}; 104 }, 105 106 isIdle: function(){ 107 return {"func" : function(ent){ 108 return ent.isIdle(); 109 }, 110 "dynamicProperties": ['idle']}; 111 }, 112 113 isFoundation: function(){ 114 return {"func": function(ent){ 115 return ent.foundationProgress() !== undefined; 116 }, 117 "dynamicProperties": []}; 118 }, 119 120 byDistance: function(startPoint, dist){ 121 return {"func": function(ent){ 122 if (ent.position() === undefined){ 123 return false; 124 }else{ 125 return (SquareVectorDistance(startPoint, ent.position()) < dist*dist); 126 } 127 }, 128 "dynamicProperties": ['position']}; 129 }, 130 131 // Distance filter with no auto updating, use with care 132 byStaticDistance: function(startPoint, dist){ 133 return {"func": function(ent){ 134 if (!ent.position()){ 135 return false; 136 }else{ 137 return (SquareVectorDistance(startPoint, ent.position()) < dist*dist); 138 } 139 }, 140 "dynamicProperties": []}; 141 }, 142 143 isDropsite: function(resourceType){ 144 return {"func": function(ent){ 145 return (ent.resourceDropsiteTypes() && ent.resourceDropsiteTypes().indexOf(resourceType) !== -1); 146 }, 147 "dynamicProperties": []}; 148 }, 149 150 byResource: function(resourceType){ 151 return {"func" : function(ent){ 152 var type = ent.resourceSupplyType(); 153 if (!type) 154 return false; 155 var amount = ent.resourceSupplyMax(); 156 if (!amount) 157 return false; 158 159 // Skip targets that are too hard to hunt 160 if (ent.isUnhuntable()) 161 return false; 162 163 // And don't go for the bloody fish! TODO: better accessibility checks 164 if (ent.hasClass("SeaCreature")){ 165 return false; 166 } 167 168 // Don't go for floating treasures since we won't be able to reach them and it kills the pathfinder. 169 if (ent.templateName() == "other/special_treasure_shipwreck_debris" || 170 ent.templateName() == "other/special_treasure_shipwreck" ){ 171 return false; 172 } 173 174 // Don't gather enemy farms 175 if (!ent.isOwn() && ent.owner() !== 0){ 176 return false; 177 } 178 179 if (ent.getMetadata("inaccessible") === true){ 180 return false; 181 } 182 183 // too many workers trying to gather from this resource 184 if (ent.getMetadata("full") === true){ 185 return false; 186 } 187 188 if (type.generic == "treasure"){ 189 return (resourceType == type.specific); 190 } else { 191 return (resourceType == type.generic); 192 } 193 }, 194 "dynamicProperties": [/*"resourceSupplyAmount", */"owner", "metadata.inaccessible", "metadata.full"]}; 195 } 261 if (type.generic == "treasure") 262 return (this.resourceType == type.specific); 263 else 264 return (this.resourceType == type.generic); 196 265 }; 266 Engine.RegisterSerializablePrototype("FilterByResource", FilterByResource.prototype); -
binaries/data/mods/public/simulation/ai/qbot/attackMoveToCC.js
38 38 var targets = militaryManager.getEnemyBuildings(gameState,"ConquestCritical"); 39 39 // If there are no critical structures, attack anything else that's critical 40 40 if (targets.length == 0) { 41 targets = gameState.entities.filter(function(ent) { 42 return (gameState.isEntityEnemy(ent) && ent.hasClass("ConquestCritical") && ent.owner() !== 0 && ent.position()); 43 }); 41 targets = gameState.entities.filter(new FilterEnemyConquestCritical(gameState)); 44 42 } 45 43 // If there's nothing, attack anything else that's less critical 46 44 if (targets.length == 0) { … … 203 201 this.previousHealth = totalHealth; 204 202 }; 205 203 204 Engine.RegisterSerializablePrototype("AttackMoveToCC", AttackMoveToCC.prototype); -
binaries/data/mods/public/simulation/ai/qbot/attackMoveToLocation.js
1 // Default target finder aims for conquest critical targets 2 function DefaultTargetFinder() 3 { 4 } 5 DefaultTargetFinder.prototype.findTargets = function(gameState, militaryManager) 6 { 7 // Find the critical enemy buildings we could attack 8 var targets = militaryManager.getEnemyBuildings(gameState,"ConquestCritical"); 9 // If there are no critical structures, attack anything else that's critical 10 if (targets.length == 0) { 11 targets = gameState.entities.filter(new FilterEnemyConquestCritical(gameState)); 12 } 13 // If there's nothing, attack anything else that's less critical 14 if (targets.length == 0) { 15 targets = militaryManager.getEnemyBuildings(gameState,"Town"); 16 } 17 if (targets.length == 0) { 18 targets = militaryManager.getEnemyBuildings(gameState,"Village"); 19 } 20 return targets; 21 }; 22 1 23 function AttackMoveToLocation(gameState, militaryManager, minAttackSize, maxAttackSize, targetFinder){ 2 24 this.minAttackSize = minAttackSize || Config.attack.minAttackSize; 3 25 this.maxAttackSize = maxAttackSize || Config.attack.maxAttackSize; … … 6 28 this.previousTime = 0; 7 29 this.state = "unexecuted"; 8 30 9 this.targetFinder = targetFinder || this.defaultTargetFinder;31 this.targetFinder = targetFinder || new DefaultTargetFinder(); 10 32 11 33 this.healthRecord = []; 12 34 }; … … 29 51 || availableCount >= this.maxAttackSize); 30 52 }; 31 53 32 // Default target finder aims for conquest critical targets33 AttackMoveToLocation.prototype.defaultTargetFinder = function(gameState, militaryManager){34 // Find the critical enemy buildings we could attack35 var targets = militaryManager.getEnemyBuildings(gameState,"ConquestCritical");36 // If there are no critical structures, attack anything else that's critical37 if (targets.length == 0) {38 targets = gameState.entities.filter(function(ent) {39 return (gameState.isEntityEnemy(ent) && ent.hasClass("ConquestCritical") && ent.owner() !== 0 && ent.position());40 });41 }42 // If there's nothing, attack anything else that's less critical43 if (targets.length == 0) {44 targets = militaryManager.getEnemyBuildings(gameState,"Town");45 }46 if (targets.length == 0) {47 targets = militaryManager.getEnemyBuildings(gameState,"Village");48 }49 return targets;50 };51 52 54 // Executes the attack plan, after this is executed the update function will be run every turn 53 55 AttackMoveToLocation.prototype.execute = function(gameState, militaryManager){ 54 56 var availableCount = militaryManager.countAvailableUnits(); … … 57 59 58 60 var pending = EntityCollectionFromIds(gameState, this.idList); 59 61 60 var targets = this.targetFinder (gameState, militaryManager);62 var targets = this.targetFinder.findTargets(gameState, militaryManager); 61 63 62 64 if (targets.length === 0){ 63 targets = this.defaultTargetFinder(gameState, militaryManager);65 targets = new DefaultTargetFinder().findTargets(gameState, militaryManager); 64 66 } 65 67 66 68 // If we have a target, move to it … … 236 238 this.previousHealth = totalHealth; 237 239 }; 238 240 241 Engine.RegisterSerializablePrototype("AttackMoveToLocation", AttackMoveToLocation.prototype); 242 Engine.RegisterSerializablePrototype("DefaultTargetFinder", DefaultTargetFinder.prototype); -
binaries/data/mods/public/simulation/ai/qbot/config.js
1 var baseConfig = {1 var Config = { 2 2 "attack" : { 3 3 "minAttackSize" : 20, // attackMoveToLocation 4 4 "maxAttackSize" : 60, // attackMoveToLocation … … 55 55 56 56 "debug" : false 57 57 }; 58 59 var Config = {60 "debug": false61 };62 63 Config.__proto__ = baseConfig;64 No newline at end of file -
binaries/data/mods/public/simulation/ai/qbot/defence.js
41 41 if (numAttackers * this.DEFENCE_RATIO <= numAssignedDefenders){ 42 42 militaryManager.unassignUnits(unassignedDefenders); 43 43 44 var CCs = gameState.getOwnEntities().filter( Filters.byClass("CivCentre"));44 var CCs = gameState.getOwnEntities().filter(new FilterByClass("CivCentre")); 45 45 46 46 for (var i in unassignedDefenders){ 47 47 var pos = this.defenders[unassignedDefenders[i]].position(); … … 62 62 // Check to see if we need to recruit more defenders 63 63 if (numAttackers * this.DEFENCE_RATIO > numDefenders){ 64 64 var numNeeded = Math.ceil(numAttackers * this.DEFENCE_RATIO - numDefenders); 65 var numIdleAvailable = militaryManager.countAvailableUnits( Filters.isIdle());65 var numIdleAvailable = militaryManager.countAvailableUnits(new FilterIsIdle()); 66 66 67 67 if (numIdleAvailable > numNeeded){ 68 var newUnits = militaryManager.getAvailableUnits(numNeeded, Filters.isIdle());68 var newUnits = militaryManager.getAvailableUnits(numNeeded, new FilterIsIdle()); 69 69 for (var i in newUnits){ 70 70 var ent = gameState.getEntityById(newUnits[i]); 71 71 } … … 142 142 // Returns an entity collection of key buildings which should be defended. 143 143 // Currently just returns civ centres 144 144 Defence.prototype.getKeyBuildings = function(gameState){ 145 return gameState.getOwnEntities().filter( Filters.byClass("CivCentre"));145 return gameState.getOwnEntities().filter(new FilterByClass("CivCentre")); 146 146 }; 147 147 148 148 /* … … 276 276 } 277 277 } 278 278 }; 279 280 Engine.RegisterSerializablePrototype("Defence", Defence.prototype); -
binaries/data/mods/public/simulation/ai/qbot/economy.js
43 43 var numGatherers = {}; 44 44 for ( var type in this.gatherWeights){ 45 45 numGatherers[type] = gameState.updatingCollection("workers-gathering-" + type, 46 Filters.byMetadata("gather-type", type), gameState.getOwnEntitiesByRole("worker")).length;46 new FilterByMetadata("gather-type", type), gameState.getOwnEntitiesByRole("worker")).length; 47 47 } 48 48 49 49 var types = Object.keys(this.gatherWeights); … … 111 111 var self = this; 112 112 113 113 // Search for idle workers, and tell them to gather resources based on demand 114 var filter = Filters.or(Filters.isIdle(), Filters.byMetadata("subrole", "idle"));114 var filter = new FilterOr(new FilterIsIdle(), new FilterByMetadata("subrole", "idle")); 115 115 var idleWorkers = gameState.updatingCollection("idle-workers", filter, gameState.getOwnEntitiesByRole("worker")); 116 116 117 117 if (idleWorkers.length) { … … 133 133 134 134 EconomyManager.prototype.workersBySubrole = function(gameState, subrole) { 135 135 var workers = gameState.getOwnEntitiesByRole("worker"); 136 return gameState.updatingCollection("subrole-" + subrole, Filters.byMetadata("subrole", subrole), workers);136 return gameState.updatingCollection("subrole-" + subrole, new FilterByMetadata("subrole", subrole), workers); 137 137 }; 138 138 139 139 EconomyManager.prototype.assignToFoundations = function(gameState) { … … 163 163 164 164 var target = foundations.toEntityArray()[0]; 165 165 166 var nonBuilderWorkers = workers.filter(function(ent) { 167 // check position so garrisoned units aren't tasked 168 return (ent.getMetadata("subrole") !== "builder" && ent.position() !== undefined); 169 }); 166 var nonBuilderWorkers = workers.filter(new FilterNonBuilders()); 170 167 171 168 var nearestNonBuilders = nonBuilderWorkers.filterNearest(target.position(), extraNeeded); 172 169 … … 184 181 185 182 var numFood = 0; 186 183 187 gameState.updatingCollection("active-dropsite-food", Filters.byMetadata("active-dropsite-food", true),184 gameState.updatingCollection("active-dropsite-food", new FilterByMetadata("active-dropsite-food", true), 188 185 gameState.getOwnDropsites("food")).forEach(function (dropsite){ 189 186 numFood += dropsite.getMetadata("nearby-resources-food").length; 190 187 }); … … 339 336 340 337 gameState.getOwnDropsites(resource).forEach(function(ent) { 341 338 if (ent.getMetadata("nearby-resources-" + resource) === undefined){ 342 var filterPos = Filters.byStaticDistance(ent.position(), radius);339 var filterPos = new FilterByStaticDistance(ent.position(), radius); 343 340 344 341 var collection = gameState.getResourceSupplies(resource).filter(filterPos); 345 342 collection.registerUpdates(); … … 411 408 if (this.checkResourceConcentrations(gameState, resource) < this.dropsiteNumbers[resource]){ 412 409 var spot = this.getBestResourceBuildSpot(gameState, resource); 413 410 414 var myCivCentres = gameState.getOwnEntities().filter(function(ent) { 415 if (!ent.hasClass("CivCentre") || ent.position() === undefined){ 416 return false; 417 } 418 var dx = (spot[0]-ent.position()[0]); 419 var dy = (spot[1]-ent.position()[1]); 420 var dist2 = dx*dx + dy*dy; 421 return (ent.hasClass("CivCentre") && dist2 < 180*180); 422 }); 411 var myCivCentres = gameState.getOwnEntities().filter(new FilterNearbyCivCenters(spot)); 423 412 424 413 if (myCivCentres.length === 0){ 425 414 queues.economicBuilding.addItem(new BuildingConstructionPlan(gameState, "structures/{civ}_civil_centre", spot)); … … 521 510 }); 522 511 523 512 // Gatherer count updates for non-workers 524 var filter = Filters.and(Filters.not(Filters.byMetadata("worker-object", undefined)),525 Filters.not(Filters.byMetadata("role", "worker")));513 var filter = new FilterAnd(new FilterNot(new FilterByMetadata("worker-object", undefined)), 514 new FilterNot(new FilterByMetadata("role", "worker"))); 526 515 gameState.updatingCollection("reassigned-workers", filter, gameState.getOwnEntities()).forEach(function(ent){ 527 516 ent.getMetadata("worker-object").updateGathererCounts(gameState); 528 517 }); … … 541 530 542 531 Engine.ProfileStop(); 543 532 }; 533 534 Engine.RegisterSerializablePrototype("EconomyManager", EconomyManager.prototype); -
binaries/data/mods/public/simulation/ai/qbot/filters.js
1 function FilterEnemyConquestCritical(gameState) 2 { 3 this.gameState = gameState; 4 this.dynamicProperties = []; 5 } 6 FilterEnemyConquestCritical.prototype.test = function(ent) 7 { 8 return (this.gameState.isEntityEnemy(ent) && ent.hasClass("ConquestCritical") && ent.owner() !== 0 && ent.position()); 9 }; 10 Engine.RegisterSerializablePrototype("FilterEnemyConquestCritical", FilterEnemyConquestCritical.prototype); 11 12 function FilterNonBuilders() 13 { 14 this.dynamicProperties = []; 15 } 16 FilterNonBuilders.prototype.test = function(ent) 17 { 18 // check position so garrisoned units aren't tasked 19 return (ent.getMetadata("subrole") !== "builder" && ent.position() !== undefined); 20 }; 21 Engine.RegisterSerializablePrototype("FilterNonBuilders", FilterNonBuilders.prototype); 22 23 function FilterNearbyCivCenters(spot) 24 { 25 this.spot = spot; 26 this.dynamicProperties = []; 27 } 28 FilterNearbyCivCenters.prototype.test = function(ent) 29 { 30 if (!ent.hasClass("CivCentre") || ent.position() === undefined) 31 return false; 32 33 var dx = (this.spot[0]-ent.position()[0]); 34 var dy = (this.spot[1]-ent.position()[1]); 35 var dist2 = dx*dx + dy*dy; 36 return (ent.hasClass("CivCentre") && dist2 < 180*180); 37 }; 38 Engine.RegisterSerializablePrototype("FilterNearbyCivCenters", FilterNearbyCivCenters.prototype); 39 40 function FilterAvailableTrainers(template) 41 { 42 this.template = template; 43 this.dynamicProperties = []; 44 } 45 FilterAvailableTrainers.prototype.test = function(ent) 46 { 47 var maxQueueLength = 2; // avoid tying up resources in giant training queues 48 var trainable = ent.trainableEntities(); 49 if (!trainable || trainable.indexOf(this.template) == -1) 50 return false; 51 52 var queue = ent.trainingQueue(); 53 if (queue) 54 if (queue.length >= maxQueueLength) 55 return false; 56 57 return true; 58 }; 59 Engine.RegisterSerializablePrototype("FilterAvailableTrainers", FilterAvailableTrainers.prototype); 60 61 function FilterAvailableBuilders(template) 62 { 63 this.template = template; 64 this.dynamicProperties = []; 65 } 66 FilterAvailableBuilders.prototype.test = function(ent) 67 { 68 var buildable = ent.buildableEntities(); 69 if (!buildable || buildable.indexOf(this.template) == -1) 70 return false; 71 72 return true; 73 }; 74 Engine.RegisterSerializablePrototype("FilterAvailableBuilders", FilterAvailableBuilders.prototype); 75 76 function FilterEnemyStructuresByClass(gameState, cls) 77 { 78 this.gameState = gameState; 79 this.cls = cls; 80 this.dynamicProperties = []; 81 } 82 FilterEnemyStructuresByClass.prototype.test = function(ent) 83 { 84 return (this.gameState.isEntityEnemy(ent) && ent.hasClass("Structure") && ent.hasClass(this.cls) && ent.owner() !== 0 && ent.position()); 85 }; 86 Engine.RegisterSerializablePrototype("FilterEnemyStructuresByClass", FilterEnemyStructuresByClass.prototype); 87 -
binaries/data/mods/public/simulation/ai/qbot/gamestate.js
133 133 134 134 GameState.prototype.getOwnEntities = function() { 135 135 if (!this.store.ownEntities){ 136 this.store.ownEntities = this.getEntities().filter( Filters.byOwner(this.player));136 this.store.ownEntities = this.getEntities().filter(new FilterByOwner(this.player)); 137 137 this.store.ownEntities.registerUpdates(); 138 138 } 139 139 … … 155 155 } 156 156 } 157 157 if (diplomacyChange || !this.store.enemyEntities){ 158 var filter = Filters.byOwners(enemies);158 var filter = new FilterByOwners(enemies); 159 159 this.store.enemyEntities = this.getEntities().filter(filter); 160 160 this.store.enemyEntities.registerUpdates(); 161 161 this.store.enemies = enemies; … … 179 179 180 180 GameState.prototype.getOwnEntitiesByMetadata = function(key, value){ 181 181 if (!this.store[key + "-" + value]){ 182 var filter = Filters.byMetadata(key, value);182 var filter = new FilterByMetadata(key, value); 183 183 this.store[key + "-" + value] = this.getOwnEntities().filter(filter); 184 184 this.store[key + "-" + value].registerUpdates(); 185 185 } … … 193 193 194 194 // TODO: fix this so it picks up not in use training stuff 195 195 GameState.prototype.getOwnTrainingFacilities = function(){ 196 return this.updatingCollection("own-training-facilities", Filters.byTrainingQueue(), this.getOwnEntities());196 return this.updatingCollection("own-training-facilities", new FilterByTrainingQueue(), this.getOwnEntities()); 197 197 }; 198 198 199 199 GameState.prototype.getOwnEntitiesByType = function(type){ 200 var filter = Filters.byType(type); 201 return this.updatingCollection("own-by-type-" + type, filter, this.getOwnEntities()); 200 return this.updatingCollection("own-by-type-" + type, new FilterByType(type), this.getOwnEntities()); 202 201 }; 203 202 204 203 GameState.prototype.countEntitiesByType = function(type) { … … 259 258 * already too busy. 260 259 */ 261 260 GameState.prototype.findTrainers = function(template) { 262 var maxQueueLength = 2; // avoid tying up resources in giant training queues 263 264 return this.getOwnTrainingFacilities().filter(function(ent) { 265 266 var trainable = ent.trainableEntities(); 267 if (!trainable || trainable.indexOf(template) == -1) 268 return false; 269 270 var queue = ent.trainingQueue(); 271 if (queue) { 272 if (queue.length >= maxQueueLength) 273 return false; 274 } 275 276 return true; 277 }); 261 return this.getOwnTrainingFacilities().filter(new FilterAvailableTrainers(template)); 278 262 }; 279 263 280 264 /** 281 265 * Find units that are capable of constructing the given building type. 282 266 */ 283 267 GameState.prototype.findBuilders = function(template) { 284 return this.getOwnEntities().filter(function(ent) { 285 286 var buildable = ent.buildableEntities(); 287 if (!buildable || buildable.indexOf(template) == -1) 288 return false; 289 290 return true; 291 }); 268 return this.getOwnEntities().filter(new FilterAvailableBuilders(template)); 292 269 }; 293 270 294 271 GameState.prototype.getOwnFoundations = function() { 295 return this.updatingCollection("ownFoundations", Filters.isFoundation(), this.getOwnEntities());272 return this.updatingCollection("ownFoundations", new FilterIsFoundation(), this.getOwnEntities()); 296 273 }; 297 274 298 275 GameState.prototype.getOwnDropsites = function(resource){ 299 return this.updatingCollection("dropsite-own-" + resource, Filters.isDropsite(resource), this.getOwnEntities());276 return this.updatingCollection("dropsite-own-" + resource, new FilterIsDropsite(resource), this.getOwnEntities()); 300 277 }; 301 278 302 279 GameState.prototype.getResourceSupplies = function(resource){ 303 return this.updatingCollection("resource-" + resource, Filters.byResource(resource), this.getEntities());280 return this.updatingCollection("resource-" + resource, new FilterByResource(resource), this.getEntities()); 304 281 }; 305 282 306 283 GameState.prototype.getEntityLimits = function() { … … 321 298 else 322 299 return (this.playerData.entityCounts[category] >= this.playerData.entityLimits[category]); 323 300 }; 301 302 Engine.RegisterSerializablePrototype("GameState", GameState.prototype); -
binaries/data/mods/public/simulation/ai/qbot/housing.js
27 27 28 28 Engine.ProfileStop(); 29 29 }; 30 31 Engine.RegisterSerializablePrototype("HousingManager", HousingManager.prototype); -
binaries/data/mods/public/simulation/ai/qbot/map-module.js
261 261 threshold = threshold ? threshold : 256; 262 262 Engine.DumpImage(name, this.map, this.width, this.height, threshold); 263 263 }; 264 265 Engine.RegisterSerializablePrototype("Map", Map.prototype); -
binaries/data/mods/public/simulation/ai/qbot/military.js
8 8 9 9 var MilitaryAttackManager = function() { 10 10 // these use the structure soldiers[unitId] = true|false to register the units 11 this.attackManagers = [ AttackMoveToLocation];11 this.attackManagers = ["AttackMoveToLocation"]; 12 12 this.availableAttacks = []; 13 13 this.currentAttacks = []; 14 14 … … 49 49 this.bFort[i] = gameState.applyCiv(this.bFort[i]); 50 50 } 51 51 52 this.getEconomicTargets = function(gameState, militaryManager){53 return militaryManager.getEnemyBuildings(gameState, "Economic");54 };52 // this.getEconomicTargets = function(gameState, militaryManager){ 53 // return militaryManager.getEnemyBuildings(gameState, "Economic"); 54 // }; 55 55 // TODO: figure out how to make this generic 56 56 for (var i in this.attackManagers){ 57 this.availableAttacks[i] = new this.attackManagers[i](gameState, this);57 this.availableAttacks[i] = new global[this.attackManagers[i]](gameState, this); 58 58 } 59 59 60 60 var enemies = gameState.getEnemyEntities(); 61 var filter = Filters.byClassesOr(["CitizenSoldier", "Champion", "Hero", "Siege"]);61 var filter = new FilterByClassesOr(["CitizenSoldier", "Champion", "Hero", "Siege"]); 62 62 this.enemySoldiers = enemies.filter(filter); // TODO: cope with diplomacy changes 63 63 this.enemySoldiers.registerUpdates(); 64 64 }; … … 141 141 }; 142 142 143 143 // return count of enemy buildings for a given building class 144 MilitaryAttackManager.prototype.getEnemyBuildings = function(gameState,cls) { 145 var targets = gameState.entities.filter(function(ent) { 146 return (gameState.isEntityEnemy(ent) && ent.hasClass("Structure") && ent.hasClass(cls) && ent.owner() !== 0 && ent.position()); 147 }); 144 MilitaryAttackManager.prototype.getEnemyBuildings = function(gameState, cls) { 145 var targets = gameState.entities.filter(new FilterEnemyStructuresByClass(gameState, cls)); 148 146 return targets; 149 147 }; 150 148 … … 435 433 this.currentAttacks.push(this.availableAttacks[i]); 436 434 //debug("Attacking!"); 437 435 } 438 this.availableAttacks.splice(i, 1, new this.attackManagers[i](gameState, this));436 this.availableAttacks.splice(i, 1, new global[this.attackManagers[i]](gameState, this)); 439 437 } 440 438 Engine.ProfileStop(); 441 439 … … 457 455 458 456 Engine.ProfileStop(); 459 457 }; 458 459 Engine.RegisterSerializablePrototype("MilitaryAttackManager", MilitaryAttackManager.prototype); -
binaries/data/mods/public/simulation/ai/qbot/plan-building.js
122 122 "angle" : angle 123 123 }; 124 124 }; 125 126 Engine.RegisterSerializablePrototype("BuildingConstructionPlan", BuildingConstructionPlan.prototype); -
binaries/data/mods/public/simulation/ai/qbot/plan-training.js
53 53 54 54 UnitTrainingPlan.prototype.addItem = function(){ 55 55 this.number += 1; 56 }; 57 No newline at end of file 56 }; 57 58 Engine.RegisterSerializablePrototype("UnitTrainingPlan", UnitTrainingPlan.prototype); -
binaries/data/mods/public/simulation/ai/qbot/qbot.js
50 50 51 51 this.firstTime = false; 52 52 53 var myKeyEntities = gameState.getOwnEntities().filter(function(ent) { 54 return ent.hasClass("CivCentre"); 55 }); 53 var myKeyEntities = gameState.getOwnEntities().filter(new FilterByClass("CivCentre")); 56 54 57 55 if (myKeyEntities.length == 0){ 58 56 myKeyEntities = gameState.getOwnEntities(); 59 57 } 60 58 61 59 62 var filter = Filters.byClass("CivCentre");60 var filter = new FilterByClass("CivCentre"); 63 61 var enemyKeyEntities = gameState.getEnemyEntities().filter(filter); 64 62 65 63 if (enemyKeyEntities.length == 0){ … … 146 144 Engine.ProfileStop(); 147 145 }; 148 146 149 // TODO: Remove override when the whole AI state is serialised150 QBotAI.prototype.Deserialize = function(data)151 {152 BaseAI.prototype.Deserialize.call(this, data);153 };154 155 // Override the default serializer156 QBotAI.prototype.Serialize = function()157 {158 var ret = BaseAI.prototype.Serialize.call(this);159 ret._entityMetadata = {};160 return ret;161 };162 163 147 function debug(output){ 164 148 if (Config.debug){ 165 149 if (typeof output === "string"){ … … 178 162 descendant.prototype[m] = parent.prototype[m]; 179 163 } 180 164 } 165 166 Engine.RegisterSerializablePrototype("QBotAI", QBotAI.prototype); -
binaries/data/mods/public/simulation/ai/qbot/queue-manager.js
199 199 200 200 for (var i in this.priorities){ 201 201 if (!(this.priorities[i] > 0)){ 202 warn("QueueManager received bad priorities, please report this error: " + uneval(this.priorities)); 202 203 this.priorities[i] = 1; // TODO: make the Queue Manager not die when priorities are zero. 203 warn("QueueManager received bad priorities, please report this error: " + uneval(this.priorities));204 204 } 205 205 } 206 206 … … 300 300 Engine.ProfileStop(); 301 301 Engine.ProfileStop(); 302 302 }; 303 304 Engine.RegisterSerializablePrototype("QueueManager", QueueManager.prototype); -
binaries/data/mods/public/simulation/ai/qbot/queue.js
111 111 } 112 112 } 113 113 return count; 114 }; 115 No newline at end of file 114 }; 115 116 Engine.RegisterSerializablePrototype("Queue", Queue.prototype); -
binaries/data/mods/public/simulation/ai/qbot/resources.js
64 64 sum += this.population * 50; // based on typical unit costs 65 65 return sum; 66 66 }; 67 68 Engine.RegisterSerializablePrototype("Resources", Resources.prototype); -
binaries/data/mods/public/simulation/ai/qbot/terrain-analysis.js
347 347 newStack = []; 348 348 } 349 349 return count; 350 }; 351 No newline at end of file 350 }; 351 352 Engine.RegisterSerializablePrototype("TerrainAnalysis", TerrainAnalysis.prototype); 353 Engine.RegisterSerializablePrototype("PathFinder", PathFinder.prototype); 354 Engine.RegisterSerializablePrototype("Accessibility", Accessibility.prototype); -
binaries/data/mods/public/simulation/ai/qbot/timer.js
9 9 10 10 11 11 //-EmjeR-// Timer class // 12 var Timer = function() { 13 ///Private array. 14 var alarmList = []; 12 var Timer = function() 13 { 14 this.alarmList = []; 15 } 16 17 ///Private methods 18 Timer.prototype.num_alarms = function() 19 { 20 return this.alarmList.length; 21 }; 22 23 Timer.prototype.get_alarm = function(id) 24 { 25 return this.alarmList[id]; 26 }; 15 27 16 ///Private methods 17 function num_alarms(){18 return alarmList.length;19 28 Timer.prototype.add_alarm = function(index, alarm) 29 { 30 this.alarmList[index] = alarm; 31 }; 20 32 21 function get_alarm(id) { 22 return alarmList[id]; 23 }; 33 Timer.prototype.delete_alarm = function(id) 34 { 35 // Set the array element to undefined 36 delete this.alarmList[id]; 37 }; 24 38 25 function add_alarm(index, alarm) { 26 alarmList[index] = alarm; 27 }; 39 ///Privileged methods 40 // Add an new alarm to the list 41 Timer.prototype.setTimer = function(gameState, interval, delay, repeat) 42 { 43 delay = delay || 0; 44 repeat = repeat || -1; 28 45 29 function delete_alarm(id) { 30 // Set the array element to undefined 31 delete alarmList[id]; 32 }; 46 var index = this.num_alarms(); 33 47 34 ///Privileged methods 35 // Add an new alarm to the list 36 this.setTimer = function(gameState, interval, delay, repeat) { 37 delay = delay || 0; 38 repeat = repeat || -1; 39 40 var index = num_alarms(); 41 42 //Add a new alarm to the list 43 add_alarm(index, new alarm(gameState, index, interval, delay, repeat)); 44 return index; 45 }; 48 //Add a new alarm to the list 49 this.add_alarm(index, new Alarm(gameState, index, interval, delay, repeat)); 50 return index; 51 }; 46 52 53 // Check if a alarm has reached its interval. 54 Timer.prototype.checkTimer = function(gameState,id) 55 { 56 var alarm = this.get_alarm(id); 57 if (alarm === undefined) 58 return false; 59 if (!alarm.active) 60 return false; 61 var time = gameState.getTimeElapsed(); 62 var alarmState = false; 47 63 48 // Check if a alarm has reached its interval. 49 this.checkTimer = function(gameState,id) { 50 var alarm = get_alarm(id); 51 if (alarm === undefined) 52 return false; 53 if (!alarm.active) 54 return false; 55 var time = gameState.getTimeElapsed(); 56 var alarmState = false; 57 58 // If repeat forever (repeat is -1). Or if the alarm has rung less times than repeat. 59 if (alarm.repeat < 0 || alarm.counter < alarm.repeat) { 60 var time_diffrence = time - alarm.start_time - alarm.delay - alarm.interval * alarm.counter; 61 if (time_diffrence > alarm.interval) { 62 alarmState = true; 63 alarm.counter++; 64 } 64 // If repeat forever (repeat is -1). Or if the alarm has rung less times than repeat. 65 if (alarm.repeat < 0 || alarm.counter < alarm.repeat) { 66 var time_diffrence = time - alarm.start_time - alarm.delay - alarm.interval * alarm.counter; 67 if (time_diffrence > alarm.interval) { 68 alarmState = true; 69 alarm.counter++; 65 70 } 66 67 // Check if the alarm has rung 'alarm.repeat' times if so, delete the alarm. 68 if (alarm.counter >= alarm.repeat && alarm.repeat != -1) { 69 this.clearTimer(id); 70 } 71 72 return alarmState; 73 }; 71 } 74 72 75 // Remove an alarm from the list.76 this.clearTimer = function(id) {77 delete_alarm(id);78 } ;73 // Check if the alarm has rung 'alarm.repeat' times if so, delete the alarm. 74 if (alarm.counter >= alarm.repeat && alarm.repeat != -1) { 75 this.clearTimer(id); 76 } 79 77 80 // Activate a deactivated alarm. 81 this.activateTimer = function(id) { 82 var alarm = get_alarm(id); 83 alarm.active = true; 84 }; 78 return alarmState; 79 }; 85 80 86 // Deactivate an active alarm but don't delete it. 87 this.deactivateTimer = function(id) { 88 var alarm = get_alarm(id); 89 alarm.active = false; 90 }; 81 // Remove an alarm from the list. 82 Timer.prototype.clearTimer = function(id) 83 { 84 this.delete_alarm(id); 91 85 }; 86 87 // Activate a deactivated alarm. 88 Timer.prototype.activateTimer = function(id) 89 { 90 var alarm = this.get_alarm(id); 91 alarm.active = true; 92 }; 93 94 // Deactivate an active alarm but don't delete it. 95 Timer.prototype.deactivateTimer = function(id) { 96 var alarm = this.get_alarm(id); 97 alarm.active = false; 98 }; 92 99 93 94 100 //-EmjeR-// Alarm class // 95 function alarm(gameState, id, interval, delay, repeat) { 101 function Alarm(gameState, id, interval, delay, repeat) 102 { 96 103 this.id = id; 97 104 this.interval = interval; 98 105 this.delay = delay; … … 102 109 this.active = true; 103 110 this.counter = 0; 104 111 }; 112 113 Engine.RegisterSerializablePrototype("Timer", Timer.prototype); 114 Engine.RegisterSerializablePrototype("Alarm", Alarm.prototype); -
binaries/data/mods/public/simulation/ai/qbot/walkToCC.js
33 33 var targets = militaryManager.getEnemyBuildings(gameState,"ConquestCritical"); 34 34 // If there are no critical structures, attack anything else that's critical 35 35 if (targets.length == 0) { 36 targets = gameState.entities.filter(function(ent) { 37 return (gameState.isEntityEnemy(ent) && ent.hasClass("ConquestCritical") && ent.owner() !== 0); 38 }); 36 targets = gameState.entities.filter(new FilterEnemyConquestCritical(gameState)); 39 37 } 40 38 // If there's nothing, attack anything else that's less critical 41 39 if (targets.length == 0) { … … 82 80 for (var i in removeList){ 83 81 this.idList.splice(this.idList.indexOf(removeList[i]),1); 84 82 } 85 }; 86 No newline at end of file 83 }; 84 85 Engine.RegisterSerializablePrototype("WalkToCC", WalkToCC.prototype); -
binaries/data/mods/public/simulation/ai/qbot/worker.js
128 128 var nearestResources = undefined; 129 129 var nearestDropsite = undefined; 130 130 131 gameState.updatingCollection("active-dropsite-" + resource, Filters.byMetadata("active-dropsite-" + resource, true),131 gameState.updatingCollection("active-dropsite-" + resource, new FilterByMetadata("active-dropsite-" + resource, true), 132 132 gameState.getOwnDropsites(resource)).forEach(function (dropsite){ 133 133 if (dropsite.position()){ 134 134 var dist = VectorDistance(ent.position(), dropsite.position()); … … 248 248 }else{ 249 249 return type.generic; 250 250 } 251 }; 252 No newline at end of file 251 }; 252 253 Engine.RegisterSerializablePrototype("Worker", Worker.prototype);