Changeset View
Standalone View
binaries/data/mods/public/simulation/components/Population.js
- This file was added.
function Population() {} | ||||||||||
Population.prototype.Schema = | ||||||||||
"<a:help>Specifies the Population cap increase generated by this entity.</a:help>" + | ||||||||||
"<a:example>" + | ||||||||||
"<Bonus>15</Bonus>" + | ||||||||||
"</a:example>" + | ||||||||||
"<element name='Bonus' a:help='Population cap increase while this entity exists'>" + | ||||||||||
Freagarach: +`.` | ||||||||||
lonehawkAuthorUnsubmitted Done Inline Actions@Freagarach Sorry, I don't understand this? Am I supposed to add a dot after this plus? lonehawk: @Freagarach Sorry, I don't understand this? Am I supposed to add a dot after this plus? | ||||||||||
FreagarachUnsubmitted Done Inline ActionsNay, I meant that at line 8 after exists there should be a dot ^^ Freagarach: Nay, I meant that at line 8 after `exists` there should be a dot ^^ | ||||||||||
"<data type='nonNegativeInteger'/>" + | ||||||||||
"</element>"; | ||||||||||
Population.prototype.Init = function() | ||||||||||
{ | ||||||||||
this.bonus = +this.template.Bonus; | ||||||||||
}; | ||||||||||
Population.prototype.GetPopBonus = function() | ||||||||||
{ | ||||||||||
return this.bonus; | ||||||||||
}; | ||||||||||
Population.prototype.OnOwnershipChanged = function(msg) | ||||||||||
{ | ||||||||||
if (msg.from != INVALID_PLAYER) | ||||||||||
{ | ||||||||||
let cmpPlayer = QueryPlayerIDInterface(msg.from); | ||||||||||
if (cmpPlayer) | ||||||||||
cmpPlayer.AddPopulationBonuses(-this.GetPopBonus()); | ||||||||||
} | ||||||||||
Not Done Inline ActionsYou'll need to use the same GetBonus - this.bonus here, as the new owner might not actually have the same modifiers as the previous one. wraitii: You'll need to use the same `GetBonus - this.bonus` here, as the new owner might not actually… | ||||||||||
if (msg.to != INVALID_PLAYER) | ||||||||||
{ | ||||||||||
let cmpPlayer = QueryPlayerIDInterface(msg.to); | ||||||||||
if (cmpPlayer) | ||||||||||
cmpPlayer.AddPopulationBonuses(this.GetPopBonus()); | ||||||||||
} | ||||||||||
}; | ||||||||||
Population.prototype.OnValueModification = function(msg) | ||||||||||
{ | ||||||||||
Done Inline Actions@Freagarach Sorry, I got swept away with other things, and I couldn't devote time for this. Do you think the above OnValueModification function is where I should be looking for the issue? I will check this in the coming weekend. I wish we could set a breakpoint and do a line-by-line debugging like we do in browsers to see if the correct value is being set. I tried checking our wiki, but there doesn't seem to be a way to do this? (Or I completely missed it). lonehawk: @Freagarach Sorry, I got swept away with other things, and I couldn't devote time for this. Do… | ||||||||||
Not Done Inline ActionsYou can use warn(uneval(variablename)); to debug values. Since the components are hotloaded, you can add them while testing stuff. Freagarach: You can use `warn(uneval(variablename));` to debug values. Since the components are hotloaded… | ||||||||||
if (msg.component != "Population") | ||||||||||
Not Done Inline ActionsThis should be in the if (msg.to != INVALID_PLAYER)-block. Freagarach: This should be in the `if (msg.to != INVALID_PLAYER)`-block. | ||||||||||
return; | ||||||||||
// Foundations shouldn't give a pop bonus. | ||||||||||
let cmpFoundation = Engine.QueryInterface(this.entity, IID_Foundation); | ||||||||||
if (cmpFoundation) | ||||||||||
return; | ||||||||||
// Update the population bonuses. | ||||||||||
let newPopBonus = Math.round(ApplyValueModificationsToEntity("Population/Bonus", +this.template.Bonus, this.entity)); | ||||||||||
let popDifference = newPopBonus - this.bonus; | ||||||||||
this.bonus = newPopBonus; | ||||||||||
if (!popDifference) | ||||||||||
return; | ||||||||||
let cmpPlayer = QueryOwnerInterface(this.entity); | ||||||||||
if (cmpPlayer) | ||||||||||
cmpPlayer.AddPopulationBonuses(popDifference); | ||||||||||
}; | ||||||||||
Done Inline Actions
Extra (unnecessary) newline. Freagarach: Extra (unnecessary) newline. | ||||||||||
Engine.RegisterComponentType(IID_Population, "Population", Population); |
+.