Ticket #1871: numworker.diff
File numworker.diff, 10.3 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/gui/session/session.xml
866 866 <object size="90 -2 126 34" name="attackAndArmorStats" type="image" sprite="stretched:session/icons/stances/defensive.png" tooltip="Attack and Armor" tooltip_style="sessionToolTip"/> 867 867 868 868 <!-- Resource carrying icon/counter --> 869 <!-- Used also for number of gatherers/builders --> 869 870 <object size="100%-78 -2 100%-28 34" type="text" name="resourceCarryingText" style="CarryingTextRight"/> 870 <object size="100%-36 -2 100% 34" type="image" name="resourceCarryingIcon" />871 <object size="100%-36 -2 100% 34" type="image" name="resourceCarryingIcon" tooltip_style="sessionToolTip"/> 871 872 </object> 872 873 873 874 <!-- Big unit icon --> -
binaries/data/mods/public/gui/session/selection_details.js
131 131 getGUIObjectByName("resourceCarryingText").hidden = false; 132 132 getGUIObjectByName("resourceCarryingIcon").sprite = "stretched:session/icons/resources/"+carried.type+".png"; 133 133 getGUIObjectByName("resourceCarryingText").caption = carried.amount + " / " + carried.max; 134 getGUIObjectByName("resourceCarryingIcon").tooltip = ""; 134 135 } 135 136 // Use the same indicators for traders 136 137 else if (entState.trader && entState.trader.goods.amount > 0) … … 139 140 getGUIObjectByName("resourceCarryingText").hidden = false; 140 141 getGUIObjectByName("resourceCarryingIcon").sprite = "stretched:session/icons/resources/"+entState.trader.goods.type+".png"; 141 142 getGUIObjectByName("resourceCarryingText").caption = entState.trader.goods.amount; 143 getGUIObjectByName("resourceCarryingIcon").tooltip = ""; 142 144 } 145 // And for number of workers 146 else if (entState.foundation) 147 { 148 getGUIObjectByName("resourceCarryingIcon").hidden = false; 149 getGUIObjectByName("resourceCarryingText").hidden = false; 150 getGUIObjectByName("resourceCarryingIcon").sprite = "stretched:session/icons/repair.png"; 151 getGUIObjectByName("resourceCarryingText").caption = entState.foundation.numBuilders + " "; 152 getGUIObjectByName("resourceCarryingIcon").tooltip = "number of builders"; 153 } 154 else if (entState.resourceSupply && (!entState.resourceSupply.killBeforeGather || !entState.hitpoints)) 155 { 156 getGUIObjectByName("resourceCarryingIcon").hidden = false; 157 getGUIObjectByName("resourceCarryingText").hidden = false; 158 getGUIObjectByName("resourceCarryingIcon").sprite = "stretched:session/icons/repair.png"; 159 getGUIObjectByName("resourceCarryingText").caption = entState.resourceSupply.gatherers.length + " / " + entState.resourceSupply.maxGatherers + " "; 160 getGUIObjectByName("resourceCarryingIcon").tooltip = "number/max of gatherers"; 161 } 143 162 else 144 163 { 145 164 getGUIObjectByName("resourceCarryingIcon").hidden = true; … … 148 167 149 168 // Set Player details 150 169 getGUIObjectByName("specific").caption = specificName; 151 170 getGUIObjectByName("player").caption = playerName; 152 171 getGUIObjectByName("playerColorBackground").sprite = "colour: " + playerColor; 153 172 154 173 if (genericName) -
binaries/data/mods/public/simulation/components/GuiInterface.js
235 235 if (cmpFoundation) 236 236 { 237 237 ret.foundation = { 238 "progress": cmpFoundation.GetBuildPercentage() 238 "progress": cmpFoundation.GetBuildPercentage(), 239 "numBuilders": cmpFoundation.GetNumBuilders(), 239 240 }; 240 241 } 241 242 -
binaries/data/mods/public/simulation/components/Foundation.js
12 12 // its obstruction once there's nothing in the way. 13 13 this.committed = false; 14 14 15 // Set up a timer so we can count the number of builders in a 1-second period. 16 // (We assume each builder only builds once per second, which is what UnitAI 17 // implements.) 18 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 19 this.timer = cmpTimer.SetInterval(this.entity, IID_Foundation, "UpdateTimeout", 1000, 1000, {}); 20 this.recentBuilders = []; // builder entities since the last timeout 21 this.numRecentBuilders = 0; // number of builder entities as of the last timeout 15 this.builders = []; // builder entities 22 16 this.buildMultiplier = 1; // Multiplier for the amount of work builders do. 23 17 24 18 this.previewEntity = INVALID_ENTITY; 25 19 }; 26 20 27 Foundation.prototype.UpdateTimeout = function()28 {29 this.numRecentBuilders = this.recentBuilders.length;30 this.recentBuilders = [];31 this.SetBuildMultiplier();32 33 Engine.QueryInterface(this.entity, IID_Visual).SetVariable("numbuilders", this.numRecentBuilders);34 };35 36 21 Foundation.prototype.InitialiseConstruction = function(owner, template) 37 22 { 38 23 this.finalTemplateName = template; … … 80 65 return Math.floor(this.GetBuildProgress() * 100); 81 66 }; 82 67 68 Foundation.prototype.GetNumBuilders = function() 69 { 70 return this.builders.length; 71 }; 72 83 73 Foundation.prototype.IsFinished = function() 84 74 { 85 75 return (this.GetBuildProgress() == 1.0); … … 115 105 cmpStatisticsTracker.IncreaseResourceUsedCounter(r, -scaled); 116 106 } 117 107 } 118 119 // Reset the timer120 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);121 cmpTimer.CancelTimer(this.timer);122 108 }; 123 109 124 110 /** 125 * Adds a builder to the counter. Used indirectly by UnitAI to signal that 126 * a unit has started the construction timer and will actually build soon. 111 * Adds or removes a builder to the counter. 127 112 */ 128 113 Foundation.prototype.AddBuilder = function(builderEnt) 129 114 { 130 if (this.recentBuilders.indexOf(builderEnt) != -1) 131 return; 115 if (this.builders.indexOf(builderEnt) === -1) 116 { 117 this.builders.push(builderEnt); 118 Engine.QueryInterface(this.entity, IID_Visual).SetVariable("numbuilders", this.builders.length); 119 this.SetBuildMultiplier(); 120 } 121 }; 132 122 133 this.recentBuilders.push(builderEnt); 134 if (this.recentBuilders.length > this.numRecentBuilders) 123 Foundation.prototype.RemoveBuilder = function(builderEnt) 124 { 125 if (this.builders.indexOf(builderEnt) !== -1) 135 126 { 136 this.numRecentBuilders = this.recentBuilders.length; 127 this.builders.splice(this.builders.indexOf(builderEnt),1); 128 Engine.QueryInterface(this.entity, IID_Visual).SetVariable("numbuilders", this.builders.length); 137 129 this.SetBuildMultiplier(); 138 130 } 139 131 }; 140 132 141 133 /** 142 134 * Sets the build rate multiplier, which is applied to all builders. 135 * Yields a total rate of construction equal to numBuilders^0.7 143 136 */ 137 144 138 Foundation.prototype.SetBuildMultiplier = function() 145 139 { 146 // Yields a total rate of construction equal to numRecentBuilders^0.7 147 this.buildMultiplier = Math.pow(this.numRecentBuilders, 0.7) / this.numRecentBuilders; 140 var numBuilders = this.builders.length; 141 if (numBuilders == 0) 142 this.buildMultiplier = 1; 143 else 144 this.buildMultiplier = Math.pow(numBuilders, 0.7) / numBuilders; 148 145 }; 149 146 150 147 /** … … 241 238 var cmpCost = Engine.QueryInterface(this.entity, IID_Cost); 242 239 var amount = work / cmpCost.GetBuildTime(); 243 240 244 // Record this builder so we can count the total number245 this.AddBuilder(builderEnt);246 247 241 // Add an appropriate proportion of hitpoints 248 242 var cmpHealth = Engine.QueryInterface(this.entity, IID_Health); 249 243 var maxHealth = cmpHealth.GetMaxHitpoints(); -
binaries/data/mods/public/simulation/components/UnitAI.js
2103 2103 2104 2104 this.order.data.force = false; 2105 2105 2106 var target = this.order.data.target;2106 this.repairTarget = this.order.data.target; // temporary, deleted in "leave". 2107 2107 // Check we can still reach and repair the target 2108 if (!this.CheckTargetRange(t arget, IID_Builder) || !this.CanRepair(target))2108 if (!this.CheckTargetRange(this.repairTarget, IID_Builder) || !this.CanRepair(this.repairTarget)) 2109 2109 { 2110 2110 // Can't reach it, no longer owned by ally, or it doesn't exist any more 2111 2111 this.FinishOrder(); … … 2113 2113 } 2114 2114 else 2115 2115 { 2116 var cmpFoundation = Engine.QueryInterface(t arget, IID_Foundation);2116 var cmpFoundation = Engine.QueryInterface(this.repairTarget, IID_Foundation); 2117 2117 if (cmpFoundation) 2118 2118 cmpFoundation.AddBuilder(this.entity); 2119 2119 } … … 2124 2124 }, 2125 2125 2126 2126 "leave": function() { 2127 var cmpFoundation = Engine.QueryInterface(this.repairTarget, IID_Foundation); 2128 if (cmpFoundation) 2129 cmpFoundation.RemoveBuilder(this.entity); 2130 delete this.repairTarget; 2127 2131 this.StopTimer(); 2128 2132 }, 2129 2133 2130 2134 "Timer": function(msg) { 2131 var target = this.order.data.target;2132 2135 // Check we can still reach and repair the target 2133 if (!this.CheckTargetRange(t arget, IID_Builder) || !this.CanRepair(target))2136 if (!this.CheckTargetRange(this.repairTarget, IID_Builder) || !this.CanRepair(this.repairTarget)) 2134 2137 { 2135 2138 // Can't reach it, no longer owned by ally, or it doesn't exist any more 2136 2139 this.FinishOrder(); … … 2138 2141 } 2139 2142 2140 2143 var cmpBuilder = Engine.QueryInterface(this.entity, IID_Builder); 2141 cmpBuilder.PerformBuilding(t arget);2144 cmpBuilder.PerformBuilding(this.repairTarget); 2142 2145 }, 2143 2146 }, 2144 2147 … … 2592 2595 cmpSupply.RemoveGatherer(this.entity); 2593 2596 delete this.gatheringTarget; 2594 2597 } 2595 2598 // And the Foundation builder count 2599 if (this.repairTarget) 2600 { 2601 var cmpFoundation = Engine.QueryInterface(this.repairTarget, IID_Foundation); 2602 if (cmpFoundation) 2603 cmpFoundation.RemoveBuilder(this.entity); 2604 delete this.repairTarget; 2605 } 2606 2596 2607 // Clean up range queries 2597 2608 var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager); 2598 2609 if (this.losRangeQuery)