I'm still not quite clear what you're trying to do with this table, but
I did go out and find a function that would do it for you... now in the
test file I created for this, I didn't do the numbering of rows and
columns on the top line and the left margin, I just created a file w/
10x10 rows and columns of different things... it's not very pretty but
it works, if you want to add in the row and column labels, and put a
space in between elements in that array, you'll just have to do a little
math work but it should work out fine... here's what I came up with:

void do_testfseek( CHAR_DATA *ch, char *argument )
{
    FILE *fp;
    char c, arg1[MIL];
    int x,y;
    long offset;

    argument = one_argument(argument, arg1);

    if ( arg1[0] == '\0' || argument[0] == '\0'
    || !is_number(arg1) || !is_number(argument) )
        return;

    x = atoi(arg1);
    y = atoi(argument);

    offset = ((y - 1) * 11) + x - 1;

    if ( ( fp = file_open("../src/testfile.txt","r") ) == NULL )
    {
        file_close(fp);
        return;
    }

    fseek(fp,offset,SEEK_SET);
    c = getc(fp);
    printf_to_char(ch,"%c at %d,%d", c,x,y);
    file_close(fp);
    return;
}

Now, what fseek does is when you open the file, the current location in
the file that's being pointed to is 0, the offset argument that you pass
to fseek is the offset in characters from the point you specify in the
3rd argument (SEEK_SET in this case, which is the head of the file), to
move the location pointer to... example is that you open the file at
location 0, and pass it an offset of 3 (0 indexed), it moves to the 4th
character on the first line... the tricky part would generally be trying
to figure out how to give it an offset that would move it down a
specific number of lines, but knowing in advance that each line would be
10 characters long solves that problem... just remember that it reads an
EOL as a character also, so the length of each line is actually 11 and
not 10... so for the function above, I created a text file with this:

1234567890
abcdefghij
klmnopqrst
uvwxyzABCD
EFGHIJKLMN
OPQRSTUVWX
[EMAIL PROTECTED]&*
()-=_+[]{}
,./<>?;':"
\|`~zyxwvu

and then declared the command in interp.c and interp.h, recompiled,
rebooted the mud, and passed it some test x and y coordinates (with the
top left corner being labeled to me as 1,1, and y's going up as you move
down in the file), so if I typed testfseek 3 5, it printed out a capital
G, test 9 1 returns a 9, test 7 7 returns a %, and so forth... anyway,
hope this helps, you can simply modify the above function to, instead of
being a command function, be something like the following:

char *get_immresvuln( FILE *fp, int x, int y )
{
    etc etc...
}

and return the letter at the coordinates you pass to the function, and
then you could just pass that function the file you plan to use to hold
these tables, and for the x and y coordinate, whatever you're basing
those values on, be it ch->level for x and victim->level for y, or
whatever... you'll probably want to also put in some checks to make sure
nothing goes out of bounds, like if offset > 109, which would put it at
or after the EOL marker on the last line... anyway, hope this all
helps...

Richard Lindsey

-----Original Message-----
From: bLAm flEx TRiStaN ?../? [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 05, 2004 11:34 PM
To: [email protected]
Cc: [EMAIL PROTECTED]
Subject: making the mud read from a grid-like file

I was thinking of a different way to handle vulns/immunes/resists that
could 
be quickly and easily modified, and i can to thinking about having an 
external file, say /data/immsvulnsres.txt or something and in that file
it 
looked like:

  1 2 3 4 5 6 7 8 9 10
1
2     r                 r
3
4              i
5
6             v
7
8      i            v
9
10

and each type represented a number on the x and y axis, and the grid 
basically reads that if theres a 'r' the x axis is not very effective 
against the y axis....'v' is vuln etc...

like you figure out which IMM_/RES_/VULN_ thing represents which number,

then you tell the code to go X spaces to the right and Y lines down...
then 
just fread_letter what it finds
now i don't think this should be too difficult at all, i'm just
wondering if 
anybody can shed some light on the part where you tell it to go X right
and 
Y down

_________________________________________________________________
Free yourself from those irritating pop-up ads with MSn Premium. Get
2months 
FREE*  
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU
=http://hotmail.com/enca&HL=Market_MSNIS_Taglines


-- 
ROM mailing list
[email protected]
http://www.rom.org/cgi-bin/mailman/listinfo/rom

Reply via email to