Swr 1.0 - Calculate function

Posted by Nick Cash on Tue 14 Jan 2003 10:13 PM — 9 posts, 26,072 views.

USA #0
I was trying to make it so you couldn't get to a differen't starsystem in my MUD. I added a password thing and that all works right, but I'm doing something wrong with the code. I've tried using str_cmp to compare arg4 to starsystem->password, but I don't know. I guess I'm doing something wrong. I'll post the code in the next post since it is larger than 6000 characters otherwise. Thanks for any and all help in solving this problem.
USA #1
void do_calculate(CHAR_DATA *ch, char *argument )
{
char arg1[MAX_INPUT_LENGTH];
char arg2[MAX_INPUT_LENGTH];
char arg3[MAX_INPUT_LENGTH];
char arg4[MAX_INPUT_LENGTH];
int chance , count;
SHIP_DATA *ship;
SPACE_DATA *starsystem;

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


if ( (ship = ship_from_cockpit(ch->in_room->vnum)) == NULL )
{
send_to_char("&RYou must be in the cockpit of a ship to do that!\n\r",ch);
return;
}

if ( ship->class > SHIP_PLATFORM )
{
send_to_char("&RThis isn't a spacecraft!\n\r",ch);
return;
}

if ( (ship = ship_from_navseat(ch->in_room->vnum)) == NULL )
{
send_to_char("&RYou must be at a nav computer to calculate jumps.\n\r",ch);
return;
}

if ( autofly(ship) )
{
send_to_char("&RYou'll have to turn off the ships autopilot first....\n\r",ch);
return;
}

if ( ship->class == SHIP_PLATFORM )
{
send_to_char( "&RAnd what exactly are you going to calculate...?\n\r" , ch );
return;
}
if (ship->hyperspeed == 0)
{
send_to_char("&RThis ship is not equipped with a hyperdrive!\n\r",ch);
return;
}
if (ship->shipstate == SHIP_DOCKED)
{
send_to_char("&RYou can't do that until after you've launched!\n\r",ch);
return;
}
if (ship->starsystem == NULL)
{
send_to_char("&RYou can only do that in realspace.\n\r",ch);
return;
}
if (argument[0] == '\0')
{
send_to_char("&WFormat: Calculate <starsystem> <entry x> <entry y> <entry z> <password>\n\r&wPossible destinations:\n\r",ch);
for ( starsystem = first_starsystem; starsystem; starsystem = starsystem->next )
{
set_char_color( AT_NOTE, ch );
ch_printf(ch,"%-30s %d\n\r",starsystem->name,
(abs(starsystem->xpos - ship->starsystem->xpos)+
abs(starsystem->ypos - ship->starsystem->ypos))/2);
count++;
}
if ( !count )
{
send_to_char( "No Starsystems found.\n\r", ch );
}
return;
}
chance = IS_NPC(ch) ? ch->top_level
: (int) (ch->pcdata->learned[gsn_navigation]) ;
if ( number_percent( ) > chance )
{
send_to_char("&RYou cant seem to figure the charts out today.\n\r",ch);
learn_from_failure( ch, gsn_navigation );
return;
}


ship->currjump = starsystem_from_name( arg1 );
ship->jx = atoi(arg2);
ship->jy = atoi(arg3);
ship->jz = atoi(argument);

starsystem = ship->currjump;

if ( arg4 != starsystem->password)
{
send_to_char( "&RPassword Denied.\n\r", ch);
return;
}

if ( ship->currjump == NULL )
{
send_to_char( "&RYou can't seem to find that starsytem on your charts.\n\r", ch);
return;
}

Note: Needs two posts for this code...
Amended on Tue 14 Jan 2003 10:29 PM by Nick Cash
USA #2
Rest of the code starting where the previous code left off..


else
{
SPACE_DATA * starsystem;

starsystem = ship->currjump;

if ( starsystem->star1 && strcmp(starsystem->star1,"") &&
abs(ship->jx - starsystem->s1x) < 300 &&
abs(ship->jy - starsystem->s1y) < 300 &&
abs(ship->jz - starsystem->s1z) < 300 )
{
echo_to_cockpit( AT_RED, ship, "WARNING.. Jump coordinates too close to stellar object.");
echo_to_cockpit( AT_RED, ship, "WARNING.. Hyperjump NOT set.");
ship->currjump = NULL;
return;
}
else if ( starsystem->star2 && strcmp(starsystem->star2,"") &&
abs(ship->jx - starsystem->s2x) < 300 &&
abs(ship->jy - starsystem->s2y) < 300 &&
abs(ship->jz - starsystem->s2z) < 300 )
{
echo_to_cockpit( AT_RED, ship, "WARNING.. Jump coordinates too close to stellar object.");
echo_to_cockpit( AT_RED, ship, "WARNING.. Hyperjump NOT set.");
ship->currjump = NULL;
return;
}
else if ( starsystem->planet1 && strcmp(starsystem->planet1,"") &&
abs(ship->jx - starsystem->p1x) < 300 &&
abs(ship->jy - starsystem->p1y) < 300 &&
abs(ship->jz - starsystem->p1z) < 300 )
{
echo_to_cockpit( AT_RED, ship, "WARNING.. Jump coordinates too close to stellar object.");
echo_to_cockpit( AT_RED, ship, "WARNING.. Hyperjump NOT set.");
ship->currjump = NULL;
return;
}
else if ( starsystem->planet2 && strcmp(starsystem->planet2,"") &&
abs(ship->jx - starsystem->p2x) < 300 &&
abs(ship->jy - starsystem->p2y) < 300 &&
abs(ship->jz - starsystem->p2z) < 300 )
{
echo_to_cockpit( AT_RED, ship, "WARNING.. Jump coordinates too close to stellar object.");
echo_to_cockpit( AT_RED, ship, "WARNING.. Hyperjump NOT set.");
ship->currjump = NULL;
return;
}
else if ( starsystem->planet3 && strcmp(starsystem->planet3,"") &&
abs(ship->jx - starsystem->p3x) < 300 &&
abs(ship->jy - starsystem->p3y) < 300 &&
abs(ship->jz - starsystem->p3z) < 300 )
{
echo_to_cockpit( AT_RED, ship, "WARNING.. Jump coordinates too close to stellar object.");
echo_to_cockpit( AT_RED, ship, "WARNING.. Hyperjump NOT set.");
ship->currjump = NULL;
return;
}
else
{
ship->jx += number_range ( -250 , 250 );
ship->jy += number_range ( -250 , 250 );
ship->jz += number_range ( -250 , 250 );
}
}

ship->hyperdistance = abs(ship->starsystem->xpos - ship->currjump->xpos) ;
ship->hyperdistance += abs(ship->starsystem->ypos - ship->currjump->ypos) ;
ship->hyperdistance /= 5;

if (ship->hyperdistance<100)
ship->hyperdistance = 100;

ship->hyperdistance += number_range(0, 200);

sound_to_room( ch->in_room , "!!SOUND(computer)" );

send_to_char( "&GHyperspace course set. Ready for the jump to hyperspace.\n\r", ch);
act( AT_PLAIN, "$n does some calculations using the ships computer.", ch,
NULL, argument , TO_ROOM );

learn_from_success( ch, gsn_navigation );

WAIT_STATE( ch , 2*PULSE_VIOLENCE );
}
USA #3
I would assume the password is an integer?

if that's the case, you would need a

pass = atoi(arg4);

before your comparison, then do your

if (pass == ship->password)
{
//password is good
}

if your password is a string.. instead do a..

if(!str_cmp(arg4, ship->password))
{
//password is good
}
USA #4
I tried that, it didn't work again. It compiles alright but on the MUD it just keeps saying Permission Denied, even when you have the right password in. By the way the password is a string. What I need is for it to say if the password is wrong, but if it is right then it just keeps going and continues along with the rest of if statements in the function.

Again thanks for all help.
USA #5
also if you're looking to make the password mandantory..

you would need a..

if (arg4[0] != '\0')
{
send_to_char("Please supply a password.\n\r");
return;
}

..at the begining of the function

otherwise a more complex set of checks would be needed..

if (starsystem->password && starsystem-password[0] != '\0')
{
//check for password (my previous post)
}
//else continue as normal

hope this helps or sparks an idea
USA #6
doh! nm.. I see the problem, one second. check your assignments.. i.e. argument, arg3, ect.
USA #7
ship->jz = atoi(argument);

should be..

ship->jz = atoi(arg4);

and all of your refrences to your supplied password need to be 'argument' using !str_cmp(argument, ship->password)

that should work ;-)
USA #8
Thanks! It works perfectly. Its exactly what I needed. Thanks again and again. :)