@@ -17,7 +17,6 @@ local SpSetProjectileTarget = Spring.SetProjectileTarget
17
17
18
18
local SpGetProjectileVelocity = Spring .GetProjectileVelocity
19
19
local SpGetProjectileOwnerID = Spring .GetProjectileOwnerID
20
- local SpGetUnitStates = Spring .GetUnitStates
21
20
local SpGetProjectileTimeToLive = Spring .GetProjectileTimeToLive
22
21
local SpGetUnitWeaponTarget = Spring .GetUnitWeaponTarget
23
22
local SpGetProjectileTarget = Spring .GetProjectileTarget
@@ -30,6 +29,9 @@ if gadgetHandler:IsSyncedCode() then
30
29
local checkingFunctions = {}
31
30
local applyingFunctions = {}
32
31
local math_sqrt = math.sqrt
32
+ local mathCos = math.cos
33
+ local mathSin = math.sin
34
+ local mathPi = math.pi
33
35
34
36
local specialWeaponCustomDefs = {}
35
37
local weaponDefNamesID = {}
@@ -106,33 +108,27 @@ if gadgetHandler:IsSyncedCode() then
106
108
end
107
109
108
110
applyingFunctions .sector_fire = function (proID )
109
- local ownerID = SpGetProjectileOwnerID (proID )
110
- local ownerState = SpGetUnitStates (ownerID )
111
- -- if ownerState.active == true then
112
111
local infos = projectiles [proID ]
113
- -- x' = x cos θ − y sin θ
114
- -- y' = x sin θ + y cos θ
115
112
local vx , vy , vz = SpGetProjectileVelocity (proID )
116
-
117
- angle_factor = tonumber (infos .spread_angle )* random ()- tonumber (infos .spread_angle )* 0.5
118
- angle_factor = angle_factor * math.pi / 180
119
- vx_new = vx * math.cos (angle_factor ) - vz * math.sin (angle_factor )
120
- vz_new = vx * math.sin (angle_factor ) + vz * math.cos (angle_factor )
121
-
122
- -- vx_new = vx
123
- -- vz_new = vz
124
- -- velocity_reduction = 1-math.sqrt(1-tonumber(infos.max_range_reduction))
125
- -- velocity_floor = (1-velocity_reduction)^2
126
- -- velocity_factor = random()*(1-velocity_floor)
127
- -- velocity_factor = math.sqrt(velocity_floor+velocity_factor)
128
- velocity_factor = 1 - (random ()) ^ (1 + tonumber (infos .max_range_reduction ))* tonumber (infos .max_range_reduction )
129
- vx = vx_new * velocity_factor
130
- -- vy = vy*velocity_factor
131
- vz = vz_new * velocity_factor
132
-
133
- SpSetProjectileVelocity (proID ,vx ,vy ,vz )
134
- -- end
135
- end
113
+
114
+ local spread_angle = tonumber (infos .spread_angle )
115
+ local max_range_reduction = tonumber (infos .max_range_reduction )
116
+
117
+ local angle_factor = (spread_angle * (random () - 0.5 )) * mathPi / 180
118
+ local cos_angle = mathCos (angle_factor )
119
+ local sin_angle = mathSin (angle_factor )
120
+
121
+ local vx_new = vx * cos_angle - vz * sin_angle
122
+ local vz_new = vx * sin_angle + vz * cos_angle
123
+
124
+ local velocity_factor = 1 - (random () ^ (1 + max_range_reduction )) * max_range_reduction
125
+
126
+ vx = vx_new * velocity_factor
127
+ vz = vz_new * velocity_factor
128
+
129
+ SpSetProjectileVelocity (proID , vx , vy , vz )
130
+ end
131
+
136
132
137
133
checkingFunctions .retarget = {}
138
134
checkingFunctions .retarget [" always" ] = function (proID )
@@ -314,9 +310,8 @@ if gadgetHandler:IsSyncedCode() then
314
310
end
315
311
316
312
function gadget :ProjectileCreated (proID , proOwnerID , weaponDefID )
317
- local wDefID = Spring .GetProjectileDefID (proID )
318
- if specialWeaponCustomDefs [wDefID ] then
319
- projectiles [proID ] = specialWeaponCustomDefs [wDefID ]
313
+ if specialWeaponCustomDefs [weaponDefID ] then
314
+ projectiles [proID ] = specialWeaponCustomDefs [weaponDefID ]
320
315
active_projectiles [proID ] = nil
321
316
end
322
317
end
0 commit comments