1
0
Fork 0
mirror of https://github.com/doukutsu-rs/doukutsu-rs synced 2024-11-29 08:42:50 +00:00

build fixes

This commit is contained in:
Alula 2020-12-03 23:24:58 +01:00
parent f103e1aa2e
commit a9f626c3b5
No known key found for this signature in database
GPG key ID: 3E00485503A1D8BA
2 changed files with 30 additions and 8 deletions

View file

@ -692,8 +692,8 @@ impl NPC {
}
{
let player = self.get_closest_player_mut(players);
if abs(player.x - self.x) < 480 * 0x200 && abs(player.y - self.y) < 240 * 0x200
let i = self.get_closest_player_idx_mut(&players);
if abs(players[i].x - self.x) < 480 * 0x200 && abs(players[i].y - self.y) < 240 * 0x200
&& state.game_rng.range(0..5) == 1 {
let mut particle = NPCMap::create_npc(199, &state.npc_table);
particle.cond.set_alive(true);
@ -745,8 +745,8 @@ impl NPC {
}
{
let player = self.get_closest_player_mut(players);
if abs(player.x - self.x) < 480 * 0x200 && abs(player.y - self.y) < 240 * 0x200
let i = self.get_closest_player_idx_mut(&players);
if abs(players[i].x - self.x) < 480 * 0x200 && abs(players[i].y - self.y) < 240 * 0x200
&& state.game_rng.range(0..5) == 1 {
let mut particle = NPCMap::create_npc(199, &state.npc_table);
particle.cond.set_alive(true);
@ -797,8 +797,8 @@ impl NPC {
}
{
let player = self.get_closest_player_mut(players);
if abs(player.x - self.x) < 480 * 0x200 && abs(player.y - self.y) < 240 * 0x200
let i = self.get_closest_player_idx_mut(&players);
if abs(players[i].x - self.x) < 480 * 0x200 && abs(players[i].y - self.y) < 240 * 0x200
&& state.game_rng.range(0..5) == 1 {
let mut particle = NPCMap::create_npc(199, &state.npc_table);
particle.cond.set_alive(true);
@ -846,8 +846,8 @@ impl NPC {
}
{
let player = self.get_closest_player_mut(players);
if abs(player.x - self.x) < 480 * 0x200 && abs(player.y - self.y) < 240 * 0x200
let i = self.get_closest_player_idx_mut(&players);
if abs(players[i].x - self.x) < 480 * 0x200 && abs(players[i].y - self.y) < 240 * 0x200
&& state.game_rng.range(0..5) == 1 {
let mut particle = NPCMap::create_npc(199, &state.npc_table);
particle.cond.set_alive(true);

View file

@ -4,6 +4,28 @@ use crate::npc::NPC;
use crate::player::Player;
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 {
let mut max_dist = f64::MAX;
let mut player_idx = 0;