From fe44791e2446d274a8251a1e83c2c6c1d967d156 Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Fri, 13 Sep 2024 19:59:10 -0500 Subject: [PATCH 01/27] proof of concept complete --- scripts/Units/armguard.bos | 29 +++++++++--------- scripts/Units/armguard.cob | Bin 3998 -> 3306 bytes .../LandDefenceOffence/armguard.lua | 8 ++--- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index d4146a604f5..614f41e9bd1 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -5,11 +5,10 @@ piece flare1, flare2, base, turret, barrel1, barrel2, sleeves; -static-var nextBarrel, trajectoryMode, lastHeading; +static-var nextBarrel, trajectoryMode, lastHeading, aimingLow; #define SIGNAL_AIM 1 -#define LOW_TRAJECTORY 0 -#define HIGH_TRAJECTORY 1 +#define SIGNAL_RESET_DELAY 2 Create() @@ -31,6 +30,7 @@ Create() dont-shade sleeves; dont-shade turret; nextBarrel = 0; + aimingLow = 0; } #define SMOKEPIECE base @@ -44,13 +44,11 @@ RequestState(requestedState) Activate() { signal SIGNAL_AIM; - start-script RequestState(HIGH_TRAJECTORY); } Deactivate() { signal SIGNAL_AIM; - start-script RequestState(LOW_TRAJECTORY); } restoreAfterDelay() @@ -80,6 +78,14 @@ restoreAfterDelay() turn sleeves to x-axis <0.000000> speed <45.000000>; } +resetHighLowAim() +{ + signal SIGNAL_RESET_DELAY; + set-signal-mask SIGNAL_RESET_DELAY; + sleep 200; + aimingLow = 0; +} + aimCommon(heading, pitch) { turn turret to y-axis heading speed <30.000000>; @@ -92,11 +98,8 @@ aimCommon(heading, pitch) AimPrimary(heading, pitch) { - if( trajectoryMode != LOW_TRAJECTORY ) - { - return(0); - } - + aimingLow = 1; + start-script resetHighLowAim(); signal SIGNAL_AIM; set-signal-mask SIGNAL_AIM; call-script aimCommon(heading, pitch); @@ -108,15 +111,13 @@ AimPrimary(heading, pitch) { return(0); } - return (1); } AimSecondary(heading, pitch) { - if( trajectoryMode != HIGH_TRAJECTORY ) - { - return(0); + if (aimingLow == 1){ + return (0); } signal SIGNAL_AIM; diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index a7f4bc7dd8be7cdf5ee32215319eab6cecde231a..42950622af53eb733066821e0bec3f84e3505bf1 100644 GIT binary patch literal 3306 zcmb7GO^6&t6t3y)c2`6~%lduHz5Hkk7h}-VgYU|9-rl&W{fWbKg z5fl+o@u0Hc!5=*6NiPx)L4@@b5Y$r?!JCR0{6VsQ-|P3bYn!wt8$MoDz4yNN)vKzW z%sA%`0{eka66a=N`8Ri?bB_S;0e4}30oE-!PakbZ?VkBm{jlPPonZj1@WQ4#-$#2% z<6$KpR^nkL9#-OE8Q<}V)Su~9HlD|RcOvz!n|S(fVV&-bcT1_ir@_Hm#=#tpt9_+@ zqCU}s{6uReh=EJ;j&RVM74DO|mdRR2xHzQNW}TQr__hWV5gY-^v$aB2fd$c#nJ=mGYy>4n@4DW;M;?Cnt zOqb=dj_B~6svcu8wm9B78}IH9d!Y`~LVnZBczy@@$9So&`;{^FYqe`_sh>l<=m0PC zo+AOi862NgF8WPF)4CqMPk6I@^Nb_6@GYf2Lt%@zHz``8eejN2zbjw$4%gdquVYWF z9oOTWJ+<#stj&7b=BG}iM*FFBeqcKJF~N6gH|F!dcHBqRZ-Vu2h0b2}{d3c#=0XRV z&bYWv+>Z;5I`oNtt;64(YpG*#R>y74dfp+V*Lvi9QqRv1|MvE&Z5`j!mLC0R+QDVL zk7MI~{-Uv5v)H}$+v{ApjygA>S>*k%I`p%rZ8~^o_zxk%bsGoW>Rudf@Uss2wix60 z3vWEPH(-9=L;By;c%EAv-{iC3GRtQgwK0xwFV-o)#j5iu)oJ@|@^YPZ&yfeZO{eKH zo#r>4Ha9+tH=X7uZJW+zI#uVZs+0A39>%-Hn5dst$8^4=e$)B3&Q0fwIyXL>n@*cE zEY``M{GXQBmD{vfZPQ|Y(_((pVsq1C^QIQg?*yI!UIX3&-T~eRc7U5fI1j7OC&THDFfRKgLl&0H z{0s-jLT1AP-cb=2R?AQv3xjOpuoBAS`4dk*Fxp(mhc3&9M@PdU$S^xmF0)x-esM15e+}i}U8yrcgSo zQa2ShN_Sl}J3-N<3+={@8x_HYAO$zBL_zQeHGbc{_q@3o-XwWV`8fC9^PS&&?j&uA z$O142ym3UN1<9Z99u`R-5$OR>VSf`+Rwbd1a>mO&`_k(ntsc_)gPbK1GWHUoMDBY& zq~$|eKBVPCT0SKCGf8CQx7tqXURL5n(kS8nG5SqgiLA!SGc}vg2W`lAb;QZYb8URs zM?OXb4qcLanv3?V_5FfB%k0^V^~EJ~tH%j_SpSLhamoAO*`#<&bl5(UNZa{muH!rs zcd`}S4}96UAW`4MwdW07#?=|Qa18xcKdGNB@B6r8;+1u~tbN6;=Qu%T7@srPqI-PaBS8}07 zOvnAjb9tuR%Ab3up)F0-_TMSu%wsq-c2gYcIYUi)zES>T3gkY{Me6E!rRJaYkdt~@ zLdq)MWimIO(-cSKl#r^^-&ZM)>NAW4rUi(b0-mTh~ z-WO+7Ydwgk{XK|B*J016?dzm^8GBOh^}bHqqy2i^6jS>;DbK^)i}w3L?e!iW)V_W{ z+@A!l0Pg{}fxEy*z_-905-NtK`h8HByZx2C+t2cCE<0vzu(|Fx z=kh_Q!2~DqZJoV~Wn!ppf(3 mUeBz{MlZ|Fq7zH Date: Tue, 22 Oct 2024 21:53:38 -0500 Subject: [PATCH 02/27] gauntlet and agitator done --- scripts/Units/armguard.bos | 53 +++++++++++++++--- scripts/Units/armguard.cob | Bin 3306 -> 3792 bytes .../LandDefenceOffence/armguard.lua | 23 ++++---- .../LandDefenceOffence/corpun.lua | 22 ++++---- 4 files changed, 66 insertions(+), 32 deletions(-) diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index 614f41e9bd1..a65a5a40909 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -5,7 +5,7 @@ piece flare1, flare2, base, turret, barrel1, barrel2, sleeves; -static-var nextBarrel, trajectoryMode, lastHeading, aimingLow; +static-var nextBarrel, trajectoryMode, lastHeading, aimingState, resetHighFrame, delayFrames; #define SIGNAL_AIM 1 #define SIGNAL_RESET_DELAY 2 @@ -30,7 +30,9 @@ Create() dont-shade sleeves; dont-shade turret; nextBarrel = 0; - aimingLow = 0; + aimingState = 0; + resetHighFrame = 0; + delayFrames = 450; } #define SMOKEPIECE base @@ -78,14 +80,32 @@ restoreAfterDelay() turn sleeves to x-axis <0.000000> speed <45.000000>; } -resetHighLowAim() +resetStateLow() { signal SIGNAL_RESET_DELAY; + get PRINT(aimingState, 7777); set-signal-mask SIGNAL_RESET_DELAY; - sleep 200; - aimingLow = 0; + get PRINT(aimingState, 8888); + sleep 1000; + get PRINT(aimingState, 9999); + aimingState = 0; + get PRINT(aimingState, 11112); } +// resetStateHigh() +// { +// signal SIGNAL_RESET_DELAY; +// get PRINT(aimingState, 1111); +// sleep 3000; +// get PRINT(aimingState, 2222); +// aimingState = 0; +// get PRINT(aimingState, 3333); +// set-signal-mask SIGNAL_RESET_DELAY; +// get PRINT(aimingState, 4444); +// sleep 50; +// get PRINT(aimingState, 5555); +// } + aimCommon(heading, pitch) { turn turret to y-axis heading speed <30.000000>; @@ -98,8 +118,11 @@ aimCommon(heading, pitch) AimPrimary(heading, pitch) { - aimingLow = 1; - start-script resetHighLowAim(); + if (aimingState == 2){ + return (0); + } + aimingState = 1; + start-script resetStateLow(); signal SIGNAL_AIM; set-signal-mask SIGNAL_AIM; call-script aimCommon(heading, pitch); @@ -116,12 +139,24 @@ AimPrimary(heading, pitch) AimSecondary(heading, pitch) { - if (aimingLow == 1){ + + if (aimingState == 1){ return (0); } - + var frame; + frame = (get GAME_FRAME); + get PRINT(aimingState, 9690, frame, resetHighFrame); + if (aimingState == 2 && frame > resetHighFrame){ + aimingState = 0; + return (0); + } + if (aimingState != 2){ + resetHighFrame = frame + delayFrames; + } + aimingState = 2; signal SIGNAL_AIM; set-signal-mask SIGNAL_AIM; + call-script aimCommon(heading, pitch); return (1); } diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index 42950622af53eb733066821e0bec3f84e3505bf1..30b790ebcd15bad32000449b366d61cb23fecd3c 100644 GIT binary patch delta 1023 zcmaKrO-NKx6vywm@4Y)8jpLQE#z&-*g)j+Cw2+Ww+VlYfO|=+kQA&(d2+e?0P&7(1 zD-DOUC?bOhi)=RLMuZ@Quy#QZ5kw9|goL?_DCmFR%+#Rf;&Ee%2V1b0N<5D}ElMzlSySNl;O2C7()cANt z#YNd-_bENXF72h$e2lh};tX|ChR5kRUE_}wb@Nr3L`<mj)LId7TZ@F$X6@BBjQE(Z)z0nQT>I4|iBr8c^EYv0=jLKay#{NAu1$V^ z&;RwD^*3|Y9&_tE^*Tv8THt&x^8+W!wsVgjV%8&{5%;QX`GQH>4iPrixNp?-huuQJ z>e)?rbCYTtwo$tEz9=DEDdRm(v9{?r%;I9x(RCsEDz0DPS|7?WX|<)z9WW)-&dRLK zmhm^|j@%`=pax{GGT6bJC%d;NBt*&Xv2Yivs-gh9AwMi>9kVY`F}Aqm1d1PNlTpe7we*vNxI z;KlV@(7`|`SY7BK9g4t0SW4LrAtdF^2!ak3K?GstceWk){O0}Uy*F=u%-bVh(iv-v zX{0)Os>Z~4k1ju9%q3c)6Wo^*g-i(x>KAt1flfXUr!FeAr_@=j=plR6bCc+jcDaC@ z92SciIWAZ5SkB8${E<|8qSmIu;Ja}gXH3>}oor7ctKq@vT1AvFeV(%%Vlkk}^n5K7 zwN^()70z>lwO9&|G%u?-y01ejxXkqf3S2*9gX>R-?XR!SnqocQxQ=m2B46jQs207k zIrPOWd~Z<)1Wl5{n%As1{)a7ID|~-YOM+2 Date: Tue, 22 Oct 2024 22:01:37 -0500 Subject: [PATCH 03/27] code cleanup, adjust low weapon delay --- scripts/Units/armguard.bos | 25 +++---------------------- scripts/Units/armguard.cob | Bin 3792 -> 3549 bytes 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index a65a5a40909..abe80a36d82 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -80,32 +80,14 @@ restoreAfterDelay() turn sleeves to x-axis <0.000000> speed <45.000000>; } -resetStateLow() +resetState() { signal SIGNAL_RESET_DELAY; - get PRINT(aimingState, 7777); set-signal-mask SIGNAL_RESET_DELAY; - get PRINT(aimingState, 8888); - sleep 1000; - get PRINT(aimingState, 9999); + sleep 250; aimingState = 0; - get PRINT(aimingState, 11112); } -// resetStateHigh() -// { -// signal SIGNAL_RESET_DELAY; -// get PRINT(aimingState, 1111); -// sleep 3000; -// get PRINT(aimingState, 2222); -// aimingState = 0; -// get PRINT(aimingState, 3333); -// set-signal-mask SIGNAL_RESET_DELAY; -// get PRINT(aimingState, 4444); -// sleep 50; -// get PRINT(aimingState, 5555); -// } - aimCommon(heading, pitch) { turn turret to y-axis heading speed <30.000000>; @@ -122,7 +104,7 @@ AimPrimary(heading, pitch) return (0); } aimingState = 1; - start-script resetStateLow(); + start-script resetState(); signal SIGNAL_AIM; set-signal-mask SIGNAL_AIM; call-script aimCommon(heading, pitch); @@ -145,7 +127,6 @@ AimSecondary(heading, pitch) } var frame; frame = (get GAME_FRAME); - get PRINT(aimingState, 9690, frame, resetHighFrame); if (aimingState == 2 && frame > resetHighFrame){ aimingState = 0; return (0); diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index 30b790ebcd15bad32000449b366d61cb23fecd3c..efb9e1bde1bc9ed202383716631e4508601c412d 100644 GIT binary patch delta 350 zcmXBPAxHyp6vy%R{+xHa+npRJyD$`VL71DYiSx1!F^EkticL`jlS~mzCiyj4SWq@* zQj<6bBDypYVS>S^*i4ose`@&fz7Jmb|DT55(pgJH2Fams^FNs)zQ_VqDaW^LE+#=?AG-OMP4H3i?Un62N8aBF9DAMf@UVyB=LtT~g~z^T(V zpNjRwsv2|?*E)(LcU<$hai=x@>sfXNB`?-84!oMykx$mlv$=dp7IimLks@tViyr8a zJiafa6cuQW7OBZ!+);;K>4UzgM}8m@(Fo;eib}LZE3`pnI;3Md2_!9Nj0?J=7Tr^a Mx&a!>i?54+Skn+5i9m delta 592 zcmaLUJxD@P6bJBgudk;*^z{a@K{CihPzjrYtZ=I3Ew$7TK?G3|L`yZ43PD>D9HJ$H zh;nf;3B(B6tRZNM2%@DVnwq1b|5YjxYWQ)^;obAj{df%AwnsH0@_`e29QBBl-aSMq zFVPOfQRlsdXt$ObL8@8O!b%c|Q^9&fS*ul~gl17nTI#!0bylzC&Ap}0-yXGAEp6<5 zRYMY@u{ZoPxHa;3GiP;Qym{Je?4O1;tt6KP2Zf*QmVJ4o(l!=)NStz5k6;thYX0Fv zmfozc|muBp Date: Tue, 29 Oct 2024 21:44:21 -0500 Subject: [PATCH 04/27] rewrite using all gameframe timing not signals --- scripts/Units/armguard.bos | 104 ++++++++++++++++++------------------- scripts/Units/armguard.cob | Bin 3549 -> 3556 bytes 2 files changed, 52 insertions(+), 52 deletions(-) diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index abe80a36d82..70a3ca72f4d 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -5,10 +5,14 @@ piece flare1, flare2, base, turret, barrel1, barrel2, sleeves; -static-var nextBarrel, trajectoryMode, lastHeading, aimingState, resetHighFrame, delayFrames; +static-var nextBarrel, trajectoryMode, lastHeading, aimingState, switchAimModeFrame; -#define SIGNAL_AIM 1 -#define SIGNAL_RESET_DELAY 2 +#define SIGNAL_AIM 1 +#define RESET_HIGH_DELAY_FRAMES 450 +#define RESET_LOW_DELAY_FRAMES 30 +#define AIMING_NEITHER 0 +#define AIMING_LOW 1 +#define AIMING_HIGH 2 Create() @@ -30,33 +34,57 @@ Create() dont-shade sleeves; dont-shade turret; nextBarrel = 0; - aimingState = 0; - resetHighFrame = 0; - delayFrames = 450; + + //smasel declare default values for smart select + aimingState = AIMING_NEITHER; + switchAimModeFrame = 0; } #define SMOKEPIECE base #include "smokeunit_thread_nohit.h" -RequestState(requestedState) +smartAimSelect(weaponNumber) { - trajectoryMode = requestedstate; -} + var gameFrame; + gameFrame = (get GAME_FRAME); -Activate() -{ - signal SIGNAL_AIM; -} + //smasel i'm gonna have to put the framechecks here just in case an invalid target + if (switchAimModeFrame < gameFrame){ + aimingState = AIMING_NEITHER; + } -Deactivate() -{ - signal SIGNAL_AIM; + //smasel block if another weapon is firing + if (aimingState != AIMING_NEITHER && weaponNumber != aimingState){ + return (0); + } + + //smasel stop bonus shots + if ((weaponNumber == AIMING_HIGH) && (gameFrame < (get WEAPON_RELOADSTATE(AIMING_LOW)))){ + return (0); + } else if ((weaponNumber == AIMING_LOW) && (gameFrame < (get WEAPON_RELOADSTATE(AIMING_HIGH)))){ + return (0); + } + + //smasel if aimingState is neither, set aimingState and its expiration + if (weaponNumber == AIMING_NEITHER){ + aimingState = weaponNumber; + if (weaponNumber == AIMING_LOW){ + switchAimModeFrame = (gameFrame + RESET_LOW_DELAY_FRAMES); + } else if (weaponNumber == AIMING_HIGH){ + switchAimModeFrame = (gameFrame + RESET_HIGH_DELAY_FRAMES); + } + } + + if(weaponNumber == aimingState){ + return (1); + } } restoreAfterDelay() { set-signal-mask SIGNAL_AIM; sleep 3500; + aimingState = AIMING_NEITHER; if(lastHeading > <-180.000000>) { turn turret to y-axis <180.000000> speed <30.000000>; @@ -80,14 +108,6 @@ restoreAfterDelay() turn sleeves to x-axis <0.000000> speed <45.000000>; } -resetState() -{ - signal SIGNAL_RESET_DELAY; - set-signal-mask SIGNAL_RESET_DELAY; - sleep 250; - aimingState = 0; -} - aimCommon(heading, pitch) { turn turret to y-axis heading speed <30.000000>; @@ -100,45 +120,25 @@ aimCommon(heading, pitch) AimPrimary(heading, pitch) { - if (aimingState == 2){ - return (0); - } - aimingState = 1; - start-script resetState(); signal SIGNAL_AIM; set-signal-mask SIGNAL_AIM; call-script aimCommon(heading, pitch); + + start-script smartAimSelect(AIMING_LOW); - // Prevent low-trajectory "bonus shots" while high-trajectory is reloading - var reloading; - reloading = (get GAME_FRAME) < (get WEAPON_RELOADSTATE(2)); - if( reloading ) - { - return(0); - } return (1); } AimSecondary(heading, pitch) { - - if (aimingState == 1){ - return (0); - } - var frame; - frame = (get GAME_FRAME); - if (aimingState == 2 && frame > resetHighFrame){ - aimingState = 0; - return (0); - } - if (aimingState != 2){ - resetHighFrame = frame + delayFrames; - } - aimingState = 2; + + signal SIGNAL_AIM; set-signal-mask SIGNAL_AIM; - call-script aimCommon(heading, pitch); + + start-script smartAimSelect(AIMING_HIGH); + return (1); } @@ -257,4 +257,4 @@ Killed(severity, corpsetype) explode barrel1 type EXPLODE_ON_HIT | FIRE | SMOKE | FALL | NOHEATCLOUD; explode flare1 type EXPLODE_ON_HIT | FIRE | SMOKE | FALL | NOHEATCLOUD; return corpsetype; -} +} \ No newline at end of file diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index efb9e1bde1bc9ed202383716631e4508601c412d..eabc24b0b3a2c67eab0d5e022f2687575c1b3e55 100644 GIT binary patch delta 1049 zcmZ9LO=uHQ5XaxV>~7PLzza)kLm*9C#MTd55d?L`21Eo8tq4UuCA3kBEovGlqM`9n z@t|NkD0d8U{i+IwWyjbdgHoGAh_+{qJ`_IRFyStY8p6Rue zQc2JPtcX$$to*#VQZ?`v?8SP0ws)By>iFzmlk~7AqmAgSer;@C((P8kF;zZ9eKgEt zlp&jEXcrav84c1DZ&6$NdXT0G&TnP3Z;}~MHGknjorf*3khYSqltB@;))3CBu#x@EwF2Zdd9%ok4M{F2Z1sjpzfWe-` z)RlUTSIt_?2`$8Y+HsT8O3G9NOT1)vdtu_2{}Sc+zYq(XNv1#SP<;UL`KjHX4hx95 zF{O0o&1hS?9lEfD+>V^ZUvtuN_r-!;DJHpDSY;wclyXBdM56+C+HO8vg&A+eY07By zLN)27Fs|Hf7j*s+_^0mJ9nKj}B)2TjT;kE%_O|M;XB{T)iX7A@iO<6f6VJhn5`Tax z6Km@PKhYN7u_|PRkDEvBo=zLZ!h$lPyb%6l44M$%v|Lf9o0a}+7b-c`a*_UU75_=z zXqluKI;0|wiSgBFAMNM)=pOQTHF|_j`Tj8cZa&-U(OtgZx;&%p|K4c>u|;1l@DEAd=za-vwSqU`1Qdl9N)<1*^;9o5=vIWH{YVQ%Y@&!4 zdoawcw9ZMs$MFnCt^#9D_5 z)fQC^JsCZdfe~Aa=AFKk=hhDSVkOlY$!{yKK9C#?=G9k{A(#!4J1~DpJ_UPP%>}#x zP~)FpuK8P1;Fijph|DN0`|M#%bycNyTaX0mlX=qKpr%1v_pof|c+3oH!lZ3&wrYOz z$j&AmI9`5Qd97}mNZQh}5Xi+9R3>OH=Ov-wxG9(@_1c;sF*LR|OQCw}>p1wYg6jF^ z?6>f%H|qV-{f;JPz6Q$SIwQ3!&7p2(B`I?ur~AJv57y!j5O356ja~<|*@3C$Z`9w3 z*+bCVgY<)tlu4- uaL0?Mi-n>~UFV7yCymqX7JPRM(aU3Q*HFvo3=Q-mjOO(3n&*M9*xgPKnO From abd4295c558b0372c02fbc8ec4fffdd064e866d7 Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Fri, 1 Nov 2024 21:35:27 -0500 Subject: [PATCH 05/27] rewrite complete, it works better now --- scripts/Units/armguard.bos | 93 +++++++++++++++++++++++++------------ scripts/Units/armguard.cob | Bin 3556 -> 3780 bytes 2 files changed, 63 insertions(+), 30 deletions(-) diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index 70a3ca72f4d..6e9db5e6654 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -5,14 +5,15 @@ piece flare1, flare2, base, turret, barrel1, barrel2, sleeves; -static-var nextBarrel, trajectoryMode, lastHeading, aimingState, switchAimModeFrame; +static-var nextBarrel, trajectoryMode, lastHeading, aimingState, switchAimModeFrame, queueLowFrame, errorTriggerFrame, weaponToCheck, debugGameFrame; -#define SIGNAL_AIM 1 -#define RESET_HIGH_DELAY_FRAMES 450 -#define RESET_LOW_DELAY_FRAMES 30 -#define AIMING_NEITHER 0 -#define AIMING_LOW 1 -#define AIMING_HIGH 2 +#define SIGNAL_AIM 1 +#define RESET_LOW_DELAY_FRAMES 30 +#define RESET_HIGH_DELAY_FRAMES 450 +#define RESET_ERROR_DELAY_FRAMES 1350 +#define AIMING_NEITHER 0 +#define AIMING_LOW 1 +#define AIMING_HIGH 2 Create() @@ -34,50 +35,75 @@ Create() dont-shade sleeves; dont-shade turret; nextBarrel = 0; + weaponToCheck = AIMING_LOW; + //start-script debugTimer(); //smasel declare default values for smart select aimingState = AIMING_NEITHER; - switchAimModeFrame = 0; + switchAimModeFrame = 302; } #define SMOKEPIECE base #include "smokeunit_thread_nohit.h" +//smasel WATCH THE FORT, I'll remove this when debugging is complete. +// debugTimer(){ +// while (TRUE){ +// debugGameFrame = get GAME_FRAME; +// get PRINT(debugGameFrame, switchAimModeFrame, aimingState, queueLowFrame); +// sleep 1000; +// } +// } + smartAimSelect(weaponNumber) { + if (weaponToCheck == AIMING_HIGH){ + weaponToCheck = AIMING_LOW; + } else{ + weaponToCheck = AIMING_HIGH; + } + var gameFrame; gameFrame = (get GAME_FRAME); + //smasel queue low trajectory steal + if (weaponNumber == AIMING_LOW){ + queueLowFrame = (switchAimModeFrame + RESET_LOW_DELAY_FRAMES); + } + //smasel i'm gonna have to put the framechecks here just in case an invalid target if (switchAimModeFrame < gameFrame){ aimingState = AIMING_NEITHER; } //smasel block if another weapon is firing - if (aimingState != AIMING_NEITHER && weaponNumber != aimingState){ - return (0); - } - - //smasel stop bonus shots - if ((weaponNumber == AIMING_HIGH) && (gameFrame < (get WEAPON_RELOADSTATE(AIMING_LOW)))){ - return (0); - } else if ((weaponNumber == AIMING_LOW) && (gameFrame < (get WEAPON_RELOADSTATE(AIMING_HIGH)))){ + if ((aimingState != AIMING_NEITHER) && (weaponNumber != aimingState)){ return (0); } //smasel if aimingState is neither, set aimingState and its expiration - if (weaponNumber == AIMING_NEITHER){ - aimingState = weaponNumber; + if (aimingState == AIMING_NEITHER){ + + //stop bonus shots + var lowReloadState, highReloadState; + lowReloadState = (get WEAPON_RELOADSTATE(AIMING_LOW)); + highReloadState = (get WEAPON_RELOADSTATE(AIMING_HIGH)); + if (weaponNumber == AIMING_LOW){ switchAimModeFrame = (gameFrame + RESET_LOW_DELAY_FRAMES); - } else if (weaponNumber == AIMING_HIGH){ + aimingState = AIMING_LOW; + if (switchAimModeFrame < highReloadState){ + switchAimModeFrame = highReloadState; + } + } else if ((weaponNumber == AIMING_HIGH) && (queueLowFrame < gameFrame)){ switchAimModeFrame = (gameFrame + RESET_HIGH_DELAY_FRAMES); + if (switchAimModeFrame < lowReloadState){ + switchAimModeFrame = lowReloadState; + } + aimingState = AIMING_HIGH; } - } - - if(weaponNumber == aimingState){ - return (1); - } + return (0); + } } restoreAfterDelay() @@ -120,24 +146,31 @@ aimCommon(heading, pitch) AimPrimary(heading, pitch) { + start-script smartAimSelect(AIMING_LOW); + if (aimingState != AIMING_LOW){ + return(0); + } + signal SIGNAL_AIM; set-signal-mask SIGNAL_AIM; + call-script aimCommon(heading, pitch); - - start-script smartAimSelect(AIMING_LOW); return (1); } AimSecondary(heading, pitch) { - - + start-script smartAimSelect(AIMING_HIGH); + if (aimingState != AIMING_HIGH){ + return (0); + } signal SIGNAL_AIM; set-signal-mask SIGNAL_AIM; - call-script aimCommon(heading, pitch); - start-script smartAimSelect(AIMING_HIGH); + + + call-script aimCommon(heading, pitch); return (1); } diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index eabc24b0b3a2c67eab0d5e022f2687575c1b3e55..003ebf47439069021f7e8097690e731ae54c351a 100644 GIT binary patch delta 931 zcmZ9LO=uHQ5XaxV{mQo4@IsI@u4y9bp*1y%gM~m z#5ho>5a>ZEVnsnOenF)cZ$d$j?Wsq_UJ9PX|7><4xbS=L&71$sn|Zst9)2kf+e)b{ z@W25}sXol|YzvfXf~TMYdogGa&kPY(_Fip7O-36`k&VE}-UEU7ZJzYy2ZaJUzm#Hw4Au1jFtp7*VMSEOZ0%-UJj8B zohv+vl}Ty7D2;1~U#7xSNug2vNyn(BYhL^pAsWg3D&7}u(xfVDBaPk_P1!aY%@Jqq zu(%{Dc;o^_F(?XS8HsfGxent8 zdoa$MTtw2MZhy}400sQX9;0)-iSZJTIAe5^TNv+g2jdL?aMpL>1w`Kjj+IlQby7#O zTf=wa4CVQqJIWKD#|v(X4|`^7uRJO$mT&gT&+4k?_ud6M#@kaL=pwJCcGESU^mlN@ zAE4Wj{SfwfTILmho__OxjscNNKWR(mvUe}L?=5fx|u^7i#g?Gd;9_nF!PIR`)h2DgZeksar9Fwv% za7Bud-&J5ElfyI7(!>jykQuZk-*j)=5m2o(zT41UeaY}Lz*TbCnXgayw^E*l_ zv=(e%WddVkw9*CCQr@Avc5$y~910R4J=>Ey9Br(OZ`5>P7EyOkMN3>r%v)=nttWjd zJ6e2nhX;~^Yn`HRUAb*E85rwx3vDOwCneZ+%e#8@TU~u}^82CA7U;ohZ3BA-m(@i{ zW85nZ*lxXfYb?19TC$c4SflEHHM9I`^wG)gV`p0-IN_g`lWqLv0Vk)!XZLkj>>H`?mfA5spt3@6Y>+cqMO5Tvq Date: Fri, 1 Nov 2024 21:44:14 -0500 Subject: [PATCH 06/27] reduce delay swithcing to high --- scripts/Units/armguard.bos | 2 +- scripts/Units/armguard.cob | Bin 3780 -> 3780 bytes .../LandDefenceOffence/corpun.lua | 2 -- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index 6e9db5e6654..7e9affd2c0b 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -8,7 +8,7 @@ piece flare1, flare2, base, turret, barrel1, barrel2, sleeves; static-var nextBarrel, trajectoryMode, lastHeading, aimingState, switchAimModeFrame, queueLowFrame, errorTriggerFrame, weaponToCheck, debugGameFrame; #define SIGNAL_AIM 1 -#define RESET_LOW_DELAY_FRAMES 30 +#define RESET_LOW_DELAY_FRAMES 10 #define RESET_HIGH_DELAY_FRAMES 450 #define RESET_ERROR_DELAY_FRAMES 1350 #define AIMING_NEITHER 0 diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index 003ebf47439069021f7e8097690e731ae54c351a..aba40e50724e30be271e94c3ce33161122ea6648 100644 GIT binary patch delta 21 bcmX>idqj4F1~VhqW=&>&Mj#c*lFbDGL-qwo delta 21 bcmX>idqj4F1~a4FW=&>&Mj#c*lFbDGMREmj diff --git a/units/CorBuildings/LandDefenceOffence/corpun.lua b/units/CorBuildings/LandDefenceOffence/corpun.lua index 7b8f2534bb3..72602024961 100644 --- a/units/CorBuildings/LandDefenceOffence/corpun.lua +++ b/units/CorBuildings/LandDefenceOffence/corpun.lua @@ -23,7 +23,6 @@ return { metalcost = 1300, nochasecategory = "MOBILE", objectname = "Units/CORPUN.s3o", - onoffable = true, script = "Units/armguard.cob", seismicsignature = 0, selfdestructas = "largeBuildingExplosionGenericSelfd", @@ -36,7 +35,6 @@ return { buildinggrounddecaltype = "decals/corpun_aoplane.dds", model_author = "Mr Bob", normaltex = "unittextures/cor_normal.dds", - onoffname = "trajectory", subfolder = "CorBuildings/LandDefenceOffence", unitgroup = "weapon", usebuildinggrounddecal = true, From 70281544adc9e2811d6bd030afbad1c3f6ead5fe Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Fri, 1 Nov 2024 21:44:31 -0500 Subject: [PATCH 07/27] remove high trajectory toggle --- units/ArmBuildings/LandDefenceOffence/armguard.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/units/ArmBuildings/LandDefenceOffence/armguard.lua b/units/ArmBuildings/LandDefenceOffence/armguard.lua index ea425cfc82c..de5a1fe71c1 100644 --- a/units/ArmBuildings/LandDefenceOffence/armguard.lua +++ b/units/ArmBuildings/LandDefenceOffence/armguard.lua @@ -23,7 +23,6 @@ return { metalcost = 1250, nochasecategory = "MOBILE", objectname = "Units/ARMGUARD.s3o", - onoffable = true, script = "Units/ARMGUARD.cob", seismicsignature = 0, selfdestructas = "mediumBuildingExplosionGenericSelfd", @@ -36,7 +35,6 @@ return { buildinggrounddecaltype = "decals/armguard_aoplane.dds", model_author = "Beherith", normaltex = "unittextures/Arm_normal.dds", - onoffname = "trajectory", subfolder = "ArmBuildings/LandDefenceOffence", unitgroup = "weapon", usebuildinggrounddecal = true, From 2b0623b7e61e9d637753a11268a90cba1fa375c0 Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Fri, 1 Nov 2024 22:28:17 -0500 Subject: [PATCH 08/27] code cleanup --- scripts/Units/armguard.bos | 16 ++-------------- scripts/Units/armguard.cob | Bin 3780 -> 3664 bytes 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index 7e9affd2c0b..1c10fb7b6d8 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -5,12 +5,12 @@ piece flare1, flare2, base, turret, barrel1, barrel2, sleeves; -static-var nextBarrel, trajectoryMode, lastHeading, aimingState, switchAimModeFrame, queueLowFrame, errorTriggerFrame, weaponToCheck, debugGameFrame; +//smasel remove debugGameFrame +static-var nextBarrel, trajectoryMode, lastHeading, aimingState, switchAimModeFrame, queueLowFrame, errorTriggerFrame, debugGameFrame; #define SIGNAL_AIM 1 #define RESET_LOW_DELAY_FRAMES 10 #define RESET_HIGH_DELAY_FRAMES 450 -#define RESET_ERROR_DELAY_FRAMES 1350 #define AIMING_NEITHER 0 #define AIMING_LOW 1 #define AIMING_HIGH 2 @@ -35,12 +35,6 @@ Create() dont-shade sleeves; dont-shade turret; nextBarrel = 0; - weaponToCheck = AIMING_LOW; - //start-script debugTimer(); - - //smasel declare default values for smart select - aimingState = AIMING_NEITHER; - switchAimModeFrame = 302; } #define SMOKEPIECE base @@ -57,12 +51,6 @@ Create() smartAimSelect(weaponNumber) { - if (weaponToCheck == AIMING_HIGH){ - weaponToCheck = AIMING_LOW; - } else{ - weaponToCheck = AIMING_HIGH; - } - var gameFrame; gameFrame = (get GAME_FRAME); diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index aba40e50724e30be271e94c3ce33161122ea6648..a5b086f10ce513b1dac7af4c71e26784f700ebca 100644 GIT binary patch delta 537 zcmXxhK}Zx)90u_B&CKr1uCp?_#VYD9l$A>>ZMd-IX`@31i;H+D1rZMw;z2|MgCHTg z6olIsM5j8rE9gNybdUuFp-YG8k{1u*#Y2bn5O^r*8_|K^|Gkg-zxU=byFK5#vyL&Q zO6y+Pu(}>x8xJX<2#df_L!S3d#tqAnbGUR^YJ*U3kjdxPf6#qbuf} zckowBlAqyYjO(aimj96IoIiVOL6fElEDfd<4GQeHGFalAmxRYDE7|?_tTSvpJt^!A zqCuFs6z^ckb=b7}u)tIwwuSEW;L|)qxS?kBDRGx8?oznz>)Z6 z`tc4tKFxE=lc;keUc(QLwbY!yx*(VRUiSINFRtm+7o{p$-Q%UK$X7X(rW{K_iw316 zG&5-$D& D8%<}r delta 643 zcmZ9}K}Zx)7zgn8fAe-{M|b5dgRD!sDG{<1?ux_`7!3%ZwX>fr3I-i%U{^o&k2-m4ckir~VOwROp`+H#6x*2VD<6WqR$TRN0O-_#G%*{HS2 zDc%g^o#`=?Nn4WuC0vu!ID$Z~Vh~fZfQy)yPsrsLTV>iEdZ?^+^-~@EN%eF}i*-hr89GIxxbNrl339Hz_^Z%+`jyvOJ>%Plvzpu>bGWKO# zSMXVydJNxr{2<1q>aCz(zIo?RkUo>cn4B^r9H&hMXXUB6iyM+nRB%VC9OtCQ@qxVN zxZe1k@PV(g;9rpoei?tb+CfQ1S;gvR+{wrHPzP=Zw%>ZZ#yLDy-P>az-ZrWkAO8S`y=`d# From 472f261b116de2ad17510f2379f22806b5131add Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Sat, 2 Nov 2024 15:50:25 -0500 Subject: [PATCH 09/27] reduce buggy low priority selection --- scripts/Units/armguard.bos | 2 +- scripts/Units/armguard.cob | Bin 3664 -> 3664 bytes 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index 1c10fb7b6d8..7347e5d3d9a 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -9,7 +9,7 @@ piece flare1, flare2, base, turret, barrel1, barrel2, sleeves; static-var nextBarrel, trajectoryMode, lastHeading, aimingState, switchAimModeFrame, queueLowFrame, errorTriggerFrame, debugGameFrame; #define SIGNAL_AIM 1 -#define RESET_LOW_DELAY_FRAMES 10 +#define RESET_LOW_DELAY_FRAMES 20 #define RESET_HIGH_DELAY_FRAMES 450 #define AIMING_NEITHER 0 #define AIMING_LOW 1 diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index a5b086f10ce513b1dac7af4c71e26784f700ebca..a0735630836fa951f0d852a42ed64832c83e0d25 100644 GIT binary patch delta 21 bcmca0b3taq7A8iK&0CrD8G+PO=4>tiS4IaD delta 21 bcmca0b3taq7A8in&0CrD8G+PO=4>tiR)_}w From b3973a5baf8dea8774033ea9799ef26b83e15024 Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Sat, 2 Nov 2024 19:42:15 -0500 Subject: [PATCH 10/27] reloadstate moved inside each individual weapon's if --- scripts/Units/armguard.bos | 10 ++++------ scripts/Units/armguard.cob | Bin 3664 -> 3664 bytes 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index 7347e5d3d9a..7ceba2b1e47 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -71,20 +71,18 @@ smartAimSelect(weaponNumber) //smasel if aimingState is neither, set aimingState and its expiration if (aimingState == AIMING_NEITHER){ - - //stop bonus shots - var lowReloadState, highReloadState; - lowReloadState = (get WEAPON_RELOADSTATE(AIMING_LOW)); - highReloadState = (get WEAPON_RELOADSTATE(AIMING_HIGH)); - if (weaponNumber == AIMING_LOW){ switchAimModeFrame = (gameFrame + RESET_LOW_DELAY_FRAMES); aimingState = AIMING_LOW; + var highReloadState; + highReloadState = (get WEAPON_RELOADSTATE(AIMING_HIGH)); if (switchAimModeFrame < highReloadState){ switchAimModeFrame = highReloadState; } } else if ((weaponNumber == AIMING_HIGH) && (queueLowFrame < gameFrame)){ switchAimModeFrame = (gameFrame + RESET_HIGH_DELAY_FRAMES); + var lowReloadState; + lowReloadState = (get WEAPON_RELOADSTATE(AIMING_LOW)); if (switchAimModeFrame < lowReloadState){ switchAimModeFrame = lowReloadState; } diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index a0735630836fa951f0d852a42ed64832c83e0d25..5e4293b38805d178c235fdaac02949be9faf2560 100644 GIT binary patch delta 91 zcmca0b3tZ<5A)<6CJCmm43n=h>#;B>FbPcVU^Y-?Vqjok5nvKv0n$uB8pLN1U=?6U gU=#QZ6Pv8ck~}$p*<=!n45tz!L?QF$l`P9S0Wi`Jp8x;= delta 71 zcmca0b3tZ<4>Jpc0+Ybx02UJ#CI$wE$upP@7?~$`GD$NrGfqxp)|=eHBEiTwc_EAN a Date: Fri, 15 Nov 2024 21:24:31 -0600 Subject: [PATCH 11/27] optimized high/low errorstate now we don't get random aimstate changes for grids of smartselect turrets. errorstate now works correctly so it switches modes faster. --- scripts/Units/armguard.bos | 77 +++++++++++++++++++++---------------- scripts/Units/armguard.cob | Bin 3664 -> 3931 bytes 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index 7ceba2b1e47..b9fc039fee0 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -6,14 +6,15 @@ piece flare1, flare2, base, turret, barrel1, barrel2, sleeves; //smasel remove debugGameFrame -static-var nextBarrel, trajectoryMode, lastHeading, aimingState, switchAimModeFrame, queueLowFrame, errorTriggerFrame, debugGameFrame; +static-var nextBarrel, trajectoryMode, lastHeading, aimingState, switchAimModeFrame, queueLowFrame, firedLowFailed, debugGameFrame; -#define SIGNAL_AIM 1 -#define RESET_LOW_DELAY_FRAMES 20 -#define RESET_HIGH_DELAY_FRAMES 450 -#define AIMING_NEITHER 0 -#define AIMING_LOW 1 -#define AIMING_HIGH 2 +#define SIGNAL_AIM 1 +#define RESET_LOW_DELAY_FRAMES 20 +#define RESET_HIGH_DELAY_FRAMES 450 +#define RESET_HIGH_ERRORSTATE_FRAMES 900 +#define AIMING_NEITHER 0 +#define AIMING_LOW 1 +#define AIMING_HIGH 2 Create() @@ -35,56 +36,64 @@ Create() dont-shade sleeves; dont-shade turret; nextBarrel = 0; + //start-script debugTimer(); } #define SMOKEPIECE base #include "smokeunit_thread_nohit.h" //smasel WATCH THE FORT, I'll remove this when debugging is complete. -// debugTimer(){ -// while (TRUE){ -// debugGameFrame = get GAME_FRAME; -// get PRINT(debugGameFrame, switchAimModeFrame, aimingState, queueLowFrame); -// sleep 1000; -// } -// } +debugTimer(){ + while (TRUE){ + debugGameFrame = get GAME_FRAME; + get PRINT(debugGameFrame, switchAimModeFrame, aimingState, queueLowFrame); + sleep 500; + } +} smartAimSelect(weaponNumber) { - var gameFrame; + var gameFrame, highReloadState, lowReloadState, greatestReloadState;; gameFrame = (get GAME_FRAME); - //smasel queue low trajectory steal + //define a period where low is given priority to steal. if (weaponNumber == AIMING_LOW){ queueLowFrame = (switchAimModeFrame + RESET_LOW_DELAY_FRAMES); } - //smasel i'm gonna have to put the framechecks here just in case an invalid target if (switchAimModeFrame < gameFrame){ - aimingState = AIMING_NEITHER; - } + highReloadState = (get WEAPON_RELOADSTATE(AIMING_HIGH)); + lowReloadState = (get WEAPON_RELOADSTATE(AIMING_LOW)); + + //prevent bonus shots, prevent unintentional + if (highReloadState > lowReloadState ){ + greatestReloadState = highReloadState; + } else{ + greatestReloadState = lowReloadState; + } + if (greatestReloadState > switchAimModeFrame){ + switchAimModeFrame = greatestReloadState; + } - //smasel block if another weapon is firing - if ((aimingState != AIMING_NEITHER) && (weaponNumber != aimingState)){ - return (0); + //check if the low weapon aimed but didn't fire. + if (((lowReloadState + RESET_LOW_DELAY_FRAMES) < switchAimModeFrame) && (queueLowFrame > switchAimModeFrame)){ + firedLowFailed = TRUE; + } else{ + firedLowFailed = FALSE; + } + aimingState = AIMING_NEITHER; } - - //smasel if aimingState is neither, set aimingState and its expiration + if (aimingState == AIMING_NEITHER){ if (weaponNumber == AIMING_LOW){ switchAimModeFrame = (gameFrame + RESET_LOW_DELAY_FRAMES); aimingState = AIMING_LOW; - var highReloadState; - highReloadState = (get WEAPON_RELOADSTATE(AIMING_HIGH)); - if (switchAimModeFrame < highReloadState){ - switchAimModeFrame = highReloadState; - } } else if ((weaponNumber == AIMING_HIGH) && (queueLowFrame < gameFrame)){ - switchAimModeFrame = (gameFrame + RESET_HIGH_DELAY_FRAMES); - var lowReloadState; - lowReloadState = (get WEAPON_RELOADSTATE(AIMING_LOW)); - if (switchAimModeFrame < lowReloadState){ - switchAimModeFrame = lowReloadState; + if (firedLowFailed == TRUE){ + //if low aimed but failed to fire, aim high for longer. + switchAimModeFrame = (gameFrame + RESET_HIGH_ERRORSTATE_FRAMES); + } else{ + switchAimModeFrame = (gameFrame + RESET_HIGH_DELAY_FRAMES); } aimingState = AIMING_HIGH; } diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index 5e4293b38805d178c235fdaac02949be9faf2560..71ee2487823a470431ba6d4df07b74b85a09a804 100644 GIT binary patch delta 821 zcmYk4O-NKx6vxj!@4okZj^o@uXzX*evS^BWkv3ooK@e0f3MB{}vKX5zqOgKCIYrSz zFpz^Fw5UZ96%;pwRKTy>peUSTE1J6t8-N7TB6fL&U5vx$oa{$ZnPXzLD!Z< ztw%#G)CKh)3Sd>#=2~3cBrfy3U3xg=vXL>~z}-eJc>63;OY+Y<5S37%0|J@gHSK5M zsZMRH?eD8Vm4y+>KBya%{Wd4>?SQGsD!*XHx-c(*geHpua0^fm;cen%W1qZlxHV`=F8&2sXU=tf-MzMPnclQ!MI`KoOBZ1qY!ZWDq|PLD4}$a1b2? zr{gLvk~%mvbZ~G`Cl?2GsUWxren5vx5gbJNzb1(9@w*@A-uvhB-evu1ZOkO1a&RDO z5CzfeXD3AT2a;i;IOf@KA=axT>4fB2wQydVj7~1drrDUtS-!%nPnqZuLWCMkL(cY( zFy+!Z4cNZ?G^ z_-x3T6XiX5aJt!&LLeev1I22kj0Zw|@wPI_6;c-* Date: Fri, 15 Nov 2024 21:46:42 -0600 Subject: [PATCH 12/27] further improve consistency for errorstate --- scripts/Units/armguard.bos | 5 ++++- scripts/Units/armguard.cob | Bin 3931 -> 4075 bytes 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index b9fc039fee0..3e85c93615e 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -76,10 +76,12 @@ smartAimSelect(weaponNumber) } //check if the low weapon aimed but didn't fire. - if (((lowReloadState + RESET_LOW_DELAY_FRAMES) < switchAimModeFrame) && (queueLowFrame > switchAimModeFrame)){ + if (((lowReloadState + RESET_LOW_DELAY_FRAMES) < gameFrame) && (queueLowFrame > switchAimModeFrame)){ firedLowFailed = TRUE; + get PRINT(1111); } else{ firedLowFailed = FALSE; + get PRINT(2222); } aimingState = AIMING_NEITHER; } @@ -90,6 +92,7 @@ smartAimSelect(weaponNumber) aimingState = AIMING_LOW; } else if ((weaponNumber == AIMING_HIGH) && (queueLowFrame < gameFrame)){ if (firedLowFailed == TRUE){ + get PRINT(3333); //if low aimed but failed to fire, aim high for longer. switchAimModeFrame = (gameFrame + RESET_HIGH_ERRORSTATE_FRAMES); } else{ diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index 71ee2487823a470431ba6d4df07b74b85a09a804..f2f5011b5c011ded7197468313d7e1eedf74d38b 100644 GIT binary patch delta 504 zcmXxgO(;ZB6bJBg?z?Zi_k6uZ(GZHJOq8kd5o19qQ5GXnimeq3S&)#T)ELq!r7T2Y zrN*p8v17q%%4V>Ug@i3T|EuxpcRsrJcF%pen)lj>CZZq|z=}oWBAYK-LNo{0(1iXm z9f?`oA>-DUt$gLPBy@dUn2FeQ*rB7!4X zHjA>a8&s0TvnqL5UUiJuC1jg8XjcUn^SAsTw2RHbusQfQO8zp(yur78Gl+SXxp7re z_5vS@8))aW^dMfzJmS5i5p$WhKmn_e+WxGNloOX;C#pL0-4@SEwL8h1vgTg!sq}b_ zd@fU7oNxc?Eb4ms_PUg3Nn7C&x5!iBF;8UHikf*jiJ4!)QA80KfFT%z9oT~dxP%9I zhDZGC7x;i5(4|CW5Qb*xggzL7Ntl5p*nnL)fipNSrEC>J?c$`S`D2R*IG zfrE%zVuuwuxa_`ClA9!@=Hy2CzRRyZ&-45a&+~iweRjTd#55xEgA;Npk%4TV6A#e` z#JxlVxM!|o36;Afr+(?0rC6FwYte9+i5NE|(&CEcuvK&7v<2A Date: Sat, 16 Nov 2024 16:50:57 -0600 Subject: [PATCH 13/27] create gadget to stop bad targetting --- .../unit_weapon_smart_select_helper.lua | 60 ++++++++++++++++++ scripts/Units/armguard.bos | 2 - scripts/Units/armguard.cob | Bin 4075 -> 3979 bytes .../LandDefenceOffence/corpun.lua | 1 + 4 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 luarules/gadgets/unit_weapon_smart_select_helper.lua diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua new file mode 100644 index 00000000000..135561a74b7 --- /dev/null +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -0,0 +1,60 @@ +function gadget:GetInfo() + return { + name = "Weapon Smart Select Helper", + desc = "Prevents auto-target units from blocking manual command fire orders for lower priority weapons.", + author = "SethDGamre", + date = "2024.11.16", + license = "GNU GPL, v2 or later", + layer = 0, + enabled = true + } +end + +if not gadgetHandler:IsSyncedCode() then return end + +--use customparams.smart_weapon_select_priority to define which weapon number is preferred over the other(s) and enable auto-targetting override. + +--functions +local spGetUnitIsDead = Spring.GetUnitIsDead +local spValidUnitID = Spring.ValidUnitID +local spAddUnitDamage = Spring.AddUnitDamage +local spGetUnitVelocity = Spring.GetUnitVelocity +local spGetUnitBasePosition = Spring.GetUnitBasePosition +local spGetUnitPosition = Spring.GetUnitPosition +local spSpawnCEG = Spring.SpawnCEG +local spPlaySoundFile = Spring.PlaySoundFile +local spTestMoveOrder = Spring.TestMoveOrder +local spGetUnitHealth = Spring.GetUnitHealth +local spDestroyUnit = Spring.DestroyUnit + +--tables +local smartWeaponsWatch = {} +local unitDefsWithSmartWeapons = {} + +for unitDefID, def in ipairs(UnitDefs) do + if def.customParams.smart_weapon_select_priority then + smartWeaponsWatch[unitDefID] = def.customParams.smart_weapon_select_priority + for weaponNumber, weaponData in ipairs(def.weapons) do + Spring.Echo("Shitshit", weaponNumber, weaponData, weaponData.name) + Script.SetWatchWeapon(weaponData.weaponDef, true) + end + end +end + +for weaponDefID, weaponDef in ipairs(WeaponDefs) do + +end + +function gadget:GameFrame(frame) + +end + +-- function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag, synced) +-- Spring.Echo("AllowCommand", unitID, unitDefID, unitTeam, cmdID) +-- return true +-- end + +function gadget:AllowWeaponTargetCheck(attackerID, attackerWeaponNum, attackerWeaponDefID) + Spring.Echo("AllowWeaponTargetCheck", attackerID, attackerWeaponNum, attackerWeaponDefID) + return 1, 0 +end \ No newline at end of file diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index 3e85c93615e..2a77aea1b14 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -78,10 +78,8 @@ smartAimSelect(weaponNumber) //check if the low weapon aimed but didn't fire. if (((lowReloadState + RESET_LOW_DELAY_FRAMES) < gameFrame) && (queueLowFrame > switchAimModeFrame)){ firedLowFailed = TRUE; - get PRINT(1111); } else{ firedLowFailed = FALSE; - get PRINT(2222); } aimingState = AIMING_NEITHER; } diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index f2f5011b5c011ded7197468313d7e1eedf74d38b..7d652a57bf83064393c26d8f2818984897c93489 100644 GIT binary patch delta 411 zcmW;Iy-Px26bA5f?uWN~O}zu@`zM)Sc znt?f3hGVF}In?0++EBuGl;HwuPzMK|;1xdL6Mn%6;A>$75-Zc5vEaV^$ LMJPM({viJYdy7s? delta 454 zcmXxgO(;ZB6bJBg-n(z+y*G>(p`i$=nJ8*VGnCmWW#J=Au{7DJkp&5fg&J&5DMg9$ zu~Fk?F(I>K!AjYXlB{IU&i{&AzyCS6Q}^9>v$Y?!F-1hB5QJru$U)VsHB2-M1!%_p zITwqYobboYO0I8YBK8aqg;cBI1yJ?A|F4cHnKEk}N*Nxd0$#gps7m*LcxvmR(nHx( zQ6tOZnpHd`?<&q~60vmlS=GEClU8@Rt#9U;p8k%$tUhp6uB>@JkVK$^bCN+`%L(#c zUXf3JBp76lNS(dHN#vk>*+V=deNLJ;<=na8Q^~kZoR?j3<^TWy diff --git a/units/CorBuildings/LandDefenceOffence/corpun.lua b/units/CorBuildings/LandDefenceOffence/corpun.lua index 72602024961..c23f1224ed7 100644 --- a/units/CorBuildings/LandDefenceOffence/corpun.lua +++ b/units/CorBuildings/LandDefenceOffence/corpun.lua @@ -38,6 +38,7 @@ return { subfolder = "CorBuildings/LandDefenceOffence", unitgroup = "weapon", usebuildinggrounddecal = true, + smart_weapon_select_priority = 1, }, featuredefs = { dead = { From c2e460cebbe1d0a64d01220af81d374898c9c710 Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Sun, 17 Nov 2024 13:58:37 -0600 Subject: [PATCH 14/27] Update unit_weapon_smart_select_helper.lua --- luarules/gadgets/unit_weapon_smart_select_helper.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua index 135561a74b7..20bba4819d0 100644 --- a/luarules/gadgets/unit_weapon_smart_select_helper.lua +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -5,7 +5,7 @@ function gadget:GetInfo() author = "SethDGamre", date = "2024.11.16", license = "GNU GPL, v2 or later", - layer = 0, + layer = 1100, enabled = true } end @@ -55,6 +55,6 @@ end -- end function gadget:AllowWeaponTargetCheck(attackerID, attackerWeaponNum, attackerWeaponDefID) - Spring.Echo("AllowWeaponTargetCheck", attackerID, attackerWeaponNum, attackerWeaponDefID) - return 1, 0 + Spring.Echo("AllowWeaponTargetCheck", attackerID, attackerWeaponNum, attackerWeaponDefID, Spring.GetGameFrame()) + return false, true end \ No newline at end of file From 552fc13a67ccf6c8b8ef2ea23f394a900b0e7c7d Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Sun, 17 Nov 2024 13:59:01 -0600 Subject: [PATCH 15/27] Update unit_weapon_smart_select_helper.lua --- luarules/gadgets/unit_weapon_smart_select_helper.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua index 20bba4819d0..b252d230072 100644 --- a/luarules/gadgets/unit_weapon_smart_select_helper.lua +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -5,7 +5,7 @@ function gadget:GetInfo() author = "SethDGamre", date = "2024.11.16", license = "GNU GPL, v2 or later", - layer = 1100, + layer = 1, enabled = true } end From 81c3cc73d4946464187a291763b6a5736bd51475 Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Sun, 17 Nov 2024 14:00:42 -0600 Subject: [PATCH 16/27] code cleanup --- .../unit_weapon_smart_select_helper.lua | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua index b252d230072..b860dbeaa43 100644 --- a/luarules/gadgets/unit_weapon_smart_select_helper.lua +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -14,19 +14,6 @@ if not gadgetHandler:IsSyncedCode() then return end --use customparams.smart_weapon_select_priority to define which weapon number is preferred over the other(s) and enable auto-targetting override. ---functions -local spGetUnitIsDead = Spring.GetUnitIsDead -local spValidUnitID = Spring.ValidUnitID -local spAddUnitDamage = Spring.AddUnitDamage -local spGetUnitVelocity = Spring.GetUnitVelocity -local spGetUnitBasePosition = Spring.GetUnitBasePosition -local spGetUnitPosition = Spring.GetUnitPosition -local spSpawnCEG = Spring.SpawnCEG -local spPlaySoundFile = Spring.PlaySoundFile -local spTestMoveOrder = Spring.TestMoveOrder -local spGetUnitHealth = Spring.GetUnitHealth -local spDestroyUnit = Spring.DestroyUnit - --tables local smartWeaponsWatch = {} local unitDefsWithSmartWeapons = {} @@ -41,13 +28,9 @@ for unitDefID, def in ipairs(UnitDefs) do end end -for weaponDefID, weaponDef in ipairs(WeaponDefs) do - -end - -function gadget:GameFrame(frame) +-- function gadget:GameFrame(frame) -end +-- end -- function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag, synced) -- Spring.Echo("AllowCommand", unitID, unitDefID, unitTeam, cmdID) From b4a49fd0083861f619528a90f6eea43264a2791b Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Sun, 17 Nov 2024 14:01:24 -0600 Subject: [PATCH 17/27] more code cleanup --- luarules/gadgets/unit_weapon_smart_select_helper.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua index b860dbeaa43..ecba797b010 100644 --- a/luarules/gadgets/unit_weapon_smart_select_helper.lua +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -22,7 +22,7 @@ for unitDefID, def in ipairs(UnitDefs) do if def.customParams.smart_weapon_select_priority then smartWeaponsWatch[unitDefID] = def.customParams.smart_weapon_select_priority for weaponNumber, weaponData in ipairs(def.weapons) do - Spring.Echo("Shitshit", weaponNumber, weaponData, weaponData.name) + Spring.Echo("smart_weapon_select_priority", weaponData.name, weaponNumber, weaponData) Script.SetWatchWeapon(weaponData.weaponDef, true) end end From 7f05ae6d2f31ff019fbf0eb4728a651b02ddcf2c Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Sun, 17 Nov 2024 14:02:29 -0600 Subject: [PATCH 18/27] Update unit_weapon_smart_select_helper.lua --- luarules/gadgets/unit_weapon_smart_select_helper.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua index ecba797b010..9bd9820832e 100644 --- a/luarules/gadgets/unit_weapon_smart_select_helper.lua +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -28,6 +28,12 @@ for unitDefID, def in ipairs(UnitDefs) do end end +function gadget:AllowWeaponTargetCheck(attackerID, attackerWeaponNum, attackerWeaponDefID) + Spring.Echo("AllowWeaponTargetCheck", attackerID, attackerWeaponNum, attackerWeaponDefID, Spring.GetGameFrame()) + return false, true +end + + -- function gadget:GameFrame(frame) -- end @@ -36,8 +42,3 @@ end -- Spring.Echo("AllowCommand", unitID, unitDefID, unitTeam, cmdID) -- return true -- end - -function gadget:AllowWeaponTargetCheck(attackerID, attackerWeaponNum, attackerWeaponDefID) - Spring.Echo("AllowWeaponTargetCheck", attackerID, attackerWeaponNum, attackerWeaponDefID, Spring.GetGameFrame()) - return false, true -end \ No newline at end of file From 015a8c7e6c331b983f6992bcae8106d725fb639b Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Sun, 17 Nov 2024 20:39:43 -0600 Subject: [PATCH 19/27] fix gadgets.lua entry so it works with engine change from 12 years ago --- luarules/gadgets.lua | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/luarules/gadgets.lua b/luarules/gadgets.lua index 879498075bf..76304037452 100644 --- a/luarules/gadgets.lua +++ b/luarules/gadgets.lua @@ -1506,14 +1506,21 @@ function gadgetHandler:TerraformComplete(unitID, unitDefID, unitTeam, end function gadgetHandler:AllowWeaponTargetCheck(attackerID, attackerWeaponNum, attackerWeaponDefID) - for _, g in ipairs(self.AllowWeaponTargetCheckList) do - if not g:AllowWeaponTargetCheck(attackerID, attackerWeaponNum, attackerWeaponDefID) then - return false +local ignore = true +for _, g in ipairs(self.AllowWeaponTargetCheckList) do + local allowCheck, ignoreCheck = g:AllowWeaponTargetCheck(attackerID, attackerWeaponNum, attackerWeaponDefID) + if not ignoreCheck then + ignore = false + if not allowCheck then + return 0 end end - return true end +return ((ignore and -1) or 1) +end + + function gadgetHandler:AllowWeaponTarget(attackerID, targetID, attackerWeaponNum, attackerWeaponDefID, defPriority) local allowed = true local priority = 1.0 From 95acb62ac1f6fa15bdb1d19c5c6d78c3f4e15961 Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Sun, 17 Nov 2024 20:39:45 -0600 Subject: [PATCH 20/27] Update unit_weapon_smart_select_helper.lua --- .../unit_weapon_smart_select_helper.lua | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua index 9bd9820832e..fdb718c7c51 100644 --- a/luarules/gadgets/unit_weapon_smart_select_helper.lua +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -10,6 +10,10 @@ function gadget:GetInfo() } end +function gadget:CommandNotify(cmdID, params, options) + Spring.Echo("CommandNotify", cmdID) + end + if not gadgetHandler:IsSyncedCode() then return end --use customparams.smart_weapon_select_priority to define which weapon number is preferred over the other(s) and enable auto-targetting override. @@ -17,6 +21,11 @@ if not gadgetHandler:IsSyncedCode() then return end --tables local smartWeaponsWatch = {} local unitDefsWithSmartWeapons = {} +local cmdSuspensionTable = { + [CMD.ATTACK] = true, + [CMD.AREA_ATTACK] = true, + [CMD.CMD_UNIT_SET_TARGET] = true +} for unitDefID, def in ipairs(UnitDefs) do if def.customParams.smart_weapon_select_priority then @@ -29,16 +38,28 @@ for unitDefID, def in ipairs(UnitDefs) do end function gadget:AllowWeaponTargetCheck(attackerID, attackerWeaponNum, attackerWeaponDefID) - Spring.Echo("AllowWeaponTargetCheck", attackerID, attackerWeaponNum, attackerWeaponDefID, Spring.GetGameFrame()) + --Spring.Echo("AllowWeaponTargetCheck", attackerID, attackerWeaponNum, attackerWeaponDefID, Spring.GetGameFrame()) return false, true -end + end --- function gadget:GameFrame(frame) +function gadget:GameFrame(frame) --- end +end + +function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag, synced) + if cmdSuspensionTable[cmdID] then + -- Custom logic when the command is in the suspension table + Spring.Echo("Command suspended:", cmdID) + + -- Your additional logic here + return false -- Disallow the command if it's in the suspension table + + end + return true + -- Allow all other commands + end --- function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag, synced) --- Spring.Echo("AllowCommand", unitID, unitDefID, unitTeam, cmdID) --- return true --- end +-- function gadget:CommandFallback(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag) +-- Spring.Echo("commandFallback", cmdID) +-- end \ No newline at end of file From 60783600cce85280ca7e006f077209855a71292c Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Tue, 19 Nov 2024 19:47:49 -0600 Subject: [PATCH 21/27] Update unit_weapon_smart_select_helper.lua --- .../unit_weapon_smart_select_helper.lua | 39 ++++++------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua index fdb718c7c51..04bbf820ef4 100644 --- a/luarules/gadgets/unit_weapon_smart_select_helper.lua +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -5,33 +5,32 @@ function gadget:GetInfo() author = "SethDGamre", date = "2024.11.16", license = "GNU GPL, v2 or later", - layer = 1, + layer = 2, enabled = true } end -function gadget:CommandNotify(cmdID, params, options) - Spring.Echo("CommandNotify", cmdID) - end - if not gadgetHandler:IsSyncedCode() then return end --use customparams.smart_weapon_select_priority to define which weapon number is preferred over the other(s) and enable auto-targetting override. +--functions +local spGetGameFrame = Spring.GetGameFrame() + --tables local smartWeaponsWatch = {} local unitDefsWithSmartWeapons = {} local cmdSuspensionTable = { [CMD.ATTACK] = true, [CMD.AREA_ATTACK] = true, - [CMD.CMD_UNIT_SET_TARGET] = true + [CMD.UNIT_SET_TARGET] = true, } for unitDefID, def in ipairs(UnitDefs) do if def.customParams.smart_weapon_select_priority then smartWeaponsWatch[unitDefID] = def.customParams.smart_weapon_select_priority for weaponNumber, weaponData in ipairs(def.weapons) do - Spring.Echo("smart_weapon_select_priority", weaponData.name, weaponNumber, weaponData) + Spring.Echo("smart_weapon_select_priority", def.name, weaponNumber, weaponData) Script.SetWatchWeapon(weaponData.weaponDef, true) end end @@ -39,27 +38,11 @@ end function gadget:AllowWeaponTargetCheck(attackerID, attackerWeaponNum, attackerWeaponDefID) --Spring.Echo("AllowWeaponTargetCheck", attackerID, attackerWeaponNum, attackerWeaponDefID, Spring.GetGameFrame()) + local command = Spring.GetUnitCommands(attackerID, -1) + Spring.Echo((command)) + if command[1] then + Spring.Echo(command[1].id, attackerID, attackerWeaponNum) + end return false, true end - -function gadget:GameFrame(frame) - -end - -function gadget:AllowCommand(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag, synced) - if cmdSuspensionTable[cmdID] then - -- Custom logic when the command is in the suspension table - Spring.Echo("Command suspended:", cmdID) - - -- Your additional logic here - return false -- Disallow the command if it's in the suspension table - - end - return true - -- Allow all other commands - end - --- function gadget:CommandFallback(unitID, unitDefID, unitTeam, cmdID, cmdParams, cmdOptions, cmdTag) --- Spring.Echo("commandFallback", cmdID) --- end \ No newline at end of file From da2c6908aa22966742f71446078fd2aea2125b36 Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Wed, 20 Nov 2024 21:15:45 -0600 Subject: [PATCH 22/27] gadget complete? --- .../unit_weapon_smart_select_helper.lua | 76 ++++++++++++++---- scripts/Units/armguard.bos | 12 +-- scripts/Units/armguard.cob | Bin 3979 -> 3796 bytes 3 files changed, 61 insertions(+), 27 deletions(-) diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua index 04bbf820ef4..c6b05dbe1b8 100644 --- a/luarules/gadgets/unit_weapon_smart_select_helper.lua +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -14,35 +14,79 @@ if not gadgetHandler:IsSyncedCode() then return end --use customparams.smart_weapon_select_priority to define which weapon number is preferred over the other(s) and enable auto-targetting override. +--static +local frameCheckModulo = Game.gameSpeed +local cmdAttack = CMD.ATTACK + +--variables +local gameFrame = 0 + --functions -local spGetGameFrame = Spring.GetGameFrame() +local ggGetUnitTargetIndex = GG.getUnitTargetIndex +local spGetUnitCommands = Spring.GetUnitCommands --tables -local smartWeaponsWatch = {} +local unitSuspendAutoAiming = {} local unitDefsWithSmartWeapons = {} -local cmdSuspensionTable = { - [CMD.ATTACK] = true, - [CMD.AREA_ATTACK] = true, - [CMD.UNIT_SET_TARGET] = true, -} for unitDefID, def in ipairs(UnitDefs) do if def.customParams.smart_weapon_select_priority then - smartWeaponsWatch[unitDefID] = def.customParams.smart_weapon_select_priority + unitDefsWithSmartWeapons[unitDefID] = def.customParams.smart_weapon_select_priority for weaponNumber, weaponData in ipairs(def.weapons) do - Spring.Echo("smart_weapon_select_priority", def.name, weaponNumber, weaponData) + --Spring.Echo("smart_weapon_select_priority", def.name, weaponNumber, weaponData) Script.SetWatchWeapon(weaponData.weaponDef, true) end end end -function gadget:AllowWeaponTargetCheck(attackerID, attackerWeaponNum, attackerWeaponDefID) - --Spring.Echo("AllowWeaponTargetCheck", attackerID, attackerWeaponNum, attackerWeaponDefID, Spring.GetGameFrame()) - local command = Spring.GetUnitCommands(attackerID, -1) - Spring.Echo((command)) - if command[1] then - Spring.Echo(command[1].id, attackerID, attackerWeaponNum) +local function manualCommandIssued(attackerID) + local firstCommand = spGetUnitCommands(attackerID, 1) + if next(firstCommand) then + if (firstCommand[1].id) == cmdAttack then + --Spring.Echo("firstCommand", attackerID) + return true + end + elseif ggGetUnitTargetIndex(attackerID) then + --Spring.Echo("ggGetUnitTargetIndex", attackerID, ggGetUnitTargetIndex(attackerID)) + return true + else + return false end - return false, true +end + +function gadget:UnitFinished(unitID, unitDefID, unitTeam) + if unitDefsWithSmartWeapons[unitDefID] then + unitSuspendAutoAiming[unitID] = false + --Spring.Echo("unit Added!", unitID) end +end +function gadget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam) + unitSuspendAutoAiming[unitID] = nil + --Spring.Echo("unit destroyed!", unitID) +end + +function gadget:AllowWeaponTargetCheck(attackerID, attackerWeaponNum, attackerWeaponDefID) + if unitSuspendAutoAiming[attackerID] == true then + --Spring.Echo("no autotarget!!", attackerID) + return false, false + else + --Spring.Echo("yes autotarget!!", attackerID) + return false, true + end +end + +function gadget:GameFrame(frame) + if frame % frameCheckModulo == 3 then + for attackerID in pairs(unitSuspendAutoAiming) do + --Spring.Echo("gameFrame Check!!!", attackerID) + if manualCommandIssued(attackerID) == true then + unitSuspendAutoAiming[attackerID] = true + --Spring.Echo("true") + else + unitSuspendAutoAiming[attackerID] = false + --Spring.Echo("false") + end + end + end +end \ No newline at end of file diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index 2a77aea1b14..43035b6f361 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -9,7 +9,7 @@ piece flare1, flare2, base, turret, barrel1, barrel2, sleeves; static-var nextBarrel, trajectoryMode, lastHeading, aimingState, switchAimModeFrame, queueLowFrame, firedLowFailed, debugGameFrame; #define SIGNAL_AIM 1 -#define RESET_LOW_DELAY_FRAMES 20 +#define RESET_LOW_DELAY_FRAMES 15 #define RESET_HIGH_DELAY_FRAMES 450 #define RESET_HIGH_ERRORSTATE_FRAMES 900 #define AIMING_NEITHER 0 @@ -42,15 +42,6 @@ Create() #define SMOKEPIECE base #include "smokeunit_thread_nohit.h" -//smasel WATCH THE FORT, I'll remove this when debugging is complete. -debugTimer(){ - while (TRUE){ - debugGameFrame = get GAME_FRAME; - get PRINT(debugGameFrame, switchAimModeFrame, aimingState, queueLowFrame); - sleep 500; - } -} - smartAimSelect(weaponNumber) { var gameFrame, highReloadState, lowReloadState, greatestReloadState;; @@ -90,7 +81,6 @@ smartAimSelect(weaponNumber) aimingState = AIMING_LOW; } else if ((weaponNumber == AIMING_HIGH) && (queueLowFrame < gameFrame)){ if (firedLowFailed == TRUE){ - get PRINT(3333); //if low aimed but failed to fire, aim high for longer. switchAimModeFrame = (gameFrame + RESET_HIGH_ERRORSTATE_FRAMES); } else{ diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index 7d652a57bf83064393c26d8f2818984897c93489..846ad8982b866c001aa762105d5d42e88c0fc409 100644 GIT binary patch delta 519 zcmY+=F=!KE6bJC{eRr2!F3IIWl{8As5NM?dv{1xKgtka41OhHjp-=_MPzouwP#RFs zp+nmt{wavkMT%{LpM4}R~xyZ3#M@4mJ4*VK@y zl!{Z3CJd!Q%>I*$DpjEml;e9dx<53nF&ngTs>kAWelk7n`P+p#hFivYw4vihgOfO$h=m@pFgz9(JuOat}vVRUYF`;I>q-!1xSx#&xtA-yj)0=7}bq1bzoSF(7tYf0NpI z0!Ma6EVS(e7VTcA53lWr?p*55$ta4UvJ}w>Jr#$Ot{MT)&%-j01t%-Z*mCl+`mcV) zI)j_xyYd-N!aMqph8uY=se?u&E6)r3oo)I=Clu1Wc1qGiD$ygV(k5+DlULuOHl0zI sTvw@n%Fqan(*r6|nU?4U)#xp~qq?j5)E3W83|80diDn)c^nh delta 662 zcmYMyPe>GT6bJC%`^|55oc-g@+QPc5x|)Z;m0ao|8A5cBZvCN)P^8haSPDyvT@)j> zIwT$BOM! z2L&|c851(G7jc#jMuZvvSM%t~{PBS`2%{A)o z8o6;R`i!RRB6G|}TE8ut3-egCgh_icv$0pHom!E_x;-F$_--4rjTtW|JGkYQ`aE{p ze-p~PlQh>!yL}(Mp?scIn&}vQ&KRT4>PFrj_3OF^w!$2?T_joDaQ#xlBX^kVXIJQ` z>~-r~=`MZ>2fZGr504$!E7QpPbFzqg{;({g$#oTeY*=1mljJ^R|FfK~fyH zf_|u95vE-pDM;L RRW8m}&rZ!$uHr}P+g~9zbb$Z> From e66f87e95a4878e1d9a1fbd5b3e2b264bd9e4e77 Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Thu, 21 Nov 2024 13:21:00 -0600 Subject: [PATCH 23/27] everything 100% working, performance not good --- .../unit_weapon_smart_select_helper.lua | 21 +++--------- scripts/Units/armguard.bos | 33 +++++++++++-------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua index c6b05dbe1b8..4809ac460fe 100644 --- a/luarules/gadgets/unit_weapon_smart_select_helper.lua +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -23,7 +23,7 @@ local gameFrame = 0 --functions local ggGetUnitTargetIndex = GG.getUnitTargetIndex -local spGetUnitCommands = Spring.GetUnitCommands +local spGetUnitCurrentCommand = Spring.GetUnitCurrentCommand --tables local unitSuspendAutoAiming = {} @@ -33,21 +33,15 @@ for unitDefID, def in ipairs(UnitDefs) do if def.customParams.smart_weapon_select_priority then unitDefsWithSmartWeapons[unitDefID] = def.customParams.smart_weapon_select_priority for weaponNumber, weaponData in ipairs(def.weapons) do - --Spring.Echo("smart_weapon_select_priority", def.name, weaponNumber, weaponData) Script.SetWatchWeapon(weaponData.weaponDef, true) end end end local function manualCommandIssued(attackerID) - local firstCommand = spGetUnitCommands(attackerID, 1) - if next(firstCommand) then - if (firstCommand[1].id) == cmdAttack then - --Spring.Echo("firstCommand", attackerID) - return true - end + if spGetUnitCurrentCommand(attackerID) == cmdAttack then + return true elseif ggGetUnitTargetIndex(attackerID) then - --Spring.Echo("ggGetUnitTargetIndex", attackerID, ggGetUnitTargetIndex(attackerID)) return true else return false @@ -57,35 +51,30 @@ end function gadget:UnitFinished(unitID, unitDefID, unitTeam) if unitDefsWithSmartWeapons[unitDefID] then unitSuspendAutoAiming[unitID] = false - --Spring.Echo("unit Added!", unitID) end end function gadget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerDefID, attackerTeam) unitSuspendAutoAiming[unitID] = nil - --Spring.Echo("unit destroyed!", unitID) end function gadget:AllowWeaponTargetCheck(attackerID, attackerWeaponNum, attackerWeaponDefID) if unitSuspendAutoAiming[attackerID] == true then - --Spring.Echo("no autotarget!!", attackerID) return false, false else - --Spring.Echo("yes autotarget!!", attackerID) return false, true end end + + function gadget:GameFrame(frame) if frame % frameCheckModulo == 3 then for attackerID in pairs(unitSuspendAutoAiming) do - --Spring.Echo("gameFrame Check!!!", attackerID) if manualCommandIssued(attackerID) == true then unitSuspendAutoAiming[attackerID] = true - --Spring.Echo("true") else unitSuspendAutoAiming[attackerID] = false - --Spring.Echo("false") end end end diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index 43035b6f361..699eaf012d4 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -6,7 +6,7 @@ piece flare1, flare2, base, turret, barrel1, barrel2, sleeves; //smasel remove debugGameFrame -static-var nextBarrel, trajectoryMode, lastHeading, aimingState, switchAimModeFrame, queueLowFrame, firedLowFailed, debugGameFrame; +static-var nextBarrel, trajectoryMode, lastHeading, aimingState, switchAimModeFrame, queueLowFrame, firedLowFailed, gameFrame; #define SIGNAL_AIM 1 #define RESET_LOW_DELAY_FRAMES 15 @@ -42,9 +42,25 @@ Create() #define SMOKEPIECE base #include "smokeunit_thread_nohit.h" +setAimingState(weaponNumber) +{ + if (weaponNumber == AIMING_LOW){ + switchAimModeFrame = (gameFrame + RESET_LOW_DELAY_FRAMES); + aimingState = AIMING_LOW; + } else if ((weaponNumber == AIMING_HIGH) && (queueLowFrame < gameFrame)){ + if (firedLowFailed == TRUE){ + //if low aimed but failed to fire, aim high for longer. + switchAimModeFrame = (gameFrame + RESET_HIGH_ERRORSTATE_FRAMES); + } else{ + switchAimModeFrame = (gameFrame + RESET_HIGH_DELAY_FRAMES); + } + aimingState = AIMING_HIGH; + } +} + smartAimSelect(weaponNumber) { - var gameFrame, highReloadState, lowReloadState, greatestReloadState;; + var highReloadState, lowReloadState, greatestReloadState;; gameFrame = (get GAME_FRAME); //define a period where low is given priority to steal. @@ -76,18 +92,7 @@ smartAimSelect(weaponNumber) } if (aimingState == AIMING_NEITHER){ - if (weaponNumber == AIMING_LOW){ - switchAimModeFrame = (gameFrame + RESET_LOW_DELAY_FRAMES); - aimingState = AIMING_LOW; - } else if ((weaponNumber == AIMING_HIGH) && (queueLowFrame < gameFrame)){ - if (firedLowFailed == TRUE){ - //if low aimed but failed to fire, aim high for longer. - switchAimModeFrame = (gameFrame + RESET_HIGH_ERRORSTATE_FRAMES); - } else{ - switchAimModeFrame = (gameFrame + RESET_HIGH_DELAY_FRAMES); - } - aimingState = AIMING_HIGH; - } + call-script setAimingState(weaponNumber); return (0); } } From da48f3a4ee949dd583bf4b87d71a29f8ce2962d5 Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Thu, 21 Nov 2024 13:21:04 -0600 Subject: [PATCH 24/27] Update armguard.cob --- scripts/Units/armguard.cob | Bin 3796 -> 3851 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index 846ad8982b866c001aa762105d5d42e88c0fc409..d0969d2bc2ab47a51cc41d7df04f4117e47f60ea 100644 GIT binary patch delta 739 zcmY+CPe@cz6vpql@4olu&N$wVe(N~7#i{;A7E+~bue zv}ln}@hr9)+G^hcXDf!fIG$361J@n?g1<&=S8%&e8_gQ?oSiGTT<7i6vyq z{^!64@Ec@t6M4`Fs^Ai+gS%iFJO}IeiT(kbQ7Q-af-*P;PJ#2F25x|R;1PHV=D;iP r4t&a}g8G8RGWY@3z#p&yymnqp7t>?SBlWBGYqhh@(dHPhrB^or1buf& delta 719 zcmYk4KWG#|6vp41+1a~YlXZ@$cSnd3jv(OzUbrGfA_go3MMz^IA!uw;h;X1nAZSP$ z39-oexJF4MLP#MfnohA1Bw&$3h+<<3gUx{;2*M$LZ?hg*_|3fU{o6OQyL$4|z;HlB z1&{-imMFrm&qyy(1H1+!&^s@OFB$n326D%ioT(Yl(zN}&DbMZcg7MH==AEbOp%3J{ zt+SDGP+vq-(zwZX)l@sk+dUjZPo0J)L;p4Nr?r`1duTk!_WwQhv)nXxC|7IQo5UZ5 zLEfTFhyD^&Oo!xeaDqvWyK#3BgB#(v7!9hGCbdlU>V-^cHTtCU)0Ff2eg|KgsX;w+ z>d^=2oMdv1(x$QIUyw6Wfop>T{J$_&=W(hA?X z^m1g@7NwEvVJn>PlQmeMWj!~}PG<5&`I+-+WRU-Ky*Ifo+xa=ZEThrwAjU+p79HbQ z-bQEmmb9ZP&&yI=k%_p(4^sUI`WkP`UcAA-WaY>P54;-fsq&&;)-&({`~VTYY5|nN z6)+8E!2)Q3b+Ch9Xcz2(Ht2vPAu53isDX1}3QU7Ja2G6tCU^p#g3W~b=mm@|@CLjG N9~1fAdrF3q{eL%7Zj}H4 From 5d667ce2cc38285814e8a794fa8cc6d3396c55a6 Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Thu, 21 Nov 2024 18:13:04 -0600 Subject: [PATCH 25/27] neww version, now with 1000% better performance --- .../unit_weapon_smart_select_helper.lua | 69 ++++++++++++------ scripts/Units/armguard.bos | 11 +++ scripts/Units/armguard.cob | Bin 3851 -> 4047 bytes 3 files changed, 57 insertions(+), 23 deletions(-) diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua index 4809ac460fe..c24678a401c 100644 --- a/luarules/gadgets/unit_weapon_smart_select_helper.lua +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -22,8 +22,11 @@ local cmdAttack = CMD.ATTACK local gameFrame = 0 --functions -local ggGetUnitTargetIndex = GG.getUnitTargetIndex +local ggGetUnitTarget = GG.GetUnitTarget local spGetUnitCurrentCommand = Spring.GetUnitCurrentCommand +local spCallCOBScript = Spring.CallCOBScript +local spGetUnitWeaponHaveFreeLineOfFire = Spring.GetUnitWeaponHaveFreeLineOfFire +local spGetUnitCommands = Spring.GetUnitCommands --tables local unitSuspendAutoAiming = {} @@ -31,26 +34,59 @@ local unitDefsWithSmartWeapons = {} for unitDefID, def in ipairs(UnitDefs) do if def.customParams.smart_weapon_select_priority then - unitDefsWithSmartWeapons[unitDefID] = def.customParams.smart_weapon_select_priority + unitDefsWithSmartWeapons[unitDefID] = {preferredWeapon = tonumber(def.customParams.smart_weapon_select_priority)} for weaponNumber, weaponData in ipairs(def.weapons) do + if weaponNumber ~= unitDefsWithSmartWeapons[unitDefID].preferredWeapon then + unitDefsWithSmartWeapons[unitDefID].otherWeapon = tonumber(weaponNumber) + end Script.SetWatchWeapon(weaponData.weaponDef, true) end end end +local function weaponTargettingCheck(attackerID, targetData) + if type(targetData) == "number" then + end + if not attackerID or not targetData then return false end + if #targetData == 1 then + if not spGetUnitWeaponHaveFreeLineOfFire(attackerID, unitSuspendAutoAiming[attackerID].preferredWeapon, targetData[1]) then + spCallCOBScript ( attackerID, unitSuspendAutoAiming[attackerID].overrideScriptID, 0, unitSuspendAutoAiming[attackerID].otherWeapon) + return false + end + elseif #targetData > 1 then + if not spGetUnitWeaponHaveFreeLineOfFire(attackerID, unitSuspendAutoAiming[attackerID].preferredWeapon, targetData[1], targetData[2], targetData[3]) then + spCallCOBScript ( attackerID, unitSuspendAutoAiming[attackerID].overrideScriptID, 0, unitSuspendAutoAiming[attackerID].otherWeapon) + return true + else + return false + end + end +end + local function manualCommandIssued(attackerID) + local returnTargetTable = {} if spGetUnitCurrentCommand(attackerID) == cmdAttack then - return true - elseif ggGetUnitTargetIndex(attackerID) then - return true - else - return false + local attackTarget = spGetUnitCommands(attackerID, 1) + returnTargetTable = attackTarget[1].params + return returnTargetTable end + local setTargetData = ggGetUnitTarget(attackerID) or {} + --Spring.Echo("setTargetData type", type(setTargetData)) + if type(setTargetData) ~= "number" and setTargetData[1] then + returnTargetTable = setTargetData + return returnTargetTable + end + return {} end function gadget:UnitFinished(unitID, unitDefID, unitTeam) if unitDefsWithSmartWeapons[unitDefID] then - unitSuspendAutoAiming[unitID] = false + unitSuspendAutoAiming[unitID] = { + unitDefID = unitDefID, + preferredWeapon = unitDefsWithSmartWeapons[unitDefID].preferredWeapon, + otherWeapon = unitDefsWithSmartWeapons[unitDefID].otherWeapon, + overrideScriptID = Spring.GetCOBScriptID(unitID, "overrideAimingState") + } end end @@ -58,24 +94,11 @@ function gadget:UnitDestroyed(unitID, unitDefID, unitTeam, attackerID, attackerD unitSuspendAutoAiming[unitID] = nil end -function gadget:AllowWeaponTargetCheck(attackerID, attackerWeaponNum, attackerWeaponDefID) - if unitSuspendAutoAiming[attackerID] == true then - return false, false - else - return false, true - end -end - - - function gadget:GameFrame(frame) if frame % frameCheckModulo == 3 then for attackerID in pairs(unitSuspendAutoAiming) do - if manualCommandIssued(attackerID) == true then - unitSuspendAutoAiming[attackerID] = true - else - unitSuspendAutoAiming[attackerID] = false - end + local targetData = manualCommandIssued(attackerID) + weaponTargettingCheck(attackerID, targetData) end end end \ No newline at end of file diff --git a/scripts/Units/armguard.bos b/scripts/Units/armguard.bos index 699eaf012d4..586c3c19c93 100644 --- a/scripts/Units/armguard.bos +++ b/scripts/Units/armguard.bos @@ -42,6 +42,17 @@ Create() #define SMOKEPIECE base #include "smokeunit_thread_nohit.h" +overrideAimingState(weaponNumber) +{ + if (weaponNumber == AIMING_LOW){ + switchAimModeFrame = (gameFrame + RESET_LOW_DELAY_FRAMES); + aimingState = AIMING_LOW; + } else if ((weaponNumber == AIMING_HIGH)){ + switchAimModeFrame = (gameFrame + RESET_HIGH_DELAY_FRAMES); + aimingState = AIMING_HIGH; + } +} + setAimingState(weaponNumber) { if (weaponNumber == AIMING_LOW){ diff --git a/scripts/Units/armguard.cob b/scripts/Units/armguard.cob index d0969d2bc2ab47a51cc41d7df04f4117e47f60ea..1a8cf47514460459040197ec236f4594178b3fbd 100644 GIT binary patch delta 562 zcmX}pO-NKx6bJBg?)#W|<2YU$V=VBaLIugbwF2%BEJoV$!th0cYCl4p{11V|_+t zR7Sbx*{EX&)lQS{vG2Y)p?K?b>M(vd4^MTo${ZJ)3&!#o+}yWUG46(%!vQY`p}xj= zq6wE0wYq$iZ!o{1hxnd&Wtts4u6U`r_if2g$5z;WNYO8B({DO$M6%RFz4VAC2{cEW zv_-SLig&b3pXeL?q?p839gXV~4Dlf-gEi>Z{Vq7d~M zO1Z4T$W|&F^JC?omUS)1IM6=wMx5QIQ7?b7XC&ni7sj-{Rv0qd2e{C`TV&0rG}v@Bjb+ From 5e0edb025ecaf697b5ef17177c0276f2a76697fe Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Thu, 21 Nov 2024 18:29:27 -0600 Subject: [PATCH 26/27] fixed ground targetting error, cleanup code --- .../gadgets/unit_weapon_smart_select_helper.lua | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua index c24678a401c..0de365c1858 100644 --- a/luarules/gadgets/unit_weapon_smart_select_helper.lua +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -37,25 +37,22 @@ for unitDefID, def in ipairs(UnitDefs) do unitDefsWithSmartWeapons[unitDefID] = {preferredWeapon = tonumber(def.customParams.smart_weapon_select_priority)} for weaponNumber, weaponData in ipairs(def.weapons) do if weaponNumber ~= unitDefsWithSmartWeapons[unitDefID].preferredWeapon then - unitDefsWithSmartWeapons[unitDefID].otherWeapon = tonumber(weaponNumber) + unitDefsWithSmartWeapons[unitDefID].deferredWeapon = tonumber(weaponNumber) end - Script.SetWatchWeapon(weaponData.weaponDef, true) end end end local function weaponTargettingCheck(attackerID, targetData) - if type(targetData) == "number" then - end if not attackerID or not targetData then return false end if #targetData == 1 then if not spGetUnitWeaponHaveFreeLineOfFire(attackerID, unitSuspendAutoAiming[attackerID].preferredWeapon, targetData[1]) then - spCallCOBScript ( attackerID, unitSuspendAutoAiming[attackerID].overrideScriptID, 0, unitSuspendAutoAiming[attackerID].otherWeapon) + spCallCOBScript ( attackerID, unitSuspendAutoAiming[attackerID].overrideScriptID, 0, unitSuspendAutoAiming[attackerID].deferredWeapon) return false end elseif #targetData > 1 then - if not spGetUnitWeaponHaveFreeLineOfFire(attackerID, unitSuspendAutoAiming[attackerID].preferredWeapon, targetData[1], targetData[2], targetData[3]) then - spCallCOBScript ( attackerID, unitSuspendAutoAiming[attackerID].overrideScriptID, 0, unitSuspendAutoAiming[attackerID].otherWeapon) + if not spGetUnitWeaponHaveFreeLineOfFire(attackerID, unitSuspendAutoAiming[attackerID].preferredWeapon, _, _, _, targetData[1], targetData[2], targetData[3]) then + spCallCOBScript ( attackerID, unitSuspendAutoAiming[attackerID].overrideScriptID, 0, unitSuspendAutoAiming[attackerID].deferredWeapon) return true else return false @@ -71,7 +68,6 @@ local function manualCommandIssued(attackerID) return returnTargetTable end local setTargetData = ggGetUnitTarget(attackerID) or {} - --Spring.Echo("setTargetData type", type(setTargetData)) if type(setTargetData) ~= "number" and setTargetData[1] then returnTargetTable = setTargetData return returnTargetTable @@ -84,7 +80,7 @@ function gadget:UnitFinished(unitID, unitDefID, unitTeam) unitSuspendAutoAiming[unitID] = { unitDefID = unitDefID, preferredWeapon = unitDefsWithSmartWeapons[unitDefID].preferredWeapon, - otherWeapon = unitDefsWithSmartWeapons[unitDefID].otherWeapon, + deferredWeapon = unitDefsWithSmartWeapons[unitDefID].deferredWeapon, overrideScriptID = Spring.GetCOBScriptID(unitID, "overrideAimingState") } end From 8adb417f7d1517bdaad575c2a96eeb077ab5e5d0 Mon Sep 17 00:00:00 2001 From: SethDGamre Date: Thu, 21 Nov 2024 19:24:46 -0600 Subject: [PATCH 27/27] attack/settarget now override once with a 10 second cooldown to make it more responsive. --- .../unit_weapon_smart_select_helper.lua | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/luarules/gadgets/unit_weapon_smart_select_helper.lua b/luarules/gadgets/unit_weapon_smart_select_helper.lua index 0de365c1858..109f2d78b10 100644 --- a/luarules/gadgets/unit_weapon_smart_select_helper.lua +++ b/luarules/gadgets/unit_weapon_smart_select_helper.lua @@ -17,6 +17,7 @@ if not gadgetHandler:IsSyncedCode() then return end --static local frameCheckModulo = Game.gameSpeed local cmdAttack = CMD.ATTACK +local innitializeExpirationFrames = Game.gameSpeed * 10 --variables local gameFrame = 0 @@ -46,15 +47,22 @@ end local function weaponTargettingCheck(attackerID, targetData) if not attackerID or not targetData then return false end if #targetData == 1 then - if not spGetUnitWeaponHaveFreeLineOfFire(attackerID, unitSuspendAutoAiming[attackerID].preferredWeapon, targetData[1]) then - spCallCOBScript ( attackerID, unitSuspendAutoAiming[attackerID].overrideScriptID, 0, unitSuspendAutoAiming[attackerID].deferredWeapon) + local canShoot = spGetUnitWeaponHaveFreeLineOfFire(attackerID, unitSuspendAutoAiming[attackerID].preferredWeapon, targetData[1]) + if not canShoot then + spCallCOBScript(attackerID, unitSuspendAutoAiming[attackerID].overrideScriptID, 0, unitSuspendAutoAiming[attackerID].deferredWeapon) return false + elseif canShoot and gameFrame > unitSuspendAutoAiming[attackerID].overrideExpirationFrame then + spCallCOBScript(attackerID, unitSuspendAutoAiming[attackerID].overrideScriptID, 0, unitSuspendAutoAiming[attackerID].preferredWeapon) + unitSuspendAutoAiming[attackerID].overrideExpirationFrame = gameFrame + innitializeExpirationFrames + return true end elseif #targetData > 1 then - if not spGetUnitWeaponHaveFreeLineOfFire(attackerID, unitSuspendAutoAiming[attackerID].preferredWeapon, _, _, _, targetData[1], targetData[2], targetData[3]) then - spCallCOBScript ( attackerID, unitSuspendAutoAiming[attackerID].overrideScriptID, 0, unitSuspendAutoAiming[attackerID].deferredWeapon) + local canShoot = spGetUnitWeaponHaveFreeLineOfFire(attackerID, unitSuspendAutoAiming[attackerID].preferredWeapon, _, _, _, targetData[1], targetData[2], targetData[3]) + if not canShoot then + spCallCOBScript(attackerID, unitSuspendAutoAiming[attackerID].overrideScriptID, 0, unitSuspendAutoAiming[attackerID].deferredWeapon) return true - else + elseif canShoot then + spCallCOBScript(attackerID, unitSuspendAutoAiming[attackerID].overrideScriptID, 0, unitSuspendAutoAiming[attackerID].preferredWeapon) return false end end @@ -68,11 +76,12 @@ local function manualCommandIssued(attackerID) return returnTargetTable end local setTargetData = ggGetUnitTarget(attackerID) or {} - if type(setTargetData) ~= "number" and setTargetData[1] then - returnTargetTable = setTargetData + if type(setTargetData) == "number" then + returnTargetTable[1] = setTargetData return returnTargetTable + else + return setTargetData end - return {} end function gadget:UnitFinished(unitID, unitDefID, unitTeam) @@ -81,7 +90,8 @@ function gadget:UnitFinished(unitID, unitDefID, unitTeam) unitDefID = unitDefID, preferredWeapon = unitDefsWithSmartWeapons[unitDefID].preferredWeapon, deferredWeapon = unitDefsWithSmartWeapons[unitDefID].deferredWeapon, - overrideScriptID = Spring.GetCOBScriptID(unitID, "overrideAimingState") + overrideScriptID = Spring.GetCOBScriptID(unitID, "overrideAimingState"), + overrideExpirationFrame = gameFrame + innitializeExpirationFrames } end end @@ -92,6 +102,7 @@ end function gadget:GameFrame(frame) if frame % frameCheckModulo == 3 then + gameFrame = frame for attackerID in pairs(unitSuspendAutoAiming) do local targetData = manualCommandIssued(attackerID) weaponTargettingCheck(attackerID, targetData)