Index: binaries/data/mods/public/simulation/components/Formation.js
===================================================================
--- binaries/data/mods/public/simulation/components/Formation.js
+++ binaries/data/mods/public/simulation/components/Formation.js
@@ -66,17 +66,15 @@
"" +
"" +
"" +
- "" +
- "" +
+ "" +
+ "" +
"";
var g_ColumnDistanceThreshold = 128; // distance at which we'll switch between column/box formations
Formation.prototype.Init = function()
{
- this.formationShape = this.template.FormationShape;
this.sortingClasses = this.template.SortingClasses.split(/\s+/g);
- this.sortingOrder = this.template.SortingOrder;
this.shiftRows = this.template.ShiftRows == "true";
this.separationMultiplier = {
"width": +this.template.UnitSeparationWidthMultiplier,
@@ -89,26 +87,26 @@
this.maxRows = +(this.template.MaxRows || 0);
this.centerGap = +(this.template.CenterGap || 0);
- this.animations = [];
- if (this.template.Animations)
+ if (this.template.AnimationVariants)
{
- let differentAnimations = this.template.Animations.split(/\s*;\s*/);
- // loop over the different rectangulars that will map to different animations
- for (var rectAnimation of differentAnimations)
- {
- var rect, replacementAnimationName;
- [rect, replacementAnimationName] = rectAnimation.split(/\s*:\s*/);
- var rows, columns;
+ this.animationvariants = [];
+ let differentAnimationVariants = this.template.AnimationVariants.split(/\s*;\s*/);
+ // loop over the different rectangulars that will map to different animation variants
+ for (let rectAnimationVariant of differentAnimationVariants)
+ {
+ let rect, replacementAnimationVariant;
+ [rect, replacementAnimationVariant] = rectAnimationVariant.split(/\s*:\s*/);
+ let rows, columns;
[rows, columns] = rect.split(/\s*,\s*/);
- var minRow, maxRow, minColumn, maxColumn;
+ let minRow, maxRow, minColumn, maxColumn;
[minRow, maxRow] = rows.split(/\s*\.\.\s*/);
[minColumn, maxColumn] = columns.split(/\s*\.\.\s*/);
- this.animations.push({
+ this.animationvariants.push({
"minRow": +minRow,
"maxRow": +maxRow,
"minColumn": +minColumn,
"maxColumn": +maxColumn,
- "animation": replacementAnimationName
+ "name": replacementAnimationVariant
});
}
}
@@ -133,6 +131,33 @@
.SetInterval(this.entity, IID_Formation, "ShapeUpdate", 1000, 1000, null);
};
+Formation.prototype.Serialize = function()
+{
+ return {
+ "lastOrderVariant": this.lastOrderVariant,
+ "members": this.members,
+ "memberPositions": this.memberPositions,
+ "maxRowsUsed": this.maxRowsUsed,
+ "maxColumnsUsed": this.maxColumnsUsed,
+ "inPosition": this.inPosition,
+ "columnar": this.columnar,
+ "rearrange": this.rearrange,
+ "formationMembersWithAura": this.formationMembersWithAura,
+ "width": this.width,
+ "depth": this.depth,
+ "oldOrientation": this.oldOrientation,
+ "twinFormations": this.twinFormations,
+ "formationSeparation": this.formationSeparation
+ };
+};
+
+Formation.prototype.Deserialize = function(data)
+{
+ this.Init();
+ for (let key in data)
+ this[key] = data[key];
+}
+
/**
* Set the value from which two twin formations will become one.
*/
@@ -203,45 +228,44 @@
};
/**
- * Get the formation animation for a certain member of this formation
+ * Get the formation animation variant for a certain member of this formation
* @param entity The entity ID to get the animation for
- * @return The name of the transformed animation as defined in the template
+ * @return The name of the animation variant as defined in the template
* E.g. "testudo_row1" or undefined if does not exist
*/
-Formation.prototype.GetFormationAnimation = function(entity)
+Formation.prototype.GetFormationAnimationVariant = function(entity)
{
- var animationGroup = this.animations;
- if (!animationGroup.length || this.columnar || !this.memberPositions[entity])
+ if (!this.animationvariants || !this.animationvariants.length || this.columnar || !this.memberPositions[entity])
return undefined;
- var row = this.memberPositions[entity].row;
- var column = this.memberPositions[entity].column;
- for (var i = 0; i < animationGroup.length; ++i)
+ let row = this.memberPositions[entity].row;
+ let column = this.memberPositions[entity].column;
+ for (let i = 0; i < this.animationvariants.length; ++i)
{
- var minRow = animationGroup[i].minRow;
+ let minRow = this.animationvariants[i].minRow;
if (minRow < 0)
minRow += this.maxRowsUsed + 1;
if (row < minRow)
continue;
- var maxRow = animationGroup[i].maxRow;
+ let maxRow = this.animationvariants[i].maxRow;
if (maxRow < 0)
maxRow += this.maxRowsUsed + 1;
if (row > maxRow)
continue;
- var minColumn = animationGroup[i].minColumn;
+ let minColumn = this.animationvariants[i].minColumn;
if (minColumn < 0)
minColumn += this.maxColumnsUsed[row] + 1;
if (column < minColumn)
continue;
- var maxColumn = animationGroup[i].maxColumn;
+ let maxColumn = this.animationvariants[i].maxColumn;
if (maxColumn < 0)
maxColumn += this.maxColumnsUsed[row] + 1;
if (column > maxColumn)
continue;
- return animationGroup[i].animation;
+ return this.animationvariants[i].name;
}
return undefined;
};
@@ -636,11 +660,10 @@
var count = active.length;
- var shape = this.formationShape;
+ let shape = this.template.FormationShape;
var shiftRows = this.shiftRows;
var centerGap = this.centerGap;
- var sortingOrder = this.sortingOrder;
-
+ let sortingOrder = this.template.SortingOrder;
var offsets = [];
// Choose a sensible size/shape for the various formations, depending on number of units
@@ -656,7 +679,7 @@
}
else
{
- var depth = Math.sqrt(count / this.widthDepthRatio);
+ let depth = Math.sqrt(count / this.widthDepthRatio);
if (this.maxRows && depth > this.maxRows)
depth = this.maxRows;
cols = Math.ceil(count / Math.ceil(depth) + (this.shiftRows ? 0.5 : 0));
@@ -726,8 +749,8 @@
x += side * centerGap / 2;
}
var column = Math.ceil(n/2) + Math.ceil(c/2) * side;
- var r1 = randFloat(-1, 1) * this.sloppyness;
- var r2 = randFloat(-1, 1) * this.sloppyness;
+ let r1 = randFloat(-1, 1) * this.sloppyness;
+ let r2 = randFloat(-1, 1) * this.sloppyness;
offsets.push(new Vector2D(x + r1, z + r2));
offsets[offsets.length - 1].row = r+1;
Index: binaries/data/mods/public/simulation/components/UnitAI.js
===================================================================
--- binaries/data/mods/public/simulation/components/UnitAI.js
+++ binaries/data/mods/public/simulation/components/UnitAI.js
@@ -1312,7 +1312,7 @@
let cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation);
if (cmpFormation)
{
- this.formationAnimationVariant = cmpFormation.GetFormationAnimation(this.entity);
+ this.formationAnimationVariant = cmpFormation.GetFormationAnimationVariant(this.entity);
if (this.formationAnimationVariant)
this.SetAnimationVariant(this.formationAnimationVariant);
else
@@ -1341,7 +1341,7 @@
{
let cmpFormation = Engine.QueryInterface(this.formationController, IID_Formation);
if (cmpFormation)
- this.formationAnimationVariant = cmpFormation.GetFormationAnimation(this.entity);
+ this.formationAnimationVariant = cmpFormation.GetFormationAnimationVariant(this.entity);
}
if (this.formationAnimationVariant)
this.SetAnimationVariant(this.formationAnimationVariant);
Index: binaries/data/mods/public/simulation/templates/special/formations/anti_cavalry.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/special/formations/anti_cavalry.xml
+++ binaries/data/mods/public/simulation/templates/special/formations/anti_cavalry.xml
@@ -14,10 +14,10 @@
8
2
0.8
-
+
1..1,1..-1: anti_cavalry_front;
2..2,1..-1: anti_cavalry_back
-
+
true
Index: binaries/data/mods/public/simulation/templates/special/formations/phalanx.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/special/formations/phalanx.xml
+++ binaries/data/mods/public/simulation/templates/special/formations/phalanx.xml
@@ -12,11 +12,11 @@
5
20
8
-
+
1..1,1..-1: phalanx_front;
2..2,1..-1: phalanx_mid;
3..-1,1..-1: phalanx_back
-
+
false
Index: binaries/data/mods/public/simulation/templates/special/formations/syntagma.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/special/formations/syntagma.xml
+++ binaries/data/mods/public/simulation/templates/special/formations/syntagma.xml
@@ -14,14 +14,14 @@
4
8
9
-
+
1..2,1..-1: syntagma_front;
3..3,1..-1: syntagma_01;
4..4,1..-1: syntagma_02;
5..5,1..-1: syntagma_03;
6..6,1..-1: syntagma_04;
7...-1,1..-1: syntagma_back
-
+
0.15
Index: binaries/data/mods/public/simulation/templates/special/formations/testudo.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/special/formations/testudo.xml
+++ binaries/data/mods/public/simulation/templates/special/formations/testudo.xml
@@ -13,7 +13,7 @@
0.8
8
8
-
+
1..1,2..7: testudo_front;
1..1,1..1: testudo_front_left;
1..1,8..8: testudo_front_right;
@@ -62,7 +62,7 @@
16..16,8..8: testudo_right;
16..16,2..7: testudo_top;
16..16,1..1: testudo_left
-
+
false
Index: binaries/data/mods/public/simulation/templates/template_formation.xml
===================================================================
--- binaries/data/mods/public/simulation/templates/template_formation.xml
+++ binaries/data/mods/public/simulation/templates/template_formation.xml
@@ -31,7 +31,7 @@
1
1
0
-
+
false