Перевод этой страницы:

Xash3D

All old is new again

Инструменты пользователя

Инструменты сайта


Боковая панель

xashcookbook:en:recipes:code:server:classes

Adding new monster classes

by Ghoul, modified by CRxTRDude
Original site: http://www.planethalflife.com/hlprogramming/tutorial.asp?i=126

Tutorial type: Intermediate - A/F


Alrighty, this tutorial will show you how to add new «class» types to monsters. Ex. a human grunt uses a class type of CLASS_HUMAN_MILITARY. Lets say you added in Black Ops. from Op4. If they were CLASS_HUMAN_MILITARY then they would be friends with human grunts, but that isn't the way it worked in Op4, so lets add a CLASS_BLACK_OP. First open up cbase.h, scroll down a little and you should see this:

// For CLASSIFY
#define	CLASS_NONE	 0
#define CLASS_MACHINE	 1
#define CLASS_PLAYER	 2
#define	CLASS_HUMAN_PASSIVE	 3
#define CLASS_HUMAN_MILITARY	4
#define CLASS_ALIEN_MILITARY	5
#define CLASS_ALIEN_PASSIVE	 6
#define CLASS_ALIEN_MONSTER	 7
#define CLASS_ALIEN_PREY	 8
#define CLASS_ALIEN_PREDATOR	9
#define CLASS_INSECT	 10
#define CLASS_PLAYER_ALLY	 11
#define CLASS_PLAYER_BIOWEAPON	12 // hornets and snarks.launched by players
#define CLASS_ALIEN_BIOWEAPON	13 // hornets and snarks.launched by the alien menace
#define	CLASS_BARNACLE	 99 // special because no one pays attention to it, and it eats a wide cross-section of creatures. 

Now, between CLASS_ALIEN_BIOWEAPON and CLASS_BARNACLE add in this:

...
#define CLASS_ALIEN_BIOWEAPON	13 // hornets and snarks.launched by the alien menace 
#define CLASS_BLACK_OP	 14
#define	CLASS_BARNACLE	 99 // special because no one pays attention to it, and it eats a wide cross-section of creatures

Note that you have 14 there despite the fact that you have 15 classes, it's because CLASS_NONE is set to 0, therefore you have to start counting from 0 and so on.

Now that we have our new class declared, we have to open up monsters.cpp. Find IRelationship for the class CBaseMonster. Close to the top of the function you should see a grid of code like this: (from the original Half-Life SDK)

static int iEnemy[14][14] =
	{			 //   NONE	MACH	PLYR	HPASS	HMIL	AMIL	APASS	AMONST	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NO,	R_NO,	R_FR,	R_NO,	R_DL,	R_NO,	R_NO,	R_DL,	R_DL,	R_DL },
	/*ALIENPREDATO*/{ R_NO,	R_NO,	R_DL,	R_DL,	R_DL,	R_NO,	R_NO,	R_NO,	R_HT,	R_DL,	R_NO,	R_DL,	R_NO,	R_NO,	R_DL,	R_DL,	R_DL },
	/*INSECT*/		{ R_FR,	R_FR,	R_FR,	R_FR,	R_FR,	R_NO,	R_FR,	R_FR,	R_FR,	R_FR,	R_NO,	R_FR,	R_NO,	R_NO,	R_FR,	R_FR,	R_FR },
	/*PLAYERALLY*/	{ R_NO,	R_DL,	R_AL,	R_AL,	R_DL,	R_DL,	R_DL,	R_DL,	R_DL,	R_DL,	R_NO,	R_NO,	R_NO,	R_NO,	R_DL,	R_DL,	R_DL },
	/*PBIOWEAPON*/	{ R_NO,	R_NO,	R_DL,	R_DL,	R_DL,	R_DL,	R_DL,	R_DL,	R_DL,	R_DL,	R_NO,	R_DL,	R_NO,	R_DL,	R_DL,	R_DL,	R_DL },
	/*ABIOWEAPON*/	{ R_NO,	R_NO,	R_DL,	R_DL,	R_DL,	R_AL,	R_NO,	R_DL,	R_DL,	R_NO,	R_NO,	R_DL,	R_DL,	R_NO,	R_DL,	R_DL,	R_DL },

As a rule of thumb, the rows with /*...*/ is that class. The columns represent the relationship of the class to the other classes mentioned (eg. PLYR for the player).

Ok, next is the main part of the tutorial. Examine the grid, first, change the iEnemy array for every class you want to have. In our example, we want to have 15 classes, therefore edit like so: static int iEnemy[15][15].

Next you need to add one row to our array. You can copy and paste the last row onto the grid. Change the labels to /*BLACKOP*/ and BLKOP or whatever. Your grid should look like this:

static int iEnemy[15][15] =
	{			 //   NONE	MACH	PLYR	HPASS	HMIL	AMIL	APASS	AMONST	APREY	APRED	INSECT	PLRALY	PBWPN	ABWPN	BLKOP
....
	/*BLACKOPS*/{ R_NO,	R_NO,	R_HT,	R_DL,	R_DL,	R_HT,	R_DL,	R_DL,	R_DL,	R_DL,	R_NO,	R_HT,	R_NO,	R_NO,	R_DL,	R_DL,	R_DL,  R_AL},
	};

Note that each time you add a row, you should add a column entry on all the relationships in the table. This will prevent mishaps during gameplay.

Now we are almost done. If you look at the grid you see a lot of R_ this and R_ that. In monsters.h take a look at this code:

// monster to monster relationship types
#define R_AL	-2 // (ALLY) pals. Good alternative to R_NO when applicable
#define R_FR	-1// (FEAR)will run
#define	R_NO	0// (NO RELATIONSHIP) disregard
#define R_DL	1// (DISLIKE) will attack
#define R_HT	2// (HATE)will attack this character instead of any visible DISLIKEd characters
#define R_NM	3// (NEMESIS) A monster Will ALWAYS attack its nemsis, no matter what 

Those are the monster relationship types. Using those defines set up your Black Op to have its enemies and friends. Now the only thing you have to do is go into your monsters Classify() function and have it return CLASS_BLACK_OP and your all set. I hope you learned from the tutorial. And maybe when you get experienced enough, you can makes the egon's secondary attack make monsters attack everything (including other monsters like them) like I did! If you have any questions or concerns please mail me, [email protected]. Thanks, and happy coding!

xashcookbook/en/recipes/code/server/classes.txt · Последние изменения: 2014/06/08 08:39 — crxtrdude