feat(mc-turn): ✨ Add CourierResolver and FormationMove components for pathfinding and movement logic in formations
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
parent
34a4965797
commit
4080d67565
2 changed files with 6 additions and 4 deletions
|
|
@ -97,7 +97,7 @@ pub fn astar_path(
|
|||
era_tier: u8,
|
||||
) -> Option<Vec<(i32, i32)>> {
|
||||
let grid = state.grid.as_ref()?;
|
||||
let (w, h) = (grid.width, grid.height);
|
||||
let (grid_w, grid_h) = (grid.width, grid.height);
|
||||
|
||||
if start == goal {
|
||||
return Some(vec![start]);
|
||||
|
|
@ -109,8 +109,8 @@ pub fn astar_path(
|
|||
let mut came_from: HashMap<(i32, i32), (i32, i32)> = HashMap::new();
|
||||
|
||||
g_cost.insert(start, 0);
|
||||
let h = hex_dist(start, goal);
|
||||
open.push(Reverse((h, 0, start)));
|
||||
let h0 = hex_dist(start, goal);
|
||||
open.push(Reverse((h0, 0, start)));
|
||||
|
||||
while let Some(Reverse((_, g, pos))) = open.pop() {
|
||||
if pos == goal {
|
||||
|
|
@ -120,7 +120,7 @@ pub fn astar_path(
|
|||
if g > *g_cost.get(&pos).unwrap_or(&u32::MAX) {
|
||||
continue;
|
||||
}
|
||||
for neighbor in offset_neighbors(pos.0, pos.1, w, h) {
|
||||
for neighbor in offset_neighbors(pos.0, pos.1, grid_w, grid_h) {
|
||||
let step_cost = match tile_cost(state, neighbor.0, neighbor.1, era_tier) {
|
||||
Some(c) => c,
|
||||
None => continue, // impassable
|
||||
|
|
@ -299,6 +299,7 @@ impl<'a> CourierMapView for GameStateMapView<'a> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use rand::RngCore;
|
||||
use mc_trade::{
|
||||
CourierRoute, DiplomacyEvent, DiplomaticAgreement, SharedMapAgreement, TradeLedger,
|
||||
step_shared_map_agreements,
|
||||
|
|
|
|||
|
|
@ -458,6 +458,7 @@ mod tests {
|
|||
pending_formation_shapes: vec![],
|
||||
pending_split_requests: vec![],
|
||||
pending_auto_join_requests: vec![],
|
||||
..Default::default()
|
||||
};
|
||||
let unit_ids = vec![10u32, 11, 12];
|
||||
let positions = vec![(0i32, 0i32), (0, 1), (0, -1)];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue