| Posted by
| David Haley
USA (3,881 posts) Bio
|
| 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 |
|