Since the place is using just 32-bit numbers for room flags, how do you go over BV30 without it going hay-wire on you? i know its possible because i was building for this other guy and he has about 50 room flags.
SWR room flags (above BV30)
Posted by Destiny on Mon 13 Jan 2003 09:03 AM — 18 posts, 66,783 views.
Either he reworked the bitflag structure or he was using a second roomflag structure. Odds are he used a second structure since reworking the bitflag structure entirely is obnoxiously difficult and is hardly worth the effort.
how would you set that up? I see where you define room_flags in build.c, but i cant see where it links those to their corresponding bit variables.
Meaning:
(in build.c)
char * const r_flags [] =
{
"dark", "reserved", "nomob", "indoors", "can_land", "can_fly", "no_drive",
"nomagic", "bank", "private", "safe", "remove_this_flag", "petshop", "norecall",
"donation", "nodropall", "silence", "logspeech", "nodrop", "clanstoreroom",
"plr_home", "empty_home", "teleport", "hotel", "nofloor", "refinery", "factory",
"republic_recruit", "shipyard", "spacecraft", "prototype", "auction"
};
(in mud.h)
#define ROOM_DARK BV00
/* BV01 now reserved for track BV01 and hunt */
#define ROOM_NO_MOB BV02
#define ROOM_INDOORS BV03
#define ROOM_CAN_LAND BV04
#define ROOM_CAN_FLY BV05
#define ROOM_NO_DRIVING BV06
#define ROOM_NO_MAGIC BV07
#define ROOM_BANK BV08
Where does it tell you that "nomob" = ROOM_NO_MOB or BV02?
Meaning:
(in build.c)
char * const r_flags [] =
{
"dark", "reserved", "nomob", "indoors", "can_land", "can_fly", "no_drive",
"nomagic", "bank", "private", "safe", "remove_this_flag", "petshop", "norecall",
"donation", "nodropall", "silence", "logspeech", "nodrop", "clanstoreroom",
"plr_home", "empty_home", "teleport", "hotel", "nofloor", "refinery", "factory",
"republic_recruit", "shipyard", "spacecraft", "prototype", "auction"
};
(in mud.h)
#define ROOM_DARK BV00
/* BV01 now reserved for track BV01 and hunt */
#define ROOM_NO_MOB BV02
#define ROOM_INDOORS BV03
#define ROOM_CAN_LAND BV04
#define ROOM_CAN_FLY BV05
#define ROOM_NO_DRIVING BV06
#define ROOM_NO_MAGIC BV07
#define ROOM_BANK BV08
Where does it tell you that "nomob" = ROOM_NO_MOB or BV02?
Quote:
Where does it tell you that "nomob" = ROOM_NO_MOB or BV02?
Where does it tell you that "nomob" = ROOM_NO_MOB or BV02?
In C, you start counting arrays from 0. So in char * const r_flags [] = { "dark", "reserved", "nomob", ...,
dark is BV00, reserved is BV01, and nomob is BV02.
I realize that, but you see, there are about 80 BV00 flags located in mud.h i want to know how the mud knows which one is the right one to use. i found an interesting line in act_wiz.c that says:
flag_string(location->room_flags, r_flags) );
and flag_string is this:
char * flag_string args( ( int bitvector, char * const flagarray[] ) );
that looks kinda like what im looking for, but the thing is i still dont see how it knows that location->room_flags tells it to use that certain set of Bit variables,
flag_string(location->room_flags, r_flags) );
and flag_string is this:
char * flag_string args( ( int bitvector, char * const flagarray[] ) );
that looks kinda like what im looking for, but the thing is i still dont see how it knows that location->room_flags tells it to use that certain set of Bit variables,
Each BV00 all do the same thing, they all toggle bit 0 of an integer. But defines have been created so that you can use names such as ROOM_DARK instead of BV00 to save your sanity. What you are doing is toggling bit 0 of the 32-bit integer you have setup in your structs. For example:
in room_index_data you have..
int flags;
The SET_BIT() macro takes that 32 bit integer and toggles one of 32 bits that make up that integer.
In all actuality you could have:
SET_BIT(room->flags, BV00);
and it would be the same as..
SET_BIT(room->flags, ROOM_DARK);
What 'redit flags dark' does, is it takes the argument 'dark' and searches through the r_flags[] array, until it finds a match.. it then takes that array position (in this case position 0) and sets the cooresponding bit (BV00)on the room->flags integer, using SET_BIT.
in room_index_data you have..
int flags;
The SET_BIT() macro takes that 32 bit integer and toggles one of 32 bits that make up that integer.
In all actuality you could have:
SET_BIT(room->flags, BV00);
and it would be the same as..
SET_BIT(room->flags, ROOM_DARK);
What 'redit flags dark' does, is it takes the argument 'dark' and searches through the r_flags[] array, until it finds a match.. it then takes that array position (in this case position 0) and sets the cooresponding bit (BV00)on the room->flags integer, using SET_BIT.
Perhaps I'm just not understanding, or maybe im not wording my question right. I know the bitvectors are and what they do and how to create arrays. All i want to know how to do is to create a second array of flags that redit and rstat will pick up on. I can make the array just fine, but i cant get the commands to pick up on the new array as well. there was one time about 5 hours ago or so that redit picked up on it, but rstat just crashed the mud, regardless of whether or not i had used the new array, so my thought was that the compiler got the two arrays confused. that's why redit could assign a bitvector, but redit cant read two at once.
Can someone please just tell me how to create an array or a structure within the current array to expand the number of room flags that i have and can use.
-David Rocco
Can someone please just tell me how to create an array or a structure within the current array to expand the number of room flags that i have and can use.
-David Rocco
Here's what you need to do..
First open build.c..
add your second array:
char * const r_flags2 [] =
{
"r00", "r01", "r02", "r03", "r04", "r05",
"r06", "r07", "r08", "r09", "r10", "r11",
"r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
"r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
};
further down.. below get_rflag..
add this:
int get_rflag2( char *flag )
{
int x;
for ( x = 0; x < 32; x++ )
if ( !str_cmp( flag, r_flags2[x] ) )
return x;
return -1;
}
then in do_redit()
add this below the.. if ( !str_cmp( arg, "flags" ) ) section
if ( !str_cmp( arg, "flags2" ) )
{
if ( !argument || argument[0] == '\0' )
{
send_to_char( "Toggle the room flags.\n\r", ch );
send_to_char( "Usage: redit flags <flag> [flag]...\n\r", ch );
send_to_char( "\n\rPossible Flags: \n\r", ch );
send_to_char( "blah blah blah\n\r", ch );
return;
}
while ( argument[0] != '\0' )
{
argument = one_argument( argument, arg2 );
value = get_rflag2( arg2 );
if ( value < 0 || value > 31 )
ch_printf( ch, "Unknown flag: %s\n\r", arg2 );
TOGGLE_BIT( location->room_flags2, 1 << value );
}
return;
}
then open act_wiz.c
and in do_rstat()
below..
ch_printf( ch, "&GRoom flags: &W%s\n\r",
flag_string(location->room_flags, r_flags) );
add..
ch_printf( ch, "&GRoom flags2: &W%s\n\r",
flag_string(location->room_flags2, r_flags2) );
then open up mud.h
and add this to room_index_data..
int room_flags2;
Now all you have to do is add a second set of defines..
For example:
...
#define ROOM_PROTOTYPE BV30
#define ROOM_AUCTION BV31
/* Second Set of Room Flags */
#define ROOM_FLAG1 BV00
#define ROOM_FLAG2 BV01
Recompile and you're done.. now too add more flags, add them too array r_flags2 instead of r_flags in build.c,
and use 'redit flags2' instead of 'redit flags'
When using the flags in your code.. just use SET_BIT(room->room_flags2, ROOM_FLAG1); instead of room->room_flags
Hope this helps.. I don't actually use this code (i use extended BV's) and I may have forgot something.. but it should work for ya.
First open build.c..
add your second array:
char * const r_flags2 [] =
{
"r00", "r01", "r02", "r03", "r04", "r05",
"r06", "r07", "r08", "r09", "r10", "r11",
"r12", "r13", "r14", "r15", "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
"r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
};
further down.. below get_rflag..
add this:
int get_rflag2( char *flag )
{
int x;
for ( x = 0; x < 32; x++ )
if ( !str_cmp( flag, r_flags2[x] ) )
return x;
return -1;
}
then in do_redit()
add this below the.. if ( !str_cmp( arg, "flags" ) ) section
if ( !str_cmp( arg, "flags2" ) )
{
if ( !argument || argument[0] == '\0' )
{
send_to_char( "Toggle the room flags.\n\r", ch );
send_to_char( "Usage: redit flags <flag> [flag]...\n\r", ch );
send_to_char( "\n\rPossible Flags: \n\r", ch );
send_to_char( "blah blah blah\n\r", ch );
return;
}
while ( argument[0] != '\0' )
{
argument = one_argument( argument, arg2 );
value = get_rflag2( arg2 );
if ( value < 0 || value > 31 )
ch_printf( ch, "Unknown flag: %s\n\r", arg2 );
TOGGLE_BIT( location->room_flags2, 1 << value );
}
return;
}
then open act_wiz.c
and in do_rstat()
below..
ch_printf( ch, "&GRoom flags: &W%s\n\r",
flag_string(location->room_flags, r_flags) );
add..
ch_printf( ch, "&GRoom flags2: &W%s\n\r",
flag_string(location->room_flags2, r_flags2) );
then open up mud.h
and add this to room_index_data..
int room_flags2;
Now all you have to do is add a second set of defines..
For example:
...
#define ROOM_PROTOTYPE BV30
#define ROOM_AUCTION BV31
/* Second Set of Room Flags */
#define ROOM_FLAG1 BV00
#define ROOM_FLAG2 BV01
Recompile and you're done.. now too add more flags, add them too array r_flags2 instead of r_flags in build.c,
and use 'redit flags2' instead of 'redit flags'
When using the flags in your code.. just use SET_BIT(room->room_flags2, ROOM_FLAG1); instead of room->room_flags
Hope this helps.. I don't actually use this code (i use extended BV's) and I may have forgot something.. but it should work for ya.
Also you may want to use things like
ROOM2_FLAG1 instead of ROOM_ to help keep track of what is what. This *IS* the easiest way to get extra flags. I know you probably wanted to just add to the r_flag[] array and not have to use 'redit flags2' but.. trust me.. the alternative can be quite a pain. ;-)
ROOM2_FLAG1 instead of ROOM_ to help keep track of what is what. This *IS* the easiest way to get extra flags. I know you probably wanted to just add to the r_flag[] array and not have to use 'redit flags2' but.. trust me.. the alternative can be quite a pain. ;-)
Awesome, thank you so much
You also need to change the load/save code for rooms to load/save the extra integer. Be warned this will make your area files incompatible with stock SMAUG and SMAUG editors, if you use those.
Acually I was doing this to my MUD also. This is the easiest way to get more flags but you did forget one thing. When you compile all of that then you will get an error like this one:
act_wiz.c: In function `do_rstat':
act_wiz.c:1035: `r_flags2' undeclared
To fix this all you need to do is go into mud.h and find this:
extern char * const r_flags [];
Thats about line 3279, this way you won't have to search for it to much. Under that just add this:
extern char * const r_flags2 [];
Then everything should compile correctly. Hope that helped if you were having trouble. Thanks for the code Boborak.
act_wiz.c: In function `do_rstat':
act_wiz.c:1035: `r_flags2' undeclared
To fix this all you need to do is go into mud.h and find this:
extern char * const r_flags [];
Thats about line 3279, this way you won't have to search for it to much. Under that just add this:
extern char * const r_flags2 [];
Then everything should compile correctly. Hope that helped if you were having trouble. Thanks for the code Boborak.
Nick is right. So here is what you need to do for it to save/load the flags.
For loading:
in void load_rooms()
go down below for ( ; ; ) and find:
int x1, x2, x3, x4, x5, x6;
and add make it look like this (add x7)
int x1, x2, x3, x4, x5, x6, x7;
then go down and find this:
sscanf( ln, "%d %d %d %d %d %d",
&x1, &x2, &x3, &x4, &x5, &x6 );
And make it look like this:
sscanf( ln, "%d %d %d %d %d %d %d",
&x1, &x2, &x3, &x4, &x5, &x6, &x7 );
Below that look for this (should be about two lines down):
pRoomIndex->room_flags = x2;
Below that add:
pRoomIndex->room_flags2 = x7;
I think you need to do this, I've never acually messed with the read/save functions for rooms:
Find this:
x1=x2=x3=x4=x5=x6=0;
Change it to this:
x1=x2=x3=x4=x5=x6=x7=0;
Thas all for db.c and the load function. Now for the save function.
All of this is under void fold_area():
Search for:
/* save rooms */
This will put you in the general area of code you need to be. Go down and find this:
fprintf( fpout, "0 %d %d %d %d %d \n", room->room_flags,
room->sector_type,
room->tele_delay,
room->tele_vnum,
room->tunnel );
And change the fprintf to this:
fprintf( fpout, "0 %d %d %d %d %d %d \n",
Then next to the room->room_flags make it look like this:
room->room_flags, room->room_flags2,
The end result should look something like this:
fprintf( fpout, "0 %d %d %d %d %d %d\n", room->room_flags,
room->room_flags2,
room->sector_type,
room->tele_delay,
room->tele_vnum,
room->tunnel );
Yeah, again I have never toyed with these functions but it compiles alright so I think it should work alright also. Good luck, and if it doesn't/does work then post the answer here.
For loading:
in void load_rooms()
go down below for ( ; ; ) and find:
int x1, x2, x3, x4, x5, x6;
and add make it look like this (add x7)
int x1, x2, x3, x4, x5, x6, x7;
then go down and find this:
sscanf( ln, "%d %d %d %d %d %d",
&x1, &x2, &x3, &x4, &x5, &x6 );
And make it look like this:
sscanf( ln, "%d %d %d %d %d %d %d",
&x1, &x2, &x3, &x4, &x5, &x6, &x7 );
Below that look for this (should be about two lines down):
pRoomIndex->room_flags = x2;
Below that add:
pRoomIndex->room_flags2 = x7;
I think you need to do this, I've never acually messed with the read/save functions for rooms:
Find this:
x1=x2=x3=x4=x5=x6=0;
Change it to this:
x1=x2=x3=x4=x5=x6=x7=0;
Thas all for db.c and the load function. Now for the save function.
All of this is under void fold_area():
Search for:
/* save rooms */
This will put you in the general area of code you need to be. Go down and find this:
fprintf( fpout, "0 %d %d %d %d %d \n", room->room_flags,
room->sector_type,
room->tele_delay,
room->tele_vnum,
room->tunnel );
And change the fprintf to this:
fprintf( fpout, "0 %d %d %d %d %d %d \n",
Then next to the room->room_flags make it look like this:
room->room_flags, room->room_flags2,
The end result should look something like this:
fprintf( fpout, "0 %d %d %d %d %d %d\n", room->room_flags,
room->room_flags2,
room->sector_type,
room->tele_delay,
room->tele_vnum,
room->tunnel );
Yeah, again I have never toyed with these functions but it compiles alright so I think it should work alright also. Good luck, and if it doesn't/does work then post the answer here.
you will also have to add this in your do_look function so you can see the room flags when you do look in your mud.
set_char_color(AT_CYAN, ch);
send_to_char("[", ch);
send_to_char(flag_string(ch->in_room->room_flags, r_flags), ch);
send_to_char(" ", ch);
send_to_char(flag_string(ch->in_room->room_flags2, r_flags2), ch);
send_to_char("]", ch);
set_char_color(AT_CYAN, ch);
send_to_char("[", ch);
send_to_char(flag_string(ch->in_room->room_flags, r_flags), ch);
send_to_char(" ", ch);
send_to_char(flag_string(ch->in_room->room_flags2, r_flags2), ch);
send_to_char("]", ch);
I added all of the above stuff, and I tried getting it to work. Now all of it works, except for the saving. I've been staring at it for at least half an hour, I figured that the x7 parts were a bit backwards, so I changed those around, and it's still not working. Anyone see any typos on any of this? Or is my problem a bit more serious? Thanks
Can you show us the lines where you save, and also load, those flags? It is almost impossible to debug code simply by a description that "it doesn't work".
I think I understand. When I wrote the save/load I put the save in a differen't spot then the load. I think this is the problem, let me restate what to do here:
Under void fold_area():
Search for:
/* save rooms */
This will put you in the general area of code you need to be. Go down and find this:
fprintf( fpout, "0 %d %d %d %d %d \n", room->room_flags,
room->sector_type,
room->tele_delay,
room->tele_vnum,
room->tunnel );
This is what needs fixing, just look here:
fprintf( fpout, "0 %d %d %d %d %d %d\n",
room->room_flags,
room->sector_type,
room->tele_delay,
room->tele_vnum,
room->tunnel,
room->room_flags2 );
That should fix it, just put the room->room_flags2 at the bottom of the list so it reads in last becase thats how its loaded. If this doesn't work then tell me, I'll take a look at the problem again. If it works then post here again please, I'd like to know the end result. Hope it helps.
Under void fold_area():
Search for:
/* save rooms */
This will put you in the general area of code you need to be. Go down and find this:
fprintf( fpout, "0 %d %d %d %d %d \n", room->room_flags,
room->sector_type,
room->tele_delay,
room->tele_vnum,
room->tunnel );
This is what needs fixing, just look here:
fprintf( fpout, "0 %d %d %d %d %d %d\n",
room->room_flags,
room->sector_type,
room->tele_delay,
room->tele_vnum,
room->tunnel,
room->room_flags2 );
That should fix it, just put the room->room_flags2 at the bottom of the list so it reads in last becase thats how its loaded. If this doesn't work then tell me, I'll take a look at the problem again. If it works then post here again please, I'd like to know the end result. Hope it helps.
This is in fold_area:
fprintf( fpout, "0 %d %d %d %d %d %d\n", room->room_flags,
room->sector_type,
room->tele_delay,
room->tele_vnum,
room->tunnel,
room->room_flags2 );
else
fprintf( fpout, "0 %d %d %d\n", room->room_flags,
room->room_flags2,
room->sector_type );
this is in load_rooms:
sscanf( ln, "%d %d %d %d %d %d %d",
&x1, &x2, &x3, &x4, &x5, &x6, &x7 );
pRoomIndex->room_flags = x2;
pRoomIndex->room_flags2 = x7;
pRoomIndex->sector_type = x3;
pRoomIndex->tele_delay = x4;
pRoomIndex->tele_vnum = x5;
pRoomIndex->tunnel = x6;
I've put the stuff in for do_look, and it shows as the flag being set on the room. I've guessed on what the area file should look like, and I believe that's right also.
Thanks for the help.
fprintf( fpout, "0 %d %d %d %d %d %d\n", room->room_flags,
room->sector_type,
room->tele_delay,
room->tele_vnum,
room->tunnel,
room->room_flags2 );
else
fprintf( fpout, "0 %d %d %d\n", room->room_flags,
room->room_flags2,
room->sector_type );
this is in load_rooms:
sscanf( ln, "%d %d %d %d %d %d %d",
&x1, &x2, &x3, &x4, &x5, &x6, &x7 );
pRoomIndex->room_flags = x2;
pRoomIndex->room_flags2 = x7;
pRoomIndex->sector_type = x3;
pRoomIndex->tele_delay = x4;
pRoomIndex->tele_vnum = x5;
pRoomIndex->tunnel = x6;
I've put the stuff in for do_look, and it shows as the flag being set on the room. I've guessed on what the area file should look like, and I believe that's right also.
Thanks for the help.