| 364 | } |
| 365 | |
| 366 | staticfn void |
| 367 | makerooms(void) |
| 368 | { |
| 369 | boolean tried_vault = FALSE; |
| 370 | int themeroom_tries = 0; |
| 371 | char *fname; |
| 372 | nhl_sandbox_info sbi = {NHL_SB_SAFE, 1*1024*1024, 0, 1*1024*1024}; |
| 373 | lua_State *themes = (lua_State *) gl.luathemes[u.uz.dnum]; |
| 374 | |
| 375 | if (!themes && *(fname = svd.dungeons[u.uz.dnum].themerms)) { |
| 376 | if ((themes = nhl_init(&sbi)) != 0) { |
| 377 | if (!nhl_loadlua(themes, fname)) { |
| 378 | /* loading lua failed, don't use themed rooms */ |
| 379 | nhl_done(themes); |
| 380 | themes = (lua_State *) 0; |
| 381 | } else { |
| 382 | /* success; save state for this dungeon branch */ |
| 383 | gl.luathemes[u.uz.dnum] = (genericptr_t) themes; |
| 384 | /* keep themes context, so not 'nhl_done(themes);' */ |
| 385 | iflags.in_lua = FALSE; /* can affect error messages */ |
| 386 | } |
| 387 | } |
| 388 | if (!themes) /* don't try again when making next level */ |
| 389 | *fname = '\0'; /* svd.dungeons[u.uz.dnum].themerms */ |
| 390 | } |
| 391 | |
| 392 | if (themes) { |
| 393 | create_des_coder(); |
| 394 | iflags.in_lua = gi.in_mk_themerooms = TRUE; |
| 395 | gt.themeroom_failed = FALSE; |
| 396 | lua_getglobal(themes, "pre_themerooms_generate"); |
| 397 | nhl_pcall_handle(themes, 0, 0, "makerooms-1", NHLpa_impossible); |
| 398 | iflags.in_lua = gi.in_mk_themerooms = FALSE; |
| 399 | } |
| 400 | |
| 401 | /* make rooms until satisfied */ |
| 402 | /* rnd_rect() will returns 0 if no more rects are available... */ |
| 403 | while (svn.nroom < (MAXNROFROOMS - 1) && rnd_rect()) { |
| 404 | if (svn.nroom >= (MAXNROFROOMS / 6) && rn2(2) && !tried_vault) { |
| 405 | tried_vault = TRUE; |
| 406 | if (create_vault()) { |
| 407 | gv.vault_x = svr.rooms[svn.nroom].lx; |
| 408 | gv.vault_y = svr.rooms[svn.nroom].ly; |
| 409 | svr.rooms[svn.nroom].hx = -1; |
| 410 | } |
| 411 | } else { |
| 412 | if (themes) { |
| 413 | iflags.in_lua = gi.in_mk_themerooms = TRUE; |
| 414 | gt.themeroom_failed = FALSE; |
| 415 | lua_getglobal(themes, "themerooms_generate"); |
| 416 | nhl_pcall_handle(themes, 0, 0, "makerooms-2", NHLpa_panic); |
| 417 | iflags.in_lua = gi.in_mk_themerooms = FALSE; |
| 418 | if (gt.themeroom_failed |
| 419 | && ((themeroom_tries++ > 10) |
| 420 | || (svn.nroom >= (MAXNROFROOMS / 6)))) |
| 421 | break; |
| 422 | } else { |
| 423 | if (!create_room(-1, -1, -1, -1, -1, -1, OROOM, -1)) |
no test coverage detected