Skip to content

Commit

Permalink
Updates.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryankopf committed Aug 20, 2023
1 parent 8f5f13a commit d300a67
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 23 deletions.
1 change: 1 addition & 0 deletions src/initializations/startup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub fn startup(
.insert(position)
.insert(position.to_transform_layer(0.5))
.insert(Plant { growth, plant_type })
.insert( Object { itemtype: plant_type, ..default() } )
.id()
;
if plant_type.is_forageable().0.is_some() && growth > 0.5 {
Expand Down
2 changes: 1 addition & 1 deletion src/task_system/personality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub fn personalities(
territorial::territorial(entity, brain, physical_body, position, nest, &potential_targets);
},
Some(PersonalityTrait::Human) => {
human::human(entity, brain, physical_body, position, nest, &objects, &already_targeted, &obstacles, &tiletypes);
human::human(entity, brain, physical_body, position, &objects, &already_targeted, &obstacles, &tiletypes);
},
_ => {
nopersonality::nopersonality(entity, brain, physical_body, position, nest);
Expand Down
49 changes: 28 additions & 21 deletions src/task_system/personality/human.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ pub fn human(
mut brain: Mut<Brain>,
mut physical_body: Mut<PhysicalBody>,
position: &Position,
nest: Option<&Nest>,
potential_targets: &Query<(Entity, Option<&Object>, Option<&Zone>, Option<&WorkTarget>, &Position)>,
already_targeted: &Vec<Entity>,
obstacles: &std::collections::HashSet<Position>,
Expand All @@ -19,28 +18,30 @@ pub fn human(
.map(|(_, _, _, _, position)| *position)
.collect();
// Anything to DO?
let mut i = 0;
for (target_entity, target_object, target_zone, target_worktarget, target_position) in potential_targets.iter() {
// i += 1;
// println!("Target {} of {}", i, potential_targets.iter().count());

if already_targeted.contains(&target_entity) { continue; }
if target_entity == entity { continue; }
let distance = position.distance(&target_position);
if distance > 100 { continue; }
if target_object.is_none() && target_zone.is_none() { continue; }
if ! crate::is_position_reachable(position, target_position, obstacles, tiletypes) { continue; }

if distance > 50 { continue; }
let is_reachable = || crate::is_position_reachable(position, target_position, obstacles, tiletypes);

// TARGET OBJECTS
if target_object.is_some() {
let target_object = target_object.unwrap();
if target_object.itemtype.is_choppable().0.is_some() && target_worktarget.is_some() {
brain.task = Some(Task::Chop);
return;
}
if target_object.itemtype.is_forageable().0.is_some() {
brain.task = Some(Task::Forage);
return;
if target_worktarget.is_some() {
if target_object.itemtype.is_choppable().0.is_some() {
if set_task(&mut brain, Task::Chop, is_reachable) { return; }
}
if target_object.itemtype.is_forageable().0.is_some() {
if set_task(&mut brain, Task::Forage, is_reachable) { return; }
}
}
if target_object.under_construction {
brain.task = Some(Task::Construct);
return;
if set_task(&mut brain, Task::Construct, is_reachable) { return; }
}
// if target_object.itemtype.is_harvestable().0.is_some() {
// brain.task = Some(Task::Harvest);
Expand All @@ -52,18 +53,24 @@ pub fn human(
let target_zone = target_zone.unwrap();
if target_zone.zone_type == ZoneType::Farm {
if ! object_positions.contains(&target_position) { // Ensure nothing is already planted there.
println!("Planting!");
brain.task = Some(Task::Plant);
return;
if set_task(&mut brain, Task::Plant, is_reachable) { return; }
}
}
if target_zone.zone_type == ZoneType::Construction {
brain.task = Some(Task::Construct);
return;
if set_task(&mut brain, Task::Construct, is_reachable) { return; }
}
}

}
brain.motivation = Some(Motivation::Meander);
brain.task = None;
brain.task = Some(Task::Meander);
}

fn set_task(
brain: &mut Mut<Brain>,
task: Task,
is_reachable: impl FnOnce() -> bool,
) -> bool {
if !is_reachable() { return false; }
brain.task = Some(task);
return true;
}
2 changes: 1 addition & 1 deletion src/thinking_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Plugin for ThinkingPlugin {
.run_if(in_state(GameState::InGame))
,
remotivate_system
.run_if(bevy::time::common_conditions::on_timer(bevy::utils::Duration::from_secs_f32(0.5)))
.run_if(bevy::time::common_conditions::on_timer(bevy::utils::Duration::from_secs_f32(2.5)))
.run_if(in_state(GameState::InGame))
)
)
Expand Down

0 comments on commit d300a67

Please sign in to comment.