Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Swr 1.0 - Calculate function

Swr 1.0 - Calculate function

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Nick Cash   USA  (626 posts)  Bio
Date Tue 14 Jan 2003 10:13 PM (UTC)
Message
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.

~Nick Cash
http://www.nick-cash.com
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #1 on Tue 14 Jan 2003 10:14 PM (UTC)

Amended on Tue 14 Jan 2003 10:29 PM (UTC) by Nick Cash

Message
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...

~Nick Cash
http://www.nick-cash.com
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #2 on Tue 14 Jan 2003 10:15 PM (UTC)
Message
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 );
}

~Nick Cash
http://www.nick-cash.com
Top

Posted by Boborak   USA  (228 posts)  Bio
Date Reply #3 on Tue 14 Jan 2003 10:40 PM (UTC)
Message
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
}
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #4 on Tue 14 Jan 2003 10:50 PM (UTC)
Message
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.

~Nick Cash
http://www.nick-cash.com
Top

Posted by Boborak   USA  (228 posts)  Bio
Date Reply #5 on Tue 14 Jan 2003 10:53 PM (UTC)
Message
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
Top

Posted by Boborak   USA  (228 posts)  Bio
Date Reply #6 on Tue 14 Jan 2003 10:56 PM (UTC)
Message
doh! nm.. I see the problem, one second. check your assignments.. i.e. argument, arg3, ect.
Top

Posted by Boborak   USA  (228 posts)  Bio
Date Reply #7 on Tue 14 Jan 2003 10:59 PM (UTC)
Message
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 ;-)
Top

Posted by Nick Cash   USA  (626 posts)  Bio
Date Reply #8 on Tue 14 Jan 2003 11:04 PM (UTC)
Message
Thanks! It works perfectly. Its exactly what I needed. Thanks again and again. :)

~Nick Cash
http://www.nick-cash.com
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


18,728 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.