2019-04-01 00:39:47 -07:00
|
|
|
//! `ObjectFreq` type.
|
|
|
|
|
2019-06-13 18:09:07 -07:00
|
|
|
use crate::err::*;
|
2019-04-01 00:39:47 -07:00
|
|
|
|
|
|
|
/// Reads a `plac` chunk.
|
|
|
|
pub fn read(b: &[u8]) -> ResultS<(ObjectFreq, usize)>
|
|
|
|
{
|
|
|
|
read_data! {
|
|
|
|
endian: BIG, buf: b, size: 12, start: 0, data {
|
2019-04-01 06:05:06 -07:00
|
|
|
let flags = u16[0] flag ObjectFreqFlags;
|
2019-04-01 00:39:47 -07:00
|
|
|
let cnt_ini = u16[2];
|
|
|
|
let cnt_min = u16[4];
|
|
|
|
let cnt_max = u16[6];
|
|
|
|
let cnt_rnd = u16[8];
|
|
|
|
let chance = u16[10];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 06:05:06 -07:00
|
|
|
Ok((ObjectFreq{flags, cnt_ini, cnt_min, cnt_max, cnt_rnd, chance}, 12))
|
2019-04-01 00:39:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/// The difficulty definition for various object types.
|
|
|
|
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
2019-06-21 18:34:10 -07:00
|
|
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
2019-06-25 03:52:21 -07:00
|
|
|
pub struct ObjectFreq {
|
2019-04-01 06:05:06 -07:00
|
|
|
pub flags: ObjectFreqFlags,
|
2019-04-01 00:39:47 -07:00
|
|
|
pub cnt_ini: u16,
|
|
|
|
pub cnt_min: u16,
|
|
|
|
pub cnt_max: u16,
|
|
|
|
pub cnt_rnd: u16,
|
|
|
|
pub chance: u16,
|
|
|
|
}
|
|
|
|
|
2019-07-02 21:34:14 -07:00
|
|
|
c_bitfield! {
|
2019-04-01 06:05:06 -07:00
|
|
|
/// Flags for `ObjectFreq`.
|
|
|
|
#[cfg_attr(feature = "serde_obj", derive(serde::Serialize))]
|
2019-06-25 03:52:21 -07:00
|
|
|
pub struct ObjectFreqFlags: u16 {
|
2019-07-02 21:34:14 -07:00
|
|
|
RANDOM_LOCATION = 0,
|
|
|
|
_3 = 3,
|
|
|
|
_4 = 4,
|
|
|
|
_5 = 5,
|
|
|
|
_6 = 6,
|
2019-04-01 06:05:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-01 00:39:47 -07:00
|
|
|
// EOF
|