Camouflage Skill issue (issue with can_see func)

Posted by Dralnu on Sat 03 Sep 2005 10:35 PM — 24 posts, 79,541 views.

USA #0
I feel kinda stupid, but anywho:
I'm adding in a skill. Its in and everything compiles cleanly, but now I'm working on fixing it into can_see. Goal here is to make it so that only rangers can actually see people aff_camo, and there will be an image via infravision that someone is there, but looking at the can_see func, I'm kinda lost.


bool can_see( CHAR_DATA * ch, CHAR_DATA * victim )
{
   if( !victim )  /* Gorog - panicked attempt to stop crashes */
      return FALSE;
   if( !ch )
   {
      if( IS_AFFECTED( victim, AFF_INVISIBLE ) || IS_AFFECTED( victim, AFF_HIDE ) || xIS_SET( victim->act, PLR_WIZINVIS ) || IS_AFFECTED( victim, AFF_CAMO ) )
         return FALSE;
      else
         return TRUE;
   }

   if( ch == victim )
      return TRUE;

   if( !IS_NPC( victim ) && xIS_SET( victim->act, PLR_WIZINVIS ) && get_trust( ch ) < victim->pcdata->wizinvis )
      return FALSE;

   /*
    * SB 
*/
   if( IS_NPC( victim ) && xIS_SET( victim->act, ACT_MOBINVIS ) && get_trust( ch ) < victim->mobinvis )
      return FALSE;

   /*
    * Deadlies link-dead over 2 ticks aren't seen by mortals -- Blodkai
    */
   if( !IS_IMMORTAL( ch ) && !IS_NPC( ch ) && !IS_NPC( victim ) && IS_PKILL( victim ) && victim->timer > 1 && !victim->desc )
      return FALSE;

   if( !IS_NPC( ch ) && xIS_SET( ch->act, PLR_HOLYLIGHT ) )
      return TRUE;

   /*
    * The miracle cure for blindness? -- Altrag 
    */
   if( !IS_AFFECTED( ch, AFF_TRUESIGHT ) )
   {
      if( IS_AFFECTED( ch, AFF_BLIND ) )
         return FALSE;

      if( room_is_dark( ch->in_room ) && !IS_AFFECTED( ch, AFF_INFRARED ) )
         return FALSE;

      if( IS_AFFECTED( victim, AFF_INVISIBLE ) && !IS_AFFECTED( ch, AFF_DETECT_INVIS ) )
         return FALSE;

      if( IS_AFFECTED( victim, AFF_HIDE )
          && !IS_AFFECTED( ch, AFF_DETECT_HIDDEN )
          && !victim->fighting && ( IS_NPC( ch ) ? !IS_NPC( victim ) : IS_NPC( victim ) ) )
         return FALSE;
   }

   /*
    * Redone by Narn to let newbie council members see pre-auths. 
    */
   if( NOT_AUTHED( victim ) )
   {
      if( NOT_AUTHED( ch ) || IS_IMMORTAL( ch ) || IS_NPC( ch ) )
         return TRUE;

      if( ch->pcdata->council && !str_cmp( ch->pcdata->council->name, "Newbie Council" ) )
         return TRUE;

      return FALSE;
   }

 /* Commented out for who list purposes 
    if (!NOT_AUTHED(victim) && NOT_AUTHED(ch) && !IS_IMMORTAL(victim) 
    && !IS_NPC(victim))
   	return FALSE;*/
   return TRUE;
}


That is what I have. Its all stock pretty much cept for the first part where the bit about IS_AFFECTED( victim, AFF_CAMO ). Any hints or am I in the wrong function here?
USA #1
I don't understand why the first bit starts with if ( !ch ). Seems that the whole point is that you want to know if ch 'can_see' victim...

In any case you're in the right place for rangers being able to see camo, but you'll have to do the infrared somewhere else I think.
USA #2
Yeah, you need to place the camo check besides the !ch check.
USA #3
So I did that right?
USA #4
So far, yes. You need to add another check (or two, depending what you want) for the actual check against rangers/camo.
USA #5
something along the lines of


elseif ( ( ch->class != CLASS_RANGER ) && IS_AFFECTED( victim, AFF_CAMO ) )
     return false


or would I need to make it more like


if( ch->CLASS_RANGER && IS_AFFECTED( victim, AFF_CAMO )
    return TRUE
elseif( IS_AFFECTED( victim, AFF_INVISIBLE ) || IS_AFFECTED( victim, AFF_HIDE ) || xIS_SET( victim->act, PLR_WIZINVIS ) || IS_AFFECTED( victim, AFF_CAMO ) )
         return FALSE;
      else
         return TRUE;

[Edit #1]
Fixed an error in syntax
Amended on Sun 04 Sep 2005 10:34 PM by Dralnu
USA #6
No... you want to work in this block of code:
   /*
    * The miracle cure for blindness? -- Altrag 
    */
   if( !IS_AFFECTED( ch, AFF_TRUESIGHT ) )
   {
      if( IS_AFFECTED( ch, AFF_BLIND ) )
         return FALSE;

      if( room_is_dark( ch->in_room ) && !IS_AFFECTED( ch, AFF_INFRARED ) )
         return FALSE;

      if( IS_AFFECTED( victim, AFF_INVISIBLE ) && !IS_AFFECTED( ch, AFF_DETECT_INVIS ) )
         return FALSE;

      if( IS_AFFECTED( victim, AFF_HIDE )
          && !IS_AFFECTED( ch, AFF_DETECT_HIDDEN )
          && !victim->fighting && ( IS_NPC( ch ) ? !IS_NPC( victim ) : IS_NPC( victim ) ) )
         return FALSE;
   }
This seems to be where most invisibility stuff is handled. You can add a simple check here like so:
if ( IS_AFFECTED( victim->AFF_CAMO ) && ch->class != CLASS_RANGER   )
     return false;
You would of course also add extra clauses to the ifcheck depending on what skills allow detection of camouflaged characters.

Note that you don't need to cover all cases; the function will return true by default so you only need to cover cases where ch can't see victim.
USA #7
I don't want truesight to detect the character, hence my placement. Invisible is magic, and hide is a cheap version of camo the way I have it set up, and most classes wouldn't be able to see a char who has been camouflaged unless they have infravision which wouldn't tell who was there, just that something is there. Anywho, I don't want someone with Truesight to be able to detect the player w/ it, which is what that series of ifchecks is doing.
USA #8
Then just put it outside of the if-check, if you don't want truesight to affect it. People in your world are badass camouflage artists, though... :-)
USA #9
I'm planning on making additions to the skill/spell system laterm but the way I see it, true sight is something more magical then anything. Bad-ass camouflage it may be called, but way I see it, someone who is invis will have a magical aura around them, and someone who is just hiding can be found easily enough. This will, maybe later, be outdoors/forest only (I plan on making most of the world forest anyways, at least half). I'll post the changes I made later. It has compiled cleanly enough, but as is I have no way to test it since I don't have a Linux MUD client (and I won't use telnet since I have no clue how to).
USA #10
Plus this is a class-specific skill, and the class might come out peaceful only, so it won't be a problem pk-wise if that were to happen
USA #11

/*
 * True if char can see victim.
 */
bool can_see( CHAR_DATA * ch, CHAR_DATA * victim )
{
   if( !victim )  /* Gorog - panicked attempt to stop crashes */
      return FALSE;
   if( !ch )
   {
      if( ch->Class != CLASS_RANGER && IS_AFFECTED( victim, AFF_CAMO) )
         return FALSE;
else if( IS_AFFECTED( victim, AFF_INVISIBLE ) || IS_AFFECTED( victim, AFF_HIDE ) || IS_AFFECTED( victim, AFF_CAMO || xIS_SET( victim->act, PLR_WIZINVIS ) ) )
         return FALSE;
      else
         return TRUE;
   }

   if( ch == victim )
      return TRUE;

   if( !IS_NPC( victim ) && xIS_SET( victim->act, PLR_WIZINVIS ) && get_trust( ch ) < victim->pcdata->wizinvis )
      return FALSE;

   /*
    * SB 
*/
   if( IS_NPC( victim ) && xIS_SET( victim->act, ACT_MOBINVIS ) && get_trust( ch ) < victim->mobinvis )
      return FALSE;

   /*
    * Deadlies link-dead over 2 ticks aren't seen by mortals -- Blodkai
    */
   if( !IS_IMMORTAL( ch ) && !IS_NPC( ch ) && !IS_NPC( victim ) && IS_PKILL( victim ) && victim->timer > 1 && !victim->desc )
      return FALSE;

   if( !IS_NPC( ch ) && xIS_SET( ch->act, PLR_HOLYLIGHT ) )
      return TRUE;

   /*
    * The miracle cure for blindness? -- Altrag 
    */
   if( !IS_AFFECTED( ch, AFF_TRUESIGHT ) )
   {
      if( IS_AFFECTED( ch, AFF_BLIND ) )
         return FALSE;

      if( room_is_dark( ch->in_room ) && !IS_AFFECTED( ch, AFF_INFRARED ) )
         return FALSE;

      if( IS_AFFECTED( victim, AFF_INVISIBLE ) && !IS_AFFECTED( ch, AFF_DETECT_INVIS ) )
         return FALSE;

      if( IS_AFFECTED( victim, AFF_HIDE )
          && !IS_AFFECTED( ch, AFF_DETECT_HIDDEN )
          && !victim->fighting && ( IS_NPC( ch ) ? !IS_NPC( victim ) : IS_NPC( victim ) ) )
         return FALSE;
   }

   /*
    * Redone by Narn to let newbie council members see pre-auths. 
    */
   if( NOT_AUTHED( victim ) )
   {
      if( NOT_AUTHED( ch ) || IS_IMMORTAL( ch ) || IS_NPC( ch ) )
         return TRUE;

      if( ch->pcdata->council && !str_cmp( ch->pcdata->council->name, "Newbie Council" ) )
         return TRUE;

      return FALSE;
   }

 /* Commented out for who list purposes 
    if (!NOT_AUTHED(victim) && NOT_AUTHED(ch) && !IS_IMMORTAL(victim) 
    && !IS_NPC(victim))
   	return FALSE;*/
   return TRUE;
}


That is the code as-is after changes. Right now I cann't test it since I'm lacking a client to connect with, If you see any problems or whatever, please let me know, and let me know if you know of a good client for Linux :)
USA #12
What's wrong with telnet? :-)

Anyhow your code won't work, because you put all that stuff under the ifcheck "if (!ch)" but then you check ch->class... basically what you're doing is saying "if ch is null, then do the following..." But that's not at all what you want to do; in fact you want to make sure that ch is NOT null before continuing.
USA #13
Then give me an idea what to do? I'm stumped now -.-

I did add a check into the TRUE_SIGHT bit to get part of it fixed, but in any case, and I think I'm going to leave it there for the time being. Got other things to do, and I'll fix things up later and build around it until I can think of something better
Amended on Tue 06 Sep 2005 01:53 AM by Dralnu
USA #14
I'm not sure I understand your question. Just put your camo ifcheck outside the truesight and after the "if ( !ch )" checks.

Is the problem that you don't know why "if ( !ch )" is there, i.e. what it does and why it's important?
USA #15
Looking through the code, it looks like if the target isn't ch, then...

But anyways, would it be better to add the ifcheck before if( !ch )?
USA #16
Oh, ok... you don't know what null pointers are, then.

So pointers point to memory addresses, right? Well, sometimes a pointer can point 'nowhere' - this is what is called a null pointer.

Characters have pointers to their group leaders. However, if a character has no leader, that pointer will be null. That is a way of indicating that although there is this pointer, it currently is "empty" - in other words, don't try to follow it and find what character lies at the other end.

Dereferencing a null pointer is a Very Bad Thing (tm). This will crash your program:
CHAR_DATA * ch = NULL;
ch->age = 123;


So, when one writes "if ( !ch )" it has nothing to do with whether or not ch is the target or things like that. What it actually means is: "if ( ch == NULL )".

Don't ask me why this function would be called with a NULL ch. It's really kind of strange, but apparently they had a good reason to do it. It could just be a security, again because having a null pointer can mean blowing up your program.

So there you go - putting your ifcheck before the "if ( !ch )" line would be a Very Bad Thing (tm). :-)
USA #17
The reason is for the web server. Smaug has one, and of course viewing the online who list on a web has no ch. When I added cloak, I forgot to add the check in that !ch ifcheck, and someone viewed the online who list. Bam, crash.
USA #18
Ah, ok... thanks for clearing that up. :) (This is a place where comments would have been useful...)
USA #19
I think I see what I had missed, but back to the original issue: How COULD I get this done the way I want it to get done, or where could I alter true sight itself? I looked for it and didn't see it...
USA #20
Err, haven't we already determined that? The if victim-is-camouflaged and if-ch-is-not-a-ranger?
USA #21
Nvm. I'll figure it out some other time. I did it the way I thought it would, and honestly I'm still not sure wtf I'm doing, so until it finally clicks, I'm leaving it as is. This isn't me giving up, this is me retreating to relaod -.-
USA #22
Maybe I missed something but, you do realize you are editing a codebase that uses telnet right? unless you removed the IAC negotiations and did something completely different, which for all I know is completely possible, how do you expect to connect to your mud.
USA #23
I ment client, as in using something like zmud instead of telnet for connection...