alrighty, here is the indented code:
void do_refuel(CHAR_DATA *ch, char *argument )
{
SHIP_DATA *ship;
OBJ_DATA *obj;
char arg1[MAX_INPUT_LENGTH];
char arg2[MAX_INPUT_LENGTH];
bool station = FALSE;
bool hascan = FALSE;
int gascan = 0;
int totalneed = 0;
int totalfill = 0;
argument = one_argument( argument, arg1 );
argument = one_argument( argument, arg2 );
ship = ship_in_room( ch->in_room , arg1 );
if ( arg1[0] == '\0' )
{
send_to_char("Usage: refuel <vehicle> <gas can>\n\r",ch);
send_to_char("If you are in a gas station, the gas can is optional.\n\r",ch);
return;
}
if ( !ship )
{
act( AT_PLAIN, "I see no $T here.", ch, NULL, arg1, TO_CHAR );
return;
}
if ( ship->energy == ship->maxenergy )
{
send_to_char("Your gas tank is already full!\n\r",ch);
return;
}
if ( !IS_SET( ch->in_room->room_flags, ROOM_GAS_STATION ) && ( arg2[0] == '\0' ) )
{
send_to_char( "You're not in a gas station.\n\r", ch );
return;
}
if ( IS_SET( ch->in_room->room_flags, ROOM_GAS_STATION ) )
station = TRUE;
if ( arg2[0] != '\0' )
{
if ( ms_find_obj(ch) )
return;
if ( ( obj = get_obj_carry( ch, arg2 ) ) == NULL )
{
send_to_char( "You do not have that item.\n\r", ch );
return;
}
}
if ( obj->item_type != ITEM_FUEL )
{
send_to_char("That is not a can of gas.\n\r",ch);
return;
}
if ( obj->item_type == ITEM_FUEL )
{
hascan = TRUE;
if ( obj->value[3] == 0 )
{
send_to_char("The can is empty.\n\r",ch);
return;
}
gascan = obj->value[3];
totalneed = ( ship->maxenergy - ship->energy );
if ( gascan <= totalneed )
{
totalfill = gascan;
send_to_char("You put gas in the tank, emptying the can.\n\r",ch);
}
if ( gascan > totalneed )
{
totalfill = ( gascan - ( gascan - totalneed ) );
send_to_char("You fill the tank, leaving some gas in the can.\n\r",ch);
}
obj->value[3] = ( obj->value[3] - totalfill );
ship->energy = ( ship->energy + totalfill );
}
if ( station && !hascan )
{
send_to_char("You grab the hose and start filling your tank.\n\r",ch);
act( AT_PLAIN, "$n takes the hose and begins filling their tank.", ch, NULL, argument , TO_ROOM );
ship->energy = ship->maxenergy;
send_to_char("You finish filling the tank.\n\r",ch);
act( AT_PLAIN, "$n finishes filling their tank.", ch, NULL, argument , TO_ROOM );
return;
}
return;
}
And here is the stackdump the segmentation fault produces in swreality.exe.stackdump:
Exception: STATUS_ACCESS_VIOLATION at eip=004F1FFD
eax=00000004 ebx=00000004 ecx=1008EB00 edx=1008EB00 esi=610EF060 edi=61005A9C
ebp=0022DF58 esp=0022D710 program=C:\cygwin\home\jim\pmud\src\swreality.exe, pid 1188, thread main
cs=001B ds=0023 es=0023 fs=0038 gs=0000 ss=0023
Stack trace:
Frame Function Args
0022DF58 004F1FFD (1008FF38, 0022EC2B, 10089698, 0022E3C0)
0022EBC8 0047DF54 (1008FF38, 0022EC27, 0022EB44, 0022EB44)
0022F038 004544C8 (00566160, 00000000, 00000066, 6109106A)
0022F068 00453A29 (00000002, 617842C8, 100100A8, 0022F0C0)
0022F0A8 61005F34 (0022F0C0, 00000000, 00000000, 00000000)
0022FF88 6100614B (00000000, 00000000, 00000000, 00000000)
End of stack trace
It generates this segment fault when you type refuel <vehicle> and you are in the gas station with the vehicle, otherwise the if statements catch and it sends the correct message.
I've managed to target one part of the code. It will successfully execute all the code except for this part:
if ( station && !hascan )
{
send_to_char("You grab the hose and start filling your tank.\n\r",ch);
act( AT_PLAIN, "$n takes the hose and begins filling their tank.", ch, NULL, argument , TO_ROOM );
ship->energy = ship->maxenergy;
send_to_char("You finish filling the tank.\n\r",ch);
act( AT_PLAIN, "$n finishes filling their tank.", ch, NULL, argument , TO_ROOM );
return;
}
So it has to do with either the code itself or the if statement, because it's the only part that doesn't work. but I could be wrong, what do you think?
-Kronos |