//This should be at top of code
bool found = FALSE; // if there is no coal found, the found variable will default to false and notify the player there is no coal in his/her inventory.
char arg1[MIL];
char arg2[MIL];
argument = one_argument(argument, arg1); // This is for the all and all. arguments
argument = one_argument(argument, arg2); // This is for the container, the furnace argument
//assuming you've got some checks in here for syntax safeguards to check if arg1[0] == '\0' or arg2[0] == '\0', etc
if ((container = get_obj_here(ch, NULL, arg2)) == NULL) { // Check to see if there is a container in the room
act_new("You see no $T here.", ch, NULL, arg2, TO_CHAR, POS_RESTING);
return;
}
if (container->item_type != ITEM_FURNACE) { // Check here so there is no need to check in the loop if the container is a furnace or not
send_to_char("That's not a furnace.\n\r", ch);
return;
}
if (!str_cmp(arg1, "all" ) || !str_prefix(arg1, "all.")) { // Checks if player enters "all" -or- "all." as the prefix to a string
for (obj = ch->carrying; obj != NULL; obj = obj_next) { // Need to add a loop because you're not just looking at one object, but all in inv
obj_next = obj->next_content;
if ((arg1[3] == '\0' || is_name(&arg1[4], obj->name)) { // Checks if player entered "all", if so all items are looked at OR
// if player entered "all.", then the 5th letter and beyond of all.<whatever> is
// compared with object name.
if ( obj == container ) {
send_to_char( "You can't fold it into itself.\r\n", ch );
continue; // Do NOT return;, a return will exit the loop AND the function. A continue will return to the top of the loop & continue on
}
if ( obj->item_type == ITEM_COALSEAM) {
obj_from_char(obj); // Take the obj from player
obj_to_obj(obj, container); // Place it in furnace
// Put some message here notifying player that object is now in furnace something like:
sprintf (buf, "You put %s in %s.\n\r", obj->short_descr, obj->short_descr);
send_to_char (buf, ch);
found = TRUE; // Added this so if no coal is found, you can notify player at bottom of function.
} else
continue; // Skip back to top of loop if obj has a different item type other than coal
}
}
if (!found) // No coal was found, so notify the player
send_to_char ("You don't have any coal.\n\r",ch);
bool str_cmp(const char *astr, const char *bstr) {
if (astr == NULL) {
dbbug("Str_cmp: null astr.", 0);
return TRUE;
}
if (bstr == NULL) {
dbbug("Str_cmp: null bstr.", 0);
return TRUE;
}
for (; *astr || *bstr; astr++, bstr++) {
if (LOWER(*astr) != LOWER(*bstr))
return TRUE;
}
return FALSE;
}
/* returns: 0 if equal, 1 if arg1 > arg2, -1 if arg1 < arg2 */
/* scan 'till found different or end of both */
int str_cmp(char *arg1, char *arg2)
{
int chk, i;
for (i = 0; *(arg1 + i) || *(arg2 + i); i++)
if (chk = LOWER(*(arg1 + i)) - LOWER(*(arg2 + i)))
if (chk < 0)
return (-1);
else
return (1);
return(0);
}
if (container->item_type == ITEM_FURNACE){
if ( obj->item_type != ITEM_COALSEAM)
{
send_to_char ("You can only put coal or wood in a furnace.",ch);
return;
}
}
if ( str_cmp( arg1, "all" ) && str_prefix( "all.", arg1 ) )
{
if ( ( obj = get_obj_carry( ch, arg1, ch ) ) == NULL )
{
send_to_char( "You do not have that item.\r\n", ch );
return;
}
if ( obj == container )
{
send_to_char( "You can't fold it into itself.\r\n", ch );
return;
}
if (container->item_type == ITEM_FURNACE){
if ( obj->item_type != ITEM_COALSEAM)
{
send_to_char ("You can only put coal or wood in a furnace.",ch);
return;
}
}
if ( ( arg1[3] == '\0' || is_name( &arg1[4], obj->name ) )
&& can_see_obj( ch, obj )
&& WEIGHT_MULT(obj) == 100
&& obj->wear_loc == WEAR_NONE
&& obj != container
&& can_drop_obj( ch, obj )
&& get_obj_weight( obj ) + get_true_weight( container )
<= (container->value[0] * 10)
&& get_obj_weight(obj) < (container->value[3] * 10))
{
if ( ( arg1[3] == '\0' || is_name( &arg1[4], obj->name ) )
&& can_see_obj( ch, obj )
&& WEIGHT_MULT(obj) == 100
&& obj->wear_loc == WEAR_NONE
&& obj != container
&& can_drop_obj( ch, obj )
&& get_obj_weight( obj ) + get_true_weight( container )
<= (container->value[0] * 10)
&& get_obj_weight(obj) < (container->value[3] * 10)
&& (container->item_type != ITEM_FURNACE || obj->item_type == ITEM_COALSEAM))
{
/* returns: 0 if equal, 1 if arg1 > arg2, -1 if arg1 < arg2 */
/* scan 'till found different or end of both */
int str_cmp(char *arg1, char *arg2)
{
int chk, i;
for (i = 0; *(arg1 + i) || *(arg2 + i); i++)
if (chk = LOWER(*(arg1 + i)) - LOWER(*(arg2 + i)))
if (chk < 0)
return (-1);
else
return (1);
return(0);
}
*(ch + i) == *(i + ch) == ch[i] == i[ch]
Well, I went back to the "all" and "all." portion and added this
Again, I figured adding this would stop the put all furnace from allowing anything other than coal to be put in it. Can anyone see where I am going wrong here? I've also tried bracketing differently, running the if check slightly different using
if (container->item_type == ITEM_FURNACE && obj->item_type != ITEM_COALSEAM). This also works but goes back to the top as I said first. It works with put ANYTHING ELSE furnace and prints You can only put coal or wood in a furnace. However, it's just the put all portion that isn't working properly.
IE.
put all.ore furnace
You put a copper ore in a furnace.
You put a copper ore in a furnace.
put ore furnace
You can only put coal or wood in a furnace.
Edit by Kiasyn: code tags