Post tutorial RSS Doom Source Code Tutorial 4

Power-up your bullet weapons Part 1. In this tutorial we will make a faster chain gun and a more accurate shotgun.

Posted by on - Basic Client Side Coding

Tutorial 4
Game: Doom1, Doom2.
Level: Basic.
Objective: Modify the bullet weapons using defs files and C source.
Resources required: Visual C++, source code for Doom, defs files (doomsday or risen3d).

Introduction: In tutorial 3 a detailed description of how the weapons in doom worked was outlined; particular attention was given to the chain gun. In this installment and the next one we will try to apply our modest knowledge to modifying these weapons by making some changes to the definitions files directly. Our first target file for this session is objects.ded. But a word of caution first; the one we want to edit is the one shipped with the game launcher distribution (Kickstart or Snowberry) and not the one inside the source code folder. For further confusion, if you are doing this for risen3d , you need to edit the file R3Dstates.ded in "defs/base" folder instead. For this and older versions of doomsday (1.8.6 for example), you just need to use a simple text editor such as notepad (I prefer notepad++, it is free, shows line numbers and much better in every other aspect, google for it!). If on the other hand you want to make your mod for the latest version of doomsday (version 1.9.0 beta 6.9) then you will have to unzip the jdoom.pk3 file first, but I recommend you use a good utility such as Slade instead. It is neater and more convenient. Also you need to disable any 3D models you may have installed; this exercise is for plain 2D sprites only. With me so far? Good, let's proceed.
1. First, as always, make a backup copy of any file you intend to modify and keep it in a safe place.
2. Open the file objects.ded (or R3Dstates.ded) in your text editor and go straight to the attack states for the chain gun (around line 3917 for doomsday, line 452 for risen3d using notepad++ on my pc) as described in tutorial 3 of this series. The changes we intend to make to our guns today will include the firing rate; the damage hit points and the accuracy of your shots.
3. Lets begin by making the chain gun shoot faster. You can do this easily by shortening the time the firing frames take during each attack. Just reduce the time rate for both states from 4 tics down to say 1 tic as shown below:

State {

ID = "CHAIN1";

Sprite = "CHGG";

Frame = 0;

Tics = 4; ← change this to 1 tic.

Action = "A_FireCGun";

Next state = "CHAIN2";


State {

ID = "CHAIN2";

Sprite = "CHGG";

Frame = 1;

Tics = 4; ← change this to 1 tic.

Action = "A_FireCGun";

Next state = "CHAIN3";


In this particular case we do not need to make changes to the flash states (more on that later).
Save your changes and start doom or doom2, now grab your chain gun and start firing. It should now fire at 4 times the normal rate; wipe out those monsters in no time! Of course there is always a price to pay: you have now invented a "lead -guzzler", your 400 bullets will run out in seconds. Fear not, you can go back to your objects.ded file and increase the tic rate all the way back to, say 8 tics, save and re-start the game. See how dead slow your deadly chain gun has become. Reminds me of the old days when we used to experiment with Dehacked.
3. Away from "ded" files, let's now have a go at modding the shotgun into a sniper's rifle .We need here to increase the accuracy and the hit points. Fire up your VC++ and from your solution explorer for "doomsday/jdoom/", open the file p_pspr.c, head straight to the function definition of A_FireShotgun and change the argument in P_Gunshot from "false" to "true" as shown below in red:

change this:

P_GunShot(player->plr->mo, false);

to this:

P_GunShot(player->plr->mo, true);

Very simple!

By doing this, you've just reversed the condition in the if statement, and hence by-passed the random angle modifier element in the P_Gunshot function, which messed up your marksmanship talent. See below:

If (!accurate) true is substituted inside the bracket here then inverted.

angle += (P_Random() - P_Random()) << 18; ← this line is now skipped as the result is false.

Compile and try. Now all your bullets should hopefully hit the target exactly where you mark your cross-hair. No more crude scatter gun effect.

4. As far as the damage rate is concerned, one easy way we can mod this is by increasing the number of loops to any reasonable value inside this function. In our case we get 7 consecutive bullets hitting "exactly" the same spot at high speed. This should have, virtually, the equivalent damage effect, as using one single high caliber round:

for (i = 0; i < 7; ++i)

P_GunShot(player->plr->mo, true);

Beware though; this could kill several weak monsters if they are lining up behind each other.
Now that you have a sniper's rifle, set your cross-hair on and try to assassinate that annoying Cacodemon on level 16 with one single shot from a mile away! I know I cannot wait.

Exercise: Try a better alternative to mod your rifle: use just one single but powerful bullet. Do that by first removing the random function, use a fixed high value for the hit points and do away with the for loop.

Err...., things do not look exactly right, do they? Does a sniper rifle use pump action? Thought not! I am not a weapons expert, but we will try to rectify that in the next tutorial.

Happy shooting!


Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.