PDA

View Full Version : [code] Four-Barreled Weapon


recombinant
06-23-2003, 10:53 PM
My latest dilemma in this series involves the following weapon (fusion cutter from Dark Forces, unskinned)...

As you can see, I've labeled the four barrels to show where the projectiles are supposed to be fired from...

http://64.224.160.19/jk2images/Fusion4Barrel.jpg

Is is possible to have separate fire origins? I was planning on seeing if our weapon modeler could create four "tag_flash" tags named "tag_flash", "tag_flash1", "tag_flash2", and "tag_flash3" and alternate them in CG_AddPlayerWeapon(), but I wasn't sure if that was the right way to go. Any ideas?

For primary fire, we want to have it fire sequentially 1,2,3,4,1... and on alt-fire do all four at once (don't know if that's doable however).

If anyone has already done something like this and would like to share some of their insights I'd appreciate it. Otherwise I'll keep plugging away at it...

Thanks!

:D

razorace
06-24-2003, 01:16 AM
Sure it's possible but you'd have to do some code changes to make it work.

recombinant
06-24-2003, 02:20 AM
Sure it's possible

well, that helps a bit.

but you'd have to do some code changes to make it work.

i'm not worried about that so much (that's why i prefixed the thread name with "[code]")... i was hoping to bounce the idea of some of the more experienced coders to see if my methodology was a) not the best way to do it, b) overly complex and there was actually some simpler way of accomplishing it, and i'm going in the wrong direction.

but if the method of attack seems reasonable to you and others then I'm willing to trust your judgment. :D

thanks!

Code
06-24-2003, 07:23 PM
my 2 cents (did this for the atst)
just play around with the muzzle point, and it did the job for me

the way i 'figured' this was looking at the bryar fire code (server)
try ther ;)

recombinant
06-24-2003, 07:29 PM
Interesting.. in earlier tests, when I played around with the muzzle, it made the crosshairs shift erratically.

But I'm totally willing to take another look at it.

Thanks!

:D

Code
06-24-2003, 09:01 PM
sorry was lazy, i ment the blaster code
so that u can forgive me ;)
here is a straith paste of what i mean


//static void WP_FireBlaster( gentity_t *ent, qboolean altFire )
static void WP_FireBlaster( gentity_t *ent, qboolean altFire, qboolean isAtst)
//---------------------------------------------------------
{
vec3_t dir, angs, newMuzzle;

//NOTETOSELF : probably npc use this , as an atst

vectoangles( forward, angs );

if ( altFire )
{// add some slop to the alt-fire direction
angs[PITCH] += crandom() * BLASTER_SPREAD;
angs[YAW] += crandom() * BLASTER_SPREAD;
}

AngleVectors( angs, dir, NULL, NULL );

// FIXME: if temp_org does not have clear trace to inside the bbox, don't shoot!

if ( isAtst )
{
newMuzzle[0] = muzzle[0] - atst_muzzleone.value;
newMuzzle[1] = muzzle[1] - atst_muzzletwo.value;
newMuzzle[2] = muzzle[2] + atst_muzzletre.value;

if (altFire)
{
newMuzzle[0] += atst_muzzlefor.value;
newMuzzle[1] -= atst_muzzlefiv.value;
}

WP_FireBlasterMissile( ent, newMuzzle, dir, altFire );
}
else
{
WP_FireBlasterMissile( ent, muzzle, dir, altFire );
}

if ( isAtst )
{//fire the 'second' one also
if (!altFire)
{
newMuzzle[1] += atst_muzzlesix.value;
}
WP_FBlasterAgain(ent, altFire, newMuzzle);
if (altFire)
{//3rd and 4th !
WP_FBlasterAgain(ent, altFire, newMuzzle);
WP_FBlasterAgain(ent, altFire, newMuzzle);
}
}
}//endatstcode

razorace
06-25-2003, 04:17 AM
Well, the real question is how indepth of a change do you want?

recombinant
06-25-2003, 03:17 PM
...well, if it's going to have to be really in-depth fix, then I'll have to go for it.

I'm going to try out the multiple tag method first and see how that goes (since our modeler already put them in the model).

I'll keep you posted on my progress.

:D

Azymn
06-25-2003, 04:10 PM
You'll need the multiple tag_flash#'s clientside for rendering the muzzle "powder flash" on firing, and then you'll have to create 4 vec3_t muzzle points (see the vec3_t array Code referenced above) as offsets from the player origin to determine where the 'bullet' originates serverside.

You have the right idea.

recombinant
06-26-2003, 03:44 AM
thanks, Azymn. I'll try out your suggestions....

...of course it doesn't mean I won't ask you more questions later, but I'll give it a shot.

:D

razorace
06-26-2003, 05:05 AM
Yeah, Azymn stated what I was getting at. At the minimum, you'll need to change the clientside to make the muzzle flash work correctly.

You can also play with some stuff server depending on how close you want the bolt orientation to the actual muzzle, but it's not really that critical. Raven did really simple system based off the viewpoint or something like that. I made MotF be based off the actual ghoul2 model but that's 1) complicated and 2) screws up the crosshair alignment.

recombinant
06-26-2003, 05:10 AM
something's not right here. i must be making my modifications in the wrong location (btw, this only refers to the "tag_flash" issue - I haven't gotten back to the muzzle stuff...).

During one click of the mouse button, my debug statement in cg_weapons.c, CG_AddPlayerWeapon output the following (written out to the console):


iFusionBarrel: 0
iFusionBarrel: 1
iFusionBarrel: 2
iFusionBarrel: 3
iFusionBarrel: 0
iFusionBarrel: 1
iFusionBarrel: 2
iFusionBarrel: 3
iFusionBarrel: 0


based on the value of iFusionBarrel, it decides which tag_flash to use:


CG_Printf("iFusionBarrel: %i\n", iFusionBarrel); // jodfmod debug
if (iFusionBarrel == 0)
{
CG_PositionEntityOnTag( &flash, &gun, gun.hModel, "tag_flash");
}
else if (iFusionBarrel == 1)
{
CG_PositionEntityOnTag( &flash, &gun, gun.hModel, "tag_flash1");
}
else if (iFusionBarrel == 2)
{
CG_PositionEntityOnTag( &flash, &gun, gun.hModel, "tag_flash2");
}
else if (iFusionBarrel == 3)
{
CG_PositionEntityOnTag( &flash, &gun, gun.hModel, "tag_flash3");
}

iFusionBarrel++;
if (iFusionBarrel == 4)
{
iFusionBarrel = 0;
}


So obviously that must be the wrong place to put it, or have the firing logic to the incrementing... because this seems to just increment over and over. thus creating a random (practically) selection of the tag_flash...

This was a similar problem I was having in CG_CalcMuzzlePoint.

Hmmm...

razorace
06-26-2003, 06:33 AM
Well, is iFusionBarrel a global varible?

recombinant
06-26-2003, 12:37 PM
Originally posted by razorace
Well, is iFusionBarrel a global varible?

...not currently.

Basically, I was using it locally within CG_AddPlayerWeapon(), but I'm beginning to see that I've been narrowing my scope too much.

So I'm thinking I should probably make iFusionBarrel global, and increment it when firing instead. Then in CG_AddPlayerWeapon() use the appropriate tag_flash. Sound reasonable?

...then on to the muzzle issue.

recombinant
06-26-2003, 03:02 PM
OK. Looks like that was the right way to go. Funny. Just this morning before I read your post I was mulling all this over (as I often do when getting ready for work...) and it occurred to me that I needed to have the separation - i.e. increment it in the firing function.

...then razor asked the above question which confirmed my suspicions.

So now I have a g_iFusionBarrel global that maintains the current flash "index" and it gets incremented in CG_FireWeapon(). It seems to be working correctly now.

Now I have to deal with the projectile issue.

:D

razorace
06-26-2003, 03:30 PM
Well, remember if you're using a single varible, that will mean that other players' firing will effect the counter.

recombinant
06-26-2003, 04:35 PM
OK... good point.

So I added a component to the centity_s struct and now in CG_AddPlayerWeapon I do the following:


CG_Printf("cent->fusionBarrelIndex: %i\n", cent->fusionBarrelIndex); // jodfmod debug
if (cent->fusionBarrelIndex == 0)
{
CG_PositionEntityOnTag( &flash, &gun, gun.hModel, "tag_flash");
}
else if (cent->fusionBarrelIndex == 1)
{
CG_PositionEntityOnTag( &flash, &gun, gun.hModel, "tag_flash1");
}
else if (cent->fusionBarrelIndex == 2)
{
CG_PositionEntityOnTag( &flash, &gun, gun.hModel, "tag_flash2");
}
else if (cent->fusionBarrelIndex == 3)
{
CG_PositionEntityOnTag( &flash, &gun, gun.hModel, "tag_flash3");
}


...and increment it in CG_FireWeapon() like so:


// lightning gun only does this this on initial press
if ( ent->weapon == WP_FUSION_CUTTER ) {

//---------------------------------------------------------
// jodfmod - increment barrel index for the current entity
//---------------------------------------------------------
cent->fusionBarrelIndex++;
if (cent->fusionBarrelIndex == 4)
{
cent->fusionBarrelIndex = 0;
}
//---------------------------------------------------------

if ( cent->pe.lightningFiring ) {
return;
}
}


So hopefully that will work OK...

recombinant
06-27-2003, 03:45 PM
Well, I was able to get the four-barreled weapon firing working last night!

At first, I was somewhat dubious about my edits, but it worked just like I wanted it to!

Thanks for the help, gentlemen (with special shouts going out to Azymn)!!!

:sbdance

recombinant
06-27-2003, 03:54 PM
now on to part two, which is the alt-fire, in which four projectiles need to be shot out at once.

It was intimated to me that this would probably be the easier of the two cases, but we shall see...

:holosid:

Wudan
06-27-2003, 03:58 PM
Indeed, I think it shall prove to be the easier of the two.

razorace
06-27-2003, 05:14 PM
Yep, just check out how the server handles the creation of alt-fire effects/missiles and simply create 4 bolts with a simple vertical offset (based on your oientation if you're picky).

recombinant
06-27-2003, 05:19 PM
Originally posted by razorace
Yep, just check out how the server handles the creation of alt-fire effects/missiles and simply create 4 bolts with a simple vertical offset (based on your oientation if you're picky).

good suggestion, razor.

thanks!

:D

recombinant
06-27-2003, 05:22 PM
...and just found something I can use! A fellow teammate already did a similar thing with the repeater...

it won't be long now!

:sbdance

recombinant
06-28-2003, 02:53 PM
Looks like I've almost got it going, but there's something up with my vector math...

stupidly, I just added/subtracted offset values from the second element a temporary muzzle entity I create in the routine, mistakenly thinking that this would do what I want.

The funny thing is that if I'm turned one way, it looks like I"m shooting one big projectile (since from that perspective they're all stacked one on top of another), and if I turn 90 degrees I get four projectiles horizontally - basically what I wanted.

So obviously it's offsetting the muzzle on one axis only in threespace (duh).

My next question is...

How can I come up with the appropriate offsets that will always be perpendicular to the player's view, thus creating four projectiles in a row horizontally that shoot forward?

Here's a diagram of what I'm trying to accomplish (the black dashed arrow is the muzzle vector, and the red arrows are the desired vectors offset from the muzzle):

http://64.224.160.19/jk2images/VectorDiagram.gif

(I've always had a problem with vectors in math... grrrrr...)

Thanks!

:D

Azymn
06-28-2003, 05:57 PM
Since i'm bored-crazy right now, and you've got most of it done...

static void ShootFourShots( gentity_t *ent )
{
gentity_t *missile1;
gentity_t *missile2;
gentity_t *missile3;
gentity_t *missile4;

vec3_t tmpMuzzle, newMuzzle;

VectorCopy(fusionMuzzle[0], tmpMuzzle);
VectorCopy(ent->s.pos.trBase, newMuzzle);

VectorMA(newMuzzle, tmpMuzzle[0], forward, newMuzzle);
VectorMA(newMuzzle, tmpMuzzle[1], right, newMuzzle);
newMuzzle[2] += ent->client->ps.viewheight + tmpMuzzle[2];

SnapVector( newMuzzle );

missile1 = CreateMissile( newMuzzle, forward, FUSION_CUTTER_VELOCITY, 10000, ent, qfalse);

...rinse, repeat as necessary....

:)

Wudan
06-28-2003, 07:27 PM
BooYah! Azymn with the wicked math tricks!

recombinant
06-29-2003, 01:29 AM
BooYahh is right!!!

http://64.224.160.19/jk2images/FourBarrelShot.jpg

Many thanks again to the master!!!

:D

But I'd really like to know *why* it works - what the concept is behind the functions. I'm happy to copy and paste the code, but I really need to understand what's going on here! Ack!

razorace
06-29-2003, 03:51 AM
static void ShootFourShots( gentity_t *ent )
{

//racc - create missile entities
gentity_t *missile1;
gentity_t *missile2;
gentity_t *missile3;
gentity_t *missile4;

//racc - initialize origin point vectors
//tmpMzzle = muzzle point in x/y orientation from the player (doesn't worry about the z axis)
//newMuzzle = working muzzle origin vector. This is where your
//desired muzzle point vector will be at the end of the calculations.
vec3_t tmpMuzzle, newMuzzle;

VectorCopy(fusionMuzzle[0], tmpMuzzle);
VectorCopy(ent->s.pos.trBase, newMuzzle);

//racc - Translate the x factor of the fusionMuzzle into the current
//muzzle position by using the forward/right vectors determined
//earlier.
VectorMA(newMuzzle, tmpMuzzle[0], forward, newMuzzle);

//racc - Translate the y factor with the same method.
VectorMA(newMuzzle, tmpMuzzle[1], right, newMuzzle);

//racc - Bump up the muzzle point so it's in terms of the viewpoint inside of the player origin.
newMuzzle[2] += ent->client->ps.viewheight + tmpMuzzle[2];

//racc - Convert the data to integers to make it easier on the network connection.
SnapVector( newMuzzle );

//racc - Configure missile1 with the newly calculated muzzle point.
missile1 = CreateMissile( newMuzzle, forward, FUSION_CUTTER_VELOCITY, 10000, ent, qfalse);

Fracman
06-29-2003, 04:53 PM
To be perfect, you'd have to adjust the firing sequences to the inclination of the weapon, since it is lower on the right side of your screenshot.
And it seems the two left and the two right projectiles are closer to each other, leaving a gap between the middle two.
But its not that important.
Cool its working!!!

recombinant
06-29-2003, 09:31 PM
Thanks for the inline comments, razorace - they help immensely...

Fracman - yes it's not perfect, but I'm really happy with the results so far, and I still have some tweaking to do with it anyway.

Thanks for all the great help, guys!! YOU ROCK!!!

:D

ImmolatedYoda
06-29-2003, 11:46 PM
man, i cant wait to plug some stormies with some secondary fusion cutter action....:D good work recombinant and everyone else, youre helping a better cause! ;)

razorace
06-30-2003, 03:37 AM
Originally posted by recombinant
Thanks for the inline comments, razorace - they help immensely...Thanks for all the great help, guys!! YOU ROCK!!!

:D
You're welcome.

recombinant
07-03-2003, 04:20 PM
Originally posted by Fracman
To be perfect, you'd have to adjust the firing sequences to the inclination of the weapon, since it is lower on the right side of your screenshot.
And it seems the two left and the two right projectiles are closer to each other, leaving a gap between the middle two.

After playing around with the code for a bit I think I've got it looking much better:

http://64.224.160.19/jk2images/FusionCutter070203a.jpg

http://64.224.160.19/jk2images/FusionCutter070203b.jpg

There's still an issue with the sequencing on the primary fire that Salv pointed out to me privately, but that shouldn't be too difficult to fix.

:holosid:

recombinant
07-03-2003, 05:29 PM
...as predicted, the fix for the sequencing was trivial.

whew!

:holosid:

Fracman
07-03-2003, 06:56 PM
Everything is trivial... after you know how to do :D

Nice work, Code-Recombinant! :p

RoxStar
07-04-2003, 01:40 AM
Man, If I could do half of the stuff you guys are doing...

SepTa
07-24-2003, 08:31 PM
If you could do half of it.... hmmm...... that brings up a good point. How do you do half this stuff.

Ok, let me reitterate. I've scoured the base pk3s, searched them up and down. I still havent found the files that control the weaponry. Furthermore, I've only ever seen lightsaber mods, and not very good ones at that. I've yet to find a mod that actually edits the gun's projectiles. Reskins and new models all over the place, with some quickened fire rates, dubbed as weapon mods. But none of the projectiles have changed. But looking at the FC here... It appears you guys have pulled it off.to my knowledge, you guys are the only people to actually successfully turn one weapon into another.

My question is: What files controll the weapon actions? sounds?what controls the projectiles? I might be able to pull off making some very unique guns, I'm good at figuring out code. But I need to know file names and directories first. Any help here?

Commodus
07-24-2003, 09:40 PM
The source. Download the second set of editing tools and you will get the source code for the game, cgame and ui modules of JK2 (in C code).

When the .c files are compiled they make .qvm files (which are located in the vm directory in the .pk3s).

Fracman
07-25-2003, 05:55 AM
The source has those weapon related files:
bg_weapons.h (defines to enable each weapons and ammo separately)
bg_weapons.c (properties of each weapon, e.g. ammo, damage)
cg_weaponinit.c (initialize weapon structures and assign models & sounds)
cg_weapon.c (insert weapons in game)
fx_xxx.c (weapon effects)
g_weapon.c (firing weapons, primary and secondary fire)

recombinant
07-25-2003, 07:27 PM
Originally posted by Commodus
The source. Download the second set of editing tools and you will get the source code for the game, cgame and ui modules of JK2 (in C code).

When the .c files are compiled they make .qvm files (which are located in the vm directory in the .pk3s).

...succinctly put. well done!

:D

RoxStar
07-25-2003, 11:47 PM
Thanks.