Ticket #2531: default_formations.diff
File default_formations.diff, 7.2 KB (added by , 10 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Identity.js
57 57 "</element>" + 58 58 "</optional>" + 59 59 "<optional>" + 60 "<element name='Formations' a:help='Optional list of space-separated formations t his unit is allowed to use. Choices include: Scatter, Box, ColumnClosed, LineClosed, ColumnOpen, LineOpen, Flank, Skirmish, Wedge, Testudo, Phalanx, Syntagma, BattleLine'>" +60 "<element name='Formations' a:help='Optional list of space-separated formations templates (see simulation/templates/formations for possible templates)'>" + 61 61 "<attribute name='datatype'>" + 62 62 "<value>tokens</value>" + 63 63 "</attribute>" + … … 65 65 "</element>" + 66 66 "</optional>" + 67 67 "<optional>" + 68 "<element name='DefaultFormation'>" + 69 "<text/>" + 70 "</element>" + 71 "</optional>" + 72 "<optional>" + 68 73 "<element name='Icon'>" + 69 74 "<text/>" + 70 75 "</element>" + … … 106 111 return this.GetClassesList().indexOf(name) != -1; 107 112 }; 108 113 114 Identity.prototype.GetDefaultFormation = function() 115 { 116 if (this.template.DefaultFormation) 117 return this.template.DefaultFormation; 118 return "formations/line_closed"; 119 }; 120 121 109 122 Identity.prototype.GetFormationsList = function() 110 123 { 111 124 if (this.template.Formations && "_string" in this.template.Formations) -
binaries/data/mods/public/simulation/helpers/Commands.js
1157 1157 } 1158 1158 1159 1159 /** 1160 * Get an alternative formation for this list of entities 1161 * If the entities had a prior formation, this will be preferred, 1162 * if they don't the default formation will be preferred 1163 */ 1164 function GetAlternativeFormation(ents) 1165 { 1166 var r = "formations/line_closed"; 1167 var cmpTemplateManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_TemplateManager); 1168 // object in the form 1169 // {"formations/line_closed": 5, "formations/testudo": 10} 1170 var defaultFormations = {}; 1171 // count the default formations of the members 1172 for each (var ent in ents) 1173 { 1174 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); 1175 if (!cmpUnitAI) 1176 continue; 1177 var formation = cmpUnitAI.GetLastFormationTemplate(); 1178 if (formation) 1179 { 1180 if (defaultFormations[formation]) 1181 defaultFormations[formation]++; 1182 else 1183 defaultFormations[formation] = 1; 1184 continue; 1185 } 1186 var cmpIdentity = Engine.QueryInterface(ent, IID_Identity); 1187 if (!cmpIdentity) 1188 continue; 1189 var formation = cmpIdentity.GetDefaultFormation(); 1190 if (formation) 1191 { 1192 if (defaultFormations[formation]) 1193 defaultFormations[formation]++; 1194 else 1195 defaultFormations[formation] = 1; 1196 } 1197 } 1198 var mostWantedFormationCount = 0; 1199 for (let formation in defaultFormations) 1200 { 1201 if (defaultFormations[formation] > mostWantedFormationCount) 1202 { 1203 r = formation; 1204 mostWantedFormationCount = defaultFormations[formation]; 1205 } 1206 } 1207 return r; 1208 } 1209 1210 /** 1160 1211 * Returns a list of UnitAI components, each belonging either to a 1161 1212 * selected unit or to a formation entity for groups of the selected units. 1162 1213 */ … … 1176 1227 return [ cmpUnitAI ]; 1177 1228 } 1178 1229 1230 var defaultFormationTemplate = GetAlternativeFormation(ents); 1179 1231 // Separate out the units that don't support the chosen formation 1180 1232 var formedEnts = []; 1181 1233 var nonformedUnitAIs = []; … … 1190 1242 // TODO: We only check if the formation is usable by some units 1191 1243 // if we move them to it. We should check if we can use formations 1192 1244 // for the other cases. 1193 if (cmpIdentity && cmpIdentity.CanUseFormation(formationTemplate || "formations/line_closed"))1245 if (cmpIdentity && cmpIdentity.CanUseFormation(formationTemplate || defaultFormationTemplate)) 1194 1246 formedEnts.push(ent); 1195 1247 else 1196 1248 nonformedUnitAIs.push(cmpUnitAI); … … 1242 1294 { 1243 1295 if (!formationTemplate || !CanMoveEntsIntoFormation(cluster, formationTemplate)) 1244 1296 { 1245 // get the most recently used formation, or default to line closed 1246 var lastFormationTemplate = undefined; 1247 for each (var ent in cluster) 1248 { 1249 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI); 1250 if (cmpUnitAI) 1251 { 1252 var template = cmpUnitAI.GetLastFormationTemplate(); 1253 if (lastFormationTemplate === undefined) 1254 { 1255 lastFormationTemplate = template; 1256 } 1257 else if (lastFormationTemplate != template) 1258 { 1259 lastFormationTemplate = undefined; 1260 break; 1261 } 1262 } 1263 } 1264 if (lastFormationTemplate && CanMoveEntsIntoFormation(cluster, lastFormationTemplate)) 1265 formationTemplate = lastFormationTemplate; 1297 // get the most recently used formation 1298 if (defaultFormationTemplate && CanMoveEntsIntoFormation(cluster, defaultFormationTemplate)) 1299 formationTemplate = defaultFormationTemplate; 1266 1300 else 1267 1301 formationTemplate = "formations/line_closed"; 1268 1302 } -
binaries/data/mods/public/simulation/templates/units/rome_infantry_spearman_b.xml
16 16 <Icon>units/rome_infantry_spearman.png</Icon> 17 17 <History>The Triarii were the third line of heavy infantry in the Republican Roman army. Made up of the veterans from previous campaigns, they often possessed the most fashionable arms and armor. Armed with a spear and gladius, the Triarii usually did not fight unless the battle was going poorly or enemy forces required the use of a spear to fend them off. In many cases the Triarii were left at the camp instead of marching out with the rest of the army.</History> 18 18 <RequiredTechnology>phase_town</RequiredTechnology> 19 <DefaultFormation>formations/testudo</DefaultFormation> 19 20 </Identity> 20 21 <Promotion> 21 22 <Entity>units/rome_infantry_spearman_a</Entity> -
binaries/data/mods/public/simulation/templates/units/rome_infantry_swordsman_b.xml
28 28 <SpecificName>Hastatus</SpecificName> 29 29 <Icon>units/rome_infantry_swordsman.png</Icon> 30 30 <History>The hastati were the first line of heavy infantry in the early Republican Roman army. They used pila and gladii as their main weapons, throwing the former into the enemy formation and then closing with the sword. For defense they used a large shield called a scutum and wore the best armor they could afford. Hastati were recruited from the young men of Rome, a small part of the 700,000 troops Rome could bring to bear against its opponents.</History> 31 <DefaultFormation>formations/testudo</DefaultFormation> 31 32 </Identity> 32 33 <Promotion> 33 34 <Entity>units/rome_infantry_swordsman_a</Entity>