Change agent's condition field back to a bool (from bitflags) and add a separate int_counter field.

This commit is contained in:
Avi Weinstock 2021-05-09 17:38:46 -04:00
parent 1dfcdce1c0
commit 1ae105125d
6 changed files with 58 additions and 69 deletions

View File

@ -125,6 +125,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Wolf AI will no longer circle into walls and will instead use the power of raycasts to stop early - Wolf AI will no longer circle into walls and will instead use the power of raycasts to stop early
- Squirrels are no longer immune to arrows at some angles. - Squirrels are no longer immune to arrows at some angles.
- /spawn command's auto-complete now works for species names - /spawn command's auto-complete now works for species names
- Mindflayer AI now correctly summons husks at certain HP thresholds.
## [0.9.0] - 2021-03-20 ## [0.9.0] - 2021-03-20

43
Cargo.lock generated
View File

@ -2399,15 +2399,6 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "inline_tweak"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7033e97b20277cc0d043226d1940fa7719ff08d2305d1fc7421e53066d00eb4b"
dependencies = [
"lazy_static",
]
[[package]] [[package]]
name = "inotify" name = "inotify"
version = "0.7.1" version = "0.7.1"
@ -5523,7 +5514,6 @@ name = "veloren-common"
version = "0.9.0" version = "0.9.0"
dependencies = [ dependencies = [
"approx 0.4.0", "approx 0.4.0",
"assets_manager",
"bitflags", "bitflags",
"criterion", "criterion",
"crossbeam-channel", "crossbeam-channel",
@ -5532,7 +5522,6 @@ dependencies = [
"dot_vox", "dot_vox",
"enum-iterator", "enum-iterator",
"hashbrown", "hashbrown",
"image",
"indexmap", "indexmap",
"lazy_static", "lazy_static",
"num-derive", "num-derive",
@ -5540,10 +5529,8 @@ dependencies = [
"ordered-float 2.1.1", "ordered-float 2.1.1",
"rand 0.8.3", "rand 0.8.3",
"rayon", "rayon",
"ron",
"roots", "roots",
"serde", "serde",
"serde_json",
"serde_repr", "serde_repr",
"slab", "slab",
"slotmap", "slotmap",
@ -5557,9 +5544,22 @@ dependencies = [
"tracing-subscriber", "tracing-subscriber",
"uuid", "uuid",
"vek", "vek",
"veloren-common-assets",
"veloren-common-base", "veloren-common-base",
] ]
[[package]]
name = "veloren-common-assets"
version = "0.9.0"
dependencies = [
"assets_manager",
"dot_vox",
"image",
"lazy_static",
"ron",
"tracing",
]
[[package]] [[package]]
name = "veloren-common-base" name = "veloren-common-base"
version = "0.9.0" version = "0.9.0"
@ -5652,6 +5652,19 @@ dependencies = [
"veloren-common-net", "veloren-common-net",
] ]
[[package]]
name = "veloren-i18n"
version = "0.9.0"
dependencies = [
"deunicode",
"git2",
"hashbrown",
"ron",
"serde",
"tracing",
"veloren-common-assets",
]
[[package]] [[package]]
name = "veloren-network" name = "veloren-network"
version = "0.3.0" version = "0.3.0"
@ -5736,7 +5749,6 @@ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"futures-util", "futures-util",
"hashbrown", "hashbrown",
"inline_tweak",
"itertools 0.10.0", "itertools 0.10.0",
"lazy_static", "lazy_static",
"num_cpus", "num_cpus",
@ -5805,7 +5817,6 @@ dependencies = [
"cpal", "cpal",
"criterion", "criterion",
"crossbeam", "crossbeam",
"deunicode",
"directories-next", "directories-next",
"dispatch 0.1.4", "dispatch 0.1.4",
"dot_vox", "dot_vox",
@ -5815,7 +5826,6 @@ dependencies = [
"gfx_device_gl", "gfx_device_gl",
"gfx_gl", "gfx_gl",
"gilrs", "gilrs",
"git2",
"glsl-include", "glsl-include",
"glutin", "glutin",
"glyph_brush", "glyph_brush",
@ -5853,6 +5863,7 @@ dependencies = [
"veloren-common-net", "veloren-common-net",
"veloren-common-state", "veloren-common-state",
"veloren-common-systems", "veloren-common-systems",
"veloren-i18n",
"veloren-server", "veloren-server",
"veloren-voxygen-anim", "veloren-voxygen-anim",
"veloren-world", "veloren-world",

View File

@ -280,7 +280,8 @@ pub struct Agent {
pub struct ActionState { pub struct ActionState {
pub timer: f32, pub timer: f32,
pub counter: f32, pub counter: f32,
pub condition: u8, pub condition: bool,
pub int_counter: u8,
} }
impl Agent { impl Agent {

View File

@ -577,33 +577,27 @@ fn handle_ability(data: &JoinData, update: &mut StateUpdate, input: InputKind) {
.inventory .inventory
.equipped(equip_slot) .equipped(equip_slot)
.map(|i| &i.item_config_expect().abilities) .map(|i| &i.item_config_expect().abilities)
.and_then(|abilities| { .and_then(|abilities| match input {
tracing::info!("ability: {:?} {:?}", input, abilities); InputKind::Primary => Some(abilities.primary.clone()),
match input { InputKind::Secondary => Some(abilities.secondary.clone()),
InputKind::Primary => Some(abilities.primary.clone()), InputKind::Ability(0) => abilities.abilities.get(0).cloned().and_then(unlocked),
InputKind::Secondary => Some(abilities.secondary.clone()), InputKind::Ability(i) => abilities
InputKind::Ability(0) => abilities.abilities.get(0).cloned().and_then(unlocked), .abilities
InputKind::Ability(skill_index) => abilities .get(if i < 2 { skill_index } else { i })
.abilities .cloned()
.get(skill_index) .and_then(unlocked),
.cloned() InputKind::Roll | InputKind::Jump | InputKind::Fly | InputKind::Block => None,
.and_then(unlocked),
InputKind::Roll | InputKind::Jump | InputKind::Fly | InputKind::Block => None,
}
}) })
.map(|a| { .map(|a| {
let tool = unwrap_tool_data(data, equip_slot).map(|t| t.kind); let tool = unwrap_tool_data(data, equip_slot).map(|t| t.kind);
tracing::info!("ability tool: {:?} {:?}", input, tool);
a.adjusted_by_skills(&data.skill_set, tool) a.adjusted_by_skills(&data.skill_set, tool)
}) })
.filter(|ability| ability.requirements_paid(data, update)) .filter(|ability| ability.requirements_paid(data, update))
{ {
tracing::info!("ability before setting state: {:?} {:?}", input, ability);
update.character = CharacterState::from(( update.character = CharacterState::from((
&ability, &ability,
AbilityInfo::from_input(data, matches!(equip_slot, EquipSlot::Offhand), input), AbilityInfo::from_input(data, matches!(equip_slot, EquipSlot::Offhand), input),
)); ));
tracing::info!("ability setting state: {:?} {:?}", input, update.character);
} }
} }
} }
@ -807,14 +801,12 @@ impl AbilityInfo {
tool_data.map(|t| HandInfo::from_main_tool(t, from_offhand)), tool_data.map(|t| HandInfo::from_main_tool(t, from_offhand)),
); );
let ret = Self { Self {
tool, tool,
hand, hand,
input, input,
input_attr: data.controller.queued_inputs.get(&input).copied(), input_attr: data.controller.queued_inputs.get(&input).copied(),
}; }
tracing::info!("AbilityInfo::from_input: {:?} {:?}", input, ret);
ret
} }
} }

View File

@ -22,7 +22,7 @@ common-net = { package = "veloren-common-net", path = "../common/net" }
world = { package = "veloren-world", path = "../world" } world = { package = "veloren-world", path = "../world" }
network = { package = "veloren-network", path = "../network", features = ["metrics", "compression"], default-features = false } network = { package = "veloren-network", path = "../network", features = ["metrics", "compression"], default-features = false }
inline_tweak = "1.0.8" # inline_tweak = "1.0.8"
specs = { git = "https://github.com/amethyst/specs.git", features = ["shred-derive"], rev = "5a9b71035007be0e3574f35184acac1cd4530496" } specs = { git = "https://github.com/amethyst/specs.git", features = ["shred-derive"], rev = "5a9b71035007be0e3574f35184acac1cd4530496" }
specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", rev = "b65fb220e94f5d3c9bc30074a076149763795556" } specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", rev = "b65fb220e94f5d3c9bc30074a076149763795556" }

View File

@ -2996,18 +2996,12 @@ impl<'a> AgentData<'a> {
) { ) {
const MINDFLAYER_ATTACK_DIST: f32 = 16.0; const MINDFLAYER_ATTACK_DIST: f32 = 16.0;
const MINION_SUMMON_THRESHOLD: f32 = 0.20; const MINION_SUMMON_THRESHOLD: f32 = 0.20;
// Bit index of action_state.condition for whether the mindflayer initialized
// minion summoning state
const MINDFLAYER_INITIALIZED_THRESHOLD: usize = 0;
// Bit index of action_state.condition for how many fireballs left to shoot
// before blinking (this is a 2 bit number, from 0-3)
const MINDFLAYER_NUM_FIREBALLS_LO: usize = 1;
const MINDFLAYER_NUM_FIREBALLS_MASK: usize = 0b110;
let health_fraction = self.health.map_or(0.5, |h| h.fraction()); let health_fraction = self.health.map_or(0.5, |h| h.fraction());
// Sets counter at start of combat // Sets counter at start of combat, using `condition` to keep track of whether
if (agent.action_state.condition & (1 << MINDFLAYER_INITIALIZED_THRESHOLD)) == 0 { // it was already intitialized
if !agent.action_state.condition {
agent.action_state.counter = 1.0 - MINION_SUMMON_THRESHOLD; agent.action_state.counter = 1.0 - MINION_SUMMON_THRESHOLD;
agent.action_state.condition |= 1 << MINDFLAYER_INITIALIZED_THRESHOLD; agent.action_state.condition = true;
} }
agent.action_state.timer = (agent.action_state.timer - read_data.dt.0 as f32).max(0.0); agent.action_state.timer = (agent.action_state.timer - read_data.dt.0 as f32).max(0.0);
if agent.action_state.timer > 0.0 { if agent.action_state.timer > 0.0 {
@ -3020,7 +3014,6 @@ impl<'a> AgentData<'a> {
.actions .actions
.push(ControlAction::basic_input(InputKind::Ability(2))); .push(ControlAction::basic_input(InputKind::Ability(2)));
//tracing::info!("Pushing summon state: {:?}", agent);
if matches!(self.char_state, CharacterState::BasicSummon(c) if matches!(c.stage_section, StageSection::Recover)) if matches!(self.char_state, CharacterState::BasicSummon(c) if matches!(c.stage_section, StageSection::Recover))
{ {
agent.action_state.counter -= MINION_SUMMON_THRESHOLD; agent.action_state.counter -= MINION_SUMMON_THRESHOLD;
@ -3029,16 +3022,14 @@ impl<'a> AgentData<'a> {
self.char_state, self.char_state,
CharacterState::BasicSummon(_) | CharacterState::Blink(_) CharacterState::BasicSummon(_) | CharacterState::Blink(_)
) { ) {
// Deliberately do nothing here to prevent overwriting summon/blink state with another // Deliberately do nothing here to prevent overwriting summon/blink
// input // state with another input
} else if mindflayer_is_far { } else if mindflayer_is_far {
// If too far from target, throw a random number of necrotic spheres at them and then // If too far from target, throw a random number of necrotic spheres at them and
// blink to them. // then blink to them.
let num_fireballs = (agent.action_state.condition & 0b110) >> 1; let num_fireballs = &mut agent.action_state.int_counter;
if num_fireballs == 0 { if *num_fireballs == 0 {
let new_num_fireballs = rand::random::<u8>() % 4; *num_fireballs = rand::random::<u8>() % 4;
agent.action_state.condition &= !0b110;
agent.action_state.condition |= new_num_fireballs << 1;
controller.actions.push(ControlAction::StartInput { controller.actions.push(ControlAction::StartInput {
input: InputKind::Ability(0), input: InputKind::Ability(0),
target_entity: agent target_entity: agent
@ -3049,9 +3040,7 @@ impl<'a> AgentData<'a> {
select_pos: None, select_pos: None,
}); });
} else { } else {
let new_num_fireballs = num_fireballs - 1; *num_fireballs -= 1;
agent.action_state.condition &= !0b110;
agent.action_state.condition |= new_num_fireballs << 1;
controller.actions.push(ControlAction::StartInput { controller.actions.push(ControlAction::StartInput {
input: InputKind::Ability(1), input: InputKind::Ability(1),
target_entity: agent target_entity: agent
@ -3393,9 +3382,6 @@ impl<'a> AgentData<'a> {
const MINOTAUR_FRENZY_THRESHOLD: f32 = 0.5; const MINOTAUR_FRENZY_THRESHOLD: f32 = 0.5;
const MINOTAUR_ATTACK_RANGE: f32 = 5.0; const MINOTAUR_ATTACK_RANGE: f32 = 5.0;
const MINOTAUR_CHARGE_DISTANCE: f32 = 15.0; const MINOTAUR_CHARGE_DISTANCE: f32 = 15.0;
// Bit index of the action_state.condition if the minotaur should use secondary
// instead of primary
const MINOTAUR_STATE_SECONDARY: usize = 0;
let minotaur_attack_distance = let minotaur_attack_distance =
self.body.map_or(0.0, |b| b.radius()) + MINOTAUR_ATTACK_RANGE; self.body.map_or(0.0, |b| b.radius()) + MINOTAUR_ATTACK_RANGE;
let health_fraction = self.health.map_or(1.0, |h| h.fraction()); let health_fraction = self.health.map_or(1.0, |h| h.fraction());
@ -3434,20 +3420,18 @@ impl<'a> AgentData<'a> {
.push(ControlAction::basic_input(InputKind::Ability(0))); .push(ControlAction::basic_input(InputKind::Ability(0)));
} }
} else if attack_data.dist_sqrd < minotaur_attack_distance.powi(2) { } else if attack_data.dist_sqrd < minotaur_attack_distance.powi(2) {
if (agent.action_state.condition & (1 << MINOTAUR_STATE_SECONDARY)) != 0 if agent.action_state.condition && !self.char_state.is_attack() {
&& !self.char_state.is_attack()
{
// Cripple target if not just used cripple // Cripple target if not just used cripple
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Secondary)); .push(ControlAction::basic_input(InputKind::Secondary));
agent.action_state.condition &= !(1 << MINOTAUR_STATE_SECONDARY); agent.action_state.condition = false;
} else if !self.char_state.is_attack() { } else if !self.char_state.is_attack() {
// Cleave target if not just used cleave // Cleave target if not just used cleave
controller controller
.actions .actions
.push(ControlAction::basic_input(InputKind::Primary)); .push(ControlAction::basic_input(InputKind::Primary));
agent.action_state.condition |= 1 << MINOTAUR_STATE_SECONDARY; agent.action_state.condition = true;
} }
} }
// Make minotaur move towards target // Make minotaur move towards target