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 ➜ Showing Current Language in Say

Showing Current Language in Say

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


Posted by Twystedpair   (4 posts)  Bio
Date Thu 03 Jul 2003 07:17 AM (UTC)
Message
I'm trying to get the current language spoken by the character to show up in say. I cannot, for the life of me, figure it out. I can get a language to show up but it's not the language currently being spoken. I know that I'm just overlooking something that I should know...if anyone could help me get on the right track I'd appreciate it.
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Thu 03 Jul 2003 08:15 AM (UTC)
Message
Can you post a snippet showing what you did - that will help see if you are on the right track.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Twystedpair   (4 posts)  Bio
Date Reply #2 on Thu 03 Jul 2003 12:08 PM (UTC)

Amended on Thu 03 Jul 2003 12:13 PM (UTC) by Twystedpair

Message
Here is the line, I just can't figure out what to define the string as:

ch_printf(ch, "&CYou say (&W%s&C): &W%s\n\r", ??, drunk_speech( argument, ch ));

I've tried everything I can think of and find in the code at the moment. I'm not that wonderful at C but I'm just learning to do minor alterations right now. I tried lang_names[ch->speaking] but got the wrong language...so I set it as an integer and just showed ch->speaking in say and it shows 2, 4, 8, 16, 32, etc. as I go through speaking the different languages, when I need it to show 0, 1, 2, 3, etc. or atleast that's what I think considering the language names are in a const right there in the same file.
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #3 on Thu 03 Jul 2003 01:15 PM (UTC)

Amended on Thu 03 Jul 2003 01:18 PM (UTC) by David Haley

Message
Actually, ch->speaking uses the power of 2 numbers (1, 2, 4, 8, 16, etc.) because it's a set of flags. For example, if 2 is set, then ch is speaking language 2 is being spoken. If 6 is set, then ch is speaking languages 2 AND 3 (represented by 2 + 4).

So you have two problems:
1- mobs who speak multiple languages probably should either not have a language indicator, or should only display the first language. However, the problem is that mobs who speak multiple languages are probably "special mobs" such as the supermob, who must be understood at all times. Or, immortals can use "speak all" to speak all languages at once. I would recommend leaving the language tag off for people speaking more than one.

2- you need to make a routine to translate from powers of 2, and display the right text. Here is the code that was in my MUD. I didn't write it, and since it works (and I've never needed to) I haven't looked into the exact details, but it's fairly straightforward. You will probably have to modify it, because this isn't stock SMAUG anymore... but maybe it's similar enough to require minimal modification.


for ( vch = ch->in_room->first_person; vch; vch = vch->next_in_room )
{
   char buffer[MAX_STRING_LENGTH];
   char understand[MAX_STRING_LENGTH];
   char *sbuf = argument;
   bool language;
   bool can_understand;

   if ( vch == ch )
      continue;

   can_understand = TRUE;

   if ( !knows_language(vch, ch->speaking, ch) &&
      (!IS_NPC(ch) || ch->speaking != 0) )
   {
      sbuf = scramble(argument, ch->speaking);
      can_understand = FALSE;
   }

   if ( ch->speaking != 0 )
   {
      language = TRUE;
   }

   sbuf = drunk_speech( sbuf, ch );

   MOBtrigger = FALSE;

   if (language)
   {
      int i, count, lang;
      count = lang = 0;
      for (i = LANG_COMMON; lang_array[i] != LANG_UNKNOWN; i++)
      {
         if (ch->speaking & lang_array[i])
         {
            count++;
            lang = i;
         }
      }
      if (count == 1)
      {
         if (can_understand)
            sprintf(understand, "in %s", lang_names[lang]);
         else
            sprintf(understand, "in some language");
         sprintf(buffer, "$n says, %s, '$t'", understand);
      }
      else
      {
         sprintf(buffer, "$n says '$t'");
      }
   }
   else
      sprintf(buffer, "$n says '$t'");

   act( AT_SAY, buffer, ch, sbuf, vch, TO_VICT );
}


This is the code that the game calls when looping through the room's people to display to everyone what ch said.

Where language is a bool, set to false if ch->speaking == 0 (which I believe means speaking all) and true otherwise; lang_names is the strings corresponding to language numbers; can_understand is a boolean set to true if victim (or vch) can understand ch's language; understand is a simple char string. I think that's it.

Let me know if this helps you. :)

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Twystedpair   (4 posts)  Bio
Date Reply #4 on Thu 03 Jul 2003 03:16 PM (UTC)
Message
Took a little bit of obvious modification but plopped right in without a hitch. That's exactly what I was thinking with the ch-> speaking, after I set it to show me what it actually was. Now that I look at the working code, it makes sense. Thanks much!
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.


15,900 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.