3041 end; |
3041 end; |
3042 |
3042 |
3043 //////////////////////////////////////////////////////////////////////////////// |
3043 //////////////////////////////////////////////////////////////////////////////// |
3044 procedure doStepPortal(Gear: PGear); |
3044 procedure doStepPortal(Gear: PGear); |
3045 var iterator: PGear; |
3045 var iterator: PGear; |
|
3046 s: hwFloat; |
3046 begin |
3047 begin |
3047 if (Land[hwRound(Gear^.Y), hwRound(Gear^.X)] and $FF00) = 0 then DeleteGear(Gear); |
3048 if (Land[hwRound(Gear^.Y), hwRound(Gear^.X)] and $FF00) = 0 then DeleteGear(Gear); |
3048 if not AllInactive and (Gear^.IntersectGear <> nil) then |
3049 if Gear^.IntersectGear <> nil then |
3049 //if (Gear^.IntersectGear <> nil) then |
3050 //if (Gear^.IntersectGear <> nil) then |
3050 begin |
3051 begin |
3051 iterator:= GearsList; |
3052 iterator:= GearsList; |
3052 while iterator <> nil do |
3053 while iterator <> nil do |
3053 begin |
3054 begin |
3054 if iterator^.Active and (iterator^.Kind <> gtPortal) and |
3055 if (iterator^.Kind <> gtPortal) then |
3055 (hwRound(hwAbs(Gear^.X-iterator^.X)+hwAbs(Gear^.Y-iterator^.Y)) < Gear^.Radius+iterator^.Radius) and |
3056 if (((iterator^.State and gstMoving) <> 0) or (Gear^.IntersectGear^.dY.isNegative and not Gear^.dY.isNegative)) |
3056 ((hwAbs(Gear^.X-(iterator^.X+iterator^.dX))+hwAbs(Gear^.Y-(iterator^.Y+iterator^.dY))).QWordValue < (hwAbs(Gear^.X-iterator^.X)+hwAbs(Gear^.Y-iterator^.Y)).QWordValue) and |
3057 and (hwRound(Distance(Gear^.X-iterator^.X,Gear^.Y-iterator^.Y)) < iterator^.Radius+Gear^.Radius) then // Let's check this one more closely |
3057 (hwRound(Distance(Gear^.X-iterator^.X,Gear^.Y-iterator^.Y)) < Gear^.Radius+iterator^.Radius) then // Let's check this one more closely |
3058 if (Gear^.dX*iterator^.dX + Gear^.dY*iterator^.dY).isNegative then // make sure object moves towards the portal |
3058 begin |
3059 begin |
3059 iterator^.X:=Gear^.IntersectGear^.X+_128; |
3060 s:= (_1+(Int2hwFloat(Gear^.Radius))) / Distance(Gear^.IntersectGear^.dX, Gear^.IntersectGear^.dY); |
3060 iterator^.Y:=Gear^.IntersectGear^.Y+_128; |
3061 iterator^.X:= Gear^.IntersectGear^.X + s * Gear^.IntersectGear^.dX; |
3061 iterator^.dX.isNegative:= not iterator^.dX.isNegative; |
3062 iterator^.Y:= Gear^.IntersectGear^.Y + s * Gear^.IntersectGear^.dY; |
3062 end; |
3063 s:= Distance(iterator^.dX, iterator^.dY) / Distance(Gear^.IntersectGear^.dX, Gear^.IntersectGear^.dY); |
|
3064 iterator^.dX:= s * Gear^.IntersectGear^.dX; |
|
3065 iterator^.dY:= s * Gear^.IntersectGear^.dY; |
|
3066 end; |
3063 |
3067 |
3064 iterator:= iterator^.NextGear; |
3068 iterator:= iterator^.NextGear; |
3065 end; |
3069 end; |
3066 // do portal stuff |
3070 // do portal stuff |
3067 end |
3071 end |
3074 end; |
3078 end; |
3075 |
3079 |
3076 procedure doStepMovingPortal(Gear: PGear); |
3080 procedure doStepMovingPortal(Gear: PGear); |
3077 var x, y, tx, ty: LongInt;//, bx, by, tangle: LongInt; |
3081 var x, y, tx, ty: LongInt;//, bx, by, tangle: LongInt; |
3078 iterator: PGear; |
3082 iterator: PGear; |
|
3083 s, dx, dy: hwFloat; |
3079 begin |
3084 begin |
3080 Gear^.X:= Gear^.X + Gear^.dX; |
3085 Gear^.X:= Gear^.X + Gear^.dX; |
3081 Gear^.Y:= Gear^.Y + Gear^.dY; |
3086 Gear^.Y:= Gear^.Y + Gear^.dY; |
3082 x:= hwRound(Gear^.X); |
3087 x:= hwRound(Gear^.X); |
3083 y:= hwRound(Gear^.Y); |
3088 y:= hwRound(Gear^.Y); |
3088 if not calcSlopeTangent(Gear, x, y, tx, ty, 255) then |
3093 if not calcSlopeTangent(Gear, x, y, tx, ty, 255) then |
3089 begin |
3094 begin |
3090 DeleteGear(Gear); |
3095 DeleteGear(Gear); |
3091 EXIT; |
3096 EXIT; |
3092 end; |
3097 end; |
3093 if not Gear^.dX.isNegative then ty:= -ty; |
3098 |
3094 Gear^.DirAngle:= DxDy2Angle(Int2hwFloat(tx),Int2hwFloat(ty)); |
3099 // reject shots at too irregular terrain |
|
3100 if DistanceI(tx,ty) < _10 then |
|
3101 begin |
|
3102 DeleteGear(Gear); |
|
3103 EXIT; |
|
3104 end; |
|
3105 |
|
3106 // making a normal, normalized vector |
|
3107 s:= _1/DistanceI(tx,ty); |
|
3108 dx:= -s * ty; |
|
3109 dy:= s * tx; |
|
3110 |
|
3111 // make sure the vector is pointing outwards |
|
3112 if not (Gear^.dX*dx + Gear^.dY*dy).isNegative then |
|
3113 begin |
|
3114 dx:= -dx; |
|
3115 dy:= -dy; |
|
3116 end; |
|
3117 |
|
3118 Gear^.dX:= dx; |
|
3119 Gear^.dY:= dy; |
|
3120 |
|
3121 Gear^.DirAngle:= DxDy2Angle(-dy,dx); |
|
3122 if not Gear^.dX.isNegative then Gear^.DirAngle:= 180-Gear^.DirAngle; |
3095 (* |
3123 (* |
3096 This is not quite doing what I want, but basically hoping to avoid portals just sitting out in midair |
3124 This is not quite doing what I want, but basically hoping to avoid portals just sitting out in midair |
3097 Works ok for right angles, aaaand that's about it. |
3125 Works ok for right angles, aaaand that's about it. |
3098 The opposite approach could be taken, we could determine the angle of the land using sheepluva's code and snap the Angle/DirAngle to it. |
3126 The opposite approach could be taken, we could determine the angle of the land using sheepluva's code and snap the Angle/DirAngle to it. |
3099 tangle:= Gear^.Angle+1024; |
3127 tangle:= Gear^.Angle+1024; |