Index: binaries/data/mods/public/simulation/components/Controllability.js
===================================================================
--- /dev/null
+++ binaries/data/mods/public/simulation/components/Controllability.js
@@ -0,0 +1,93 @@
+class Controllability
+{
+ get Schema()
+ {
+ return "Deals with the controllability of structures and units." +
+ "" +
+ "true" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "Main" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "" +
+ "";
+ }
+
+ /**
+ * The initialisation of the component.
+ */
+ Init()
+ {
+ this.Controllable = this.template.Controllable;
+ this.ControllableByComponent = this.template.ByComponent;
+ }
+
+ /**
+ * Whether the entity is controllable in some way.
+ *
+ * @param {string} IID - The IID to check for controllability.
+ * When undefined returns the main controllability.
+ * @param {string} IID - The order type to check for controllability.
+ * When undefined returns the main controllability of the IID.
+ * @return {boolean} - Whether the entity can be given the order.
+ */
+ GetControllability(IID, orderType)
+ {
+ if (!IID)
+ return this.Controllable == "true";
+ if (this.ControllableByComponent[IID].Main != "true")
+ return false;
+ return !!this.ControllableByComponent[IID][orderType] &&
+ this.ControllableByComponent[IID][orderType] == "true";
+ }
+
+ /**
+ * Whether the entity is controllable in some way.
+ *
+ * @param {boolean} bool - The boolean to set the controllability to.
+ * @param {string} IID - The IID to set the controllability for.
+ * When undefined sets the main controllability.
+ * @param {string} orderType - The order type to set the controllability for.
+ * When undefined sets the main controllability of the IID.
+ */
+ SetControllability(bool, IID, orderType)
+ {
+ if (IID)
+ {
+ if (!this.ControllableByComponent[IID])
+ this.ControllableByComponent[IID] = { "Main": true };
+ if (orderType)
+ {
+ if (!this.ControllableByComponent[IID][orderType])
+ this.ControllableByComponent[IID][orderType];
+ this.ControllableByComponent[IID][orderType] = bool;
+ }
+ else
+ this.ControllableByComponent[IID].Main = bool;
+ }
+ else
+ this.Controllable = bool;
+ }
+}
+
+Engine.RegisterComponentType(IID_Controllability, "Controllability", Controllability);
Index: binaries/data/mods/public/simulation/components/interfaces/Controllability.js
===================================================================
--- /dev/null
+++ binaries/data/mods/public/simulation/components/interfaces/Controllability.js
@@ -0,0 +1,6 @@
+Engine.RegisterInterface("Controllability");
+
+/**
+ * Message sent from Controllability component.
+ */
+Engine.RegisterMessageType("ControllabilityChanged");
Index: binaries/data/mods/public/simulation/helpers/Commands.js
===================================================================
--- binaries/data/mods/public/simulation/helpers/Commands.js
+++ binaries/data/mods/public/simulation/helpers/Commands.js
@@ -1665,6 +1665,10 @@
*/
function CanControlUnit(entity, player, controlAll)
{
+ let cmpControllability = Engine.QueryInterface(entity, IID_Controllability);
+ if (cmpControllability)
+ warn(uneval(cmpControllability.GetControllability("UnitAI", "Order")));
+
return IsOwnedByPlayer(player, entity) || controlAll;
}
Index: binaries/data/mods/public/simulation/templates/template_unit.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_unit.xml
+++ binaries/data/mods/public/simulation/templates/template_unit.xml
@@ -6,6 +6,15 @@
1
15
+
+ true
+
+
+ true
+ true
+
+
+
1
0