Buildings Processing
Tile/Chunk updates events
This commit is contained in:
@@ -144,6 +144,7 @@ impl HexCoord {
|
||||
};
|
||||
}
|
||||
|
||||
/// Converts this coordinate to it's chunk local equivalent
|
||||
pub fn to_chunk(&self) -> HexCoord {
|
||||
let c_pos = self.to_chunk_pos();
|
||||
let off = self.to_offset();
|
||||
@@ -164,14 +165,20 @@ impl HexCoord {
|
||||
return IVec2::new(self.hex.x + (self.hex.y / 2), self.hex.y);
|
||||
}
|
||||
|
||||
/// Convert the current coordiante to an index
|
||||
pub fn to_index(&self, width: usize) -> usize {
|
||||
return ((self.hex.x + self.hex.y * width as i32) + (self.hex.y / 2)) as usize;
|
||||
}
|
||||
|
||||
/// Gets the index of this coord in the chunk array.
|
||||
///
|
||||
/// [`width`] is in number of chunks
|
||||
pub fn to_chunk_index(&self, width: usize) -> usize {
|
||||
let pos = self.to_chunk_pos();
|
||||
return (pos.x + pos.y * width as i32) as usize;
|
||||
}
|
||||
|
||||
/// Gets the index of this tile in the chunk
|
||||
pub fn to_chunk_local_index(&self) -> usize {
|
||||
return self.to_chunk().to_index(Chunk::SIZE);
|
||||
}
|
||||
@@ -251,6 +258,37 @@ impl HexCoord {
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn hex_select_bounded(
|
||||
&self,
|
||||
radius: usize,
|
||||
include_center: bool,
|
||||
height: usize,
|
||||
width: usize,
|
||||
) -> Vec<HexCoord> {
|
||||
assert!(radius != 0, "Radius cannot be zero");
|
||||
let mut result = Vec::with_capacity(get_tile_count(radius));
|
||||
|
||||
if include_center {
|
||||
if self.is_in_bounds(height, width) {
|
||||
result.push(*self);
|
||||
}
|
||||
}
|
||||
|
||||
for k in 0..(radius + 1) {
|
||||
let mut p = self.scale(4, k);
|
||||
for i in 0..6 {
|
||||
for _j in 0..k {
|
||||
p = p.get_neighbor(i);
|
||||
if p.is_in_bounds(height, width) {
|
||||
result.push(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
pub fn select_ring(&self, radius: usize) -> Vec<HexCoord> {
|
||||
assert!(radius != 0, "Radius cannot be zero");
|
||||
let mut result = Vec::with_capacity(radius * 6);
|
||||
|
||||
Reference in New Issue
Block a user