Ticket #1899: cycle-entities.patch

File cycle-entities.patch, 10.0 KB (added by alpha123, 11 years ago)
Line 
1Index: binaries/data/config/default.cfg
2===================================================================
3--- binaries/data/config/default.cfg (revision 13327)
4+++ binaries/data/config/default.cfg (working copy)
5@@ -207,8 +230,10 @@
6 hotkey.selection.idleworker = Period ; Select next idle worker
7 hotkey.selection.idlewarrior = Comma ; Select next idle warrior
8+hotkey.selection.hero = SingleQuote ; Cycle through living heroes.
9 hotkey.selection.offscreen = Alt ; Include offscreen units in selection
10 hotkey.selection.group.select.0 = 0
11 hotkey.selection.group.save.0 = "Ctrl+0"
12@@ -240,9 +265,23 @@
13 hotkey.selection.group.select.9 = 9
14 hotkey.selection.group.save.9 = "Ctrl+9"
15 hotkey.selection.group.add.9 = "Shift+9"
16+hotkey.selection.building.civcentre = "J" ; Cycle through buildings.
17+hotkey.selection.building.barracks = "K"
18+hotkey.selection.building.fortress = "Y"
19+hotkey.selection.building.corral = "O"
20+hotkey.selection.building.market = "P"
21+hotkey.selection.building.stables = "L"
22+hotkey.selection.building.elestables = "L"
23+hotkey.selection.building.kennel = "L"
24+hotkey.selection.building.gymnasion = "L"
25+hotkey.selection.building.syssiton = "L"
26+hotkey.selection.building.armycamp = "L"
27+hotkey.selection.building.apadana = "I"
28+hotkey.selection.building.prytaneion = "I"
29
30 ; > SESSION CONTROLS
31 hotkey.session.kill = Delete ; Destroy selected units
32Index: binaries/data/mods/public/gui/session/input.js
33===================================================================
34--- binaries/data/mods/public/gui/session/input.js (revision 13327)
35+++ binaries/data/mods/public/gui/session/input.js (working copy)
36@@ -1977,6 +2025,37 @@
37 resetIdleUnit();
38 }
39
40+function cycleEntities(entities) {
41+ if (entities.length < 1)
42+ return;
43+
44+ var append = Engine.HotkeyIsPressed("selection.add");
45+ var selectall = Engine.HotkeyIsPressed("selection.offscreen");
46+ var selection = g_Selection.toList(), currentIndex, newIndex = 0, newList = [];
47+
48+ if (selectall)
49+ newList = entities;
50+ else if (append)
51+ {
52+ // Find the first hero not in the selection.
53+ newIndex = entities.indexOf(
54+ Math.min.apply(Math, entities.filter(function(hero) selection.indexOf(hero) == -1)));
55+ }
56+ else if (selection.length == 1 && (currentIndex = entities.indexOf(selection[0])) > -1)
57+ {
58+ newIndex = Math.min(currentIndex + 1, entities.length);
59+ if (newIndex == entities.length)
60+ newIndex = 0;
61+ }
62+
63+ if (!newList.length && newIndex > -1)
64+ newList = [entities[newIndex]];
65+
66+ if (!append)
67+ g_Selection.reset();
68+ g_Selection.addList(newList);
69+}
70+
71 function stopUnits(entities)
72 {
73 Engine.PostNetworkCommand({ "type": "stop", "entities": entities, "queued": false });
74Index: binaries/data/mods/public/simulation/templates/template_structure_military_barracks.xml
75===================================================================
76--- binaries/data/mods/public/simulation/templates/template_structure_military_barracks.xml (revision 13339)
77+++ binaries/data/mods/public/simulation/templates/template_structure_military_barracks.xml (working copy)
78@@ -37,7 +37,7 @@
79 <Identity>
80 <GenericName>Barracks</GenericName>
81 <Tooltip>Train citizen-soldiers. Research military improvements. Garrison: 10.</Tooltip>
82- <Classes datatype="tokens">Town</Classes>
83+ <Classes datatype="tokens">Town Barracks</Classes>
84 <Icon>structures/barracks.png</Icon>
85 <RequiredTechnology>phase_town</RequiredTechnology>
86 </Identity>
87Index: binaries/data/mods/public/simulation/templates/structures/pers_stables.xml
88===================================================================
89--- binaries/data/mods/public/simulation/templates/structures/pers_stables.xml (revision 13339)
90+++ binaries/data/mods/public/simulation/templates/structures/pers_stables.xml (working copy)
91@@ -19,6 +19,7 @@
92 <SpecificName>Tavileh</SpecificName>
93 <History>Cavalry was primarily used as an elite assault force by the Persians.</History>
94 <Tooltip>Train citizen-cavalry units.</Tooltip>
95+ <Classes datatype="tokens">Town -Barracks</Classes>
96 <Icon>structures/pers_stable.png</Icon>
97 </Identity>
98 <Obstruction>
99Index: binaries/data/mods/public/gui/session/session.xml
100===================================================================
101--- binaries/data/mods/public/gui/session/session.xml (revision 13339)
102+++ binaries/data/mods/public/gui/session/session.xml (working copy)
103@@ -132,11 +218,144 @@
104 <object hotkey="selection.idlewarrior">
105 <action on="Press">findIdleUnit(["Hero", "Champion", "CitizenSoldier", "Siege", "Warship"]);</action>
106 </object>
107
108+ <!-- Cycle through living heroes. -->
109+ <object hotkey="selection.hero">
110+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("GetSimulationState").players[Engine.GetPlayerID()].heroes);</action>
111+ </object>
112+
113+ <!-- Cycle through buildings. -->
114+ <object hotkey="selection.building.civcentre">
115+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("FindUnitsByClass", {classes: ["CivCentre"]}));</action>
116+ </object>
117+
118+ <object hotkey="selection.building.barracks">
119+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("FindUnitsByClass", {classes: ["Barracks", "Embassy"]}));</action>
120+ </object>
121+
122+ <object hotkey="selection.building.fortress">
123+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("FindUnitsByClass", {classes: ["GarrisonFortress"]}));</action>
124+ </object>
125+
126+ <object hotkey="selection.building.corral">
127+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("FindUnitsByGenericName", {genericNames: ["Corral"]}));</action>
128+ </object>
129+
130+ <object hotkey="selection.building.market">
131+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("FindUnitsByClass", {classes: ["BarterMarket"]}));</action>
132+ </object>
133+
134+ <object hotkey="selection.building.stables">
135+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("FindUnitsByGenericName", {genericNames: ["Cavalry Stables"]}));</action>
136+ </object>
137+
138+ <object hotkey="selection.building.elestables">
139+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("FindUnitsByGenericName", {genericNames: ["Elephant Stables"]}));</action>
140+ </object>
141+
142+ <object hotkey="selection.building.kennel">
143+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("FindUnitsByGenericName", {genericNames: ["Kennel"]}));</action>
144+ </object>
145+
146+ <object hotkey="selection.building.gymnasion">
147+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("FindUnitsByGenericName", {genericNames: ["Gymnasium"]}));</action>
148+ </object>
149+
150+ <object hotkey="selection.building.syssiton">
151+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("FindUnitsByGenericName", {genericNames: ["Military Mess Hall"]}));</action>
152+ </object>
153+
154+ <object hotkey="selection.building.armycamp">
155+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("FindUnitsByGenericName", {genericNames: ["Entrenched Army Camp"]}));</action>
156+ </object>
157+
158+ <object hotkey="selection.building.apadana">
159+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("FindUnitsByGenericName", {genericNames: ["Persian Palace"]}));</action>
160+ </object>
161+
162+ <object hotkey="selection.building.prytaneion">
163+ <action on="Press">cycleEntities(Engine.GuiInterfaceCall("FindUnitsByGenericName", {genericNames: ["Council Chamber"]}));</action>
164+ </object>
165+
166 <!-- ================================ ================================ -->
167 <!-- Developer / Debug items -->
168 <!-- ================================ ================================ -->
169Index: binaries/data/mods/public/simulation/components/GuiInterface.js
170===================================================================
171--- binaries/data/mods/public/simulation/components/GuiInterface.js (revision 13339)
172+++ binaries/data/mods/public/simulation/components/GuiInterface.js (working copy)
173@@ -1552,6 +1552,30 @@
174 PlaySound(data.name, data.entity);
175 };
176
177+GuiInterface.prototype.FindUnitsByClass = function(player, data)
178+{
179+ var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
180+ return rangeMan.GetEntitiesByPlayer(player).filter(function(e) {
181+ var cmpUnitAI = Engine.QueryInterface(e, IID_UnitAI);
182+ var cmpIdentity = Engine.QueryInterface(e, IID_Identity);
183+ var cmpFoundation = Engine.QueryInterface(e, IID_Foundation);
184+ return cmpIdentity && !cmpFoundation && (cmpUnitAI ? !cmpUnitAI.IsGarrisoned() : true) &&
185+ data.classes.some(function(c) cmpIdentity.HasClass(c));
186+ });
187+};
188+
189+GuiInterface.prototype.FindUnitsByGenericName = function(player, data)
190+{
191+ var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
192+ return rangeMan.GetEntitiesByPlayer(player).filter(function(e) {
193+ var cmpUnitAI = Engine.QueryInterface(e, IID_UnitAI);
194+ var cmpIdentity = Engine.QueryInterface(e, IID_Identity);
195+ var cmpFoundation = Engine.QueryInterface(e, IID_Foundation);
196+ return cmpIdentity && !cmpFoundation && (cmpUnitAI ? !cmpUnitAI.IsGarrisoned() : true) &&
197+ data.genericNames.indexOf(cmpIdentity.GetGenericName()) > -1;
198+ });
199+};
200+
201 function isIdleUnit(ent, idleClass)
202 {
203 var cmpUnitAI = Engine.QueryInterface(ent, IID_UnitAI);
204@@ -1737,6 +1761,8 @@
205 "SetWallPlacementPreview": 1,
206 "GetFoundationSnapData": 1,
207 "PlaySound": 1,
208+ "FindUnitsByClass": 1,
209+ "FindUnitsByGenericName": 1,
210 "FindIdleUnits": 1,
211 "GetTradingRouteGain": 1,
212 "GetTradingDetails": 1,
213Index: binaries/data/mods/public/simulation/templates/structures/brit_kennel.xml
214===================================================================
215--- binaries/data/mods/public/simulation/templates/structures/brit_kennel.xml (revision 13339)
216+++ binaries/data/mods/public/simulation/templates/structures/brit_kennel.xml (working copy)
217@@ -29,7 +29,7 @@
218 </Health>
219 <Identity>
220 <Civ>brit</Civ>
221- <GenericName>Special Building</GenericName>
222+ <GenericName>Kennel</GenericName>
223 <SpecificName>Kennel</SpecificName>
224 <Tooltip>Train Celtic war dogs.</Tooltip>
225 <Icon>structures/kennel.png</Icon>