dome
Hello soldier! I see you would like to get a new, shiny and pickable weapon... Well, read on! The
tools you will need is:
- of course the code
- FloEdit
- MapEdit (to add the weapon to maps)
- Compiler
1. Open up WL_AGENT.C file, and do a search for 'struct atkinf' (without quotes, of course). You should find a piece of code looking like this one:
struct atkinf
{
char tics,attack,frame; // attack is 1 for gun, 2 for knife
} attackinfo[4][14] =
{
{ {6,0,1},{6,2,2},{6,0,3},{6,-1,4} },
{ {8,0,1},{8,1,2},{8,0,3},{8,-1,4} },
{ {6,0,1},{6,1,2},{6,3,3},{6,-1,4} },
{ {6,0,1},{6,1,2},{6,4,3},{6,-1,4} },
};
You are wondering what is this? Well, it's the weapon behaviour code. You may see that we are
starting "from the end", and I'm not sure this is the best way... Anyway, 1st line of the numbers
is for knife, 2 for pistol, 3 for machinegun and 4 for chaingun. Below, add the new line copied from the ones above - it's depending on what type of weapon would you like to have. In this tutorial, I wanted to have something with machinegun-behaviour. Also, don't forget to add +1 in the bracket after "attackinfo". So, the code now looks like this:
struct atkinf
{
char tics,attack,frame; // attack is 1 for gun, 2 for knife
} attackinfo[5][14] =
{
{ {6,0,1},{6,2,2},{6,0,3},{6,-1,4} },
{ {8,0,1},{8,1,2},{8,0,3},{8,-1,4} },
{ {6,0,1},{6,1,2},{6,3,3},{6,-1,4} },
{ {6,0,1},{6,1,2},{6,4,3},{6,-1,4} },
{ {6,0,1},{6,1,2},{6,3,3},{6,-1,4} },
};
Now do a search for CheckWeaponChange. Modify the entire little function to this (copy & paste).
void CheckWeaponChange (void)
{
int i,buttons;
if (!gamestate.ammo) // must use knife with no ammo
return;
switch (LastScan)
{
case 2:
LastScan=0;
gamestate.weapon = gamestate.chosenweapon = wp_knife;
break;
case 3:
LastScan=0;
gamestate.weapon = gamestate.chosenweapon = wp_pistol;
break;
case 4:
LastScan=0;
if (gamestate.bestweapon >= wp_machinegun)
{
gamestate.weapon = gamestate.chosenweapon = wp_machinegun;
}
break;
case 5:
LastScan=0;
if (gamestate.bestweapon >= wp_chaingun)
gamestate.weapon = gamestate.chosenweapon = wp_chaingun;
}
break;
case 6:
LastScan=0;
if (gamestate.bestweapon >=wp_saw)
gamestate.weapon = gamestate.chosenweapon = wp_saw;
}
break;
}
DrawWeapon();
}
Here I used the modified version of code from "Weapon Change Sound".
Good. Now you may close the WL_AGENT.C file. Open up the WL_DEF.H, and scroll down until you see a bunch of funny names like CHAINATK1, CHAINATK2 and so on. It's the sprite definition
for the weapons:
SPR_CHAINREADY,SPR_CHAINATK1,SPR_CHAINATK2,SPR_CHAINATK3,
SPR_CHAINATK4,
The same are for machinegun and pistol before that. Below the CHAINATK things, add your own ones. Let's say your new weapon will be called SAW. So the code will now look like this:
SPR_CHAINREADY,SPR_CHAINATK1,SPR_CHAINATK2,SPR_CHAINATK3,
SPR_CHAINATK4,
SPR_SAWREADY,SPR_SAWATK1,SPR_SAWATK2,SPR_SAWATK3,
SPR_SAWATK4,
So now we have the weapon defined. We are still in WL_DEF.H, so let's make a use of it! Search
for bo_spear until you will find a bunch of bo_ names in the row. Below bo_spear add:
bo_saw
Yes that was really hard, wasn't it? Okay, now let's modify the existing object so we can pickup
our new weapon. Of course you may also add new sprites with FloEdit and then add the bo_
definition to it. Open the WL_ACT1.C, and search for SPR_STAT names. Pick one not-needed sprite, and after the SPR_STAT add "," and write bo_saw.
Now, when the player crosses that item, he will pick up the SAW.
Do a search for NUMWEAPONS 5. You will get this:
define NUMWEAPONS 5
typedef enum {
wp_knife,
wp_pistol,
wp_machinegun,
wp_chaingun
} weapontype;
Add +1 to NUMWEAPONS, and below wp_chaingun add wp_saw, so the code will look like this:
define NUMWEAPONS 6
typedef enum {
wp_knife,
wp_pistol,
wp_machinegun,
wp_chaingun,
wp_saw
} weapontype;
Scroll down a bit so you will see case bo_spear:. After that, add case bo_saw:. This is not the end of our adventure yet . Open up WL_AGENT.C again . Search for bo_spear. You will get:
case bo_spear:
spearflag = true;
spearx = player->x;
speary = player->y;
spearangle = player->angle;
playstate = ex_completed;
After that, add:
case bo_saw:
SD_PlaySound (GETMACHINESND);
GiveWeapon (wp_saw);
break;
So now the weapon is really pickable. But don't check yet. Now it's the end! Open up WL_DRAW.C. After scrolling down you will see sth like this:
int weaponscale[NUMWEAPONS] ={SPR_KNIFEREADY,SPR_PISTOLREADY,
SPR_MACHINEGUNREADY,SPR_CHAINREADY};
after SPR_CHAINREADY add SPR_SAWREADY so the code will look like this:
int weaponscale[NUMWEAPONS] ={SPR_KNIFEREADY,SPR_PISTOLREADY,
SPR_MACHINEGUNREADY,SPR_CHAINREADY,SPR_SAWREADY};
And now let's do some cosmetic work. Open up WL_AGENT.C and do a search for "GunAttack".
There you should see the bunch of Sd_Playsounds. Copy one of those defs and modify for SAW.
It's easy, so I won't write it here.
Okay, now everything you have to do is to add the proper sprites in FloEdit. Because we wrote SPR_SAWREADY after SPR_CHAINREADY, you should add new sprites directly after end of Chaingun animations. If you do, everything should be OK.
This tutorial was really messy, don't you think? Drop me an e-mail if it works/ doesn't for you.
[email]muad.dib1@wp.pl[/email].
Code Editing Tutorials
Adding a brand new weapon
Adding a brand new weapon
Hello soldier! I see you would like to get a new, shiny and pickable weapon... Well, read on! The
tools you will need is:
- of course the code
- FloEdit
- MapEdit (to add the weapon to maps)
- Compiler
1. Open up WL_AGENT.C file, and do a search for 'struct atkinf' (without quotes, of course). You should find a piece of code looking like this one:
struct atkinf
{
char tics,attack,frame; // attack is 1 for gun, 2 for knife
} attackinfo[4][14] =
{
{ {6,0,1},{6,2,2},{6,0,3},{6,-1,4} },
{ {8,0,1},{8,1,2},{8,0,3},{8,-1,4} },
{ {6,0,1},{6,1,2},{6,3,3},{6,-1,4} },
{ {6,0,1},{6,1,2},{6,4,3},{6,-1,4} },
};
You are wondering what is this? Well, it's the weapon behaviour code. You may see that we are
starting "from the end", and I'm not sure this is the best way... Anyway, 1st line of the numbers
is for knife, 2 for pistol, 3 for machinegun and 4 for chaingun. Below, add the new line copied from the ones above - it's depending on what type of weapon would you like to have. In this tutorial, I wanted to have something with machinegun-behaviour. Also, don't forget to add +1 in the bracket after "attackinfo". So, the code now looks like this:
struct atkinf
{
char tics,attack,frame; // attack is 1 for gun, 2 for knife
} attackinfo[5][14] =
{
{ {6,0,1},{6,2,2},{6,0,3},{6,-1,4} },
{ {8,0,1},{8,1,2},{8,0,3},{8,-1,4} },
{ {6,0,1},{6,1,2},{6,3,3},{6,-1,4} },
{ {6,0,1},{6,1,2},{6,4,3},{6,-1,4} },
{ {6,0,1},{6,1,2},{6,3,3},{6,-1,4} },
};
Now do a search for CheckWeaponChange. Modify the entire little function to this (copy & paste).
void CheckWeaponChange (void)
{
int i,buttons;
if (!gamestate.ammo) // must use knife with no ammo
return;
switch (LastScan)
{
case 2:
LastScan=0;
gamestate.weapon = gamestate.chosenweapon = wp_knife;
break;
case 3:
LastScan=0;
gamestate.weapon = gamestate.chosenweapon = wp_pistol;
break;
case 4:
LastScan=0;
if (gamestate.bestweapon >= wp_machinegun)
{
gamestate.weapon = gamestate.chosenweapon = wp_machinegun;
}
break;
case 5:
LastScan=0;
if (gamestate.bestweapon >= wp_chaingun)
gamestate.weapon = gamestate.chosenweapon = wp_chaingun;
}
break;
case 6:
LastScan=0;
if (gamestate.bestweapon >=wp_saw)
gamestate.weapon = gamestate.chosenweapon = wp_saw;
}
break;
}
DrawWeapon();
}
Here I used the modified version of code from "Weapon Change Sound".
Good. Now you may close the WL_AGENT.C file. Open up the WL_DEF.H, and scroll down until you see a bunch of funny names like CHAINATK1, CHAINATK2 and so on. It's the sprite definition
for the weapons:
SPR_CHAINREADY,SPR_CHAINATK1,SPR_CHAINATK2,SPR_CHAINATK3,
SPR_CHAINATK4,
The same are for machinegun and pistol before that. Below the CHAINATK things, add your own ones. Let's say your new weapon will be called SAW. So the code will now look like this:
SPR_CHAINREADY,SPR_CHAINATK1,SPR_CHAINATK2,SPR_CHAINATK3,
SPR_CHAINATK4,
SPR_SAWREADY,SPR_SAWATK1,SPR_SAWATK2,SPR_SAWATK3,
SPR_SAWATK4,
So now we have the weapon defined. We are still in WL_DEF.H, so let's make a use of it! Search
for bo_spear until you will find a bunch of bo_ names in the row. Below bo_spear add:
bo_saw
Yes that was really hard, wasn't it? Okay, now let's modify the existing object so we can pickup
our new weapon. Of course you may also add new sprites with FloEdit and then add the bo_
definition to it. Open the WL_ACT1.C, and search for SPR_STAT names. Pick one not-needed sprite, and after the SPR_STAT add "," and write bo_saw.
Now, when the player crosses that item, he will pick up the SAW.
Do a search for NUMWEAPONS 5. You will get this:
define NUMWEAPONS 5
typedef enum {
wp_knife,
wp_pistol,
wp_machinegun,
wp_chaingun
} weapontype;
Add +1 to NUMWEAPONS, and below wp_chaingun add wp_saw, so the code will look like this:
define NUMWEAPONS 6
typedef enum {
wp_knife,
wp_pistol,
wp_machinegun,
wp_chaingun,
wp_saw
} weapontype;
Scroll down a bit so you will see case bo_spear:. After that, add case bo_saw:. This is not the end of our adventure yet . Open up WL_AGENT.C again . Search for bo_spear. You will get:
case bo_spear:
spearflag = true;
spearx = player->x;
speary = player->y;
spearangle = player->angle;
playstate = ex_completed;
After that, add:
case bo_saw:
SD_PlaySound (GETMACHINESND);
GiveWeapon (wp_saw);
break;
So now the weapon is really pickable. But don't check yet. Now it's the end! Open up WL_DRAW.C. After scrolling down you will see sth like this:
int weaponscale[NUMWEAPONS] ={SPR_KNIFEREADY,SPR_PISTOLREADY,
SPR_MACHINEGUNREADY,SPR_CHAINREADY};
after SPR_CHAINREADY add SPR_SAWREADY so the code will look like this:
int weaponscale[NUMWEAPONS] ={SPR_KNIFEREADY,SPR_PISTOLREADY,
SPR_MACHINEGUNREADY,SPR_CHAINREADY,SPR_SAWREADY};
And now let's do some cosmetic work. Open up WL_AGENT.C and do a search for "GunAttack".
There you should see the bunch of Sd_Playsounds. Copy one of those defs and modify for SAW.
It's easy, so I won't write it here.
Okay, now everything you have to do is to add the proper sprites in FloEdit. Because we wrote SPR_SAWREADY after SPR_CHAINREADY, you should add new sprites directly after end of Chaingun animations. If you do, everything should be OK.
This tutorial was really messy, don't you think? Drop me an e-mail if it works/ doesn't for you.
[email]muad.dib1@wp.pl[/email].