fix 2P behavior in TSC commands and ironhead fight

This commit is contained in:
Sallai József 2022-07-09 20:01:31 +03:00
parent 75b077c772
commit a1d0f2dc63
2 changed files with 35 additions and 9 deletions

View File

@ -46,7 +46,7 @@ use crate::scene::title_scene::TitleScene;
use crate::scene::Scene; use crate::scene::Scene;
use crate::scripting::tsc::credit_script::CreditScriptVM; use crate::scripting::tsc::credit_script::CreditScriptVM;
use crate::scripting::tsc::text_script::{ScriptMode, TextScriptExecutionState, TextScriptVM}; 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::stage::{BackgroundType, Stage, StageTexturePaths};
use crate::texture_set::SpriteBatch; use crate::texture_set::SpriteBatch;
use crate::weapon::bullet::BulletManager; use crate::weapon::bullet::BulletManager;
@ -1427,6 +1427,7 @@ impl GameScene {
&& !self.player2.cond.hidden() && !self.player2.cond.hidden()
&& (self.player1.x - self.player2.x).abs() < 240 * 0x200 && (self.player1.x - self.player2.x).abs() < 240 * 0x200
&& (self.player1.y - self.player2.y).abs() < 200 * 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_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; self.frame.target_y = (self.player1.target_y * 2 + self.player2.target_y) / 3;

View File

@ -520,7 +520,7 @@ impl TextScriptVM {
break; break;
} }
TextScriptExecutionState::WaitStanding(event, ip) => { 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); state.textscript_vm.state = TextScriptExecutionState::Running(event, ip);
} }
break; break;
@ -692,6 +692,7 @@ impl TextScriptVM {
state.control_flags.set_control_enabled(false); state.control_flags.set_control_enabled(false);
game_scene.player1.shock_counter = 0; game_scene.player1.shock_counter = 0;
game_scene.player2.shock_counter = 0;
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
} }
@ -702,6 +703,9 @@ impl TextScriptVM {
game_scene.player1.up = false; game_scene.player1.up = false;
game_scene.player1.shock_counter = 0; 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); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
} }
TSCOpCode::FRE => { TSCOpCode::FRE => {
@ -964,6 +968,7 @@ impl TextScriptVM {
} }
TSCOpCode::MM0 => { TSCOpCode::MM0 => {
game_scene.player1.vel_x = 0; game_scene.player1.vel_x = 0;
game_scene.player2.vel_x = 0;
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
} }
@ -1215,6 +1220,7 @@ impl TextScriptVM {
let mode: Option<ControlMode> = FromPrimitive::from_u8(control_mode); let mode: Option<ControlMode> = FromPrimitive::from_u8(control_mode);
if let Some(mode) = mode { if let Some(mode) = mode {
game_scene.player1.control_mode = mode; game_scene.player1.control_mode = mode;
game_scene.player2.control_mode = mode;
} }
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
@ -1351,8 +1357,12 @@ impl TextScriptVM {
npc.tsc_direction = tsc_direction as u16; npc.tsc_direction = tsc_direction as u16;
if direction == Direction::FacingPlayer { if direction == Direction::FacingPlayer {
npc.direction = let player = match state.textscript_vm.executor_player {
if game_scene.player1.x < npc.x { Direction::Left } else { Direction::Right }; 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 { } else if tsc_direction != 5 {
npc.direction = direction; npc.direction = direction;
} }
@ -1404,8 +1414,12 @@ impl TextScriptVM {
npc.tsc_direction = tsc_direction as u16; npc.tsc_direction = tsc_direction as u16;
if direction == Direction::FacingPlayer { if direction == Direction::FacingPlayer {
npc.direction = let player = match state.textscript_vm.executor_player {
if game_scene.player1.x < npc.x { Direction::Left } else { Direction::Right }; 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 { } else if tsc_direction != 5 {
npc.direction = direction; npc.direction = direction;
} }
@ -1441,8 +1455,12 @@ impl TextScriptVM {
npc.tsc_direction = tsc_direction as u16; npc.tsc_direction = tsc_direction as u16;
if direction == Direction::FacingPlayer { if direction == Direction::FacingPlayer {
npc.direction = let player = match state.textscript_vm.executor_player {
if game_scene.player1.x < npc.x { Direction::Left } else { Direction::Right }; 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 { } else if tsc_direction != 5 {
npc.direction = direction; npc.direction = direction;
} }
@ -1468,7 +1486,12 @@ impl TextScriptVM {
npc.tsc_direction = tsc_direction as u16; npc.tsc_direction = tsc_direction as u16;
if direction == Direction::FacingPlayer { 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 { } else {
npc.direction = direction; npc.direction = direction;
} }
@ -1584,6 +1607,7 @@ impl TextScriptVM {
let mask = read_cur_varint(&mut cursor)? as u16; let mask = read_cur_varint(&mut cursor)? as u16;
game_scene.player1.equip.0 |= mask; game_scene.player1.equip.0 |= mask;
game_scene.player2.equip.0 |= mask;
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
} }
@ -1591,6 +1615,7 @@ impl TextScriptVM {
let mask = read_cur_varint(&mut cursor)? as u16; let mask = read_cur_varint(&mut cursor)? as u16;
game_scene.player1.equip.0 &= !mask; game_scene.player1.equip.0 &= !mask;
game_scene.player2.equip.0 &= !mask;
exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32); exec_state = TextScriptExecutionState::Running(event, cursor.position() as u32);
} }