mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
remove readability macros from harvester attack ai
This commit is contained in:
parent
3e23205640
commit
789379f44e
@ -4758,6 +4758,15 @@ impl<'a> AgentData<'a> {
|
|||||||
read_data: &ReadData,
|
read_data: &ReadData,
|
||||||
rng: &mut impl Rng,
|
rng: &mut impl Rng,
|
||||||
) {
|
) {
|
||||||
|
// --- reference ---
|
||||||
|
// Inputs:
|
||||||
|
// Primary: scythe
|
||||||
|
// Secondary: firebreath
|
||||||
|
// Abilities:
|
||||||
|
// 0: explosivepumpkin
|
||||||
|
// 1: ensaring_vines_0
|
||||||
|
// 2: ensaring_vines_1
|
||||||
|
|
||||||
// --- setup ---
|
// --- setup ---
|
||||||
|
|
||||||
// behaviour parameters
|
// behaviour parameters
|
||||||
@ -4785,7 +4794,7 @@ impl<'a> AgentData<'a> {
|
|||||||
SinceFarPumpkin,
|
SinceFarPumpkin,
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup line of sight check
|
// line of sight check
|
||||||
let line_of_sight_with_target = || {
|
let line_of_sight_with_target = || {
|
||||||
entities_have_line_of_sight(
|
entities_have_line_of_sight(
|
||||||
self.pos,
|
self.pos,
|
||||||
@ -4798,46 +4807,110 @@ impl<'a> AgentData<'a> {
|
|||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- readability macros ---
|
// --- main ---
|
||||||
|
|
||||||
// actions
|
// handle timers
|
||||||
macro_rules! reset_timer {
|
match self.char_state {
|
||||||
($timer:ident) => {
|
CharacterState::BasicBeam(_) => {
|
||||||
agent.combat_state.timers[ActionStateTimers::$timer as usize] = 0.0
|
agent.combat_state.timers[ActionStateTimers::SinceFirebreath as usize] = 0.0;
|
||||||
};
|
},
|
||||||
|
CharacterState::BasicRanged(_) => {
|
||||||
|
agent.combat_state.timers[ActionStateTimers::SinceCloseMixup as usize] = 0.0;
|
||||||
|
agent.combat_state.timers[ActionStateTimers::SinceFarPumpkin as usize] = 0.0;
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
agent.combat_state.timers[ActionStateTimers::SinceFirebreath as usize] +=
|
||||||
|
read_data.dt.0;
|
||||||
|
agent.combat_state.timers[ActionStateTimers::SinceCloseMixup as usize] +=
|
||||||
|
read_data.dt.0;
|
||||||
|
agent.combat_state.timers[ActionStateTimers::SinceFarPumpkin as usize] +=
|
||||||
|
read_data.dt.0;
|
||||||
|
},
|
||||||
}
|
}
|
||||||
macro_rules! increment_timer {
|
|
||||||
($timer:ident) => {
|
// vine summoning
|
||||||
agent.combat_state.timers[ActionStateTimers::$timer as usize] += read_data.dt.0
|
let health_fraction = self.health.map_or(0.5, |h| h.fraction());
|
||||||
};
|
|
||||||
|
if health_fraction < SECOND_VINE_CREATION_THRESHOLD
|
||||||
|
&& !agent.combat_state.conditions
|
||||||
|
[ActionStateConditions::HasSummonedSecondVines as usize]
|
||||||
|
{
|
||||||
|
// second vines summon
|
||||||
|
controller.push_basic_input(InputKind::Ability(2));
|
||||||
|
if matches!(self.char_state, CharacterState::SpriteSummon(c) if matches!(c.stage_section, StageSection::Recover))
|
||||||
|
{
|
||||||
|
agent.combat_state.conditions
|
||||||
|
[ActionStateConditions::HasSummonedSecondVines as usize] = true;
|
||||||
}
|
}
|
||||||
macro_rules! use_scythe {
|
} else if health_fraction < FIRST_VINE_CREATION_THRESHOLD
|
||||||
() => {
|
&& !agent.combat_state.conditions[ActionStateConditions::HasSummonedFirstVines as usize]
|
||||||
controller.push_basic_input(InputKind::Primary)
|
{
|
||||||
};
|
// first vines summon
|
||||||
|
controller.push_basic_input(InputKind::Ability(1));
|
||||||
|
if matches!(self.char_state, CharacterState::SpriteSummon(c) if matches!(c.stage_section, StageSection::Recover))
|
||||||
|
{
|
||||||
|
agent.combat_state.conditions
|
||||||
|
[ActionStateConditions::HasSummonedFirstVines as usize] = true;
|
||||||
}
|
}
|
||||||
macro_rules! use_fire_breath {
|
|
||||||
() => {
|
|
||||||
controller.push_basic_input(InputKind::Secondary)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
macro_rules! use_pumpkin {
|
// close range
|
||||||
() => {
|
else if attack_data.dist_sqrd < (attack_data.body_dist + 0.75 * MELEE_RANGE).powi(2) {
|
||||||
controller.push_basic_input(InputKind::Ability(0))
|
if matches!(self.char_state, CharacterState::BasicBeam(c) if c.timer < Duration::from_secs_f32(FIREBREATH_SHORT_TIME))
|
||||||
};
|
{
|
||||||
|
// keep using firebreath under short time limit
|
||||||
|
controller.push_basic_input(InputKind::Secondary);
|
||||||
|
} else if agent.combat_state.timers[ActionStateTimers::SinceCloseMixup as usize]
|
||||||
|
> CLOSE_MIXUP_COOLDOWN
|
||||||
|
// for now, no line of sight check for consitency in attacks
|
||||||
|
{
|
||||||
|
// mix up close range attacks
|
||||||
|
if agent.combat_state.timers[ActionStateTimers::SinceFirebreath as usize]
|
||||||
|
< FIREBREATH_COOLDOWN
|
||||||
|
{
|
||||||
|
// if on firebreath cooldown, throw pumpkin
|
||||||
|
controller.push_basic_input(InputKind::Ability(0));
|
||||||
|
} else {
|
||||||
|
let randomise = rng.gen_range(1..=3);
|
||||||
|
match randomise {
|
||||||
|
1 => controller.push_basic_input(InputKind::Secondary), // firebreath
|
||||||
|
2 => controller.push_basic_input(InputKind::Ability(0)), // pumpkin
|
||||||
|
_ => controller.push_basic_input(InputKind::Primary), // scythe
|
||||||
}
|
}
|
||||||
macro_rules! use_first_vines {
|
|
||||||
() => {
|
|
||||||
controller.push_basic_input(InputKind::Ability(1))
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
macro_rules! use_second_vines {
|
} else if attack_data.angle < 60.0 {
|
||||||
() => {
|
// scythe melee
|
||||||
controller.push_basic_input(InputKind::Ability(2))
|
controller.push_basic_input(InputKind::Primary);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
macro_rules! move_to_target {
|
}
|
||||||
() => {
|
// mid range (with line of sight)
|
||||||
|
else if attack_data.dist_sqrd < FIREBREATH_RANGE.powi(2) && line_of_sight_with_target() {
|
||||||
|
if matches!(self.char_state, CharacterState::BasicBeam(c) if c.timer < Duration::from_secs_f32(FIREBREATH_TIME))
|
||||||
|
{
|
||||||
|
// keep using firebreath under full time limit
|
||||||
|
controller.push_basic_input(InputKind::Secondary);
|
||||||
|
} else if attack_data.angle < 30.0
|
||||||
|
&& agent.combat_state.timers[ActionStateTimers::SinceFirebreath as usize]
|
||||||
|
> FIREBREATH_COOLDOWN
|
||||||
|
{
|
||||||
|
// start using firebreath
|
||||||
|
controller.push_basic_input(InputKind::Secondary);
|
||||||
|
} else if agent.combat_state.timers[ActionStateTimers::SinceCloseMixup as usize] > CLOSE_MIXUP_COOLDOWN {
|
||||||
|
// throw pumpkin
|
||||||
|
controller.push_basic_input(InputKind::Ability(0));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// long range (with line of sight)
|
||||||
|
else if attack_data.dist_sqrd < MAX_PUMPKIN_RANGE.powi(2)
|
||||||
|
&& line_of_sight_with_target()
|
||||||
|
&& agent.combat_state.timers[ActionStateTimers::SinceFarPumpkin as usize]
|
||||||
|
> FAR_PUMPKIN_COOLDOWN
|
||||||
|
{
|
||||||
|
// throw pumpkin
|
||||||
|
controller.push_basic_input(InputKind::Ability(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
// closing gap
|
||||||
|
if !(attack_data.dist_sqrd < (attack_data.body_dist + 0.4 * MELEE_RANGE).powi(2)) {
|
||||||
self.path_toward_target(
|
self.path_toward_target(
|
||||||
agent,
|
agent,
|
||||||
controller,
|
controller,
|
||||||
@ -4845,110 +4918,7 @@ impl<'a> AgentData<'a> {
|
|||||||
read_data,
|
read_data,
|
||||||
Path::Partial,
|
Path::Partial,
|
||||||
None,
|
None,
|
||||||
)
|
);
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// shortcuts
|
|
||||||
macro_rules! conditions {
|
|
||||||
($condition:ident) => {
|
|
||||||
agent.combat_state.conditions[ActionStateConditions::$condition as usize]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
macro_rules! timers {
|
|
||||||
($timer:ident) => {
|
|
||||||
agent.combat_state.timers[ActionStateTimers::$timer as usize]
|
|
||||||
};
|
|
||||||
}
|
|
||||||
macro_rules! is_in_vines_recovery {
|
|
||||||
() => (
|
|
||||||
matches!(self.char_state, CharacterState::SpriteSummon(c) if matches!(c.stage_section, StageSection::Recover))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
macro_rules! is_using_firebreath {
|
|
||||||
// currently using firebreath and under time limit
|
|
||||||
($time_limit:ident) => (
|
|
||||||
matches!(self.char_state, CharacterState::BasicBeam(c) if c.timer < Duration::from_secs_f32($time_limit))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- main ---
|
|
||||||
|
|
||||||
// handle timers
|
|
||||||
match self.char_state {
|
|
||||||
CharacterState::BasicBeam(_) => {
|
|
||||||
reset_timer!(SinceFirebreath);
|
|
||||||
},
|
|
||||||
CharacterState::BasicRanged(_) => {
|
|
||||||
reset_timer!(SinceCloseMixup);
|
|
||||||
reset_timer!(SinceFarPumpkin);
|
|
||||||
},
|
|
||||||
_ => {
|
|
||||||
increment_timer!(SinceFirebreath);
|
|
||||||
increment_timer!(SinceCloseMixup);
|
|
||||||
increment_timer!(SinceFarPumpkin);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
// vine summoning
|
|
||||||
let health_fraction = self.health.map_or(0.5, |h| h.fraction());
|
|
||||||
|
|
||||||
if health_fraction < SECOND_VINE_CREATION_THRESHOLD && !conditions!(HasSummonedSecondVines)
|
|
||||||
{
|
|
||||||
use_second_vines!();
|
|
||||||
if is_in_vines_recovery!() {
|
|
||||||
conditions!(HasSummonedSecondVines) = true;
|
|
||||||
}
|
|
||||||
} else if health_fraction < FIRST_VINE_CREATION_THRESHOLD
|
|
||||||
&& !conditions!(HasSummonedFirstVines)
|
|
||||||
{
|
|
||||||
use_first_vines!();
|
|
||||||
if is_in_vines_recovery!() {
|
|
||||||
conditions!(HasSummonedFirstVines) = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// close range
|
|
||||||
else if attack_data.dist_sqrd < (attack_data.body_dist + 0.75 * MELEE_RANGE).powi(2) {
|
|
||||||
if is_using_firebreath!(FIREBREATH_SHORT_TIME) {
|
|
||||||
use_fire_breath!();
|
|
||||||
} else if timers!(SinceCloseMixup) > CLOSE_MIXUP_COOLDOWN
|
|
||||||
// for now, no line of sight check for consitency in attacks
|
|
||||||
{
|
|
||||||
if timers!(SinceFirebreath) < FIREBREATH_COOLDOWN {
|
|
||||||
use_pumpkin!();
|
|
||||||
} else {
|
|
||||||
let randomise = rng.gen_range(1..=3);
|
|
||||||
match randomise {
|
|
||||||
1 => use_fire_breath!(),
|
|
||||||
2 => use_pumpkin!(),
|
|
||||||
_ => use_scythe!(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if attack_data.angle < 60.0 {
|
|
||||||
use_scythe!();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// mid range (with line of sight)
|
|
||||||
else if attack_data.dist_sqrd < FIREBREATH_RANGE.powi(2) && line_of_sight_with_target() {
|
|
||||||
if is_using_firebreath!(FIREBREATH_TIME) {
|
|
||||||
use_fire_breath!();
|
|
||||||
} else if attack_data.angle < 30.0 && timers!(SinceFirebreath) > FIREBREATH_COOLDOWN {
|
|
||||||
use_fire_breath!();
|
|
||||||
} else if timers!(SinceCloseMixup) > CLOSE_MIXUP_COOLDOWN {
|
|
||||||
use_pumpkin!();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// long range (with line of sight)
|
|
||||||
else if attack_data.dist_sqrd < MAX_PUMPKIN_RANGE.powi(2)
|
|
||||||
&& line_of_sight_with_target()
|
|
||||||
&& timers!(SinceFarPumpkin) > FAR_PUMPKIN_COOLDOWN
|
|
||||||
{
|
|
||||||
use_pumpkin!();
|
|
||||||
}
|
|
||||||
|
|
||||||
// closing gap
|
|
||||||
if !(attack_data.dist_sqrd < (attack_data.body_dist + 0.4 * MELEE_RANGE).powi(2)) {
|
|
||||||
move_to_target!();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user