Npc New.cpp: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Source file npc_new.cpp is also known as monster_dummy.cpp; found in newly created mod folders and used as a template for creating a new npc from scratch.
{{Dead end|date=January 2024}}


== npc_New.cpp ==


== monster_dummy.cpp ==
<source lang=cpp>
 
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
<pre>//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
// This is a skeleton file for use when creating a new  
// This is a skeleton file for use when creating a new  
// NPC. Copy and rename this file for the new
// NPC. Copy and rename this file for the new
// NPC and add the copy to the build.
// NPC and add the copy to the build.
//
//
// Leave this file in the build until we ship! Allowing
// Replace occurrences of CNPC_New with the new NPC's
// this file to be rebuilt with the rest of the game ensures
// classname. Don't forget the lower-case occurrence in  
// that it stays up to date with the rest of the NPC code.
//
// Replace occurances of CNewNPC with the new NPC's
// classname. Don't forget the lower-case occurance in  
// LINK_ENTITY_TO_CLASS()
// LINK_ENTITY_TO_CLASS()
//
//
Line 21: Line 17:
//
//
// 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 occurances
// 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 33: Line 29:
#include "ai_schedule.h"
#include "ai_schedule.h"
#include "ai_hull.h"
#include "ai_hull.h"
#include "ai_squad.h"
#include "soundent.h"
#include "soundent.h"
#include "game.h"
#include "game.h"
Line 40: Line 37:
#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 44:


//=========================================================
//=========================================================
// Private activities
// Private animevents
//=========================================================
//=========================================================
int ACT_MYCUSTOMACTIVITY = -1;
int NEWNPC_AE_ANIMEVENT;
int NEWNPC_AE_ANIMEVENT2;


//=========================================================
//=========================================================
// Custom schedules
// Private activities
//=========================================================
//=========================================================
enum
Activity ACT_NEWNPC_ACTIVITY;
{
Activity ACT_NEWNPC_ACTIVITY2;
SCHED_MYCUSTOMSCHEDULE = LAST_SHARED_SCHEDULE,
};


//=========================================================
//=========================================================
// Custom tasks
// Shared interaction
//=========================================================
//=========================================================
enum
int g_interactionExample = 0; // REMEMBER TO ADD THIS TO AI_Interactions.h
{
int g_interactionExample2 = 0; // REMEMBER TO ADD THIS TO AI_Interactions.h
TASK_MYCUSTOMTASK = LAST_SHARED_TASK,
};
 


//=========================================================
// -----------------------------------------------
// Custom Conditions
// > Squad slots
//=========================================================
// -----------------------------------------------
enum  
enum SquadSlot_T
{
{
COND_MYCUSTOMCONDITION = LAST_SHARED_CONDITION,
SQUAD_SLOT_EXAMPLE = LAST_SHARED_SQUADSLOT,
SQUAD_SLOT_EXAMPLE2,
};
};


//=========================================================
//=========================================================
//=========================================================
//=========================================================
class CNewNPC : public CAI_BaseNPC
class CNPC_New : public CAI_BaseNPC
{
{
DECLARE_CLASS( CNewNPC, CAI_BaseNPC );
DECLARE_CLASS( CNPC_New, CAI_BaseNPC );
DECLARE_DATADESC();
DEFINE_CUSTOM_AI;


public:
public:
Line 85: Line 82:
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
};


DECLARE_DATADESC();
enum
 
{
// This is a dummy field. In order to provide save/restore
TASK_NEWNPC_TASK = BaseClass::NEXT_TASK,
// code in this file, we must have at least one field
TASK_NEWNPC_TASK2,
// for the code to operate on. Delete this field when
NEXT_TASK
// you are ready to do your own save/restore for this
};
// character.
int m_iDeleteThisField;


DEFINE_CUSTOM_AI;
enum
{
COND_NEWNPC_CONDITION = BaseClass::NEXT_CONDITION,
COND_NEWNPC_CONDITION2,
NEXT_CONDITION
};
};
};


LINK_ENTITY_TO_CLASS( npc_newnpc, CNewNPC );
LINK_ENTITY_TO_CLASS( npc_newnpc, CNPC_New );
IMPLEMENT_CUSTOM_AI( npc_citizen,CNewNPC );
 


//---------------------------------------------------------
//---------------------------------------------------------
// Save/Restore
// Save/Restore
//---------------------------------------------------------
//---------------------------------------------------------
BEGIN_DATADESC( CNewNPC )
BEGIN_DATADESC( CNPC_New )
 
DEFINE_FIELD( m_iDeleteThisField, FIELD_INTEGER ),


END_DATADESC()
END_DATADESC()


//-----------------------------------------------------------------------------
AI_BEGIN_CUSTOM_NPC(npc_newnpc, CNPC_New)
// Purpose: Initialize the custom schedules
// Input  :
// Output :
//-----------------------------------------------------------------------------
void CNewNPC::InitCustomSchedules(void)
{
INIT_CUSTOM_AI(CNewNPC);
 
ADD_CUSTOM_TASK(CNewNPC, TASK_MYCUSTOMTASK);
 
ADD_CUSTOM_SCHEDULE(CNewNPC, SCHED_MYCUSTOMSCHEDULE);


ADD_CUSTOM_ACTIVITY(CNewNPC, ACT_MYCUSTOMACTIVITY);
AI_END_CUSTOM_NPC()
 
ADD_CUSTOM_CONDITION(CNewNPC, COND_MYCUSTOMCONDITION);
}


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
Line 134: Line 123:
//
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CNewNPC::Precache( void )
void CNPC_New::Precache( void )
{
{
PrecacheModel( "models/mymodel.mdl" );
PrecacheModel( NPC_NEW_MODEL );


BaseClass::Precache();
BaseClass::Precache();
}
}


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
Line 147: Line 135:
//
//
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CNewNPC::Spawn( void )
void CNPC_New::Spawn( void )
{
{
Precache();
Precache();


SetModel( "models/mymodel.mdl" );
SetModel( NPC_NEW_MODEL );
SetHullType(HULL_HUMAN);
SetHullType(HULL_HUMAN);
SetHullSizeNormal();
SetHullSizeNormal();
Line 159: Line 147:
SetMoveType( MOVETYPE_STEP );
SetMoveType( MOVETYPE_STEP );
SetBloodColor( BLOOD_COLOR_RED );
SetBloodColor( BLOOD_COLOR_RED );
m_iHealth = 20;
m_iHealth = 20;
m_flFieldOfView = 0.5;
m_flFieldOfView = 0.5; // indicates the width of this NPC's forward view cone ( as a dotproduct result )
m_NPCState = NPC_STATE_NONE;
m_NPCState = NPC_STATE_NONE;


CapabilitiesClear();
CapabilitiesClear();
//CapabilitiesAdd( bits_CAP_NONE );
CapabilitiesAdd( bits_CAP_TURN_HEAD | bits_CAP_MOVE_GROUND );


NPCInit();
NPCInit();
}
}


//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
Line 176: Line 163:
// Output :  
// Output :  
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
Class_T CNewNPC::Classify( void )
Class_T CNPC_New::Classify( void )
{
{
return CLASS_NONE;
return CLASS_NONE;
}</pre>
}</source>


--[[User:M4pster|M4pster]] 22:08, 1 February 2013 (PST)
{{Uncategorized|date=January 2024}}

Latest revision as of 12:12, 30 May 2025

Dead End - Icon.png
This article has no Wikipedia icon links to other VDC articles. Please help improve this article by adding links Wikipedia icon that are relevant to the context within the existing text.
January 2024

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 "ai_squad.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(npc_newnpc, 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;
}
Wikipedia - Letter.png
This article has not been added to any content Wikipedia icon categories. Please help out by Wikipedia icon adding categories.
January 2024