forked from 0ad/0ad
implement ptol civ bonus and optimization of ResourceTrickle component, refs #4082
This was SVN commit r18920.
This commit is contained in:
parent
e55ee5048e
commit
fe01a710a5
@ -210,6 +210,17 @@ Auras.prototype.Clean = function()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When only Player class affected, we do not need a rangeQuery as applicable only to player entity
|
||||||
|
// and templates TODO maybe add a new type "player"
|
||||||
|
if (this.IsGlobalAura(name) && this.GetClasses(name).length == 1 && this.GetClasses(name)[0] == "Player")
|
||||||
|
{
|
||||||
|
this.ApplyTemplateBonus(name, affectedPlayers);
|
||||||
|
let cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager);
|
||||||
|
let playerEnts = affectedPlayers.map(player => cmpPlayerManager.GetPlayerByID(player));
|
||||||
|
this.ApplyBonus(name, playerEnts);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
this[name].rangeQuery = cmpRangeManager.CreateActiveQuery(
|
this[name].rangeQuery = cmpRangeManager.CreateActiveQuery(
|
||||||
this.entity,
|
this.entity,
|
||||||
0,
|
0,
|
||||||
|
@ -32,36 +32,47 @@ ResourceTrickle.prototype.Schema =
|
|||||||
|
|
||||||
ResourceTrickle.prototype.Init = function()
|
ResourceTrickle.prototype.Init = function()
|
||||||
{
|
{
|
||||||
|
this.ComputeRates();
|
||||||
// Call the timer
|
// Call the timer
|
||||||
var cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
let cmpTimer = Engine.QueryInterface(SYSTEM_ENTITY, IID_Timer);
|
||||||
cmpTimer.SetInterval(this.entity, IID_ResourceTrickle, "Trickle", this.GetTimer(), this.GetTimer(), undefined);
|
cmpTimer.SetInterval(this.entity, IID_ResourceTrickle, "Trickle", this.GetTimer(), this.GetTimer(), undefined);
|
||||||
};
|
};
|
||||||
|
|
||||||
ResourceTrickle.prototype.GetTimer = function()
|
ResourceTrickle.prototype.GetTimer = function()
|
||||||
{
|
{
|
||||||
var interval = +this.template.Interval;
|
return +this.template.Interval;
|
||||||
return interval;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ResourceTrickle.prototype.GetRates = function()
|
ResourceTrickle.prototype.GetRates = function()
|
||||||
{
|
{
|
||||||
var rates = {};
|
return this.rates;
|
||||||
for (var resource in this.template.Rates)
|
};
|
||||||
rates[resource] = ApplyValueModificationsToEntity("ResourceTrickle/Rates/"+resource, +this.template.Rates[resource], this.entity);
|
|
||||||
|
|
||||||
return rates;
|
ResourceTrickle.prototype.ComputeRates = function()
|
||||||
|
{
|
||||||
|
this.rates = {};
|
||||||
|
for (let resource in this.template.Rates)
|
||||||
|
this.rates[resource] = ApplyValueModificationsToEntity("ResourceTrickle/Rates/"+resource, +this.template.Rates[resource], this.entity);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Do the actual work here
|
// Do the actual work here
|
||||||
ResourceTrickle.prototype.Trickle = function(data, lateness)
|
ResourceTrickle.prototype.Trickle = function(data, lateness)
|
||||||
{
|
{
|
||||||
var cmpPlayer = QueryOwnerInterface(this.entity);
|
// The player entity may also have a ResourceTrickle component
|
||||||
|
let cmpPlayer = QueryOwnerInterface(this.entity) || Engine.QueryInterface(this.entity, IID_Player);
|
||||||
if (!cmpPlayer)
|
if (!cmpPlayer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var rates = this.GetRates();
|
for (let resource in this.rates)
|
||||||
for (var resource in rates)
|
cmpPlayer.AddResource(resource, this.rates[resource]);
|
||||||
cmpPlayer.AddResource(resource, rates[resource]);
|
};
|
||||||
|
|
||||||
|
ResourceTrickle.prototype.OnValueModification = function(msg)
|
||||||
|
{
|
||||||
|
if (msg.component != "ResourceTrickle")
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.ComputeRates();
|
||||||
};
|
};
|
||||||
|
|
||||||
Engine.RegisterComponentType(IID_ResourceTrickle, "ResourceTrickle", ResourceTrickle);
|
Engine.RegisterComponentType(IID_ResourceTrickle, "ResourceTrickle", ResourceTrickle);
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"type": "global",
|
||||||
|
"affects": ["Player"],
|
||||||
|
"affectedPlayers": ["ExclusiveMutualAlly"],
|
||||||
|
"modifications": [
|
||||||
|
{ "value": "ResourceTrickle/Rates/food", "add": 1.0 }
|
||||||
|
],
|
||||||
|
"auraName": "Breadbasket of the Mediterranean",
|
||||||
|
"auraDescription": "All allies automatically gain a slow trickle of food income."
|
||||||
|
}
|
@ -60,6 +60,15 @@
|
|||||||
<SharedLosTech>unlock_shared_los</SharedLosTech>
|
<SharedLosTech>unlock_shared_los</SharedLosTech>
|
||||||
<SharedDropsitesTech>unlock_shared_dropsites</SharedDropsitesTech>
|
<SharedDropsitesTech>unlock_shared_dropsites</SharedDropsitesTech>
|
||||||
</Player>
|
</Player>
|
||||||
|
<ResourceTrickle>
|
||||||
|
<Rates>
|
||||||
|
<food>0.0</food>
|
||||||
|
<wood>0.0</wood>
|
||||||
|
<stone>0.0</stone>
|
||||||
|
<metal>0.0</metal>
|
||||||
|
</Rates>
|
||||||
|
<Interval>1000</Interval>
|
||||||
|
</ResourceTrickle>
|
||||||
<StatisticsTracker/>
|
<StatisticsTracker/>
|
||||||
<TechnologyManager/>
|
<TechnologyManager/>
|
||||||
</Entity>
|
</Entity>
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Entity parent="special/player">
|
<Entity parent="special/player">
|
||||||
|
<Auras datatype="tokens">teambonuses/ptol_player_teambonus</Auras>
|
||||||
<EntityLimits>
|
<EntityLimits>
|
||||||
<LimitRemovers>
|
<LimitRemovers>
|
||||||
<CivilCentre>
|
<CivilCentre>
|
||||||
|
Loading…
Reference in New Issue
Block a user