2025-03-15 19:34:29 -04:00
|
|
|
use physis::{
|
2025-03-15 21:41:39 -04:00
|
|
|
common::{Language, Platform},
|
2025-03-15 19:34:29 -04:00
|
|
|
gamedata::GameData,
|
|
|
|
layer::{
|
|
|
|
ExitRangeInstanceObject, InstanceObject, LayerEntryData, LayerGroup, PopRangeInstanceObject,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2025-03-15 20:36:39 -04:00
|
|
|
use crate::config::get_config;
|
2025-03-15 19:34:29 -04:00
|
|
|
|
|
|
|
/// Represents a loaded zone
|
|
|
|
pub struct Zone {
|
2025-03-15 20:49:07 -04:00
|
|
|
pub id: u16,
|
2025-03-23 16:31:30 -04:00
|
|
|
layer_group: Option<LayerGroup>,
|
2025-03-15 19:34:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Zone {
|
|
|
|
pub fn load(id: u16) -> Self {
|
|
|
|
let config = get_config();
|
|
|
|
|
2025-03-23 16:31:30 -04:00
|
|
|
let mut zone = Self {
|
|
|
|
id,
|
|
|
|
layer_group: None,
|
|
|
|
};
|
|
|
|
|
|
|
|
let Some(mut game_data) = GameData::from_existing(Platform::Win32, &config.game_location)
|
|
|
|
else {
|
|
|
|
return zone;
|
|
|
|
};
|
2025-03-15 21:41:39 -04:00
|
|
|
|
2025-03-23 16:31:30 -04:00
|
|
|
let Some(exh) = game_data.read_excel_sheet_header("TerritoryType") else {
|
|
|
|
return zone;
|
|
|
|
};
|
|
|
|
let Some(exd) = game_data.read_excel_sheet("TerritoryType", &exh, Language::None, 0) else {
|
|
|
|
return zone;
|
|
|
|
};
|
2025-03-15 21:41:39 -04:00
|
|
|
|
2025-03-23 16:31:30 -04:00
|
|
|
let Some(territory_type_row) = &exd.read_row(&exh, id as u32) else {
|
|
|
|
return zone;
|
|
|
|
};
|
|
|
|
let territory_type_row = &territory_type_row[0];
|
2025-03-15 21:41:39 -04:00
|
|
|
|
|
|
|
// e.g. ffxiv/fst_f1/fld/f1f3/level/f1f3
|
|
|
|
let physis::exd::ColumnData::String(bg_path) = &territory_type_row.data[1] else {
|
|
|
|
panic!("Unexpected type!");
|
|
|
|
};
|
|
|
|
|
2025-03-23 16:31:30 -04:00
|
|
|
let Some(level_index) = bg_path.find("/level/") else {
|
|
|
|
return zone;
|
|
|
|
};
|
|
|
|
|
|
|
|
let path = format!("bg/{}/level/planmap.lgb", &bg_path[..level_index]);
|
|
|
|
let Some(lgb) = game_data.extract(&path) else {
|
|
|
|
return zone;
|
|
|
|
};
|
|
|
|
zone.layer_group = LayerGroup::from_existing(&lgb);
|
|
|
|
|
|
|
|
zone
|
2025-03-15 19:34:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Search for an exit box matching an id.
|
|
|
|
pub fn find_exit_box(
|
|
|
|
&self,
|
|
|
|
instance_id: u32,
|
|
|
|
) -> Option<(&InstanceObject, &ExitRangeInstanceObject)> {
|
|
|
|
// TODO: also check position!
|
2025-03-23 16:31:30 -04:00
|
|
|
for group in &self.layer_group.as_ref().unwrap().layers {
|
2025-03-15 19:34:29 -04:00
|
|
|
for object in &group.objects {
|
|
|
|
if let LayerEntryData::ExitRange(exit_range) = &object.data {
|
|
|
|
if object.instance_id == instance_id {
|
|
|
|
return Some((object, exit_range));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn find_pop_range(
|
|
|
|
&self,
|
|
|
|
instance_id: u32,
|
|
|
|
) -> Option<(&InstanceObject, &PopRangeInstanceObject)> {
|
|
|
|
// TODO: also check position!
|
2025-03-23 16:31:30 -04:00
|
|
|
for group in &self.layer_group.as_ref().unwrap().layers {
|
2025-03-15 19:34:29 -04:00
|
|
|
for object in &group.objects {
|
|
|
|
if let LayerEntryData::PopRange(pop_range) = &object.data {
|
|
|
|
if object.instance_id == instance_id {
|
|
|
|
return Some((object, pop_range));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|