06 Jan, 2009, seabast wrote in the 1st comment:
Votes: 0
Hello for some reason I crash when i drop/eat/purge any crafted items and I'm not sure why….been looking at it for hours thought maybe someone here could help me out.


void do_craft (CHAR_DATA *ch, char *argument)
{
OBJ_DATA *chunk;
OBJ_DATA *item;
int ore_weight = 0;
int typ;
int ore;
char buf[MSL];
char arg1[MSL];
char arg2[MSL];
bool excess = FALSE;
int percent;
int chance = number_percent();

struct forge_type
{
char * name;
sh_int type;
int wear_loc;
sh_int weap_typ;
int ore_min;
};


static const struct forge_type forge_table[] = {
{ "breastplate", ITEM_ARMOR, ITEM_WEAR_BODY, 0, 20 },
{ "gauntlets", ITEM_ARMOR, ITEM_WEAR_HANDS, 0, 10 },
{ "boots", ITEM_ARMOR, ITEM_WEAR_FEET, 0, 10 },
{ "bracer", ITEM_ARMOR, ITEM_WEAR_WRIST, 0, 5 },
{ "sleeves", ITEM_ARMOR, ITEM_WEAR_ARMS, 0, 10 },
{ "shield", ITEM_ARMOR, ITEM_WEAR_OFFHAND, 0, 15 },
{ "leggings", ITEM_ARMOR, ITEM_WEAR_LEGS, 0, 15 },
{ "ring", ITEM_ARMOR, ITEM_WEAR_FINGER, 0, 3 },
{ "helmet", ITEM_ARMOR, ITEM_WEAR_HEAD, 0, 8 },
{ "sword", ITEM_WEAPON, ITEM_WIELD, WEAPON_SWORD, 10 },
{ "dagger", ITEM_WEAPON, ITEM_WIELD, WEAPON_DAGGER, 5 },
{ "spear", ITEM_WEAPON, ITEM_WIELD, WEAPON_SPEAR, 5 },
{ "mace", ITEM_WEAPON, ITEM_WIELD, WEAPON_MACE, 8 },
{ "axe", ITEM_WEAPON, ITEM_WIELD, WEAPON_AXE, 12 },
{ "flail", ITEM_WEAPON, ITEM_WIELD, WEAPON_FLAIL, 12 },
{ "polearm", ITEM_WEAPON, ITEM_WIELD, WEAPON_POLEARM, 15 },
{ NULL, 0, 0, 0, 0 }
};

if ((percent = get_skill (ch, skill_lookup ("craft"))) <= 1)
{
send_to_char ("You might hurt yourself!\n\r", ch);
return;
}

if (argument[0] == '\0')
{
send_to_char ("Syntax: craft <item type> <mineral type>.\n\r", ch);
return;
}

argument = one_argument (argument, arg1);
argument = one_argument (argument, arg2);

/* Validate arg1 first */

for (typ = 0; forge_table[typ].name != NULL; typ++)
{
if (!str_cmp (arg1, forge_table[typ].name))
break;
}

if (forge_table[typ].name == NULL)
{
int col = 0;

send_to_char ("Invalid item, available choices are:\n\r\n\r", ch);

for (typ = 0; forge_table[typ].name != NULL; typ++)
{
sprintf (buf, "%s ", forge_table[typ].name);
send_to_char (buf, ch);

if (++col == 6)
{
send_to_char ("\n\r", ch);
col = 0;
}
}

send_to_char ("\n\r", ch);

return;
}

/* Validate arg2 */

for (ore = 0; mineral_table[ore].name != NULL; ore++)
{
if (!str_cmp (arg2, mineral_table[ore].name))
break;
}

if (mineral_table[ore].name == NULL)
{
send_to_char ("That is not a craftable material.\n\r", ch);
return;
}

for (chunk = ch->carrying; chunk != NULL; chunk = chunk->next)
{

if (chunk->item_type != ITEM_ORE)
continue;


if (ore == chunk->value[0])
ore_weight += chunk->weight;
}

if (ore_weight < forge_table[typ].ore_min)
{
sprintf (buf, "You lack the %s to craft a %s.\n\r", mineral_table[ore].name, forge_table[typ].name);
send_to_char (buf, ch);
return;
}

/* Now that we've determined we have enough, extract the ore… */

ore_weight = 0;

for (chunk = ch->carrying; chunk != NULL; chunk = chunk->next)
{
if (chunk->item_type != ITEM_ORE)
continue;

if (ore == chunk->value[0])
{
ore_weight += chunk->weight;
extract_obj (chunk);
}

if (ore_weight >= forge_table[typ].ore_min)
{
if (ore_weight > forge_table[typ].ore_min) /* No wastage! */
{
OBJ_DATA *left;
int leftover;

leftover = ore_weight - forge_table[typ].ore_min;

left = create_object (get_obj_index (OBJ_VNUM_ORE), 0);
free_string (left->name);
free_string (left->short_descr);
free_string (left->description);
sprintf (buf, "chunk ore %s", mineral_table[ore].name);
left->name = str_dup (buf);
sprintf (buf, "a chunk of %s", mineral_table[ore].name);
left->short_descr = str_dup (buf);
sprintf (buf, "A chunk of %s sits here.", mineral_table[ore].name);
left->description = str_dup (buf);
left->item_type = ITEM_ORE;
left->value[0] = ore;
left->weight = leftover;

obj_to_char (left, ch);
excess = TRUE;
}
break;
}
}

/* Now the REAL fun begins */

sprintf (buf, "You begin to craft the %s.\n\r", forge_table[typ].name);
act (buf, ch, NULL, NULL, TO_CHAR );
act ("$n begins to craft something.", ch, NULL, NULL, TO_ROOM);

if (percent < chance - 40) /* Kablooey! */
{
send_to_char ("The forge blows up in your face!\n\r", ch);
spell_fireball(skill_lookup("fireball"), 200, ch,NULL,TARGET_CHAR);
return;
}

act ("You continue to hammer away at your creation…", ch, NULL, NULL, TO_CHAR );
act ("$n hammers away.", ch, NULL, NULL, TO_ROOM);

if (percent < chance - 30) /* Not quite… */
{
send_to_char ("Your hammer strike splits your piece in two!\n\r", ch);
return;
}

sprintf (buf, "The %s is now taking shape…", forge_table[typ].name);
act (buf, ch, NULL, NULL, TO_CHAR );
act ("$n continues to work.", ch, NULL, NULL, TO_ROOM);

if (percent < chance - 20) /* Oops… */
{
sprintf (buf, "The %s appears to be too flimsy to use.", forge_table[typ].name);
send_to_char (buf, ch);
send_to_char ("Frustratedly, you discard the piece.\n\r", ch);
return;
}

sprintf (buf, "You put the final touches on the %s…", forge_table[typ].name);
act (buf, ch, NULL, NULL, TO_CHAR );
act ("$n continues to work.", ch, NULL, NULL, TO_ROOM);

if (percent < chance - 10) /* No Cigar */
{
sprintf (buf, "You slip and damage the %s beyond repair!", forge_table[typ].name);
send_to_char (buf, ch);
send_to_char ("Frustratedly, you discard the piece.\n\r", ch);
return;
}

/* Good job! */
sprintf(buf, "%s\n\r", chunk->short_descr);
send_to_char (buf, ch);

item = create_object (get_obj_index (OBJ_VNUM_BLANK), 0);

free_string (item->name);
free_string (item->short_descr);
free_string (item->description);

sprintf (buf, "%s %s %s", forge_table[typ].name, mineral_table[ore].name, ch->name);

item->name = str_dup (buf);

switch (forge_table[typ].wear_loc)
{
case ITEM_WEAR_LEGS:
case ITEM_WEAR_FEET:
case ITEM_WEAR_HANDS:
case ITEM_WEAR_ARMS:
{
sprintf(buf, "(%s Crafted) pair of %s %s", ch->name,mineral_table[ore].name, forge_table[typ].name);
item->short_descr = str_dup (buf);
sprintf(buf, "A pair of %s %s lies here.", mineral_table[ore].name, forge_table[typ].name);
item->description = str_dup (buf);

break;
}

default:
{
const char *article;

if (mineral_table[ore].name[0] == 'a' ||
mineral_table[ore].name[0] == 'e' ||
mineral_table[ore].name[0] == 'i' ||
mineral_table[ore].name[0] == 'o' ||
mineral_table[ore].name[0] == 'u')
article = "an";
else
article = "a";

sprintf (buf, "(%s Crafted)%s %s %s", ch->name, article, mineral_table[ore].name, forge_table[typ].name);
item->short_descr = str_dup (buf);
sprintf (buf, "%s %s %s lies here.", capitalize(article), mineral_table[ore].name, forge_table[typ].name);
item->description = str_dup (buf);
break;
}
}

item->item_type = forge_table[typ].type;
TOGGLE_BIT (item->wear_flags, forge_table[typ].wear_loc);

switch (item->item_type)
{
case ITEM_ARMOR:
{
int number;

number = UMAX(20, ch->level);

item->value[0] = number;
item->value[1] = number;
item->value[2] = number;
item->value[3] = (5 * UMAX(20, ch->level)) / 6;

break;
}

case ITEM_WEAPON:
{

item->value[0] = forge_table[typ].weap_typ;
item->value[1] = UMAX (15, (ch->level + 20) / 5);
item->value[2] = ch->level < 80 ? 4 : 5;

switch (item->value[0])
{
case WEAPON_SWORD:
item->value[3] = attack_lookup ("slash");
break;
case WEAPON_DAGGER:
case WEAPON_SPEAR:
item->value[3] = attack_lookup ("stab");
break;
case WEAPON_MACE:
case WEAPON_FLAIL:
case WEAPON_POLEARM:
item->value[3] = attack_lookup ("pound");
break;
case WEAPON_AXE:
item->value[3] = attack_lookup ("chop");
break;
default:
item->value[3] = attack_lookup ("blast");
break;
}

break;
}
default:
return;
}
item->material = mineral_table[ore].name;
sprintf (buf, "You have successfully forged %s!\n\r", item->short_descr);
send_to_char (buf, ch);
sprintf (buf, "$n has successfully forged %s!\n\r", item->short_descr);
act (buf, ch, NULL, NULL, TO_ROOM);
obj_to_char (item, ch);

if (excess)
{
sprintf (buf, "You managed to save some %s.\n\r", mineral_table[ore].name);
send_to_char (buf, ch);
}
save_char_obj( ch );
return;
}
06 Jan, 2009, David Haley wrote in the 2nd comment:
Votes: 0
You should run it through gdb to figure out where it's crashing and what the relevant variable values are at that point.
0.0/2