Differential D3155 Diff 14521 ps/trunk/binaries/data/mods/public/simulation/components/ResourceGatherer.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/ResourceGatherer.js
Show First 20 Lines • Show All 328 Lines • ▼ Show 20 Lines | |||||
*/ | */ | ||||
ResourceGatherer.prototype.DropResources = function() | ResourceGatherer.prototype.DropResources = function() | ||||
{ | { | ||||
this.carrying = {}; | this.carrying = {}; | ||||
Engine.PostMessage(this.entity, MT_ResourceCarryingChanged, { "to": this.GetCarryingStatus() }); | Engine.PostMessage(this.entity, MT_ResourceCarryingChanged, { "to": this.GetCarryingStatus() }); | ||||
}; | }; | ||||
/** | |||||
* @param {string} type - A generic resource type. | |||||
*/ | |||||
ResourceGatherer.prototype.AddToPlayerCounter = function(type) | |||||
{ | |||||
// We need to be removed from the player counter first. | |||||
if (this.lastGathered) | |||||
return; | |||||
let cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); | |||||
if (cmpPlayer) | |||||
cmpPlayer.AddResourceGatherer(type); | |||||
this.lastGathered = type; | |||||
}; | |||||
/** | |||||
* @param {number} playerid - Optionally a player ID. | |||||
*/ | |||||
ResourceGatherer.prototype.RemoveFromPlayerCounter = function(playerid) | |||||
{ | |||||
if (!this.lastGathered) | |||||
return; | |||||
let cmpPlayer = playerid != undefined ? | |||||
QueryPlayerIDInterface(playerid) : | |||||
QueryOwnerInterface(this.entity, IID_Player); | |||||
if (cmpPlayer) | |||||
cmpPlayer.RemoveResourceGatherer(this.lastGathered); | |||||
delete this.lastGathered; | |||||
}; | |||||
// Since we cache gather rates, we need to make sure we update them when tech changes. | // Since we cache gather rates, we need to make sure we update them when tech changes. | ||||
// and when our owner change because owners can had different techs. | // and when our owner change because owners can had different techs. | ||||
ResourceGatherer.prototype.OnValueModification = function(msg) | ResourceGatherer.prototype.OnValueModification = function(msg) | ||||
{ | { | ||||
if (msg.component != "ResourceGatherer") | if (msg.component != "ResourceGatherer") | ||||
return; | return; | ||||
this.RecalculateGatherRatesAndCapacities(); | this.RecalculateGatherRatesAndCapacities(); | ||||
}; | }; | ||||
ResourceGatherer.prototype.OnOwnershipChanged = function(msg) | ResourceGatherer.prototype.OnOwnershipChanged = function(msg) | ||||
{ | { | ||||
if (msg.to == INVALID_PLAYER) | if (msg.to == INVALID_PLAYER) | ||||
{ | |||||
this.RemoveFromPlayerCounter(msg.from); | |||||
return; | return; | ||||
} | |||||
this.RecalculateGatherRatesAndCapacities(); | this.RecalculateGatherRatesAndCapacities(); | ||||
}; | }; | ||||
ResourceGatherer.prototype.OnGlobalInitGame = function(msg) | ResourceGatherer.prototype.OnGlobalInitGame = function(msg) | ||||
{ | { | ||||
this.RecalculateGatherRatesAndCapacities(); | this.RecalculateGatherRatesAndCapacities(); | ||||
}; | }; | ||||
ResourceGatherer.prototype.OnMultiplierChanged = function(msg) | ResourceGatherer.prototype.OnMultiplierChanged = function(msg) | ||||
{ | { | ||||
let cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); | let cmpPlayer = QueryOwnerInterface(this.entity, IID_Player); | ||||
if (cmpPlayer && msg.player == cmpPlayer.GetPlayerID()) | if (cmpPlayer && msg.player == cmpPlayer.GetPlayerID()) | ||||
this.RecalculateGatherRatesAndCapacities(); | this.RecalculateGatherRatesAndCapacities(); | ||||
}; | }; | ||||
Engine.RegisterComponentType(IID_ResourceGatherer, "ResourceGatherer", ResourceGatherer); | Engine.RegisterComponentType(IID_ResourceGatherer, "ResourceGatherer", ResourceGatherer); |
Wildfire Games · Phabricator