3203 end; |
3203 end; |
3204 |
3204 |
3205 procedure doStepPortal(Gear: PGear); |
3205 procedure doStepPortal(Gear: PGear); |
3206 var |
3206 var |
3207 iterator, conPortal: PGear; |
3207 iterator, conPortal: PGear; |
3208 s, acptRadius, cdxy: hwFloat; |
3208 s, acptRadius, itdist, nx, ny, pspeed, nspeed: hwFloat; |
3209 noTrap, hasdxy: Boolean; |
3209 noTrap, hasdxy: Boolean; |
3210 begin |
3210 begin |
3211 doPortalColorSwitch(); |
3211 doPortalColorSwitch(); |
3212 |
3212 |
3213 // destroy portal if ground it was attached too is gone |
3213 // destroy portal if ground it was attached too is gone |
3279 if hasdxy and not (Gear^.dX*iterator^.dX + Gear^.dY*iterator^.dY).isNegative then |
3279 if hasdxy and not (Gear^.dX*iterator^.dX + Gear^.dY*iterator^.dY).isNegative then |
3280 continue; |
3280 continue; |
3281 // won't port stuff that moves away from me! |
3281 // won't port stuff that moves away from me! |
3282 |
3282 |
3283 // wow! good candidate there, let's see if the distance really is small enough! |
3283 // wow! good candidate there, let's see if the distance really is small enough! |
3284 if (Distance(Gear^.X-iterator^.X,Gear^.Y-iterator^.Y) > acptRadius) then |
3284 itdist := Distance(Gear^.X-iterator^.X,Gear^.Y-iterator^.Y); |
|
3285 if (itdist > acptRadius) then |
3285 continue; |
3286 continue; |
3286 (* |
3287 (* |
3287 noTrap := ((not Gear^.dY.isNegative or (Gear^.dY.QWordValue = 0)) |
3288 noTrap := ((not Gear^.dY.isNegative or (Gear^.dY.QWordValue = 0)) |
3288 // can't be entered from above |
3289 // can't be entered from above |
3289 or ((conPortal^.dY.isNegative and not (conPortal^.dY.QWordValue = 0)))); |
3290 or ((conPortal^.dY.isNegative and not (conPortal^.dY.QWordValue = 0)))); |
3298 DeleteCI(iterator); |
3299 DeleteCI(iterator); |
3299 |
3300 |
3300 // Until loops are reliably broken |
3301 // Until loops are reliably broken |
3301 inc(iterator^.PortalCounter); |
3302 inc(iterator^.PortalCounter); |
3302 |
3303 |
3303 // TODO: more accurate porting |
3304 // find out how much speed parallel to the portal vector |
3304 cdxy := Distance(conPortal^.dX, conPortal^.dY); |
3305 // the gear has |
3305 s := (Int2hwFloat(Gear^.Radius)) / cdxy; |
3306 pspeed:= (Gear^.dX * iterator^.dX + Gear^.dY * iterator^.dY ); |
3306 |
3307 // create a normal of the portal vector |
|
3308 nx := - Gear^.dY; |
|
3309 ny := Gear^.dX; |
|
3310 // pick the normal vector that's pointing skywards |
|
3311 if (not ny.isNegative) then |
|
3312 begin |
|
3313 nx.isNegative := not nx.isNegative; |
|
3314 ny.isNegative := not ny.isNegative; |
|
3315 end; |
|
3316 // now let's find out how much speed the gear has in the |
|
3317 // direction of that normal |
|
3318 nspeed:= (nx * iterator^.dX + ny * iterator^.dY); |
|
3319 |
|
3320 // now let's project those back to the connected portal's vectors |
|
3321 nx := - conPortal^.dY; |
|
3322 ny := conPortal^.dX; |
|
3323 if ny.isNegative then |
|
3324 begin |
|
3325 nx.isNegative := not nx.isNegative; |
|
3326 ny.isNegative := not ny.isNegative; |
|
3327 end; |
|
3328 iterator^.dX := -pspeed * conPortal^.dX + -nspeed * nx; |
|
3329 iterator^.dY := -pspeed * conPortal^.dY + -nspeed * ny; |
3307 if iterator^.Kind = gtCake then |
3330 if iterator^.Kind = gtCake then |
3308 begin |
3331 itdist := int2hwFloat(iterator^.Radius) - _0_1; |
3309 iterator^.X := conPortal^.X ; |
3332 s := itdist / Distance(iterator^.dX, iterator^.dY); |
3310 iterator^.Y := conPortal^.Y ; |
3333 iterator^.X := conPortal^.X + s * iterator^.dX; |
3311 end |
3334 iterator^.Y := conPortal^.Y + s * iterator^.dY; |
3312 else |
3335 end; |
3313 begin |
|
3314 iterator^.X := conPortal^.X + s * conPortal^.dX; |
|
3315 iterator^.Y := conPortal^.Y + s * conPortal^.dY; |
|
3316 |
|
3317 s := Distance(iterator^.dX, iterator^.dY) / cdxy; |
|
3318 |
|
3319 iterator^.dX := s * conPortal^.dX; |
|
3320 iterator^.dY := s * conPortal^.dY |
|
3321 end; |
|
3322 |
3336 |
3323 FollowGear := iterator; |
3337 FollowGear := iterator; |
3324 |
3338 |
|
3339 { |
3325 s := _0_2 + _0_008 * Gear^.Health; |
3340 s := _0_2 + _0_008 * Gear^.Health; |
3326 iterator^.dX := s * iterator^.dX; |
3341 iterator^.dX := s * iterator^.dX; |
3327 iterator^.dY := s * iterator^.dY; |
3342 iterator^.dY := s * iterator^.dY; |
|
3343 } |
3328 |
3344 |
3329 if Gear^.Health > 1 then dec(Gear^.Health); |
3345 if Gear^.Health > 1 then dec(Gear^.Health); |
3330 //dec(iterator^.Health);?? |
3346 |
3331 |
3347 { // breaks (some) loops |
3332 // breaks (some) loops |
|
3333 if Distance(iterator^.dX, iterator^.dY) > _0_96 then |
3348 if Distance(iterator^.dX, iterator^.dY) > _0_96 then |
3334 begin |
3349 begin |
3335 iterator^.dX := iterator^.dX + signAs(cGravity * getRandom(1000),iterator^.dX); |
3350 iterator^.dX := iterator^.dX + signAs(cGravity * getRandom(1000),iterator^.dX); |
3336 iterator^.dY := iterator^.dY + signAs(cGravity * getRandom(1000),iterator^.dY); |
3351 iterator^.dY := iterator^.dY + signAs(cGravity * getRandom(1000),iterator^.dY); |
3337 s := _0_96 / Distance(iterator^.dX, iterator^.dY); |
3352 s := _0_96 / Distance(iterator^.dX, iterator^.dY); |
3338 iterator^.dX := s * iterator^.dX; |
3353 iterator^.dX := s * iterator^.dX; |
3339 iterator^.dY := s * iterator^.dX; |
3354 iterator^.dY := s * iterator^.dX; |
3340 end; |
3355 end; |
3341 end; |
3356 } |
3342 end; |
3357 end; |
3343 |
3358 |
3344 procedure doStepMovingPortal_real(Gear: PGear); |
3359 procedure doStepMovingPortal_real(Gear: PGear); |
3345 var |
3360 var |
3346 x, y, tx, ty: LongInt; |
3361 x, y, tx, ty: LongInt; |