entityplacementcallback.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. class EntityPlacementCallback : ObjectSnapCallback
  2. {
  3. #ifdef DIAG_DEVELOPER
  4. #ifndef SERVER
  5. ref array<Shape> m_Shapes = new array<Shape>();
  6. #endif
  7. #endif
  8. void EntityPlacementCallback()
  9. {
  10. }
  11. void ~EntityPlacementCallback()
  12. {
  13. ClearDebugShapes();
  14. }
  15. void ClearDebugShapes()
  16. {
  17. #ifdef DIAG_DEVELOPER
  18. #ifndef SERVER
  19. foreach (auto shape : m_Shapes)
  20. {
  21. shape.Destroy();
  22. shape = null;
  23. }
  24. m_Shapes.Clear();
  25. #endif
  26. #endif
  27. }
  28. override void OnSetup()
  29. {
  30. #ifdef DIAG_DEVELOPER
  31. #ifndef SERVER
  32. m_DebugEnabled = DiagMenu.GetBool(DiagMenuIDs.INVENTORY_ENTITY_PLACEMENT_CALLBACK_DEBUG);
  33. #endif
  34. #endif
  35. ClearDebugShapes();
  36. m_DirectionFunc[0] = 1.2;
  37. m_DirectionFunc[1] = 0.3;
  38. Human human;
  39. if (Class.CastTo(human, m_Owner))
  40. {
  41. m_OwnerPosition = human.GetBonePositionWS(human.GetBoneIndexByName("Head"));
  42. HumanInputController hic = human.GetInputController();
  43. if (hic)
  44. {
  45. float headingAngle = hic.GetHeadingAngle() + Math.PI_HALF;
  46. m_OwnerDirection[0] = Math.Cos(headingAngle);
  47. m_OwnerDirection[1] = 0.0;
  48. m_OwnerDirection[2] = Math.Sin(headingAngle);
  49. m_OwnerDirection.Normalized();
  50. }
  51. else
  52. {
  53. m_OwnerDirection = human.GetDirection();
  54. }
  55. }
  56. else if (m_Owner)
  57. {
  58. m_OwnerPosition = m_Owner.GetPosition();
  59. m_OwnerDirection = m_Owner.GetDirection();
  60. }
  61. }
  62. override void OnDebug(vector p0, vector p1, bool hasHit, bool found)
  63. {
  64. #ifdef DIAG_DEVELOPER
  65. #ifndef SERVER
  66. Shape shape;
  67. int alpha = 0x33000000;
  68. int colour = 0x00FF0000;
  69. if (!hasHit && found)
  70. {
  71. colour = 0x000000FF;
  72. }
  73. else if (!hasHit)
  74. {
  75. colour = 0x0000FF00;
  76. alpha = 0x11000000;
  77. }
  78. shape = Shape.Create(ShapeType.BBOX, colour | alpha, ShapeFlags.NOZBUFFER | ShapeFlags.TRANSP, -m_Extents, m_Extents);
  79. shape.SetMatrix(m_Transform);
  80. m_Shapes.Insert(shape);
  81. vector p[2];
  82. p[0] = p0;
  83. p[1] = p1;
  84. shape = Shape.CreateLines(colour | 0xFF000000, ShapeFlags.NOZBUFFER | ShapeFlags.TRANSP, p, 2);
  85. m_Shapes.Insert(shape);
  86. #endif
  87. #endif
  88. }
  89. override bool OnFirstContact(Object other)
  90. {
  91. if (!other.IsTransport())
  92. {
  93. return false;
  94. }
  95. return true;
  96. }
  97. override bool OnQuery(Object other)
  98. {
  99. if (other.IsScenery())
  100. {
  101. return false;
  102. }
  103. if (other.IsMan())
  104. {
  105. return false;
  106. }
  107. EntityAI entity;
  108. if (Class.CastTo(entity, other))
  109. {
  110. if (entity.IsAnimal() || entity.IsZombie())
  111. {
  112. return false;
  113. }
  114. }
  115. if (other.GetCollisionRadius() < 0.05)
  116. {
  117. return false;
  118. }
  119. return true;
  120. }
  121. override bool OnCollide(Object other)
  122. {
  123. if (other.IsScenery())
  124. {
  125. return false;
  126. }
  127. if (other.IsMan())
  128. {
  129. return false;
  130. }
  131. if (!other.CanObstruct() && !other.IsTransport())
  132. {
  133. return false;
  134. }
  135. return true;
  136. }
  137. };