Skip to content

Commit

Permalink
let's try this
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Apr 27, 2021
1 parent fe91bb0 commit 30ce5db
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions examples/dorf_hero/src/ai/scorers/enemy_distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl ScorerBuilder for EnemyDistanceBuilder {
fn build(&self, cmd: &mut Commands, scorer: Entity, _actor: Entity) {
cmd.entity(scorer).insert(EnemyDistance {
within: self.within,
evaluator: LinearEvaluator::new_ranged(0.0, self.within),
evaluator: LinearEvaluator::new_ranged(self.within, 0.0),
});
}
}
Expand All @@ -47,7 +47,7 @@ pub fn enemy_distance(
if let Ok(hero_pos) = hero_q.single() {
let distance = util::euclidean_distance(enemy_pos, hero_pos);
if distance <= enemy_distance.within {
score.set(enemy_distance.evaluator.evaluate((distance - enemy_distance.within).abs()));
score.set(enemy_distance.evaluator.evaluate(distance / enemy_distance.within));
} else {
score.set(0.0);
}
Expand All @@ -57,7 +57,7 @@ pub fn enemy_distance(
for enemy_pos in enemy_q.iter() {
let distance = util::euclidean_distance(enemy_pos, hero_pos);
if distance <= enemy_distance.within {
score.set(enemy_distance.evaluator.evaluate((distance - enemy_distance.within).abs()));
score.set(enemy_distance.evaluator.evaluate(distance / enemy_distance.within));
} else {
score.set(0.0);
}
Expand Down
4 changes: 2 additions & 2 deletions examples/dorf_hero/src/ai/scorers/fear_of_death.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct FearOfDeathBuilder;
impl ScorerBuilder for FearOfDeathBuilder {
fn build(&self, cmd: &mut Commands, scorer: Entity, _actor: Entity) {
cmd.entity(scorer).insert(FearOfDeath {
evaluator: PowerEvaluator::new(2.),
evaluator: PowerEvaluator::new_ranged(2., 1.0, 0.0),
});
}
}
Expand All @@ -30,7 +30,7 @@ pub fn fear_of_death(hp_q: Query<&Hp>, mut scorer_q: Query<(&Actor, &mut Score,
for (Actor(actor), mut score, fear) in scorer_q.iter_mut() {
if let Ok(hp) = hp_q.get(*actor) {
let perc = hp.current as f32 / hp.max as f32;
score.set(fear.evaluator.evaluate((perc - 1.).abs()));
score.set(fear.evaluator.evaluate(perc));
}
}
}

0 comments on commit 30ce5db

Please sign in to comment.