1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818
use super::*;
use crate::{
site2::gen::{inscribed_polystar, place_circular},
util::{sampler::Sampler, RandomField, DIAGONALS},
Land,
};
use common::{
comp::misc::PortalData,
generation::{EntityInfo, SpecialEntity},
resources::Secs,
terrain::SpriteKind,
};
use rand::prelude::*;
use std::sync::Arc;
use vek::*;
pub struct Room {
room_base: i32,
room_center: Vec2<i32>,
clear_center: Vec2<i32>,
mob_room: bool,
boss_room: bool,
portal_to_boss: bool,
}
pub struct Cultist {
base: i32,
bounds: Aabr<i32>,
pub(crate) alt: i32,
pub(crate) center: Vec2<i32>,
pub(crate) room_data: Vec<Room>,
room_size: i32,
floors: i32,
}
impl Cultist {
pub fn generate(land: &Land, _rng: &mut impl Rng, site: &Site, tile_aabr: Aabr<i32>) -> Self {
let bounds = Aabr {
min: site.tile_wpos(tile_aabr.min),
max: site.tile_wpos(tile_aabr.max),
};
let center = bounds.center();
let base = land.get_alt_approx(center) as i32;
let room_size = 30;
let mut room_data = vec![];
let floors = 3;
for f in 0..=floors {
for s in 0..=1 {
// rooms
let rooms = [1, 2];
let boss_portal_floor =
(1 + (RandomField::new(0).get(center.with_z(base + 1)) % 2)) as i32;
let portal_to_boss_index =
(RandomField::new(0).get(center.with_z(base)) % 4) as usize;
if rooms.contains(&f) {
for (d, dir) in DIAGONALS.iter().enumerate() {
let room_base = base - (f * (2 * (room_size))) - (s * room_size);
let room_center = center + (dir * ((room_size * 2) - 5 + (10 * s)));
let clear_center = center + (dir * ((room_size * 2) - 6 + (10 * s)));
let mob_room = s < 1;
let portal_to_boss =
mob_room && d == portal_to_boss_index && f == boss_portal_floor;
room_data.push(Room {
room_base,
room_center,
clear_center,
mob_room,
boss_room: false,
portal_to_boss,
});
}
}
}
}
let boss_room_base = base - (6 * room_size);
room_data.push(Room {
room_base: boss_room_base,
room_center: center,
clear_center: center,
mob_room: false,
boss_room: true,
portal_to_boss: false,
});
Self {
bounds,
alt: land.get_alt_approx(site.tile_center_wpos((tile_aabr.max - tile_aabr.min) / 2))
as i32
+ 2,
base,
center,
room_size,
room_data,
floors,
}
}
pub fn spawn_rules(&self, wpos: Vec2<i32>) -> SpawnRules {
SpawnRules {
waypoints: false,
trees: wpos.distance_squared(self.bounds.center()) > (75_i32).pow(2),
..SpawnRules::default()
}
}
}
impl Structure for Cultist {
#[cfg(feature = "use-dyn-lib")]
const UPDATE_FN: &'static [u8] = b"render_cultist\0";
#[cfg_attr(feature = "be-dyn-lib", export_name = "render_cultist")]
fn render_inner(&self, _site: &Site, _land: &Land, painter: &Painter) {
let center = self.center;
let base = self.base;
let room_size = self.room_size;
let floors = self.floors;
let mut thread_rng = thread_rng();
let candles_lite = Fill::Sampling(Arc::new(|wpos| {
Some(match (RandomField::new(0).get(wpos)) % 30 {
0 => Block::air(SpriteKind::Candle),
_ => Block::new(BlockKind::Air, Rgb::new(0, 0, 0)),
})
}));
let mut tower_positions = vec![];
let mut clear_positions = vec![];
let room_data = &self.room_data;
let mut star_positions = vec![];
let mut sprite_positions = vec![];
let mut random_npcs = vec![];
let rock_broken = Fill::Sampling(Arc::new(|center| {
Some(match (RandomField::new(0).get(center)) % 52 {
0..=8 => Block::new(BlockKind::Rock, Rgb::new(60, 55, 65)),
9..=17 => Block::new(BlockKind::Rock, Rgb::new(65, 60, 70)),
18..=26 => Block::new(BlockKind::Rock, Rgb::new(70, 65, 75)),
27..=35 => Block::new(BlockKind::Rock, Rgb::new(75, 70, 80)),
36..=37 => Block::new(BlockKind::Air, Rgb::new(0, 0, 0)),
_ => Block::new(BlockKind::Rock, Rgb::new(55, 50, 60)),
})
}));
let rock = Fill::Brick(BlockKind::Rock, Rgb::new(55, 50, 60), 24);
let water = Fill::Block(Block::new(BlockKind::Water, Rgb::zero()));
let key_door = Fill::Block(Block::air(SpriteKind::KeyDoor));
let key_hole = Fill::Block(Block::air(SpriteKind::Keyhole));
let gold_chain = Fill::Block(Block::air(SpriteKind::SeaDecorChain));
for room in room_data {
let (room_base, room_center, mob_room) =
(room.room_base, room.room_center, room.mob_room);
// rooms
// encapsulation
painter
.aabb(Aabb {
min: (room_center - room_size - 23).with_z(room_base - room_size - 1),
max: (room_center + room_size + 23).with_z(room_base - 2),
})
.fill(rock.clone());
if mob_room {
painter
.aabb(Aabb {
min: (room_center - room_size - 2).with_z(room_base - room_size - 1),
max: (room_center + room_size + 2).with_z(room_base - 2),
})
.fill(rock_broken.clone());
}
// solid floor
painter
.aabb(Aabb {
min: (room_center - room_size - 10).with_z(room_base - room_size - 2),
max: (room_center + room_size + 10).with_z(room_base - room_size - 1),
})
.fill(rock.clone());
// floor candles
painter
.cylinder(Aabb {
min: (room_center - room_size + 1).with_z(room_base - room_size - 1),
max: (room_center + room_size - 1).with_z(room_base - room_size),
})
.fill(candles_lite.clone());
}
for s in 0..=floors {
let room_base = base - (s * (2 * room_size));
// center pit
for p in 3..=5 {
let pos = 3 * p;
let radius = pos * 2;
let amount = pos;
let clear_radius = radius - 8;
let tower_pos = place_circular(center, radius as f32, amount);
let clear_pos = place_circular(center, clear_radius as f32, amount);
tower_positions.extend(tower_pos);
clear_positions.extend(clear_pos);
}
for tower_center in &tower_positions {
let height_var =
(RandomField::new(0).get(tower_center.with_z(room_base)) % 15) as i32;
let height = height_var * 3;
let size = height_var / 3;
// towers
// encapsulation if under ground
if room_base < base {
painter
.aabb(Aabb {
min: (tower_center - 9 - size).with_z(room_base - 2),
max: (tower_center + 9 + size).with_z(room_base + 10 + height),
})
.fill(rock.clone());
painter
.aabb(Aabb {
min: (tower_center - 9 - (size / 2)).with_z(room_base + 8 + height),
max: (tower_center + 9 + (size / 2))
.with_z(room_base + 10 + height + 5 + (height / 2)),
})
.fill(rock.clone());
}
painter
.aabb(Aabb {
min: (tower_center - 8 - size).with_z(room_base),
max: (tower_center + 8 + size).with_z(room_base + 10 + height),
})
.fill(rock_broken.clone());
painter
.aabb(Aabb {
min: (tower_center - 8 - (size / 2)).with_z(room_base + 10 + height),
max: (tower_center + 8 + (size / 2))
.with_z(room_base + 10 + height + 5 + (height / 2)),
})
.fill(rock_broken.clone());
// vault carves floor 0
painter
.vault(
Aabb {
min: Vec2::new(tower_center.x - 8 - size, tower_center.y - 4 - size)
.with_z(room_base + size),
max: Vec2::new(tower_center.x + 8 + size, tower_center.y + 4 + size)
.with_z(room_base + height),
},
Dir::X,
)
.clear();
painter
.vault(
Aabb {
min: Vec2::new(tower_center.x - 4 - size, tower_center.y - 8 - size)
.with_z(room_base + size),
max: Vec2::new(tower_center.x + 4 + size, tower_center.y + 8 + size)
.with_z(room_base + height),
},
Dir::Y,
)
.clear();
// vault carves floor 1
painter
.vault(
Aabb {
min: Vec2::new(
tower_center.x - 8 - (size / 2),
tower_center.y - 4 - (size / 2),
)
.with_z(room_base + 10 + height),
max: Vec2::new(
tower_center.x + 8 + (size / 2),
tower_center.y + 4 + (size / 2),
)
.with_z(room_base + 10 + height + 5 + (height / 4) + (size / 2)),
},
Dir::X,
)
.clear();
painter
.vault(
Aabb {
min: Vec2::new(
tower_center.x - 4 - (size / 2),
tower_center.y - 8 - (size / 2),
)
.with_z(room_base + 10 + height),
max: Vec2::new(
tower_center.x + 4 + (size / 2),
tower_center.y + 8 + (size / 2),
)
.with_z(room_base + 10 + height + 5 + (height / 4) + (size / 2)),
},
Dir::Y,
)
.clear();
}
// tower clears
for (tower_center, clear_center) in tower_positions.iter().zip(&clear_positions) {
let height_var =
(RandomField::new(0).get(tower_center.with_z(room_base)) % 15) as i32;
let height = height_var * 3;
let size = height_var / 3;
// tower clears
painter
.aabb(Aabb {
min: (clear_center - 9 - size).with_z(room_base + size),
max: (clear_center + 9 + size).with_z(room_base + 8 + height),
})
.clear();
painter
.aabb(Aabb {
min: (clear_center - 8 - (size / 2)).with_z(room_base + 10 + height),
max: (clear_center + 8 + (size / 2))
.with_z(room_base + 8 + height + 5 + (height / 2)),
})
.clear();
// decay
let decay_size = 8 + size;
painter
.cylinder(Aabb {
min: (clear_center - decay_size).with_z(room_base + 8 + height),
max: (clear_center + decay_size).with_z(room_base + 10 + height),
})
.clear();
painter
.cylinder(Aabb {
min: (clear_center - decay_size + 5)
.with_z(room_base + 8 + height + 5 + (height / 2)),
max: (clear_center + decay_size - 5)
.with_z(room_base + 10 + height + 5 + (height / 2)),
})
.clear();
}
// center clear
painter
.cylinder(Aabb {
min: (center - room_size + 10).with_z(room_base),
max: (center + room_size - 10).with_z(room_base + (4 * (room_size))),
})
.clear();
}
// room clears
for room in room_data {
let (room_base, room_center, clear_center, mob_room, boss_room, portal_to_boss) = (
room.room_base,
room.room_center,
room.clear_center,
room.mob_room,
room.boss_room,
room.portal_to_boss,
);
painter
.cylinder(Aabb {
min: (clear_center - room_size - 1).with_z(room_base - room_size),
max: (clear_center + room_size + 1).with_z(room_base - 4),
})
.clear();
// room decor
let decor_var = RandomField::new(0).get(room_center.with_z(room_base)) % 4;
if mob_room {
// room_center platform or water basin
if decor_var < 3 {
painter
.aabb(Aabb {
min: (room_center - room_size + 10).with_z(room_base - room_size - 1),
max: (room_center + room_size - 10).with_z(room_base - 2),
})
.fill(rock_broken.clone());
}
// carves
let spacing = 12;
let carve_length = room_size + 8;
let carve_width = 3;
for f in 0..3 {
for c in 0..5 {
// candles & chest & npcs
let sprite_pos_1 = Vec2::new(
room_center.x - room_size + (spacing / 2) + (spacing * c) - carve_width
+ 2,
room_center.y - carve_length + 2,
)
.with_z(room_base - room_size - 1 + ((room_size / 3) * f));
sprite_positions.push(sprite_pos_1);
let sprite_pos_2 = Vec2::new(
room_center.x - room_size + (spacing / 2) + (spacing * c) + carve_width
- 2,
room_center.y + carve_length - 2,
)
.with_z(room_base - room_size - 1 + ((room_size / 3) * f));
sprite_positions.push(sprite_pos_2);
let sprite_pos_3 = Vec2::new(
room_center.x - carve_length + 2,
room_center.y - room_size + (spacing / 2) + (spacing * c) - carve_width
+ 2,
)
.with_z(room_base - room_size - 1 + ((room_size / 3) * f));
sprite_positions.push(sprite_pos_3);
let sprite_pos_4 = Vec2::new(
room_center.x + carve_length - 2,
room_center.y - room_size + (spacing / 2) + (spacing * c) + carve_width
- 2,
)
.with_z(room_base - room_size - 1 + ((room_size / 3) * f));
sprite_positions.push(sprite_pos_4);
let candle_limiter = painter.aabb(Aabb {
min: (room_center - room_size + 10)
.with_z(room_base - room_size - 2 + ((room_size / 3) * f)),
max: (room_center + room_size - 10)
.with_z(room_base - room_size + ((room_size / 3) * f)),
});
painter
.vault(
Aabb {
min: Vec2::new(
room_center.x - room_size + (spacing / 2) + (spacing * c)
- carve_width,
room_center.y - carve_length,
)
.with_z(room_base - room_size - 1 + ((room_size / 3) * f)),
max: Vec2::new(
room_center.x - room_size
+ (spacing / 2)
+ (spacing * c)
+ carve_width,
room_center.y + carve_length,
)
.with_z(
room_base - room_size - 3
+ (room_size / 3)
+ ((room_size / 3) * f),
),
},
Dir::Y,
)
.clear();
painter
.aabb(Aabb {
min: Vec2::new(
room_center.x - room_size + (spacing / 2) + (spacing * c)
- carve_width,
room_center.y - carve_length,
)
.with_z(room_base - room_size - 2 + ((room_size / 3) * f)),
max: Vec2::new(
room_center.x - room_size
+ (spacing / 2)
+ (spacing * c)
+ carve_width,
room_center.y + carve_length,
)
.with_z(room_base - room_size - 1 + ((room_size / 3) * f)),
})
.intersect(candle_limiter)
.fill(rock.clone());
painter
.aabb(Aabb {
min: Vec2::new(
room_center.x - room_size + (spacing / 2) + (spacing * c)
- carve_width,
room_center.y - carve_length,
)
.with_z(room_base - room_size - 1 + ((room_size / 3) * f)),
max: Vec2::new(
room_center.x - room_size
+ (spacing / 2)
+ (spacing * c)
+ carve_width,
room_center.y + carve_length,
)
.with_z(room_base - room_size + ((room_size / 3) * f)),
})
.intersect(candle_limiter)
.fill(candles_lite.clone());
painter
.vault(
Aabb {
min: Vec2::new(
room_center.x - carve_length,
room_center.y - room_size + (spacing / 2) + (spacing * c)
- carve_width,
)
.with_z(room_base - room_size - 1 + ((room_size / 3) * f)),
max: Vec2::new(
room_center.x + carve_length,
room_center.y - room_size
+ (spacing / 2)
+ (spacing * c)
+ carve_width,
)
.with_z(
room_base - room_size - 3
+ (room_size / 3)
+ ((room_size / 3) * f),
),
},
Dir::X,
)
.clear();
painter
.aabb(Aabb {
min: Vec2::new(
room_center.x - carve_length,
room_center.y - room_size + (spacing / 2) + (spacing * c)
- carve_width,
)
.with_z(room_base - room_size - 2 + ((room_size / 3) * f)),
max: Vec2::new(
room_center.x + carve_length,
room_center.y - room_size
+ (spacing / 2)
+ (spacing * c)
+ carve_width,
)
.with_z(room_base - room_size - 1 + ((room_size / 3) * f)),
})
.intersect(candle_limiter)
.fill(rock.clone());
painter
.aabb(Aabb {
min: Vec2::new(
room_center.x - carve_length,
room_center.y - room_size + (spacing / 2) + (spacing * c)
- carve_width,
)
.with_z(room_base - room_size - 1 + ((room_size / 3) * f)),
max: Vec2::new(
room_center.x + carve_length,
room_center.y - room_size
+ (spacing / 2)
+ (spacing * c)
+ carve_width,
)
.with_z(room_base - room_size + ((room_size / 3) * f)),
})
.intersect(candle_limiter)
.fill(candles_lite.clone());
}
// mob room npcs
for dir in CARDINALS {
for d in 1..=4 {
let npc_pos = (room_center + dir * ((spacing / 2) * d))
.with_z(room_base - room_size + ((room_size / 3) * f));
let pos_var = RandomField::new(0).get(npc_pos) % 10;
if pos_var < 2 {
painter.spawn(EntityInfo::at(npc_pos.as_()).with_asset_expect(
"common.entity.dungeon.cultist.cultist",
&mut thread_rng,
None,
))
} else if pos_var > 2 && f > 0 {
painter.sphere_with_radius(npc_pos, 5_f32).clear();
}
}
}
let decor_var = RandomField::new(0).get(room_center.with_z(room_base)) % 4;
if decor_var < 3 {
// portal platform
painter
.cylinder(Aabb {
min: (room_center - 3).with_z(room_base - (room_size / 4) - 5),
max: (room_center + 3).with_z(room_base - (room_size / 4) - 4),
})
.fill(rock.clone());
} else {
painter
.cylinder(Aabb {
min: (room_center - room_size + 10)
.with_z(room_base - room_size - 3),
max: (room_center + room_size - 10)
.with_z(room_base - room_size - 2),
})
.fill(rock.clone());
painter
.cylinder(Aabb {
min: (room_center - room_size + 10)
.with_z(room_base - room_size - 2),
max: (room_center + room_size - 10)
.with_z(room_base - room_size - 1),
})
.fill(water.clone());
painter
.aabb(Aabb {
min: (room_center - room_size + 10)
.with_z(room_base - room_size - 1),
max: (room_center + room_size - 10)
.with_z(room_base - (room_size / 4) - 3),
})
.clear();
}
}
}
// room portals
let mob_portal = room_center.with_z(room_base - (room_size / 4));
let mob_portal_target = (room_center + 10).with_z(room_base - (room_size * 2));
let mini_boss_portal = room_center.with_z(room_base - (room_size * 2));
let exit_position = (center - 10).with_z(base - (6 * room_size));
let boss_position = (center - 10).with_z(base - (7 * room_size));
let boss_portal = center.with_z(base - (7 * room_size));
let mini_boss_portal_target = if portal_to_boss {
boss_position.as_::<f32>()
} else {
exit_position.as_::<f32>()
};
if mob_room {
painter.spawn(EntityInfo::at(mob_portal.as_::<f32>()).into_special(
SpecialEntity::Teleporter(PortalData {
target: mob_portal_target.as_::<f32>(),
requires_no_aggro: true,
buildup_time: Secs(5.),
}),
));
painter.spawn(EntityInfo::at(mini_boss_portal.as_::<f32>()).into_special(
SpecialEntity::Teleporter(PortalData {
target: mini_boss_portal_target,
requires_no_aggro: true,
buildup_time: Secs(5.),
}),
));
} else if boss_room {
painter.spawn(EntityInfo::at(boss_portal.as_::<f32>()).into_special(
SpecialEntity::Teleporter(PortalData {
target: exit_position.as_::<f32>(),
requires_no_aggro: true,
buildup_time: Secs(5.),
}),
));
}
if !mob_room {
if boss_room {
let npc_pos = room_center.with_z(room_base - room_size);
painter.spawn(EntityInfo::at(npc_pos.as_()).with_asset_expect(
"common.entity.dungeon.cultist.mindflayer",
&mut thread_rng,
None,
));
} else {
let npc_pos = (room_center - 2).with_z(room_base - room_size);
painter.spawn(EntityInfo::at(npc_pos.as_()).with_asset_expect(
"common.entity.dungeon.cultist.warlock",
&mut thread_rng,
None,
));
painter.spawn(EntityInfo::at(npc_pos.as_()).with_asset_expect(
"common.entity.dungeon.cultist.warlord",
&mut thread_rng,
None,
));
painter.spawn(
EntityInfo::at(((room_center + 5).with_z(room_base - room_size)).as_())
.with_asset_expect(
"common.entity.dungeon.cultist.beastmaster",
&mut thread_rng,
None,
),
);
}
// gold chains
let chain_positions = place_circular(room_center, 15.0, 10);
for pos in chain_positions {
painter
.aabb(Aabb {
min: pos.with_z(room_base - 12),
max: (pos + 1).with_z(room_base - 4),
})
.fill(gold_chain.clone());
}
}
let down = if mob_room && decor_var < 3 {
0
} else if mob_room && decor_var > 2 {
room_size
} else {
10
};
let magic_circle_bb = painter.cylinder(Aabb {
min: (room_center - 15).with_z(room_base - 3 - down),
max: (room_center + 16).with_z(room_base - 2 - down),
});
star_positions.push((magic_circle_bb, room_center));
}
// candles & chests & npcs
for sprite_pos in sprite_positions {
// keep center pit clear
if sprite_pos.xy().distance_squared(center) > 40_i32.pow(2)
|| sprite_pos.z < (base - (6 * room_size))
{
match (RandomField::new(0).get(sprite_pos + 1)) % 16 {
0 => {
if sprite_pos.z > (base - (6 * room_size)) {
random_npcs.push(sprite_pos)
}
},
1 => {
// prisoners
painter
.aabb(Aabb {
min: (sprite_pos - 1).with_z(sprite_pos.z),
max: (sprite_pos + 2).with_z(sprite_pos.z + 3),
})
.fill(key_door.clone());
painter
.aabb(Aabb {
min: sprite_pos.with_z(sprite_pos.z + 3),
max: (sprite_pos + 1).with_z(sprite_pos.z + 4),
})
.fill(key_hole.clone());
painter
.aabb(Aabb {
min: (sprite_pos).with_z(sprite_pos.z),
max: (sprite_pos + 1).with_z(sprite_pos.z + 2),
})
.clear();
painter.spawn(EntityInfo::at(sprite_pos.as_()).with_asset_expect(
match (RandomField::new(0).get(sprite_pos)) % 10 {
0 => "common.entity.village.farmer",
1 => "common.entity.village.guard",
2 => "common.entity.village.hunter",
3 => "common.entity.village.skinner",
_ => "common.entity.village.villager",
},
&mut thread_rng,
None,
));
},
_ => {
painter.sprite(
sprite_pos,
match (RandomField::new(0).get(sprite_pos)) % 20 {
0 => SpriteKind::DungeonChest5,
_ => SpriteKind::Candle,
},
);
},
}
}
}
// random_npcs around upper entrance and bottom portal
for s in 0..=1 {
let radius = 62.0 - (s * 50) as f32;
let npcs = place_circular(center, radius, 8 - (s * 4));
for npc_pos in npcs {
random_npcs.push(npc_pos.with_z(base + 8 - ((6 * room_size) * s) - (s * 8)));
}
}
for pos in random_npcs {
let entities = [
"common.entity.dungeon.cultist.cultist",
"common.entity.dungeon.cultist.turret",
"common.entity.dungeon.cultist.husk",
"common.entity.dungeon.cultist.husk_brute",
"common.entity.dungeon.cultist.hound",
];
let npc = entities[(RandomField::new(0).get(pos) % entities.len() as u32) as usize];
painter.spawn(EntityInfo::at(pos.as_()).with_asset_expect(npc, &mut thread_rng, None));
}
// outside portal
let top_position = (center - 20).with_z(base + 125);
let bottom_position = center.with_z(base - (6 * room_size));
let top_pos = Vec3::new(
top_position.x as f32,
top_position.y as f32,
top_position.z as f32,
);
let bottom_pos = Vec3::new(
bottom_position.x as f32,
bottom_position.y as f32,
bottom_position.z as f32,
);
painter.spawn(
EntityInfo::at(bottom_pos).into_special(SpecialEntity::Teleporter(PortalData {
target: top_pos,
requires_no_aggro: true,
buildup_time: Secs(5.),
})),
);
let stone_purple = Block::new(BlockKind::GlowingRock, Rgb::new(96, 0, 128));
let magic_circle_bb = painter.cylinder(Aabb {
min: (center - 15).with_z(base - (floors * (2 * room_size)) - 1),
max: (center + 16).with_z(base - (floors * (2 * room_size))),
});
let magic_circle_bb_boss = painter.cylinder(Aabb {
min: (center - 15).with_z(base - (7 * room_size) - 2),
max: (center + 16).with_z(base - (7 * room_size) - 1),
});
star_positions.push((magic_circle_bb, center));
star_positions.push((magic_circle_bb_boss, center));
for (magic_circle_bb, position) in star_positions {
let magic_circle = painter.prim(Primitive::sampling(
magic_circle_bb,
inscribed_polystar(position, 15.0, 7),
));
painter.fill(magic_circle, Fill::Block(stone_purple));
}
// base floor
painter
.cylinder(Aabb {
min: (center - room_size - 15).with_z(base - (floors * (2 * room_size)) - 3),
max: (center + room_size + 15).with_z(base - (floors * (2 * room_size)) - 2),
})
.fill(rock.clone());
}
}