1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2025-07-13 00:06:01 +00:00

Use set_flag function to handle OOB flags

This commit is contained in:
dawnDus 2022-01-25 23:41:21 -05:00
parent 7448ce0e59
commit b99cb8a34d
No known key found for this signature in database
GPG key ID: 972AABDE81848F21
4 changed files with 15 additions and 15 deletions

View file

@ -238,7 +238,7 @@ impl NPCList {
/// Deletes NPCs with specified type. /// Deletes NPCs with specified type.
pub fn kill_npcs_by_type(&self, npc_type: u16, smoke: bool, state: &mut SharedGameState) { pub fn kill_npcs_by_type(&self, npc_type: u16, smoke: bool, state: &mut SharedGameState) {
for npc in self.iter_alive().filter(|n| n.npc_type == npc_type) { for npc in self.iter_alive().filter(|n| n.npc_type == npc_type) {
state.game_flags.set(npc.flag_num as usize, true); state.set_flag(npc.flag_num as usize, true);
npc.cond.set_alive(false); npc.cond.set_alive(false);
if smoke { if smoke {
@ -311,7 +311,7 @@ impl NPCList {
} }
} }
state.game_flags.set(npc.flag_num as usize, true); state.set_flag(npc.flag_num as usize, true);
if npc.npc_flags.show_damage() { if npc.npc_flags.show_damage() {
if vanish { if vanish {
@ -331,7 +331,7 @@ impl NPCList {
for npc in self.iter_alive() { for npc in self.iter_alive() {
if npc.event_num == event_num { if npc.event_num == event_num {
npc.cond.set_alive(false); npc.cond.set_alive(false);
state.game_flags.set(npc.flag_num as usize, true); state.set_flag(npc.flag_num as usize, true);
} }
} }
} }
@ -341,7 +341,7 @@ impl NPCList {
for npc in self.iter_alive() { for npc in self.iter_alive() {
if npc.npc_type == npc_type { if npc.npc_type == npc_type {
npc.cond.set_alive(false); npc.cond.set_alive(false);
state.game_flags.set(npc.flag_num as usize, true); state.set_flag(npc.flag_num as usize, true);
match npc.size { match npc.size {
1 => self.create_death_smoke(npc.x, npc.y, npc.display_bounds.right as usize, 3, state, &npc.rng), 1 => self.create_death_smoke(npc.x, npc.y, npc.display_bounds.right as usize, 3, state, &npc.rng),

View file

@ -1,6 +1,6 @@
use std::io; use std::io;
use byteorder::{BE, LE, ReadBytesExt, WriteBytesExt}; use byteorder::{ReadBytesExt, WriteBytesExt, BE, LE};
use num_traits::{clamp, FromPrimitive}; use num_traits::{clamp, FromPrimitive};
use crate::common::{Direction, FadeState}; use crate::common::{Direction, FadeState};
@ -99,28 +99,28 @@ impl GameProfile {
for (idx, &flags) in self.flags.iter().enumerate() { for (idx, &flags) in self.flags.iter().enumerate() {
if flags & 0b00000001 != 0 { if flags & 0b00000001 != 0 {
state.game_flags.set(idx * 8, true); state.set_flag(idx * 8, true);
} }
if flags & 0b00000010 != 0 { if flags & 0b00000010 != 0 {
state.game_flags.set(idx * 8 + 1, true); state.set_flag(idx * 8 + 1, true);
} }
if flags & 0b00000100 != 0 { if flags & 0b00000100 != 0 {
state.game_flags.set(idx * 8 + 2, true); state.set_flag(idx * 8 + 2, true);
} }
if flags & 0b00001000 != 0 { if flags & 0b00001000 != 0 {
state.game_flags.set(idx * 8 + 3, true); state.set_flag(idx * 8 + 3, true);
} }
if flags & 0b00010000 != 0 { if flags & 0b00010000 != 0 {
state.game_flags.set(idx * 8 + 4, true); state.set_flag(idx * 8 + 4, true);
} }
if flags & 0b00100000 != 0 { if flags & 0b00100000 != 0 {
state.game_flags.set(idx * 8 + 5, true); state.set_flag(idx * 8 + 5, true);
} }
if flags & 0b01000000 != 0 { if flags & 0b01000000 != 0 {
state.game_flags.set(idx * 8 + 6, true); state.set_flag(idx * 8 + 6, true);
} }
if flags & 0b10000000 != 0 { if flags & 0b10000000 != 0 {
state.game_flags.set(idx * 8 + 7, true); state.set_flag(idx * 8 + 7, true);
} }
} }

View file

@ -814,7 +814,7 @@ impl TextScriptVM {
if flag_to >= flag_from { if flag_to >= flag_from {
for flag in flag_from..=flag_to { for flag in flag_from..=flag_to {
if state.get_flag(flag) { if state.get_flag(flag) {
state.game_flags.set(flag, false); state.set_flag(flag, false);
break; break;
} }
} }

View file

@ -462,7 +462,7 @@ impl SharedGameState {
if id < self.game_flags.len() { if id < self.game_flags.len() {
self.game_flags.set(id, value); self.game_flags.set(id, value);
} else { } else {
log::warn!("Attempted to set an out-of-bounds flag {}:", id); log::warn!("Attempted to set an out-of-bounds flag: {} to {}.", id, value);
} }
} }