@@ -22,10 +22,13 @@ function Create(self)
22
22
end
23
23
24
24
self .guideRadius = self :NumberValueExists (" TrajectoryGuideBlastRadius" ) and self :GetNumberValue (" TrajectoryGuideBlastRadius" ) or 12 ;
25
+ self .guideAccuracy = self :NumberValueExists (" TrajectoryGuideAccuracy" ) and self :GetNumberValue (" TrajectoryGuideAccuracy" ) or 1 ;
25
26
self .maxTrajectoryPars = self :NumberValueExists (" TrajectoryGuideLength" ) and self :GetNumberValue (" TrajectoryGuideLength" ) or 60 ;
26
27
self .guideColor = self :NumberValueExists (" TrajectoryGuideColorIndex" ) and self :GetNumberValue (" TrajectoryGuideColorIndex" ) or 120 ;
27
28
self .skipLines = self :NumberValueExists (" TrajectoryGuideSkipLines" ) and self :GetNumberValue (" TrajectoryGuideSkipLines" ) or 1 ;
28
- self .drawHitsOnly = self :GetNumberValue (" TrajectoryGuideDrawHitsOnly" ) == 1 ;
29
+ self .viewCorrection = self :NumberValueExists (" TrajectoryGuideViewCorrection" ) and self :GetNumberValue (" TrajectoryGuideViewCorrection" ) or 0 ;
30
+ self .drawHitsOnly = self :NumberValueExists (" TrajectoryGuideDrawHitsOnly" );
31
+ self .includeMOHits = self :NumberValueExists (" TrajectoryGuideIncludeMOHits" );
29
32
end
30
33
31
34
function Update (self )
@@ -34,11 +37,7 @@ function Update(self)
34
37
if MovableMan :IsActor (actor ) and ToActor (actor ):IsPlayerControlled () then
35
38
local actor = ToActor (actor );
36
39
local controller = actor :GetController ();
37
- if self .isThrownDevice then
38
- if not self .throwTimer and controller :IsState (Controller .WEAPON_FIRE ) then
39
- self .throwTimer = Timer ();
40
- end
41
- elseif (self :DoneReloading () or self .FiredFrame ) and self .Magazine and self .Magazine .RoundCount ~= 0 then
40
+ if not self .isThrownDevice and (self :DoneReloading () or self .FiredFrame ) and self .Magazine and self .Magazine .RoundCount ~= 0 then
42
41
self .projectileVel = self .Magazine .NextRound .FireVel ;
43
42
self .projectileGravity = self .Magazine .NextRound .NextParticle .GlobalAccScalar ;
44
43
end
@@ -57,9 +56,9 @@ function Update(self)
57
56
local rotationThisFrame = actor .AngularVel * TimerMan .DeltaTimeSecs ;
58
57
local maxVel = self .projectileVelMax or (actor .FGArm .ThrowStrength + math.abs (actor .AngularVel * 0.5 ))/ math.sqrt (math.abs (self .Mass ) + 1 );
59
58
local minVel = self .projectileVelMin or maxVel * 0.2 ;
60
- -- The following offset is as found in the source code (To-do: expose and utilize EndThrowOffset properly instead)
59
+ -- The following offset is as found in the source code (TODO: utilize EndThrowOffset properly instead)
61
60
guideParPos = actor .Pos + actor .Vel * rte .PxTravelledPerFrame + Vector ((actor .FGArm .ParentOffset .X + actor .FGArm .MaxLength ) * actor .FlipFactor , actor .FGArm .ParentOffset .Y - actor .FGArm .MaxLength * 0.5 ):RadRotate (actor :GetAimAngle (false ) * actor .FlipFactor );
62
- local projectileVel = self . throwTimer and minVel + (maxVel - minVel ) * math.min ( self . throwTimer . ElapsedSimTimeMS , actor .ThrowPrepTime ) / actor . ThrowPrepTime or maxVel ;
61
+ local projectileVel = minVel + (maxVel - minVel ) * actor .ThrowProgress ;
63
62
guideParVel = Vector (projectileVel , 0 ):RadRotate (actor .RotAngle + actor :GetAimAngle (true ) + rotationThisFrame );
64
63
else
65
64
guideParPos = self .MuzzlePos ;
@@ -74,12 +73,24 @@ function Update(self)
74
73
if self .projectileAirResistance ~= 0 and guideParVel .Largest >= self .projectileAirThreshold then
75
74
guideParVel :SetMagnitude (guideParVel .Magnitude * (1 - (self .projectileAirResistance * TimerMan .DeltaTimeSecs * 2.5 ))); -- To-do: replace "* 2.5" with something more intangible
76
75
end
77
- guideParPos = guideParPos + guideParVel ;
78
- if SceneMan :GetTerrMatter (guideParPos .X , guideParPos .Y ) == rte .airID then
79
- self .guideTable [# self .guideTable + 1 ] = guideParPos ;
80
- else
76
+ local roughHit = false ;
77
+ for i = 1 , self .guideAccuracy do
78
+ local moCheck = self .includeMOHits and SceneMan :GetMOIDPixel (guideParPos .X , guideParPos .Y ) or rte .NoMOID ;
79
+ if SceneMan :GetTerrMatter (guideParPos .X , guideParPos .Y ) == rte .airID and (moCheck == rte .NoMOID or moCheck == self .ID ) then
80
+ self .guideTable [# self .guideTable + 1 ] = guideParPos ;
81
+ else
82
+ roughHit = true ;
83
+ break ;
84
+ end
85
+ guideParPos = guideParPos + guideParVel / self .guideAccuracy ;
86
+ end
87
+ if roughHit then
81
88
hitPos = Vector (self .guideTable [# self .guideTable ].X , self .guideTable [# self .guideTable ].Y );
82
- SceneMan :CastStrengthRay (self .guideTable [# self .guideTable ], SceneMan :ShortestDistance (self .guideTable [# self .guideTable ], guideParPos , false ), 0 , hitPos , 3 , rte .airID , false );
89
+ if self .includeMOHits then
90
+ SceneMan :CastObstacleRay (self .guideTable [# self .guideTable ], SceneMan :ShortestDistance (self .guideTable [# self .guideTable ], guideParPos , false ), Vector (), hitPos , self .ID , - 2 , rte .airID , 3 );
91
+ else
92
+ SceneMan :CastStrengthRay (self .guideTable [# self .guideTable ], SceneMan :ShortestDistance (self .guideTable [# self .guideTable ], guideParPos , false ), 0 , hitPos , 3 , rte .airID , false );
93
+ end
83
94
self .guideTable [# self .guideTable + 1 ] = hitPos ;
84
95
break ;
85
96
end
@@ -90,20 +101,20 @@ function Update(self)
90
101
self .guideTable = {};
91
102
end
92
103
if # self .guideTable > 1 and (not self .drawHitsOnly or hitPos ) then
104
+ local screen = ActivityMan :GetActivity ():ScreenOfPlayer (controller .Player );
93
105
if self .skipLines > 0 then
94
106
for i = 1 , # self .guideTable - 1 do
95
107
if self .skipLines == 0 or i % (self .skipLines + 1 ) == 0 then
96
- PrimitiveMan :DrawLinePrimitive (controller . Player , self .guideTable [i ], self .guideTable [i + 1 ], self .guideColor );
108
+ PrimitiveMan :DrawLinePrimitive (screen , self .guideTable [i ], self .guideTable [i + 1 ], self .guideColor );
97
109
end
98
110
end
99
111
end
100
- PrimitiveMan :DrawCirclePrimitive (controller .Player , self .guideTable [# self .guideTable ], self .guideRadius , self .guideColor );
101
- -- Optional: move view point closer to guide point?
102
- -- local viewLength = SceneMan:ShortestDistance(actor.EyePos, actor.ViewPoint, SceneMan.SceneWrapsX).Magnitude;
103
- -- local viewPoint = actor.ViewPoint + SceneMan:ShortestDistance(actor.ViewPoint, self.guideTable[#self.guideTable], SceneMan.SceneWrapsX):SetMagnitude(viewLength);
104
- -- SceneMan:SetScrollTarget(viewPoint, 0.1, false, ActivityMan:GetActivity():ScreenOfPlayer(controller.Player));
112
+ PrimitiveMan :DrawCirclePrimitive (screen , self .guideTable [# self .guideTable ], self .guideRadius , self .guideColor );
113
+ if self .viewCorrection > 0 then
114
+ local viewLength = SceneMan :ShortestDistance (actor .EyePos , actor .ViewPoint , SceneMan .SceneWrapsX ).Magnitude ;
115
+ local viewPoint = actor .ViewPoint + SceneMan :ShortestDistance (actor .ViewPoint , self .guideTable [# self .guideTable ], SceneMan .SceneWrapsX ):SetMagnitude (viewLength );
116
+ SceneMan :SetScrollTarget (viewPoint , self .viewCorrection , false , screen );
117
+ end
105
118
end
106
- else
107
- self .throwTimer = nil ;
108
119
end
109
120
end
0 commit comments