From 2882b3e143e38e196ce5f505d6ed802fbe1c7d23 Mon Sep 17 00:00:00 2001 From: saurtron Date: Fri, 20 Dec 2024 03:05:58 +0100 Subject: [PATCH 1/6] Fix typo hasVBO -> hasFBO. (#4044) --- common/platformFunctions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/platformFunctions.lua b/common/platformFunctions.lua index 58a2e7d5e9..07c3de43d8 100644 --- a/common/platformFunctions.lua +++ b/common/platformFunctions.lua @@ -35,7 +35,7 @@ local function checkRequires(allRequires) return false elseif req == 'shaders' and not hasShaders then return false - elseif req == 'fbo' and not hasVBO then + elseif req == 'fbo' and not hasFBO then return false end end From e4648fb9f721e2dfafd000df4acf23b1c434fa40 Mon Sep 17 00:00:00 2001 From: saurtron Date: Fri, 20 Dec 2024 03:22:56 +0100 Subject: [PATCH 2/6] Add missing Test.expectCallin to test_wait test example. (#4046) --- luaui/Widgets/TestsExamples/test_utilities/test_wait.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/luaui/Widgets/TestsExamples/test_utilities/test_wait.lua b/luaui/Widgets/TestsExamples/test_utilities/test_wait.lua index c01fb82b6b..78140bea0c 100644 --- a/luaui/Widgets/TestsExamples/test_utilities/test_wait.lua +++ b/luaui/Widgets/TestsExamples/test_utilities/test_wait.lua @@ -1,5 +1,6 @@ function setup() Test.clearMap() + Test.expectCallin("UnitCreated") end function cleanup() From 09fca80f495bd9d0227880241ab245707eea090f Mon Sep 17 00:00:00 2001 From: saurtron Date: Fri, 20 Dec 2024 14:25:00 +0100 Subject: [PATCH 3/6] Fix shutdown from cmd_extractor_snap when WG.DrawUnitShapeGL4 not available. (#4047) Fix shutdown from cmd_extractor_snap when WG.DrawUnitShapeGL4 not available. --- luaui/Widgets/cmd_extractor_snap.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/luaui/Widgets/cmd_extractor_snap.lua b/luaui/Widgets/cmd_extractor_snap.lua index 7e982dd9df..852c0064d5 100644 --- a/luaui/Widgets/cmd_extractor_snap.lua +++ b/luaui/Widgets/cmd_extractor_snap.lua @@ -323,5 +323,8 @@ end function widget:Shutdown() + if not WG.DrawUnitShapeGL4 then + return + end clear() end From 8aeb54ed9290f460c3cf4f91935a058e72a2c462 Mon Sep 17 00:00:00 2001 From: WatchTheFort <36827423+WatchTheFort@users.noreply.github.com> Date: Fri, 20 Dec 2024 11:10:38 -0500 Subject: [PATCH 4/6] Revert "Tweaks and improvement to declutter defense-ranges" (#4049) Revert "Tweaks and improvement to declutter defense-ranges (#3732)" This reverts commit 00678b76f9a06f1daf84d8b7483cbd044cbf7756. --- .../Shaders/attack_range_gl4.vert.glsl | 19 +- .../weapon_range_rings_unified_gl4.frag.glsl | 39 -- .../weapon_range_rings_unified_gl4.vert.glsl | 457 ------------------ luaui/Widgets/gui_anti_ranges.lua | 2 +- luaui/Widgets/gui_attackrange_gl4.lua | 227 ++++----- luaui/Widgets/gui_defenserange.lua | 2 +- luaui/Widgets/gui_defenserange_gl4.lua | 417 ++++++++++++---- units/ArmBots/T2/armaak.lua | 3 - units/ArmBuildings/LandUtil/armmine1.lua | 5 +- units/ArmBuildings/LandUtil/armmine2.lua | 1 - units/ArmBuildings/LandUtil/armmine3.lua | 1 - units/ArmBuildings/SeaUtil/armfmine3.lua | 1 - units/ArmGantry/armthor.lua | 3 - units/ArmShips/T2/armbats.lua | 3 - units/ArmShips/T2/armepoch.lua | 12 - units/ArmShips/T2/armlship.lua | 1 - units/ArmShips/T2/armmship.lua | 1 - units/ArmShips/armpship.lua | 4 - units/CorAircraft/T2/corcrwh.lua | 6 - units/CorBots/T2/coraak.lua | 12 - units/CorBuildings/LandUtil/cormine1.lua | 1 - units/CorBuildings/LandUtil/cormine2.lua | 1 - units/CorBuildings/LandUtil/cormine3.lua | 1 - units/CorBuildings/SeaUtil/corfmine3.lua | 1 - units/CorGantry/corjugg.lua | 6 - units/CorGantry/corkorg.lua | 1 - units/CorShips/T2/corbats.lua | 3 - units/CorShips/T2/corblackhy.lua | 7 - units/CorShips/T2/cormship.lua | 1 - units/Legion/Air/T2 Air/legfort.lua | 6 - units/Legion/Air/T2 Air/legheavydrone.lua | 3 - units/Legion/Air/T2 Air/legionnaire.lua | 3 - units/Legion/Air/T2 Air/legvenator.lua | 3 - units/Legion/Air/legdrone.lua | 3 - units/Legion/Defenses/legbombard.lua | 1 - units/Legion/Ships/leghastatus.lua | 3 - units/Legion/Ships/leghastatusalt.lua | 3 - units/Legion/Ships/legportent.lua | 3 - units/Legion/T3/legpede.lua | 3 - 39 files changed, 403 insertions(+), 866 deletions(-) delete mode 100644 luaui/Widgets/Shaders/weapon_range_rings_unified_gl4.frag.glsl delete mode 100644 luaui/Widgets/Shaders/weapon_range_rings_unified_gl4.vert.glsl diff --git a/luaui/Widgets/Shaders/attack_range_gl4.vert.glsl b/luaui/Widgets/Shaders/attack_range_gl4.vert.glsl index 1929ba2976..1b84b8f84a 100644 --- a/luaui/Widgets/Shaders/attack_range_gl4.vert.glsl +++ b/luaui/Widgets/Shaders/attack_range_gl4.vert.glsl @@ -19,8 +19,6 @@ uniform float lineAlphaUniform = 1.0; uniform float cannonmode = 0.0; uniform float fadeDistOffset = 0.0; uniform float drawMode = 0.0; -uniform float inMiniMap = 0.0; - uniform sampler2D heightmapTex; uniform sampler2D losTex; // hmm maybe? @@ -145,7 +143,7 @@ void main() { // rotate the circle into unit space, wierd that it has to be rotated on other direction float maxAngleDif = 1; float mainDirDegrees = 0; - if (MAXANGLEDIF > 0.0) { + if (MAXANGLEDIF != 0) { maxAngleDif = fract(MAXANGLEDIF);// goes from 0.0 to 1.0, where 0.25 would mean a 90 deg cone mainDirDegrees = MAXANGLEDIF - maxAngleDif;// Is the offset in degrees. } @@ -251,22 +249,14 @@ void main() { //--- DISTANCE FADE --- vec4 camPos = cameraViewInv[3]; - - // Note that this is not the same as the distance from the unit to the camera, but the distance from the circle to the camera float distToCam = length(modelWorldPos.xyz - camPos.xyz); //dist from cam // FadeStart, FadeEnd, StartAlpha, EndAlpha float fadeDist = visibility.y - visibility.x; - if (ISDGUN > 0.5) { FADEALPHA = clamp((visibility.y + fadeDistOffset + 1000 - distToCam)/(fadeDist),visibility.w,visibility.z); } else { FADEALPHA = clamp((visibility.y + fadeDistOffset - distToCam)/(fadeDist),visibility.w,visibility.z); } - - if (inMiniMap> 0.5){ - FADEALPHA = 1.0; - } - //FADEALPHA = clamp((visibility.y + fadeDistOffset - distToCam)/(fadeDist),visibility.w,visibility.z); //--- Optimize by anything faded out getting transformed back to origin with 0 range? @@ -307,12 +297,7 @@ void main() { //worldPos = circleWorldPos; //worldPos.a = RANGE; alphaControl.x = circlepointposition.z; // save circle progress here - - if (inMiniMap < 0.5) { - gl_Position = cameraViewProj * vec4(circleWorldPos.xyz, 1.0); - } else { - gl_Position = mmDrawViewProj * vec4(circleWorldPos.xyz, 1.0); - } + gl_Position = cameraViewProj * vec4(circleWorldPos.xyz, 1.0); //lets blend the alpha here, and save work in FS: float outalpha = OUTOFBOUNDSALPHA * (MOUSEALPHA + FADEALPHA * lineAlphaUniform); diff --git a/luaui/Widgets/Shaders/weapon_range_rings_unified_gl4.frag.glsl b/luaui/Widgets/Shaders/weapon_range_rings_unified_gl4.frag.glsl deleted file mode 100644 index 167f29d969..0000000000 --- a/luaui/Widgets/Shaders/weapon_range_rings_unified_gl4.frag.glsl +++ /dev/null @@ -1,39 +0,0 @@ -#version 330 - -#extension GL_ARB_uniform_buffer_object : require -#extension GL_ARB_shading_language_420pack: require -// This shader is (c) Beherith (mysterme@gmail.com), released under the MIT license - -//__DEFINES__ - -#line 20000 - -uniform float selUnitCount = 1.0; -uniform float selBuilderCount = 1.0; -uniform float drawAlpha = 1.0; -uniform float drawMode = 0.0; - -//_ENGINEUNIFORMBUFFERDEFS__ - -in DataVS { - flat vec4 v_blendedcolor; -}; - -out vec4 fragColor; - -void main() { - - fragColor = v_blendedcolor; - // For testing: - #if (DEBUG == 1) - if (fract(gl_FragCoord.x * 0.125) < 0.4) { - #if (STATICUNITS == 0) - fragColor.rgba *= 0.0; - #endif - }else{ - #if(STATICUNITS == 1) - fragColor.rgba *= 0.0; - #endif - } - #endif -} \ No newline at end of file diff --git a/luaui/Widgets/Shaders/weapon_range_rings_unified_gl4.vert.glsl b/luaui/Widgets/Shaders/weapon_range_rings_unified_gl4.vert.glsl deleted file mode 100644 index d526f6f01b..0000000000 --- a/luaui/Widgets/Shaders/weapon_range_rings_unified_gl4.vert.glsl +++ /dev/null @@ -1,457 +0,0 @@ - -#version 420 -#extension GL_ARB_uniform_buffer_object : require -#extension GL_ARB_shader_storage_buffer_object : require -#extension GL_ARB_shading_language_420pack: require -// This shader is (c) Beherith (mysterme@gmail.com), released under the MIT license -#line 10000 - -//__DEFINES__ - -layout (location = 0) in vec4 circlepointposition; // x,y in range [-1,1], progress in range [0,1] -layout (location = 1) in vec4 posscale; // abs pos for static units, offset for dynamic units, scale is actual range, Y is turretheight -layout (location = 2) in vec4 color1; // Base color for the circle -layout (location = 3) in vec4 visibility; // FadeStart, FadeEnd, StartAlpha, EndAlpha -layout (location = 4) in vec4 projectileParams; // projectileSpeed, iscylinder!!!! , heightBoostFactor , heightMod -layout (location = 5) in vec4 additionalParams; // groupselectionfadescale, weaponType, ISDGUN, MAXANGLEDIF -layout (location = 6) in uvec4 instData; - -uniform float lineAlphaUniform = 1.0; -uniform float cannonmode = 0.0; -uniform float fadeDistOffset = 0.0; -uniform float inMiniMap = 0.0; - - -uniform float selUnitCount = 1.0; -uniform float selBuilderCount = 1.0; -uniform float drawAlpha = 1.0; -uniform float drawMode = 0.0; - - -uniform sampler2D heightmapTex; -uniform sampler2D losTex; // hmm maybe? -uniform sampler2D mapNormalTex; // hmm maybe? - -// Ease-of-use defines for the vertex shader outputs -#define V_CIRCLEPROGRESS v_params.x -#define V_GROUPSELECTIONFADESCALE v_params.y -#define V_WEAPONTYPE v_params.z - -out DataVS { - flat vec4 v_blendedcolor; -}; - -//__ENGINEUNIFORMBUFFERDEFS__ - -#if (STATICUNITS == 0) - struct SUniformsBuffer { - uint composite; // u8 drawFlag; u8 unused1; u16 id; - - uint unused2; - uint unused3; - uint unused4; - - float maxHealth; - float health; - float unused5; - float unused6; - - vec4 drawPos; // Note that this is map height at unit.xz - vec4 speed; - vec4[4] userDefined; //can't use float[16] because float in arrays occupies 4 * float space - }; - - layout(std140, binding=1) readonly buffer UniformsBuffer { - SUniformsBuffer uni[]; - }; - - #define UNITID (uni[instData.y].composite >> 16) -#endif - -#line 11000 - -vec2 inverseMapSize = 1.0 / mapSize.xy; - -float heightAtWorldPos(vec2 w){ - // Some texel magic to make the heightmap tex perfectly align: - const vec2 heightmaptexel = vec2(8.0, 8.0); - w += vec2(-8.0, -8.0) * (w * inverseMapSize) + vec2(4.0, 4.0) ; - - vec2 uvhm = clamp(w, heightmaptexel, mapSize.xy - heightmaptexel); - uvhm = uvhm * inverseMapSize; - - return texture(heightmapTex, uvhm, 0.0).x; -} - -vec4 normalsAndHeightAtWorldPos(vec2 w){ - // Some texel magic to make the heightmap tex perfectly align: - // Some texel magic to make the heightmap tex perfectly align: - const vec2 heightmaptexel = vec2(8.0, 8.0); - w += vec2(-8.0, -8.0) * (w * inverseMapSize) + vec2(4.0, 4.0) ; - - vec2 uvhm = clamp(w, heightmaptexel, mapSize.xy - heightmaptexel); - uvhm = uvhm * inverseMapSize; - vec4 heightAndNormal = vec4(0.0); - heightAndNormal.w = texture(mapNormalTex, uvhm, 0.0).x; - heightAndNormal.xz = texture(mapNormalTex, uvhm, 0.1).ra; - heightAndNormal.y = 1.0 - sqrt(1.0 - dot(heightAndNormal.xz, heightAndNormal.xz)); - return heightAndNormal; -} - -float GetRangeFactor(float projectileSpeed) { // returns >0 if weapon can shoot here, <0 if it cannot, 0 if just right - // on first run, with yDiff = 0, what do we get? - float speed2d = projectileSpeed * 0.707106; - float gravity = 120.0 * (0.001111111); - return ((speed2d * speed2d) * 2.0 ) / (gravity); -} - -float GetRange2DCannon(float yDiff,float projectileSpeed,float rangeFactor,float heightBoostFactor) { // returns >0 if weapon can shoot here, <0 if it cannot, 0 if just right - // on first run, with yDiff = 0, what do we get? - - //float factor = 0.707106; - float smoothHeight = 100.0; - float speed2d = projectileSpeed*0.707106; - float speed2dSq = speed2d * speed2d; - float gravity = -1.0* (120.0 /900); - - if (heightBoostFactor < 0){ - heightBoostFactor = (2.0 - rangeFactor) / sqrt(rangeFactor); - } - - if (yDiff < -100.0){ - yDiff = yDiff * heightBoostFactor; - }else { - if (yDiff < 0.0) { - yDiff = yDiff * (1.0 + (heightBoostFactor - 1.0 ) * (-1.0 * yDiff) * 0.01); - } - } - - float root1 = speed2dSq + 2 * gravity *yDiff; - if (root1 < 0.0 ){ - return 0.0; - }else{ - return rangeFactor * ( speed2dSq + speed2d * sqrt( root1 ) ) / (-1.0 * gravity); - } -} - -vec2 rotate2D(vec2 v, float a) { - float s = sin(a); - float c = cos(a); - mat2 m = mat2(c, s, -s, c); - return m * v; -} - -//float heightMod  default: 0.2 (0.8 for #Cannon, 1.0 for #BeamLaser and #LightningCannon) -//Changes the spherical weapon range into an ellipsoid. Values above 1.0 mean the weapon cannot target as high as it can far, values below 1.0 mean it can target higher than it can far. For example 0.5 would allow the weapon to target twice as high as far. - -//float heightBoostFactor default: -1.0 -//Controls the boost given to range by high terrain. Values > 1.0 result in increased range, 0.0 means the cannon has fixed range regardless of height difference to target. Any value < 0.0 (i.e. the default value) result in an automatically calculated value based on range and theoretical maximum range. - -// Ease of use defines for the vertex shader inputs: -#define RANGE posscale.w -#define TURRETHEIGHT posscale.y - -#define PROJECTILESPEED projectileParams.x -#define ISCYLINDER projectileParams.y -#define HEIGHTBOOSTFACTOR projectileParams.z -#define HEIGHTMOD projectileParams.w - -#define GROUPSELECTIONFADESCALE additionalParams.x -#define WEAPONTYPE additionalParams.y -#define ISDGUN additionalParams.z -#define MAXANGLEDIF additionalParams.w - -#define FADESTART visibility.x -#define FADEEND visibility.y -#define STARTALPHA visibility.z -#define ENDALPHA visibility.w - -#define UNUSEDALPHA alphaControl.x -#define OUTOFBOUNDSALPHA alphaControl.y -#define FADEALPHA alphaControl.z -#define MOUSEALPHA alphaControl.w - -#define SELECTEDNESS uni[instData.y].userDefined[1].z - -bool isSphereVisible(vec3 position, float radius) -{ - vec4 planes[6]; - mat4 m = cameraViewProj; - - // Extract the frustum planes from the combined view-projection matrix - planes[0] = m[3] + m[0]; // Left plane - planes[1] = m[3] - m[0]; // Right plane - planes[2] = m[3] + m[1]; // Bottom plane - planes[3] = m[3] - m[1]; // Top plane - planes[4] = m[3] + m[2]; // Near plane - planes[5] = m[3] - m[2]; // Far plane - - // Normalize the plane equations - for(int i = 0; i < 6; i++) - { - float length = length(planes[i].xyz); - planes[i] /= length; - } - - // Check if the sphere is outside any of the frustum planes - for(int i = 0; i < 6; i++) - { - float distance = dot(planes[i].xyz, position) + planes[i].w; - if(distance < -radius) - return false; // Sphere is completely outside this plane - } - - return true; // Sphere is at least partially inside the frustum -} - -void main() { - vec4 circleWorldPos = vec4(1.0); - vec3 modelWorldPos = vec3(0.0); - float maxAngleDif = 1; - float mainDirDegrees = 0; - vec4 circleprogress = vec4(0.0); - #if (STATICUNITS == 1) - modelWorldPos = posscale.xyz; - circleWorldPos.xz = circlepointposition.xy * RANGE + posscale.xz; - #else - // Get the center pos of the unit - modelWorldPos = uni[instData.y].drawPos.xyz; - - // The turret is a bit higher up than drawPos.y (which is the ground pos) - modelWorldPos.y += TURRETHEIGHT; - - // Get its heading - float unitHeading = uni[instData.y].drawPos.w ; - - circleprogress.xy = circlepointposition.xy; - // find angle between unit Heading and circleprogress.xy - //unitHeading is -pi to +pi, with zero on z+, and increasing towards x+ - //circleheading is -pi to +pi, with zero z-, and increasing towards x+ - - // rotate the circle into unit space, wierd that it has to be rotated on other direction - if (MAXANGLEDIF > 0.0) { - maxAngleDif = fract(MAXANGLEDIF);// goes from 0.0 to 1.0, where 0.25 would mean a 90 deg cone - mainDirDegrees = MAXANGLEDIF - maxAngleDif;// Is the offset in degrees. - } - circleprogress.xy = rotate2D(circleprogress.xy, (3.141592 -1.0*unitHeading + mainDirDegrees * 3.141592 / 180.0)); - if (ISDGUN > 0.5) { - circleWorldPos.xz = circleprogress.xy * RANGE * 1.05 + modelWorldPos.xz; - } else { - circleWorldPos.xz = circleprogress.xy * RANGE + modelWorldPos.xz; - } - #endif - - - - circleprogress.w = circlepointposition.z; - v_blendedcolor = color1; - - #if (STATICUNITS == 1) - //gl_Position = cameraViewProj * vec4(circleWorldPos.xyz, 1.0); return; - #endif - - vec4 alphaControl = vec4(1.0); - - // get heightmap - circleWorldPos.y = heightAtWorldPos(circleWorldPos.xz); - - - if (cannonmode > 0.5){ - - // BAR only has 3 distinct ballistic projectiles, heightBoostFactor is only a handful from -1 to 2.8 and 6 and 8 - // gravity we can assume to be linear - - float heightDiff = (circleWorldPos.y - modelWorldPos.y) * 0.5; - - float rangeFactor = RANGE / GetRangeFactor(PROJECTILESPEED); //correct - if (rangeFactor > 1.0 ) rangeFactor = 1.0; - if (rangeFactor <= 0.0 ) rangeFactor = 1.0; - float radius = RANGE;// - heightDiff; - float adjRadius = GetRange2DCannon(heightDiff * HEIGHTMOD, PROJECTILESPEED, rangeFactor, HEIGHTBOOSTFACTOR); - float adjustment = radius * 0.5; - float yDiff = 0; - float adds = 0; - //for (int i = 0; i < mod(timeInfo.x/8,16); i ++){ //i am a debugging god - for (int i = 0; i < 16; i ++){ - if (adjRadius > radius){ - radius = radius + adjustment; - adds = adds + 1; - }else{ - radius = radius - adjustment; - adds = adds - 1; - } - adjustment = adjustment * 0.5; - circleWorldPos.xz = circleprogress.xy * radius + modelWorldPos.xz; - float newY = heightAtWorldPos(circleWorldPos.xz ); - yDiff = abs(circleWorldPos.y - newY); - circleWorldPos.y = max(0, newY); - heightDiff = circleWorldPos.y - modelWorldPos.y; - adjRadius = GetRange2DCannon(heightDiff * HEIGHTMOD, PROJECTILESPEED, rangeFactor, HEIGHTBOOSTFACTOR); - } - }else{ - if (ISCYLINDER < 0.5){ // isCylinder - //simple implementation, 4 samples per point - //for (int i = 0; i -20) { // for submerged units, try to keep the ranges above the water for clarity - modelWorldPos.y = max(1, modelWorldPos.y); - circleWorldPos.y = max(1, circleWorldPos.y); - } - - - - // -- HANDLE MAXANGLEDIFF - // If the unit cant fire in that direction due to maxanglediff constraints, then put the point back to modelWorldPos - // Also, dont - // convert current circleprogress to relative heading: - float relheadingradians = abs(((circleprogress.w - 0.5)) * 2); - if (MAXANGLEDIF != 0.0) { - if(relheadingradians > maxAngleDif){ - circleWorldPos.xyz = modelWorldPos.xyz; - } - OUTOFBOUNDSALPHA = 1.0; - } - - circleWorldPos.y += 4; // lift it from the ground - - - //--- DISTANCE FADE --- - vec4 camPos = cameraViewInv[3]; - - // Note that this is not the same as the distance from the unit to the camera, but the distance from the circle to the camera - float distToCam = length(modelWorldPos.xyz - camPos.xyz) ; //dist from cam - // FadeStart, FadeEnd, StartAlpha, EndAlpha - float fadeDist = FADEEND - FADESTART; - - // TODO VALIDATE - if (ISDGUN > 0.5) { - FADEALPHA = clamp((FADEEND + fadeDistOffset + 1000 - distToCam)/(fadeDist), ENDALPHA, STARTALPHA); - } else { - FADEALPHA = clamp((FADEEND + fadeDistOffset - distToCam)/(fadeDist), ENDALPHA, STARTALPHA); - } - // -- IN-SHADER MOUSE-POS BASED HIGHLIGHTING - float disttomousefromunit = 1.0 - smoothstep(48, 64, length(modelWorldPos.xz - mouseWorldPos.xz)); - // this will be positive if in mouse, negative else - float highlightme = clamp( (disttomousefromunit ) + 0.0, 0.0, 1.0); - // Note that this doesnt really work well with boundary-only stenciling, due to random draw order. - MOUSEALPHA = (0.1 + 0.5 * step(0.5,drawMode)) * highlightme; - - - if (inMiniMap> 0.5){ - // No extra fade control when on the minimap - FADEALPHA = 1.0; - }else{ - // TODO if the sphere were to be completely faded out, dont draw it at all: - if (highlightme < 0.0 ){ - if (FADESTART < FADEEND) { - // Rings that fade out on distance - if ((distToCam + RANGE) > FADEEND) { - FADEALPHA = 0.0; - circleWorldPos.xz = modelWorldPos.xz; - } - }else { - // Rings that fade out when close to the camera - // TODO ANTINUKES! - if ((distToCam - RANGE) < FADEEND) { - FADEALPHA = 0.0; - //circleWorldPos.xz = modelWorldPos.xz; - } - } - - //--- Optimize by anything faded out getting transformed back to origin with 0 range? - //seems pretty ok! - - //if a sphere at modelworldpos.xyz, with range poscale.w is out of the viewport, set visible to false: - if (isSphereVisibleXY(vec4(modelWorldPos.xyz, 1.0), posscale.w * 3.0 )){ - //circleWorldPos.xz = modelWorldPos.xz; - } - } - } - - //FADEALPHA = clamp((FADEEND + fadeDistOffset - distToCam)/(fadeDist), ENDALPHA, STARTALPHA); - - - if (cannonmode > 0.5){ - // cannons should fade distance based on their range - //float cvmin = max(FADESTART + fadeDistOffset, 2* RANGE); - //float cvmax = max(FADEEND + fadeDistOffset, 4* RANGE); - //FADEALPHA = clamp((cvmin - distToCam)/(cvmax - cvmin + 1.0),STARTALPHA , ENDALPHA); - } - - v_blendedcolor = color1; - - // -- DARKEN OUT OF LOS - //vec4 losTexSample = texture(losTex, vec2(circleWorldPos.x / mapSize.z, circleWorldPos.z / mapSize.w)); // lostex is PO2 - //float inlos = dot(losTexSample.rgb,vec3(0.33)); - //inlos = clamp(inlos*5 -1.4 , 0.5,1.0); // fuck if i know why, but change this if LOSCOLORS are changed! - //v_blendedcolor.rgb *= inlos; - - // --- YES FOG - float fogDist = length((cameraView * vec4(circleWorldPos.xyz,1.0)).xyz); - float fogFactor = clamp((fogParams.y - fogDist) * fogParams.w, 0, 1); - v_blendedcolor.rgb = mix(fogColor.rgb, vec3(v_blendedcolor), fogFactor); - - - - - - // ------------ dump the stuff for FS -------------------- - //V_CIRCLEPROGRESS = circlepointposition.z; // save circle progress here - - - if (inMiniMap < 0.5) { - gl_Position = cameraViewProj * vec4(circleWorldPos.xyz, 1.0); - //pull 16 elmos forward in Z: - gl_Position.z = (gl_Position.z) - 128.0 / (gl_Position.w); // send 16 elmos forward in Z - } else { - gl_Position = mmDrawViewProj * vec4(circleWorldPos.xyz, 1.0); - } - - //lets blend the alpha here, and save work in FS: - float outalpha = OUTOFBOUNDSALPHA * (MOUSEALPHA + FADEALPHA * lineAlphaUniform); - v_blendedcolor.a *= outalpha ; - if (ISDGUN > 0.5) { - v_blendedcolor.a = clamp(v_blendedcolor.a * 3, 0.1, 1.0); - } - // Additional unituniform based selectedness metrics: - - float vs_selunitcount = selUnitCount; - // -- nano is 2 - if(WEAPONTYPE == 2.0) { - vs_selunitcount = selBuilderCount; - } - vs_selunitcount = clamp(selUnitCount, 1, 25); - - float innerRingDim = GROUPSELECTIONFADESCALE * 0.1 * vs_selunitcount; - float finalAlpha = drawAlpha; - if(drawMode == 2.0) { - finalAlpha = drawAlpha / pow(innerRingDim, 2); - } - finalAlpha = clamp(finalAlpha, 0.0, 1.0); - v_blendedcolor.a *= finalAlpha; - - //vec4 heightAndNormal = normalsAndHeightAtWorldPos(circleWorldPos.xz); - //v_blendedcolor.rgb = heightAndNormal.xyz * 0.5 + 0.5; - //v_blendedcolor.rgb = vec3(fract(distToCam/100)); -} \ No newline at end of file diff --git a/luaui/Widgets/gui_anti_ranges.lua b/luaui/Widgets/gui_anti_ranges.lua index 6c4db033fe..0d45816475 100644 --- a/luaui/Widgets/gui_anti_ranges.lua +++ b/luaui/Widgets/gui_anti_ranges.lua @@ -8,7 +8,7 @@ function widget:GetInfo() license = "GNU GPL, v2 or later", version = 4, layer = 5, - enabled = false + enabled = true } end diff --git a/luaui/Widgets/gui_attackrange_gl4.lua b/luaui/Widgets/gui_attackrange_gl4.lua index 09af4eb245..16600f2cbd 100644 --- a/luaui/Widgets/gui_attackrange_gl4.lua +++ b/luaui/Widgets/gui_attackrange_gl4.lua @@ -16,9 +16,6 @@ function widget:GetInfo() } end -------------------------------------- -local autoReload = false - --------------------------------------------------------------------------------------------------------------------------- -- Bindable action: cursor_range_toggle -- The widget's individual unit type's display setup is saved in LuaUI/config/AttackRangeConfig2.lua @@ -38,7 +35,7 @@ local buttonConfig = { local colorConfig = { drawStencil = true, -- whether to draw the outer, merged rings (quite expensive!) - cannon_separate_stencil = true, -- set to true to have cannon and ground be on different stencil mask + cannon_separate_stencil = false, -- set to true to have cannon and ground be on different stencil mask drawInnerRings = true, -- whether to draw inner, per attack rings (very cheap) externalalpha = 0.80, -- alpha of outer rings @@ -47,54 +44,37 @@ local colorConfig = { outer_fade_height_difference = 2500, -- this is the height difference at which the outer ring starts to fade out compared to inner rings ground = { color = { 1.0, 0.22, 0.05, 0.60 }, - fadeparams = { 1500, 3200, 1.0, 0.0 }, -- FadeStart, FadeEnd, StartAlpha, EndAlpha + fadeparams = { 1500, 2200, 1.0, 0.0 }, -- FadeStart, FadeEnd, StartAlpha, EndAlpha groupselectionfadescale = 0.75, externallinethickness = 3.0, - internallinethickness = 1.8, - minimapexternallinethickness = 1.0, - minimapinternallinethickness = 0.5, + internallinethickness = 2.0, }, nano = { - color = { 0.24, 1.0, 0.2, 0.60 }, + color = { 0.24, 1.0, 0.2, 0.40 }, fadeparams = { 2000, 4000, 1.0, 0.0 }, -- FadeStart, FadeEnd, StartAlpha, EndAlpha groupselectionfadescale = 0.05, externallinethickness = 3.0, internallinethickness = 2.0, - minimapexternallinethickness = 1.0, - minimapinternallinethickness = 0.5, }, AA = { color = { 0.8, 0.44, 2.0, 0.40 }, - fadeparams = { 1500, 3200, 1.0, 0.0 }, -- FadeStart, FadeEnd, StartAlpha, EndAlpha + fadeparams = { 1500, 2200, 1.0, 0.0 }, -- FadeStart, FadeEnd, StartAlpha, EndAlpha groupselectionfadescale = 0.75, - externallinethickness = 3.0, - internallinethickness = 1.8, - minimapexternallinethickness = 1.5, - minimapinternallinethickness = 0.5, + externallinethickness = 2.5, + internallinethickness = 2.0, }, cannon = { - color = {1.0, 0.22, 0.05, 0.60}, - fadeparams = { 1500, 3600, 1.0, 0.0 }, -- FadeStart, FadeEnd, StartAlpha, EndAlpha + color = { 1.0, 0.22, 0.05, 0.60 }, + fadeparams = { 1500, 2200, 1.0, 0.0 }, -- FadeStart, FadeEnd, StartAlpha, EndAlpha groupselectionfadescale = 0.75, externallinethickness = 3.0, internallinethickness = 2.0, - minimapexternallinethickness = 1.0, - minimapinternallinethickness = 0.5, - }, - lrpc = { - color = {1.0, 0.22, 0.05, 0.60}, - fadeparams = { 5000, 1000, 1.0, 0.5 }, -- FadeStart, FadeEnd, StartAlpha, EndAlpha - groupselectionfadescale = 0.75, - externallinethickness = 3.0, - internallinethickness = 2.0, -- Not used as LRPC is not stencilled - minimapexternallinethickness = 2.0, - minimapinternallinethickness = 0.5, }, } ---------------------------------- local show_selected_weapon_ranges = true -local weaponTypeMap = { 'ground', 'nano', 'AA', 'cannon', 'lrpc' } +local weaponTypeMap = { 'ground', 'nano', 'AA', 'cannon' } local unitDefRings = {} --each entry should be a unitdefIDkey to a table: @@ -200,14 +180,11 @@ local function initializeUnitDefRing(unitDefID) local color = colorConfig[weaponTypeMap[weaponType]].color local fadeparams = colorConfig[weaponTypeMap[weaponType]].fadeparams - local isCylinder = 0 - if (weaponDef.cylinderTargeting) and (weaponDef.cylinderTargeting > 0.0) then - isCylinder = 1 - end + local isCylinder = weaponDef.cylinderTargeting and 1 or 0 local isDgun = (weaponDef.type == "DGun") and 1 or 0 local wName = weaponDef.name - if (weaponDef.type == "AircraftBomb") or (wName:find("bogus")) or weaponDef.customParams.bogus then + if (weaponDef.type == "AircraftBomb") or (wName:find("bogus")) then range = 0 end --Spring.Echo("weaponNum: ".. weaponNum ..", name: " .. tableToString(weaponDef.name)) @@ -230,11 +207,7 @@ local function initializeUnitDefRing(unitDefID) -- maindir "0 1 0" is designed for shooting at feet prevention! local maxangledif = 0 - - -- customParams (note the case), is a table of strings always - if (weapons[weaponNum].maxAngleDif > -1) and - (not (weaponDef.customParams and weaponDef.customParams.noattackrangearc)) then - --Spring.Echo(weaponDef.customParams)--, weapons[weaponNum].customParams.noattackarc) + if weapons[weaponNum].maxAngleDif > -1 then local offsetdegrees = 0 local difffract = 0 @@ -264,7 +237,7 @@ local function initializeUnitDefRing(unitDefID) maxangledif = maxangledif + difffract else - end + end @@ -275,18 +248,18 @@ local function initializeUnitDefRing(unitDefID) --for k,v in pairs(weapons[weaponNum]) do Spring.Echo(k,v)end end - --if weapons[weaponNum].maxAngleDif then Spring.Echo(weapons[weaponNum].maxAngleDif,'for',weaponDef.name, 'saved as',maxangledif ) end - - local ringParams = { range, color[1], color[2], color[3], color[4], --5 - fadeparams[1], fadeparams[2], fadeparams[3], fadeparams[4], --9 - weaponDef.projectilespeed or 1, --10 - isCylinder,-- and 1 or 0, (11) - weaponDef.heightBoostFactor or 0, --12 - weaponDef.heightMod or 0, --13 - groupselectionfadescale, --14 - weaponType, --15 - isDgun, --16 - maxangledif --17 + --if weapons[weaponNum].maxAngleDif then Spring.Echo(weapons[weaponNum].maxAngleDif,'for',weaponDef.name ) end + + local ringParams = { range, color[1], color[2], color[3], color[4], + fadeparams[1], fadeparams[2], fadeparams[3], fadeparams[4], + weaponDef.projectilespeed or 1, + isCylinder, + weaponDef.heightBoostFactor or 0, + weaponDef.heightMod or 0, + groupselectionfadescale, + weaponType, + isDgun, + maxangledif } unitDefRings[unitDefID]['rings'][weaponNum] = ringParams end @@ -358,11 +331,6 @@ local GetActiveCommand = Spring.GetActiveCommand local GetSelectedUnits = Spring.GetSelectedUnits local chobbyInterface -local CMD_ATTACK = CMD.ATTACK -local CMD_FIGHT = CMD.FIGHT -local CMD_AREA_ATTACK = CMD.AREA_ATTACK -local CMD_MANUALFIRE = CMD.MANUALFIRE - function widget:TextCommand(command) local mycommand = false --buttonConfig["enemy"][tag] @@ -399,18 +367,18 @@ local largeCircleSegments = 512 local smallCircleVBO = nil local smallCircleSegments = 128 -local weaponTypeToString = { "ground", "nano", "AA", "cannon", 'lrpc' } +local weaponTypeToString = { "ground", "nano", "AA", "cannon", } local allyenemypairs = { "ally", "enemy" } local attackRangeClasses = { 'enemyground', 'enemyAA', 'enemynano', 'allyground', 'allyAA', 'enemycannon', 'allycannon', - 'allynano', 'allylrpc', 'enemylrpc' } + 'allynano' } local attackRangeVAOs = {} local circleInstanceVBOLayout = { - { id = 1, name = 'posscale', size = 4 }, -- abs pos for static units, offset for dynamic units, scale is actual range, Y is turretheight + { id = 1, name = 'posscale', size = 4 }, -- a vec4 for pos + scale { id = 2, name = 'color1', size = 4 }, -- vec4 the color of this new - { id = 3, name = 'visibility', size = 4 }, --- vec4 FadeStart, FadeEnd, StartAlpha, EndAlpha + { id = 3, name = 'visibility', size = 4 }, --- vec4 heightdrawstart, heightdrawend, fadefactorin, fadefactorout { id = 4, name = 'projectileParams', size = 4 }, --- heightboost gradient - { id = 5, name = 'additionalParams', size = 4 }, --- groupselectionfadescale, weaponType, ISDGUN, MAXANGLEDIF + { id = 5, name = 'additionalParams', size = 4 }, --- groupselectionfadescale, +3 additional reserved { id = 6, name = 'instData', size = 4, type = GL.UNSIGNED_INT }, } @@ -421,17 +389,12 @@ local attackRangeShader = nil local shaderSourceCache = { shaderName = 'Attack Range GL4', - vssrcpath = "LuaUI/Widgets/Shaders/weapon_range_rings_unified_gl4.vert.glsl", - fssrcpath = "LuaUI/Widgets/Shaders/weapon_range_rings_unified_gl4.frag.glsl", - shaderConfig = { - MYGRAVITY = Game.gravity + 0.1, - STATICUNITS = 0, - DEBUG = autoReload and 1 or 0, - }, + vssrcpath = "LuaUI/Widgets/Shaders/attack_range_gl4.vert.glsl", + fssrcpath = "LuaUI/Widgets/Shaders/attack_range_gl4.frag.glsl", + shaderConfig = {MYGRAVITY = Game.gravity + 0.1,}, uniformInt = { heightmapTex = 0, losTex = 1, - mapNormalTex = 2, }, uniformFloat = { lineAlphaUniform = 1, @@ -440,7 +403,6 @@ local shaderSourceCache = { drawMode = 0, selBuilderCount = 1.0, selUnitCount = 1.0, - inMiniMap = 0.0, }, } @@ -449,11 +411,38 @@ local function goodbye(reason) widgetHandler:RemoveWidget() end +local function makeCircleVBO(circleSegments) + circleSegments = circleSegments - 1 -- for po2 buffers + local circleVBO = gl.GetVBO(GL.ARRAY_BUFFER, true) + if circleVBO == nil then goodbye("Failed to create circleVBO") end + + local VBOLayout = { + { id = 0, name = "position", size = 4 }, + } + + local VBOData = {} + + for i = 0, circleSegments do -- this is +1 + VBOData[#VBOData + 1] = math.sin(math.pi * 2 * i / circleSegments) -- X + VBOData[#VBOData + 1] = math.cos(math.pi * 2 * i / circleSegments) -- Y + VBOData[#VBOData + 1] = i / circleSegments -- circumference [0-1] + VBOData[#VBOData + 1] = 0 + end + + circleVBO:Define( + circleSegments + 1, + VBOLayout + ) + circleVBO:Upload(VBOData) + return circleVBO +end + local cacheTable = {} for i = 1, 24 do cacheTable[i] = 0 end -- code for selected units start here + local selectedUnits = {} local selUnits = {} local updateSelection = false @@ -496,19 +485,9 @@ local function AddSelectedUnit(unitID, mouseover) if weapon.onlyTargets and weapon.onlyTargets.vtol then entry.weapons[weaponNum] = 3 -- weaponTypeMap[3] is "AA" elseif weaponDef.type == "Cannon" then - if weaponDef.range > 2000 then - entry.weapons[weaponNum] = 5 -- weaponTypeMap[5] is "lrpc" - else - entry.weapons[weaponNum] = 4 -- weaponTypeMap[4] is "cannon" - end - elseif weaponDef.type == "Melee" then - entry.weapons[weaponNum] = 1 -- weaponTypeMap[1] is "ground" + entry.weapons[weaponNum] = 4 -- weaponTypeMap[4] is "cannon" else - if weaponDef.range > 2000 then - entry.weapons[weaponNum] = 5 - else - entry.weapons[weaponNum] = 1 -- weaponTypeMap[1] is "ground" - end + entry.weapons[weaponNum] = 1 -- weaponTypeMap[1] is "ground" end end end @@ -524,7 +503,7 @@ local function AddSelectedUnit(unitID, mouseover) end - + local x, y, z, mpx, mpy, mpz, apx, apy, apz = spGetUnitPosition(unitID, true, true) --for weaponNum = 1, #weapons do local addedRings = 0 @@ -560,25 +539,8 @@ local function AddSelectedUnit(unitID, mouseover) local ringParams = unitDefRings[unitDefID]['rings'][j] if drawIt and ringParams[1] > 0 then - - local weaponID = j - -- TODO: - -- Weapons aim from their WPY positions, but that can change for e.g. popups! - -- This is quite important to pass in as posscale.y! - -- Need to cache weaponID of the respective weapon for this to work - -- also assumes that weapons are centered onto drawpos - local x, y, z, mpx, mpy, mpz, apx, apy, apz = spGetUnitPosition(unitID, true, true) - local wpx, wpy, wpz, wdx, wdy, wdz = Spring.GetUnitWeaponVectors(unitID, weaponID) - --Spring.Echo("unitID", unitID,"weaponID", weaponID, "y", y, "mpy", mpy,"wpy", wpy) - - -- Now this is a truly terrible hack, we cache each unitDefID's max weapon turret height at position 18 in the table - -- so it only goes up with popups - local turretHeight = math.max(ringParams[18] or 0, (wpy or mpy ) - y) - ringParams[18] = turretHeight - - cacheTable[1] = mpx - cacheTable[2] = turretHeight + cacheTable[2] = mpy cacheTable[3] = mpz local vaokey = allystring .. weaponTypeToString[weaponType] @@ -954,7 +916,7 @@ function widget:RecvLuaMsg(msg, playerID) end end -local drawcounts = {} +local drawcounts = {} local cameraHeightFactor = 0 @@ -963,7 +925,6 @@ local function GetCameraHeightFactor() end local groundnukeair = { "ground", "nano", "AA" } -local cannonlrpc = { "cannon", "lrpc" } local function DRAWRINGS(primitiveType, linethickness) if not show_selected_weapon_ranges and not isBuilding then return end local stencilMask @@ -987,39 +948,29 @@ local function DRAWRINGS(primitiveType, linethickness) attackRangeShader:SetUniform("cannonmode", 1) for i, allyState in ipairs(allyenemypairs) do - for j, wt in ipairs(cannonlrpc) do - if linethickness or wt == 'cannon' then - local atkRangeClass = allyState .. wt - local iT = attackRangeVAOs[atkRangeClass] - local stencilOffset = colorConfig.cannon_separate_stencil and 3 or 0 - stencilMask = 2 ^ (4 * (i - 1) + stencilOffset) -- if 0 then it's on the same as "ground" - drawcounts[stencilMask] = iT.usedElements - if iT.usedElements > 0 then - if linethickness then - glLineWidth(colorConfig[wt][linethickness] * cameraHeightFactor) - end - glStencilMask(stencilMask) - glStencilFunc(GL_NOTEQUAL, stencilMask, stencilMask) - iT.VAO:DrawArrays(primitiveType, iT.numVertices, 0, iT.usedElements, 0) -- +1!!! - end + local atkRangeClass = allyState .. "cannon" + local iT = attackRangeVAOs[atkRangeClass] + local stencilOffset = colorConfig.cannon_separate_stencil and 3 or 0 + stencilMask = 2 ^ (4 * (i - 1) + stencilOffset) -- if 0 then it's on the same as "ground" + drawcounts[stencilMask] = iT.usedElements + if iT.usedElements > 0 then + if linethickness then + glLineWidth(colorConfig['cannon'][linethickness] * cameraHeightFactor) end + glStencilMask(stencilMask) + glStencilFunc(GL_NOTEQUAL, stencilMask, stencilMask) + iT.VAO:DrawArrays(primitiveType, iT.numVertices, 0, iT.usedElements, 0) -- +1!!! end end end -function widget:DrawWorld(inMiniMap) - - if autoReload then - attackRangeShader = LuaShader.CheckShaderUpdates(shaderSourceCache) or attackRangeShader - end - +function widget:DrawWorldPreUnit() if chobbyInterface then return end if not Spring.IsGUIHidden() and (not WG['topbar'] or not WG['topbar'].showingQuit()) then cameraHeightFactor = GetCameraHeightFactor() * 0.5 + 0.5 glTexture(0, "$heightmap") glTexture(1, "$info") - glTexture(2, '$normals') - + -- Stencil Setup -- -- https://learnopengl.com/Advanced-OpenGL/Stencil-testing if colorConfig.drawStencil then @@ -1030,18 +981,17 @@ function widget:DrawWorld(inMiniMap) glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE) -- Set The Stencil Buffer To 1 Where Draw Any Polygon attackRangeShader:Activate() - + attackRangeShader:SetUniform("selUnitCount", selUnitCount) attackRangeShader:SetUniform("selBuilderCount", selBuilderCount) attackRangeShader:SetUniform("drawMode", 0.0) - attackRangeShader:SetUniform("inMiniMap", inMiniMap and 1.0 or 0.0) attackRangeShader:SetUniform("drawAlpha", colorConfig.fill_alpha) attackRangeShader:SetUniform("fadeDistOffset", colorConfig.outer_fade_height_difference) DRAWRINGS(GL_TRIANGLE_FAN) -- FILL THE CIRCLES glLineWidth(math.max(0.1, 4 + math.sin(gameFrame * 0.04) * 10)) glColorMask(true, true, true, true) -- re-enable color drawing - glStencilMask(0) + glStencilMask(0) attackRangeShader:SetUniform("lineAlphaUniform", colorConfig.externalalpha) @@ -1049,20 +999,20 @@ function widget:DrawWorld(inMiniMap) attackRangeShader:SetUniform("drawMode", 1.0) attackRangeShader:SetUniform("drawAlpha", 1.0) - DRAWRINGS(GL_LINE_LOOP, inMiniMap and 'minimapexternallinethickness' or 'externallinethickness') -- DRAW THE OUTER RINGS + DRAWRINGS(GL_LINE_LOOP, 'externallinethickness') -- DRAW THE OUTER RINGS -- This is the correct way to exit out of the stencil mode, to not break drawing of area commands: glStencilTest(false) glStencilMask(255) glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP) glClear(GL_STENCIL_BUFFER_BIT) - -- All the above are needed :() - end + -- All the above are needed :( + end if colorConfig.drawInnerRings then attackRangeShader:SetUniform("lineAlphaUniform", colorConfig.internalalpha) attackRangeShader:SetUniform("drawMode", 2.0) attackRangeShader:SetUniform("fadeDistOffset", 0) - DRAWRINGS(GL_LINE_LOOP, inMiniMap and 'minimapinternallinethickness' or 'internallinethickness') -- DRAW THE INNER RINGS + DRAWRINGS(GL_LINE_LOOP, 'internallinethickness') -- DRAW THE INNER RINGS end attackRangeShader:Deactivate() @@ -1073,13 +1023,6 @@ function widget:DrawWorld(inMiniMap) end end -function widget:DrawInMiniMap() - -- TODO: - -- do a sanity check and dont draw here if there are too many units selected... - widget:DrawWorld(true) -end - - -- Need to add all the callins for handling unit creation/destruction/gift of builders --[[ diff --git a/luaui/Widgets/gui_defenserange.lua b/luaui/Widgets/gui_defenserange.lua index 12f2d17d88..cb54f1c4bc 100644 --- a/luaui/Widgets/gui_defenserange.lua +++ b/luaui/Widgets/gui_defenserange.lua @@ -10,7 +10,7 @@ function widget:GetInfo() date = "October 21, 2007", license = "GNU GPL v2", layer = -100, - enabled = false + enabled = true } end diff --git a/luaui/Widgets/gui_defenserange_gl4.lua b/luaui/Widgets/gui_defenserange_gl4.lua index 3cfa2cc3e8..956f832be4 100644 --- a/luaui/Widgets/gui_defenserange_gl4.lua +++ b/luaui/Widgets/gui_defenserange_gl4.lua @@ -8,7 +8,7 @@ function widget:GetInfo() date = "2021.04.26", license = "Lua: GPLv2, GLSL: (c) Beherith (mysterme@gmail.com)", layer = -100, - enabled = true + enabled = false } end @@ -66,40 +66,40 @@ end local enabledAsSpec = true local buttonConfig = { - ally = { ground = false, air = false, nuke = true }, + ally = { ground = true, air = true, nuke = true }, enemy = { ground = true, air = true, nuke = true } } local colorConfig = { --An array of R, G, B, Alpha drawStencil = true, -- wether to draw the outer, merged rings (quite expensive!) drawInnerRings = true, -- wether to draw inner, per defense rings (very cheap) - externalalpha = 0.7, -- alpha of outer rings - internalalpha = 0.17, -- alpha of inner rings + externalalpha = 0.70, -- alpha of outer rings + internalalpha = 0.0, -- alpha of inner rings distanceScaleStart = 2000, -- Linewidth is 100% up to this camera height - distanceScaleEnd = 8000, -- Linewidth becomes 50% above this camera height + distanceScaleEnd = 4000, -- Linewidth becomes 50% above this camera height ground = { - color = {1.3, 0.18, 0.04, 0.74}, - fadeparams = { 2200, 5500, 1.0, 0.0}, -- FadeStart, FadeEnd, StartAlpha, EndAlpha - externallinethickness = 6.0, + color = {1.0, 0.2, 0.0, 1.0}, + fadeparams = { 2000, 5000, 1.0, 0.0}, -- FadeStart, FadeEnd, StartAlpha, EndAlpha + externallinethickness = 4.0, internallinethickness = 2.0, }, air = { - color = {0.8, 0.44, 1.6, 0.70}, - fadeparams = { 3200, 8000, 0.4, 0.0}, -- FadeStart, FadeEnd, StartAlpha, EndAlpha + color = {0.90, 0.45, 1.2, 1.0}, + fadeparams = { 2000, 5000, 0.4, 0.0}, -- FadeStart, FadeEnd, StartAlpha, EndAlpha externallinethickness = 4.0, internallinethickness = 2.0, }, nuke = { - color = {1.2, 1.0, 0.3, 0.8}, - fadeparams = {6000, 3000, 0.6, 0.0}, -- FadeStart, FadeEnd, StartAlpha, EndAlpha + color = {0.7, 0.8, 1.0, 1.0}, + fadeparams = {5000, 4000, 0.6, 0.0}, -- FadeStart, FadeEnd, StartAlpha, EndAlpha externallinethickness = 4.0, - internallinethickness = 1.0, + internallinethickness = 2.0, }, cannon = { - color = {1.3, 0.18, 0.04, 0.5}, - fadeparams = {7000, 6000, 0.8, 0.0}, -- FadeStart, FadeEnd, StartAlpha, EndAlpha - externallinethickness = 10.0, - internallinethickness = 1.0, + color = {1.0, 0.6, 0.0, 1.0}, + fadeparams = {3000, 6000, 0.8, 0.0}, -- FadeStart, FadeEnd, StartAlpha, EndAlpha + externallinethickness = 4.0, + internallinethickness = 2.0, }, } @@ -192,7 +192,7 @@ local function initUnitList() ['armllt'] = { weapons = { 1 } }, ['armbeamer'] = { weapons = { 1 } }, ['armhlt'] = { weapons = { 1 } }, - ['armguard'] = { weapons = { 1 } }, --4 + ['armguard'] = { weapons = { 4} }, ['armrl'] = { weapons = { 2 } }, --light aa ['armferret'] = { weapons = { 2 } }, ['armcir'] = { weapons = { 2 } }, --chainsaw @@ -204,16 +204,16 @@ local function initUnitList() ['armfflak'] = { weapons = { 2 } }, --floating flak AA ['armatl'] = { weapons = { 1 } }, --adv torpedo launcher - ['armamb'] = { weapons = { 1 } }, --ambusher 4 - ['armpb'] = { weapons = { 1 } }, --pitbull 4 + ['armamb'] = { weapons = { 4 } }, --ambusher + ['armpb'] = { weapons = { 4 } }, --pitbull ['armanni'] = { weapons = { 1 } }, ['armflak'] = { weapons = { 2 } }, ['armmercury'] = { weapons = { 2 } }, ['armemp'] = { weapons = { 1 } }, ['armamd'] = { weapons = { 3 } }, --antinuke - ['armbrtha'] = { weapons = { 4 } }, - ['armvulc'] = { weapons = { 4 } }, + ['armbrtha'] = { weapons = { 4 } }, + ['armvulc'] = { weapons = { 4 } }, -- CORTEX ['cormaw'] = { weapons = { 1 } }, @@ -222,7 +222,7 @@ local function initUnitList() ['corllt'] = { weapons = { 1 } }, ['corhllt'] = { weapons = { 1 } }, ['corhlt'] = { weapons = { 1 } }, - ['corpun'] = { weapons = { 1} }, --4 + ['corpun'] = { weapons = { 4} }, ['corrl'] = { weapons = { 2 } }, ['cormadsam'] = { weapons = { 2 } }, ['corerad'] = { weapons = { 2 } }, @@ -235,15 +235,15 @@ local function initUnitList() ['corfrt'] = { weapons = { 2 } }, --floating rocket laucher ['corenaa'] = { weapons = { 2 } }, --floating flak AA - ['cortoast'] = { weapons = { 1 } }, --4 + ['cortoast'] = { weapons = { 4 } }, ['corvipe'] = { weapons = { 1 } }, ['cordoom'] = { weapons = { 1, 1, 1} }, ['corflak'] = { weapons = { 2 } }, ['corscreamer'] = { weapons = { 2 } }, - ['cortron'] = { weapons = { 4 } }, + ['cortron'] = { weapons = { 1 } }, ['corfmd'] = { weapons = { 3 } }, - ['corint'] = { weapons = { 4 } }, - ['corbuzz'] = { weapons = { 4 } }, + ['corint'] = { weapons = { 4 } }, + ['corbuzz'] = { weapons = { 4 } }, ['armscab'] = { weapons = { 3 } }, ['armcarry'] = { weapons = { 3 } }, @@ -254,20 +254,7 @@ local function initUnitList() -- LEGION ['legabm'] = { weapons = { 3 } }, --antinuke - ['legrampart'] = { weapons = { 3, 1 } }, --rampart - ['legacluster'] = { weapons = { 1 } }, --T2 arty - ['leghive'] = { weapons = { 1 } }, --Drone-defense - ['legmg'] = { weapons = { 1 } }, --ground-AA MG defense - ['legbombard'] = { weapons = { 1 } }, --Grenadier defense - ['legbastion'] = { weapons = { 1 } }, --T2 Heatray Tower - ['legrl'] = { weapons = { 2 } }, --T1 AA - ['leglupara'] = { weapons = { 2 } }, --T1.5 AA - ['legrhapsis'] = { weapons = { 2 } }, --T1.5 AA - ['legflak'] = { weapons = { 2 } }, --T2 AA FLAK - ['leglraa'] = { weapons = { 2 } }, --T2 LR-AA - ['legperdition'] = { weapons = { 4 } }, --T2 LR-AA - ['legstarfall'] = { weapons = { 4 } }, - ['leglrpc'] = { weapons = { 4 } }, + ['legrampart'] = { weapons = { 3 } }, --rampart -- SCAVENGERS ['scavbeacon_t1_scav'] = { weapons = { 1 } }, @@ -397,10 +384,6 @@ function widget:TextCommand(command) end ------ GL4 THINGS ----- ---- - -local autoReload = false - -- nukes and cannons: local largeCircleVBO = nil local largeCircleSegments = 512 @@ -415,12 +398,10 @@ local defenseRangeClasses = {'enemyair','enemyground','enemynuke','allyair','all local defenseRangeVAOs = {} local circleInstanceVBOLayout = { - {id = 1, name = 'posscale', size = 4}, -- abs pos for static units, offset for dynamic units, scale is actual range, Y is turretheight + {id = 1, name = 'posscale', size = 4}, -- a vec4 for pos + scale {id = 2, name = 'color1', size = 4}, -- vec4 the color of this new - {id = 3, name = 'visibility', size = 4}, --- vec4 FadeStart, FadeEnd, StartAlpha, EndAlpha + {id = 3, name = 'visibility', size = 4}, --- vec4 heightdrawstart, heightdrawend, fadefactorin, fadefactorout {id = 4, name = 'projectileParams', size = 4}, --- heightboost gradient - {id = 5, name = 'additionalParams', size = 4 }, --- groupselectionfadescale, weaponType, ISDGUN, MAXANGLEDIF - {id = 6, name = 'instData', size = 4, type = GL.UNSIGNED_INT }, -- Currently unused within defense ranges, as they are forced-static } local luaShaderDir = "LuaUI/Widgets/Include/" @@ -428,40 +409,290 @@ local LuaShader = VFS.Include(luaShaderDir.."LuaShader.lua") VFS.Include(luaShaderDir.."instancevbotable.lua") local defenseRangeShader = nil -local shaderSourceCache = { - shaderName = 'Defense Range GL4', - vssrcpath = "LuaUI/Widgets/Shaders/weapon_range_rings_unified_gl4.vert.glsl", - fssrcpath = "LuaUI/Widgets/Shaders/weapon_range_rings_unified_gl4.frag.glsl", - shaderConfig = { - MYGRAVITY = Game.gravity + 0.1, - STATICUNITS = 1, - DEBUG = autoReload and 1 or 0, - }, - uniformInt = { - heightmapTex = 0, - losTex = 1, - mapNormalTex = 2, - }, - uniformFloat = { - lineAlphaUniform = 1, - cannonmode = 0, - fadeDistOffset = 0, - drawMode = 0, - selBuilderCount = 1.0, - selUnitCount = 1.0, - inMiniMap = 0.0, - }, -} - local function goodbye(reason) Spring.Echo("DefenseRange GL4 widget exiting with reason: "..reason) widgetHandler:RemoveWidget() end +local function makeCircleVBO(circleSegments) + circleSegments = circleSegments -1 -- for po2 buffers + local circleVBO = gl.GetVBO(GL.ARRAY_BUFFER,true) + if circleVBO == nil then goodbye("Failed to create circleVBO") end + + local VBOLayout = { + {id = 0, name = "position", size = 4}, + } + + local VBOData = {} + + for i = 0, circleSegments do -- this is +1 + VBOData[#VBOData+1] = math.sin(math.pi*2* i / circleSegments) -- X + VBOData[#VBOData+1] = math.cos(math.pi*2* i / circleSegments) -- Y + VBOData[#VBOData+1] = i / circleSegments -- circumference [0-1] + VBOData[#VBOData+1] = 0 + end + + circleVBO:Define( + circleSegments + 1, + VBOLayout + ) + circleVBO:Upload(VBOData) + return circleVBO +end + +local vsSrc = [[ +#version 420 +#line 10000 + +//__DEFINES__ + +layout (location = 0) in vec4 circlepointposition; +layout (location = 1) in vec4 posscale; +layout (location = 2) in vec4 color1; +layout (location = 3) in vec4 visibility; // FadeStart, FadeEnd, StartAlpha, EndAlpha +layout (location = 4) in vec4 projectileParams; // projectileSpeed, iscylinder!!!! , heightBoostFactor , heightMod + +uniform float lineAlphaUniform = 1.0; +uniform float cannonmode = 0.0; + +uniform sampler2D heightmapTex; +uniform sampler2D losTex; // hmm maybe? + +out DataVS { + flat vec4 blendedcolor; +}; + +//__ENGINEUNIFORMBUFFERDEFS__ + +#line 11000 + +float heightAtWorldPos(vec2 w){ + vec2 uvhm = heightmapUVatWorldPos(w); + return textureLod(heightmapTex, uvhm, 0.0).x; +} + +float GetRangeFactor(float projectileSpeed) { // returns >0 if weapon can shoot here, <0 if it cannot, 0 if just right + // on first run, with yDiff = 0, what do we get? + float speed2d = projectileSpeed * 0.707106; + float gravity = 120.0 * (0.001111111); + return ((speed2d * speed2d) * 2.0 ) / (gravity); +} + +float GetRange2DCannon(float yDiff,float projectileSpeed,float rangeFactor,float heightBoostFactor) { // returns >0 if weapon can shoot here, <0 if it cannot, 0 if just right + // on first run, with yDiff = 0, what do we get? + + //float factor = 0.707106; + float smoothHeight = 100.0; + float speed2d = projectileSpeed*0.707106; + float speed2dSq = speed2d * speed2d; + float gravity = -1.0* (120.0 /900); + + if (heightBoostFactor < 0){ + heightBoostFactor = (2.0 - rangeFactor) / sqrt(rangeFactor); + } + + if (yDiff < -100.0){ + yDiff = yDiff * heightBoostFactor; + }else { + if (yDiff < 0.0) { + yDiff = yDiff * (1.0 + (heightBoostFactor - 1.0 ) * (-1.0 * yDiff) * 0.01); + } + } + + float root1 = speed2dSq + 2 * gravity *yDiff; + if (root1 < 0.0 ){ + return 0.0; + }else{ + return rangeFactor * ( speed2dSq + speed2d * sqrt( root1 ) ) / (-1.0 * gravity); + } +} + +//float heightMod  default: 0.2 (0.8 for #Cannon, 1.0 for #BeamLaser and #LightningCannon) +//Changes the spherical weapon range into an ellipsoid. Values above 1.0 mean the weapon cannot target as high as it can far, values below 1.0 mean it can target higher than it can far. For example 0.5 would allow the weapon to target twice as high as far. + +//float heightBoostFactor default: -1.0 +//Controls the boost given to range by high terrain. Values > 1.0 result in increased range, 0.0 means the cannon has fixed range regardless of height difference to target. Any value < 0.0 (i.e. the default value) result in an automatically calculated value based on range and theoretical maximum range. + +#define RANGE posscale.w +#define PROJECTILESPEED projectileParams.x +#define ISCYLINDER projectileParams.y +#define HEIGHTBOOSTFACTOR projectileParams.z +#define HEIGHTMOD projectileParams.w +#define YGROUND posscale.y + +#define OUTOFBOUNDSALPHA alphaControl.y +#define FADEALPHA alphaControl.z +#define MOUSEALPHA alphaControl.w + + +void main() { + // translate to world pos: + vec4 circleWorldPos = vec4(1.0); + circleWorldPos.xz = circlepointposition.xy * RANGE + posscale.xz; + + vec4 alphaControl = vec4(1.0); + + // get heightmap + circleWorldPos.y = heightAtWorldPos(circleWorldPos.xz); + + + if (cannonmode > 0.5){ + + // BAR only has 3 distinct ballistic projectiles, heightBoostFactor is only a handful from -1 to 2.8 and 6 and 8 + // gravity we can assume to be linear + + float heightDiff = (circleWorldPos.y - YGROUND) * 0.5; + + float rangeFactor = RANGE / GetRangeFactor(PROJECTILESPEED); //correct + if (rangeFactor > 1.0 ) rangeFactor = 1.0; + if (rangeFactor <= 0.0 ) rangeFactor = 1.0; + float radius = RANGE;// - heightDiff; + float adjRadius = GetRange2DCannon(heightDiff * HEIGHTMOD, PROJECTILESPEED, rangeFactor, HEIGHTBOOSTFACTOR); + float adjustment = radius * 0.5; + float yDiff = 0; + float adds = 0; + //for (int i = 0; i < mod(timeInfo.x/8,16); i ++){ //i am a debugging god + for (int i = 0; i < 16; i ++){ + if (adjRadius > radius){ + radius = radius + adjustment; + adds = adds + 1; + }else{ + radius = radius - adjustment; + adds = adds - 1; + } + adjustment = adjustment * 0.5; + circleWorldPos.xz = circlepointposition.xy * radius + posscale.xz; + float newY = heightAtWorldPos(circleWorldPos.xz ); + yDiff = abs(circleWorldPos.y - newY); + circleWorldPos.y = max(0, newY); + heightDiff = circleWorldPos.y - posscale.y; + adjRadius = GetRange2DCannon(heightDiff * HEIGHTMOD, PROJECTILESPEED, rangeFactor, HEIGHTBOOSTFACTOR); + } + }else{ + if (ISCYLINDER < 0.5){ // isCylinder + //simple implementation, 4 samples per point + //for (int i = 0; i 0.5){ + // cannons should fade distance based on their range + float cvmin = max(visibility.x, 2* RANGE); + float cvmax = max(visibility.y, 4* RANGE); + //FADEALPHA = clamp((cvmin - distToCam)/(cvmax - cvmin + 1.0),visibility.z,visibility.w); + } + + blendedcolor = color1; + + // -- DARKEN OUT OF LOS + vec4 losTexSample = texture(losTex, vec2(circleWorldPos.x / mapSize.z, circleWorldPos.z / mapSize.w)); // lostex is PO2 + float inlos = dot(losTexSample.rgb,vec3(0.33)); + inlos = clamp(inlos*5 -1.4 , 0.5,1.0); // fuck if i know why, but change this if LOSCOLORS are changed! + blendedcolor.rgb *= inlos; + + // --- YES FOG + float fogDist = length((cameraView * vec4(circleWorldPos.xyz,1.0)).xyz); + float fogFactor = clamp((fogParams.y - fogDist) * fogParams.w, 0, 1); + blendedcolor.rgb = mix(fogColor.rgb, vec3(blendedcolor), fogFactor); + + + // -- IN-SHADER MOUSE-POS BASED HIGHLIGHTING + float disttomousefromunit = 1.0 - smoothstep(48, 64, length(posscale.xz - mouseWorldPos.xz)); + // this will be positive if in mouse, negative else + float highightme = clamp( (disttomousefromunit ) + 0.0, 0.0, 1.0); + MOUSEALPHA = highightme; + + // ------------ dump the stuff for FS -------------------- + //worldPos = circleWorldPos; + //worldPos.a = RANGE; + alphaControl.x = circlepointposition.z; // save circle progress here + gl_Position = cameraViewProj * vec4(circleWorldPos.xyz, 1.0); + + + //lets blend the alpha here, and save work in FS: + float outalpha = OUTOFBOUNDSALPHA * (MOUSEALPHA + FADEALPHA * lineAlphaUniform); + blendedcolor.a *= outalpha ; + //blendedcolor.rgb = vec3(fract(distToCam/100)); +} +]] + +local fsSrc = [[ +#version 330 + +#extension GL_ARB_uniform_buffer_object : require +#extension GL_ARB_shading_language_420pack: require + +//_DEFINES__ + +#line 20000 + + +//_ENGINEUNIFORMBUFFERDEFS__ + +in DataVS { + flat vec4 blendedcolor; +}; + +out vec4 fragColor; + +void main() { + fragColor = blendedcolor; // now pared down to only this, all work is done in vertex shader now +} +]] + + local function makeShaders() - defenseRangeShader = LuaShader.CheckShaderUpdates(shaderSourceCache, 0) - if not defenseRangeShader then + local engineUniformBufferDefs = LuaShader.GetEngineUniformBufferDefs() + vsSrc = vsSrc:gsub("//__ENGINEUNIFORMBUFFERDEFS__", engineUniformBufferDefs) + fsSrc = fsSrc:gsub("//__ENGINEUNIFORMBUFFERDEFS__", engineUniformBufferDefs) + defenseRangeShader = LuaShader( + { + vertex = vsSrc:gsub("//__DEFINES__", "#define MYGRAVITY "..tostring(Game.gravity+0.1)), + fragment = fsSrc, + --geometry = gsSrc, no geom shader for now + uniformInt = { + heightmapTex = 0, + losTex = 1, + }, + uniformFloat = { + lineAlphaUniform = 1, + cannonmode = 0, + }, + }, + "defenseRangeShader GL4" + ) + shaderCompiled = defenseRangeShader:Initialize() + if not shaderCompiled then goodbye("Failed to compile defenseRangeShader GL4 ") return false end @@ -524,7 +755,7 @@ local function hashPos(x,z) end local cacheTable = {} -for i=1,24 do cacheTable[i] = 0 end +for i=1,16 do cacheTable[i] = 0 end local function UnitDetected(unitID, unitDefID, unitTeam, noUpload) if unitDefRings[unitDefID] == nil then return end -- no rings for this @@ -543,24 +774,12 @@ local function UnitDetected(unitID, unitDefID, unitTeam, noUpload) local allystring = alliedUnit and "ally" or "enemy" if buttonConfig[allystring][buttonconfigmap[weaponType]] then --local weaponType = unitDefRings[unitDefID]['weapons'][weaponNum] - - local weaponID = i - local ringParams = unitDefRings[unitDefID]['rings'][i] - local x, y, z, mpx, mpy, mpz, apx, apy, apz = spGetUnitPosition(unitID, true, true) - local wpx, wpy, wpz, wdx, wdy, wdz = Spring.GetUnitWeaponVectors(unitID, weaponID) - --Spring.Echo("Defranges: unitID", unitID,x,y,z,"weaponID", weaponID, "y", y, "mpy", mpy,"wpy", wpy) - - -- Now this is a truly terrible hack, we cache each unitDefID's max weapon turret height at position 18 in the table - -- so it only goes up with popups - local turretHeight = math.max(ringParams[18] or 0, (wpy or mpy ) - y) - ringParams[18] = turretHeight - - cacheTable[1] = mpx - cacheTable[2] = turretHeight + cacheTable[2] = mpy cacheTable[3] = mpz local vaokey = allystring .. weaponTypeToString[weaponType] + local ringParams = unitDefRings[unitDefID]['rings'][i] for i = 1,13 do cacheTable[i+3] = ringParams[i] end @@ -845,10 +1064,6 @@ local function DRAWRINGS(primitiveType, linethickness) end defenseRangeShader:SetUniform("cannonmode",1) - if not linethickness then - -- NOTE: THIS IS THE WORLDS NASTIEST HACK TO PREVENT THE CANNON RINGS FROM BEING DRAWN STENCILED! - return - end for i,allyState in ipairs(allyenemypairs) do local defRangeClass = allyState.."cannon" local iT = defenseRangeVAOs[defRangeClass] @@ -856,7 +1071,7 @@ local function DRAWRINGS(primitiveType, linethickness) drawcounts[stencilMask] = iT.usedElements if iT.usedElements > 0 and buttonConfig[allyState]["ground"] then if linethickness then - glLineWidth(colorConfig['cannon'][linethickness] * cameraHeightFactor * 0.15) + glLineWidth(colorConfig['cannon'][linethickness] * cameraHeightFactor) end glStencilMask(stencilMask) glStencilFunc(GL.NOTEQUAL, stencilMask, stencilMask) @@ -865,16 +1080,10 @@ local function DRAWRINGS(primitiveType, linethickness) end end -function widget:DrawWorld() +function widget:DrawWorldPreUnit() --if fullview and not enabledAsSpec then -- return --end - - if autoReload then - defenseRangeShader = LuaShader.CheckShaderUpdates(shaderSourceCache) or defenseRangeShader - end - - if chobbyInterface then return end if not Spring.IsGUIHidden() and (not WG['topbar'] or not WG['topbar'].showingQuit()) then cameraHeightFactor = GetCameraHeightFactor() * 0.5 + 0.5 @@ -887,7 +1096,6 @@ function widget:DrawWorld() glClear(GL.STENCIL_BUFFER_BIT) -- clear prev stencil glDepthTest(false) -- always draw glColorMask(false, false, false, false) -- disable color drawing - glStencilTest(true) -- enable stencil test glStencilMask(255) -- all 8 bits glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE) -- Set The Stencil Buffer To 1 Where Draw Any Polygon @@ -935,6 +1143,7 @@ end + --SAVE / LOAD CONFIG FILE function widget:GetConfigData() local data = {} diff --git a/units/ArmBots/T2/armaak.lua b/units/ArmBots/T2/armaak.lua index 704c4af5f9..f9eaa7e58a 100644 --- a/units/ArmBots/T2/armaak.lua +++ b/units/ArmBots/T2/armaak.lua @@ -142,9 +142,6 @@ return { [2] = 0.33, [3] = 0.7, }, - customparams = { - bogus = 1 - }, }, armaabot_missile1 = { areaofeffect = 64, diff --git a/units/ArmBuildings/LandUtil/armmine1.lua b/units/ArmBuildings/LandUtil/armmine1.lua index a3b2e4ccd3..f84b6cc108 100644 --- a/units/ArmBuildings/LandUtil/armmine1.lua +++ b/units/ArmBuildings/LandUtil/armmine1.lua @@ -78,8 +78,6 @@ return { weapondefs = { minerange = { areaofeffect = 0, - avoidfeature = false, - avoidground = false, craterareaofeffect = 0, craterboost = 0, cratermult = 0, @@ -89,7 +87,7 @@ return { impulsefactor = 0, name = "Crawlingbomb Dummy Weapon", range = 64, - reloadtime = 0.1, + reloadtime = 1, soundhitwet = "", soundhitwetvolume = 0, tolerance = 1000000, @@ -106,7 +104,6 @@ return { weapons = { [1] = { def = "MINERANGE", - onlytargetcategory = "SURFACE", }, }, }, diff --git a/units/ArmBuildings/LandUtil/armmine2.lua b/units/ArmBuildings/LandUtil/armmine2.lua index 077a534e90..866395f2b7 100644 --- a/units/ArmBuildings/LandUtil/armmine2.lua +++ b/units/ArmBuildings/LandUtil/armmine2.lua @@ -104,7 +104,6 @@ return { weapons = { [1] = { def = "MINERANGE", - onlytargetcategory = "SURFACE", }, }, }, diff --git a/units/ArmBuildings/LandUtil/armmine3.lua b/units/ArmBuildings/LandUtil/armmine3.lua index a53afece60..3b8c19e84c 100644 --- a/units/ArmBuildings/LandUtil/armmine3.lua +++ b/units/ArmBuildings/LandUtil/armmine3.lua @@ -104,7 +104,6 @@ return { weapons = { [1] = { def = "MINERANGE", - onlytargetcategory = "SURFACE", }, }, }, diff --git a/units/ArmBuildings/SeaUtil/armfmine3.lua b/units/ArmBuildings/SeaUtil/armfmine3.lua index 79f18c97d9..101878c9ad 100644 --- a/units/ArmBuildings/SeaUtil/armfmine3.lua +++ b/units/ArmBuildings/SeaUtil/armfmine3.lua @@ -106,7 +106,6 @@ return { weapons = { [1] = { def = "MINERANGE", - onlytargetcategory = "SURFACE", }, }, }, diff --git a/units/ArmGantry/armthor.lua b/units/ArmGantry/armthor.lua index f5a98e2562..93c814519e 100644 --- a/units/ArmGantry/armthor.lua +++ b/units/ArmGantry/armthor.lua @@ -241,9 +241,6 @@ return { default = 300, subs = 30, }, - customparams = { - noattackrangearc= 1, - }, }, }, weapons = { diff --git a/units/ArmShips/T2/armbats.lua b/units/ArmShips/T2/armbats.lua index 7a3cdb135f..06d63c53c9 100644 --- a/units/ArmShips/T2/armbats.lua +++ b/units/ArmShips/T2/armbats.lua @@ -128,9 +128,6 @@ return { default = 300, vtol = 65, }, - customparams = { - noattackrangearc= 1, - }, }, }, weapons = { diff --git a/units/ArmShips/T2/armepoch.lua b/units/ArmShips/T2/armepoch.lua index 3eddfefc3c..8a67bb69d8 100644 --- a/units/ArmShips/T2/armepoch.lua +++ b/units/ArmShips/T2/armepoch.lua @@ -161,9 +161,6 @@ return { commanders = 1, vtol = 150, }, - customparams = { - noattackrangearc= 1, - }, }, flak = { accuracy = 1000, @@ -201,9 +198,6 @@ return { [2] = 0.33, [3] = 0.7, }, - customparams = { - noattackrangearc= 1, - }, }, heavyplasma = { accuracy = 600, @@ -234,9 +228,6 @@ return { default = 437, vtol = 200, }, - customparams = { - noattackrangearc= 1, - }, }, mediumplasma = { accuracy = 350, @@ -264,9 +255,6 @@ return { default = 270, vtol = 65, }, - customparams = { - noattackrangearc= 1, - }, }, }, weapons = { diff --git a/units/ArmShips/T2/armlship.lua b/units/ArmShips/T2/armlship.lua index fc5c134c43..4849418b84 100644 --- a/units/ArmShips/T2/armlship.lua +++ b/units/ArmShips/T2/armlship.lua @@ -188,7 +188,6 @@ return { spark_forkdamage = "0.5", spark_maxunits = "2", spark_range = "100", - noattackrangearc= 1, }, damage = { default = 35, diff --git a/units/ArmShips/T2/armmship.lua b/units/ArmShips/T2/armmship.lua index 18fe614b3e..f66770b311 100644 --- a/units/ArmShips/T2/armmship.lua +++ b/units/ArmShips/T2/armmship.lua @@ -195,7 +195,6 @@ return { speceffect = "split", splitexplosionceg = "genericshellexplosion-medium", when = "yvel<0", - noattackrangearc= 1, }, damage = { commanders = 350, diff --git a/units/ArmShips/armpship.lua b/units/ArmShips/armpship.lua index 2ecc6fd1b7..67646d4218 100644 --- a/units/ArmShips/armpship.lua +++ b/units/ArmShips/armpship.lua @@ -128,10 +128,6 @@ return { subs = 70, vtol = 37, }, - customparams = { - noattackrangearc= 1, - }, - }, }, weapons = { diff --git a/units/CorAircraft/T2/corcrwh.lua b/units/CorAircraft/T2/corcrwh.lua index 93ff6a9bb0..4e231f9493 100644 --- a/units/CorAircraft/T2/corcrwh.lua +++ b/units/CorAircraft/T2/corcrwh.lua @@ -127,9 +127,6 @@ return { damage = { vtol = 76, }, - customparams = { - noattackrangearc= 1, - }, }, dragonmawh = { accuracy = 700, @@ -176,9 +173,6 @@ return { default = 6, subs = 3, }, - customparams = { - noattackrangearc= 1, - }, }, krowlaser2 = { areaofeffect = 32, diff --git a/units/CorBots/T2/coraak.lua b/units/CorBots/T2/coraak.lua index 133680847e..a409995d91 100644 --- a/units/CorBots/T2/coraak.lua +++ b/units/CorBots/T2/coraak.lua @@ -141,9 +141,6 @@ return { [2] = 0.33, [3] = 0.7, }, - customparams = { - bogus = 1 - }, }, bogus_missile = { areaofeffect = 48, @@ -220,9 +217,6 @@ return { damage = { vtol = 80, }, - customparams = { - bogus = 1 - }, }, coraabot_missile2 = { areaofeffect = 24, @@ -270,9 +264,6 @@ return { damage = { vtol = 80, }, - customparams = { - bogus = 1 - }, }, coraabot_missile3 = { areaofeffect = 24, @@ -320,9 +311,6 @@ return { damage = { vtol = 80, }, - customparams = { - bogus = 1 - }, }, coraabot_missile4 = { areaofeffect = 64, diff --git a/units/CorBuildings/LandUtil/cormine1.lua b/units/CorBuildings/LandUtil/cormine1.lua index 458c9e320a..bcec924be0 100644 --- a/units/CorBuildings/LandUtil/cormine1.lua +++ b/units/CorBuildings/LandUtil/cormine1.lua @@ -105,7 +105,6 @@ return { weapons = { [1] = { def = "MINERANGE", - onlytargetcategory = "SURFACE", }, }, }, diff --git a/units/CorBuildings/LandUtil/cormine2.lua b/units/CorBuildings/LandUtil/cormine2.lua index 7a73dc82e9..2b7bb3b459 100644 --- a/units/CorBuildings/LandUtil/cormine2.lua +++ b/units/CorBuildings/LandUtil/cormine2.lua @@ -104,7 +104,6 @@ return { weapons = { [1] = { def = "MINERANGE", - onlytargetcategory = "SURFACE", }, }, }, diff --git a/units/CorBuildings/LandUtil/cormine3.lua b/units/CorBuildings/LandUtil/cormine3.lua index f701732a42..1384eafcb9 100644 --- a/units/CorBuildings/LandUtil/cormine3.lua +++ b/units/CorBuildings/LandUtil/cormine3.lua @@ -104,7 +104,6 @@ return { weapons = { [1] = { def = "MINERANGE", - onlytargetcategory = "SURFACE", }, }, }, diff --git a/units/CorBuildings/SeaUtil/corfmine3.lua b/units/CorBuildings/SeaUtil/corfmine3.lua index 2836d5790b..9d2e585926 100644 --- a/units/CorBuildings/SeaUtil/corfmine3.lua +++ b/units/CorBuildings/SeaUtil/corfmine3.lua @@ -106,7 +106,6 @@ return { weapons = { [1] = { def = "MINERANGE", - onlytargetcategory = "SURFACE", }, }, }, diff --git a/units/CorGantry/corjugg.lua b/units/CorGantry/corjugg.lua index aa4b7207a4..b6c5a885e2 100644 --- a/units/CorGantry/corjugg.lua +++ b/units/CorGantry/corjugg.lua @@ -139,9 +139,6 @@ return { damage = { default = 75, }, - customparams = { - noattackrangearc= 1, - }, }, juggernaut_fire = { areaofeffect = 65, @@ -212,9 +209,6 @@ return { damage = { default = 150, }, - customparams = { - noattackrangearc= 1, - }, }, }, weapons = { diff --git a/units/CorGantry/corkorg.lua b/units/CorGantry/corkorg.lua index e80711c726..da4b51671d 100644 --- a/units/CorGantry/corkorg.lua +++ b/units/CorGantry/corkorg.lua @@ -278,7 +278,6 @@ return { customparams = { lups_noshockwave = true, nofire = true, - noattackrangearc= 1, }, damage = { default = 150, diff --git a/units/CorShips/T2/corbats.lua b/units/CorShips/T2/corbats.lua index 212b9b710b..e53372cf0d 100644 --- a/units/CorShips/T2/corbats.lua +++ b/units/CorShips/T2/corbats.lua @@ -162,9 +162,6 @@ return { default = 300, vtol = 65, }, - customparams = { - noattackrangearc= 1, - }, }, }, weapons = { diff --git a/units/CorShips/T2/corblackhy.lua b/units/CorShips/T2/corblackhy.lua index cf0294fc5d..cfd775ee2d 100644 --- a/units/CorShips/T2/corblackhy.lua +++ b/units/CorShips/T2/corblackhy.lua @@ -192,10 +192,6 @@ return { damage = { vtol = 150, }, - - customparams = { - noattackrangearc= 1, - }, }, heavylaser = { areaofeffect = 8, @@ -231,9 +227,6 @@ return { default = 270, vtol = 65, }, - customparams = { - noattackrangearc= 1, - }, }, heavyplasma = { accuracy = 500, diff --git a/units/CorShips/T2/cormship.lua b/units/CorShips/T2/cormship.lua index bbb44d9407..83ff273b37 100644 --- a/units/CorShips/T2/cormship.lua +++ b/units/CorShips/T2/cormship.lua @@ -194,7 +194,6 @@ return { speceffect = "split", splitexplosionceg = "genericshellexplosion-medium", when = "yvel<0", - noattackrangearc= 1, }, damage = { commanders = 500, diff --git a/units/Legion/Air/T2 Air/legfort.lua b/units/Legion/Air/T2 Air/legfort.lua index 8cc11e1312..47ba633fb8 100644 --- a/units/Legion/Air/T2 Air/legfort.lua +++ b/units/Legion/Air/T2 Air/legfort.lua @@ -117,9 +117,6 @@ return { damage = { default = 36, }, - customparams = { - noattackrangearc= 1, - }, }, plasma = { accuracy = 960, @@ -148,9 +145,6 @@ return { subs = 50, vtol = 30, }, - customparams = { - noattackrangearc= 1, - }, }, aa_missiles = { areaofeffect = 16, diff --git a/units/Legion/Air/T2 Air/legheavydrone.lua b/units/Legion/Air/T2 Air/legheavydrone.lua index 5b0d4e0c75..648e983072 100644 --- a/units/Legion/Air/T2 Air/legheavydrone.lua +++ b/units/Legion/Air/T2 Air/legheavydrone.lua @@ -106,9 +106,6 @@ return { default = 10, vtol = 2, }, - customparams = { - noattackrangearc= 1, - }, }, }, weapons = { diff --git a/units/Legion/Air/T2 Air/legionnaire.lua b/units/Legion/Air/T2 Air/legionnaire.lua index 2e278fe254..cd9d33d0c5 100644 --- a/units/Legion/Air/T2 Air/legionnaire.lua +++ b/units/Legion/Air/T2 Air/legionnaire.lua @@ -122,9 +122,6 @@ return { default = 2, vtol = 80, }, - customparams = { - noattackrangearc= 1, - }, }, }, diff --git a/units/Legion/Air/T2 Air/legvenator.lua b/units/Legion/Air/T2 Air/legvenator.lua index 8e2506f6e3..d8e6f27eb3 100644 --- a/units/Legion/Air/T2 Air/legvenator.lua +++ b/units/Legion/Air/T2 Air/legvenator.lua @@ -111,9 +111,6 @@ return { default = 24, vtol = 480, }, - customparams = { - noattackrangearc= 1, - }, }, }, weapons = { diff --git a/units/Legion/Air/legdrone.lua b/units/Legion/Air/legdrone.lua index b45dd85d31..c67fdceead 100644 --- a/units/Legion/Air/legdrone.lua +++ b/units/Legion/Air/legdrone.lua @@ -137,9 +137,6 @@ return { default = 12, vtol = 4, }, - customparams = { - noattackrangearc= 1, - }, }, }, weapons = { diff --git a/units/Legion/Defenses/legbombard.lua b/units/Legion/Defenses/legbombard.lua index 9c3d2440cb..408ba096fb 100644 --- a/units/Legion/Defenses/legbombard.lua +++ b/units/Legion/Defenses/legbombard.lua @@ -186,7 +186,6 @@ return { subs = 300, }, customparams = { - noattackrangearc= 1, exclude_preaim = true } }, diff --git a/units/Legion/Ships/leghastatus.lua b/units/Legion/Ships/leghastatus.lua index e87ff3d9cb..d93b98b88a 100644 --- a/units/Legion/Ships/leghastatus.lua +++ b/units/Legion/Ships/leghastatus.lua @@ -127,9 +127,6 @@ return { default = 55, vtol = 30, }, - customparams = { - noattackrangearc= 1, - }, }, }, diff --git a/units/Legion/Ships/leghastatusalt.lua b/units/Legion/Ships/leghastatusalt.lua index e9b9d61b94..5e7bff0124 100644 --- a/units/Legion/Ships/leghastatusalt.lua +++ b/units/Legion/Ships/leghastatusalt.lua @@ -139,9 +139,6 @@ return { hvyboats = 11, vtol = 2, }, - customparams = { - noattackrangearc= 1, - }, }, }, weapons = { diff --git a/units/Legion/Ships/legportent.lua b/units/Legion/Ships/legportent.lua index 100ff55d5c..c968f930be 100644 --- a/units/Legion/Ships/legportent.lua +++ b/units/Legion/Ships/legportent.lua @@ -132,9 +132,6 @@ return { vtol = 30, sub = 30, }, - customparams = { - noattackrangearc= 1, - }, }, }, diff --git a/units/Legion/T3/legpede.lua b/units/Legion/T3/legpede.lua index d48cc724cc..d42db278fa 100644 --- a/units/Legion/T3/legpede.lua +++ b/units/Legion/T3/legpede.lua @@ -187,9 +187,6 @@ return { default = 21, vtol = 21, }, - customparams = { - noattackrangearc= 1, - }, }, railgunt2 = { areaofeffect = 16, From 0e4db0d5b04e75c6779a872ab8ae8c674eeb9118 Mon Sep 17 00:00:00 2001 From: WatchTheFort <36827423+WatchTheFort@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:14:56 -0500 Subject: [PATCH 5/6] Remove code to fix math.random returning float instead of int (#4051) Remove code to fix math.random returning float instead of int, engine ticket has been long since fixed --- unitbasedefs/lootboxes/lootboxnano.lua | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/unitbasedefs/lootboxes/lootboxnano.lua b/unitbasedefs/lootboxes/lootboxnano.lua index 62c424293f..bd3b5a3334 100644 --- a/unitbasedefs/lootboxes/lootboxnano.lua +++ b/unitbasedefs/lootboxes/lootboxnano.lua @@ -1,8 +1,3 @@ --- Workaround for engine bug https://github.com/beyond-all-reason/spring/issues/45 -local math_random = function(x, y) - return x + math.floor( y * math.random() ) -end - local tiers = { T1 = 1, T2 = 2, @@ -23,7 +18,7 @@ local createCustomBuildList = function(tier) local buildList = {} for i = 1, buildListSize do - local buildOption = buildOptions[tier][math_random(1, #buildOptions[tier])] + local buildOption = buildOptions[tier][math.random(1, #buildOptions[tier])] buildList[i] = buildOption end @@ -77,7 +72,7 @@ local function getRandomModel(tier) }, } - local randomModel = math_random(1, 2) + local randomModel = math.random(1, 2) return models[tier][randomModel].objectName, models[tier][randomModel].script end From 1f8184d5f0ae77fb3ef18e9ee39c1716b3a3cd87 Mon Sep 17 00:00:00 2001 From: Floris Date: Sat, 21 Dec 2024 16:14:38 +0100 Subject: [PATCH 6/6] dgun stall assist: minor code cleanup --- luaui/Widgets/unit_dgun_stall_assist.lua | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/luaui/Widgets/unit_dgun_stall_assist.lua b/luaui/Widgets/unit_dgun_stall_assist.lua index 5f2a1841fd..90aee129da 100644 --- a/luaui/Widgets/unit_dgun_stall_assist.lua +++ b/luaui/Widgets/unit_dgun_stall_assist.lua @@ -1,4 +1,3 @@ - function widget:GetInfo() return { name = "DGun Stall Assist", @@ -11,9 +10,6 @@ function widget:GetInfo() } end ----------------------------------------------------------------- --- Config ----------------------------------------------------------------- local targetEnergy = 600 local watchForTime = 5 @@ -22,14 +18,13 @@ local watchForTime = 5 ---------------------------------------------------------------- local watchTime = 0 local waitedUnits = nil -- nil / waitedUnits[1..n] = uID -local shouldWait = {} -- shouldWait[uDefID] = true / nil -local isFactory = {} -- isFactory[uDefID] = true / nil +local shouldWait = {} +local isFactory = {} local gameStarted local stallIds = {UnitDefNames['armcom'].id, UnitDefNames['corcom'].id, UnitDefNames['legcom'] and UnitDefNames['legcom'].id} - ---------------------------------------------------------------- -- Speedups ---------------------------------------------------------------- @@ -41,7 +36,6 @@ local spGetMyTeamID = Spring.GetMyTeamID local spGetTeamResources = Spring.GetTeamResources local spGetTeamUnits = Spring.GetTeamUnits local spGetUnitDefID = Spring.GetUnitDefID -local spGetSpectatingState = Spring.GetSpectatingState local spGetUnitIsBeingBuilt = Spring.GetUnitIsBeingBuilt local CMD_DGUN = CMD.DGUN @@ -75,7 +69,7 @@ function widget:Initialize() end for uDefID, uDef in pairs(UnitDefs) do - if (uDef.buildSpeed > 0) and uDef.canAssist and (not uDef.canManualFire) then + if uDef.buildSpeed > 0 and uDef.canAssist and not uDef.canManualFire then shouldWait[uDefID] = true if uDef.isFactory then isFactory[uDefID] = true @@ -97,13 +91,13 @@ function widget:Update(dt) end end - if (stallUnitSelected) then + if stallUnitSelected then watchTime = watchForTime end else watchTime = watchTime - dt - if waitedUnits and (watchTime < 0) then + if waitedUnits and watchTime < 0 then local toUnwait = {} for i = 1, #waitedUnits do @@ -127,11 +121,11 @@ function widget:Update(dt) end end - if (watchTime > 0) and (not waitedUnits) then + if watchTime > 0 and not waitedUnits then local myTeamID = spGetMyTeamID() local currentEnergy, energyStorage = spGetTeamResources(myTeamID, "energy") - if (currentEnergy < targetEnergy) and (energyStorage >= targetEnergy) then + if currentEnergy < targetEnergy and energyStorage >= targetEnergy then waitedUnits = {} local myUnits = spGetTeamUnits(myTeamID)