comparison src/th06/ecl.rs @ 664:f08e8e3c6196

Use bitflags for the rank, instead of an u16.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sun, 11 Aug 2019 19:55:45 +0200
parents 598f3125cbac
children 965ecdbf0316
comparison
equal deleted inserted replaced
663:994f41154be8 664:f08e8e3c6196
4 IResult, 4 IResult,
5 bytes::complete::take_while_m_n, 5 bytes::complete::take_while_m_n,
6 number::complete::{le_u8, le_u16, le_u32, le_i16, le_i32, le_f32}, 6 number::complete::{le_u8, le_u16, le_u32, le_i16, le_i32, le_f32},
7 }; 7 };
8 use encoding_rs::SHIFT_JIS; 8 use encoding_rs::SHIFT_JIS;
9 use bitflags::bitflags;
10
11 bitflags! {
12 /// Bit flags describing the current difficulty level.
13 pub struct Rank: u16 {
14 /// Easy mode.
15 const Easy = 0x100;
16
17 /// Normal mode.
18 const Normal = 0x200;
19
20 /// Hard mode.
21 const Hard = 0x400;
22
23 /// Lunatic mode.
24 const Lunatic = 0x800;
25
26 /// Any or all modes.
27 const All = 0xff00;
28 }
29 }
9 30
10 /// A single instruction, part of a `Script`. 31 /// A single instruction, part of a `Script`.
11 #[derive(Debug, Clone)] 32 #[derive(Debug, Clone)]
12 pub struct CallSub { 33 pub struct CallSub {
13 /// Time at which this instruction will be called. 34 /// Time at which this instruction will be called.
14 pub time: i32, 35 pub time: i32,
15 36
16 /// TODO 37 /// The difficulty level(s) this instruction will be called at.
17 pub rank_mask: u16, 38 pub rank_mask: Rank,
18 39
19 /// TODO 40 /// TODO
20 pub param_mask: u16, 41 pub param_mask: u16,
21 42
22 /// The instruction to call. 43 /// The instruction to call.
207 78 => fn DelayAttack(), 228 78 => fn DelayAttack(),
208 79 => fn NoDelayAttack(), 229 79 => fn NoDelayAttack(),
209 81 => fn SetBulletLaunchOffset(x: f32, y: f32, z: f32), 230 81 => fn SetBulletLaunchOffset(x: f32, y: f32, z: f32),
210 82 => fn SetExtendedBulletAttributes(a: i32, b: i32, c: i32, d: i32, e: f32, f: f32, g: f32, h: f32), 231 82 => fn SetExtendedBulletAttributes(a: i32, b: i32, c: i32, d: i32, e: f32, f: f32, g: f32, h: f32),
211 83 => fn ChangeBulletsInStarBonus(), 232 83 => fn ChangeBulletsInStarBonus(),
212 // 84: ('i', None), 233 84 => fn UNK0(UNK: i32),
213 85 => fn NewLaser(laser_type: i16, sprite_idx_offset: i16, angle: f32, speed: f32, start_offset: f32, end_offset: f32, max_length: f32, width: f32, start_duration: i32, duration: i32, end_duration: i32, grazing_delay: i32, grazing_extra_duration: i32, UNK1: i32), 234 85 => fn NewLaser(laser_type: i16, sprite_idx_offset: i16, angle: f32, speed: f32, start_offset: f32, end_offset: f32, max_length: f32, width: f32, start_duration: i32, duration: i32, end_duration: i32, grazing_delay: i32, grazing_extra_duration: i32, UNK1: i32),
214 86 => fn NewLaserTowardsPlayer(laser_type: i16, sprite_idx_offset: i16, angle: f32, speed: f32, start_offset: f32, end_offset: f32, max_length: f32, width: f32, start_duration: i32, duration: i32, end_duration: i32, grazing_delay: i32, grazing_extra_duration: i32, UNK1: i32), 235 86 => fn NewLaserTowardsPlayer(laser_type: i16, sprite_idx_offset: i16, angle: f32, speed: f32, start_offset: f32, end_offset: f32, max_length: f32, width: f32, start_duration: i32, duration: i32, end_duration: i32, grazing_delay: i32, grazing_extra_duration: i32, UNK1: i32),
215 87 => fn SetUpcomingLaserId(id: i32), 236 87 => fn SetUpcomingLaserId(id: i32),
216 88 => fn AlterLaserAngle(id: i32, delta: f32), 237 88 => fn AlterLaserAngle(id: i32, delta: f32),
217 90 => fn RepositionLaser(id: i32, ox: f32, oy: f32, oz: f32), 238 90 => fn RepositionLaser(id: i32, ox: f32, oy: f32, oz: f32),
293 break; 314 break;
294 } 315 }
295 316
296 let (i2, size) = le_u16(i2)?; 317 let (i2, size) = le_u16(i2)?;
297 let (i2, rank_mask) = le_u16(i2)?; 318 let (i2, rank_mask) = le_u16(i2)?;
319 let rank_mask = Rank::from_bits(rank_mask).unwrap();
298 let (i2, param_mask) = le_u16(i2)?; 320 let (i2, param_mask) = le_u16(i2)?;
299 // FIXME: this - 12 can trigger a panic, fuzz it! 321 // FIXME: this - 12 can trigger a panic, fuzz it!
300 let data = &i2[..size as usize - 12]; 322 let data = &i2[..size as usize - 12];
301 let (data, instr) = parse_sub_instruction_args(data, opcode)?; 323 let (data, instr) = parse_sub_instruction_args(data, opcode)?;
302 assert_eq!(data.len(), 0); 324 assert_eq!(data.len(), 0);