Make cheering moddable

Reviewed by: @Angen
Differential Revision: https://code.wildfiregames.com/D3081
This was SVN commit r24192.
This commit is contained in:
Stan 2020-11-16 14:47:41 +00:00
parent bd43bdca69
commit 3a4a7ee5f9
2 changed files with 21 additions and 4 deletions

View file

@ -24,6 +24,11 @@ UnitAI.prototype.Schema =
"<element name='CanPatrol'>" +
"<data type='boolean'/>" +
"</element>" +
"<optional>" +
"<element name='CheeringTime'>" +
"<data type='nonNegativeInteger'/>" +
"</element>" +
"</optional>" +
"<optional>" +
"<interleave>" +
"<element name='NaturalBehaviour' a:help='Behaviour of the unit in the absence of player commands (intended for animals)'>" +
@ -1433,7 +1438,12 @@ UnitAI.prototype.UnitFsmSpec = {
"IDLE": {
"Order.Cheer": function() {
// Do not cheer if there is no cheering time.
if (!this.cheeringTime)
return { "discardOrder": true };
this.SetNextState("CHEERING");
return false;
},
"enter": function() {
@ -1930,7 +1940,9 @@ UnitAI.prototype.UnitFsmSpec = {
}
let cmpUnitAI = Engine.QueryInterface(this.order.data.target, IID_UnitAI);
this.shouldCheer = cmpUnitAI && (!cmpUnitAI.IsAnimal() || cmpUnitAI.IsDangerousAnimal());
// Units with no cheering time do not cheer.
this.shouldCheer = cmpUnitAI && (!cmpUnitAI.IsAnimal() || cmpUnitAI.IsDangerousAnimal()) && this.cheeringTime > 0;
return false;
},
@ -2013,7 +2025,11 @@ UnitAI.prototype.UnitFsmSpec = {
"FINDINGNEWTARGET": {
"Order.Cheer": function() {
if (!this.cheeringTime)
return { "discardOrder": true };
this.SetNextState("CHEERING");
return false;
},
"enter": function() {
@ -3043,7 +3059,7 @@ UnitAI.prototype.UnitFsmSpec = {
"CHEERING": {
"enter": function() {
this.SelectAnimation("promotion");
this.StartTimer(2800);
this.StartTimer(this.cheeringTime);
return false;
},
@ -3279,7 +3295,7 @@ UnitAI.prototype.UnitFsmSpec = {
"CHEERING": {
"enter": function() {
this.SelectAnimation("promotion");
this.StartTimer(2800);
this.StartTimer(this.cheeringTime);
return false;
},
@ -3328,7 +3344,7 @@ UnitAI.prototype.Init = function()
this.lastHealed = undefined;
this.formationAnimationVariant = undefined;
this.cheeringTime = +(this.template.CheeringTime || 0);
this.SetStance(this.template.DefaultStance);
};

View file

@ -126,6 +126,7 @@
<FormationController>false</FormationController>
<CanGuard>true</CanGuard>
<CanPatrol>true</CanPatrol>
<CheeringTime>2800</CheeringTime>
</UnitAI>
<UnitMotion>
<FormationController>false</FormationController>