50% Packetloss wrote: |
when someone goes into the wormhole they will spectated. |
Code: Show/Hide struct tilerecord
{ unsigned x : 12; unsigned y : 12; unsigned tile : 8; }; |
Code: Show/Hide #pragma pack(1)
struct tilerecord { unsigned int x : 12; unsigned int y : 12; unsigned int tile : 8; }; struct lvlheader { unsigned short type; /* should be 19778, aka 'B' followed by 'M' */ unsigned int lengh; }; #pragma pack() ... stuff goes here, assume now i'm inside a function ready to read the coords off .... char buff[6]; struct tilerecord *tile = (struct tilerecord*)buff; struct lvlheader *header = (struct lvlheader*)buff; /* could use a union, but this is good enough */ FILE *f; f = fopen(LVLFILENAME, "rb"); if (!f) return 0; /* couldn't open file */ if (fread(buff, 6, 1, f)) /* check to see if has bmp data up front */ { if (header->type == 19778) /* yep, has the string "BM" up front */ fseek(f, header->length, SEEK_SET); /* skip forward to end of BMP data */ else /* didn't have header up front, means should be tile info */ fseek(f, 0, SEEK_SET); /* rewind to front again */ } else /* couldn't read 6 bytes, which COULD mean a lvl with only 1 tile, or an empty file */ fseek(f, 0, SEEK_SET); /* We should now be where the tile info is at */ while (fread(buff, 4, 1, f)) { /* keep reading until we cannot read 4 bytes anymore */ if (tile->tile == 220) /* check to see if wormhole */ { /* Do your "found a wormhole" stuff here. * Remember, it only tells the upper-left corner of a wormhole, * so the actual area includes the 4x4 box (i think) to the right/down * of this position. */ } } fclose(f); |
Code: Show/Hide case EVENT_PlayerMove: { Player *p = (Player*)event.p[0]; if ((p->tile.x == blahx) && (p->tile.y == blahy)) //blahs being x and y values of wormhole { sendPublic("Blah"); //command such as *spec } } |
Code: Show/Hide struct tilerecord { unsigned int x : 12; unsigned int y : 12; unsigned int tile : 8; }; struct lvlheader { unsigned short type; /* should be 19778, aka 'B' followed by 'M' */ unsigned int lengh; }; //Simple enough, never seen :12/:8 before but assume they are the number of bits. struct tilerecord *tile = (struct tilerecord*)buff; struct lvlheader *header = (struct lvlheader*)buff; //declare some pointers, typecast them = to the char[6], never typecasted a char to a stuct i made before, but im sure it works //I learned fstream. in school so this stdio.h is new to me but looks about the same idea. if (fread(buff, 6, 1, f)) /* check to see if has bmp data up front */ { if (header->type == 19778) /* yep, has the string "BM" up front */ fseek(f, header->length, SEEK_SET); /* skip forward to end of BMP data */ else /* didn't have header up front, means should be tile info */ fseek(f, 0, SEEK_SET); /* rewind to front again */ } else /* couldn't read 6 bytes, which COULD mean a lvl with only 1 tile, or an empty file */ fseek(f, 0, SEEK_SET); //fread seems to be the same thing as read(), takes in 6 chars, pass it the file, EZ. now the confustion sets in, how did the var header get that info into it? I understand that it points to the char variable that now has the bmp header info in it but its like magic to me that the data hopped into the correct place in the struct variable while (fread(buff, 4, 1, f)) { if (tile->tile == 220) /* check to see if wormhole */ { cout << tile->x << ',' << tile->y; cout << endl; } } fclose(f); //then again its done with the variable tile, how exactly does it take a number such as 251 179 063 220 that would be in buff and magicly turn it into (1019,1019)? |
Code: Show/Hide case EVENT_ArenaSettings: { settings = (arenaSettings*)event.p[0]; ReadLvlFile(); // Grabs wormholes from file, stores in array } |