/// <summary> /// Creates a Formation from an EnemyFormationTemplate. /// </summary> /// <param name="template">The EnemyFormationTemplate used to create the Formation.</param> /// <returns></returns> public Formation Create(AiFormationTemplate template) { var positions = new CombatEntity[GameplayConstants.MaxFormationRows][]; int leaderId = -1; for (int i = 0; i < template.EntityBases.Length; i++) { positions[i] = new CombatEntity[GameplayConstants.MaxFormationColumns]; for (int j = 0; j < template.EntityBases[i].Length; j++) { if (template.EntityBases[i][j] != null) { var entity = _combatEntityFactory.Create(template.EntityBases[i][j]); positions[i][j] = entity; if (template.EntityBases[i][j].Id == template.LeaderId && leaderId == -1) { leaderId = entity.Id; } } else { positions[i][j] = null; } } } return(new Formation { Id = _id++, LeaderId = leaderId, Name = template.Name, OwnerId = GameplayConstants.AiId, Positions = positions, AiRandomness = template.AiRandomness }); }