Skip to content

Commit

Permalink
Parsing .DTm works a bit, old ui now renders .DTm map
Browse files Browse the repository at this point in the history
  • Loading branch information
LedinecMing committed Nov 18, 2024
1 parent d54235a commit f8bbd9c
Show file tree
Hide file tree
Showing 14 changed files with 622 additions and 433 deletions.
12 changes: 7 additions & 5 deletions dt_lib/src/battle/army.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use num::{integer::sqrt, pow};
use once_cell::sync::Lazy;
use pathfinding::directed::astar::astar;

use super::control::Control;
use super::control::{Control, PC_ControlSetings};
#[derive(Clone, Debug, Default, Sections)]
#[alkahest(Deserialize, Serialize, SerializeRef, Formula)]
pub struct ArmyStats {
Expand Down Expand Up @@ -70,6 +70,7 @@ pub struct Army {
pub defeated: bool,
//#[default_value = "Control::PC"]
pub control: Control,
pub pc_settings: Option<PC_ControlSetings>,
//#[unused]
pub path: Vec<(usize, usize)>,
}
Expand Down Expand Up @@ -101,6 +102,7 @@ impl Army {
) -> Self {
let hitmap: Vec<Option<usize>> = (0..*MAX_TROOPS).map(|_| None::<usize>).collect();
let mut army = Army {
pc_settings: None,
troops: Vec::new(),
building: None,
hitmap,
Expand Down Expand Up @@ -221,8 +223,8 @@ impl Army {
Ok(())
}

pub fn add_item(&mut self, item: usize) {
self.inventory.push(Item { index: item })
pub fn add_item(&mut self, item: Item) {
self.inventory.push(item)
}
pub fn remove_item(&mut self, rem_item: usize) {
if let Some(index) = self
Expand Down Expand Up @@ -304,14 +306,14 @@ pub fn find_path(
}
.into_iter()
.filter(|p: &(usize, usize)| {
let hitbox = &gamemap.hitmap[p.0][p.1];
let hitbox = &gamemap.hitmap[*p];
hitbox.passable()
&& (!(hitbox.need_transport ^ on_transport)
|| hitbox.building.is_some_and(|n| {
objects[gamemap.buildings[n].id].obj_type == ObjectType::Bridge
}))
})
.map(|p| (p, 10 / TILES[gamemap.tilemap[p.0][p.1]].walkspeed))
.map(|p| (p, 10 / TILES[gamemap.tilemap[p]].walkspeed))
},
|&p| dist(&p, &goal),
|&p| p == goal,
Expand Down
41 changes: 27 additions & 14 deletions dt_lib/src/battle/control.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use advini::{Ini, IniParseError};
use alkahest::*;
use math_thingies::Percent;

use crate::time::time::Time;
#[derive(Clone, Debug)]
#[alkahest(Deserialize, Serialize, SerializeRef, Formula)]
pub struct Relations {
player: u8,
ally: u8,
neighbour: u8,
enemy: u8,
pub player: u8,
pub ally: u8,
pub neighbour: u8,
pub enemy: u8,
}
impl Ini for Relations {
fn eat(chars: std::str::Chars) -> Result<(Self, std::str::Chars), IniParseError> {
Expand Down Expand Up @@ -73,17 +76,27 @@ impl Ini for Control {
}

#[derive(Clone, Debug, Default)]
#[alkahest(Deserialize, Serialize, SerializeRef, Formula)]
pub struct PC_ControlSetings {
xp_like_player: bool,
xp_add: u64,
units_dont_have_money: bool,
ignores_ai_armys: bool,
targets_player: bool,
forbid_random_targets: bool,
forbid_random_talks: bool,
not_interested_in_buildings: bool,
patrol_radius: Option<u64>,
relations: Relations,
pub xp_like_player: bool,
pub xp_add: u64,
pub xp_correction: Percent,
pub gold_income: u64,
pub mana_income: u64,
pub speed_correction: Percent,
pub units_dont_have_money: bool,
pub ignores_ai_armys: bool,
pub targets_player: bool,
pub forbid_random_targets: bool,
pub forbid_random_talks: bool,
pub not_interested_in_buildings: bool,
pub aggression: u8,
pub patrol: u8,
pub revive_everyone: bool,
pub revive_time: Time,
pub garrison_power: u8,
pub patrol_radius: Option<u64>,
pub relations: Relations,
}
#[derive(Clone, Debug)]
pub enum Target {
Expand Down
1 change: 1 addition & 0 deletions dt_lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![allow(unused_imports)]
pub mod battle;
pub mod bonuses;
pub mod effects;
Expand Down
Loading

0 comments on commit f8bbd9c

Please sign in to comment.