From a1d0f2dc639f70bb33e68abab95a68553f416731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sallai=20J=C3=B3zsef?= Date: Sat, 9 Jul 2022 20:01:31 +0300 Subject: [PATCH] fix 2P behavior in TSC commands and ironhead fight --- src/scene/game_scene.rs | 3 ++- src/scripting/tsc/text_script.rs | 41 +++++++++++++++++++++++++------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/scene/game_scene.rs b/src/scene/game_scene.rs index e31b642..c49c831 100644 --- a/src/scene/game_scene.rs +++ b/src/scene/game_scene.rs @@ -46,7 +46,7 @@ use crate::scene::title_scene::TitleScene; use crate::scene::Scene; use crate::scripting::tsc::credit_script::CreditScriptVM; use crate::scripting::tsc::text_script::{ScriptMode, TextScriptExecutionState, TextScriptVM}; -use crate::shared_game_state::{Language, ReplayState, PlayerCount, SharedGameState, TileSize}; +use crate::shared_game_state::{Language, PlayerCount, ReplayState, SharedGameState, TileSize}; use crate::stage::{BackgroundType, Stage, StageTexturePaths}; use crate::texture_set::SpriteBatch; use crate::weapon::bullet::BulletManager; @@ -1427,6 +1427,7 @@ impl GameScene { && !self.player2.cond.hidden() && (self.player1.x - self.player2.x).abs() < 240 * 0x200 && (self.player1.y - self.player2.y).abs() < 200 * 0x200 + && self.player1.control_mode != ControlMode::IronHead { self.frame.target_x = (self.player1.target_x * 2 + self.player2.target_x) / 3; self.frame.target_y = (self.player1.target_y * 2 + self.player2.target_y) / 3; diff --git a/src/scripting/tsc/text_script.rs b/src/scripting/tsc/text_script.rs index 86774b9..ab59503 100644 --- a/src/scripting/tsc/text_script.rs +++ b/src/scripting/tsc/text_script.rs @@ -520,7 +520,7 @@ impl TextScriptVM { break; } TextScriptExecutionState::WaitStanding(event, ip) => { - if game_scene.player1.flags.hit_bottom_wall() { + if game_scene.player1.flags.hit_bottom_wall() || game_scene.player2.flags.hit_bottom_wall() { state.textscript_vm.state = TextScriptExecutionState::Running(event, ip); } break; @@ -692,6 +692,7 @@ impl TextScriptVM { state.control_flags.set_control_enabled(false); game_scene.player1.shock_counter = 0; + game_scene.player2.shock_counter = 0; exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); } @@ -702,6 +703,9 @@ impl TextScriptVM { game_scene.player1.up = false; game_scene.player1.shock_counter = 0; + game_scene.player2.up = false; + game_scene.player2.shock_counter = 0; + exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); } TSCOpCode::FRE => { @@ -964,6 +968,7 @@ impl TextScriptVM { } TSCOpCode::MM0 => { game_scene.player1.vel_x = 0; + game_scene.player2.vel_x = 0; exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); } @@ -1215,6 +1220,7 @@ impl TextScriptVM { let mode: Option = FromPrimitive::from_u8(control_mode); if let Some(mode) = mode { game_scene.player1.control_mode = mode; + game_scene.player2.control_mode = mode; } exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); @@ -1351,8 +1357,12 @@ impl TextScriptVM { npc.tsc_direction = tsc_direction as u16; if direction == Direction::FacingPlayer { - npc.direction = - if game_scene.player1.x < npc.x { Direction::Left } else { Direction::Right }; + let player = match state.textscript_vm.executor_player { + TargetPlayer::Player1 => &game_scene.player1, + TargetPlayer::Player2 => &game_scene.player2, + }; + + npc.direction = if player.x < npc.x { Direction::Left } else { Direction::Right }; } else if tsc_direction != 5 { npc.direction = direction; } @@ -1404,8 +1414,12 @@ impl TextScriptVM { npc.tsc_direction = tsc_direction as u16; if direction == Direction::FacingPlayer { - npc.direction = - if game_scene.player1.x < npc.x { Direction::Left } else { Direction::Right }; + let player = match state.textscript_vm.executor_player { + TargetPlayer::Player1 => &game_scene.player1, + TargetPlayer::Player2 => &game_scene.player2, + }; + + npc.direction = if player.x < npc.x { Direction::Left } else { Direction::Right }; } else if tsc_direction != 5 { npc.direction = direction; } @@ -1441,8 +1455,12 @@ impl TextScriptVM { npc.tsc_direction = tsc_direction as u16; if direction == Direction::FacingPlayer { - npc.direction = - if game_scene.player1.x < npc.x { Direction::Left } else { Direction::Right }; + let player = match state.textscript_vm.executor_player { + TargetPlayer::Player1 => &game_scene.player1, + TargetPlayer::Player2 => &game_scene.player2, + }; + + npc.direction = if player.x < npc.x { Direction::Left } else { Direction::Right }; } else if tsc_direction != 5 { npc.direction = direction; } @@ -1468,7 +1486,12 @@ impl TextScriptVM { npc.tsc_direction = tsc_direction as u16; if direction == Direction::FacingPlayer { - npc.direction = if game_scene.player1.x < npc.x { Direction::Left } else { Direction::Right }; + let player = match state.textscript_vm.executor_player { + TargetPlayer::Player1 => &game_scene.player1, + TargetPlayer::Player2 => &game_scene.player2, + }; + + npc.direction = if player.x < npc.x { Direction::Left } else { Direction::Right }; } else { npc.direction = direction; } @@ -1584,6 +1607,7 @@ impl TextScriptVM { let mask = read_cur_varint(&mut cursor)? as u16; game_scene.player1.equip.0 |= mask; + game_scene.player2.equip.0 |= mask; exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); } @@ -1591,6 +1615,7 @@ impl TextScriptVM { let mask = read_cur_varint(&mut cursor)? as u16; game_scene.player1.equip.0 &= !mask; + game_scene.player2.equip.0 &= !mask; exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); }