Hello again, I noticed that SWR doesn't have code in the do_refuel command, so I tried to make my own. It compiles fine, and I really don't see any problems, however it causes a segmentation fault when I execute the command. Can anybody see why it's doing this?
void do_refuel(CHAR_DATA *ch, char *argument )
{
SHIP_DATA *ship;
OBJ_INDEX_DATA *obj;
ROOM_INDEX_DATA *in_room;
bool station = FALSE;
int gascan;
int totalneed;
int totalfill;
if ( ship->energy == ship->maxenergy )
{
send_to_char("Your gas tank is already full!\n\r",ch);
return;
}
if ( !IS_SET( in_room->room_flags, ROOM_GAS_STATION ) && !obj )
{
send_to_char( "You're not in a gas station.\n\r", ch );
return;
}
if ( IS_SET( in_room->room_flags, ROOM_GAS_STATION ) )
station = TRUE;
if ( !station && !obj )
{
send_to_char("I do not see that here.\n\r",ch);
return;
}
if ( !station && obj->item_type != ITEM_FUEL )
{
send_to_char("That is not a can of gas.\n\r",ch);
return;
}
if ( !station && obj->item_type == ITEM_FUEL )
{
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 && argument == '\0' )
{
send_to_char("A gas station employee approaches the vehicle and fills the tank.\n\r",ch);
ship->energy = ship->maxenergy;
}
}
Here's the info from the stack dump.. though I don't know what help it is:
Exception: STATUS_ACCESS_VIOLATION at eip=004F1DCF
eax=00000000 ebx=00000004 ecx=0022DFA0 edx=00000000 esi=610EF060 edi=61005A9C
ebp=0022DF58 esp=0022DF30 program=C:\cygwin\home\jim\pmud\src\swreality.exe, pid 1380, thread main
cs=001B ds=0023 es=0023 fs=0038 gs=0000 ss=0023
Stack trace:
Frame Function Args
0022DF58 004F1DCF (1008FF38, 0022EC26, 10089698, 0022E3C0)
0022EBC8 0047DF54 (1008FF38, 0022EC26, 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
I'm using SWRFUSS on Cygwin in case it matters. This was done at like 1am so I apologize if any of the code seems unecessary, but I'd like to know what's causing this crash.
Thanks,
Kronos
void do_refuel(CHAR_DATA *ch, char *argument )
{
SHIP_DATA *ship;
OBJ_INDEX_DATA *obj;
ROOM_INDEX_DATA *in_room;
bool station = FALSE;
int gascan;
int totalneed;
int totalfill;
if ( ship->energy == ship->maxenergy )
{
send_to_char("Your gas tank is already full!\n\r",ch);
return;
}
if ( !IS_SET( in_room->room_flags, ROOM_GAS_STATION ) && !obj )
{
send_to_char( "You're not in a gas station.\n\r", ch );
return;
}
if ( IS_SET( in_room->room_flags, ROOM_GAS_STATION ) )
station = TRUE;
if ( !station && !obj )
{
send_to_char("I do not see that here.\n\r",ch);
return;
}
if ( !station && obj->item_type != ITEM_FUEL )
{
send_to_char("That is not a can of gas.\n\r",ch);
return;
}
if ( !station && obj->item_type == ITEM_FUEL )
{
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 && argument == '\0' )
{
send_to_char("A gas station employee approaches the vehicle and fills the tank.\n\r",ch);
ship->energy = ship->maxenergy;
}
}
Here's the info from the stack dump.. though I don't know what help it is:
Exception: STATUS_ACCESS_VIOLATION at eip=004F1DCF
eax=00000000 ebx=00000004 ecx=0022DFA0 edx=00000000 esi=610EF060 edi=61005A9C
ebp=0022DF58 esp=0022DF30 program=C:\cygwin\home\jim\pmud\src\swreality.exe, pid 1380, thread main
cs=001B ds=0023 es=0023 fs=0038 gs=0000 ss=0023
Stack trace:
Frame Function Args
0022DF58 004F1DCF (1008FF38, 0022EC26, 10089698, 0022E3C0)
0022EBC8 0047DF54 (1008FF38, 0022EC26, 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
I'm using SWRFUSS on Cygwin in case it matters. This was done at like 1am so I apologize if any of the code seems unecessary, but I'd like to know what's causing this crash.
Thanks,
Kronos