/* resyncs only if the stacks are empty */ void CEngine::tryAllDirs() { unsigned int i; CRoom *room; CRoom *candidate; mappingOff(); print_debug(DEBUG_ANALYZER, "in try_dir_all_dirs"); if (stacker.amount() == 0) { print_debug(DEBUG_ANALYZER, "leaving. No candidates in stack to check. This results in FULL RESYNC."); return; } for (i = 0; i < stacker.amount(); i++) { room = stacker.get(i); // dodgy part - iterate over enum! so iterate over 6 exits for (int d = 0; d < 6; d++) { ExitDirection dir = static_cast<ExitDirection>(d); if (room->isConnected(dir)) { candidate = room->getExitRoom(dir); if (testRoom(candidate) ) stacker.put(candidate); } } } print_debug(DEBUG_ANALYZER, "leaving try_dir_all_dirs"); }
void CEngine::tryLook() { unsigned int i; CRoom *room; print_debug(DEBUG_ANALYZER, "in tryLook"); if (stacker.amount() == 0) { print_debug(DEBUG_ANALYZER, "leaving. No candidates in stack to check. This results in FULL RESYNC."); return; } for (i = 0; i < stacker.amount(); i++) { room = stacker.get(i); if (testRoom(room)) stacker.put(room); } }
/* Abre uma subsala completamente fechada */ void fixRoom(Nivel* nivel){ int stop = 0, i, j; int tamI = nivel->tamI; int tamJ = nivel->tamJ; /* Detecta alguma subsala fechada */ for(i = 1; (!stop) && (i < tamI - 1); i++){ for(j = 0; (!stop) && (j < tamJ - 1); j++){ if(nivel->mapa[i][j].shown == 2){ i--; j--; stop = 1; } } } /* Verifica se eh possivel abri-la para cima */ if((nivel->mapa[i - 1][j].shown == 1) && (i > 1)){ nivel->mapa[i - 1][j].shown = 0; } /* Ou para baixo */ while((i < tamI - 2) && (nivel->mapa[i + 1][j].shown != 1)) i++; if(i < tamI - 2) nivel->mapa[i + 1][j].shown = 0; /* Ou a abre para a direita */ else{ while((j < tamJ - 2) && (nivel->mapa[i][j + 1].shown != 1)) j++; if(j < tamJ - 2) nivel->mapa[i][j + 1].shown = 0; } testRoom(nivel); }
/* Gera um mapa */ void genRoom(Nivel* nivel){ int rooms, maxSize; int tamI = nivel->tamI; int tamJ = nivel->tamJ; /* Verifica quantas salas devemn ser geradas e variaveis de controle para seus tamanhos */ getRoomsStats(nivel, &rooms, &maxSize); /* Gera um subsala a cada iteracao. Uma subsala nao deve ser fechada */ do{ /* Determina o centro da subsala */ int centerI = rand() % tamI; int centerJ = rand() % tamJ; /* Determina a linha dos muros superiores */ int up = centerI - (3 * (rand() % maxSize) / 2); if(up == centerI) up--; if(up < 0) up = 0; /* Determina alinha dos muros inferiores */ int down = centerI + (3 * (rand() % maxSize) / 2); if(down == centerI) down++; if(down >= tamI) down= tamI - 1; /* Determina a coluna dos muros esquerdos */ int left = centerJ - (3 * (rand() % maxSize) / 2); if(left == centerJ) left--; if(left < 0) left = 0; /* Determina acoluna dos muros direitos */ int right = centerJ + (3 * (rand() % maxSize) / 2); if(right == centerJ) right++; if(right >= tamJ) right = tamJ - 1; /* Variaveis de controle que verificam se ao menos alguma porta foi criada em cada lado dos muros * * Caso negativo, alguma posicao do lado do muro que nao recebeu uma porta eh aberta * * Isso diminui o numero de subsalas fechadas e reduz significativamente o numero de chamadas da funcao de teste */ int door1 = 0; int door2 = 0; /* Para os muros verticais */ for(int j = left; j <= right; j++){ if((j > 1) && (nivel->mapa[up][j].shown == 1)){ door1 = 1; nivel->mapa[up][j - 1].shown = 2; } nivel->mapa[up][j].shown = 1; if((j > 1) && (nivel->mapa[down][j].shown == 1)){ door2 = 1; nivel->mapa[down][j - 1].shown = 2; } nivel->mapa[down][j].shown = 1; } if(door1 == 0){ int j; do{ j = rand() % right; }while(j < left); nivel->mapa[up][j].shown = 2; } if(door2 == 0){ int j; do{ j = rand() % right; }while(j < left); nivel->mapa[down][j].shown = 2; } /* Idem para os horizontais */ door1 = 0; door2 = 0; for(int i = up; i <= down; i++){ if((i > 1) && (nivel->mapa[i][left].shown == 1)){ door1 = 1; nivel->mapa[i - 1][left].shown = 2; } nivel->mapa[i][left].shown = 1; if((i > 1) && (nivel->mapa[i][right].shown == 1)){ door2 = 1; nivel->mapa[i - 1][right].shown = 2; } nivel->mapa[i][right].shown = 1; } if(door1 == 0){ int i; do{ i = rand() % down; }while(i < up); nivel->mapa[i][left].shown = 2; } if(door2 == 0){ int i; do{ i = rand() % down; }while(i < up); nivel->mapa[i][right].shown = 2; } /* Cerca os extremos do mapa com muros */ for(int i = 0; i < tamJ; i++){ nivel->mapa[tamI - 1][i].shown = 1; nivel->mapa[0][i].shown = 1; } for(int i = 0; i < tamI; i++){ nivel->mapa[i][tamJ - 1].shown = 1; nivel->mapa[i][0].shown = 1; } rooms--; }while(rooms); testRoom(nivel); }
void CEngine::tryDir() { unsigned int i; CRoom *room; CRoom *candidate; nameMatch = 0; descMatch = 0; print_debug(DEBUG_ANALYZER, "in try_dir"); ExitDirection dir = numbydir(event.dir[0]); if (dir == ED_UNKNOWN) { print_debug(DEBUG_ANALYZER, "Error in try_dir - faulty DIR given as input!\r\n"); return; } CCommand cmd = commandQueue.peek(); if (cmd.timer.elapsed() > conf->getPrespamTTL() ) { print_debug(DEBUG_ANALYZER, "The command queue has head entry with lifetime over limit. Resetting"); commandQueue.clear(); toggle_renderer_reaction(); } else if (cmd.dir == dir && !event.fleeing ) { // we moved in awaited direction commandQueue.dequeue(); } if (stacker.amount() == 0) { print_debug(DEBUG_ANALYZER, "leaving. No candidates in stack to check. This results in FULL RESYNC."); return; } for (i = 0; i < stacker.amount(); i++) { room = stacker.get(i); if (room->isConnected(dir)) { candidate = room->getExitRoom(dir); if (testRoom(candidate) ) { stacker.put(candidate); } } else { if (stacker.amount() == 1 && mapping) { print_debug(DEBUG_ANALYZER, "Going to add new room..."); mapCurrentRoom(room, dir); return; } } } /* roomname update */ if (stacker.next() == 1) { /* this means we have exactly one match */ // printf("nameMatch %i, descMatch %i\r\n", nameMatch, descMatch); if (nameMatch > 0) { /* Autorefresh only if case has been changed. */ if (conf->getAutorefresh() && event.name.toLower() == stacker.nextFirst()->getName().toLower()) { send_to_user("--[ (AutoRefreshed) not exact room name match: %i errors.\r\n", nameMatch); stacker.nextFirst()->setName(event.name); } else { send_to_user("--[ not exact room name match: %i errors. Use 'mrefresh' to fix it!\r\n", nameMatch); } } if (conf->getAutorefresh() && descMatch > 0) { send_to_user("--[ (AutoRefreshed) not exact room desc match: %i errors.\r\n", descMatch); stacker.nextFirst()->setDesc(event.desc); } else if (!conf->getAutorefresh() && descMatch > 0) { send_to_user("--[ not exact room desc match: %i errors.\r\n", descMatch); } } print_debug(DEBUG_ANALYZER, "leaving tryDir"); }