Fury Prod.  


Tutorial #1
Poison: part 2 (Cgame)

OK. We have the power up defined and taking the place of an item. Now we need to create what it looks like to the player when they are poisoned, or when someone else is poisoned. Open up cg_players.c in the client project. We are looking for a function called CG_PlayerPowerups. Roughly line 1085 is where it starts. You will notice that this is where the game actually gets what effect, and or sounds should be going on for specific powerups. If you take a look at the quad entry:

All it is saying is.... if your powerups include PW_QUAD (quad powerup), then to the scene add a lighting effect from our origin (spot on the map). The light will be of the color blue. We can tell it is blue because it is defined in RGB. (Red Green Blue). Notice the 0.2, 0.2, 1. The red value is 0.2, green is 0.2 (these values are just enough to emit light) and blue is 1 (full on). Thus when you have quad, you glow blue.

For Poison, we thought green would be the best for obvious gaming poison stereotypes. So our added line should read like this:

So the only thing that is different is checking for the powerup PW_POISONED (having been poisoned, not having poison powerup), and the color emitted. Changed the 1 from blue to green is all. Pretty simple. We need to make the change in another place as well. This time find the function CG_AddRefEntityWithPowerups. This is where it draws other players powerups on your screen. Around the player and whatnot. Pertinent lines include:

So these lines are telling the game that if you have the powerup battlesuit, then start a custom shader named battleSuitShader. We will do this for being Poisoned as well. So our lines should look like the following:

Just telling the game we need to add a custom shader named poisonedShader if we are poisoned. We also need to add it to our weapon/HUD so....inside cg_weapons.c in a function called CG_AddWeaponWithPowerups (about line 525) oddly enough....we find:

Pretty much the same as the reference before.... Just tells the game to use a custom shader and where to get it. So we should be looking like:

So...guess we need to tell the game what poisonedShader and poisonedWeaponShader is huh? OK..I thought you would never ask....

Since we are calling things that the game has no idea exist, we need to make them exist I guess huh? So check cg_local.h roughly line 596 in a struct called cgMedia_t:

We need to insert our additions here.... should fall right in line with the previous stuff...


Now the game knows they exist, but what is it going to do with these? How should the game react? Well lets get to it....So open up cg_main.c and look for function CG_RegisterGraphics. We are looking around line 598... for this:

This is defining and telling the game where to get the shader. As with regenShader, you will need to define the poisonShader inside the shader documents to ensure that the game knows what graphic to use. So we follow ID's lead and add our lines after these like this:

OK, so I am going to jump a little ahead and give you a scenario. When poison does damage... and you die, what is it you need? A method of telling the game what killed you, so it know what message to print. This is mostly handled in the game project, but there is one file on the client side that also handles this. So..open up cg_event.c and look for the function CG_Obituary (about line 58). Down towards the bottom of that function, there are a few lines that look like:

Followed by a ton of case statements. These basically track how a person died, who killed them, and what to print on the screen. So... we need to add our own line for death by poisoning. Which should look like the following...

This just tells the computer that if we die, from poison, say we were infected by whomever killed us.

That is all the that needs to be referenced from the Cgame part of the project.....

previous... next...

news | projects | FoF | tactics | download | tutorials | team