mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added spawn_town server setting
This commit is contained in:
parent
d8117b3b3d
commit
24763972ea
@ -297,17 +297,26 @@ impl Server {
|
||||
// but are needed to be explicit about casting (and to make the compiler stop
|
||||
// complaining)
|
||||
|
||||
// spawn in the chunk, that is in the middle of the world
|
||||
let center_chunk: Vec2<i32> = world.sim().map_size_lg().chunks().map(i32::from) / 2;
|
||||
|
||||
// Find a town to spawn in that's close to the centre of the world
|
||||
let spawn_chunk = world
|
||||
.civs()
|
||||
.sites()
|
||||
.filter(|site| matches!(site.kind, world::civ::SiteKind::Settlement))
|
||||
.map(|site| site.center)
|
||||
.min_by_key(|site_pos| site_pos.distance_squared(center_chunk))
|
||||
.unwrap_or(center_chunk);
|
||||
// Search for town defined by spawn_town server setting. If this fails, or is
|
||||
// None, set spawn to the nearest town to the centre of the world
|
||||
let spawn_chunk = match settings.spawn_town.as_ref().and_then(|spawn_town| {
|
||||
world.civs().sites().find(|site| {
|
||||
site.site_tmp
|
||||
.map_or(false, |id| index.sites[id].name() == spawn_town)
|
||||
})
|
||||
}) {
|
||||
Some(t) => t.center,
|
||||
None => {
|
||||
let center_chunk = world.sim().map_size_lg().chunks().map(i32::from) / 2;
|
||||
world
|
||||
.civs()
|
||||
.sites()
|
||||
.filter(|site| matches!(site.kind, world::civ::SiteKind::Settlement))
|
||||
.map(|site| site.center)
|
||||
.min_by_key(|site_pos| site_pos.distance_squared(center_chunk))
|
||||
.unwrap_or(center_chunk)
|
||||
},
|
||||
};
|
||||
|
||||
// Calculate the middle of the chunk in the world
|
||||
let spawn_wpos = TerrainChunkSize::center_wpos(spawn_chunk);
|
||||
|
@ -42,6 +42,7 @@ pub struct Settings {
|
||||
pub banned_words_files: Vec<PathBuf>,
|
||||
pub max_player_group_size: u32,
|
||||
pub client_timeout: Duration,
|
||||
pub spawn_town: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
@ -59,6 +60,7 @@ impl Default for Settings {
|
||||
banned_words_files: Vec::new(),
|
||||
max_player_group_size: 6,
|
||||
client_timeout: Duration::from_secs(40),
|
||||
spawn_town: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user