really strange armor problem

Locked
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

really strange armor problem

Post by Rawing »

okay, let's see... first off, I've done G_LocationDamage ( described here: http://code3arena.planetquake.gamespy.c ... al14.shtml).
I am trying to make 3 different types of armor: head, body and legs. I guess it's too much to write here what I had to change :)
Okay, next I've moved CheckArmor() from G_Damage to G_LocationDamage. It's called every time a client gets hit so it doesn't make a difference. I added "int dflags;" and set them to DAMAGE_HEAD when you get hit in the head, DAMAGE_BODY when get hit in the body and DAMAGE_LEGS when you get hit in the legs. CheckArmor has been modified too: just added if(dflags==DAMAGE_HEAD){client->ps.stats[STAT_ARMOR_HEAD] -= take; } ......
compiled it, tested it. Doesn't work. I've been playing around; modified it for testing to look like this:

Code: Select all

int CheckArmor (gentity_t *ent, int damage, int dflags)
{
	gclient_t	*client;
	int			save;

	if (dflags & DAMAGE_NO_ARMOR)
		return 0;

	client = ent->client;
	if (!client)
		return 0;
	return 500;
}
hit in the feet: damage
hit in the body: health increases
hit in the head: damage

But that's not all; I added this to cg_drawstatusbar:

Code: Select all

trap_R_SetColor( colors[0] );
	
	value = ps->stats[STAT_ARMOR_HEAD];
	CG_DrawField (100, 312, 1, value);
		
	value = ps->stats[STAT_ARMOR_BODY];
	CG_DrawField (100, 372, 1, value);
		
	value = ps->stats[STAT_ARMOR_LEGS];
	CG_DrawField (100, 432, 1, value);
In game it says you have 9(!!!) armor, although I set it to 100 :S
It's really strange to me lol :offended:
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: really strange armor problem

Post by ^misantropia^ »

What does your statIndex_t enum look like?
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: really strange armor problem

Post by Rawing »

You mean this one?

Code: Select all

// player_state->stats[] indexes
// NOTE: may not have more than 16
typedef enum {
	STAT_HEALTH,
	STAT_HOLDABLE_ITEM,
#ifdef MISSIONPACK
	STAT_PERSISTANT_POWERUP,
#endif
	STAT_WEAPONS,					// 16 bit fields			
	STAT_ARMOR_HEAD,
	STAT_ARMOR_BODY,
	STAT_ARMOR_LEGS,
	STAT_DEAD_YAW,					// look this direction when dead (FIXME: get rid of?)
	STAT_CLIENTS_READY,				// bit mask of clients wishing to exit the intermission (FIXME: configstring?)
	STAT_MAX_HEALTH,				// health / armor limit, changable by handicap
	STAT_PLAYERHEAL,				// amount of health player will receive through regeneration
	STAT_MEDKITS					// amount of medkits in inventory
} statIndex_t;
btw: I know that all three types of armor ARE DEFINITIVELY set to 100 ( I tried to just add the armor to the damage and everything did exactly 100 more damage ).
[color=#FF0000]/callvote kick all_enemies[/color]
jal_
Posts: 223
Joined: Mon Mar 24, 2008 4:13 pm

Re: really strange armor problem

Post by jal_ »

just added if(dflags==DAMAGE_HEAD){client->ps.stats[STAT_ARMOR_HEAD] -= take; } ......
compiled it, tested it. Doesn't work.
You should probably use & for the comparison. I supose some other damage flags could accompany the location.
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: really strange armor problem

Post by Rawing »

uh, sorry, my fault. I did use '&' just wrote == here in the forum.
[color=#FF0000]/callvote kick all_enemies[/color]
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: really strange armor problem

Post by Rawing »

okay, i know why it says you have 9 armor :disgust: sorted out already; i thought CG_DrawField (100, 432, 1, value) makes the size smaller :shrug:
[color=#FF0000]/callvote kick all_enemies[/color]
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: really strange armor problem

Post by Rawing »

okaaaaaaaaaaaaaay, i've replaced all those damage_head, damage_body and damage_legs by damage_no_protection and others (which were programmed already) and it WORKS!!
but i don't want to keep it like this. so i have one question and i know it's basic knowledge but i wasnt able to find it out:
what does #define DAMAGE_NO_PROTECTION 0x00000008 exactly do?? why does it matter which number i use (e.g.: 0x00000016 wouldnt work)??
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: really strange armor problem

Post by ^misantropia^ »

Because it's:

a) a hexadecimal value (0x16 == 22)
b) used in a bitmask: http://en.wikipedia.org/wiki/Bit_manipulation
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: really strange armor problem

Post by Rawing »

thanks... another hard part of coding for me to learn :offended:
[color=#FF0000]/callvote kick all_enemies[/color]
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: really strange armor problem

Post by Rawing »

why isn't '==' used for a comparison? i checked it; it works; and if you write

Code: Select all

if (dflags & DAMAGE_RADIUS)
dflags and DAMAGE_RADIUS are just added and it's true if it's not zero.(?)
[color=#FF0000]/callvote kick all_enemies[/color]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Re: really strange armor problem

Post by ^misantropia^ »

Because dflags might contain more than just DAMAGE_RADIUS. DAMAGE_RADIUS & SOME_OTHER_FLAG != DAMAGE_RADIUS.
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: really strange armor problem

Post by Rawing »

but if you just ADD something to it before the "if" checks whether it's not zero, it can't ever be zero!?
and... I'm again messing around with it... (lol) ;I added EF_STOP which simply causes a missile to not move if it hits a wall. I just changed EF_KAMIKAZE to EF_STOP and it doesn't work (once again :offended: )
[color=#FF0000]/callvote kick all_enemies[/color]
AnthonyJ
Posts: 130
Joined: Wed Nov 15, 2006 7:51 pm

Re: really strange armor problem

Post by AnthonyJ »

Rawing wrote:but if you just ADD something to it before the "if" checks whether it's not zero, it can't ever be zero!?
(x & y) is not adding two values together, it is doing a bitwise AND operation.

The wikipedia link that misantropia gave you got straight into the C coding details of it, but perhaps you need to go back a step and understand what the bitwise operators are. Try this one: http://en.wikipedia.org/wiki/Bitwise_operation

One thing I noticed that might confuse you a bit about that wikipedia link is that it doesnt explain that it is writing the numbers in binary notation, so when it says 0011 it does not mean the number eleven, but the binary value 0011, which is the decimal number three. Note that in C++ code, you'll usually see the numbers written in hexadecimal (hex), with the 0x notation, because its much clearer to see which bits are set.

Bitmasks are a clever way of storing multiple "flags" in one integer value, and then using the bitwise AND operator to test which combinations of the flags are set.
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: really strange armor problem

Post by Rawing »

oh, cool! got it xd :idea:
But what I still don't understand is my not working ef_stop flag :/

Code: Select all

#define	EF_STOP				0x00000200		// for missiles
and, in G_MissileImpact:

Code: Select all

if ( ent->s.eFlags & EF_STOP ) {
		VectorScale( ent->s.pos.trDelta, 0, ent->s.pos.trDelta );
	}
It's f***ing weird. It just continues moving lol. There can't be a problem with an other flag using 0x00000200 coz I replaced it ( :D ) so I can't image what the problem is.
[color=#FF0000]/callvote kick all_enemies[/color]
Rawing
Posts: 107
Joined: Tue Oct 23, 2007 1:40 pm

Re: really strange armor problem

Post by Rawing »

it's sorted out now.
[color=#FF0000]/callvote kick all_enemies[/color]
Locked