I suppose attaching it would help... *bonks self*

Josh
The problem:  to get something like this:

/-------------\ 
|     [ ]     | 
|      |      | 
| [ [EMAIL PROTECTED]     | 
|        \    | 
|         [ ] | 
|-------------/

(keep in mind color codes from Lope's color are there too)

into something like this:

Neat and tidy, with flowers scenting the air, the room is sparsely
furnished.  A table sits off to one side, surrounded by three chairs.  A
fire glows in the kitchens stone oven, and the smell of fresh bread drifts
tantalizingly in the air, mixing with the delicate aroma of the flowers.  A
flight of stone steps on the west wall lead to the upper floor.  To the 
southeast you see a small opening and the to the nort is a large enterance.


without going over the 75 char mark.

ie:

/-------------\ Neat and tidy, with flowers scenting the air, the room is 
|     [ ]     | sparsely furnished.  A table sits off to one side, 
|      |      | surrounded by three chairs.  A fire glows in the kitchens 
| [ [EMAIL PROTECTED]     | stone oven, and the smell of fresh bread drifts
|        \    | tantalizingly in the air, mixing with the delicate aroma 
|         [ ] | of the flowers.  A flight of stone steps on the west wall 
|-------------/ lead to the upper floor.  To the southeast you see a small
opening and the to the north is a large enterance.



now i have a function that returns a string(the map) in a format like this:


"/-------------\\ \n\r|     [ ]     |\n\r"... and im pretty sure it works ok...


heres the first try at the function i use to plug it in:

char *insert_string( const char *oldstring, char *insert )
{
   char *tempstr;
   char templine[MSL];
   char *inserted;

   int line = 1;

   tempstr = str_dup(oldstring);  /* format needs a duplicated string*/

   tempstr = format_string( tempstr, FALSE ); /* if it hasnt been formatted, 
                                              /* do so now*/

   while( *insert )
   {
      insert = getline(insert, templine); /*gets first line of map */

      strcat( templine, string_linecpy( tempstr, line ) );
      /*adds it in front of the first normal line*/

      string_linedel(tempstr, line); /*del old line*/

      string_lineadd(tempstr, templine, line); /* add the new one*/

      format_string( tempstr, FALSE ); /*format it, so line isnt too long*/

      if( ++line > 20) /*some error checking */
      {
         bug("insert_string: repeating loop, for( *insert )",0);
         break;
      }
   }

   format_string( tempstr, FALSE ); /* format any lines lower then the map*/

   return str_dup(tempstr);
}

(ignore the FALSE in format string for right now)

This is the end result:

/-------------\ Neat and tidy, with flowers scenting the air, the |
[ ] | room is sparsely furnished.  A table sits off to one side,
| | | surrounded by three chairs.  A fire glows in the kitchens |
[ [EMAIL PROTECTED] | stone oven, and the smell of fresh bread |
\ | drifts tantalizingly in the air, mixing with the delicate aroma of
| [ ] | the flowers.  A flight of stone steps on the west wall
|-------------/ lead to the upper floor.  To the southeast you see a
small opening and the to the nort is a large enterance.  

now it looks to me that its mostly working, except that format_string is 
eating all the spaces in the map.  So i made a bool case to format_string 
called ignoretilde and had the map function return its map like this:

~/-------------\~ 
~|     [ ]     |~ 
~|      |      |~ 
~| [ [EMAIL PROTECTED]     |~ 
~|        \    |~ 
~|         [ ] |~ 
~|-------------/~

since i know that my string(room desc) wont have any tildes in it, 
then i add this to the for(rdesc = oldstring; *rdesc; rdesc++) 
loop in format string.

ignore = FALSE;

for(rdesc = oldstring; *rdesc; rdesc++)
{
    if( ignoretilde )
    {
        if( *rdesc == '~' )
        {
            ignore = !ignore;
            xbuf[i++] = *rdesc;
            continue;
        }
        else if( ignore )
        {
            xbuf[i++] = *rdesc;
            continue;
        }
    }
    
    /*rest of loop as normal*/



then remembering the tildes are gonna add to the spaces and it will be off 
format i change 
the for(;;) loop so it should keep the tildes in mind and make the lines bigger.

to this:

for( ;; )
{
    int z=0;

    for (i=0; i < (77 + z) ; i++)
    {
      if (!*(rdesc+i))
         break;
      else if(*(rdesc+i) == '~')
      {
         if(ignoretilde)
           z++;
      }
    }
    if (i< (77 + z) )
    {
      break;
    }
    for ( i = ( (xbuf[0]?76:73) + z ) ; i ; i--)
    {
      if (*(rdesc+i)==' ')
         break;
    }
    if (i)
    {
      *(rdesc+i)=0;
      strcat(xbuf,rdesc);
      strcat(xbuf,"\n\r");
      rdesc += i+1;
      while (*rdesc == ' ') rdesc++;
    }
    else
    {
      bug ("No spaces", 0);
      *(rdesc+75+z)=0;
      strcat(xbuf,rdesc);
      strcat(xbuf,"-\n\r");
      rdesc += (76+z);
    }
  }
}


i have a function that removes the tildes afterwards, which is just simple, 
so i threw that at the bottom of insert_string, and compiled, then tested 
it and i got this:


/-------------\ Neat and tidy, with flowers scenting the air, the
|
[ ]     | room is sparsely furnished.  A table sits off to
| [ [EMAIL PROTECTED]     | one |      |      | side,
|        \    | surrounded by three chairs.  A fire glows in the
|
[ ] | kitchens stone oven, and the smell of fresh bread
drifts |-------------/ tantalizingly in the air, mixing with the
delicate aroma of the flowers.  A flight of stone steps on the west wall
lead to the upper floor.  To the southeast you see a small opening and the
to the nort is a large enterance.  


Now i think without the tildes, the first one seems to work fine, except that 
it likes to move the first | on the line before, i think i see that in the 
code, 
but with the additions im completely stumped.  If anyone has any ideas how to 
fix 
my mess of a code, or a better way of doing this, i'd like to hear it.

the only other idea i had was replacing all spaces in the map with tildes, then 
formatting it, then replacing them back, after this email i might try that, but 
this has got me baffled, because im not that great at strings in general.

i -thought- i had the conceptual down, but obviously not.  Also... the 
format_string() function seems to be messed up with color codes... is this 
true?  
Is it that i just need to work on a better format_string function?

thanks in advance... sorry the email was so long...

Josh

Reply via email to