Sentries (laser guided)

 

These sentries are fairly unlimited, you can drop as many as you want and they are fairly tough. They will fire at a point where you have a laser designator trained. Their rate of fire can only be described as hideous. Perfect for base defense although they do need an operator and the laser bean does kind of give you away.

You will probably want to put in some limits without them, you would have a bloodbath and nothing would get done. You could change this to fit turrets instead of people.

On to the code. Most of it is contained in sentry.c following my habit of having as much of the new code in a new file as possible.


Theres a fair amount of descriptive comments in sentry.c I'd suggest you read them to understand how I'm doing this. I could put the code on this page, but there doesn't seem much point, It's fairly easy to understand. Just read the file.

Now to make this work we need to modify 3 other files.


1: g_local.h

we need to add a couple of variables here. If you have done the dummies tut then you'll see a similarity.

find monsterinfo_t monsterinfo; it should be near the bottom of the file; just after it add

        vec3_t         sentrypoint;
        int            sentrypointset;
        edict_t        *lasdes;

As way of explanation:

sentrypoint

holds the coordinates to spawn a sentry at (you set it with a command, it copies your coordinates).

sentrypointset

Starts off being 0, is set to one when you stroe a set of coordinates, is set back to 0 when you spawn a sentry. used to make sure that you can spawn a sentry.

*lasdes

I use this to store the position pointed at by the laser designator. it kills itself after 0.3 secs unless the laser designator is still firing. Doing it this way means that only the player who spawned the sentries can use them. I was having problems with the search code for freestanding points. you can try and fix this if you wish. send me the code and I'll add it to this tut as an option with your name attached

Thats g_local.h dealt with.


2: g_items.c

All we do here is add the definition of the laser designator

Go to the code below in g_items.c. it's part of the item list.

/*QUAKED weapon_hyperblaster (.3 .3 1) (-16 -16 -16) (16 16 16)
*/
        {
               "weapon_hyperblaster", 
               Pickup_Weapon,
               Use_Weapon,
               Drop_Weapon,
               Weapon_HyperBlaster,
               "misc/w_pkup.wav",
               "models/weapons/g_hyperb/tris.md2", EF_ROTATE,
               "models/weapons/v_hyperb/tris.md2",
/* icon */             "w_hyperblaster",
/* pickup */   "HyperBlaster",
               0,
               1,
               "Cells",
               IT_WEAPON|IT_STAY_COOP,
               WEAP_HYPERBLASTER,
               NULL,
               0,
/* precache */ "weapons/hyprbu1a.wav weapons/hyprbl1a.wav weapons/hyprbf1a.wav weapons/hyprbd1a.wav misc/lasfly.wav"
        },

just after it insert the code below

 
// For the sentry
 
/*QUAKED weapon_laserdesignator (.3 .3 1) (-16 -16 -16) (16 16 16)
*/
        {
               "weapon_laserdesignator", 
               Pickup_Weapon,
               Use_Weapon,
               Drop_Weapon,
               Weapon_LasDes,
               "misc/w_pkup.wav",
               "models/weapons/g_hyperb/tris.md2", EF_ROTATE,
               "models/weapons/v_hyperb/tris.md2",
/* icon */             "w_hyperblaster",
/* pickup */   "LaserDes",
               0,
               1,
               "Cells",
               IT_WEAPON|IT_STAY_COOP,
               WEAP_HYPERBLASTER,
               NULL,
               0,
/* precache */ "weapons/hyprbu1a.wav weapons/hyprbl1a.wav weapons/hyprbf1a.wav weapons/hyprbd1a.wav misc/lasfly.wav"
        },

add this prototype to the prototypes at the top of the file.

void Weapon_LasDes (edict_t *ent);

Done with this file


3: g_cmds.c

Add these prototypes to the top, just after the include lines

void Mark_Sentry_Spawn_Point(edict_t *ent);
void Spawn_Sentry(edict_t *ent);

Next go to the end of the file and change

        else if (Q_stricmp(cmd, "playerlist") == 0)
               Cmd_PlayerList_f(ent);
        else    // anything that doesn't match a command will be a chat
               Cmd_Say_f (ent, false, true);

to read

        else if (Q_stricmp(cmd, "playerlist") == 0)
               Cmd_PlayerList_f(ent);
        else if (Q_stricmp(cmd,"marksentry")==0)
               Mark_Sentry_Spawn_Point(ent);
        else if (Q_stricmp(cmd,"spawnsentry")==0)
               Spawn_Sentry(ent);
        else    // anything that doesn't match a command will be a chat
               Cmd_Say_f (ent, false, true);

And we are done. Add sentry.c to your makefile and compile it. it should work fine.

Problems with this tut.

To create a sentry, type marksentry at the console (or bind it to a key and hit that) then move to another point and type spawnsentry. that will create a sentry at your original coordinates


Resources


Skunkworks Tutorial