Esempio n. 1
0
void generate_dungeon_rooms(dungeon* d) {
	const int w = d->width;
	const int h = d->height;
	int x;
	d->rooms = calloc((unsigned long)(w*h), sizeof(room));

	for(x=0; x<(w*h); ++x) {
		generate_room(&(d->rooms[x]));
	}

	//create paths:
	d->rooms[d->spawn_room].n = 1;
	d->rooms[d->spawn_room].s = 1;
	d->rooms[d->spawn_room].e = 1;
	d->rooms[d->spawn_room].w = 1;
	d->rooms[d->spawn_room].boss_room = 0; //spawn cannot be boss
	d->rooms[d->spawn_room].visited = 1; //spawn is familiar


	d->rooms[d->end_room].n = 1;
	d->rooms[d->end_room].s = 1;
	d->rooms[d->end_room].e = 1;
	d->rooms[d->end_room].w = 1;
	d->rooms[d->end_room].boss_room = 1; //end must be boss room

	//make sure all paths are valid
	for(x=0; x<(w*h); ++x) {
		if (d->rooms[x].n) {
			if(x < w) {
				d->rooms[x].n = 0;
			} else {
				d->rooms[x - w].s = 1;
			}
		}

		if (d->rooms[x].s) {
			if(x < ((w*h) - w)) {
				d->rooms[x + w].n = 1;
			} else {
				d->rooms[x].s = 0;
			}
		}

		if (d->rooms[x].w) {
			if(x == 0) {
				d->rooms[x].w = 0;
			} else {
				d->rooms[x-1].e = 1;
			}
		}

		if (d->rooms[x].e) {
			if(x == ((w*h)-1)) {
				d->rooms[x].e = 0;
			} else {
				d->rooms[x+1].w = 1;
			}
		}
	}
}
Esempio n. 2
0
static int gen_room(lua_State* L) {
	MTwist& mt = lua_get_gamestate(L)->rng();
	int nargs = lua_gettop(L);

	GeneratedLevel* level = lua_togenlevel(L, 1);
	int room_padding = lua_tointeger(L, 2);
	Dim size(lua_tointeger(L, 3), lua_tointeger(L, 4));
	int max_attempts = nargs >= 5 ? lua_tointeger(L, 5) : 20;

	int mark = mt.rand(4);
	if (mt.rand(4) < 3)
		mark = 0;

	bool success = generate_room(lua_get_gamestate(L)->rng(), *level, size.w,
			size.h, room_padding, mark, max_attempts);

	if (success) {
		lua_push_region(L, level->rooms().back().room_region);
	} else {
		lua_pushnil(L);
	}

	return 1;
}