ch->move = ch->move - 1;

Posted by Klered on Fri 25 Feb 2005 04:05 AM — 10 posts, 35,486 views.

#0
I put this in fight.c in the function

ch_ret damage ///Inflict damage from a hit!

My goal was to remove 1 move per strike = hit or miss. I don't understand why an extra move is removed except for the very last round. What am I missing about this loop? I used the send_to_char to report the loop....please help?

tia - travestin



    /*Travestin - Remove 1 move for each strike = hit or miss in a round*/
    
        ch->move = ch->move - 1;
       send_to_char("test the moves!\n\r", ch);



<snip>

[(867/954hp)(353/353ma)(651/690mv)]The master's apprentice->[|||| ]
Your crush **DESTROYS** the master's apprentice!
test the moves!
Your crush **DESTROYS** the master's apprentice!
test the moves!
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.

[(867/954hp)(353/353ma)(648/690mv)]The master's apprentice->[|||| ]
Your crush **DESTROYS** the master's apprentice!
test the moves!
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.

[(867/954hp)(353/353ma)(646/690mv)]The master's apprentice->[|||| ]
Your crush **DESTROYS** the master's apprentice!
test the moves!
Your crush massacres the master's apprentice!
test the moves!
The master's apprentice lacerates you!
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.

[(844/954hp)(353/353ma)(643/690mv)]The master's apprentice->[|| ]
Your crush obliterates the master's apprentice!
test the moves!
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.

[(844/954hp)(353/353ma)(641/690mv)]The master's apprentice->[|| ]
Your crush annihilates the master's apprentice!
test the moves!
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.

[(844/954hp)(353/353ma)(639/690mv)]The master's apprentice->[|| ]
Your crush **DESTROYS** the master's apprentice!
test the moves!
Your crush annihilates the master's apprentice!
test the moves!
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.
The master's apprentice decimates you!

[(819/954hp)(353/353ma)(636/690mv)]The master's apprentice->[|| ]
Your crush annihilates the master's apprentice!
test the moves!
Your crush **DESTROYS** the master's apprentice!
test the moves!
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.
The master's apprentice misses you.

[(819/954hp)(353/353ma)(633/690mv)]The master's apprentice->[| ]
Your crush annihilates the master's apprentice!
test the moves!
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.
The master's apprentice lacerates you!

[(797/954hp)(353/353ma)(631/690mv)]The master's apprentice->[| ]
Your crush annihilates the master's apprentice!
test the moves!
Your crush misses the master's apprentice.
test the moves!
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.

[(797/954hp)(353/353ma)(628/690mv)]The master's apprentice->[ !dying! ]
Your crush annihilates the master's apprentice!
test the moves!
Your crush annihilates the master's apprentice!
test the moves!
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.

[(797/954hp)(353/353ma)(625/690mv)]The master's apprentice->[ !dying! ]
Your crush annihilates the master's apprentice!
test the moves!
Your crush massacres the master's apprentice!
test the moves!
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.
Your armor deflects the master's apprentice's attack.

[(797/954hp)(353/353ma)(622/690mv)]The master's apprentice->[ !dying! ]
Your crush annihilates the master's apprentice!
test the moves!
The master's apprentice is DEAD!!
The Gods Have Bonused You For Your Dedication!
You receive 10243 experience points.
The master's apprentice gasps his last breath and blood spurts out of his mouth and ears.
You get 1000 gold coins from the corpse of the master's apprentice

[(797/954hp)(353/353ma)(621/690mv) - TNL:11071]
Amended on Fri 25 Feb 2005 03:32 PM by Klered
Canada #1
Looks to me like its working as it should, every "strike" shows you the hit message and then your bug message. Are you trying to do one move per round? Because multi-hit and second/third attack allow for more than one per round.
#2
Greven -

Trying to do 1 move per strike - hit or miss.

Its wierd how it does one move per strike + 1 - except at the last round.

One thing that I thought of was the difference in prompts(fprompt/prompt)...but they both are reporting from the same token %m/%M ....

not sure....
USA #3
I would tend to agree with Greven's suggestion, although you showed so little code and context that it's kind of hard to know for sure. OK, sure, your code removes 1 mp, but where? :)
#4
Ksilyan - not sure what you want me to show.

There is 1 line of code, and the bug message to make sure I got it in the right place.

fight.c function -


ch_ret damage( CHAR_DATA *ch, CHAR_DATA *victim, int dam, int dt )



just after


 /*
     * Hurt the victim.
     * Inform the victim of his new state.
     */
    victim->hit -= dam;


is where I placed my line. Seems that the location is ok. I would post the function but I think you would get mad at me =) you know..its huge.

got a stock fight.c?

#5
Is there anyone willing to put my code in your fight.c and just see what you get? (its 2 lines...see above)

Im just curious ... anyone wanna try? It would be appreciated.

TIA
Canada #6
Did you take this part into consideration?
    if ( retcode == rNONE )
    {
	int move;

	if ( !IS_AFFECTED(ch, AFF_FLYING)
	&&   !IS_AFFECTED(ch, AFF_FLOATING) )
	  move = encumbrance( ch, movement_loss[UMIN(SECT_MAX-1, ch->in_room->sector_type)] );
	else
	  move = encumbrance( ch, 1 );
	if ( ch->move )
	  ch->move = UMAX( 0, ch->move - move );
    }
It is at the end of multi_hit, and will certainly have an effect, and could account for the extra movement loss.
Canada #7
Yegh. I think Greven's got it.

Also, why use ch->move = ch->move - 1, instead of
ch->move --;
? :P
USA #8
Because the macro expands it multiple times. Every time you execute ch->move--, you are changing ch->move, and if you have a macro like this:

#define UMAX(a, b) (a > b ? a : b)

You will note that a and b are potentially evaluated twice, which would in the end decrement two from your value which is certainly not what you want to do.

(Re-reading)
Sorry- I thought you were referring to the code Greven showed you. In your own code, where the whole entire statement is just "ch->move = ch->move - 1;" you are correct, there is no reason to not use ch->move--;.
#9
ch->move--;

You learn something new everyday...

I will look at the multi-hit function, thanks for pointing it out. I supposed if I grep'd ch->move and looked at all the instances, I would have come across it. Thanks again for all your thoughts.