#include "ga_arena.hpp" #include "ga_trig.hpp" #ifdef _AS_VERSION_PC #include #include #include #include #include #endif extern int errno; int globalError; AsArenaBuilder::AsArenaBuilder() { vertices = 0; panels = 0; int level, row, column; for (level = 0; level < AS_MAP_LEVELS; level++) { for (row = 0; row < AS_MAP_ROWS; row++) { for (column = 0; column < AS_MAP_COLUMNS; column++) { for (int i = 0; i < 4; i++) //mapArray[level][row][column].adjacentLevelNumber[i] = 0; mapArray[level][row][column].adjacentBlock[i] = 0; mapArray[level][row][column].isRoom = 0; mapArray[level][row][column].stairInfo = 0; mapArray[level][row][column].available1 = 0; // unused at the moment mapArray[level][row][column].available2 = 0; } } } levelsInMap[0] = 1; levelsInMap[1] = 4; } /* void AsArenaBuilder::CountItems() { int level, row, column; for (level = 0; level < AS_MAP_LEVELS; level++) { for (row = 0; row < AS_MAP_ROWS; row++) { for (column = 0; column < AS_MAP_COLUMNS; column++) { if (!mapArray[level][row][column].isRoom) continue; // no room so nothing to add //* for (int i = 0; i < 4; i++) // add a panel where no adjacent level if (!mapArray[level][row][column].adjacentLevelNumber[i]) panels++; if (mapArray[level][row][column].stairInfo) // add a panel if stairs //if (0) // add a panel if stairs panels++; // could allow possiblity of stairs on other side - need to change composition of the variable else panels += 2; // ceiling and floor if no stairs } } } vertices = panels * 4; } */ void AsArenaBuilder::CountItems2() { int level, row, column; for (level = 0; level < AS_MAP_LEVELS; level++) { for (row = 0; row < AS_MAP_ROWS; row++) { for (column = 0; column < AS_MAP_COLUMNS; column++) { if (!mapArray[level][row][column].isRoom) continue; // no room so nothing to add //* //*/ if (mapArray[level][row][column].stairInfo) // add a panel if stairs //if (0) // add a panel if stairs panels +=4; // could allow possiblity of stairs on other side - need to change composition of the variable else { for (int i = 0; i < 4; i++) // add a panel where no adjacent level { if (!mapArray[level][row][column].adjacentBlock[i]) panels++; } panels += 2; // ceiling and floor if no stairs } } } } vertices = panels * 4; } #ifdef _AS_VERSION_PC /* void AsArenaBuilder::ReadMap(char *filename) { FILE *infile; int level, row, column; int fileLevel, fileRow, fileColumn, fileRoom, fileStairInfo; int fileLevels[4]; if ( ( infile = fopen ( filename, "rt" ) ) == 0 ) return ; for (level = 0; level < AS_MAP_LEVELS; level++) { for (row = 0; row < AS_MAP_ROWS; row++) { for (column = 0; column < AS_MAP_COLUMNS; column++) { // First ensure that level, row and column are correct fscanf(infile,"%d%d%d",&fileLevel, &fileRow, &fileColumn); if ((fileLevel - (level + AS_MAP_LEVEL_OFFSET)) || (fileRow - row) || (fileColumn - column)) globalError = fileLevel + (100 * fileRow) + (10000 * fileColumn); // Get isRoom fscanf(infile,"%d",&fileRoom); mapArray[level][row][column].isRoom = fileRoom; if (!fileRoom) continue; // if no room, no details follow // Get adjacent level numbers fscanf(infile,"%d%d%d%d",&(fileLevels[0]),&(fileLevels[1]),&(fileLevels[2]),&(fileLevels[3])); for (int i = 0; i < 4; i++) mapArray[level][row][column].adjacentLevelNumber[i] = fileLevels[i]; // Get stairType fscanf(infile,"%d",&fileStairInfo); mapArray[level][row][column].stairInfo = fileStairInfo; if (!fileStairInfo) continue; // if no stair, no details follow // Get stair information fscanf(infile,"%d",&fileStairInfo); // stair top or bottom mapArray[level][row][column].stairInfo |= fileStairInfo << 1; fscanf(infile,"%d",&fileStairInfo); // stair direction mapArray[level][row][column].stairInfo |= fileStairInfo << 2; } } } fclose ( infile ); CountItems(); int file1 = open ( "c:\\programs\\games\\game1\\pc\\data\\map.bin", O_WRONLY | O_CREAT | O_BINARY , S_IREAD|S_IWRITE); perror("Error:"); write(file1,mapArray,800);//sizeof(mapArray)); close(file1); } */ void AsArenaBuilder::ReadMap2(char *filename) { FILE *infile; int level, row, column; int fileLevel, fileRow, fileColumn, fileRoom, fileStairInfo; int fileLevels[4]; int blocks[AS_MAP_LEVELS][AS_MAP_ROWS][AS_MAP_COLUMNS]; int stair[AS_MAP_LEVELS][AS_MAP_ROWS][AS_MAP_COLUMNS]; totalLinks = 2; // array starts at 2, index is given by value in adjacentBlock if ( ( infile = fopen ( filename, "rt" ) ) == 0 ) return ; char temp; int numberOfLevels = 1; // read in blocks for (level = 0; level < numberOfLevels; level++) //for (level = 0; level < AS_MAP_LEVELS; level++) { for (row = 0; row < AS_MAP_ROWS; row++) { for (column = 0; column < AS_MAP_COLUMNS; column++) { fscanf(infile,"%d",&mapArray[level][row][column].isRoom); } } } // create adjacent block array (not including stairs or links) for (level = 0; level < numberOfLevels; level++) //for (level = 0; level < AS_MAP_LEVELS; level++) { for (row = 0; row < AS_MAP_ROWS; row++) { for (column = 0; column < AS_MAP_COLUMNS; column++) { if (!(mapArray[level][row][column].isRoom)) continue; if (row == 0) mapArray[level][row][column].adjacentBlock[AS_MAP_UP] = 0; else mapArray[level][row][column].adjacentBlock[AS_MAP_UP] = 1 && mapArray[level][row - 1][column].isRoom; if (row == (AS_MAP_ROWS - 1)) mapArray[level][row][column].adjacentBlock[AS_MAP_DOWN] = 0; else mapArray[level][row][column].adjacentBlock[AS_MAP_DOWN] = 1 && mapArray[level][row + 1][column].isRoom; if (column == 0) mapArray[level][row][column].adjacentBlock[AS_MAP_LEFT] = 0; else mapArray[level][row][column].adjacentBlock[AS_MAP_LEFT] = 1 && mapArray[level][row][column - 1].isRoom; if (column == (AS_MAP_COLUMNS - 1)) mapArray[level][row][column].adjacentBlock[AS_MAP_RIGHT] = 0; else mapArray[level][row][column].adjacentBlock[AS_MAP_RIGHT] = 1 && mapArray[level][row][column + 1].isRoom; } } } // read in stairs for (level = 0; level < numberOfLevels; level++) //for (level = 0; level < AS_MAP_LEVELS; level++) { for (row = 0; row < AS_MAP_ROWS; row++) { for (column = 0; column < AS_MAP_COLUMNS; column++) { // Get stairType //fscanf(infile,"%d",&mapArray[level][row][column].stairInfo); fscanf(infile,"%d",&temp); mapArray[level][row][column].stairInfo = temp; //stair[level][row][column] = temp; } } } // read in links int x1,y1,z1,directionOutOf,directionInto,x2,y2,z2; while(1) { fscanf(infile,"%d%d%d",&y1,&x1,&z1); if ((x1 + y1 + z1) == 0) break; fscanf(infile,"%d%d%d%d%d",&directionOutOf,&directionInto,&y2,&x2,&z2); mapArray[y1][x1][z1].adjacentBlock[directionOutOf] = totalLinks; links[totalLinks].x = x2; links[totalLinks].y = y2; links[totalLinks].z = z2; links[totalLinks].direction = directionInto; totalLinks++; } // finish fclose ( infile ); CountItems2(); int file1 = open ( "c:\\programs\\games\\game1\\pc\\data\\map.bin", O_WRONLY | O_CREAT | O_BINARY , S_IREAD|S_IWRITE); perror("Error:"); //write(file1,mapArray,levelsInMap[gameManager.mapNumber] * AS_MAP_ROWS * AS_MAP_COLUMNS * 8);//sizeof(mapArray)); write(file1,mapArray,AS_MAP_LEVELS * AS_MAP_ROWS * AS_MAP_COLUMNS * 8);//sizeof(mapArray)); //write(file1,mapArray,numberOfLevels * AS_MAP_ROWS * AS_MAP_COLUMNS * 8);//sizeof(mapArray)); write(file1,links,AS_MAX_LINKS * 4); close(file1); } void AsArenaBuilder::ReadBinaryMap() { //int size = sizeof(mapArray[0][0][0]); //size = 8*4*5*5; //int file1 = open ( "c:\\programs\\games\\game1\\pc\\data\\map.bin", O_RDONLY | O_BINARY); int file1 = open ( "data\\map.bin", O_RDONLY | O_BINARY); read(file1,mapArray,AS_MAP_LEVELS * AS_MAP_ROWS * AS_MAP_COLUMNS * 8); int numberOfLevels = 1; //read(file1,mapArray,numberOfLevels * AS_MAP_ROWS * AS_MAP_COLUMNS * 8); read(file1,links,AS_MAX_LINKS * 4); close(file1); CountItems2(); } #else void AsArenaBuilder::ReadBinaryMap(void *lModelAddress,int mapNumber) { char *ptr = (char *)lModelAddress; int level, row, column, link; //for (level = 0; level < AS_MAP_LEVELS; level++) for (level = 0; level < levelsInMap[mapNumber]; level++) { for (row = 0; row < AS_MAP_ROWS; row++) { for (column = 0; column < AS_MAP_COLUMNS; column++) { for (int i = 0; i < 4; i++) mapArray[level][row][column].adjacentBlock[i] = *ptr++; // mapArray[level][row][column].adjacentLevelNumber[i] = *ptr++; mapArray[level][row][column].isRoom = *ptr++; mapArray[level][row][column].stairInfo = *ptr++; mapArray[level][row][column].available1 = *ptr++; // unused at the moment mapArray[level][row][column].available2 = *ptr++; } } } for (link = 0; link < AS_MAX_LINKS; link++) { links[link].x = *ptr++; links[link].y = *ptr++; links[link].z = *ptr++; links[link].direction = *ptr++; } CountItems2(); } #endif /* int AsArenaBuilder::GetRooms(int level,int row,int column) { AsMapArrayElement *mapArray; int roomsToCreate = 0; mapArray = GetMapArray(level,row,column); //* if (!mapArray->adjacentLevelNumber[0]) roomsToCreate |= 0x01; // up if (!mapArray->adjacentLevelNumber[1]) roomsToCreate |= 0x02; // down if (!mapArray->adjacentLevelNumber[2]) roomsToCreate |= 0x04; // left if (!mapArray->adjacentLevelNumber[3]) roomsToCreate |= 0x08; // right if (mapArray->stairInfo) // stairs //if (0) // stairs { if (mapArray->stairInfo & 0x02) // Top of stairs, panel faces down { if (mapArray->stairInfo & 0x04) // Right to left, or up to down { if ((mapArray->adjacentLevelNumber[0]) && (mapArray->adjacentLevelNumber[1])) roomsToCreate |= 0x10; // up to down, facing down else roomsToCreate |= 0x20; // right to left, facing down } else // left to right, or down to up { if ((mapArray->adjacentLevelNumber[0]) && (mapArray->adjacentLevelNumber[1])) roomsToCreate |= 0x40; // down to up, facing down else roomsToCreate |= 0x80; // left to right, facing down } } else // Bottom of stairs, panel faces up { if (mapArray->stairInfo & 0x04) // Right to left, or up to down { if ((mapArray->adjacentLevelNumber[0]) && (mapArray->adjacentLevelNumber[1])) roomsToCreate |= 0x100; // up to down, facing up else roomsToCreate |= 0x200; // right to left, facing up } else // left to right, or down to up { if ((mapArray->adjacentLevelNumber[0]) && (mapArray->adjacentLevelNumber[1])) roomsToCreate |= 0x400; // down to up, facing up else roomsToCreate |= 0x800; // left to right, facing up } } } else // no stairs, but ceiling and floor { roomsToCreate |= 0x1000; roomsToCreate |= 0x2000; } return(roomsToCreate); } */ int AsArenaBuilder::GetRooms2(int level,int row,int column) { AsMapArrayElement *mapArray; int roomsToCreate = 0; mapArray = GetMapArray(level,row,column); switch(mapArray->stairInfo) { case AS_MAP_STAIRS_LEFTTORIGHT: roomsToCreate |= 0x200; break; // left to right, facing up case AS_MAP_STAIRS_RIGHTTOLEFT: roomsToCreate |= 0x80; break; // right to left, facing up case AS_MAP_STAIRS_UPTODOWN: roomsToCreate |= 0x40; break; // up to down, facing up case AS_MAP_STAIRS_DOWNTOUP: roomsToCreate |= 0x100; break; // down to up, facing up default: { if (!mapArray->adjacentBlock[0]) roomsToCreate |= 0x01; // up if (!mapArray->adjacentBlock[1]) roomsToCreate |= 0x02; // down if (!mapArray->adjacentBlock[2]) roomsToCreate |= 0x04; // left if (!mapArray->adjacentBlock[3]) roomsToCreate |= 0x08; // right roomsToCreate |= 0x10; roomsToCreate |= 0x20; } } return(roomsToCreate); } /* void AsArenaBuilder::GroundSearch(int baseY,int level,int row,int column, int direction, int length, int recurse, int depth) { int sx, sz; int count, adjacentLevel, currentLevel,lastLevel,variableBaseY; depth--; switch(direction) { case 0: // horiz { // left sz = column; currentLevel = level; variableBaseY = baseY; count = length; adjacentLevel = mapArray[level][row][sz].adjacentLevelNumber[AS_MAP_LEFT]; while(adjacentLevel && count) { lastLevel = currentLevel; currentLevel = adjacentLevel - AS_MAP_LEVEL_OFFSET; if (currentLevel == lastLevel) sz--; //else // variableBaseY += (currentLevel - lastLevel) * AS_MAP_ROOM_LENGTH; if (mapArray[currentLevel][row][sz].stairInfo) { if ((mapArray[currentLevel][row][sz].stairInfo & 0x02) && (mapArray[currentLevel][row][sz].stairInfo & 0x04)) variableBaseY += AS_MAP_ROOM_LENGTH; // top of stairs and right to left if ((!(mapArray[currentLevel][row][sz].stairInfo & 0x02)) && (!(mapArray[currentLevel][row][sz].stairInfo & 0x04))) variableBaseY -= AS_MAP_ROOM_LENGTH; // bottom of stairs and left to right } visualMap[currentLevel][row][sz] = 1; visualY[currentLevel][row][sz] = variableBaseY; if (recurse && depth) { if (sz == (column - 1)) GroundSearch(variableBaseY,currentLevel,row,sz,1,AS_MAX_SEARCH,1,depth); else GroundSearch(variableBaseY,currentLevel,row,sz,1,1,0,depth); } count--; adjacentLevel = mapArray[currentLevel][row][sz].adjacentLevelNumber[AS_MAP_LEFT]; } // right sz = column; currentLevel = level; variableBaseY = baseY; count = length; adjacentLevel = mapArray[level][row][sz].adjacentLevelNumber[AS_MAP_RIGHT]; while(adjacentLevel && count) { lastLevel = currentLevel; currentLevel = adjacentLevel - AS_MAP_LEVEL_OFFSET; if (currentLevel == lastLevel) sz++; //else // variableBaseY += (currentLevel - lastLevel) * AS_MAP_ROOM_LENGTH; if (mapArray[currentLevel][row][sz].stairInfo) { if ((mapArray[currentLevel][row][sz].stairInfo & 0x02) && (!(mapArray[currentLevel][row][sz].stairInfo & 0x04))) variableBaseY += AS_MAP_ROOM_LENGTH; // top of stairs and left to right if ((!(mapArray[currentLevel][row][sz].stairInfo & 0x02)) && (mapArray[currentLevel][row][sz].stairInfo & 0x04)) variableBaseY -= AS_MAP_ROOM_LENGTH; // bottom of stairs and right to left } visualMap[currentLevel][row][sz] = 1; visualY[currentLevel][row][sz] = variableBaseY; if (recurse && depth) { if (sz == (column + 1)) GroundSearch(variableBaseY,currentLevel,row,sz,1,AS_MAX_SEARCH,1,depth); else GroundSearch(variableBaseY,currentLevel,row,sz,1,1,0,depth); } count--; adjacentLevel = mapArray[currentLevel][row][sz].adjacentLevelNumber[AS_MAP_RIGHT]; } break; } case 1: // vert { // up sx = row; currentLevel = level; variableBaseY = baseY; count = length; adjacentLevel = mapArray[level][sx][column].adjacentLevelNumber[AS_MAP_UP]; while(adjacentLevel && count) { lastLevel = currentLevel; currentLevel = adjacentLevel - AS_MAP_LEVEL_OFFSET; if (currentLevel == lastLevel) sx--; //else // variableBaseY += (currentLevel - lastLevel) * AS_MAP_ROOM_LENGTH; if (mapArray[currentLevel][sx][column].stairInfo) { if ((mapArray[currentLevel][sx][column].stairInfo & 0x02) && (!(mapArray[currentLevel][sx][column].stairInfo & 0x04))) variableBaseY += AS_MAP_ROOM_LENGTH; // top of stairs and down to up if ((!(mapArray[currentLevel][sx][column].stairInfo & 0x02)) && (mapArray[currentLevel][sx][column].stairInfo & 0x04)) variableBaseY -= AS_MAP_ROOM_LENGTH; // bottom of stairs and up to down } visualMap[currentLevel][sx][column] = 1; visualY[currentLevel][sx][column] = variableBaseY; if (recurse && depth) { if (sx == (row - 1)) GroundSearch(variableBaseY,currentLevel,sx,column,0,AS_MAX_SEARCH,1,depth); else GroundSearch(variableBaseY,currentLevel,sx,column,0,1,0,depth); } count--; adjacentLevel = mapArray[currentLevel][sx][column].adjacentLevelNumber[AS_MAP_UP]; } // down sx = row; currentLevel = level; variableBaseY = baseY; count = length; adjacentLevel = mapArray[level][sx][column].adjacentLevelNumber[AS_MAP_DOWN]; while(adjacentLevel && count) { lastLevel = currentLevel; currentLevel = adjacentLevel - AS_MAP_LEVEL_OFFSET; if (currentLevel == lastLevel) sx++; //else // variableBaseY += (currentLevel - lastLevel) * AS_MAP_ROOM_LENGTH; if (mapArray[currentLevel][sx][column].stairInfo) { if ((mapArray[currentLevel][sx][column].stairInfo & 0x02) && (mapArray[currentLevel][sx][column].stairInfo & 0x04)) variableBaseY += AS_MAP_ROOM_LENGTH; // top of stairs and up to down if ((!(mapArray[currentLevel][sx][column].stairInfo & 0x02)) && (!(mapArray[currentLevel][sx][column].stairInfo & 0x04))) variableBaseY -= AS_MAP_ROOM_LENGTH; // bottom of stairs and down to up } visualMap[currentLevel][sx][column] = 1; visualY[currentLevel][sx][column] = variableBaseY; if (recurse && depth) { if (sx == (row + 1)) GroundSearch(variableBaseY,currentLevel,sx,column,0,AS_MAX_SEARCH,1,depth); else GroundSearch(variableBaseY,currentLevel,sx,column,0,1,0,depth); } count--; adjacentLevel = mapArray[currentLevel][sx][column].adjacentLevelNumber[AS_MAP_DOWN]; } break; } } } */ int AsArenaBuilder::ConvertDirection(int oldDirection,int rotation) { switch (oldDirection) { case AS_MAP_UP: { switch(rotation) { case 0: return(AS_MAP_UP); case AS_DEGREES_90: return(AS_MAP_LEFT); case AS_DEGREES_180: return(AS_MAP_DOWN); case AS_DEGREES_270: return(AS_MAP_RIGHT); } break; } case AS_MAP_DOWN: { switch(rotation) { case 0: return(AS_MAP_DOWN); case AS_DEGREES_90: return(AS_MAP_RIGHT); case AS_DEGREES_180: return(AS_MAP_UP); case AS_DEGREES_270: return(AS_MAP_LEFT); } break; } case AS_MAP_LEFT: { switch(rotation) { case 0: return(AS_MAP_LEFT); case AS_DEGREES_90: return(AS_MAP_DOWN); case AS_DEGREES_180: return(AS_MAP_RIGHT); case AS_DEGREES_270: return(AS_MAP_UP); } break; } case AS_MAP_RIGHT: { switch(rotation) { case 0: return(AS_MAP_RIGHT); case AS_DEGREES_90: return(AS_MAP_UP); case AS_DEGREES_180: return(AS_MAP_LEFT); case AS_DEGREES_270: return(AS_MAP_DOWN); } break; } } return(oldDirection); } int AsArenaBuilder::GetRotation(int direction, int newDirection) { switch (direction) { case AS_MAP_UP: { switch(newDirection) { case AS_MAP_DOWN: return(AS_DEGREES_180); case AS_MAP_LEFT: return(AS_DEGREES_90); case AS_MAP_RIGHT: return(AS_DEGREES_270); } break; } case AS_MAP_DOWN: { switch(newDirection) { case AS_MAP_UP: return(AS_DEGREES_180); case AS_MAP_LEFT: return(AS_DEGREES_270); case AS_MAP_RIGHT: return(AS_DEGREES_90); } break; } case AS_MAP_LEFT: { switch(newDirection) { case AS_MAP_UP: return(AS_DEGREES_270); case AS_MAP_DOWN: return(AS_DEGREES_90); case AS_MAP_RIGHT: return(AS_DEGREES_180); } break; } case AS_MAP_RIGHT: { switch(newDirection) { case AS_MAP_UP: return(AS_DEGREES_90); case AS_MAP_DOWN: return(AS_DEGREES_270); case AS_MAP_LEFT: return(AS_DEGREES_180); } break; } } } void AsArenaBuilder::GroundSearch2(int baseX,int baseY,int baseZ,int level,int row,int column, int direction, int length, int type,int oldDirection,int rotation) // int direction, int length, int type,int oldDirection,int originalDirection,int rotation) { int sx, sy, sz; int count, adjacentBlock,currentBlockStairStatus,lastBlockStairStatus; int variableBaseX,variableBaseY,variableBaseZ; int rowChange,colChange; AsMapLink link; int replicate; int newDirection; int newRotation = 0; sy = level; sx = row; sz = column; variableBaseX = baseX; variableBaseY = baseY; variableBaseZ = baseZ; count = length; adjacentBlock = mapArray[sy][sx][sz].adjacentBlock[direction]; lastBlockStairStatus = mapArray[sy][sx][sz].stairInfo; while(adjacentBlock && count) { /* rowChange = 0; colChange = 0; switch(direction) { case AS_MAP_UP: rowChange = -1; break; case AS_MAP_DOWN: rowChange = 1; break; case AS_MAP_LEFT: colChange = -1; break; case AS_MAP_RIGHT: colChange = 1; break; } */ // Obtain adjacentBlock - either a straightforward adjacent block or a link if (adjacentBlock == 1) // values > 1 indicate a link { /* sx += rowChange; sz += colChange; */ switch(direction) { case AS_MAP_UP: sx--; break; case AS_MAP_DOWN: sx++; break; case AS_MAP_LEFT: sz--; break; case AS_MAP_RIGHT: sz++; break; } } else // a link { link = links[adjacentBlock]; sx = link.x; sy = link.y; sz = link.z; newDirection = link.direction; if (newDirection != direction) { newRotation = GetRotation(direction, newDirection); oldDirection = ConvertDirection(oldDirection,newRotation); rotation = (rotation + newRotation) % AS_DEGREES_360; direction = newDirection; } } // Determine whether the baseY needs to be adjusted - depends on stairs currentBlockStairStatus = mapArray[sy][sx][sz].stairInfo; switch(direction) // this could be optimised but it would be difficult to follow { case AS_MAP_UP: { if (currentBlockStairStatus == AS_MAP_STAIRS_UPTODOWN) variableBaseY -= AS_MAP_ROOM_LENGTH; if (lastBlockStairStatus == AS_MAP_STAIRS_DOWNTOUP) variableBaseY += AS_MAP_ROOM_LENGTH; switch(rotation) { case 0: variableBaseX -= AS_MAP_ROOM_LENGTH; break; case AS_DEGREES_90: variableBaseZ += AS_MAP_ROOM_LENGTH; break; case AS_DEGREES_180: variableBaseX += AS_MAP_ROOM_LENGTH; break; case AS_DEGREES_270: variableBaseZ -= AS_MAP_ROOM_LENGTH; break; } break; } case AS_MAP_DOWN: { if (currentBlockStairStatus == AS_MAP_STAIRS_DOWNTOUP) variableBaseY -= AS_MAP_ROOM_LENGTH; if (lastBlockStairStatus == AS_MAP_STAIRS_UPTODOWN) variableBaseY += AS_MAP_ROOM_LENGTH; switch(rotation) { case 0: variableBaseX += AS_MAP_ROOM_LENGTH; break; case AS_DEGREES_90: variableBaseZ -= AS_MAP_ROOM_LENGTH; break; case AS_DEGREES_180: variableBaseX -= AS_MAP_ROOM_LENGTH; break; case AS_DEGREES_270: variableBaseZ += AS_MAP_ROOM_LENGTH; break; } break; } case AS_MAP_LEFT: { if (currentBlockStairStatus == AS_MAP_STAIRS_LEFTTORIGHT) variableBaseY -= AS_MAP_ROOM_LENGTH; if (lastBlockStairStatus == AS_MAP_STAIRS_RIGHTTOLEFT) variableBaseY += AS_MAP_ROOM_LENGTH; switch(rotation) { case 0: variableBaseZ -= AS_MAP_ROOM_LENGTH; break; case AS_DEGREES_90: variableBaseX -= AS_MAP_ROOM_LENGTH; break; case AS_DEGREES_180: variableBaseZ += AS_MAP_ROOM_LENGTH; break; case AS_DEGREES_270: variableBaseX += AS_MAP_ROOM_LENGTH; break; } break; } case AS_MAP_RIGHT: { if (currentBlockStairStatus == AS_MAP_STAIRS_RIGHTTOLEFT) variableBaseY -= AS_MAP_ROOM_LENGTH; if (lastBlockStairStatus == AS_MAP_STAIRS_LEFTTORIGHT) variableBaseY += AS_MAP_ROOM_LENGTH; switch(rotation) { case 0: variableBaseZ += AS_MAP_ROOM_LENGTH; break; case AS_DEGREES_90: variableBaseX += AS_MAP_ROOM_LENGTH; break; case AS_DEGREES_180: variableBaseZ -= AS_MAP_ROOM_LENGTH; break; case AS_DEGREES_270: variableBaseX -= AS_MAP_ROOM_LENGTH; break; } break; } } // update global arrays replicate = 0; while (visualMap[replicate][sy][sx][sz] == 1) replicate++; // watch for array error - a design condition - error results in incorrect display if (replicate >= AS_MAX_REPLICATE) replicate = AS_MAX_REPLICATE - 1; visualMap[replicate][sy][sx][sz] = 1; visualX[replicate][sy][sx][sz] = variableBaseX; visualY[replicate][sy][sx][sz] = variableBaseY; visualZ[replicate][sy][sx][sz] = variableBaseZ; visualRotation[replicate][sy][sx][sz] = rotation; if (visibleBlocks < AS_MAX_VISIBLE_BLOCKS) { visibleBlock[visibleBlocks].level = sy; visibleBlock[visibleBlocks].row = sx; visibleBlock[visibleBlocks].column = sz; visibleBlock[visibleBlocks].replicate = replicate; if ((type == AS_MAP_SEARCH_MAIN_LOOP) && (count == length)) visibleBlock[visibleBlocks].replicate |= 0x10; // for use in polygon subdivision visibleBlocks++; } // recurse the search switch(type) { case AS_MAP_SEARCH_MAIN_LOOP: { //if ((sz == (column + colChange)) && (sx == (row + rowChange))) // i.e. first adjacent - won't work with links if (count == length) // i.e. first adjacent block (haven't decreased count yet) { switch(direction) { case AS_MAP_LEFT: case AS_MAP_RIGHT: { GroundSearch2(variableBaseX,variableBaseY,variableBaseZ,sy,sx,sz,AS_MAP_UP,AS_MAX_SEARCH,AS_MAP_SEARCH_FIRST_ADJACENT,direction,rotation); GroundSearch2(variableBaseX,variableBaseY,variableBaseZ,sy,sx,sz,AS_MAP_DOWN,AS_MAX_SEARCH,AS_MAP_SEARCH_FIRST_ADJACENT,direction,rotation); break; } case AS_MAP_UP: case AS_MAP_DOWN: { GroundSearch2(variableBaseX,variableBaseY,variableBaseZ,sy,sx,sz,AS_MAP_LEFT,AS_MAX_SEARCH,AS_MAP_SEARCH_FIRST_ADJACENT,direction,rotation); GroundSearch2(variableBaseX,variableBaseY,variableBaseZ,sy,sx,sz,AS_MAP_RIGHT,AS_MAX_SEARCH,AS_MAP_SEARCH_FIRST_ADJACENT,direction,rotation); break; } } } else // Don't do the adjacent search, just one block off in each direction { switch(direction) { case AS_MAP_LEFT: case AS_MAP_RIGHT: { GroundSearch2(variableBaseX,variableBaseY,variableBaseZ,sy,sx,sz,AS_MAP_UP,1,AS_MAP_SEARCH_NO_RECURSION,direction,rotation); GroundSearch2(variableBaseX,variableBaseY,variableBaseZ,sy,sx,sz,AS_MAP_DOWN,1,AS_MAP_SEARCH_NO_RECURSION,direction,rotation); break; } case AS_MAP_UP: case AS_MAP_DOWN: { GroundSearch2(variableBaseX,variableBaseY,variableBaseZ,sy,sx,sz,AS_MAP_LEFT,1,AS_MAP_SEARCH_NO_RECURSION,direction,rotation); GroundSearch2(variableBaseX,variableBaseY,variableBaseZ,sy,sx,sz,AS_MAP_RIGHT,1,AS_MAP_SEARCH_NO_RECURSION,direction,rotation); break; } } } break; } case AS_MAP_SEARCH_FIRST_ADJACENT: { // oldDirection is the original direction of search, used to avoid going back on oneself in this adjacent search GroundSearch2(variableBaseX,variableBaseY,variableBaseZ,sy,sx,sz,oldDirection,1,AS_MAP_SEARCH_NO_RECURSION,direction,rotation); break; } case AS_MAP_SEARCH_NO_RECURSION: break; // do nothing } // end of switch(type) // tidy loop count--; lastBlockStairStatus = currentBlockStairStatus; adjacentBlock = mapArray[sy][sx][sz].adjacentBlock[direction]; } } void AsArenaBuilder::CalculateVisualMap(int X, int Y, int Z, int aroundY, int rotation) { int baseX,baseY,baseZ; int level, row, column; //* no need if reset after draw for (int i = 0; i < AS_MAX_REPLICATE; i++) { for (level = 0; level < AS_MAP_LEVELS; level++) { for (row = 0; row < AS_MAP_ROWS; row++) { for (column = 0; column < AS_MAP_COLUMNS; column++) { visualMap[i][level][row][column] = 0; } } } } // visibleBlocks = 0; /* row = (int)(X / AS_MAP_ROOM_LENGTH); level = (int)(Y / AS_MAP_ROOM_LENGTH); column = (int)(Z / AS_MAP_ROOM_LENGTH); */ int movementMask = 0x0F; // all on initially // up = 1, down = 2, left = 4, right = 8 switch(aroundY) { case 0: movementMask = 0x08; break;// right only case AS_DEGREES_90: movementMask = 0x02; break;// down only case AS_DEGREES_180: movementMask = 0x04; break;// left only case AS_DEGREES_270: movementMask = 0x01; break;// up only default: { if ((aroundY > AS_DEGREES_270) || (aroundY < AS_DEGREES_90)) movementMask &= ~0x04; // not left if ((aroundY < AS_DEGREES_270) && (aroundY > AS_DEGREES_90)) movementMask &= ~0x08; // not right if ((aroundY > AS_DEGREES_180) && (aroundY < AS_DEGREES_360)) movementMask &= ~0x02; // not down if ((aroundY > 0) && (aroundY < AS_DEGREES_180)) movementMask &= ~0x01; // not up } } row = X; level = Y; column = Z; visualMap[0][level][row][column] = 1; for (int i = 0; i < AS_MAX_REPLICATE; i++) { //baseY = visualY[level][row][column] = level * AS_MAP_ROOM_LENGTH; baseX = visualX[i][level][row][column] = 0; baseY = visualY[i][level][row][column] = 0; baseZ = visualZ[i][level][row][column] = 0; visualRotation[i][level][row][column] = rotation; } visibleBlock[visibleBlocks].level = level; visibleBlock[visibleBlocks].row = row; visibleBlock[visibleBlocks].column = column; visibleBlock[visibleBlocks].replicate = 0; visibleBlock[visibleBlocks].replicate |= 0x20; // for use in polygon subdivision visibleBlocks++; //GroundSearch(baseY,level,row,column,0,AS_MAX_SEARCH,1,3); // horiz //GroundSearch(baseY,level,row,column,1,AS_MAX_SEARCH,1,3); // vert //if (movementMask & 0x04) GroundSearch2(baseX,baseY,baseZ,level,row,column,AS_MAP_LEFT,AS_MAX_SEARCH,AS_MAP_SEARCH_MAIN_LOOP,AS_MAP_LEFT,rotation); //if (movementMask & 0x08) GroundSearch2(baseX,baseY,baseZ,level,row,column,AS_MAP_RIGHT,AS_MAX_SEARCH,AS_MAP_SEARCH_MAIN_LOOP,AS_MAP_RIGHT,rotation); //if (movementMask & 0x01) GroundSearch2(baseX,baseY,baseZ,level,row,column,AS_MAP_UP,AS_MAX_SEARCH,AS_MAP_SEARCH_MAIN_LOOP,AS_MAP_UP,rotation); //if (movementMask & 0x02) GroundSearch2(baseX,baseY,baseZ,level,row,column,AS_MAP_DOWN,AS_MAX_SEARCH,AS_MAP_SEARCH_MAIN_LOOP,AS_MAP_DOWN,rotation); }