|
|
@ -217,7 +217,7 @@ struct RawMapObject { |
|
|
|
|
|
|
|
impl RawMapObject {
|
|
|
|
fn from_byte_stream<R: Read>(cursor: &mut R) -> Result<RawMapObject, std::io::Error> {
|
|
|
|
Ok(RawMapObject {
|
|
|
|
let o = RawMapObject {
|
|
|
|
otype: cursor.read_u16::<LittleEndian>()?,
|
|
|
|
unknown1: cursor.read_u16::<LittleEndian>()?,
|
|
|
|
unknown2: cursor.read_u32::<LittleEndian>()?,
|
|
|
@ -238,7 +238,11 @@ impl RawMapObject { |
|
|
|
field5: cursor.read_u32::<LittleEndian>()?,
|
|
|
|
field6: cursor.read_u32::<LittleEndian>()?,
|
|
|
|
field7: cursor.read_u32::<LittleEndian>()?,
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
println!("{:?}", o);
|
|
|
|
|
|
|
|
Ok(o)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
@ -310,6 +314,8 @@ pub enum MapObjectType { |
|
|
|
#[derive(Debug, Copy, Clone)]
|
|
|
|
pub struct MapObject {
|
|
|
|
pub object: MapObjectType,
|
|
|
|
pub map: MapArea,
|
|
|
|
pub dropped_item: bool,
|
|
|
|
//id: u32,
|
|
|
|
}
|
|
|
|
|
|
|
@ -320,7 +326,7 @@ enum MapObjectError { |
|
|
|
|
|
|
|
|
|
|
|
impl MapObject {
|
|
|
|
fn from_raw(raw: RawMapObject, episode: Episode) -> Result<MapObject, MapObjectError> {
|
|
|
|
fn from_raw(raw: RawMapObject, episode: Episode, map_area: &MapArea) -> Result<MapObject, MapObjectError> {
|
|
|
|
let object = match (raw, episode) {
|
|
|
|
(RawMapObject {otype: 136, ..}, _) => MapObjectType::Box,
|
|
|
|
(RawMapObject {otype: 145, ..}, _) => MapObjectType::EnemyBox,
|
|
|
@ -335,8 +341,11 @@ impl MapObject { |
|
|
|
_ => return Err(MapObjectError::UnknownObjectType(raw.otype, raw))
|
|
|
|
};
|
|
|
|
|
|
|
|
println!("{:#?}", object);
|
|
|
|
Ok(MapObject {
|
|
|
|
object: object,
|
|
|
|
map: map_area.clone(),
|
|
|
|
dropped_item: false,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -496,7 +505,7 @@ impl MapVariant { |
|
|
|
|
|
|
|
fn obj_file(&self) -> String {
|
|
|
|
match self.map {
|
|
|
|
MapArea::Pioneer2Ep1 => "data/maps/map_city00_00e.dat".into(),
|
|
|
|
MapArea::Pioneer2Ep1 => "data/maps/map_city00_00o.dat".into(),
|
|
|
|
MapArea::Forest1 => format!("data/maps/map_forest01_0{}o.dat", self.minor),
|
|
|
|
MapArea::Forest2 => format!("data/maps/map_forest02_0{}o.dat", self.minor),
|
|
|
|
MapArea::Caves1 => format!("data/maps/map_cave01_0{}_0{}o.dat", self.major, self.minor),
|
|
|
@ -520,12 +529,12 @@ impl MapVariant { |
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn objects_from_map_data(path: PathBuf, episode: &Episode) -> Vec<Option<MapObject>> {
|
|
|
|
fn objects_from_map_data(path: PathBuf, episode: &Episode, map_variant: &MapVariant) -> Vec<Option<MapObject>> {
|
|
|
|
let mut cursor = File::open(path.clone()).unwrap();
|
|
|
|
let mut object_data = Vec::new();
|
|
|
|
|
|
|
|
while let Ok(raw_object) = RawMapObject::from_byte_stream(&mut cursor) {
|
|
|
|
let object = MapObject::from_raw(raw_object.clone(), *episode);
|
|
|
|
let object = MapObject::from_raw(raw_object.clone(), *episode, &map_variant.map);
|
|
|
|
object_data.push(object.ok());
|
|
|
|
|
|
|
|
}
|
|
|
@ -631,6 +640,7 @@ fn enemy_data_from_map_data(map_variant: &MapVariant, episode: &Episode) -> Vec< |
|
|
|
#[error("")]
|
|
|
|
pub enum MapsError {
|
|
|
|
InvalidMonsterId(usize),
|
|
|
|
InvalidObjectId(usize),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
@ -670,7 +680,7 @@ impl Maps { |
|
|
|
enemy_data
|
|
|
|
}),
|
|
|
|
object_data: map_variants.iter().map(|map_variant| {
|
|
|
|
objects_from_map_data(map_variant.obj_file().into(), &episode)
|
|
|
|
objects_from_map_data(map_variant.obj_file().into(), &episode, &map_variant)
|
|
|
|
}).flatten().collect(),
|
|
|
|
map_variants: map_variants,
|
|
|
|
};
|
|
|
@ -682,6 +692,10 @@ impl Maps { |
|
|
|
self.enemy_data[id].ok_or(MapsError::InvalidMonsterId(id))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn object_by_id(&self, id: usize) -> Result<MapObject, MapsError> {
|
|
|
|
self.object_data[id].ok_or(MapsError::InvalidObjectId(id))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn map_headers(&self) -> [u32; 0x20] {
|
|
|
|
self.map_variants.iter()
|
|
|
|
.enumerate()
|
|
|
|