THE HANDY VANDAL'S ALMANAC
Game Design Resources for Half-Life
Home : Topics : Menu : Reviews
Almanac 2 : Xen Rebels

Site no longer actively maintained ... HV

"'Kill -- Crush -- Destroy!'"
 

CODING ENTITIES: CLONE METHOD
See also: Coding -
Updated June 30, 2002 - 6:30 PM

 

Coding Entities: Clone Method

Here's a quick way to make new entities based on existing entities. Say you want to make a modified version of Barney:

(1) Create a new C++ source file called MyBarney.cpp (or whatever)

(2) Open the source code file that has the code you want to clone -- in this example, Barney.cpp

(3) Copy and paste all the Barney code into the NewBarney.cpp file. Then close Barney.cpp, we're done with it.

(4) Edit the NewBarney.cpp code -- all references to Barney have to be changed to NewBarney. There are several different contexts in which this happens, so go through the code line by line, don't just use global search/replace, until you know what's going on. Contexts include:

   Class name: CBarney becomes CNewBarney (or whatever)
   Entity name: monster_barney becomes monster_newbarney
   Etc. --

(5) Compile HL.DLL. (If the compile raises errors ... perhaps your new code is not entirely converted from "barney" to "newbarney" ...?)

(6) Edit your .fgd file -- copy-and-paste the Barney definition, edit the new code to read "monster_newbarney"

That's it -- you've made a new monster that's just like Barney, but not Barney.

From there you can really get into the NewBarney code -- change his reactions, his weapon, his model, whatever.

When several entities exist inside a single .cpp file, it may be easier to work in the same .cpp file (like Xen.cpp, for example). Same principles apply: copy the code for the monster class that you want to adapt, paste at bottom of existing .cpp file, and modify.
 
Coding Entities: Clone Method
Handy Vandal's Almanac Logo

"Handy Vandal" and "Handy Vandal's Almanac" copyright 2008 by Karl Gregory Jones
Almanac: Half-Life : Half-Life 2
Xen Rebels
karljones.com
Contact the Handy Vandal

Half-Life © 1998-99 Sierra On-line and Valve L.L.C. All rights reserved. Half-Life and the Half-Life logo are trademarks of Sierra On-Line. Valve and the Valve logo are trademarks of Valve L.L.C. Half-Life images, textures, music, sound effects, and other graphic or audio content © 1998-99 Valve L.L.C. All rights reserved.