ZDCMP1_Base.zc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Actor that does the bare minumum of ticking
  2. // Use for static, non-interactive actors
  3. //
  4. // Derived from bits and pieces of p_mobj.cpp
  5. // Code by Nash Muhandes and AFADoomer
  6. class SimpleActor : Actor
  7. {
  8. Vector2 floorxy;
  9. Vector3 oldpos;
  10. override void Tick()
  11. {
  12. if (IsFrozen()) { return; }
  13. Vector2 curfloorxy = (curSector.GetXOffset(sector.floor), curSector.GetYOffset(sector.floor)); // Hacky scroll check because MF8_INSCROLLSEC not externalized to ZScript?
  14. bool dotick = (curfloorxy != floorxy) || curSector.flags & sector.SECF_PUSH || (pos != oldpos);
  15. if (dotick) // Only run a full Tick once; or if we are on a carrying floor, pushers are enabled in the sector (wind), or if we moved by some external force
  16. {
  17. oldpos = pos;
  18. Super.Tick();
  19. floorxy = curfloorxy;
  20. return;
  21. }
  22. if (vel != (0, 0, 0)) // Apply velocity as required
  23. {
  24. SetXYZ(Vec3Offset(vel.X, vel.Y, vel.Z)); // Vec3Offset is portal-aware; use instead of just pos + vel, which is not
  25. }
  26. // Tick through actor states as normal
  27. if (tics == -1) { return; }
  28. else if (--tics <= 0)
  29. {
  30. SetState(CurState.NextState);
  31. }
  32. }
  33. }
  34. class ParticleBase : SimpleActor
  35. {
  36. int checktimer;
  37. int flags;
  38. FlagDef CHECKPOSITION:flags, 0;
  39. States
  40. {
  41. Fade:
  42. "####" "#" 1 A_FadeOut(0.1, FTF_REMOVE);
  43. Loop;
  44. }
  45. override void PostBeginPlay()
  46. {
  47. Super.PostBeginPlay();
  48. // Set the initial check at a random tick so they don't all check at once...
  49. checktimer = Random(0, 35);
  50. }
  51. override void Tick()
  52. {
  53. Super.Tick();
  54. if (bCheckPosition && checktimer-- <= 0)
  55. {
  56. // If it's outside the level, remove it
  57. if (!level.IsPointInLevel(pos)) { Destroy(); return; }
  58. checktimer = 35; // Check once every second.
  59. }
  60. }
  61. }
  62. class ZDCMPGameplayStatics play
  63. {
  64. static bool IsOnFloor(Actor self)
  65. {
  66. if (self is "ZDCMPPlayer")
  67. return ZDCMPPlayer(self).player.onground;
  68. return self.Pos.Z <= self.FloorZ || self.bOnMObj || self.bMBFBouncer;
  69. }
  70. static double GetVelocity(Actor self, bool xyOnly = false)
  71. {
  72. if (xyOnly)
  73. return self.Vel.XY.Length();
  74. return self.Vel.Length();
  75. }
  76. }