Add UnitAI CanPatrol boolean property to selectively disable patroling for some units, in particular animals, traders, fishing ships and female citizens.
Differential Revision: https://code.wildfiregames.com/D192 Reviewed By: Vladislav This was SVN commit r19455.
This commit is contained in:
parent
d1dae4fa12
commit
9f8e1eb59d
@ -232,11 +232,14 @@ var unitActions =
|
||||
},
|
||||
"getActionInfo": function(entState, targetState)
|
||||
{
|
||||
if (!entState.unitAI || !entState.unitAI.canPatrol)
|
||||
return false;
|
||||
|
||||
return { "possible": true };
|
||||
},
|
||||
"hotkeyActionCheck": function(target, selection)
|
||||
{
|
||||
if (!someUnitAI(selection) ||
|
||||
if (!someCanPatrol(selection) ||
|
||||
!Engine.HotkeyIsPressed("session.patrol") ||
|
||||
!getActionInfo("patrol", target).possible)
|
||||
return false;
|
||||
@ -1273,8 +1276,9 @@ var g_EntityCommands =
|
||||
"patrol": {
|
||||
"getInfo": function(entState)
|
||||
{
|
||||
if (g_Selection.toList().every(ent => !GetEntityState(ent).unitAI))
|
||||
if (!someCanPatrol(g_Selection.toList()))
|
||||
return false;
|
||||
|
||||
return {
|
||||
"tooltip": colorizeHotkey("%(hotkey)s" + " ", "session.patrol") +
|
||||
translate("Patrol") + "\n" +
|
||||
@ -1431,6 +1435,14 @@ function someGuarding(entities)
|
||||
});
|
||||
}
|
||||
|
||||
function someCanPatrol(entities)
|
||||
{
|
||||
return entities.some(ent => {
|
||||
let entState = GetEntityState(ent);
|
||||
return entState && entState.unitAI && entState.unitAI.canPatrol;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep in sync with Commands.js.
|
||||
*/
|
||||
|
@ -382,6 +382,7 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
|
||||
"hasWorkOrders": cmpUnitAI.HasWorkOrders(),
|
||||
"canGuard": cmpUnitAI.CanGuard(),
|
||||
"isGuarding": cmpUnitAI.IsGuardOf(),
|
||||
"canPatrol": cmpUnitAI.CanPatrol(),
|
||||
"possibleStances": cmpUnitAI.GetPossibleStances(),
|
||||
"isIdle":cmpUnitAI.IsIdle(),
|
||||
};
|
||||
|
@ -24,6 +24,9 @@ UnitAI.prototype.Schema =
|
||||
"<element name='CanGuard'>" +
|
||||
"<data type='boolean'/>" +
|
||||
"</element>" +
|
||||
"<element name='CanPatrol'>" +
|
||||
"<data type='boolean'/>" +
|
||||
"</element>" +
|
||||
"<optional>" +
|
||||
"<interleave>" +
|
||||
"<element name='NaturalBehaviour' a:help='Behaviour of the unit in the absence of player commands (intended for animals)'>" +
|
||||
@ -5042,7 +5045,14 @@ UnitAI.prototype.CanGuard = function()
|
||||
if (cmpGuard && cmpGuard.GetEntities().length)
|
||||
return false;
|
||||
|
||||
return (this.template.CanGuard == "true");
|
||||
return this.template.CanGuard == "true";
|
||||
};
|
||||
|
||||
UnitAI.prototype.CanPatrol = function()
|
||||
{
|
||||
// Formation controllers should always respond to commands
|
||||
// (then the individual units can make up their own minds)
|
||||
return this.IsFormationController() || this.template.CanPatrol == "true";
|
||||
};
|
||||
|
||||
/**
|
||||
@ -5093,6 +5103,12 @@ UnitAI.prototype.WalkAndFight = function(x, z, targetClasses, queued)
|
||||
|
||||
UnitAI.prototype.Patrol = function(x, z, targetClasses, queued)
|
||||
{
|
||||
if (!this.CanPatrol())
|
||||
{
|
||||
this.Walk(x, z, queued);
|
||||
return;
|
||||
}
|
||||
|
||||
this.AddOrder("Patrol", { "x": x, "z": z, "targetClasses": targetClasses, "force": true }, queued);
|
||||
};
|
||||
|
||||
|
@ -37,6 +37,7 @@
|
||||
<FleeDistance>12.0</FleeDistance>
|
||||
<FormationController>true</FormationController>
|
||||
<CanGuard>true</CanGuard>
|
||||
<CanPatrol>true</CanPatrol>
|
||||
</UnitAI>
|
||||
<UnitMotion>
|
||||
<FormationController>true</FormationController>
|
||||
|
@ -102,6 +102,7 @@
|
||||
<FleeDistance>12.0</FleeDistance>
|
||||
<FormationController>false</FormationController>
|
||||
<CanGuard>true</CanGuard>
|
||||
<CanPatrol>true</CanPatrol>
|
||||
</UnitAI>
|
||||
<UnitMotion>
|
||||
<FormationController>false</FormationController>
|
||||
|
@ -23,6 +23,7 @@
|
||||
<UnitAI>
|
||||
<AlertReactiveLevel>99</AlertReactiveLevel>
|
||||
<CanGuard>false</CanGuard>
|
||||
<CanPatrol>false</CanPatrol>
|
||||
<RoamDistance>8.0</RoamDistance>
|
||||
<FleeDistance>24.0</FleeDistance>
|
||||
<RoamTimeMin>2000</RoamTimeMin>
|
||||
|
@ -25,6 +25,7 @@
|
||||
<NaturalBehaviour>passive</NaturalBehaviour>
|
||||
<FormationController>false</FormationController>
|
||||
<CanGuard>false</CanGuard>
|
||||
<CanPatrol>false</CanPatrol>
|
||||
<RoamDistance>20</RoamDistance>
|
||||
<FleeDistance>10.0</FleeDistance>
|
||||
<RoamTimeMin>10000</RoamTimeMin>
|
||||
|
@ -57,6 +57,7 @@
|
||||
<UnitAI>
|
||||
<DefaultStance>passive</DefaultStance>
|
||||
<CanGuard>false</CanGuard>
|
||||
<CanPatrol>false</CanPatrol>
|
||||
</UnitAI>
|
||||
<UnitMotion>
|
||||
<PassabilityClass>ship-small</PassabilityClass>
|
||||
|
@ -55,6 +55,7 @@
|
||||
<UnitAI>
|
||||
<DefaultStance>passive</DefaultStance>
|
||||
<CanGuard>false</CanGuard>
|
||||
<CanPatrol>false</CanPatrol>
|
||||
</UnitAI>
|
||||
<UnitMotion>
|
||||
<PassabilityClass>ship-small</PassabilityClass>
|
||||
|
@ -86,6 +86,7 @@
|
||||
</Sound>
|
||||
<UnitAI>
|
||||
<AlertReactiveLevel>1</AlertReactiveLevel>
|
||||
<CanPatrol>false</CanPatrol>
|
||||
</UnitAI>
|
||||
<UnitMotion>
|
||||
<WalkSpeed>9.5</WalkSpeed>
|
||||
|
@ -43,6 +43,7 @@
|
||||
</Trader>
|
||||
<UnitAI>
|
||||
<CanGuard>false</CanGuard>
|
||||
<CanPatrol>false</CanPatrol>
|
||||
</UnitAI>
|
||||
<UnitMotion>
|
||||
<WalkSpeed>9.5</WalkSpeed>
|
||||
|
@ -63,6 +63,9 @@
|
||||
<trained>actor/fauna/animal/elephant_trained.xml</trained>
|
||||
</SoundGroups>
|
||||
</Sound>
|
||||
<UnitAI>
|
||||
<CanPatrol>false</CanPatrol>
|
||||
</UnitAI>
|
||||
<UnitMotion>
|
||||
<PassabilityClass>large</PassabilityClass>
|
||||
<WalkSpeed>5.5</WalkSpeed>
|
||||
|
@ -32,6 +32,7 @@
|
||||
</Identity>
|
||||
<UnitAI>
|
||||
<DefaultStance>standground</DefaultStance>
|
||||
<CanPatrol>true</CanPatrol>
|
||||
</UnitAI>
|
||||
<VisualActor>
|
||||
<Actor>units/spartans/female_citizen.xml</Actor>
|
||||
|
Loading…
Reference in New Issue
Block a user