Ticket #4085: sharing-v2.patch
File sharing-v2.patch, 9.3 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/simulation/ai/common-api/entity.js
623 623 decaying: function() { return this._entity.decaying !== undefined ? this._entity.decaying : undefined; }, 624 624 capturePoints: function() {return this._entity.capturePoints !== undefined ? this._entity.capturePoints : undefined; }, 625 625 626 "isSharedDropsite": function() { return this._entity.sharedDropsite === true; }, 627 626 628 /** 627 629 * Returns the current training queue state, of the form 628 630 * [ { "id": 0, "template": "...", "count": 1, "progress": 0.5, "metadata": ... }, ... ] -
binaries/data/mods/public/simulation/ai/common-api/gamestate.js
595 595 m.GameState.prototype.getOwnDropsites = function(resource) 596 596 { 597 597 if (resource !== undefined) 598 return this.updatingCollection(" dropsite-" + resource, m.Filters.isDropsite(resource), this.getOwnEntities());599 return this.updatingCollection(" dropsite-all", m.Filters.isDropsite(), this.getOwnEntities());598 return this.updatingCollection("ownDropsite-" + resource, m.Filters.isDropsite(resource), this.getOwnEntities()); 599 return this.updatingCollection("ownDropsite-all", m.Filters.isDropsite(), this.getOwnEntities()); 600 600 }; 601 601 602 m.GameState.prototype.getAnyDropsites = function(resource) 603 { 604 if (resource !== undefined) 605 return this.updatingGlobalCollection("anyDropsite-" + resource, m.Filters.isDropsite(resource), this.getEntities()); 606 return this.updatingGlobalCollection("anyDropsite-all", m.Filters.isDropsite(), this.getEntities()); 607 }; 608 602 609 m.GameState.prototype.getResourceSupplies = function(resource) 603 610 { 604 611 return this.updatingGlobalCollection("resource-" + resource, m.Filters.byResource(resource), this.getEntities()); -
binaries/data/mods/public/simulation/ai/petra/entityExtend.js
99 99 let closestDropsite; 100 100 let distmin = Math.min(); 101 101 let access = gameState.ai.accessibility.getAccessValue(ent.position()); 102 gameState.getOwnDropsites(resource).forEach(function(dropsite) { 103 if (!dropsite.position() || dropsite.getMetadata(PlayerID, "access") !== access) 104 return; 102 let hasSharedDropsites = gameState.playerData.hasSharedDropsites; 103 let dropsiteCollection = hasSharedDropsites ? gameState.getAnyDropsites(resource) : gameState.getOwnDropsites(resource); 104 for (let dropsite of dropsiteCollection.values()) 105 { 106 if (!dropsite.position()) 107 continue; 108 let owner = dropsite.owner(); 109 // owner !== PlayerID can only happen when hasSharedDropsites === true, so no need to test it again 110 if (owner !== PlayerID && (!dropsite.isSharedDropsite() || !gameState.isPlayerMutualAlly(owner))) 111 continue; 112 let dropsiteAccess = dropsite.getMetadata(PlayerID, "access"); 113 if (!dropsiteAccess) 114 { 115 dropsiteAccess = gameState.ai.accessibility.getAccessValue(dropsite.position()); 116 dropsite.setMetadata(PlayerID, "access", dropsiteAccess); 117 } 118 if (dropsiteAccess !== access) 119 continue; 105 120 let dist = API3.SquareVectorDistance(ent.position(), dropsite.position()); 106 121 if (dist > distmin) 107 return;122 continue; 108 123 distmin = dist; 109 124 closestDropsite = dropsite; 110 } );125 } 111 126 112 127 if (!closestDropsite) 113 128 return false; -
binaries/data/mods/public/simulation/ai/petra/worker.js
541 541 let foodDropsites = gameState.getOwnDropsites("food"); 542 542 let entPosition = position ? position : this.ent.position(); 543 543 let access = gameState.ai.accessibility.getAccessValue(entPosition); 544 let hasSharedDropsites = gameState.playerData.hasSharedDropsites; 545 let foodDropsites = (hasSharedDropsites ? gameState.getAnyDropsites("food") : gameState.getOwnDropsites("food")).toEntityArray(); 544 546 545 547 let nearestDropsiteDist = function(supply) { 546 548 let distMin = 1000000; 547 549 let pos = supply.position(); 548 foodDropsites.forEach(function (dropsite) { 549 if (!dropsite.position() || dropsite.getMetadata(PlayerID, "access") !== access) 550 return; 551 let dist = API3.SquareVectorDistance(pos, dropsite.position()); 552 if (dist < distMin) 553 distMin = dist; 554 }); 550 for (let dropsite of foodDropsites) 551 { 552 if (!dropsite.position()) 553 continue; 554 let owner = dropsite.owner(); 555 // owner !== PlayerID can only happen when hasSharedDropsites === true, so no need to test it again 556 if (owner !== PlayerID && (!dropsite.isSharedDropsite() || !gameState.isPlayerMutualAlly(owner))) 557 continue; 558 let dropsiteAccess = dropsite.getMetadata(PlayerID, "access"); 559 if (!dropsiteAccess) 560 { 561 dropsiteAccess = gameState.ai.accessibility.getAccessValue(dropsite.position()); 562 dropsite.setMetadata(PlayerID, "access", dropsiteAccess); 563 } 564 if (dropsiteAccess !== access) 565 continue; 566 distMin = Math.min(distMin, API3.SquareVectorDistance(pos, dropsite.position())); 567 } 555 568 return distMin; 556 569 }; 557 570 … … 636 649 637 650 let entPosition = this.ent.position(); 638 651 let fisherSea = this.ent.getMetadata(PlayerID, "sea"); 639 let docks = gameState.getOwnEntitiesByClass("Dock", true).filter(API3.Filters.isBuilt()); 652 let hasSharedDropsites = gameState.playerData.hasSharedDropsites; 653 let fishDropsites = (hasSharedDropsites ? gameState.getAnyDropsites("food") : gameState.getOwnDropsites("food")).filter(API3.Filters.byClass("Dock")).toEntityArray(); 640 654 641 655 let nearestDropsiteDist = function(supply) { 642 656 let distMin = 1000000; 643 657 let pos = supply.position(); 644 docks.forEach(function (dock) { 645 if (!dock.position() || dock.getMetadata(PlayerID, "sea") !== fisherSea) 646 return; 647 let dist = API3.SquareVectorDistance(pos, dock.position()); 648 if (dist < distMin) 649 distMin = dist; 650 }); 658 for (let dropsite of fishDropsites) 659 { 660 if (!dropsite.position()) 661 continue; 662 let owner = dropsite.owner(); 663 // owner !== PlayerID can only happen when hasSharedDropsites === true, so no need to test it again 664 if (owner !== PlayerID && (!dropsite.isSharedDropsite() || !gameState.isPlayerMutualAlly(owner))) 665 continue; 666 let dropsiteSea = dropsite.getMetadata(PlayerID, "sea"); 667 if (!dropsiteSea) 668 { 669 dropsiteSea = gameState.ai.accessibility.getAccessValue(dropsite.position(), true); 670 dropsite.setMetadata(PlayerID, "sea", dropsiteSea); 671 } 672 if (dropsiteSea !== fisherSea) 673 continue; 674 distMin = Math.min(distMin, API3.SquareVectorDistance(pos, dropsite.position())); 675 } 651 676 return distMin; 652 677 }; 653 678 -
binaries/data/mods/public/simulation/components/AIProxy.js
193 193 this.changes.foundationBuilders = msg.to; 194 194 }; 195 195 196 AIProxy.prototype.OnDropsiteSharingChanged = function(msg) 197 { 198 if (!this.NotifyChange()) 199 return; 200 this.changes.sharedDropsite = msg.shared; 201 }; 202 196 203 AIProxy.prototype.OnTerritoryDecayChanged = function(msg) 197 204 { 198 205 if (!this.NotifyChange()) … … 286 293 ret.resourceCarrying = cmpResourceGatherer.GetCarryingStatus(); 287 294 } 288 295 296 let cmpResourceDropsite = Engine.QueryInterface(this.entity, IID_ResourceDropsite); 297 if (cmpResourceDropsite) 298 { 299 // Updated by OnDropsiteSharingChanged 300 ret.sharedDropsite = cmpResourceDropsite.IsShared(); 301 } 302 289 303 let cmpGarrisonHolder = Engine.QueryInterface(this.entity, IID_GarrisonHolder); 290 304 if (cmpGarrisonHolder) 291 305 { -
binaries/data/mods/public/simulation/components/ResourceDropsite.js
52 52 53 53 ResourceDropsite.prototype.SetSharing = function(value) 54 54 { 55 if (this.sharable) 56 this.shared = value; 55 if (!this.sharable) 56 return; 57 this.shared = value; 58 Engine.PostMessage(this.entity, MT_DropsiteSharingChanged, { "shared": this.shared }); 57 59 }; 58 60 59 61 Engine.RegisterComponentType(IID_ResourceDropsite, "ResourceDropsite", ResourceDropsite); -
binaries/data/mods/public/simulation/components/interfaces/ResourceDropsite.js
1 1 Engine.RegisterInterface("ResourceDropsite"); 2 3 // Message of the form { "shared": true }, 4 Engine.RegisterMessageType("DropsiteSharingChanged");