mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Require rng from EntityInfo::with_asset_expect
This commit is contained in:
parent
e004fba9da
commit
6ae25d5956
@ -150,7 +150,7 @@ impl assets::Asset for EntityConfig {
|
||||
}
|
||||
|
||||
impl EntityConfig {
|
||||
pub fn from_asset_expect(asset_specifier: &str) -> Self {
|
||||
pub fn from_asset_expect_owned(asset_specifier: &str) -> Self {
|
||||
Self::load_owned(asset_specifier)
|
||||
.unwrap_or_else(|e| panic!("Failed to load {}. Error: {:?}", asset_specifier, e))
|
||||
}
|
||||
@ -220,18 +220,10 @@ impl EntityInfo {
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function for applying config from asset
|
||||
#[must_use]
|
||||
pub fn with_asset_expect(self, asset_specifier: &str) -> Self {
|
||||
let loadout_rng = rand::thread_rng();
|
||||
|
||||
self.with_asset_expect_and_rng(asset_specifier, loadout_rng)
|
||||
}
|
||||
|
||||
/// Helper function for applying config from asset
|
||||
/// with specified Rng for managing loadout.
|
||||
#[must_use]
|
||||
pub fn with_asset_expect_and_rng<R>(self, asset_specifier: &str, loadout_rng: R) -> Self
|
||||
pub fn with_asset_expect<R>(self, asset_specifier: &str, loadout_rng: &mut R) -> Self
|
||||
where
|
||||
R: rand::Rng,
|
||||
{
|
||||
@ -246,7 +238,7 @@ impl EntityInfo {
|
||||
mut self,
|
||||
config: EntityConfig,
|
||||
config_asset: Option<&str>,
|
||||
loadout_rng: R,
|
||||
loadout_rng: &mut R,
|
||||
) -> Self
|
||||
where
|
||||
R: rand::Rng,
|
||||
@ -313,7 +305,7 @@ impl EntityInfo {
|
||||
mut self,
|
||||
loadout: LoadoutKind,
|
||||
config_asset: Option<&str>,
|
||||
mut rng: R,
|
||||
rng: &mut R,
|
||||
) -> Self
|
||||
where
|
||||
R: rand::Rng,
|
||||
@ -323,18 +315,18 @@ impl EntityInfo {
|
||||
self = self.with_default_equip();
|
||||
},
|
||||
LoadoutKind::Asset(loadout) => {
|
||||
self = self.with_loadout_asset(loadout, &mut rng);
|
||||
self = self.with_loadout_asset(loadout, rng);
|
||||
},
|
||||
LoadoutKind::Hands(hands) => {
|
||||
self = self.with_hands(hands, config_asset, &mut rng);
|
||||
self = self.with_hands(hands, config_asset, rng);
|
||||
},
|
||||
LoadoutKind::Extended {
|
||||
hands,
|
||||
base_asset,
|
||||
inventory,
|
||||
} => {
|
||||
self = self.with_loadout_asset(base_asset, &mut rng);
|
||||
self = self.with_hands(hands, config_asset, &mut rng);
|
||||
self = self.with_loadout_asset(base_asset, rng);
|
||||
self = self.with_hands(hands, config_asset, rng);
|
||||
// FIXME: this shouldn't always overwrite
|
||||
// inventory. Think about this when we get to
|
||||
// entity config inheritance.
|
||||
@ -733,7 +725,7 @@ mod tests {
|
||||
loot,
|
||||
meta,
|
||||
alignment: _alignment, // can't fail if serialized, it's a boring enum
|
||||
} = EntityConfig::from_asset_expect(&config_asset);
|
||||
} = EntityConfig::from_asset_expect_owned(&config_asset);
|
||||
|
||||
validate_body(&body, &config_asset);
|
||||
// body dependent stuff
|
||||
|
@ -840,6 +840,7 @@ mod tests {
|
||||
#[test]
|
||||
fn test_entity_configs() {
|
||||
let dummy_pos = Vec3::new(0.0, 0.0, 0.0);
|
||||
let mut dummy_rng = rand::thread_rng();
|
||||
// Bird Large test
|
||||
for bird_large_species in BIRD_LARGE_ROSTER {
|
||||
let female_body = comp::bird_large::Body {
|
||||
@ -852,9 +853,13 @@ mod tests {
|
||||
};
|
||||
|
||||
let female_config = bird_large_config(female_body);
|
||||
std::mem::drop(EntityInfo::at(dummy_pos).with_asset_expect(female_config));
|
||||
std::mem::drop(
|
||||
EntityInfo::at(dummy_pos).with_asset_expect(female_config, &mut dummy_rng),
|
||||
);
|
||||
let male_config = bird_large_config(male_body);
|
||||
std::mem::drop(EntityInfo::at(dummy_pos).with_asset_expect(male_config));
|
||||
std::mem::drop(
|
||||
EntityInfo::at(dummy_pos).with_asset_expect(male_config, &mut dummy_rng),
|
||||
);
|
||||
}
|
||||
// Bird Medium test
|
||||
for bird_med_species in BIRD_MEDIUM_ROSTER {
|
||||
@ -868,14 +873,18 @@ mod tests {
|
||||
};
|
||||
|
||||
let female_config = bird_medium_config(female_body);
|
||||
std::mem::drop(EntityInfo::at(dummy_pos).with_asset_expect(female_config));
|
||||
std::mem::drop(
|
||||
EntityInfo::at(dummy_pos).with_asset_expect(female_config, &mut dummy_rng),
|
||||
);
|
||||
let male_config = bird_medium_config(male_body);
|
||||
std::mem::drop(EntityInfo::at(dummy_pos).with_asset_expect(male_config));
|
||||
std::mem::drop(
|
||||
EntityInfo::at(dummy_pos).with_asset_expect(male_config, &mut dummy_rng),
|
||||
);
|
||||
}
|
||||
// Humanoid test
|
||||
for kind in RtSimEntityKind::iter() {
|
||||
let config = humanoid_config(kind);
|
||||
std::mem::drop(EntityInfo::at(dummy_pos).with_asset_expect(config));
|
||||
std::mem::drop(EntityInfo::at(dummy_pos).with_asset_expect(config, &mut dummy_rng));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -128,15 +128,15 @@ impl<'a> System<'a> for Sys {
|
||||
}
|
||||
} else {
|
||||
let entity_config_path = entity.get_entity_config();
|
||||
let loadout_rng = entity.loadout_rng();
|
||||
let mut loadout_rng = entity.loadout_rng();
|
||||
let ad_hoc_loadout = entity.get_adhoc_loadout();
|
||||
// Body is rewritten so that body parameters
|
||||
// are consistent between reifications
|
||||
let entity_config = EntityConfig::from_asset_expect(entity_config_path)
|
||||
let entity_config = EntityConfig::from_asset_expect_owned(entity_config_path)
|
||||
.with_body(BodyBuilder::Exact(body));
|
||||
|
||||
let mut entity_info = EntityInfo::at(pos.0)
|
||||
.with_entity_config(entity_config, Some(entity_config_path), loadout_rng)
|
||||
.with_entity_config(entity_config, Some(entity_config_path), &mut loadout_rng)
|
||||
.with_lazy_loadout(ad_hoc_loadout);
|
||||
// Merchants can be traded with
|
||||
if let Some(economy) = entity.get_trade_info(&world, &index) {
|
||||
|
@ -493,7 +493,7 @@ pub fn apply_caves_supplement<'a>(
|
||||
_ => "common.entity.wild.aggressive.cave_troll",
|
||||
}
|
||||
};
|
||||
entity.with_asset_expect(asset)
|
||||
entity.with_asset_expect(asset, dynamic_rng)
|
||||
};
|
||||
|
||||
supplement.add_entity(entity);
|
||||
|
@ -584,7 +584,7 @@ pub fn apply_spots_to(canvas: &mut Canvas, _dynamic_rng: &mut impl Rng) {
|
||||
{
|
||||
canvas.spawn(
|
||||
EntityInfo::at(wpos.map(|e| e as f32) + Vec3::new(0.5, 0.5, 0.0))
|
||||
.with_asset_expect(spec),
|
||||
.with_asset_expect(spec, &mut rng),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ impl Pack {
|
||||
.groups
|
||||
.choose_weighted(dynamic_rng, |(p, _group)| *p)
|
||||
.expect("Failed to choose group");
|
||||
let entity = EntityInfo::at(pos).with_asset_expect(entity_asset);
|
||||
let entity = EntityInfo::at(pos).with_asset_expect(entity_asset, dynamic_rng);
|
||||
let group_size = dynamic_rng.gen_range(*from..=*to);
|
||||
|
||||
(entity, group_size)
|
||||
@ -479,7 +479,8 @@ mod tests {
|
||||
println!("{}:", entry);
|
||||
let (_, (_, _, asset)) = group;
|
||||
let dummy_pos = Vec3::new(0.0, 0.0, 0.0);
|
||||
let entity = EntityInfo::at(dummy_pos).with_asset_expect(asset);
|
||||
let mut dummy_rng = rand::thread_rng();
|
||||
let entity = EntityInfo::at(dummy_pos).with_asset_expect(asset, &mut dummy_rng);
|
||||
std::mem::drop(entity);
|
||||
}
|
||||
}
|
||||
|
@ -899,7 +899,7 @@ impl Settlement {
|
||||
let entity = if is_dummy {
|
||||
EntityInfo::at(entity_wpos)
|
||||
.with_agency(false)
|
||||
.with_asset_expect("common.entity.village.dummy")
|
||||
.with_asset_expect("common.entity.village.dummy", dynamic_rng)
|
||||
} else {
|
||||
match dynamic_rng.gen_range(0..=4) {
|
||||
0 => barnyard(entity_wpos, dynamic_rng),
|
||||
@ -1004,13 +1004,13 @@ fn humanoid(pos: Vec3<f32>, economy: &SiteInformation, dynamic_rng: &mut impl Rn
|
||||
match dynamic_rng.gen_range(0..8) {
|
||||
0 | 1 => entity
|
||||
.with_agent_mark(agent::Mark::Guard)
|
||||
.with_asset_expect("common.entity.village.guard"),
|
||||
.with_asset_expect("common.entity.village.guard", dynamic_rng),
|
||||
2 => entity
|
||||
.with_agent_mark(agent::Mark::Merchant)
|
||||
.with_economy(economy)
|
||||
.with_lazy_loadout(merchant_loadout)
|
||||
.with_asset_expect("common.entity.village.merchant"),
|
||||
_ => entity.with_asset_expect("common.entity.village.villager"),
|
||||
.with_asset_expect("common.entity.village.merchant", dynamic_rng),
|
||||
_ => entity.with_asset_expect("common.entity.village.villager", dynamic_rng),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,15 +75,21 @@ impl Tree {
|
||||
if above && dynamic_rng.gen_bool(0.0005) {
|
||||
canvas.spawn(
|
||||
EntityInfo::at(wpos.map(|e| e as f32) + Vec3::unit_z())
|
||||
.with_asset_expect(match dynamic_rng.gen_range(0..2) {
|
||||
0 => "common.entity.wild.aggressive.deadwood",
|
||||
_ => "common.entity.wild.aggressive.maneater",
|
||||
}),
|
||||
.with_asset_expect(
|
||||
match dynamic_rng.gen_range(0..2) {
|
||||
0 => "common.entity.wild.aggressive.deadwood",
|
||||
_ => "common.entity.wild.aggressive.maneater",
|
||||
},
|
||||
dynamic_rng,
|
||||
),
|
||||
);
|
||||
} else if above && dynamic_rng.gen_bool(0.0001) {
|
||||
canvas.spawn(
|
||||
EntityInfo::at(wpos.map(|e| e as f32) + Vec3::unit_z())
|
||||
.with_asset_expect("common.entity.wild.aggressive.swamp_troll"),
|
||||
.with_asset_expect(
|
||||
"common.entity.wild.aggressive.swamp_troll",
|
||||
dynamic_rng,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -254,11 +254,11 @@ impl Room {
|
||||
.map(|e| e as f32 / 16.0);
|
||||
match self.difficulty {
|
||||
3 => {
|
||||
let turret = turret_3(pos);
|
||||
let turret = turret_3(dynamic_rng, pos);
|
||||
supplement.add_entity(turret);
|
||||
},
|
||||
5 => {
|
||||
let turret = turret_5(pos);
|
||||
let turret = turret_5(dynamic_rng, pos);
|
||||
supplement.add_entity(turret);
|
||||
},
|
||||
_ => {},
|
||||
@ -286,13 +286,13 @@ impl Room {
|
||||
|
||||
if tile_pos == miniboss_spawn_tile && tile_wcenter.xy() == wpos2d {
|
||||
let entities = match self.difficulty {
|
||||
0 => mini_boss_0(tile_wcenter),
|
||||
1 => mini_boss_1(tile_wcenter),
|
||||
2 => mini_boss_2(tile_wcenter),
|
||||
3 => mini_boss_3(tile_wcenter),
|
||||
4 => mini_boss_4(tile_wcenter),
|
||||
0 => mini_boss_0(dynamic_rng, tile_wcenter),
|
||||
1 => mini_boss_1(dynamic_rng, tile_wcenter),
|
||||
2 => mini_boss_2(dynamic_rng, tile_wcenter),
|
||||
3 => mini_boss_3(dynamic_rng, tile_wcenter),
|
||||
4 => mini_boss_4(dynamic_rng, tile_wcenter),
|
||||
5 => mini_boss_5(dynamic_rng, tile_wcenter),
|
||||
_ => mini_boss_fallback(tile_wcenter),
|
||||
_ => mini_boss_fallback(dynamic_rng, tile_wcenter),
|
||||
};
|
||||
|
||||
for entity in entities {
|
||||
@ -304,6 +304,7 @@ impl Room {
|
||||
fn fill_boss_cell(
|
||||
&self,
|
||||
supplement: &mut ChunkSupplement,
|
||||
dynamic_rng: &mut impl Rng,
|
||||
tile_wcenter: Vec3<i32>,
|
||||
wpos2d: Vec2<i32>,
|
||||
tile_pos: Vec2<i32>,
|
||||
@ -319,13 +320,13 @@ impl Room {
|
||||
|
||||
if tile_pos == boss_spawn_tile && wpos2d == tile_wcenter.xy() {
|
||||
let entities = match self.difficulty {
|
||||
0 => boss_0(tile_wcenter),
|
||||
1 => boss_1(tile_wcenter),
|
||||
2 => boss_2(tile_wcenter),
|
||||
3 => boss_3(tile_wcenter),
|
||||
4 => boss_4(tile_wcenter),
|
||||
5 => boss_5(tile_wcenter),
|
||||
_ => boss_fallback(tile_wcenter),
|
||||
0 => boss_0(dynamic_rng, tile_wcenter),
|
||||
1 => boss_1(dynamic_rng, tile_wcenter),
|
||||
2 => boss_2(dynamic_rng, tile_wcenter),
|
||||
3 => boss_3(dynamic_rng, tile_wcenter),
|
||||
4 => boss_4(dynamic_rng, tile_wcenter),
|
||||
5 => boss_5(dynamic_rng, tile_wcenter),
|
||||
_ => boss_fallback(dynamic_rng, tile_wcenter),
|
||||
};
|
||||
|
||||
for entity in entities {
|
||||
@ -646,9 +647,13 @@ impl Floor {
|
||||
wpos2d,
|
||||
tile_pos,
|
||||
),
|
||||
RoomKind::Boss => {
|
||||
room.fill_boss_cell(supplement, tile_wcenter, wpos2d, tile_pos)
|
||||
},
|
||||
RoomKind::Boss => room.fill_boss_cell(
|
||||
supplement,
|
||||
dynamic_rng,
|
||||
tile_wcenter,
|
||||
wpos2d,
|
||||
tile_pos,
|
||||
),
|
||||
RoomKind::Peaceful | RoomKind::LavaPlatforming => {},
|
||||
}
|
||||
}
|
||||
@ -676,9 +681,9 @@ fn enemy_0(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInf
|
||||
// TODO: give enemies health skills?
|
||||
let entity = EntityInfo::at(tile_wcenter.map(|e| e as f32));
|
||||
match dynamic_rng.gen_range(0..=4) {
|
||||
0 => entity.with_asset_expect("common.entity.dungeon.tier-0.mugger"),
|
||||
1 => entity.with_asset_expect("common.entity.dungeon.tier-0.stalker"),
|
||||
_ => entity.with_asset_expect("common.entity.dungeon.tier-0.logger"),
|
||||
0 => entity.with_asset_expect("common.entity.dungeon.tier-0.mugger", dynamic_rng),
|
||||
1 => entity.with_asset_expect("common.entity.dungeon.tier-0.stalker", dynamic_rng),
|
||||
_ => entity.with_asset_expect("common.entity.dungeon.tier-0.logger", dynamic_rng),
|
||||
}
|
||||
});
|
||||
|
||||
@ -692,9 +697,9 @@ fn enemy_1(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInf
|
||||
// TODO: give enemies health skills?
|
||||
let entity = EntityInfo::at(tile_wcenter.map(|e| e as f32));
|
||||
match dynamic_rng.gen_range(0..=4) {
|
||||
0 => entity.with_asset_expect("common.entity.dungeon.tier-1.bow"),
|
||||
1 => entity.with_asset_expect("common.entity.dungeon.tier-1.staff"),
|
||||
_ => entity.with_asset_expect("common.entity.dungeon.tier-1.spear"),
|
||||
0 => entity.with_asset_expect("common.entity.dungeon.tier-1.bow", dynamic_rng),
|
||||
1 => entity.with_asset_expect("common.entity.dungeon.tier-1.staff", dynamic_rng),
|
||||
_ => entity.with_asset_expect("common.entity.dungeon.tier-1.spear", dynamic_rng),
|
||||
}
|
||||
});
|
||||
|
||||
@ -708,9 +713,9 @@ fn enemy_2(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInf
|
||||
// TODO: give enemies health skills?
|
||||
let entity = EntityInfo::at(tile_wcenter.map(|e| e as f32));
|
||||
match dynamic_rng.gen_range(0..=4) {
|
||||
0 => entity.with_asset_expect("common.entity.dungeon.tier-2.bow"),
|
||||
1 => entity.with_asset_expect("common.entity.dungeon.tier-2.staff"),
|
||||
_ => entity.with_asset_expect("common.entity.dungeon.tier-2.spear"),
|
||||
0 => entity.with_asset_expect("common.entity.dungeon.tier-2.bow", dynamic_rng),
|
||||
1 => entity.with_asset_expect("common.entity.dungeon.tier-2.staff", dynamic_rng),
|
||||
_ => entity.with_asset_expect("common.entity.dungeon.tier-2.spear", dynamic_rng),
|
||||
}
|
||||
});
|
||||
|
||||
@ -724,9 +729,9 @@ fn enemy_3(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInf
|
||||
// TODO: give enemies health skills?
|
||||
let entity = EntityInfo::at(tile_wcenter.map(|e| e as f32));
|
||||
match dynamic_rng.gen_range(0..=4) {
|
||||
0 => entity.with_asset_expect("common.entity.dungeon.tier-3.bow"),
|
||||
1 => entity.with_asset_expect("common.entity.dungeon.tier-3.staff"),
|
||||
_ => entity.with_asset_expect("common.entity.dungeon.tier-3.spear"),
|
||||
0 => entity.with_asset_expect("common.entity.dungeon.tier-3.bow", dynamic_rng),
|
||||
1 => entity.with_asset_expect("common.entity.dungeon.tier-3.staff", dynamic_rng),
|
||||
_ => entity.with_asset_expect("common.entity.dungeon.tier-3.spear", dynamic_rng),
|
||||
}
|
||||
});
|
||||
|
||||
@ -740,9 +745,9 @@ fn enemy_4(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInf
|
||||
// TODO: give enemies health skills?
|
||||
let entity = EntityInfo::at(tile_wcenter.map(|e| e as f32));
|
||||
match dynamic_rng.gen_range(0..=4) {
|
||||
0 => entity.with_asset_expect("common.entity.dungeon.tier-4.bow"),
|
||||
1 => entity.with_asset_expect("common.entity.dungeon.tier-4.staff"),
|
||||
_ => entity.with_asset_expect("common.entity.dungeon.tier-4.spear"),
|
||||
0 => entity.with_asset_expect("common.entity.dungeon.tier-4.bow", dynamic_rng),
|
||||
1 => entity.with_asset_expect("common.entity.dungeon.tier-4.staff", dynamic_rng),
|
||||
_ => entity.with_asset_expect("common.entity.dungeon.tier-4.spear", dynamic_rng),
|
||||
}
|
||||
});
|
||||
|
||||
@ -756,9 +761,9 @@ fn enemy_5(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInf
|
||||
// TODO: give enemies health skills?
|
||||
let entity = EntityInfo::at(tile_wcenter.map(|e| e as f32));
|
||||
match dynamic_rng.gen_range(0..=4) {
|
||||
0 => entity.with_asset_expect("common.entity.dungeon.tier-5.warlock"),
|
||||
1 => entity.with_asset_expect("common.entity.dungeon.tier-5.warlord"),
|
||||
_ => entity.with_asset_expect("common.entity.dungeon.tier-5.cultist"),
|
||||
0 => entity.with_asset_expect("common.entity.dungeon.tier-5.warlock", dynamic_rng),
|
||||
1 => entity.with_asset_expect("common.entity.dungeon.tier-5.warlord", dynamic_rng),
|
||||
_ => entity.with_asset_expect("common.entity.dungeon.tier-5.cultist", dynamic_rng),
|
||||
}
|
||||
});
|
||||
|
||||
@ -770,109 +775,109 @@ fn enemy_fallback(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<En
|
||||
let mut entities = Vec::new();
|
||||
entities.resize_with(number, || {
|
||||
let entity = EntityInfo::at(tile_wcenter.map(|e| e as f32));
|
||||
entity.with_asset_expect("common.entity.dungeon.fallback.enemy")
|
||||
entity.with_asset_expect("common.entity.dungeon.fallback.enemy", dynamic_rng)
|
||||
});
|
||||
|
||||
entities
|
||||
}
|
||||
|
||||
fn turret_3(pos: Vec3<f32>) -> EntityInfo {
|
||||
EntityInfo::at(pos).with_asset_expect("common.entity.dungeon.tier-3.sentry")
|
||||
fn turret_3(dynamic_rng: &mut impl Rng, pos: Vec3<f32>) -> EntityInfo {
|
||||
EntityInfo::at(pos).with_asset_expect("common.entity.dungeon.tier-3.sentry", dynamic_rng)
|
||||
}
|
||||
|
||||
fn turret_5(pos: Vec3<f32>) -> EntityInfo {
|
||||
EntityInfo::at(pos).with_asset_expect("common.entity.dungeon.tier-5.turret")
|
||||
fn turret_5(dynamic_rng: &mut impl Rng, pos: Vec3<f32>) -> EntityInfo {
|
||||
EntityInfo::at(pos).with_asset_expect("common.entity.dungeon.tier-5.turret", dynamic_rng)
|
||||
}
|
||||
|
||||
fn boss_0(tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
fn boss_0(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
vec![
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-0.boss"),
|
||||
.with_asset_expect("common.entity.dungeon.tier-0.boss", dynamic_rng),
|
||||
]
|
||||
}
|
||||
|
||||
fn boss_1(tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
fn boss_1(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
vec![
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-1.boss"),
|
||||
.with_asset_expect("common.entity.dungeon.tier-1.boss", dynamic_rng),
|
||||
]
|
||||
}
|
||||
|
||||
fn boss_2(tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
fn boss_2(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
vec![
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-2.boss"),
|
||||
.with_asset_expect("common.entity.dungeon.tier-2.boss", dynamic_rng),
|
||||
]
|
||||
}
|
||||
fn boss_3(tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
fn boss_3(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
let mut entities = Vec::new();
|
||||
entities.resize_with(2, || {
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-3.boss")
|
||||
.with_asset_expect("common.entity.dungeon.tier-3.boss", dynamic_rng)
|
||||
});
|
||||
|
||||
entities
|
||||
}
|
||||
|
||||
fn boss_4(tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
fn boss_4(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
vec![
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-4.boss"),
|
||||
.with_asset_expect("common.entity.dungeon.tier-4.boss", dynamic_rng),
|
||||
]
|
||||
}
|
||||
|
||||
fn boss_5(tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
fn boss_5(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
vec![
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-5.boss"),
|
||||
.with_asset_expect("common.entity.dungeon.tier-5.boss", dynamic_rng),
|
||||
]
|
||||
}
|
||||
|
||||
fn boss_fallback(tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
fn boss_fallback(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
vec![
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.fallback.boss"),
|
||||
.with_asset_expect("common.entity.dungeon.fallback.boss", dynamic_rng),
|
||||
]
|
||||
}
|
||||
|
||||
fn mini_boss_0(tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
fn mini_boss_0(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
vec![
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-0.miniboss"),
|
||||
.with_asset_expect("common.entity.dungeon.tier-0.miniboss", dynamic_rng),
|
||||
]
|
||||
}
|
||||
|
||||
fn mini_boss_1(tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
fn mini_boss_1(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
let mut entities = Vec::new();
|
||||
entities.resize_with(8, || {
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-1.rat")
|
||||
.with_asset_expect("common.entity.dungeon.tier-1.rat", dynamic_rng)
|
||||
});
|
||||
entities
|
||||
}
|
||||
|
||||
fn mini_boss_2(tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
fn mini_boss_2(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
let mut entities = Vec::new();
|
||||
entities.resize_with(6, || {
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-2.hakulaq")
|
||||
.with_asset_expect("common.entity.dungeon.tier-2.hakulaq", dynamic_rng)
|
||||
});
|
||||
entities
|
||||
}
|
||||
|
||||
fn mini_boss_3(tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
fn mini_boss_3(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
let mut entities = Vec::new();
|
||||
entities.resize_with(3, || {
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-3.bonerattler")
|
||||
.with_asset_expect("common.entity.dungeon.tier-3.bonerattler", dynamic_rng)
|
||||
});
|
||||
entities
|
||||
}
|
||||
|
||||
fn mini_boss_4(tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
fn mini_boss_4(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
vec![
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-4.miniboss"),
|
||||
.with_asset_expect("common.entity.dungeon.tier-4.miniboss", dynamic_rng),
|
||||
]
|
||||
}
|
||||
|
||||
@ -882,33 +887,33 @@ fn mini_boss_5(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<Entit
|
||||
0 => {
|
||||
entities.push(
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-5.beastmaster"),
|
||||
.with_asset_expect("common.entity.dungeon.tier-5.beastmaster", dynamic_rng),
|
||||
);
|
||||
entities.resize_with(entities.len() + 4, || {
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-5.hound")
|
||||
.with_asset_expect("common.entity.dungeon.tier-5.hound", dynamic_rng)
|
||||
});
|
||||
},
|
||||
1 => {
|
||||
entities.resize_with(2, || {
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-5.husk_brute")
|
||||
.with_asset_expect("common.entity.dungeon.tier-5.husk_brute", dynamic_rng)
|
||||
});
|
||||
},
|
||||
_ => {
|
||||
entities.resize_with(10, || {
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.tier-5.husk")
|
||||
.with_asset_expect("common.entity.dungeon.tier-5.husk", dynamic_rng)
|
||||
});
|
||||
},
|
||||
}
|
||||
entities
|
||||
}
|
||||
|
||||
fn mini_boss_fallback(tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
fn mini_boss_fallback(dynamic_rng: &mut impl Rng, tile_wcenter: Vec3<i32>) -> Vec<EntityInfo> {
|
||||
vec![
|
||||
EntityInfo::at(tile_wcenter.map(|e| e as f32))
|
||||
.with_asset_expect("common.entity.dungeon.fallback.miniboss"),
|
||||
.with_asset_expect("common.entity.dungeon.fallback.miniboss", dynamic_rng),
|
||||
]
|
||||
}
|
||||
|
||||
@ -1450,14 +1455,15 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_creating_bosses() {
|
||||
let mut dynamic_rng = rand::thread_rng();
|
||||
let tile_wcenter = Vec3::new(0, 0, 0);
|
||||
boss_0(tile_wcenter);
|
||||
boss_1(tile_wcenter);
|
||||
boss_2(tile_wcenter);
|
||||
boss_3(tile_wcenter);
|
||||
boss_4(tile_wcenter);
|
||||
boss_5(tile_wcenter);
|
||||
boss_fallback(tile_wcenter);
|
||||
boss_0(&mut dynamic_rng, tile_wcenter);
|
||||
boss_1(&mut dynamic_rng, tile_wcenter);
|
||||
boss_2(&mut dynamic_rng, tile_wcenter);
|
||||
boss_3(&mut dynamic_rng, tile_wcenter);
|
||||
boss_4(&mut dynamic_rng, tile_wcenter);
|
||||
boss_5(&mut dynamic_rng, tile_wcenter);
|
||||
boss_fallback(&mut dynamic_rng, tile_wcenter);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1479,19 +1485,20 @@ mod tests {
|
||||
fn test_creating_minibosses() {
|
||||
let mut dynamic_rng = rand::thread_rng();
|
||||
let tile_wcenter = Vec3::new(0, 0, 0);
|
||||
mini_boss_0(tile_wcenter);
|
||||
mini_boss_1(tile_wcenter);
|
||||
mini_boss_2(tile_wcenter);
|
||||
mini_boss_3(tile_wcenter);
|
||||
mini_boss_4(tile_wcenter);
|
||||
mini_boss_0(&mut dynamic_rng, tile_wcenter);
|
||||
mini_boss_1(&mut dynamic_rng, tile_wcenter);
|
||||
mini_boss_2(&mut dynamic_rng, tile_wcenter);
|
||||
mini_boss_3(&mut dynamic_rng, tile_wcenter);
|
||||
mini_boss_4(&mut dynamic_rng, tile_wcenter);
|
||||
mini_boss_5(&mut dynamic_rng, tile_wcenter);
|
||||
mini_boss_fallback(tile_wcenter);
|
||||
mini_boss_fallback(&mut dynamic_rng, tile_wcenter);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_creating_turrets() {
|
||||
let mut dynamic_rng = rand::thread_rng();
|
||||
let pos = Vec3::new(0.0, 0.0, 0.0);
|
||||
turret_3(pos);
|
||||
turret_5(pos);
|
||||
turret_3(&mut dynamic_rng, pos);
|
||||
turret_5(&mut dynamic_rng, pos);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user