Problem thread "Powerup Visualization"


(nUllSkillZ) #1

Hi,

I’m trying to make a little clientside mod.
This mod should give some graphical feedback of used “powerups” (invulnerability and adrenaline).
Proble:
It isn’t working (actually the game isn’t starting at all / the game hangs up with no feedback).

Here are the changes:
“cgame/cg_main.c” line ~ 1959 (in function “CG_RegisterGraphics”):


	cgs.media.AdrenalineWeaponShader =			trap_R_RegisterShader("powerups/AdrenalineWeapon");
	cgs.media.InvulnerableWeaponShader =		trap_R_RegisterShader("powerups/InvulnerableWeapon");

cgame/cgweapons.c - line ~ 1976 (in function “CG_AddWeaponWithPowerups”):


	if ( powerups & ( 1 << PW_ADRENALINE ) )
	{
		gun->customShader = cgs.media.AdrenalineWeaponShader;
	}
	else if ( powerups & ( 1 << PW_INVULNERABLE ) )
	{
		gun->customShader = cgs.media.InvulnerableWeaponShader;
	}
	trap_R_AddRefEntityToScene( gun );

The shader:


powerups/AdrenalineWeapon
{
	deformVertexes wave 100 sin 0.5 0 0 0
	{
		map textures/effects/adrenalinered.tga
		blendfunc GL_ONE GL_ONE
		tcGen environment
                tcmod rotate 30
		//tcMod turb 0 0.2 0 .2
                tcmod scroll 1 .1
	}
}

powerups/InvulnerableWeapon
{
	deformVertexes wave 100 sin 0.5 0 0 0
	{
		map textures/effects/invulnerableblue.tga
		blendfunc GL_ONE GL_ONE
		tcGen environment
                tcmod rotate 30
		//tcMod turb 0 0.2 0 .2
                tcmod scroll 1 .1
	}
}

The “powerups.pk3”-file contains the “cgame_mp_x86.dll” (also unzipped to the “etmain” directory), the “scipts/powerups.shader”, the “textures/effects/adrenalinered.jpg” and the “textures/effects/invulnerableblue.jpg”.

The server is started unpure.

Any help would be much appreciated.

Note:
This is only a test with the shaders for the weapons.
I will try to add these shaders also to the playermodels.

Second note:
Some of the code parts, the shaders, and the textures are taken from Q3.


(nUllSkillZ) #2

C-noob at work.
:smiley:
Partially solved.
I missed some declarations:
cgame/cg_local.h - line ~ 1712 (in cgMedia_t)


	qhandle_t		AdrenalineWeaponShader;
	qhandle_t		InvulnerableWeaponShader;

But the next problem occurs.
The graphics are totally messed up:

:frowning:


(IneQuation) #3

It seems you put these declarations between others and the game expected different shader indexes. Try to make these declarations the very last ones.


(nUllSkillZ) #4

I’ve inserted them at the end of the structure.


(Jaquboss) #5

UTFSB :nag:
I already answered this, try to recompile all cgame ( delete temp files ) , and you also might try to do it with ui too …


(P4nth3r) #6

yep, I had the same problem with the duke mod.
Just clean up and recompile. it works ^^


(nUllSkillZ) #7

Thank you very much for your tips Jaquboss and P4nth3r.
Seems that everything is working fine now.
I’ve had also a corrupted file (“bg_pmove.c”).
And I’ve made some stupid mistakes.
Thnx again for helping.


(P4nth3r) #8

Your welcome (Jaquboss told me before (with duke mod) so all thanx goes to him) ^^


(nUllSkillZ) #9

The mod is working now.
But I have another problem.

As far as I remember in Q3 the models under the powerup texture were shown correctly.
All I see in my mod is the powerup texture.


(Jaquboss) #10

post your powerup rendering code
guess you do it a bit bad :slight_smile:
check if you render powerups after rendering normal model
and not just overriding model shaders …


(nUllSkillZ) #11

Stupid me.
Your the best.
I’ve moved the code for the playermodell to the end of the function.
Seems to work proberly now.
Only the weapons aren’t shown correct.

I’ve found these code snippets in the Q3 source code.

Here’s the code for the playermodels (cgame/cg_players.c - line 1652):


	// ***** nUllSkillZ START *****
	if ( es->powerups & ( 1 << PW_INVULNERABLE ) )
	{
		ent->customShader = cgs.media.InvulnerableShader;
	}
	if ( es->powerups & ( 1 << PW_ADRENALINE ) )
	{
		ent->customShader = cgs.media.AdrenalineShader;
	}	
	trap_R_AddRefEntityToScene( ent );
	// ***** nUllSkillZ END *****

	*ent = backupRefEnt;
}

The code for the weapons (cgame/cg_weapons.c - line 1974):


/*
========================
CG_AddWeaponWithPowerups
========================
*/
static void CG_AddWeaponWithPowerups( refEntity_t *gun, int powerups, playerState_t *ps, centity_t *cent ) {
	// add powerup effects
	// DHM - Nerve :: no powerup effects on weapons

	// ***** nUllSkillZ START *****
	if ( powerups & ( 1 << PW_INVULNERABLE ) )
	{
		gun->customShader = cgs.media.InvulnerableWeaponShader;
	}
	if ( powerups & ( 1 << PW_ADRENALINE ) )
	{
		gun->customShader = cgs.media.AdrenalineWeaponShader;
	}
	// ***** nUllSkillZ END *****

	trap_R_AddRefEntityToScene( gun );
}

Edit:

I’ve just found the solution.
I’ve added another “trap_R_AddRefEntityToScene( gun );” at the beginning of the function.
And it’s working.
:clap: :banana:
Thnx again for your help Jaquboss.


(Jaquboss) #12
*
========================
CG_AddWeaponWithPowerups
========================
*/
static void CG_AddWeaponWithPowerups( refEntity_t *gun, int powerups, playerState_t *ps, centity_t *cent ) {
   qboolean powerup=qfalse;

  // draw normal model
   trap_R_AddRefEntityToScene( gun );

   // ***** nUllSkillZ START *****
   if ( powerups & ( 1 << PW_INVULNERABLE ) )
   {
      gun->customShader = cgs.media.InvulnerableWeaponShader;
      powerup = qtrue;
   }
   if ( powerups & ( 1 << PW_ADRENALINE ) )
   {
      gun->customShader = cgs.media.AdrenalineWeaponShader;
      powerup = qtrue;
   }
   // ***** nUllSkillZ END *****

   if ( powerup )
   trap_R_AddRefEntityToScene( gun );
} 

EDIT: ah, but still update your code so you don’t draw normal weapos twice :drink:
EDIT2: do the same for playermodels too


(nUllSkillZ) #13

Ok thnx.
Haven’t thought about this.


(nUllSkillZ) #14

Sorry to disturb again.

Another problem.
How can I get the values of the playerType (e.g. engineer) and the skill (e.g. SK_EXPLOSIVES_AND_CONSTRUCTION) in the following function:
src/cgame/cg_players.c around line 1602


/*
===============
CG_AddRefEntityWithPowerups

Adds a piece with modifications or duplications for powerups
Also called by CG_Missile for quad rockets, but nobody can tell...
===============
*/
void CG_AddRefEntityWithPowerups( refEntity_t *ent, int powerups, int team, entityState_t *es, const vec3_t fireRiseDir ) {
	centity_t *cent;
	refEntity_t backupRefEnt;//, parentEnt;
	qboolean	onFire=qfalse;
	float		alpha=0.0;
	float		fireStart, fireEnd;

	// ***** nUllSkillZ START *****
	qboolean	bln_powerup;
	qhandle_t	backupcustomShader;

	bln_powerup = qfalse;
	// ***** nUllSkillZ END *****

	cent = &cg_entities[es->number];

	ent->entityNum = es->number;

	backupRefEnt = *ent;

	if (CG_EntOnFire(&cg_entities[es->number])) {
		ent->reFlags |= REFLAG_FORCE_LOD;
	}

	trap_R_AddRefEntityToScene( ent ); // nUllSkillZ ORIGINAL

	// ***** nUllSkillZ START *****
	backupcustomShader = ent->customShader;


	if ( es->powerups & ( 1 << PW_ADRENALINE ) )
	{
		ent->customShader = cgs.media.puAdrenalineShader;
		bln_powerup = qtrue;
	}
	if ( es->powerups & ( 1 << PW_INVULNERABLE ) )
	{
			ent->customShader = cgs.media.puInvulnerableShader;
			bln_powerup = qtrue;
	}
	if ( es->powerups & ( 1 << PW_OPS_DISGUISED ) )
	{
		if ( cg.snap->ps.persistant[PERS_TEAM] == team )
		{
			ent->customShader = cgs.media.puDisguisedShader;
			bln_powerup = qtrue;
		}
	}
	if( es->powerups & ( 1 << PW_REDFLAG ) || es->powerups & ( 1 << PW_BLUEFLAG ) )
	{
			ent->customShader = cgs.media.puObjectiveShader;
			bln_powerup = qtrue;
	}

	if ( bln_powerup )
	{
		// ONLY LAST "LAYER" WILL BE SHOWN
		trap_R_AddRefEntityToScene( ent );
	}
	ent->customShader = backupcustomShader;
	// AND THEN FIRE ON TOP AS FOLLOWS
	// ***** nUllSkillZ END *****

	if (!onFire && CG_EntOnFire(&cg_entities[es->number])) {
		onFire = qtrue;
		// set the alpha
		if ( ent->entityNum == cg.snap->ps.clientNum ) {
			fireStart = cg.snap->ps.onFireStart;
			fireEnd = cg.snap->ps.onFireStart + 1500;
		}
		else {
			fireStart = es->onFireStart;
			fireEnd = es->onFireEnd;
		}

		alpha = (cg.time - fireStart) / 1500.0;
		if (alpha > 1.0) {
			alpha = (fireEnd - cg.time) / 1500.0;
			if (alpha > 1.0) {
				alpha = 1.0;
			}
		}
	}

	if (onFire) {
		if (alpha < 0.0) alpha = 0.0;
		ent->shaderRGBA[3] = (unsigned char)(255.0*alpha);
		VectorCopy( fireRiseDir, ent->fireRiseDir );
		if (VectorCompare(ent->fireRiseDir, vec3_origin)) {
			VectorSet( ent->fireRiseDir, 0, 0, 1 );
		}
		ent->customShader = cgs.media.onFireShader;
		trap_R_AddRefEntityToScene( ent );

		ent->customShader = cgs.media.onFireShader2;
		trap_R_AddRefEntityToScene( ent );

		if (ent->hModel == cent->pe.bodyRefEnt.hModel)
			trap_S_AddLoopingSound( ent->origin, vec3_origin, cgs.media.flameCrackSound, (int)(255.0*alpha), 0 );
	}

	*ent = backupRefEnt;
}

I’ve looked already in the definition of “centity_t”, “refEntity_t” and I think “entityState_t”.
Any help much appreciated.


(IneQuation) #15

From cgame/cg_consolecmds.c:

	int playerType;
	const char *s;

	playerType = cgs.clientinfo[ cg.clientNum ].cls;

	if ( playerType == PC_MEDIC )
		s = "IamMedic";
	else if ( playerType == PC_ENGINEER )
		s = "IamEngineer";
	else if ( playerType == PC_FIELDOPS )
		s = "IamFieldOps";
	else if ( playerType == PC_COVERTOPS )
		s = "IamCovertOps";
	else
		s = "IamSoldier";

Skills are stored in cgs.clientinfo[clientNum]->skill[skill]. To get a class specific skill ID, use BG_ClassSkillForClass(cgs.clientinfo[clientNum]->cls).


(Jaquboss) #16

yeah exactly, clientinfo must be valid on player anyway :slight_smile:
EDIT: fixed doublepost

if ( cgs.clientinfo[es->clientNum].cls == PC_ENGINEER && cgs.clientinfo[es->clientNum].skill[SK_EXPLOSIVES_AND_CONSTRUCTION] >= 4 ){
draw that thing
}
I would paint engineer skins w/o flakjacket and then use flakjacket as a decal
but that doesn’t belong to that place…
also you could do a model but it will take a time to fit
best would be to use diffirent playermodel :slight_smile:


(nUllSkillZ) #17

Thank you very much for your help again.
Have to look for your posts tomorrow.

I have to think about how to realize the flakjacket.
ATM I try to get it to work as the other powerups (addition of playermodels).

Another thing I have to think about is mods where players can keep the flakjacket even if they are no engineers.

Edit:

Couldn’t resist to try it :smiley:
And it works :banana:
Great job guys :clap:
Now I have to add the weapons too.