Mercurial > mm7
changeset 2284:40c4065234f8
Tokenizing ItemsTable::LoadPotions and ItemsTable::LoadPotionNotes()
author | Grumpy7 |
---|---|
date | Sat, 15 Mar 2014 01:32:56 +0100 |
parents | 53d4e8539ca1 |
children | 4fd03103be62 |
files | Items.cpp |
diffstat | 1 files changed, 103 insertions(+), 142 deletions(-) [+] |
line wrap: on
line diff
--- a/Items.cpp Fri Mar 14 23:33:07 2014 +0100 +++ b/Items.cpp Sat Mar 15 01:32:56 2014 +0100 @@ -757,161 +757,122 @@ //----- (00453B3C) -------------------------------------------------------- void ItemsTable::LoadPotions() - { +{ - CHAR Text[90]; // [sp+Ch] [bp-6Ch]@26 - char* test_string; - unsigned int uRow; - unsigned int uColumn; - unsigned __int8 potion_value; + CHAR Text[90]; + char* test_string; + unsigned int uRow; + unsigned int uColumn; + unsigned __int8 potion_value; - if ( pPotionsTXT_Raw ) - free(pPotionsTXT_Raw); - pPotionsTXT_Raw = NULL; - pPotionsTXT_Raw = (char *)pEvents_LOD->LoadRaw("potion.txt", 0); - test_string = strtok(pPotionsTXT_Raw,"\t\r\n"); - while ( 1 ) - { - if ( !test_string ) - { - MessageBoxA(0, "Error Pre-Parsing Potion Table", "Load Error", MB_ICONHAND|MB_CANCELTRYCONTINUE); - return; - } - if ( !strcmp(test_string, "222") ) - break; - - test_string = strtok(NULL, "\t\r\n"); - } - while ( 1 ) - { - test_string = strtok(NULL, "\t\r\n"); - - if ( !test_string ) - { - MessageBoxA(0, "Error Pre-Parsing Potion Table", "Load Error", MB_ICONHAND|MB_CANCELTRYCONTINUE); - return; - } - if ( !strcmp(test_string, "222") ) - break; - } + if ( pPotionNotesTXT_Raw ) + free(pPotionNotesTXT_Raw); + pPotionNotesTXT_Raw = NULL; + auto tokens = Tokenize("", '\t'); + char* pPotionsTXT_Raw = (char *)pEvents_LOD->LoadRaw("potion.txt", 0); + test_string = strtok(pPotionsTXT_Raw ,"\r") + 1; + while (test_string) + { + tokens = Tokenize(test_string, '\t'); + if (!strcmp(tokens[0], "222")) + break; + test_string = strtok(NULL ,"\r") + 1; + } + if (!test_string) + { + MessageBoxA(0, "Error Pre-Parsing Potion Table", "Load Error", MB_ICONHAND|MB_CANCELTRYCONTINUE); + return; + } - for (uRow = 0;uRow < 50; ++uRow) - { - int skip_count; - for (skip_count = 0;skip_count < 6; ++skip_count) - { - if ( !strtok(NULL, "\r\t\n") ) - break; - } - if ( skip_count != 6 ) - break; - for (uColumn = 0; uColumn < 50; ++uColumn) - { - test_string = strtok(NULL, "\r\t\n"); - if ( !test_string ) - break; - potion_value = atoi(test_string); - unsigned char c=*test_string; - if ( !potion_value ) - { - if ( tolower(c) == 'e' ) - potion_value = atoi(test_string + 1); - else - potion_value = 0; - } - this->potion_data[uRow][uColumn]=potion_value; - } - if ( uColumn != 50 ) - break; - strtok(NULL, "\r\t\n"); - } + for (uRow = 0;uRow < 50; ++uRow) + { + if (tokens.size() < 50) + { + wsprintfA(Text, "Error Parsing Potion Table at Row: %d Column: %d", uRow, tokens.size()); + MessageBoxA(0, Text, "Parsing Error", MB_ICONHAND|MB_CANCELTRYCONTINUE); + return; + } + for (uColumn = 0; uColumn < 50; ++uColumn) + { + char* currValue = tokens[uColumn + 7]; + potion_value = atoi(currValue); + if ( !potion_value && tolower(currValue[0]) == 'e') + { + potion_value = atoi(currValue + 1); + } + this->potion_data[uRow][uColumn]=potion_value; + } - if ( uRow != 50 ) - { - wsprintfA(Text, "Error Parsing Potion Table at Row: %d Column: %d", uRow, uColumn); - MessageBoxA(0, Text, "Parsing Error", MB_ICONHAND|MB_CANCELTRYCONTINUE); - } - if ( pPotionsTXT_Raw ) - { - free(pPotionsTXT_Raw); - pPotionsTXT_Raw = 0; - } - } + test_string = strtok(NULL ,"\r") + 1; + if (!test_string) + { + wsprintfA(Text, "Error Parsing Potion Table at Row: %d Column: %d", uRow, 0); + MessageBoxA(0, Text, "Parsing Error", MB_ICONHAND|MB_CANCELTRYCONTINUE); + return; + } + tokens = Tokenize(test_string, '\t'); + } +} //----- (00453CE5) -------------------------------------------------------- void ItemsTable::LoadPotionNotes() - { +{ - CHAR Text[90]; - char* test_string; - unsigned int uRow; - unsigned int uColumn; - unsigned __int8 potion_note; + CHAR Text[90]; + char* test_string; + unsigned int uRow; + unsigned int uColumn; + unsigned __int8 potion_note; if ( pPotionNotesTXT_Raw ) free(pPotionNotesTXT_Raw); pPotionNotesTXT_Raw = NULL; - pPotionNotesTXT_Raw = (char *)pEvents_LOD->LoadRaw("potnotes.txt", 0); - test_string = strtok(pPotionNotesTXT_Raw ,"\t\r\n"); - while ( 1 ) - { - if ( !test_string ) - { - MessageBoxA(0, "Error Pre-Parsing Potion Table", "Load Error", MB_ICONHAND|MB_CANCELTRYCONTINUE); - return; - } - if ( !strcmp(test_string, "222") ) - break; - test_string = strtok(NULL, "\t\r\n"); - } - while ( 1 ) - { - test_string = strtok(NULL, "\t\r\n"); - - if ( !test_string ) - { - MessageBoxA(0, "Error Pre-Parsing Potion Table", "Load Error", MB_ICONHAND|MB_CANCELTRYCONTINUE); - return; - } - if ( !strcmp(test_string, "222") ) - break; - } + auto tokens = Tokenize("", '\t'); + char* pPotionNotesTXT_Raw = (char *)pEvents_LOD->LoadRaw("potnotes.txt", 0); + test_string = strtok(pPotionNotesTXT_Raw ,"\r") + 1; + while (test_string) + { + tokens = Tokenize(test_string, '\t'); + if (!strcmp(tokens[0], "222")) + break; + test_string = strtok(NULL ,"\r") + 1; + } + if (!test_string) + { + MessageBoxA(0, "Error Pre-Parsing Potion Table", "Load Error", MB_ICONHAND|MB_CANCELTRYCONTINUE); + return; + } - for (uRow = 0;uRow < 50; ++uRow) - { - int skip_count; - for (skip_count = 0;skip_count < 6; ++skip_count) - { - if ( !strtok(NULL, "\r\t\n") ) - break; - } - if ( skip_count != 6 ) - break; - for (uColumn = 0; uColumn < 50; ++uColumn) - { - test_string = strtok(NULL, "\r\t\n"); - if ( !test_string ) - break; - potion_note = atoi(test_string); - unsigned char c=*test_string; - if ( !potion_note ) - { - if ( tolower(c) == 'e' ) - potion_note = atoi(test_string + 1); - else - potion_note = 0; - } - this->potion_note[uRow][uColumn]=potion_note; - } - if ( uColumn != 50 ) - break; - strtok(NULL, "\r\t\n"); - } - if ( uRow != 50 ) - { - wsprintfA(Text, "Error Parsing Potion Table at Row: %d Column: %d", uRow, uColumn); - MessageBoxA(0, Text, "Parsing Error", MB_ICONHAND|MB_CANCELTRYCONTINUE); - } + for (uRow = 0;uRow < 50; ++uRow) + { + if (tokens.size() < 50) + { + wsprintfA(Text, "Error Parsing Potion Table at Row: %d Column: %d", uRow, tokens.size()); + MessageBoxA(0, Text, "Parsing Error", MB_ICONHAND|MB_CANCELTRYCONTINUE); + return; + } + for (uColumn = 0; uColumn < 50; ++uColumn) + { + char* currValue = tokens[uColumn + 7]; + potion_note = atoi(currValue); + if ( !potion_note && tolower(currValue[0]) == 'e') + { + potion_note = atoi(currValue + 1); + } + this->potion_note[uRow][uColumn]=potion_note; + } + + test_string = strtok(NULL ,"\r") + 1; + if (!test_string) + { + wsprintfA(Text, "Error Parsing Potion Table at Row: %d Column: %d", uRow, 0); + MessageBoxA(0, Text, "Parsing Error", MB_ICONHAND|MB_CANCELTRYCONTINUE); + return; + } + tokens = Tokenize(test_string, '\t'); + } + + }