Advertisement
Guest User

Untitled

a guest
Jul 29th, 2022
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.47 KB | None | 0 0
  1. Class WalkTracer : LineTracer
  2. {
  3.     Line lastLine; //unused right now
  4.     Sector LastSector; //store last found sector
  5.     double LastStepHeight; //last sector height
  6.     vector3 HitPoint; //place where I found a ledge
  7.     bool HitLedge; //did I find a ledge?
  8.     actor owner; //caller
  9.     int hitcount; //count the number of times there's an intersection
  10.     double MaxStepHeight; //gotten from actor
  11.  
  12.     override ETraceStatus TraceCallback()
  13.     {
  14.        
  15.         sector NextSector = Results.HitSector;
  16.         if (!NextSector) return TRACE_skip; //if sector has not changed, continue tracing
  17.  
  18.         if(NextSector != LastSector) //sector has changed
  19.         {
  20.             //count the number of times i encounter a new sector
  21.             hitcount++;
  22.             console.printf('HIT %i', hitcount);
  23.            
  24.             vector3 hitpos = Results.HitPos;
  25.  
  26.             //get the floor height at this point
  27.             double NextStepHeight = NextSector.floorplane.ZatPoint(hitpos.XY);
  28.             //difference between current and last floor height
  29.             double stepDifference =  NextStepHeight - LastStepHeight;
  30.  
  31.             //store last sector
  32.             LastSector = NextSector;
  33.  
  34.             //store last step height
  35.             LastStepHeight = NextStepHeight;
  36.            
  37.  
  38.             if ( stepDifference > MaxStepHeight ) {
  39.                 HitLedge = true;
  40.                 return TRACE_Stop;
  41.  
  42.             } else if (stepDifference < -MaxStepHeight ) {
  43.                 HitLedge = true;
  44.                 return TRACE_Stop;
  45.  
  46.             } else {
  47.                 return TRACE_skip;
  48.             }
  49.  
  50.         } else {
  51.             return TRACE_skip;
  52.         }
  53.  
  54.         if(Results.HitType == TRACE_HitActor)
  55.         {
  56.             return TRACE_skip;
  57.         }
  58.        
  59.         return TRACE_Stop;
  60.     }
  61.  
  62.     bool TraceFrom (actor caller, vector3 start, Sector sec, vector3 direction, double maxDist, ETraceFlags traceFlags)
  63.     {
  64.         self.hitcount = 0; //reset count
  65.         self.owner = caller;   //the thing that is doing the trace
  66.         self.MaxStepHeight = caller.MaxStepHeight; //the maximum vertical movement we consider a blocking height
  67.  
  68.         self.LastSector = sec; //record sector
  69.         self.lastLine = null; //unused
  70.  
  71.         self.HitLedge = false; //reset hit
  72.         self.LastStepHeight = sec.floorplane.ZatPoint(start.XY); //get starting floor height
  73.  
  74.         return Trace (start, sec, direction, maxDist, traceFlags);
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement