void InitMap(void) { int i = 0; int iLength = 0; ptagLevelCollection pCollection; iLength = sizeof(level_data_level); theMap = (ptagMap)calloc(1, sizeof(Map)); theMap->iNoOfCollection = 0; theMap->head = NULL; theMap->tail = NULL; theMap->currentLevel = NULL; while( i < iLength ) { if (LineType(i) == LINE_TYPE_COLLECTION_BEGIN) { pCollection = InitACollection(&i); //Insert the struct in the doube list. if (theMap->head == NULL) { theMap->head = pCollection; theMap->tail = theMap->head; pCollection->next = pCollection; pCollection->prev = pCollection; } else { pCollection->next = theMap->tail->next; pCollection->next->prev = pCollection; pCollection->prev = theMap->tail; theMap->tail->next = pCollection; theMap->tail = pCollection; } theMap->iNoOfCollection++; } else GotoNextLine(&i); } theMap->current = theMap->head; for (i = 0; i < BACK_STEP_SIZE; i++) theMap->pSteps[i] = NULL; PlayRestart(); }
//align at alphabit static ptagLevelCollection InitACollection(int * i) { ptagLevelCollection pCollection; char * name; int iNameLength = 0; int j = *i; char a; ptagLevel pLevel; int iLevel = 1; int iType; pCollection = (ptagLevelCollection)calloc(1, sizeof(LevelCollection)); pCollection->iNoOfLevels = 0; pCollection->strName = (char *)calloc(MAX_COLLECTION_NAME, sizeof(char)); name = pCollection->strName; pCollection->head = NULL; pCollection->tail = NULL; assert (LineType(j) == LINE_TYPE_COLLECTION_BEGIN); //first get the name do { a = (char)level_data_level[j]; if((isalpha(a)) || (a == '_')){ name[iNameLength++] = a; j++; } else break; } while(1); GotoNextLine(&j); name[iNameLength] = '\0'; while(1) { iType = LineType(j); if (iType == LINE_TYPE_COLLECTION_BEGIN) break; //finished this collection if (iType == LINE_TYPE_LEVEL_BEGIN){ pLevel = InitALevel(&j); pLevel->iNo = iLevel++; if (pCollection->head == NULL) { pCollection->head = pLevel; pCollection->tail = pCollection->head; pLevel->next = pLevel; pLevel->prev = pLevel; } else { pLevel->next = pCollection->tail->next; pLevel->next->prev = pLevel; pLevel->prev = pCollection->tail; pCollection->tail->next = pLevel; pCollection->tail = pLevel; } pCollection->iNoOfLevels++; } else GotoNextLine(&j); } *i = j; pCollection->current = pCollection->head; return pCollection; }
LineType dc() const { return LineType(d, c); }
//we begin at the begin of a line static ptagLevel InitALevel(int *i) { ptagLevel pLevel; int j = *i; int iLineBegin = 0; int iLineEnd = 0; int iRow = 0; int iCol = 0; char a; int *pInt; int k; int b; assert (LineType(j) == LINE_TYPE_LEVEL_BEGIN); //first decide how many line rows iLineBegin = j; while(1) { //we are now at the begin of the line a = (char)level_data_level[j]; while (a != 0x0a) { if (a == '#') iLineEnd = j; a = (char)level_data_level[++j]; } if (iLineEnd == 0) //There are no '#'s in this line. break; if (iLineEnd -iLineBegin + 1 > iCol) iCol = iLineEnd - iLineBegin + 1; iRow ++; j++; iLineEnd = 0; iLineBegin = j; } //Init a structure pLevel = (ptagLevel)calloc(1, sizeof(Level)); pLevel->row = iRow; pLevel->col = iCol; pLevel->data = (int *)calloc(iRow*iCol, sizeof(int)); pInt = pLevel->data; //set value to pLevel->data j = *i; for(iRow = 0; iRow < pLevel->row; iRow++) { iLineEnd = FindLineEnd(j); for(k = 0; k <= iLineEnd; k++) { b = level_data_level[j++]; switch (b) { case '@': pLevel->manx = k; pLevel->many = iRow; pInt[iRow*iCol+k] = B_MAN; break; case '$': pInt[iRow*iCol+k] = B_OBJECT; break; case '.': pInt[iRow*iCol+k] = B_GOAL; break; case '*': pInt[iRow*iCol+k] = B_TREASURE; break; case '+': pLevel->manx = k; pLevel->many = iRow; pInt[iRow*iCol+k] = B_SAVEMAN; break; case '#': pInt[iRow*iCol+k] = B_STONE; break; default: pInt[iRow*iCol+k] = B_NOTHING; } } for ( ; k < iCol; k++) pInt[iRow*iCol+k] = B_NOTHING; GotoNextLine(&j); } *i = j; return pLevel; }
LineType da() const { return LineType(d, a); }
LineType db() const { return LineType(d, b); }
LineType cb() const { return LineType(c, b); }
LineType cd() const { return LineType(c, d); }
LineType bd() const { return LineType(b, d); }
LineType ca() const { return LineType(c, a); }
LineType bc() const { return LineType(b, c); }
LineType ba() const { return LineType(b, a); }
LineType ad() const { return LineType(a, d); }
LineType ac() const { return LineType(a, c); }
//Tetrahedron specific //edges LineType ab() const { return LineType(a, b); }