66import arc .scene .ui .layout .*;
77import arc .util .*;
88import mindustry .*;
9+ import mindustry .ai .types .*;
910import mindustry .gen .*;
1011import mindustry .type .*;
11- import mindustry .ai .*;
12- import mindustry .ai .types .*;
1312import omaloon .annotations .Annotations .*;
1413import omaloon .gen .*;
1514import omaloon .type .*;
@@ -202,40 +201,6 @@ public void splitTop(){
202201 }
203202 }
204203
205- // TODO please move this to updateChained(), makes it easier to alter its behaviour if we want for other entities.
206- @ Override
207- public void update (){
208- if (head != null && head != self () && !dead &&
209- ((Unit )self ()).controller () instanceof CommandAI ai &&
210- head instanceof Unit u && u .controller () instanceof CommandAI hai &&
211- ai .hasCommand ()){
212-
213- if (hai .command != ai .command ){
214- hai .command (ai .command );
215- }
216-
217- if (ai .attackTarget != null ){
218- if (hai .attackTarget != ai .attackTarget ){
219- hai .commandTarget (ai .attackTarget );
220- }
221- }else if (ai .targetPos != null ){
222- if (u .within (ai .targetPos , Math .max (u .hitSize () / 2f , 5f ))){
223- ai .clearCommands ();
224- ai .command (null );
225- }else if (!hai .hasCommand () || !ai .targetPos .equals (hai .targetPos )){
226- hai .commandPosition (ai .targetPos );
227- }
228- }
229- }
230-
231- if (!Vars .net .client () && head != null && head .type () instanceof GlasmoreUnitType headType ){
232- if (headType .killSmallChains && chainLength () < headType .segmentUnits ){
233- if (dead ) Call .unitDestroy (id ());
234- else Call .unitDespawn (self ());
235- }
236- }
237- }
238-
239204 @ Replace
240205 public void rotateMove (Vec2 vec ){
241206 if (head != null && head != self ()){
@@ -261,6 +226,43 @@ public void moveAt(Vec2 vec){
261226
262227 @ Insert ("update()" )
263228 public void updateChain (){
229+ if (head != null && head != self () && !dead ){
230+ if (((Unit )self ()).controller () instanceof CommandAI ai &&
231+ head instanceof Unit u && u .controller () instanceof CommandAI hai &&
232+ ai .hasCommand ()){
233+
234+ if (hai .command != ai .command ){
235+ hai .command (ai .command );
236+ }
237+
238+ if (ai .attackTarget != null ){
239+ if (hai .attackTarget != ai .attackTarget ){
240+ hai .commandTarget (ai .attackTarget );
241+ }
242+ }else if (ai .targetPos != null ){
243+ if (u .within (ai .targetPos , Math .max (u .hitSize () / 2f , 5f ))){
244+ ai .clearCommands ();
245+ ai .command (null );
246+ }else if (!hai .hasCommand () || !ai .targetPos .equals (hai .targetPos )){
247+ hai .commandPosition (ai .targetPos );
248+ }
249+ }
250+ }
251+
252+ if (((Unit )self ()).isPlayer () && head instanceof Unit u && u .controller () instanceof CommandAI hai ){
253+ if (hai .hasCommand ()) hai .command (null );
254+ hai .targetPos = null ;
255+ hai .attackTarget = null ;
256+ }
257+ }
258+
259+ if (!Vars .net .client () && head != null && head .type () instanceof GlasmoreUnitType headType ){
260+ if (headType .killSmallChains && chainLength () < headType .segmentUnits ){
261+ if (dead ) Call .unitDestroy (id ());
262+ else Call .unitDespawn (self ());
263+ }
264+ }
265+
264266 if (parent != null && self () instanceof Mechc && !type .omniMovement ) baseRotation = rotation ();
265267
266268 if (head != self () || child == null || !(type instanceof GlasmoreUnitType g )) return ;
@@ -281,4 +283,10 @@ public void updateChain(){
281283 s .segment (p .segment () + 1 );
282284 }
283285 }
286+
287+ @ Replace
288+ public boolean isLocal (){
289+ if (head != null && head != self () && head .controller () == Vars .player ) return true ;
290+ return ((Unitc )self ()).controller () == Vars .player ;
291+ }
284292}
0 commit comments