Welcome to the Builder Academy

Question relative north movement

More
20 Oct 2012 12:23 - 20 Oct 2012 20:19 #920 by wifidi
Dear tbaMUDers,
I've tried coding relative north movement without suceeding. Two versions of the idea are only north moves the character forward in the direction the character has spun to (relative north) or movement in a direction becomes relative north. Here's some basic code that experiences runtime errors:
structs.h 997:
int facing; /**< Cardinal direction of ch. */
// bool relspin; /**< Char moves forward, up, down, or spins left, right or 180. */
// bool relwalk; /**< Direction char moves becomes relative north. */

struct.h 1029:
//struct char_data = {.relspin = false, .relwalk = false};

act.h 146:
/** Relative north. */
#define FACING ((ch)->facing)
//#define RELSPIN ((ch)->relspin)
//#define RELWALK ((ch)->relwalk)

act.movement.c 31:
void player_spins_char(struct char_data *ch, int dir);

act.movement.c 114:
/* Player spins character. */
void player_spins_char(struct char_data *ch, int dir)
{
switch (dir)
{
case (EAST):
{
FACING++;
if (FACING == 4) FACING = 0;
}
case (SOUTH):
{
FACING += 2;
if (FACING == 4) FACING = 0;
if (FACING == 5) FACING = 1;
}
case (WEST):
{
FACING--;
if (FACING == -1) FACING = 3;
}
}
}

act.movement.c 163:
/* ... and the room the character will move into. */

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/* must check for relative north walking modes to properly designate
* the proposed room */

/* autoexit toggle piggybacked in lieu of PRF_RELATIVE_NORTH_WALKING_MODE_1 */
/* autoloot toggle piggybacked in lieu of PRF_RELATIVE_NORTH_WALKING_MODE_2 */

/* if using relative north, NORTH means forward */

if ((PRF_FLAGGED(ch, PRF_AUTOEXIT) || PRF_FLAGGED(ch, PRF_AUTOLOOT))
&& (dir == NORTH))
room_rnum going_to = EXIT(ch, FACING)->to_room;

/* relative north walking mode 1:
* east, west and south only spin the character */

else if (PRF_FLAGGED(ch, PRF_AUTOEXIT)
&& (dir == EAST || dir == SOUTH || dir == WEST))
{
player_spins_char(ch, dir);
return 0;
}

/* relative north walking mode 2:
* east, west and south spin and move the char in that direction, and
* that direction becomes relative north */

else if (PRF_FLAGGED(ch, PRF_AUTOLOOT)
&& (dir == EAST || dir == SOUTH || dir == WEST))
{
player_spins_char(ch, dir);
room_rnum going_to = EXIT(ch, FACING)->to_room;
}
/* UP and DOWN, or default movement remains unchanged */
else room_rnum going_to = EXIT(ch, dir)->to_room;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

I've got it working with a C++ version of Merc probably because I'm in a C++ course at the moment. It's a cool idea that runs the risk of not living up to how cool it is due to programmers about as skilled as me.
Last edit: 20 Oct 2012 20:19 by wifidi. Reason: errant code

Please Log in or Create an account to join the conversation.

More
20 Oct 2012 20:05 #921 by Liko
Replied by Liko on topic Re: relative north movement

wifidi wrote: Dear tbaMUDers,
I've tried coding relative north movement without suceeding. Two versions of the idea are only north moves the character forward in the direction the character has spun to (relative north) or movement in a direction becomes relative north. Here's some basic code that experiences runtime errors:
structs.h 997:
int facing; /**< Cardinal direction of ch. */
// bool relspin; /**< Char moves forward, up, down, or spins left, right or 180. */
// bool relwalk; /**< Direction char moves becomes relative north. */

struct.h 1029:
//struct char_data = {.relspin = false, .relwalk = false};

act.h 146:
/** Relative north. */
#define FACING ((ch)->facing)
//#define RELSPIN ((ch)->relspin)
//#define RELWALK ((ch)->relwalk)

act.movement.c 31:
void player_spins_char(struct char_data *ch, int dir);

act.movement.c 114:
/* Player spins character. */
void player_spins_char(struct char_data *ch, int dir)
{
switch (dir)
{
case (EAST):
{
FACING++;
if (FACING == 4) FACING = 0;
}
case (SOUTH):
{
FACING += 2;
if (FACING == 4) FACING = 0;
if (FACING == 5) FACING = 1;
}
case (WEST):
{
FACING--;
if (FACING == -1) FACING = 3;
}
}
}

act.movement.c 163:
/* ... and the room the character will move into. */

//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/* must check for relative north walking modes to properly designate
* the proposed room */

/* relative north walking mode 1:
* east, west and south only spin the character */
* autoexit toggle piggybacked in lieu of PRF_RELATIVE_NORTH_WALKING_MODE_1 */

if (PRF_FLAGGED(ch, PRF_AUTOEXIT)
&& (dir == EAST || dir == SOUTH || dir == WEST))
{
player_spins_char(ch, dir);
return 0;
}

/* relative north walking mode 2:
* east, west and south spin and move the char in that direction, and
* that direction becomes relative north
* autoloot toggle piggybacked in lieu of PRF_RELATIVE_NORTH_WALKING_MODE_2 */

else if (PRF_FLAGGED(ch, PRF_AUTOLOOT)
&& (dir == EAST || dir == SOUTH || dir == WEST))
player_spins_char(ch, dir);

else FACING = dir;

room_rnum going_to = EXIT(ch, FACING)->to_room;
//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

I've got it working with a C++ version of Merc probably because I'm in a C++ course at the moment. It's a cool idea that runs the risk of not living up to how cool it is due to programmers about as skilled as me.


Hello, Welcome to the TbaMud forums. When placing code in the forums its always a good idea to use the code brackets.
Now it would help if you clear up exactly what your trying to do. Are you wanting it so that your code spins the player north?

Randian(0.0.0)
Owner/Developer

Please Log in or Create an account to join the conversation.

More
20 Oct 2012 20:27 - 20 Oct 2012 23:16 #922 by wifidi
Replied by wifidi on topic Re: relative north movement
I corrected the logic since you replied.

I'm trying to have three walking modes: default (the one that debuted with text MUDs), "spin" where north moves the direction the character is facing, east spins right, west spins left and south turns about, and "relative walk" where north moves the direction the character is facing, east moves and spins right, west moves and spins left and south moves and spins about.
Last edit: 20 Oct 2012 23:16 by wifidi. Reason: unclear

Please Log in or Create an account to join the conversation.

More
20 Oct 2012 20:49 #923 by wifidi
Replied by wifidi on topic Re: relative north movement
How are the code brackets used?

Please Log in or Create an account to join the conversation.

More
21 Oct 2012 00:33 - 21 Oct 2012 00:36 #924 by Rumble
Replied by Rumble on topic Re: relative north movement
[
Code:
this is a code block[
Wich looks like:
Code:
this is a code block

Or select the text and click the code button above (the page with the <> brackets over it).

Rumble
The Builder Academy
tbamud.com 9091
rumble@tbamud.com
Last edit: 21 Oct 2012 00:36 by Rumble.

Please Log in or Create an account to join the conversation.

More
21 Oct 2012 02:26 #925 by wifidi
Replied by wifidi on topic Re: relative north movement
I got it. Mode 1 hardwired looks like:
structs.h 997:
Code:
int facing;
act.h 146:
Code:
#define FACING ((ch)->facing)
act.movement.c 375:
Code:
ACMD(do_move) { switch (subcmd) { case (EAST): { FACING++; if (FACING == 4) FACING = 0; break; } case (SOUTH): { FACING += 2; if (FACING == 4) FACING = 0; if (FACING == 5) FACING = 1; break; } case (WEST): { FACING--; if (FACING == -1) FACING = 3; } } if (subcmd == NORTH) perform_move(ch, FACING, 0); if ((subcmd == UP) || (subcmd == DOWN)) /* These subcmd defines are mapped precisely to the direction defines. */ perform_move(ch, subcmd, 0); }
The toggles I'm trying to use to toggle between default and this walking mode -- PRF_FLAGS -- generate SYSERRS. This is a tight ship being run here so there'll have to be an acceptable design.

Please Log in or Create an account to join the conversation.

Time to create page: 0.245 seconds