Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned char** MapIndexTileset = NULL;
- unsigned char** MapIndexNPCSheet = NULL;
- unsigned char** MapIndexBackgroundImage = NULL;
- unsigned char** MapIndexName = NULL;
- unsigned char** CurrentMapIndex = NULL;
- unsigned char* MapIndexBackgroundNum = NULL;
- unsigned char* MapIndexForegroundNum = NULL;
- int* MapIndexWaterLevel = NULL;
- unsigned char* MapIndexWaterScale = NULL;
- /*struct MapIndexData {
- unsigned char BackgroundNum;
- unsigned char ForegroundNum;
- unsigned char WaterScale;
- int WaterLevel;
- } *MapIndexData
- MapIntexData* Map
- */
- void LoadMapDataFromFile(void) {
- printf("importing MapData File!\n");
- char MapDataString[50];
- snprintf(MapDataString, sizeof(MapDataString), "data/Maplist");
- FILE *mapdatafile = fopen(MapDataString, "rb");
- fseek(mapdatafile, 0, SEEK_END);
- mapdata_file_size = ftell(mapdatafile);
- rewind(mapdatafile);
- //grab first 2 bytes from file to know how many maps there are
- unsigned char byte1 = fgetc(mapdatafile);
- unsigned char byte2 = fgetc(mapdatafile);
- int MapsInFile = (byte1 << 8) | byte2;
- //close file
- mapdata_buffer = (unsigned char*)malloc(mapdata_file_size - 2);
- fread(mapdata_buffer, 1, mapdata_file_size - 2, mapdatafile);
- fclose(mapdatafile);
- //make malloc of unsigned char pointers to point to each string
- int BufferLoc = 0;
- MapIndexTileset = malloc(sizeof(unsigned char*) * MapsInFile);
- MapIndexNPCSheet = malloc(sizeof(unsigned char*) * MapsInFile);
- MapIndexBackgroundImage = malloc(sizeof(unsigned char*) * MapsInFile);
- MapIndexName = malloc(sizeof(unsigned char*) * MapsInFile);
- MapIndexBackgroundNum = malloc(sizeof(unsigned char) * MapsInFile);
- MapIndexForegroundNum = malloc(sizeof(unsigned char) * MapsInFile);
- MapIndexWaterLevel = malloc(sizeof(int) * MapsInFile);
- MapIndexWaterScale = malloc(sizeof(unsigned char) * MapsInFile);
- //printf("There are %d Maps in the Maplist.\n", MapsInFile);
- for (int TimesLooped = 0; TimesLooped < MapsInFile; TimesLooped++) {
- for (unsigned char StringType = 0; StringType < 4; StringType++) {
- //printf("Loading String Type %d.\n", StringType);
- switch (StringType) {
- case 0:;
- CurrentMapIndex = MapIndexTileset;
- break;
- case 1:;
- CurrentMapIndex = MapIndexNPCSheet;
- break;
- case 2:;
- CurrentMapIndex = MapIndexBackgroundImage;
- break;
- case 3:;
- CurrentMapIndex = MapIndexName;
- break;
- default:;
- printf("ERROR, UNKNOWN KIND OF STRING TYPE ON MAP FILE LOAD!\n");
- break;
- }
- unsigned char SizeOfString = 0;
- while (mapdata_buffer[BufferLoc+SizeOfString] != 0) {
- SizeOfString++;
- }
- //printf("Size of this String is %d.\n", SizeOfString);
- //make malloc for the pointer
- unsigned char** ThisCharString = malloc(SizeOfString * sizeof(unsigned char));
- //put pointer to the data in the index
- CurrentMapIndex[TimesLooped] = *ThisCharString;
- //dump the data from buffer into malloc, including termination character
- int c;
- for (c = 0; c < SizeOfString+1; c++) {
- ThisCharString[c] = mapdata_buffer[BufferLoc+c];
- if (ThisCharString[c] != 0) {
- //printf("loaded character %c into a character string!\n", ThisCharString[c]);
- }
- else {
- //printf("termination character found.\n");
- }
- }
- //the +1 above is to pass the termination character in the file
- BufferLoc += c;
- SizeOfString = 0;
- }
- //put rest of data for BK number, FG number, Water level and water scaling into their arrays.
- MapIndexBackgroundNum[TimesLooped] = mapdata_buffer[BufferLoc];
- BufferLoc++;
- MapIndexForegroundNum[TimesLooped] = mapdata_buffer[BufferLoc];
- BufferLoc++;
- unsigned char byte1 = mapdata_buffer[BufferLoc];
- unsigned char byte2 = mapdata_buffer[BufferLoc+1];
- MapIndexWaterLevel[TimesLooped] = (byte2 << 8) | byte1;
- BufferLoc += 2;
- MapIndexWaterScale[TimesLooped] = mapdata_buffer[BufferLoc];
- BufferLoc++;
- //printf("Map %d's mapdata loaded into memory!\n", TimesLooped);
- }
- }
- void LoadMapSpritesheets(void) {
- ResetBackgrounds();
- LoadBackground(MapIndexBackgroundNum[MapNumber], 0);
- LoadBackground(MapIndexForegroundNum[MapNumber], 1);
- WaterHeight = *MapIndexWaterLevel * 0x20;
- WaterHeight -= (0x200*10);
- WaterScalingOffset = *MapIndexWaterScale;
- printf("loading tileset %s....\n", MapIndexTileset[MapNumber]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement