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 @@ -187,13 +187,29 @@ /** * Returns the 'primary' member of this formation (typically the most * important unit type), for e.g. playing a representative sound. - * Returns undefined if no members. - * TODO: actually implement something like that; currently this just returns - * the arbitrary first one. + * + * @return {number | undefined} The entity ID of "the most important" unit in the formation + * or undefined if the formation has no entities. */ Formation.prototype.GetPrimaryMember = function() { - return this.members[0]; + let heroes = []; + let champs = []; + let soldrs = []; + for (let ent of this.members) + { + let cmpIdentity = Engine.QueryInterface(ent, IID_Identity); + if (!cmpIdentity) + continue; + if (cmpIdentity.HasClass("Hero")) + heroes.push(ent); + if (cmpIdentity.HasClass("Champion")) + champs.push(ent); + if (cmpIdentity.HasClass("Soldier")) + soldrs.push(ent); + } + return pickRandom(heroes) || pickRandom(champs) || + pickRandom(soldrs) || this.members[0]; }; /**