View Single Post
Old 09-02-2008, 04:50 PM   #18
nizwiz
Rookie
 
nizwiz's Avatar
 
Join Date: Jul 2007
Posts: 159
Arrow

Well, I have a first draft that works, mostly.

I've used vanilla jk3 SDK, so you'll first have to get it to compile. Go download and install MS Visual C++ 2008 Express edition, if you haven't already. Then download and apply these code fixes. Open the solution in Visual Studio (double-click on codemp\JKA_mp(SDK).sln in Windows Explorer), then try and build the whole solution. If three DLLs have been produced in codemp\Debug, you're ready to go.

Now to the actual mod:
You'll have to edit codemp\game\w_force.c (the mod is serverside; if that won't do, tell me and I'll look into it again).
So in Visual Studio, in the left hand tree view, double-click on JK2game/Source Files/w_force.c.

First, you'll have to define which force powers are supposed to switch the saber off. On top of w_force.c, right after the #include's, add the following piece of
Code:
	const int mask_SaberDeactivatingForcePowers = 0
	//	| (1 <<	FP_HEAL) 
	//	| (1 << FP_LEVITATION)
	//	| (1 << FP_SPEED)
	//	| (1 << FP_PUSH)
	//	| (1 << FP_PULL)
	//	| (1 << FP_TELEPATHY)
	//	| (1 << FP_GRIP)
	//	| (1 << FP_LIGHTNING)
	//	| (1 << FP_RAGE)
	//	| (1 << FP_PROTECT)
	//	| (1 << FP_ABSORB)
	//	| (1 << FP_TEAM_HEAL)
	//	| (1 << FP_TEAM_FORCE)
	//	| (1 << FP_DRAIN)
	//	| (1 << FP_SEE)
	;
and then remove the comment signs (//) in front of the chosen force powers.

Now we're going to switch the saber off in WP_ForcePowerStart(...).
Jump to that function (on top of the right hand edit view, there are two list boxes right under the filename thingy; the left one should read "(Global Scope)", the right one should be empty; open the right one and select said function from the list).
You'll find a lengthy "switch" construct in the function (there's only one, so that shouldn't be a problem). Right after the switch block, insert the section indicated in this
Code:
        ...
	default:
		break;
	}

//the following section inserted by nizwiz:
	if ( self->client->ps.saberHolstered != 2 
		&& ((1 << forcePower) & mask_SaberDeactivatingForcePowers) != 0 )
	{
		// store the current activation state of the sabers in self->genericValue13
		// so that we can restore it afterwards 
		// (genericValue13 doesn't seem to be used elsewhere for players)
		self->genericValue13 = 2 - self->client->ps.saberHolstered;

		// now switch the sabers off

		if ( self->client->ps.saberHolstered == 1 
			&& self->client->saber[1].model 
			&& self->client->saber[1].model[0] )
		{//turn off second sabers
			G_Sound( self, CHAN_WEAPON, self->client->saber[1].soundOff );
		}
		else
		{//turn off first
			G_Sound( self, CHAN_WEAPON, self->client->saber[0].soundOff );
		}

		self->client->ps.saberHolstered = 2;
	}
//insertion ends here

	if ( duration )
	{
        ...
(BTW, this is mostly copied from the taunt command; following your idea, I just looked it up there, copied it and it worked like a charm; then I've modified it a bit to accomodate for the automatic re-ignition later).
Well, that's it for the deactivation part.

Finally, to re-activate the saber after all saber-deactivating powers are done, you'll have to edit - guess what - right, WP_ForcePowerStop(...). So jump there, and at the end of the function, add the section indicated in the following snippet of
Code:
        ...
	default:
		break;
	}

//the following section inserted by nizwiz:
	// if all saber deactivating force powers have been stopped,
	// and sabers had actually been forced off, switch 'em on again (if they aren't already)
	if ( (self->client->ps.fd.forcePowersActive & mask_SaberDeactivatingForcePowers) == 0
		&& self->genericValue13 != 0 )
	{
		if ( self->client->ps.saberHolstered == 2 )
		{
			self->client->ps.saberHolstered = 2 - self->genericValue13;
			if ( self->client->ps.saberHolstered == 1 
				&& self->client->saber[1].model 
				&& self->client->saber[1].model[0] )
			{//turn on second saber
				G_Sound( self, CHAN_WEAPON, self->client->saber[1].soundOn );
			}
			else
			{//turn on first
				G_Sound( self, CHAN_WEAPON, self->client->saber[0].soundOn );
			}
		}

		self->genericValue13 = 0;
	}
//insertion ends here

}
...
That's it. Now you'll just have to re-build the server (in the left hand tree view, right-click on "JK2game" and select "Build"), then pack the produced jampgamex86.dll up in a pk3 (you only need jampgamex86.dll since it's a serverside only mod) and put it in your base folder.

I've tried this mod with most force powers, and here's the deal:
- It doesn't seem to work at all for "heal" and "jump" (looks like WP_ForcePowerStart isn't called for these)
- For "push" and "pull" the deactivation part works, but the re-activation doesn't (WP_ForcePowerStop isn't called for these; they're kinda instant powers).
If you do want the de/re-activation for any of those force powers as well, say so and I'll look into again (otherwise I'd rather not).

What I haven't tried at all is "team heal" and "team energize". Also, I haven't tested the mod with dual sabers / staff. I'll leave that all to you.

And one more shortcoming (sort of): If you define any of the long-term force powers (see, speed, protect, absorb) as saber-deactivating, there's nothing that hinders you to activate the saber again while the force power's still active. If this is a problem, say so and I'll try to find a way around that (though that's likely more difficult to accomplish).

In case of problems, just post them here and I'll try to help.

Last edited by nizwiz; 09-02-2008 at 05:06 PM.
nizwiz is offline   you may: quote & reply,