LANGUAGE.C
LIB3/OBJ/HANDLERS/LANGUAGE.C · 3.4 KB
From the archive nm4dos.zip
Download the archive « Back to the archive contents
#include "language.h"
/*
** Format for language parameters :
**
** ([ name : ({ language_props, garble_object, language_size }) })
**
** name is the name seen by players, ie
** "thieves cant" or "oh yes they can"
**
** language props can include any or all of :
** L_WRITTEN : language is writable
** L_SPOKEN : language is speakable
** L_DISTANCE : language can be spoken at a distance
** L_MAGIC : An fn is called when the language is read
**
** The garble object contains the fn's :
** - garble_say, garble_tell, garble_shout, & garble_written
** which are passed the message header, ie 'Newstyle says :', and
** the message body, ie "Long live the hedgehogs!", and should
** return a mixed object ({ header, body }) from which the
** message shown to people who do not know the language comes.
** In magic languages, these fn's are called on *all* reads,
** even by people with the language.
** - squidge_text(mixed str, int size), called when there is
** not enough space to write a complete message. It should
** return something length size in chars.
**
** The language size is inexplicable. Or should that be unspeakable?
*/
mapping languages;
void create()
{
languages = ([
"common": ({ L_SPOKEN | L_WRITTEN | L_DISTANCE, "/std/languages/common", 10 }),
"light speech": ({ L_SPOKEN | L_WRITTEN | L_DISTANCE, "/std/languages/light_speech", 10 }),
"dark speech": ({ L_SPOKEN | L_WRITTEN | L_DISTANCE, "/std/languages/dark_speech", 10 }),
"little speech": ({ L_SPOKEN | L_WRITTEN | L_DISTANCE, "/std/languages/little_speech", 5 }),
"thieves cant": ({ L_SPOKEN, "/std/languages/cant", 20 }),
"grunt": ({ L_SPOKEN, "/std/languages/grunt", 2 }),
"wizard spells": ({ L_WRITTEN | L_MAGIC | L_SIZED, "/std/languages/wizard_lang", 20 }),
"morse code": ({ L_SPOKEN | L_WRITTEN | L_DISTANCE, "/w/newstyle/morse_lang", 20 }),
]);
}
int query_language_spoken( string str )
{
if( !languages[ str ] )
return 0;
return languages[ str ][ 0 ] & L_SPOKEN;
}
int query_language_written( string str )
{
if( !languages[ str ] )
return 0;
return languages[ str ][ 0 ] & L_WRITTEN;
}
int query_language_distance( string str )
{
if( !languages[ str ] )
return 0;
return languages[ str ][ 0 ] & L_DISTANCE;
}
int query_language_magic( string str )
{
if( !languages[ str ] )
return 0;
return languages[ str ][ 0 ] & L_MAGIC;
}
int query_language_size( string str )
{
if( !languages[ str ] )
return 0;
return languages[ str ][ 2 ];
}
mixed squidge_text( string lang, mixed str, int size )
{
if( !languages[ lang ] )
return 0;
if( !(languages[ lang ][ 0 ] & L_MAGIC) )
return str[ 0..(size / languages[ lang ][ 2 ]) ];
return( mixed ) languages[ lang ][ 1 ]->squidge_text( str, size );
}
int add_language( string name, int flags, mixed ob, int size )
{
languages[ name ] = ({ flags, ob, size });
}
int query_flags( string name )
{
if( !languages[ name ] )
return 0;
return languages[ name ][ 0 ];
}
mixed query_garble_object( string name )
{
if( !languages[ name ] )
return 0;
return languages[ name ][ 1 ];
}
string *query_languages()
{
return m_indices( languages );
}
int test_language( string str )
{
return pointerp( languages[ str ] );
}