Ok, right now i've spent about a month working on and improving mobprogs for
more my liking, and i've run into a problem thats stumping the hell outta
me.
I have a struction called REMEMBER_DATA with remembers certain things about
players that each mob gets after interacting with them. This struct has a
long int said_flags in it. basically a mobprog can(or should) be able to
set one of those flags(1 through 32) on or off, or another ifcheck to see if
they are on or off. Basically i want people to be able to set them to know
what a player has or hasnot done/said to a mob. Mobprog people have had
alittle difficulty getting the concept but i think you guys will see it
easier. Here's an example. In my mud we use a command called 'approach' to
go up to an NPC and see if he has anything to say. with the APPROACH
trigger you can have the NPC say something if approached.
approach mob
the test mob bows, "Hello Paragon, I have not met you before have I?"
if you do it again...
approach mob
the test mob smiles and nods, "Hello again Paragon, how goes things?"
(the code for the mobprog syntax looks like this)
> if ispc $n
> mob remember $n
> ifnot saidto $n 1
> emote bows, "Hello $n, I have not met you before have I?"
> mob set mob $n said 1
> else
> emote smiles and nods, "Hello again Paragon, how goes things?"
> endif
>endif
so theres a couple things different then stock in there, so let me explain
them
first. ifnot merely returns the opposite of if... nice and simple. mob set
is a set
command for mobs... aka mob set <type> <name> <field> <value> and the fields
are alittle different then the imm set command. the if check is simple
too...
if saidto $n 1
if the flag '1' has been set (by the mob) on the player $n it only works on
players
right now, so i have people use if ispc $n checks before ever 'remembering'
someone.
basically i changed the whole remember field to be a struct instead of a
char_data so it saves multiple ones on them. now this SEEMs to work fine as
it is... and all my bug testing i haven't found an errors untill now.
if saidto $n 2
with the second one i have a problem. it seems to use the exact same bit as
the first one. the third one never seems to set, no matter how many times i
try... basically everything seems to mess up after the first flag. heres
the code i use to set / see flags.
here's the ifcheck code block. note because of ifnot, i return errors as -1
and then merely falses and FALSE and trues as TRUE.
/*
* Case 4: Keyword, actor and value
*/
line = one_argument( line, buf );
switch( check )
{
case CHK_SAIDTO:
{
int say;
if(lval_char == NULL)
return -1;
if(mob->mprog_target->victim != lval_char)
return FALSE;
if( !is_number(buf) || (say = atoi(buf)) < 1 || say > 32 )
return -1;
return( IS_SET( mob->mprog_target->said_flags, 2^(say-1) ) );
}
now the reason i did this was iwent and looked at AFF_BLIND its defined as
(A) now i went and looked at A, and it was defined as 1. (B was 2, C was 4
etc...) which is 2 to the power of (number the player inputs -1) it makes
sure the number is a number and is between 1 and 32 also.
now heres the part in mob set:
else if ( !str_prefix( arg2, "said" ) )
{
if ( IS_NPC(victim) )
{
bug( "Mpset: mob: said: Invalid victim (vnum %d)",
IS_NPC(ch) ? ch->pIndexData->vnum : 0 );
return;
}
if ( value < 1 || value > 32 )
bug( "Mpset: mob: Invalid said value (vnum %d)",
IS_NPC(ch) ? ch->pIndexData->vnum : 0 );
else
{
REMEMBER_DATA *rem;
rem = remember(ch,victim);
if IS_SET( rem->said_flags, 2^(value-1) )
REMOVE_BIT(rem->said_flags, 2^(value-1) );
else
SET_BIT(rem->said_flags, 2^(value-1) );
}
}
now theres some non-stock stuff in there, basically the 'remember()'
fucntion just cycles through the mobs remember data's looking for the
player, if the player exists it reutrsn the point the the struct, if not, it
creates a new struct for the player. basically all of the remember stuff
besides the said_flags seem to work fine, so i really dont think thats the
problem, and this just seems to simple i dont understand whats going wrong.
to give you an example of whats going on, i made a mob, and added 5 mobprogs
to him. if you say 1, he sees if 1 is set if not, he sets it, either way he
says the state of it. each of of these 1-5 does the same thing for
different flags, the heres my first 5 says... (each should say: its not set,
setting it now)
You say to testy mob '1'
testy mob says '1 has not been set. Trying to set now.'
<20000hp 100m 100mv> sayto mob 2
You say to testy mob '2'
testy mob says '2 has now been set.'
<20000hp 100m 100mv> sayto mob 3
You say to testy mob '3'
testy mob says '3 has not been set. Trying to set now.'
<20000hp 100m 100mv> sayto mob 4
You say to testy mob '4'
testy mob says '4 has not been set. Trying to set now.'
<20000hp 100m 100mv> sayto mob 5
You say to testy mob '5'
testy mob says '5 has now been set.'
2 and 5 seem to screw up there(no reason and rhyme, except the same 2 always
screw up...) Now i say to them 1 through 5 again, expecting all 5 to say,
the has now been set. heres the result:
<20000hp 100m 100mv> sayto mob 1
You say to testy mob '1'
testy mob says '1 has now been set.'
<20000hp 100m 100mv> sayto mob 2
You say to testy mob '2'
testy mob says '2 has now been set.'
<20000hp 100m 100mv> sayto mob 3
You say to testy mob '3'
testy mob says '3 has not been set. Trying to set now.'
<20000hp 100m 100mv> sayto mob 4
You say to testy mob '4'
testy mob says '4 has now been set.'
<20000hp 100m 100mv> sayto mob 5
You say to testy mob '5'
testy mob says '5 has now been set.'
3 still seems to screw up, while the others seem to be ok, but i know they
aren't all ok, 1 and 2 seem to be set or unset together and lots of other
wierd things. I thought that bitvectors weren't that complicated, but i
just can't see to figure this out. sorry for the length i could really
appreciate any comments on anything appearing weird. If you need anything
else to comment, let me know and I'll gladly shove some more code up.
-Josh