Ticket #1353: 1353_InconsistentGathering.patch
File 1353_InconsistentGathering.patch, 5.0 KB (added by , 12 years ago) |
---|
-
binaries/data/mods/public/simulation/components/ResourceGatherer.js
187 187 /** 188 188 * Gather from the target entity. This should only be called after a successful range check, 189 189 * and if the target has a compatible ResourceSupply. 190 * It should be called at a rate of once per second.191 190 */ 192 191 ResourceGatherer.prototype.PerformGather = function(target) 193 192 { 194 var rate = this.GetTargetGatherRate(target); 195 if (!rate) 196 return { "exhausted": true }; 193 // PerformGather call interval will be determined by gather rate, so always gather 1 amount here. 194 var gatherAmount = 1; 197 195 198 196 var cmpResourceSupply = Engine.QueryInterface(target, IID_ResourceSupply); 199 197 var type = cmpResourceSupply.GetType(); … … 205 203 // Find the maximum so we won't exceed our capacity 206 204 var maxGathered = this.GetCapacities()[type.generic] - this.carrying[type.generic]; 207 205 208 var status = cmpResourceSupply.TakeResources(Math.min(rate, maxGathered));206 var status = cmpResourceSupply.TakeResources(Math.min(gatherAmount, maxGathered)); 209 207 210 208 this.carrying[type.generic] += status.amount; 211 209 … … 244 242 245 243 var type = cmpResourceSupply.GetType(); 246 244 245 var rates = this.GetGatherRates(); 246 247 247 var rate; 248 if (type.specific && this.GetGatherRates()[type.generic+"."+type.specific])249 rate = this.GetGatherRates()[type.generic+"."+type.specific];248 if (type.specific && rates[type.generic+"."+type.specific]) 249 rate = rates[type.generic+"."+type.specific]; 250 250 else 251 rate = this.GetGatherRates()[type.generic];252 251 rate = rates[type.generic]; 252 253 253 return (rate || 0); 254 254 }; 255 255 -
binaries/data/mods/public/simulation/components/UnitAI.js
944 944 945 945 "GATHERING": { 946 946 "enter": function() { 947 this.StartTimer(1000, 1000); 947 var target = this.order.data.target; 948 949 // Calculate timing based on gather rates 950 // This allows the gather rate to control how often we gather, instead of how much. 951 var cmpResourceGatherer = Engine.QueryInterface(this.entity, IID_ResourceGatherer); 952 var rate = cmpResourceGatherer.GetTargetGatherRate(target); 948 953 949 // We want to start the gather animation as soon as possible, 950 // but only if we're actually at the target and it's still alive 951 // (else it'll look like we're chopping empty air). 952 // (If it's not alive, the Timer handler will deal with sending us 953 // off to a different target.) 954 if (this.CheckTargetRange(this.order.data.target, IID_ResourceGatherer)) 955 { 956 var typename = "gather_" + this.order.data.type.specific; 957 this.SelectAnimation(typename, false, 1.0, typename); 958 } 954 if (rate) 955 { 956 // Scale timing interval based on rate, and start timer 957 var offset = 0; 958 var repeat = 1000 / rate; 959 this.StartTimer(offset, repeat); 960 961 // We want to start the gather animation as soon as possible, 962 // but only if we're actually at the target and it's still alive 963 // (else it'll look like we're chopping empty air). 964 // (If it's not alive, the Timer handler will deal with sending us 965 // off to a different target.) 966 if (this.CheckTargetRange(target, IID_ResourceGatherer)) 967 { 968 var typename = "gather_" + this.order.data.type.specific; 969 970 // TODO: Update animation speed based on gather rate? (1000 / repeat) yields exaggerated results. 971 this.SelectAnimation(typename, false, 1.0, typename); 972 } 973 } 974 else 975 { 976 // No rate, give up on gathering 977 this.FinishOrder(); 978 } 959 979 }, 960 980 961 981 "leave": function() { … … 1970 1990 { 1971 1991 this.timer = undefined; 1972 1992 } 1973 else1974 {1975 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);1976 this.timer = cmpTimer.SetTimeout(this.entity, IID_UnitAI, "TimerHandler", data.timerRepeat - lateness, data);1977 }1978 1993 1979 1994 UnitFsm.ProcessMessage(this, {"type": "Timer", "data": data, "lateness": lateness}); 1980 1995 }; … … 1992 2007 var data = { "timerRepeat": repeat }; 1993 2008 1994 2009 var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer); 1995 this.timer = cmpTimer.SetTimeout(this.entity, IID_UnitAI, "TimerHandler", offset, data); 2010 if (repeat === undefined) 2011 this.timer = cmpTimer.SetTimeout(this.entity, IID_UnitAI, "TimerHandler", offset, data); 2012 else 2013 this.timer = cmpTimer.SetInterval(this.entity, IID_UnitAI, "TimerHandler", offset, repeat, data); 1996 2014 }; 1997 2015 1998 2016 /**