Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

168 lines
5.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Base combat character with no AI
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #ifndef AI_NODE_H
  14. #define AI_NODE_H
  15. #pragma once
  16. #include "ai_hull.h"
  17. #include "bitstring.h"
  18. #include "utlvector.h"
  19. enum AI_ZoneIds_t
  20. {
  21. AI_NODE_ZONE_UNKNOWN = 0,
  22. AI_NODE_ZONE_SOLO = 1,
  23. AI_NODE_ZONE_UNIVERSAL = 3,
  24. AI_NODE_FIRST_ZONE = 4,
  25. };
  26. class CAI_Network;
  27. class CAI_Link;
  28. class CAI_Hint;
  29. class CAI_BaseNPC;
  30. #define NOT_CACHED -2 // Returned if data not in cache
  31. #define NO_NODE -1 // Returned when no node meets the qualification
  32. #define MAX_NODE_LINK_DIST 60*12 // Maximum connection length between nodes as well as furthest
  33. #define MAX_NODE_LINK_DIST_SQ (MAX_NODE_LINK_DIST*MAX_NODE_LINK_DIST) // distance allowed to travel to node via local moves
  34. #define MAX_AIR_NODE_LINK_DIST 120*12 // Maximum connection length between air nodes as well as furthest
  35. #define MAX_AIR_NODE_LINK_DIST_SQ (MAX_AIR_NODE_LINK_DIST*MAX_AIR_NODE_LINK_DIST) // distance allowed to travel to node via local moves
  36. #define NODE_HEIGHT 8 // how high to lift nodes off the ground after we drop them all (make stair/ramp mapping easier)
  37. #define NODE_CLIMB_OFFSET 8
  38. #define HULL_TEST_STEP_SIZE 16 // how far the test hull moves on each step
  39. //=========================================================
  40. // The type of node
  41. //=========================================================
  42. enum NodeType_e
  43. {
  44. NODE_ANY, // Used to specify any type of node (for search)
  45. NODE_DELETED, // Used in wc_edit mode to remove nodes during runtime
  46. NODE_GROUND,
  47. NODE_AIR,
  48. NODE_CLIMB,
  49. NODE_WATER
  50. };
  51. enum NodeInfoBits_e
  52. {
  53. bits_NODE_CLIMB_BOTTOM = (1 << 0), // Node at bottom of ladder
  54. bits_NODE_CLIMB_ON = (1 << 1), // Node on ladder somewhere
  55. bits_NODE_CLIMB_OFF_FORWARD = (1 << 2), // Dismount climb by going forward
  56. bits_NODE_CLIMB_OFF_LEFT = (1 << 3), // Dismount climb by going left
  57. bits_NODE_CLIMB_OFF_RIGHT = (1 << 4), // Dismount climb by going right
  58. bits_NODE_CLIMB_EXIT = bits_NODE_CLIMB_OFF_FORWARD| bits_NODE_CLIMB_OFF_LEFT | bits_NODE_CLIMB_OFF_RIGHT,
  59. NODE_ENT_FLAGS_SHIFT = 5,
  60. //bits_HUMAN_HULL 5
  61. //bits_SMALL_CENTERED_HULL 6
  62. //bits_WIDE_HUMAN_HULL 7
  63. //bits_TINY_HULL 8
  64. //bits_WIDE_SHORT_HULL 9
  65. //bits_MEDIUM_HULL 10
  66. //bits_TINY_CENTERED_HULL 11
  67. //bits_LARGE_HULL 12
  68. //bits_LARGE_CENTERED_HULL 13
  69. bits_DONT_DROP = ( 1 << 14 ),
  70. /****** NOTE: will need to change node graph save/load code if exceed 16 bits here ******/
  71. bits_NODE_WC_NEED_REBUILD = 0x10000000, // Used to more nodes in WC edit mode
  72. bits_NODE_WC_CHANGED = 0x20000000, // Node changed during WC edit
  73. bits_NODE_WONT_FIT_HULL = 0x40000000, // Used only for debug display
  74. bits_NODE_FALLEN = 0x80000000, // Fell through the world during initialization
  75. };
  76. //=============================================================================
  77. // >> CAI_Node
  78. //=============================================================================
  79. class CAI_Node
  80. {
  81. public:
  82. CAI_Node( int id, const Vector &origin, float yaw );
  83. CAI_Hint* GetHint() { return m_pHint; }
  84. void SetHint( CAI_Hint *pHint ) { m_pHint = pHint; }
  85. int NumLinks() const { return m_Links.Count(); }
  86. void ClearLinks() { m_Links.Purge(); }
  87. CAI_Link * GetLink( int destNodeId );
  88. CAI_Link * GetLinkByIndex( int i ) { return m_Links[i]; }
  89. bool IsLocked() const { return ( m_flNextUseTime > gpGlobals->curtime ); }
  90. void Lock( float duration ) { m_flNextUseTime = gpGlobals->curtime + duration; }
  91. void Unlock() { m_flNextUseTime = gpGlobals->curtime; }
  92. int GetZone() const { return m_zone; }
  93. void SetZone( int zone ) { m_zone = zone; }
  94. Vector GetPosition(int hull); // Hull specific position for a node
  95. CAI_Link* HasLink(int nNodeID); // Return link to nNodeID or NULL
  96. void ShuffleLinks(); // Called before GetShuffeledLinks to reorder
  97. CAI_Link* GetShuffeledLink(int nNum); // Used to get links in different order each time
  98. int GetId() const { return m_iID; }
  99. const Vector & GetOrigin() const { return m_vOrigin; }
  100. Vector & AccessOrigin() { return m_vOrigin; }
  101. float GetYaw() const { return m_flYaw; }
  102. NodeType_e SetType( NodeType_e type ) { return ( m_eNodeType = type ); }
  103. NodeType_e GetType() const { return m_eNodeType; }
  104. void SetNeedsRebuild() { m_eNodeInfo |= bits_NODE_WC_NEED_REBUILD; }
  105. void ClearNeedsRebuild() { m_eNodeInfo &= ~bits_NODE_WC_NEED_REBUILD; }
  106. bool NeedsRebuild() const { return ( ( m_eNodeInfo & bits_NODE_WC_NEED_REBUILD ) != 0 ); }
  107. void AddLink(CAI_Link *newLink);
  108. int m_iID; // ID for this node
  109. Vector m_vOrigin; // location of this node in space
  110. float m_flVOffset[NUM_HULLS]; // vertical offset for each hull type, assuming ground node, 0 otherwise
  111. float m_flYaw; // NPC on this node should face this yaw to face the hint, or climb a ladder
  112. NodeType_e m_eNodeType; // The type of node
  113. int m_eNodeInfo; // bits that tell us more about this nodes
  114. int m_zone;
  115. CUtlVector<CAI_Link *> m_Links; // growable array of links to this node
  116. float m_flNextUseTime; // When can I be used again?
  117. CAI_Hint* m_pHint; // hint attached to this node
  118. int m_iFirstShuffledLink; // first link to check
  119. };
  120. extern float GetFloorZ(const Vector &origin);
  121. extern float GetFloorDistance(const Vector &origin);
  122. #endif // AI_NODE_H