1
0
forked from 0ad/0ad

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:
elexis 2017-04-25 11:22:41 +00:00
parent d1dae4fa12
commit 9f8e1eb59d
13 changed files with 44 additions and 3 deletions

View File

@ -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.
*/

View File

@ -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(),
};

View File

@ -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);
};

View File

@ -37,6 +37,7 @@
<FleeDistance>12.0</FleeDistance>
<FormationController>true</FormationController>
<CanGuard>true</CanGuard>
<CanPatrol>true</CanPatrol>
</UnitAI>
<UnitMotion>
<FormationController>true</FormationController>

View File

@ -102,6 +102,7 @@
<FleeDistance>12.0</FleeDistance>
<FormationController>false</FormationController>
<CanGuard>true</CanGuard>
<CanPatrol>true</CanPatrol>
</UnitAI>
<UnitMotion>
<FormationController>false</FormationController>

View File

@ -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>

View File

@ -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>

View File

@ -57,6 +57,7 @@
<UnitAI>
<DefaultStance>passive</DefaultStance>
<CanGuard>false</CanGuard>
<CanPatrol>false</CanPatrol>
</UnitAI>
<UnitMotion>
<PassabilityClass>ship-small</PassabilityClass>

View File

@ -55,6 +55,7 @@
<UnitAI>
<DefaultStance>passive</DefaultStance>
<CanGuard>false</CanGuard>
<CanPatrol>false</CanPatrol>
</UnitAI>
<UnitMotion>
<PassabilityClass>ship-small</PassabilityClass>

View File

@ -86,6 +86,7 @@
</Sound>
<UnitAI>
<AlertReactiveLevel>1</AlertReactiveLevel>
<CanPatrol>false</CanPatrol>
</UnitAI>
<UnitMotion>
<WalkSpeed>9.5</WalkSpeed>

View File

@ -43,6 +43,7 @@
</Trader>
<UnitAI>
<CanGuard>false</CanGuard>
<CanPatrol>false</CanPatrol>
</UnitAI>
<UnitMotion>
<WalkSpeed>9.5</WalkSpeed>

View File

@ -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>

View File

@ -32,6 +32,7 @@
</Identity>
<UnitAI>
<DefaultStance>standground</DefaultStance>
<CanPatrol>true</CanPatrol>
</UnitAI>
<VisualActor>
<Actor>units/spartans/female_citizen.xml</Actor>