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
|
// but are needed to be explicit about casting (and to make the compiler stop
|
||||||
// complaining)
|
// complaining)
|
||||||
|
|
||||||
// spawn in the chunk, that is in the middle of the world
|
// Search for town defined by spawn_town server setting. If this fails, or is
|
||||||
let center_chunk: Vec2<i32> = world.sim().map_size_lg().chunks().map(i32::from) / 2;
|
// 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| {
|
||||||
// Find a town to spawn in that's close to the centre of the world
|
world.civs().sites().find(|site| {
|
||||||
let spawn_chunk = world
|
site.site_tmp
|
||||||
.civs()
|
.map_or(false, |id| index.sites[id].name() == spawn_town)
|
||||||
.sites()
|
})
|
||||||
.filter(|site| matches!(site.kind, world::civ::SiteKind::Settlement))
|
}) {
|
||||||
.map(|site| site.center)
|
Some(t) => t.center,
|
||||||
.min_by_key(|site_pos| site_pos.distance_squared(center_chunk))
|
None => {
|
||||||
.unwrap_or(center_chunk);
|
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
|
// Calculate the middle of the chunk in the world
|
||||||
let spawn_wpos = TerrainChunkSize::center_wpos(spawn_chunk);
|
let spawn_wpos = TerrainChunkSize::center_wpos(spawn_chunk);
|
||||||
|
@ -42,6 +42,7 @@ pub struct Settings {
|
|||||||
pub banned_words_files: Vec<PathBuf>,
|
pub banned_words_files: Vec<PathBuf>,
|
||||||
pub max_player_group_size: u32,
|
pub max_player_group_size: u32,
|
||||||
pub client_timeout: Duration,
|
pub client_timeout: Duration,
|
||||||
|
pub spawn_town: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
@ -59,6 +60,7 @@ impl Default for Settings {
|
|||||||
banned_words_files: Vec::new(),
|
banned_words_files: Vec::new(),
|
||||||
max_player_group_size: 6,
|
max_player_group_size: 6,
|
||||||
client_timeout: Duration::from_secs(40),
|
client_timeout: Duration::from_secs(40),
|
||||||
|
spawn_town: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user