Well, as the title states, I'm writing a combat code, and its getting
to me! I've stepped through it with GDB countless times to get
nothing! Whats happening, is I engage thep layer, it engages, I slash,
next round when I slash again. Bam! Dies. Somewhere between starting
the first slash, and ending it, the pCbt->victim is getting screwed up
some how. This is what gdb gave me. Alot of it I hacked out because it
was redundant string formatting for game_loop calls. You can get the
source code at alhaen.muddomain.com/~alhaen/fight.c
Breakpoint 1, initCombat (attacker=0xf6e7d870, victim=0xf6e8232c)
at fight.c:223
223 for(pCbt = attacker->attacking ; pCbt ; pCbt = pCbt->next )
(gdb) step
226 pCbt = newCombat();
(gdb)
newCombat () at fight.c:178
178 if(!combatFree)
(gdb)
179 pCbt = alloc_perm(sizeof(pCbt));
(gdb)
alloc_perm (sMem=4) at db.c:2758
2758 while (sMem % sizeof (long) != 0)
(gdb)
2760 if (sMem > MAX_PERM_BLOCK)
(gdb)
2766 if (pMemPerm == NULL || iMemPerm + sMem > MAX_PERM_BLOCK)
(gdb)
2776 pMem = pMemPerm + iMemPerm;
(gdb)
2777 iMemPerm += sMem;
(gdb)
2778 nAllocPerm += 1;
(gdb)
2779 sAllocPerm += sMem;
(gdb)
2781 }
(gdb)
newCombat () at fight.c:184
184 *pCbt = combat;
(gdb)
185 pCbt->next = NULL;
(gdb)
186 pCbt->cnext = NULL;
(gdb)
187 pCbt->attacker = NULL;
(gdb)
188 pCbt->victim = NULL;
(gdb)
189 pCbt->valid = TRUE;
(gdb)
190 return pCbt;
(gdb)
191 }
(gdb)
initCombat (attacker=0xf6e7d870, victim=0xf6e8232c) at fight.c:227
227 pCbt->damage = 0;
(gdb)
228 pCbt->taken = 0;
(gdb)
229 pCbt->next = attacker->attacking;
(gdb)
230 attacker->attacking = pCbt;
(gdb)
231 pCbt->cnext = combatList;
(gdb)
232 combatList = pCbt;
(gdb)
233 pCbt->attacker = attacker;
(gdb)
234 pCbt->victim = victim;
(gdb)
235 resetTimeout(pCbt);
(gdb)
resetTimeout (pCbt=0xf6e87b64) at fight.c:76
76 }
(gdb)
initCombat (attacker=0xf6e7d870, victim=0xf6e8232c) at fight.c:236
236 pCbt->active = TRUE;
(gdb)
238 }
(gdb)
do_engage (ch=0xf6e7d870, argument=0xf6e87b64 "") at fight.c:397
397 }
(gdb)
interpret (ch=0xf6e7d870, argument=0xf6e7c610 "darien") at interp.c:546
546 tail_chain ();
(gdb)
tail_chain () at db.c:3506
3506 }
(gdb)
interpret (ch=0xf6e7d870, argument=0xf6e7c610 "darien") at interp.c:548
548 }
(gdb)
substitute_alias (d=0xf6e7c1e8, argument=0xf6e7c609 "engage darien")
at alias.c:69
69 return;
(gdb)
104 }
(gdb)
game_loop_unix (control=6) at comm.c:830
830 break;
(gdb)
833 break;
(gdb)
836 d->incomm[0] = '\0';
(gdb)
784 for (d = descriptor_list; d != NULL; d = d_next)
(gdb)
845 update_handler ();
(gdb)
update_handler () at update.c:695
695 combatUpdate();
(gdb)
combatUpdate () at fight.c:154
154 for( pCbt = combatList; pCbt ; pCbt = pCbtNext )
(gdb)
156 if(!pCbt->valid)
(gdb)
155 { pCbtNext = pCbt->cnext;
(gdb)
156 if(!pCbt->valid)
(gdb)
158 pCbt->timeout -= 0.1f;
(gdb)
159 if(pCbt->timeout <= 0.0f )
(gdb)
164 if(isDelayed(pCbt->attacker) )
(gdb)
isDelayed (ch=0xf6e70020) at fight.c:79
79 return FALSE;
(gdb)
81 }
(gdb)
combatUpdate () at fight.c:154
154 for( pCbt = combatList; pCbt ; pCbt = pCbtNext )
(gdb)
172 }
(gdb)
game_loop_unix (control=6) at comm.c:820
820 if (d->showstr_point)
(gdb)
822 else if (d->pString)
(gdb)
825 switch (d->connected)
(gdb)
828 if (!run_olc_editor(d) &&
!interpCombat(d->original ? d->original : d->character, d->incomm))
(gdb)
run_olc_editor (d=0xf6e7c1e8) at olc.c:41
41 switch (d->editor)
(gdb)
66 return FALSE;
(gdb)
69 }
(gdb)
interpCombat (ch=0xf6e7d870, argument=0xf6e7c609 "slash") at fight.c:126
126 argument = one_argument(argument, cmd);
(gdb)
one_argument (argument=0xf6e7c609 "slash", arg_first=0xfefff6e0 "engage")
at interp.c:762
762 while (isspace (*argument))
(gdb)
765 cEnd = ' ';
(gdb)
766 if (*argument == '\'' || *argument == '"')
(gdb)
779 }
(gdb)
771 if (*argument == cEnd)
(gdb)
776 *arg_first = LOWER (*argument);
(gdb)
777 arg_first++;
(gdb)
778 argument++;
(gdb)
779 }
(gdb)
771 if (*argument == cEnd)
(gdb)
776 *arg_first = LOWER (*argument);
(gdb)
777 arg_first++;
(gdb)
778 argument++;
(gdb)
779 }
(gdb)
771 if (*argument == cEnd)
(gdb)
776 *arg_first = LOWER (*argument);
(gdb)
777 arg_first++;
(gdb)
778 argument++;
(gdb)
779 }
(gdb)
771 if (*argument == cEnd)
(gdb)
776 *arg_first = LOWER (*argument);
(gdb)
777 arg_first++;
(gdb)
778 argument++;
(gdb)
779 }
(gdb)
771 if (*argument == cEnd)
(gdb)
776 *arg_first = LOWER (*argument);
(gdb)
777 arg_first++;
(gdb)
778 argument++;
(gdb)
779 }
(gdb)
780 *arg_first = '\0';
(gdb)
782 while (isspace (*argument))
(gdb)
785 return argument;
(gdb)
786 }
(gdb)
interpCombat (ch=0xf6e7d870, argument=0xf6e7c609 "slash") at fight.c:129
129 if( ( attack = getAttack(cmd) ) == -1 )
(gdb)
getAttack (txt=0xfefff6e0 "slash") at fight.c:52
52 for( i = 0; attackTable[i].name != NULL ; i++ )
(gdb)
53 { if(LOWER(txt[0]) == LOWER(attackTable[i].name[0]) &&
(gdb)
str_prefix (astr=0xfefff6e0 "slash", bstr=0x80a324d "slash") at db.c:3279
3279 if (astr == NULL)
(gdb)
3285 if (bstr == NULL)
(gdb)
3293 if (LOWER (*astr) != LOWER (*bstr))
(gdb)
3291 for (; *astr; astr++, bstr++)
(gdb)
3293 if (LOWER (*astr) != LOWER (*bstr))
(gdb)
3291 for (; *astr; astr++, bstr++)
(gdb)
3293 if (LOWER (*astr) != LOWER (*bstr))
(gdb)
3291 for (; *astr; astr++, bstr++)
(gdb)
3293 if (LOWER (*astr) != LOWER (*bstr))
(gdb)
3291 for (; *astr; astr++, bstr++)
(gdb)
3293 if (LOWER (*astr) != LOWER (*bstr))
(gdb)
3291 for (; *astr; astr++, bstr++)
(gdb)
3297 return FALSE;
(gdb)
3298 }
(gdb)
getAttack (txt=0xfefff6e0 "slash") at fight.c:55
55 return i;
(gdb)
58 }
(gdb)
interpCombat (ch=0xf6e7d870, argument=0xf6e7c609 "slash") at fight.c:132
132 if(!ch->attacking)
(gdb)
137 if(isDelayed(ch) )
(gdb)
isDelayed (ch=0xf6e70020) at fight.c:79
79 return FALSE;
(gdb)
81 }
(gdb)
interpCombat (ch=0xf6e7d870, argument=0xf6e7c609 "slash") at fight.c:142
142 if( !(pCbt = getActive(ch) ) )
(gdb)
getActive (ch=0xf6e7d870) at fight.c:104
104 for( pCbt = ch->attacking ; pCbt ; pCbt = pCbt->next )
(gdb)
105 { if(pCbt->active && pCbt->valid )
(gdb)
109 }
(gdb)
interpCombat (ch=0xf6e7d870, argument=0xf6e7c609 "slash") at fight.c:147
147 (*attackTable[attack].attackFun)(pCbt, attack);
(gdb) p pCbt->victim->name
$1 = 0xf6e7e718 "Darien"
(gdb) step
cbtSlash (pCbt=0xf6e87b64, cn=0) at fight.c:446
446 int dam = number_range(getMinDam(ch),
getMaxDam(ch)+((ch->attackFeat[cn]/5)*number_range(1,2)));
(gdb)
getMaxDam (ch=0xf6e7d870) at fight.c:88
88 }
(gdb)
number_range (from=1, to=2) at db.c:3061
3061 if (from == 0 && to == 0)
(gdb)
3064 if ((to = to - from + 1) <= 1)
(gdb)
3067 for (power = 2; power < to; power <<= 1);
(gdb)
3069 while ((number = number_mm () & (power - 1)) >= to);
(gdb)
number_mm () at db.c:3172
3172 return random () >> 6;
(gdb)
3174 }
(gdb)
number_range (from=1, to=2) at db.c:3071
3071 return from + number;
(gdb)
3072 }
(gdb)
getMinDam (ch=0xf6e7d870) at fight.c:84
84 }
(gdb)
number_range (from=6, to=36) at db.c:3061
3061 if (from == 0 && to == 0)
(gdb)
3064 if ((to = to - from + 1) <= 1)
(gdb)
3067 for (power = 2; power < to; power <<= 1);
(gdb)
3069 while ((number = number_mm () & (power - 1)) >= to);
(gdb)
number_mm () at db.c:3172
3172 return random () >> 6;
(gdb)
3174 }
(gdb)
number_range (from=6, to=31) at db.c:3071
3071 return from + number;
(gdb)
3072 }
(gdb)
cbtSlash (pCbt=0xf6e87b64, cn=0) at fight.c:447
447 delayChar(attackTable[cn].baseDelay, ch, cn);
(gdb)
delayChar (delay=2, ch=0xf6e7d870, cn=0) at fight.c:243
243 }
(gdb)
cbtSlash (pCbt=0xf6e87b64, cn=0) at fight.c:448
448 damageMsg(pCbt, dam, cn);
(gdb) p pCbt->victim->name
$2 = 0xf6e7e718 "Darien"
(gdb) step
damageMsg (pCbt=0xf6e87b64, dam=9, cn=0) at fight.c:259
259 if(!IS_NPC(pCbt->attacker))
(gdb)
260 sendDamMsg(pCbt->attacker->pcdata->cbtYourHit,
pCbt, pCbt->attacker,cn, dam);
(gdb)
sendDamMsg (string=0xf6e7e648 "Your $a does $d damage to $N. [ $y ]",
pCbt=0xf6e87b64, to=0xf6e7d870, cn=0, dam=9) at fight.c:320
/* There's a huge chunk outta here that just formats
sendDamMsg, horribly redundant */
send_to_char (
txt=0xf6e81b32 "Davion's slash does 9 damage to
you!\n\r\n\r0;36m<200hp 100m 100mv> \033[0mÿùe]\033[0m\n\r Goblin
Head\n\r\n\r\033[0;36m<200hp 100m 100mv>
\033[0mÿù0;35mr\033[0;36mt\033[0;35ma\033[0;31ml\033[0;34ms\033[0;37m---->\033[0m:\n\rDarien
\n\r\n\r\n\r"..., ch=0xf6e8232c) at comm.c:1930
1930 }
(gdb)
1933 }
(gdb)
sendDamMsg (string=0xf6e83144 "", pCbt=0xf6e87b64, to=0xf6e8232c, cn=0, dam=9)
at fight.c:368
368 }
(gdb)
damageMsg (pCbt=0xf6e87b64, dam=9, cn=0) at fight.c:263
263 for(to = pCbt->attacker->in_room->people; to ; to =
to->next_in_room)
(gdb)
264 if(!IS_NPC(to) && to != pCbt->attacker && to
!= pCbt->victim)
(gdb)
263 for(to = pCbt->attacker->in_room->people; to ; to =
to->next_in_room)
(gdb)
264 if(!IS_NPC(to) && to != pCbt->attacker && to
!= pCbt->victim)
(gdb)
263 for(to = pCbt->attacker->in_room->people; to ; to =
to->next_in_room)
(gdb)
266 damage(pCbt->attacker, pCbt->victim, dam, cn, pCbt);
(gdb)
damage (ch=0xf6e7d870, victim=0xf6e8232c, dam=9, cn=0, pCbt=0xf6e87b64)
at fight.c:273
273 victim->hit -= dam;
(gdb) p pCbt->victim->name
$3 = 0xf6e7e718 "Darien"
(gdb) step
274 if(victim->hit < 0 )
(gdb)
280 if(!victim->attacking)
(gdb)
281 { initCombat(victim, ch);
(gdb)
Breakpoint 1, initCombat (attacker=0xf6e8232c, victim=0xf6e7d870)
at fight.c:223
223 for(pCbt = attacker->attacking ; pCbt ; pCbt = pCbt->next )
(gdb)
226 pCbt = newCombat();
(gdb)
newCombat () at fight.c:178
178 if(!combatFree)
(gdb)
179 pCbt = alloc_perm(sizeof(pCbt));
(gdb)
alloc_perm (sMem=4) at db.c:2758
2758 while (sMem % sizeof (long) != 0)
(gdb)
2760 if (sMem > MAX_PERM_BLOCK)
(gdb)
2766 if (pMemPerm == NULL || iMemPerm + sMem > MAX_PERM_BLOCK)
(gdb)
2776 pMem = pMemPerm + iMemPerm;
(gdb)
2777 iMemPerm += sMem;
(gdb)
2778 nAllocPerm += 1;
(gdb)
2779 sAllocPerm += sMem;
(gdb)
2781 }
(gdb)
newCombat () at fight.c:184
184 *pCbt = combat;
(gdb)
185 pCbt->next = NULL;
(gdb)
186 pCbt->cnext = NULL;
(gdb)
187 pCbt->attacker = NULL;
(gdb)
188 pCbt->victim = NULL;
(gdb)
189 pCbt->valid = TRUE;
(gdb)
190 return pCbt;
(gdb)
191 }
(gdb) p pCbt
$4 = (struct combatData *) 0xf6e87b68
(gdb) p pCbt->victim->name
Cannot access memory at address 0x4c
(gdb) p pCbt->attacher->name
There is no member named attacher.
(gdb) p pCbt->attacking->name
There is no member named attacking.
(gdb) p pCbt->attacking
There is no member named attacking.
(gdb) step
initCombat (attacker=0xf6e8232c, victim=0xf6e7d870) at fight.c:227
227 pCbt->damage = 0;
(gdb) p pCbt->attacker
$5 = (struct char_data *) 0x0
(gdb) p pCbt->victim
$6 = (struct char_data *) 0x0
(gdb) step
228 pCbt->taken = 0;
(gdb)
229 pCbt->next = attacker->attacking;
(gdb)
230 attacker->attacking = pCbt;
(gdb)
231 pCbt->cnext = combatList;
(gdb)
232 combatList = pCbt;
(gdb)
233 pCbt->attacker = attacker;
(gdb) p pCbt->attacker->name
Cannot access memory at address 0x4c
(gdb) p attacker->name
$7 = 0xf6e7e718 "Darien"
(gdb) step
234 pCbt->victim = victim;
(gdb) p pCbt->attacker->name
$8 = 0xf6e7e718 "Darien"
(gdb) step
235 resetTimeout(pCbt);
(gdb) step
resetTimeout (pCbt=0xf6e87b68) at fight.c:76
76 }
(gdb) step
initCombat (attacker=0xf6e8232c, victim=0xf6e7d870) at fight.c:236
236 pCbt->active = TRUE;
(gdb)
238 }
(gdb)
damage (ch=0xf6e7d870, victim=0xf6e8232c, dam=9, cn=0, pCbt=0xf6e87b64)
at fight.c:282
282 delayChar(2.0f, victim, 0);
(gdb)
delayChar (delay=2, ch=0xf6e8232c, cn=0) at fight.c:243
243 }
(gdb)
damage (ch=0xf6e7d870, victim=0xf6e8232c, dam=9, cn=0, pCbt=0xf6e87b64)
at fight.c:283
283 return;
(gdb)
296 }
(gdb)
damageMsg (pCbt=0xf6e87b64, dam=9, cn=0) at fight.c:268
268 }
(gdb)
cbtSlash (pCbt=0xf6e87b64, cn=0) at fight.c:449
449 resetTimeout(pCbt);
(gdb) p pCbt->attacker->name
$9 = 0xf6e7e528 "Davion"
(gdb) p pCbt->victim->name
$10 = 0x0
(gdb) p pCbt->victim
$11 = (struct char_data *) 0xf6e87b64
Any help very muchly apreciated.
Davion