1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! # Stronghold Kingdoms Formation Parser
//!
//! A Rust library for parsing Stronghold Kingdoms attack formation files (`.cas` files).
//!
//! ## Quick Start
//!
//! ```no_run
//! use shk_parser::{parse_formation, parse_formation_file};
//!
//! // Parse from bytes
//! let data = std::fs::read("formation.cas")?;
//! let units = parse_formation(&data)?;
//!
//! // Or parse directly from file
//! let units = parse_formation_file("formation.cas")?;
//!
//! // Display the units
//! for unit in &units {
//! println!("{}", unit);
//! }
//! # Ok::<(), Box<dyn std::error::Error>>(())
//! ```
//!
//! ## Supported Units
//!
//! - **Archers**: Basic ranged units
//! - **Pikemen**: Basic melee units
//! - **Catapults**: Siege weapons with target coordinates
//! - **Captains**: Special units with abilities:
//! - Delay: Wait for specified time
//! - Rallying Cry: Rally nearby troops
//! - Arrow Volley: Shoot arrows at target location
//! - Battle Cry: Boost morale
//! - Catapults Volley: Catapult attack at target location
//!
//! ## Features
//!
//! - **`serde`**: Enables JSON serialization/deserialization support
//! - **`tsify`**: Enables TypeScript type generation for WASM bindings (requires `serde`)
//! - **`cli`**: Enables the command-line interface
// Re-export the main types for convenience
pub use ;
pub use ;
/// Parse a formation from raw bytes
///
/// This is the main parsing function. It takes the raw bytes of a `.cas` file
/// and returns a vector of unit records.
///
/// # Examples
///
/// ```no_run
/// use shk_parser::parse_formation;
///
/// let data = std::fs::read("formation.cas")?;
/// let units = parse_formation(&data)?;
///
/// println!("Formation contains {} units", units.len());
/// for unit in &units {
/// println!("- {}", unit);
/// }
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
///
/// # Errors
///
/// Returns `ParseError` if the data is invalid or malformed.
/// See [`AttackSetupParser::parse`] for detailed error conditions.
/// Parse a formation file directly
///
/// Convenience function that reads the file and parses it in one step.
///
/// # Examples
///
/// ```no_run
/// use shk_parser::parse_formation_file;
///
/// let units = parse_formation_file("my_formation.cas")?;
/// println!("Loaded {} units from formation", units.len());
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
///
/// # Errors
///
/// Returns `ParseError` if the file cannot be read or contains invalid data.
/// See [`AttackSetupParser::parse_file`] for detailed error conditions.