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.

176 lines
4.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. // This is a skeleton file for use when creating a new
  3. // NPC. Copy and rename this file for the new
  4. // NPC and add the copy to the build.
  5. //
  6. // Leave this file in the build until we ship! Allowing
  7. // this file to be rebuilt with the rest of the game ensures
  8. // that it stays up to date with the rest of the NPC code.
  9. //
  10. // Replace occurances of CNewNPC with the new NPC's
  11. // classname. Don't forget the lower-case occurance in
  12. // LINK_ENTITY_TO_CLASS()
  13. //
  14. //
  15. // ASSUMPTIONS MADE:
  16. //
  17. // You're making a character based on CAI_BaseNPC. If this
  18. // is not true, make sure you replace all occurances
  19. // of 'CAI_BaseNPC' in this file with the appropriate
  20. // parent class.
  21. //
  22. // You're making a human-sized NPC that walks.
  23. //
  24. //=============================================================================//
  25. #include "cbase.h"
  26. #include "ai_default.h"
  27. #include "ai_task.h"
  28. #include "ai_schedule.h"
  29. #include "ai_hull.h"
  30. #include "soundent.h"
  31. #include "game.h"
  32. #include "npcevent.h"
  33. #include "entitylist.h"
  34. #include "activitylist.h"
  35. #include "ai_basenpc.h"
  36. #include "engine/IEngineSound.h"
  37. // memdbgon must be the last include file in a .cpp file!!!
  38. #include "tier0/memdbgon.h"
  39. //=========================================================
  40. // Private activities
  41. //=========================================================
  42. int ACT_MYCUSTOMACTIVITY = -1;
  43. //=========================================================
  44. // Custom schedules
  45. //=========================================================
  46. enum
  47. {
  48. SCHED_MYCUSTOMSCHEDULE = LAST_SHARED_SCHEDULE,
  49. };
  50. //=========================================================
  51. // Custom tasks
  52. //=========================================================
  53. enum
  54. {
  55. TASK_MYCUSTOMTASK = LAST_SHARED_TASK,
  56. };
  57. //=========================================================
  58. // Custom Conditions
  59. //=========================================================
  60. enum
  61. {
  62. COND_MYCUSTOMCONDITION = LAST_SHARED_CONDITION,
  63. };
  64. //=========================================================
  65. //=========================================================
  66. class CNewNPC : public CAI_BaseNPC
  67. {
  68. DECLARE_CLASS( CNewNPC, CAI_BaseNPC );
  69. public:
  70. void Precache( void );
  71. void Spawn( void );
  72. Class_T Classify( void );
  73. DECLARE_DATADESC();
  74. // This is a dummy field. In order to provide save/restore
  75. // code in this file, we must have at least one field
  76. // for the code to operate on. Delete this field when
  77. // you are ready to do your own save/restore for this
  78. // character.
  79. int m_iDeleteThisField;
  80. DEFINE_CUSTOM_AI;
  81. };
  82. LINK_ENTITY_TO_CLASS( npc_newnpc, CNewNPC );
  83. IMPLEMENT_CUSTOM_AI( npc_citizen,CNewNPC );
  84. //---------------------------------------------------------
  85. // Save/Restore
  86. //---------------------------------------------------------
  87. BEGIN_DATADESC( CNewNPC )
  88. DEFINE_FIELD( m_iDeleteThisField, FIELD_INTEGER ),
  89. END_DATADESC()
  90. //-----------------------------------------------------------------------------
  91. // Purpose: Initialize the custom schedules
  92. // Input :
  93. // Output :
  94. //-----------------------------------------------------------------------------
  95. void CNewNPC::InitCustomSchedules(void)
  96. {
  97. INIT_CUSTOM_AI(CNewNPC);
  98. ADD_CUSTOM_TASK(CNewNPC, TASK_MYCUSTOMTASK);
  99. ADD_CUSTOM_SCHEDULE(CNewNPC, SCHED_MYCUSTOMSCHEDULE);
  100. ADD_CUSTOM_ACTIVITY(CNewNPC, ACT_MYCUSTOMACTIVITY);
  101. ADD_CUSTOM_CONDITION(CNewNPC, COND_MYCUSTOMCONDITION);
  102. }
  103. //-----------------------------------------------------------------------------
  104. // Purpose:
  105. //
  106. //
  107. //-----------------------------------------------------------------------------
  108. void CNewNPC::Precache( void )
  109. {
  110. PrecacheModel( "models/mymodel.mdl" );
  111. BaseClass::Precache();
  112. }
  113. //-----------------------------------------------------------------------------
  114. // Purpose:
  115. //
  116. //
  117. //-----------------------------------------------------------------------------
  118. void CNewNPC::Spawn( void )
  119. {
  120. Precache();
  121. SetModel( "models/mymodel.mdl" );
  122. SetHullType(HULL_HUMAN);
  123. SetHullSizeNormal();
  124. SetSolid( SOLID_BBOX );
  125. AddSolidFlags( FSOLID_NOT_STANDABLE );
  126. SetMoveType( MOVETYPE_STEP );
  127. SetBloodColor( BLOOD_COLOR_RED );
  128. m_iHealth = 20;
  129. m_flFieldOfView = 0.5;
  130. m_NPCState = NPC_STATE_NONE;
  131. CapabilitiesClear();
  132. //CapabilitiesAdd( bits_CAP_NONE );
  133. NPCInit();
  134. }
  135. //-----------------------------------------------------------------------------
  136. // Purpose:
  137. //
  138. //
  139. // Output :
  140. //-----------------------------------------------------------------------------
  141. Class_T CNewNPC::Classify( void )
  142. {
  143. return CLASS_NONE;
  144. }