Browse Source

init map code

pbs
jake 5 years ago
parent
commit
c2a13536a8
  1. 181
      src/ship/map.rs
  2. 1
      src/ship/mod.rs

181
src/ship/map.rs

@ -0,0 +1,181 @@
use log::warn;
use std::io::Cursor;
use std::convert::Into;
use std::path::PathBuf;
use std::io::{Read};
use std::fs::File;
use byteorder::{LittleEndian, ReadBytesExt};
use crate::ship::monster::MonsterType;
#[derive(Debug, Copy, Clone)]
struct RawMapEnemy {
id: u32,
_unknown1: u16,
children: u16,
_unknown3: u16,
_unknown4: u16,
section: u16,
wave_idd: u16,
wave_id: u32,
x: f32,
y: f32,
z: f32,
xrot: u32,
yrot: u32,
zrot: u32,
_field1: f32,
_field2: f32,
_field3: f32,
_field4: f32,
_field5: f32,
skin: u32,
_field6: u32
}
impl RawMapEnemy {
fn from_byte_stream<R: Read>(cursor: &mut R) -> Result<RawMapEnemy, std::io::Error> {
Ok(RawMapEnemy {
id: cursor.read_u32::<LittleEndian>()?,
_unknown1: cursor.read_u16::<LittleEndian>()?,
children: cursor.read_u16::<LittleEndian>()?,
_unknown3: cursor.read_u16::<LittleEndian>()?,
_unknown4: cursor.read_u16::<LittleEndian>()?,
section: cursor.read_u16::<LittleEndian>()?,
wave_idd: cursor.read_u16::<LittleEndian>()?,
wave_id: cursor.read_u32::<LittleEndian>()?,
x: cursor.read_f32::<LittleEndian>()?,
y: cursor.read_f32::<LittleEndian>()?,
z: cursor.read_f32::<LittleEndian>()?,
xrot: cursor.read_u32::<LittleEndian>()?,
yrot: cursor.read_u32::<LittleEndian>()?,
zrot: cursor.read_u32::<LittleEndian>()?,
_field1: cursor.read_f32::<LittleEndian>()?,
_field2: cursor.read_f32::<LittleEndian>()?,
_field3: cursor.read_f32::<LittleEndian>()?,
_field4: cursor.read_f32::<LittleEndian>()?,
_field5: cursor.read_f32::<LittleEndian>()?,
skin: cursor.read_u32::<LittleEndian>()?,
_field6: cursor.read_u32::<LittleEndian>()?,
})
}
}
struct MapObjects {
}
struct MapEnemies {
}
impl MapEnemies {
fn new(path: PathBuf) -> MapEnemies {
MapEnemies {
}
}
fn read_next_enemy(&mut self) -> Option<MapEnemy> {
None
}
}
#[derive(Debug, Copy, Clone)]
pub struct MapEnemy {
pub monster: MonsterType,
hp: u32,
// other stats from bp.n
dead: bool,
}
impl MapEnemy {
fn from_raw(enemy: RawMapEnemy /*, battleparam */) -> MapEnemy {
//warn!("loading {} {} {}", enemy.id, enemy.skin, enemy.children);
warn!("{:?}", enemy);
let monster = match (enemy.id, enemy.skin) {
(66, 0) => MonsterType::Monest,
(68, 0) => MonsterType::Booma,
(68, 1) => MonsterType::Gobooma,
(68, 2) => MonsterType::Gigobooma,
(99, 0) => MonsterType::EvilShark,
_ => MonsterType::AlRappy,
};
MapEnemy {
monster: monster,
hp: 0,
dead: false,
}
}
fn new(monster: MonsterType) -> MapEnemy {
MapEnemy {
monster: monster,
hp: 0,
dead: false,
}
}
}
//impl From<RawMapEnemy> for MapEnemy
#[derive(Debug)]
pub struct Maps {
//map_indexes:
enemy_data: Vec<MapEnemy>
}
impl Maps {
pub fn new() -> Maps {
let mut maps = Maps {
enemy_data: Vec::new(),
};
maps.add_map("data/maps/map_city00_00e.dat".into());
maps.add_map("data/maps/map_forest01_00e.dat".into());
maps.add_map("data/maps/map_cave01_00_00e.dat".into());
warn!("len {}", maps.enemy_data.len());
maps
}
fn add_map(&mut self, path: PathBuf) {
let mut cursor = File::open(path).unwrap();
while let Ok(enemy) = RawMapEnemy::from_byte_stream(&mut cursor) {
let new_enemy = MapEnemy::from_raw(enemy);
match new_enemy.monster {
MonsterType::Monest => {
self.enemy_data.push(new_enemy);
for _ in 0..30 {
self.enemy_data.push(MapEnemy::new(MonsterType::Mothmant));
}
},
_ => self.enemy_data.push(new_enemy)
}
}
}
pub fn enemy_by_id(&self, id: usize) -> MapEnemy {
self.enemy_data[id]
}
}

1
src/ship/mod.rs

@ -3,4 +3,5 @@ pub mod location;
pub mod character;
pub mod room;
pub mod items;
pub mod map;
pub mod monster;
Loading…
Cancel
Save