Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////////////
- /// Revised String Table Processor for ZScript ///
- /// Allows defining custom string tables ///
- /// v1.0 ///
- /// 15th October, 2018 ///
- /// By: ZoriaRPG ///
- //////////////////////////////////////////////////
- namespace script strings
- {
- const int BUFFER_SIZE = 1024;
- const int MAX_STRINGS = 4096;
- int buffer[BUFFER_SIZE];
- int ids[MAX_STRINGS];
- /*List strings in the table using the following format:
- $ <NUMBER> : <string>
- Tokens:
- $ -- Indicates the beginning of a string ID.
- <NUMBER> a series of numeric characters that represent the numeric ID of the string.
- : -- COlon separator between <NUMBER> and <string>
- <string> The string text.
- */
- int table[]=
- "$000001:This is a string.
- $000002:This is a second.
- $000003:This is a third.
- $000004:This is a fourth
- $000005:This is a fifth.";
- void run(){}
- //stores the initial position of all strings in the table into ids[]
- //where the index of ids[index] == the string ID.
- void init()
- {
- int token[7]; int token_pos; int table_pos;
- for ( table_pos = 0; table[table_pos] != NULL; ++table_pos )
- {
- //find the tokens
- if ( table[table_pos] == '$' )
- {
- //copy the string ID into the token
- token_pos = 0;
- while( table[table_pos] != ':' )
- {
- token[token_pos] = table[q];
- ++token_pos;
- ++q;
- }
- //store the index where the token ends + 2
- ids[atoi(token)] = table_pos +2;
- }
- }
- }
- void clear()
- {
- for ( int q = 0; q < BUFFER_SIZE; ++q )
- {
- buffer[q] = 0;
- }
- }
- void fetch(int string_id)
- {
- int table_pos = ids[string_id];
- for ( int buffer_pos = 0; table[table_pos+1] != '$'; ++buffer_pos )
- {
- buffer[buffer_pos] = table[table_pos];
- ++table_pos;
- }
- }
- void store(int msg_id)
- {
- if ( msg_id <= 0 )
- {
- TraceError("Invalid message ID passed to strings.store()", msg_id);
- return;
- }
- if ( msg_id >= Game->NumMessages )
- {
- TraceError("Invalid message ID passed to strings.store()", msg_id);
- return;
- }
- SetMessage(msg_id, buffer);
- }
- void display(int string_id)
- {
- fetch(string_id);
- store(Game->NumMessages);
- Screen->Message(Game->NumMessages);
- }
- void display(int string_id, int template_message)
- {
- fetch(string_id);
- store(template_message);
- Screen->Message(template_message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement