Forum Thread
  Posts  
Some C coding confusion (Forums : Coding & Scripting : Some C coding confusion) Locked
Thread Options
TwinBeast
TwinBeast Full Metal Bionic Witch
Sep 30 2004 Anchor

Inflictor is a projectile or in melee attacks it's the creature object. Source is the creature object shooting the projectile or the melee attacker. Target is obiviously the object to be kicked.

// Kick the target before the armor saves damage
	if(inflictor 
		&& !(target->flags & MF_NOCLIP)
		&& (!source || !source->player || !source->type == MT_NAMREPAER))

The last line is confusing me. If I'm correct, ! means no. So when there is no source or source is not a player or the source type is not MT_NAMREPAER, then it will kick the target.
But how come the target gets kicked when there is a source and how come player is able to cause monsters&other players to get kicked if that is not allowed. The namrepaer part is "clear" to me, because that kind of monsters shouldn't cause a kick to their targets...

Dragonlord
Dragonlord Linux-Dragon of quick wit and sharp tongue
Sep 30 2004 Anchor

i donno exactly where this comes from but just looking at this code i've seen one thing that is strange, and i guess is wrong.

you've got
!source->type == MT_NAMREPAER

! has precedence over == and thus it would yield '1' if the source->type is '0' and '0' if the type is non '0'. then it's compared to the value of MT_NAMREPAER.

i don't think you intended this. try once
!(source->type == MT_NAMREPAER)

donno if tha helps but this just jumped into my eyes seeing it.

EDIT: or better source->type != MT_NAMREPAER

Edited by: Dragonlord

TwinBeast
TwinBeast Full Metal Bionic Witch
Sep 30 2004 Anchor

Thanks, I think I'll try those better ones for the MT_NAMREPAER

but those 2 first ones in the line are confusing...

Dragonlord
Dragonlord Linux-Dragon of quick wit and sharp tongue
Sep 30 2004 Anchor

!source is clear. this is used to avoid a SEGV (segmentation fault) which would occur if source contains 'NULL' and you would try to read values from it. so if source is 'NULL' you don't check any further (as it is true already at that place)

i donno what this should be usefull in the end to accept a kick if the source is 'NULL' so it might be not what is intended.

so i assume the entire last row is kinda cranked up as it doesn't make sense. let's try to see if I can guess what is meant (yep, i've no idea of the SDK you use there so let's try).

1) logically only a source can cause a kick as empty air doesn't kick. so in this case if the source is 'NULL' we should not kick. this would give us '&& source'

2) player should not be able to kick. so this brings us to the following: '&& !source->player'

3) finally the type should not be MT_NAMREPAER because he can not kick (if i understood right). Thus we end up with the last condition '&& (source->type != MT_NAMREPAER)'

so build all together I would try this one then:

// Kick the target before the armor saves damage
if(inflictor
&& !(target->flags & MF_NOCLIP) /* no-clip does not kick */
&& source /* we need a source to kick */
&& !source->player /* no kick by player */
&& source->type != MT_NAMREPAER /* no kick by MT_NAMREPAER */
)

TwinBeast
TwinBeast Full Metal Bionic Witch
Sep 30 2004 Anchor

Player should be able to cause a kick to his targets(and he is), but in the code it shows the opposite.

Dragonlord
Dragonlord Linux-Dragon of quick wit and sharp tongue
Sep 30 2004 Anchor

&& source->player /* no kick by moster */

if players only can kick.

if both can drop this line entirely.

Sep 30 2004 Anchor

see all you gotta do is just get some dishwasher detergent and mix it with vineger and bam there you have it... A PERFECT LINE OF CODE... okay don't try that its not the perfect line but it really is a mediocre line of code... I admire the coders out there...

--

Dragonlord
Dragonlord Linux-Dragon of quick wit and sharp tongue
Sep 30 2004 Anchor

what was that suppost to mean... *grin*

Sep 30 2004 Anchor

Just tryin to help out... lol.... IM NOT EVEN MAKING A MOD RIGHT NOW lol

--

TwinBeast
TwinBeast Full Metal Bionic Witch
Sep 30 2004 Anchor

btw, is there a difference in 0.25 and 0,25?

Sep 30 2004 Anchor

...yea one has a comma... thats an outsiders point of view :D

--

Dragonlord
Dragonlord Linux-Dragon of quick wit and sharp tongue
Sep 30 2004 Anchor

0.25 is a double value, '0,25' on the other hand is really bad as ',' is a special separation character.

ShortCutMan
ShortCutMan ♥ Pure ♥ Bred ♥ Geek ♥
Sep 30 2004 Anchor

'0,25' would be classed as a string right? Or you would just get a compile error.

--

98% of the internet population has a Myspace. If you're part of the 98% that is an emo bastard, copy and paste this into your sig.
User Posted Image

Dragonlord
Dragonlord Linux-Dragon of quick wit and sharp tongue
Oct 1 2004 Anchor

compiler error as the ',' is used as a delimiter to designate a list of items like in the following:

int a, b=5, c;

TwinBeast
TwinBeast Full Metal Bionic Witch
Oct 1 2004 Anchor

If I want "appower" to use 0.25 or some other similar value, do I use this then "double appower;"? When I want appower to be zero, do I make it zero this way:"appower = 0.0;" or this way:"appower = 0;"?

Dragonlord
Dragonlord Linux-Dragon of quick wit and sharp tongue
Oct 1 2004 Anchor

c/c++ uses auto-casting. this means that a value of type char/short/int/float are automatically casted to double if your variable uses double as its type. so in fact you can use both ways without problems.

and about float/double.
float is a single precision decimal number using 32-bits in memory. it is more than enough for game applications (although a couple of places try to concince you it's not but if you know FPU calculations you know that this is rather stupid). double is a double precisiosn decimal number using 64-bits and in fact just claims to be more precise (having more digits in the mantisse than float) but like mentioned this doesn't make much difference.

the only difference is that with float as variable type you need to cast yourself as c/c++ considers decimal values to be double by default thus:
float myValue = (float)4;
or
float myValue = 4.0f;

Oct 1 2004 Anchor

Err.. double isn't useless my child :P

BTW... I hate all languages that have ambiguous types, or whatever you would call them. You know like in Javascript 'var i;' could be an integer, float, string anything. I hate that.
C is good because you must define them as a specific data type.

Just thought I'd say that...... :D!

--

User Posted Image

Dragonlord
Dragonlord Linux-Dragon of quick wit and sharp tongue
Oct 1 2004 Anchor

double is as said double precision... but if you know a bit math and how the computer stores the floating point values then it's not really a blast to use double. better refine your calculations to take into account the unpreciseness of floating point values.

what you call 'ambigious' types are soft typed systems like Python, mostly scripting languages, and this principle is rather powerfull. the entire GenToo is build upon Python.

c is (like my language) strongly typed which has advantages and disadvantages... one obviously beeing to force a class/function to obey to certain 'types'.

both systems are good and hating soft typed systems makes you miss a lot of good stuff... especially if you work with a powerfull system like linux then soft typed systems are the big deal (i just say /bin/bash ;=) ).

Oct 1 2004 Anchor

I will never enjoy a 'soft typed system' as you call them. And I've never heard of 'GenToo'

And Dragonlord my child, regardless of whether you learned about floating point values in school yesterday or not, the doubles are more precise. They aren't just throwing memory usage away. :=P

--

User Posted Image

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.