2019-02-21 12:54:50 -08:00
|
|
|
use crate::{durandal::{bin::*, err::*, fixed::*}};
|
|
|
|
use bitflags::bitflags;
|
2019-02-20 20:03:19 -08:00
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
pub fn read_pxpx(b: &[u8]) -> ResultS<(Physics, usize)>
|
|
|
|
{
|
|
|
|
read_data! {
|
|
|
|
104, BE in b =>
|
2019-02-20 20:11:57 -08:00
|
|
|
vel_fwd = Fixed[0];
|
|
|
|
vel_bkw = Fixed[4];
|
|
|
|
vel_prp = Fixed[8];
|
|
|
|
acc_nrm = Fixed[12];
|
|
|
|
dec_nrm = Fixed[16];
|
|
|
|
dec_air = Fixed[20];
|
|
|
|
acc_grv = Fixed[24];
|
|
|
|
acc_cli = Fixed[28];
|
|
|
|
vel_trm = Fixed[32];
|
|
|
|
dec_ext = Fixed[36];
|
|
|
|
acc_ang = Fixed[40];
|
|
|
|
dec_ang = Fixed[44];
|
|
|
|
vel_ang = Fixed[48];
|
|
|
|
vel_rec = Fixed[52];
|
|
|
|
fng_vel = Fixed[56];
|
|
|
|
fng_max = Fixed[60];
|
|
|
|
ele_max = Fixed[64];
|
|
|
|
dec_xng = Fixed[68];
|
|
|
|
stp_dta = Fixed[72];
|
|
|
|
stp_amp = Fixed[76];
|
|
|
|
ply_rad = Fixed[80];
|
|
|
|
ply_hei = Fixed[84];
|
|
|
|
ply_dhi = Fixed[88];
|
|
|
|
ply_cam = Fixed[92];
|
|
|
|
ply_spl = Fixed[96];
|
|
|
|
ply_hcm = Fixed[100];
|
2019-02-20 20:03:19 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok((Physics{acc_ang, acc_cli, acc_grv, acc_nrm, dec_air, dec_ang, dec_ext,
|
|
|
|
dec_nrm, dec_xng, ele_max, fng_max, fng_vel, ply_cam, ply_dhi,
|
|
|
|
ply_hcm, ply_hei, ply_rad, ply_spl, stp_amp, stp_dta, vel_ang,
|
|
|
|
vel_bkw, vel_fwd, vel_prp, vel_rec, vel_trm}, 104))
|
|
|
|
}
|
|
|
|
|
2019-02-21 12:54:50 -08:00
|
|
|
pub fn read_fxpx(b: &[u8]) -> ResultS<(Effect, usize)>
|
|
|
|
{
|
|
|
|
read_data! {
|
|
|
|
14, BE in b =>
|
|
|
|
collection = u16[0];
|
|
|
|
shape = u16[2];
|
|
|
|
pitch = Fixed[4];
|
|
|
|
flags = u16[8];
|
2019-02-21 14:11:48 -08:00
|
|
|
delay = OptU16[10];
|
|
|
|
delay_snd = OptU16[12];
|
2019-02-21 12:54:50 -08:00
|
|
|
}
|
|
|
|
|
2019-02-21 13:12:26 -08:00
|
|
|
let flags = flag_ok!(EffectFlags, flags)?;
|
2019-02-21 12:54:50 -08:00
|
|
|
|
|
|
|
Ok((Effect{collection, shape, pitch, flags, delay, delay_snd}, 14))
|
|
|
|
}
|
|
|
|
|
2019-02-21 15:22:40 -08:00
|
|
|
pub fn read_wppx(b: &[u8]) -> ResultS<(Weapon, usize)>
|
|
|
|
{
|
|
|
|
read_data! {
|
|
|
|
134, BE in b =>
|
|
|
|
typ_item = u16[0];
|
|
|
|
typ_powerup = OptU16[2];
|
|
|
|
typ_weapon = u16[4];
|
|
|
|
flags = u16[6];
|
|
|
|
lit_value = Fixed[8];
|
|
|
|
lit_decay = u16[12];
|
|
|
|
hei_idle = Fixed[14];
|
|
|
|
amp_bob = Fixed[18];
|
|
|
|
hei_kick = Fixed[22];
|
|
|
|
hei_reload = Fixed[26];
|
|
|
|
wid_idle = Fixed[30];
|
|
|
|
amp_horz = Fixed[34];
|
|
|
|
collection = u16[38];
|
|
|
|
frm_idle = u16[40];
|
|
|
|
frm_firing = u16[42];
|
|
|
|
frm_reload = OptU16[44];
|
|
|
|
frm_charge = OptU16[48];
|
|
|
|
frm_charged = OptU16[50];
|
|
|
|
tic_ready = u16[52];
|
|
|
|
tic_load_beg = u16[54];
|
|
|
|
tic_load_mid = u16[56];
|
|
|
|
tic_load_end = u16[58];
|
|
|
|
tic_powerup = u16[60];
|
|
|
|
trig_pri = read_trigger[62..98];
|
|
|
|
trig_sec = read_trigger[98..134];
|
|
|
|
}
|
|
|
|
|
|
|
|
let typ_weapon = WeaponType::from_repr(typ_weapon)?;
|
|
|
|
let flags = flag_ok!(WeaponFlags, flags)?;
|
|
|
|
|
|
|
|
Ok((Weapon{amp_bob, amp_horz, collection, flags, frm_charge, frm_charged,
|
|
|
|
frm_firing, frm_idle, frm_reload, hei_idle, hei_kick, hei_reload,
|
|
|
|
lit_decay, lit_value, tic_load_beg, tic_load_end, tic_load_mid,
|
|
|
|
tic_powerup, tic_ready, trig_pri, trig_sec, typ_item,
|
|
|
|
typ_powerup, typ_weapon, wid_idle}, 134))
|
|
|
|
}
|
|
|
|
|
2019-02-22 10:35:42 -08:00
|
|
|
pub fn read_prpx(b: &[u8]) -> ResultS<(Projectile, usize)>
|
|
|
|
{
|
|
|
|
read_data! {
|
|
|
|
48, BE in b =>
|
|
|
|
collection = OptU16[0];
|
|
|
|
shape = u16[2];
|
|
|
|
fxt_explode = OptU16[4];
|
|
|
|
fxt_exp_media = OptU16[6];
|
|
|
|
fxt_trail = OptU16[8];
|
|
|
|
tic_trail = u16[10];
|
|
|
|
max_trail = OptU16[12];
|
|
|
|
typ_media = OptU16[14];
|
|
|
|
radius = Unit[16];
|
|
|
|
dmg_rad = Unit[18];
|
|
|
|
dmg_def = read_damage[20..32];
|
|
|
|
flags = u32[32];
|
|
|
|
speed = Unit[36];
|
|
|
|
range = Unit[38];
|
|
|
|
snd_pitch = Fixed[40];
|
|
|
|
snd_fly = OptU16[44];
|
|
|
|
snd_bounce = OptU16[46];
|
|
|
|
}
|
|
|
|
|
|
|
|
let flags = flag_ok!(ProjectileFlags, flags)?;
|
|
|
|
|
|
|
|
Ok((Projectile{collection, shape, fxt_explode, fxt_exp_media, fxt_trail,
|
|
|
|
tic_trail, max_trail, typ_media, radius, dmg_rad, dmg_def,
|
|
|
|
flags, speed, range, snd_pitch, snd_fly, snd_bounce}, 48))
|
|
|
|
}
|
|
|
|
|
2019-02-21 15:22:40 -08:00
|
|
|
fn read_trigger(b: &[u8]) -> ResultS<Trigger>
|
|
|
|
{
|
|
|
|
read_data! {
|
|
|
|
36, BE in b =>
|
|
|
|
magazine = u16[0];
|
|
|
|
typ_ammo = OptU16[2];
|
|
|
|
tic_round = OptU16[4];
|
|
|
|
tic_recover = u16[6];
|
|
|
|
tic_charge = u16[8];
|
|
|
|
recoil = Unit[10];
|
|
|
|
snd_fire = OptU16[12];
|
|
|
|
snd_click = OptU16[14];
|
|
|
|
snd_charge = OptU16[16];
|
|
|
|
snd_casing = OptU16[18];
|
|
|
|
snd_reload = OptU16[20];
|
|
|
|
snd_charged = OptU16[22];
|
|
|
|
typ_proj = u16[24];
|
|
|
|
theta = u16[26];
|
|
|
|
dx = i16[28];
|
|
|
|
dz = i16[30];
|
|
|
|
typ_casing = u16[32];
|
|
|
|
burst = u16[34];
|
|
|
|
}
|
|
|
|
|
|
|
|
let typ_casing = CasingType::from_repr(typ_casing)?;
|
|
|
|
|
|
|
|
Ok(Trigger{burst, dx, dz, magazine, recoil, snd_casing, snd_charge,
|
|
|
|
snd_charged, snd_click, snd_fire, snd_reload, theta, tic_charge,
|
|
|
|
tic_recover, tic_round, typ_ammo, typ_casing, typ_proj})
|
|
|
|
}
|
|
|
|
|
2019-02-22 10:35:42 -08:00
|
|
|
fn read_damage(b: &[u8]) -> ResultS<Damage>
|
|
|
|
{
|
|
|
|
read_data! {
|
|
|
|
12, BE in b =>
|
|
|
|
dtype = u16[0];
|
|
|
|
flags = u16[2];
|
|
|
|
dmg_base = u16[4];
|
|
|
|
dmg_rand = u16[6];
|
|
|
|
scale = Fixed[8];
|
|
|
|
}
|
|
|
|
|
|
|
|
let dtype = DamageType::from_repr(dtype)?;
|
|
|
|
let alien = flags != 0;
|
|
|
|
|
|
|
|
Ok(Damage{dtype, alien, dmg_base, dmg_rand, scale})
|
|
|
|
}
|
|
|
|
|
2019-02-20 20:03:19 -08:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub struct Physics
|
|
|
|
{
|
|
|
|
pub acc_ang: Fixed,
|
|
|
|
pub acc_cli: Fixed,
|
|
|
|
pub acc_grv: Fixed,
|
|
|
|
pub acc_nrm: Fixed,
|
|
|
|
pub dec_air: Fixed,
|
|
|
|
pub dec_ang: Fixed,
|
|
|
|
pub dec_ext: Fixed,
|
|
|
|
pub dec_nrm: Fixed,
|
|
|
|
pub dec_xng: Fixed,
|
|
|
|
pub ele_max: Fixed,
|
|
|
|
pub fng_max: Fixed,
|
|
|
|
pub fng_vel: Fixed,
|
|
|
|
pub ply_cam: Fixed,
|
|
|
|
pub ply_dhi: Fixed,
|
|
|
|
pub ply_hcm: Fixed,
|
|
|
|
pub ply_hei: Fixed,
|
|
|
|
pub ply_rad: Fixed,
|
|
|
|
pub ply_spl: Fixed,
|
|
|
|
pub stp_amp: Fixed,
|
|
|
|
pub stp_dta: Fixed,
|
|
|
|
pub vel_ang: Fixed,
|
|
|
|
pub vel_bkw: Fixed,
|
|
|
|
pub vel_fwd: Fixed,
|
|
|
|
pub vel_prp: Fixed,
|
|
|
|
pub vel_rec: Fixed,
|
|
|
|
pub vel_trm: Fixed,
|
|
|
|
}
|
|
|
|
|
2019-02-21 12:54:50 -08:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub struct Effect
|
|
|
|
{
|
|
|
|
pub collection: u16,
|
|
|
|
pub shape: u16,
|
|
|
|
pub pitch: Fixed,
|
|
|
|
pub flags: EffectFlags,
|
2019-02-21 14:11:48 -08:00
|
|
|
pub delay: OptU16,
|
|
|
|
pub delay_snd: OptU16,
|
2019-02-21 12:54:50 -08:00
|
|
|
}
|
|
|
|
|
2019-02-21 15:22:40 -08:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub struct Weapon
|
|
|
|
{
|
|
|
|
pub amp_bob: Fixed,
|
|
|
|
pub amp_horz: Fixed,
|
|
|
|
pub collection: u16,
|
|
|
|
pub flags: WeaponFlags,
|
|
|
|
pub frm_charge: OptU16,
|
|
|
|
pub frm_charged: OptU16,
|
|
|
|
pub frm_firing: u16,
|
|
|
|
pub frm_idle: u16,
|
|
|
|
pub frm_reload: OptU16,
|
|
|
|
pub hei_idle: Fixed,
|
|
|
|
pub hei_kick: Fixed,
|
|
|
|
pub hei_reload: Fixed,
|
|
|
|
pub lit_decay: u16,
|
|
|
|
pub lit_value: Fixed,
|
|
|
|
pub tic_load_beg: u16,
|
|
|
|
pub tic_load_end: u16,
|
|
|
|
pub tic_load_mid: u16,
|
|
|
|
pub tic_powerup: u16,
|
|
|
|
pub tic_ready: u16,
|
|
|
|
pub trig_pri: Trigger,
|
|
|
|
pub trig_sec: Trigger,
|
|
|
|
pub typ_item: u16,
|
|
|
|
pub typ_powerup: OptU16,
|
|
|
|
pub typ_weapon: WeaponType,
|
|
|
|
pub wid_idle: Fixed,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub struct Trigger
|
|
|
|
{
|
|
|
|
pub burst: u16,
|
|
|
|
pub dx: i16,
|
|
|
|
pub dz: i16,
|
|
|
|
pub magazine: u16,
|
|
|
|
pub recoil: Unit,
|
|
|
|
pub snd_casing: OptU16,
|
|
|
|
pub snd_charge: OptU16,
|
|
|
|
pub snd_charged: OptU16,
|
|
|
|
pub snd_click: OptU16,
|
|
|
|
pub snd_fire: OptU16,
|
|
|
|
pub snd_reload: OptU16,
|
|
|
|
pub theta: u16,
|
|
|
|
pub tic_charge: u16,
|
|
|
|
pub tic_recover: u16,
|
|
|
|
pub tic_round: OptU16,
|
|
|
|
pub typ_ammo: OptU16,
|
|
|
|
pub typ_casing: CasingType,
|
|
|
|
pub typ_proj: u16,
|
|
|
|
}
|
|
|
|
|
2019-02-22 10:35:42 -08:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub struct Projectile
|
|
|
|
{
|
|
|
|
pub collection: OptU16,
|
|
|
|
pub shape: u16,
|
|
|
|
pub fxt_explode: OptU16,
|
|
|
|
pub fxt_exp_media: OptU16,
|
|
|
|
pub fxt_trail: OptU16,
|
|
|
|
pub tic_trail: u16,
|
|
|
|
pub max_trail: OptU16,
|
|
|
|
pub typ_media: OptU16,
|
|
|
|
pub radius: Unit,
|
|
|
|
pub dmg_rad: Unit,
|
|
|
|
pub dmg_def: Damage,
|
|
|
|
pub flags: ProjectileFlags,
|
|
|
|
pub speed: Unit,
|
|
|
|
pub range: Unit,
|
|
|
|
pub snd_pitch: Fixed,
|
|
|
|
pub snd_fly: OptU16,
|
|
|
|
pub snd_bounce: OptU16,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub struct Damage
|
|
|
|
{
|
|
|
|
pub dtype: DamageType,
|
|
|
|
pub alien: bool,
|
|
|
|
pub dmg_base: u16,
|
|
|
|
pub dmg_rand: u16,
|
|
|
|
pub scale: Fixed,
|
|
|
|
}
|
|
|
|
|
2019-02-21 12:54:50 -08:00
|
|
|
bitflags! {
|
|
|
|
#[derive(Serialize)]
|
|
|
|
pub struct EffectFlags: u16
|
|
|
|
{
|
|
|
|
const EndOnLoop = 1;
|
|
|
|
const EndOnXferLoop = 1 << 1;
|
|
|
|
const SoundOnly = 1 << 2;
|
|
|
|
const MakeTwinVisible = 1 << 3;
|
|
|
|
const MediaEffect = 1 << 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-21 15:22:40 -08:00
|
|
|
bitflags! {
|
|
|
|
#[derive(Serialize)]
|
|
|
|
pub struct WeaponFlags: u16
|
|
|
|
{
|
|
|
|
const Automatic = 1;
|
|
|
|
const RemoveAfterUse = 1 << 1;
|
|
|
|
const InstantCasing = 1 << 2;
|
|
|
|
const Overloads = 1 << 3;
|
|
|
|
const RandomAmmo = 1 << 4;
|
|
|
|
const TemporaryPower = 1 << 5;
|
|
|
|
const ReloadOneHand = 1 << 6;
|
|
|
|
const FireOutOfPhase = 1 << 7;
|
|
|
|
const FireUnderMedia = 1 << 8;
|
|
|
|
const TriggerSameAmmo = 1 << 9;
|
|
|
|
const SecondaryFlip = 1 << 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 10:35:42 -08:00
|
|
|
bitflags! {
|
|
|
|
#[derive(Serialize)]
|
|
|
|
pub struct ProjectileFlags: u32
|
|
|
|
{
|
|
|
|
const Guided = 1;
|
|
|
|
const StopOnLoop = 1 << 1;
|
|
|
|
const Persistent = 1 << 2;
|
|
|
|
const Alien = 1 << 3;
|
|
|
|
const Gravity = 1 << 4;
|
|
|
|
const NoHorzError = 1 << 5;
|
|
|
|
const NoVertError = 1 << 6;
|
|
|
|
const TogglePanels = 1 << 7;
|
|
|
|
const PosVertError = 1 << 8;
|
|
|
|
const Melee = 1 << 9;
|
|
|
|
const Ripper = 1 << 10;
|
|
|
|
const PassTransRandom = 1 << 11;
|
|
|
|
const PassTransMore = 1 << 12;
|
|
|
|
const DoubleGravity = 1 << 13;
|
|
|
|
const ReboundFloor = 1 << 14;
|
|
|
|
const ThroughMedia = 1 << 15;
|
|
|
|
const BecomeItem = 1 << 16;
|
|
|
|
const Bloody = 1 << 17;
|
|
|
|
const WanderHorz = 1 << 18;
|
|
|
|
const UseLowGrav = 1 << 19;
|
|
|
|
const PassMedia = 1 << 20;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-21 15:22:40 -08:00
|
|
|
c_enum! {
|
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub enum CasingType: u16
|
|
|
|
{
|
|
|
|
0 => Rifle,
|
|
|
|
1 => Pistol,
|
|
|
|
2 => PistolLeft,
|
|
|
|
3 => PistolRight,
|
|
|
|
4 => SMG,
|
|
|
|
65535 => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
c_enum! {
|
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub enum WeaponType: u16
|
|
|
|
{
|
|
|
|
0 => Melee,
|
|
|
|
1 => Normal,
|
|
|
|
2 => DualFunc,
|
|
|
|
3 => DualPistol,
|
|
|
|
4 => Multipurpose,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-22 10:35:42 -08:00
|
|
|
c_enum! {
|
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
pub enum DamageType: u16
|
|
|
|
{
|
|
|
|
0 => Explosion,
|
|
|
|
1 => ElectricalStaff,
|
|
|
|
2 => Projectile,
|
|
|
|
3 => Absorbed,
|
|
|
|
4 => Flame,
|
|
|
|
5 => HoundClaws,
|
|
|
|
6 => AlienProjectile,
|
|
|
|
7 => HulkSlap,
|
|
|
|
8 => CompilerBolt,
|
|
|
|
9 => FusionBolt,
|
|
|
|
10 => HunterBolt,
|
|
|
|
11 => Fist,
|
|
|
|
12 => Teleporter,
|
|
|
|
13 => Defender,
|
|
|
|
14 => YetiClaws,
|
|
|
|
15 => YetiProjectile,
|
|
|
|
16 => Crushing,
|
|
|
|
17 => Lava,
|
|
|
|
18 => Suffocation,
|
|
|
|
19 => Goo,
|
|
|
|
20 => EnergyDrain,
|
|
|
|
21 => OxygenDrain,
|
|
|
|
22 => HummerBolt,
|
|
|
|
23 => ShotgunProjectile,
|
|
|
|
65535 => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-20 20:03:19 -08:00
|
|
|
// EOF
|