Sorry, here's some of my code.
u8 Floor::setDirec(u8 y, u8 x, u8 direc) {
printf("set direc ");
if (direc == -1 or randomChance(direc_change, 100)) { direc = randomRange(0, 3); }
for (u8 i = 0; i < 4; i++) {
switch (direc) {
default:
if (y+1 <= FLOOR_HEIGHT and not floor[y+1][x].set) { return direc; }
case 1:
if (x+1 <= FLOOR_WIDTH and not floor[y][x+1].set) { return direc; }
case 2:
if (y-1 >= 0 and not floor[y-1][x].set) { return direc; }
case 3:
if (x-1 >= 0 and not floor[y][x-1].set) { return direc; }
}
direc += 1;
if (direc > 3) {
direc = 0;
}
}
return -1;
}
void Floor::generatePath(u8 y, u8 x, u8 direc) {
u8 length = randomRange(path_length[0], path_length[1]);
printf("length is %d ", length);
for (u8 i = 0; i <= length; i++) {
printf("start stuff ");
direc = setDirec(y, x, direc);
if (direc == -1) { break; } // no viable directions.....
floor[y][x].set = true;
set_cells[set_index][1] = x;
set_cells[set_index][0] = y;
set_index += 1;
switch (direc) {
default: y += 1; break;
case 1: x += 1; break;
case 2: y -= 1; break;
case 3: x -= 1; break;
}
printf("finished stuff ");
}
printf("finished path ");
// set the last as the stairs
floor[y][x].set = true;
set_cells[set_index][1] = x;
set_cells[set_index][0] = y;
set_index += 1;
floor[y][x].special = CELL_STAIRS;
floor[y][x].roat = direc;
floor[y][x].type = 6;
}
void Floor::generate() {
printf("generate ");
Cell normal = {CELL_NORMAL, false, 0, 0};
for (u8 i = 0; i < FLOOR_HEIGHT; i++) {
for (u8 j = 0; j < FLOOR_WIDTH; j++) {
floor[j] = normal;
}
}
printf("start to stairs ");
// set the start
u8 x = randomRange(0, FLOOR_WIDTH-1);
u8 y = randomRange(0, FLOOR_HEIGHT-1);
floor[y][x].special = CELL_ENTRANCE;
u8 direc = setDirec(y, x, -1);
floor[y][x].roat = direc;
floor[y][x].type = 5;
generatePath(y, x, direc);
if (randomChance(room_chance, 100)) {
printf("room ");
generateRoom();
}
u8 am = randomRange(leaf_amount[0], leaf_amount[1]);
for (u8 i = 0; i < am; i++) {
printf("leaf ");
generateLeaf(CELL_NORMAL);
}
for (u8 i = 0; i < set_index; i++) {
if (floor[set_cells[set_index][0]][set_cells[set_index][1]].special == CELL_NORMAL) {
setType(set_cells[set_index][0], set_cells[set_index][1]);
}
}
}
There's a bit more, but I'm either sure it works(due to using it in other programs too) or it never does it. It manages to print "generate start to stairs set direc length is 4 start stuff set direc finished stuff start stuff set dire" of this before getting the undefined instruction.