mirror of
https://github.com/doukutsu-rs/doukutsu-rs
synced 2024-12-01 17:42:51 +00:00
build fixes
This commit is contained in:
parent
f103e1aa2e
commit
a9f626c3b5
|
@ -692,8 +692,8 @@ impl NPC {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let player = self.get_closest_player_mut(players);
|
let i = self.get_closest_player_idx_mut(&players);
|
||||||
if abs(player.x - self.x) < 480 * 0x200 && abs(player.y - self.y) < 240 * 0x200
|
if abs(players[i].x - self.x) < 480 * 0x200 && abs(players[i].y - self.y) < 240 * 0x200
|
||||||
&& state.game_rng.range(0..5) == 1 {
|
&& state.game_rng.range(0..5) == 1 {
|
||||||
let mut particle = NPCMap::create_npc(199, &state.npc_table);
|
let mut particle = NPCMap::create_npc(199, &state.npc_table);
|
||||||
particle.cond.set_alive(true);
|
particle.cond.set_alive(true);
|
||||||
|
@ -745,8 +745,8 @@ impl NPC {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let player = self.get_closest_player_mut(players);
|
let i = self.get_closest_player_idx_mut(&players);
|
||||||
if abs(player.x - self.x) < 480 * 0x200 && abs(player.y - self.y) < 240 * 0x200
|
if abs(players[i].x - self.x) < 480 * 0x200 && abs(players[i].y - self.y) < 240 * 0x200
|
||||||
&& state.game_rng.range(0..5) == 1 {
|
&& state.game_rng.range(0..5) == 1 {
|
||||||
let mut particle = NPCMap::create_npc(199, &state.npc_table);
|
let mut particle = NPCMap::create_npc(199, &state.npc_table);
|
||||||
particle.cond.set_alive(true);
|
particle.cond.set_alive(true);
|
||||||
|
@ -797,8 +797,8 @@ impl NPC {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let player = self.get_closest_player_mut(players);
|
let i = self.get_closest_player_idx_mut(&players);
|
||||||
if abs(player.x - self.x) < 480 * 0x200 && abs(player.y - self.y) < 240 * 0x200
|
if abs(players[i].x - self.x) < 480 * 0x200 && abs(players[i].y - self.y) < 240 * 0x200
|
||||||
&& state.game_rng.range(0..5) == 1 {
|
&& state.game_rng.range(0..5) == 1 {
|
||||||
let mut particle = NPCMap::create_npc(199, &state.npc_table);
|
let mut particle = NPCMap::create_npc(199, &state.npc_table);
|
||||||
particle.cond.set_alive(true);
|
particle.cond.set_alive(true);
|
||||||
|
@ -846,8 +846,8 @@ impl NPC {
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
let player = self.get_closest_player_mut(players);
|
let i = self.get_closest_player_idx_mut(&players);
|
||||||
if abs(player.x - self.x) < 480 * 0x200 && abs(player.y - self.y) < 240 * 0x200
|
if abs(players[i].x - self.x) < 480 * 0x200 && abs(players[i].y - self.y) < 240 * 0x200
|
||||||
&& state.game_rng.range(0..5) == 1 {
|
&& state.game_rng.range(0..5) == 1 {
|
||||||
let mut particle = NPCMap::create_npc(199, &state.npc_table);
|
let mut particle = NPCMap::create_npc(199, &state.npc_table);
|
||||||
particle.cond.set_alive(true);
|
particle.cond.set_alive(true);
|
||||||
|
|
|
@ -4,6 +4,28 @@ use crate::npc::NPC;
|
||||||
use crate::player::Player;
|
use crate::player::Player;
|
||||||
|
|
||||||
impl NPC {
|
impl NPC {
|
||||||
|
pub fn get_closest_player_idx_mut<'a>(&self, players: &[&'a mut Player; 2]) -> usize {
|
||||||
|
let mut max_dist = f64::MAX;
|
||||||
|
let mut player_idx = 0;
|
||||||
|
|
||||||
|
for (idx, player) in players.iter().enumerate() {
|
||||||
|
if !player.cond.alive() || player.cond.hidden() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let dist_x = abs(self.x - player.x) as f64;
|
||||||
|
let dist_y = abs(self.y - player.y) as f64;
|
||||||
|
let dist = (dist_x * dist_x + dist_y * dist_y).sqrt();
|
||||||
|
|
||||||
|
if dist < max_dist {
|
||||||
|
max_dist = dist;
|
||||||
|
player_idx = idx;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
player_idx
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_closest_player_mut<'a>(&self, players: [&'a mut Player; 2]) -> &'a mut Player {
|
pub fn get_closest_player_mut<'a>(&self, players: [&'a mut Player; 2]) -> &'a mut Player {
|
||||||
let mut max_dist = f64::MAX;
|
let mut max_dist = f64::MAX;
|
||||||
let mut player_idx = 0;
|
let mut player_idx = 0;
|
||||||
|
|
Loading…
Reference in a new issue