1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-11-25 21:55:50 +00:00

more player related opcodes

This commit is contained in:
Alula 2020-08-28 04:12:13 +02:00
parent bf03c6c9a1
commit 526523a473
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
3 changed files with 52 additions and 18 deletions

View file

@ -63,7 +63,7 @@ bitfield! {
impl Debug; impl Debug;
pub cond_x01, set_cond_x01: 0; pub cond_x01, set_cond_x01: 0;
pub cond_x02, set_cond_x02: 1; pub hidden, set_hidden: 1;
pub cond_x04, set_cond_x04: 2; pub cond_x04, set_cond_x04: 2;
pub cond_x08, set_cond_x08: 3; pub cond_x08, set_cond_x08: 3;
pub cond_x10, set_cond_x10: 4; pub cond_x10, set_cond_x10: 4;
@ -151,7 +151,7 @@ impl Player {
} }
fn tick_normal(&mut self, state: &mut SharedGameState) -> GameResult { fn tick_normal(&mut self, state: &mut SharedGameState) -> GameResult {
if self.cond.cond_x02() { if self.cond.hidden() {
return Ok(()); return Ok(());
} }
@ -464,7 +464,7 @@ impl Player {
} }
fn tick_animation(&mut self, state: &SharedGameState) { fn tick_animation(&mut self, state: &SharedGameState) {
if self.cond.cond_x02() { if self.cond.hidden() {
return; return;
} }
@ -596,7 +596,7 @@ impl GameEntity for Player {
} }
fn draw(&self, state: &mut SharedGameState, ctx: &mut Context, frame: &Frame) -> GameResult<()> { fn draw(&self, state: &mut SharedGameState, ctx: &mut Context, frame: &Frame) -> GameResult<()> {
if !self.cond.visible() || self.cond.cond_x02() { if !self.cond.visible() || self.cond.hidden() {
return Ok(()); return Ok(());
} }

View file

@ -54,7 +54,7 @@ impl Player {
&& (self.y - self.hit.top as isize) > y * 0x10 * 0x200 { && (self.y - self.hit.top as isize) > y * 0x10 * 0x200 {
self.y = ((y * 0x10 + 8) * 0x200) + self.hit.top as isize; self.y = ((y * 0x10 + 8) * 0x200) + self.hit.top as isize;
if !self.cond.cond_x02() && self.vel_y < -0x200 { if !self.cond.hidden() && self.vel_y < -0x200 {
self.flags.set_head_bounced(true); self.flags.set_head_bounced(true);
} }
@ -91,7 +91,7 @@ impl Player {
&& (self.y + self.hit.bottom as isize) > (y * 0x10 - 8) * 0x200 { && (self.y + self.hit.bottom as isize) > (y * 0x10 - 8) * 0x200 {
self.y = (y * 0x10 * 0x200) - ((self.x - x * 0x10 * 0x200) / 2) + 0x800 + self.hit.top as isize; self.y = (y * 0x10 * 0x200) - ((self.x - x * 0x10 * 0x200) / 2) + 0x800 + self.hit.top as isize;
if !self.cond.cond_x02() && self.vel_y < -0x200 { if !self.cond.hidden() && self.vel_y < -0x200 {
self.flags.set_head_bounced(true); self.flags.set_head_bounced(true);
} }
@ -110,7 +110,7 @@ impl Player {
&& (self.y + self.hit.bottom as isize) > (y * 0x10 - 8) * 0x200 { && (self.y + self.hit.bottom as isize) > (y * 0x10 - 8) * 0x200 {
self.y = (y * 0x10 * 0x200) - ((self.x - x * 0x10 * 0x200) / 2) - 0x800 + self.hit.top as isize; self.y = (y * 0x10 * 0x200) - ((self.x - x * 0x10 * 0x200) / 2) - 0x800 + self.hit.top as isize;
if !self.cond.cond_x02() && self.vel_y < -0x200 { if !self.cond.hidden() && self.vel_y < -0x200 {
self.flags.set_head_bounced(true); self.flags.set_head_bounced(true);
} }
@ -129,7 +129,7 @@ impl Player {
&& (self.y + self.hit.bottom as isize) > (y * 0x10 - 8) * 0x200 { && (self.y + self.hit.bottom as isize) > (y * 0x10 - 8) * 0x200 {
self.y = (y * 0x10 * 0x200) + ((self.x - x * 0x10 * 0x200) / 2) - 0x800 + self.hit.top as isize; self.y = (y * 0x10 * 0x200) + ((self.x - x * 0x10 * 0x200) / 2) - 0x800 + self.hit.top as isize;
if !self.cond.cond_x02() && self.vel_y < -0x200 { if !self.cond.hidden() && self.vel_y < -0x200 {
self.flags.set_head_bounced(true); self.flags.set_head_bounced(true);
} }
@ -148,7 +148,7 @@ impl Player {
&& (self.y + self.hit.bottom as isize) > (y * 0x10 - 8) * 0x200 { && (self.y + self.hit.bottom as isize) > (y * 0x10 - 8) * 0x200 {
self.y = (y * 0x10 * 0x200) + ((self.x - x * 0x10 * 0x200) / 2) + 0x800 + self.hit.top as isize; self.y = (y * 0x10 * 0x200) + ((self.x - x * 0x10 * 0x200) / 2) + 0x800 + self.hit.top as isize;
if !self.cond.cond_x02() && self.vel_y < -0x200 { if !self.cond.hidden() && self.vel_y < -0x200 {
self.flags.set_head_bounced(true); self.flags.set_head_bounced(true);
} }

View file

@ -13,7 +13,7 @@ use num_traits::FromPrimitive;
use crate::{SharedGameState, str}; use crate::{SharedGameState, str};
use crate::bitfield; use crate::bitfield;
use crate::common::{FadeState, FadeDirection}; use crate::common::{Direction, FadeDirection, FadeState};
use crate::ggez::{Context, GameResult}; use crate::ggez::{Context, GameResult};
use crate::ggez::GameError::ParseError; use crate::ggez::GameError::ParseError;
use crate::scene::game_scene::GameScene; use crate::scene::game_scene::GameScene;
@ -486,10 +486,30 @@ impl TextScriptVM {
OpCode::FRE => { OpCode::FRE => {
state.control_flags.set_flag_x01(true); state.control_flags.set_flag_x01(true);
state.control_flags.set_control_enabled(true); state.control_flags.set_control_enabled(true);
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
}
OpCode::MYD => {
let new_direction = read_cur_varint(&mut cursor)? as usize;
if let Some(direction) = Direction::from_int(new_direction) {
game_scene.player.direction = direction;
}
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
}
OpCode::SMC => {
game_scene.player.cond.set_hidden(false);
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
}
OpCode::HMC => {
game_scene.player.cond.set_hidden(true);
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
} }
OpCode::WAI => { OpCode::WAI => {
let ticks = read_cur_varint(&mut cursor)? as u32; let ticks = read_cur_varint(&mut cursor)? as u32;
exec_state = TextScriptExecutionState::WaitTicks(event, cursor.position() as u32, ticks); exec_state = TextScriptExecutionState::WaitTicks(event, cursor.position() as u32, ticks);
} }
OpCode::NOD => { OpCode::NOD => {
@ -511,10 +531,12 @@ impl TextScriptVM {
} }
OpCode::EVE => { OpCode::EVE => {
let event_num = read_cur_varint(&mut cursor)? as u16; let event_num = read_cur_varint(&mut cursor)? as u16;
exec_state = TextScriptExecutionState::Running(event_num, 0); exec_state = TextScriptExecutionState::Running(event_num, 0);
} }
OpCode::MM0 => { OpCode::MM0 => {
game_scene.player.vel_x = 0; game_scene.player.vel_x = 0;
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
} }
OpCode::CMP => { OpCode::CMP => {
@ -531,6 +553,7 @@ impl TextScriptVM {
OpCode::MLp => { OpCode::MLp => {
let life = read_cur_varint(&mut cursor)? as usize; let life = read_cur_varint(&mut cursor)? as usize;
game_scene.player.max_life += life; game_scene.player.max_life += life;
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
} }
OpCode::FAC => { OpCode::FAC => {
@ -582,8 +605,8 @@ impl TextScriptVM {
new_scene.player.y = pos_y; new_scene.player.y = pos_y;
state.textscript_vm.suspend = true; state.textscript_vm.suspend = true;
state.next_scene = Some(Box::new(new_scene)); state.next_scene = Some(Box::new(new_scene));
exec_state = TextScriptExecutionState::Running(event_num, 0); exec_state = TextScriptExecutionState::Running(event_num, 0);
} }
OpCode::FAI => { OpCode::FAI => {
@ -606,23 +629,25 @@ impl TextScriptVM {
// Zero operands // Zero operands
OpCode::AEp | OpCode::CAT | OpCode::CIL | OpCode::CPS | OpCode::AEp | OpCode::CAT | OpCode::CIL | OpCode::CPS |
OpCode::CRE | OpCode::CSS | OpCode::ESC | OpCode::FLA | OpCode::FMU | OpCode::CRE | OpCode::CSS | OpCode::ESC | OpCode::FLA | OpCode::FMU |
OpCode::HMC | OpCode::INI | OpCode::LDP | OpCode::MLP | OpCode::INI | OpCode::LDP | OpCode::MLP |
OpCode::MNA | OpCode::MS2 | OpCode::MS3 | OpCode::MNA | OpCode::MS2 | OpCode::MS3 |
OpCode::RMU | OpCode::SAT | OpCode::SLP | OpCode::SMC | OpCode::SPS | OpCode::RMU | OpCode::SAT | OpCode::SLP | OpCode::SPS |
OpCode::STC | OpCode::SVP | OpCode::TUR | OpCode::WAS | OpCode::ZAM => { OpCode::STC | OpCode::SVP | OpCode::TUR | OpCode::WAS | OpCode::ZAM => {
log::warn!("unimplemented opcode: {:?}", op); log::warn!("unimplemented opcode: {:?}", op);
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
} }
// One operand codes // One operand codes
OpCode::BOA | OpCode::BSL | OpCode::FOB | OpCode::FOM | OpCode::QUA | OpCode::UNI | OpCode::BOA | OpCode::BSL | OpCode::FOB | OpCode::FOM | OpCode::QUA | OpCode::UNI |
OpCode::MYB | OpCode::MYD | OpCode::MYB | OpCode::GIT | OpCode::NUM | OpCode::DNA | OpCode::DNP |
OpCode::GIT | OpCode::NUM | OpCode::DNA | OpCode::DNP |
OpCode::MPp | OpCode::SKm | OpCode::SKp | OpCode::EQp | OpCode::EQm | OpCode::MPp | OpCode::SKm | OpCode::SKp | OpCode::EQp | OpCode::EQm |
OpCode::ITp | OpCode::ITm | OpCode::AMm | OpCode::UNJ | OpCode::MPJ | OpCode::YNJ | OpCode::ITp | OpCode::ITm | OpCode::AMm | OpCode::UNJ | OpCode::MPJ | OpCode::YNJ |
OpCode::XX1 | OpCode::SIL | OpCode::LIp | OpCode::SOU | OpCode::CMU | OpCode::XX1 | OpCode::SIL | OpCode::LIp | OpCode::SOU | OpCode::CMU |
OpCode::SSS | OpCode::ACH => { OpCode::SSS | OpCode::ACH => {
let par_a = read_cur_varint(&mut cursor)?; let par_a = read_cur_varint(&mut cursor)?;
log::warn!("unimplemented opcode: {:?} {}", op, par_a); log::warn!("unimplemented opcode: {:?} {}", op, par_a);
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
} }
// Two operand codes // Two operand codes
@ -630,7 +655,9 @@ impl TextScriptVM {
OpCode::ITJ | OpCode::SKJ | OpCode::AMJ | OpCode::SMP | OpCode::PSp => { OpCode::ITJ | OpCode::SKJ | OpCode::AMJ | OpCode::SMP | OpCode::PSp => {
let par_a = read_cur_varint(&mut cursor)?; let par_a = read_cur_varint(&mut cursor)?;
let par_b = read_cur_varint(&mut cursor)?; let par_b = read_cur_varint(&mut cursor)?;
log::warn!("unimplemented opcode: {:?} {} {}", op, par_a, par_b); log::warn!("unimplemented opcode: {:?} {} {}", op, par_a, par_b);
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
} }
// Three operand codes // Three operand codes
@ -638,7 +665,9 @@ impl TextScriptVM {
let par_a = read_cur_varint(&mut cursor)?; let par_a = read_cur_varint(&mut cursor)?;
let par_b = read_cur_varint(&mut cursor)?; let par_b = read_cur_varint(&mut cursor)?;
let par_c = read_cur_varint(&mut cursor)?; let par_c = read_cur_varint(&mut cursor)?;
log::warn!("unimplemented opcode: {:?} {} {} {}", op, par_a, par_b, par_c); log::warn!("unimplemented opcode: {:?} {} {} {}", op, par_a, par_b, par_c);
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
} }
// Four operand codes // Four operand codes
@ -647,7 +676,9 @@ impl TextScriptVM {
let par_b = read_cur_varint(&mut cursor)?; let par_b = read_cur_varint(&mut cursor)?;
let par_c = read_cur_varint(&mut cursor)?; let par_c = read_cur_varint(&mut cursor)?;
let par_d = read_cur_varint(&mut cursor)?; let par_d = read_cur_varint(&mut cursor)?;
log::warn!("unimplemented opcode: {:?} {} {} {} {}", op, par_a, par_b, par_c, par_d); log::warn!("unimplemented opcode: {:?} {} {} {} {}", op, par_a, par_b, par_c, par_d);
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
} }
} }
@ -731,8 +762,11 @@ impl TextScript {
if event_map.contains_key(&event_num) { if event_map.contains_key(&event_num) {
if strict { if strict {
return Err(ParseError(format!("Event {} has been defined twice.", event_num))); return Err(ParseError(format!("Event {} has been defined twice.", event_num)));
} else { }
continue;
match TextScript::skip_until(b'#', &mut iter).ok() {
Some(_) => { continue; }
None => { break; }
} }
} }
@ -741,7 +775,7 @@ impl TextScript {
println!("{:x?}", &bytecode); println!("{:x?}", &bytecode);
event_map.insert(event_num, bytecode); event_map.insert(event_num, bytecode);
} }
b'\r' | b'\n' | b' ' => { b'\r' | b'\n' | b' ' | b'\t' => {
iter.next(); iter.next();
} }
n => { n => {