Npc New.cpp: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Provided the correct npc_New.cpp from "https://web.archive.org/web/20061022062326/http://developer.valvesoftware.com/wiki/Npc_New.cpp") |
||
Line 1: | Line 1: | ||
== npc_New.cpp == | |||
== | |||
<pre>//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// | <pre>//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// | ||
Line 9: | Line 7: | ||
// NPC and add the copy to the build. | // NPC and add the copy to the build. | ||
// | // | ||
// Replace occurrences of CNPC_New with the new NPC's | |||
// classname. Don't forget the lower-case occurrence in | |||
// Replace | |||
// classname. Don't forget the lower-case | |||
// LINK_ENTITY_TO_CLASS() | // LINK_ENTITY_TO_CLASS() | ||
// | // | ||
Line 21: | Line 15: | ||
// | // | ||
// You're making a character based on CAI_BaseNPC. If this | // You're making a character based on CAI_BaseNPC. If this | ||
// is not true, make sure you replace all | // is not true, make sure you replace all occurrences | ||
// of 'CAI_BaseNPC' in this file with the appropriate | // of 'CAI_BaseNPC' in this file with the appropriate | ||
// parent class. | // parent class. | ||
Line 40: | Line 34: | ||
#include "ai_basenpc.h" | #include "ai_basenpc.h" | ||
#include "engine/IEngineSound.h" | #include "engine/IEngineSound.h" | ||
#define NPC_NEW_MODEL "models/mymodel.mdl" | |||
// memdbgon must be the last include file in a .cpp file!!! | // memdbgon must be the last include file in a .cpp file!!! | ||
Line 45: | Line 41: | ||
//========================================================= | //========================================================= | ||
// Private | // Private animevents | ||
//========================================================= | //========================================================= | ||
int | int NEWNPC_AE_ANIMEVENT; | ||
int NEWNPC_AE_ANIMEVENT2; | |||
//========================================================= | //========================================================= | ||
// | // Private activities | ||
//========================================================= | //========================================================= | ||
Activity ACT_NEWNPC_ACTIVITY; | |||
Activity ACT_NEWNPC_ACTIVITY2; | |||
//========================================================= | //========================================================= | ||
// | // Shared interaction | ||
//========================================================= | //========================================================= | ||
int g_interactionExample = 0; // REMEMBER TO ADD THIS TO AI_Interactions.h | |||
int g_interactionExample2 = 0; // REMEMBER TO ADD THIS TO AI_Interactions.h | |||
// | // ----------------------------------------------- | ||
// | // > Squad slots | ||
// | // ----------------------------------------------- | ||
enum | enum SquadSlot_T | ||
{ | { | ||
SQUAD_SLOT_EXAMPLE = LAST_SHARED_SQUADSLOT, | |||
SQUAD_SLOT_EXAMPLE2, | |||
}; | }; | ||
//========================================================= | //========================================================= | ||
//========================================================= | //========================================================= | ||
class | class CNPC_New : public CAI_BaseNPC | ||
{ | { | ||
DECLARE_CLASS( | DECLARE_CLASS( CNPC_New, CAI_BaseNPC ); | ||
DECLARE_DATADESC(); | |||
DEFINE_CUSTOM_AI; | |||
public: | public: | ||
Line 85: | Line 79: | ||
void Spawn( void ); | void Spawn( void ); | ||
Class_T Classify( void ); | Class_T Classify( void ); | ||
private: | |||
enum | |||
{ | |||
SCHED_NEWNPC_SCHEDULE = BaseClass::NEXT_SCHEDULE, | |||
SCHED_NEWNPC_SCHEDULE2, | |||
NEXT_SCHEDULE | |||
}; | |||
enum | |||
{ | |||
TASK_NEWNPC_TASK = BaseClass::NEXT_TASK, | |||
TASK_NEWNPC_TASK2, | |||
NEXT_TASK | |||
}; | |||
enum | |||
{ | |||
COND_NEWNPC_CONDITION = BaseClass::NEXT_CONDITION, | |||
COND_NEWNPC_CONDITION2, | |||
NEXT_CONDITION | |||
}; | |||
}; | }; | ||
LINK_ENTITY_TO_CLASS( npc_newnpc, | LINK_ENTITY_TO_CLASS( npc_newnpc, CNPC_New ); | ||
//--------------------------------------------------------- | //--------------------------------------------------------- | ||
// Save/Restore | // Save/Restore | ||
//--------------------------------------------------------- | //--------------------------------------------------------- | ||
BEGIN_DATADESC( | BEGIN_DATADESC( CNPC_New ) | ||
END_DATADESC() | END_DATADESC() | ||
AI_BEGIN_CUSTOM_NPC(CNPC_New) | |||
AI_END_CUSTOM_NPC() | |||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
Line 134: | Line 120: | ||
// | // | ||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
void | void CNPC_New::Precache( void ) | ||
{ | { | ||
PrecacheModel( | PrecacheModel( NPC_NEW_MODEL ); | ||
BaseClass::Precache(); | BaseClass::Precache(); | ||
Line 147: | Line 133: | ||
// | // | ||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
void | void CNPC_New::Spawn( void ) | ||
{ | { | ||
Precache(); | Precache(); | ||
SetModel( | SetModel( NPC_NEW_MODEL ); | ||
SetHullType(HULL_HUMAN); | SetHullType(HULL_HUMAN); | ||
SetHullSizeNormal(); | SetHullSizeNormal(); | ||
Line 159: | Line 145: | ||
SetMoveType( MOVETYPE_STEP ); | SetMoveType( MOVETYPE_STEP ); | ||
SetBloodColor( BLOOD_COLOR_RED ); | SetBloodColor( BLOOD_COLOR_RED ); | ||
m_iHealth | m_iHealth = 20; | ||
m_flFieldOfView | m_flFieldOfView = 0.5; // indicates the width of this NPC's forward view cone ( as a dotproduct result ) | ||
m_NPCState | m_NPCState = NPC_STATE_NONE; | ||
CapabilitiesClear(); | CapabilitiesClear(); | ||
CapabilitiesAdd( bits_CAP_TURN_HEAD | bits_CAP_MOVE_GROUND ); | |||
NPCInit(); | NPCInit(); | ||
Line 176: | Line 162: | ||
// Output : | // Output : | ||
//----------------------------------------------------------------------------- | //----------------------------------------------------------------------------- | ||
Class_T | Class_T CNPC_New::Classify( void ) | ||
{ | { | ||
return CLASS_NONE; | return CLASS_NONE; | ||
}</pre> | }</pre> | ||
Revision as of 08:13, 22 June 2021
npc_New.cpp
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============// // This is a skeleton file for use when creating a new // NPC. Copy and rename this file for the new // NPC and add the copy to the build. // // Replace occurrences of CNPC_New with the new NPC's // classname. Don't forget the lower-case occurrence in // LINK_ENTITY_TO_CLASS() // // // ASSUMPTIONS MADE: // // You're making a character based on CAI_BaseNPC. If this // is not true, make sure you replace all occurrences // of 'CAI_BaseNPC' in this file with the appropriate // parent class. // // You're making a human-sized NPC that walks. // //=============================================================================// #include "cbase.h" #include "ai_default.h" #include "ai_task.h" #include "ai_schedule.h" #include "ai_hull.h" #include "soundent.h" #include "game.h" #include "npcevent.h" #include "entitylist.h" #include "activitylist.h" #include "ai_basenpc.h" #include "engine/IEngineSound.h" #define NPC_NEW_MODEL "models/mymodel.mdl" // memdbgon must be the last include file in a .cpp file!!! #include "tier0/memdbgon.h" //========================================================= // Private animevents //========================================================= int NEWNPC_AE_ANIMEVENT; int NEWNPC_AE_ANIMEVENT2; //========================================================= // Private activities //========================================================= Activity ACT_NEWNPC_ACTIVITY; Activity ACT_NEWNPC_ACTIVITY2; //========================================================= // Shared interaction //========================================================= int g_interactionExample = 0; // REMEMBER TO ADD THIS TO AI_Interactions.h int g_interactionExample2 = 0; // REMEMBER TO ADD THIS TO AI_Interactions.h // ----------------------------------------------- // > Squad slots // ----------------------------------------------- enum SquadSlot_T { SQUAD_SLOT_EXAMPLE = LAST_SHARED_SQUADSLOT, SQUAD_SLOT_EXAMPLE2, }; //========================================================= //========================================================= class CNPC_New : public CAI_BaseNPC { DECLARE_CLASS( CNPC_New, CAI_BaseNPC ); DECLARE_DATADESC(); DEFINE_CUSTOM_AI; public: void Precache( void ); void Spawn( void ); Class_T Classify( void ); private: enum { SCHED_NEWNPC_SCHEDULE = BaseClass::NEXT_SCHEDULE, SCHED_NEWNPC_SCHEDULE2, NEXT_SCHEDULE }; enum { TASK_NEWNPC_TASK = BaseClass::NEXT_TASK, TASK_NEWNPC_TASK2, NEXT_TASK }; enum { COND_NEWNPC_CONDITION = BaseClass::NEXT_CONDITION, COND_NEWNPC_CONDITION2, NEXT_CONDITION }; }; LINK_ENTITY_TO_CLASS( npc_newnpc, CNPC_New ); //--------------------------------------------------------- // Save/Restore //--------------------------------------------------------- BEGIN_DATADESC( CNPC_New ) END_DATADESC() AI_BEGIN_CUSTOM_NPC(CNPC_New) AI_END_CUSTOM_NPC() //----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CNPC_New::Precache( void ) { PrecacheModel( NPC_NEW_MODEL ); BaseClass::Precache(); } //----------------------------------------------------------------------------- // Purpose: // // //----------------------------------------------------------------------------- void CNPC_New::Spawn( void ) { Precache(); SetModel( NPC_NEW_MODEL ); SetHullType(HULL_HUMAN); SetHullSizeNormal(); SetSolid( SOLID_BBOX ); AddSolidFlags( FSOLID_NOT_STANDABLE ); SetMoveType( MOVETYPE_STEP ); SetBloodColor( BLOOD_COLOR_RED ); m_iHealth = 20; m_flFieldOfView = 0.5; // indicates the width of this NPC's forward view cone ( as a dotproduct result ) m_NPCState = NPC_STATE_NONE; CapabilitiesClear(); CapabilitiesAdd( bits_CAP_TURN_HEAD | bits_CAP_MOVE_GROUND ); NPCInit(); } //----------------------------------------------------------------------------- // Purpose: // // // Output : //----------------------------------------------------------------------------- Class_T CNPC_New::Classify( void ) { return CLASS_NONE; }