-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding territorial personality trait.
- Loading branch information
ryankopf
committed
Aug 9, 2023
1 parent
0567aaf
commit b101ba9
Showing
13 changed files
with
93 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use crate::prelude::*; | ||
pub mod territorial; | ||
pub mod nopersonality; | ||
|
||
pub struct PersonalityPlugin; | ||
|
||
impl Plugin for PersonalityPlugin { | ||
fn build(&self, app: &mut App) { | ||
app | ||
.add_systems( | ||
Update, | ||
(territorial::personality_territorial, nopersonality::personality_nopersonality) | ||
.run_if(bevy::time::common_conditions::on_timer(bevy::utils::Duration::from_secs_f32(0.5))) | ||
.run_if(in_state(GameState::InGame)) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use crate::prelude::*; | ||
|
||
pub fn personality_nopersonality( | ||
mut entities: Query<(Entity, &mut Brain, &mut PhysicalBody, &Position)> | ||
) { | ||
for (entity, mut brain, mut physical_body, position) in entities.iter_mut() { | ||
if brain.task != Some(Task::Personality) { continue; } | ||
if !brain.personality.is_empty() { continue; } | ||
|
||
brain.motivation = Some(Motivation::Meander); | ||
brain.task = None; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use crate::prelude::*; | ||
|
||
pub fn personality_territorial( | ||
mut entities: Query<(Entity, &mut Brain, &mut PhysicalBody, &Position, Option<&Nest>)> | ||
) { | ||
let potential_targets = entities.iter() | ||
.map(|(entity, _, _, position, _)| (entity, *position)) // Clone the Position data | ||
.collect::<Vec<(Entity, Position)>>(); | ||
for (entity, mut brain, mut physical_body, position, nest) in entities.iter_mut() { | ||
if brain.task != Some(Task::Personality) { continue; } | ||
if !brain.personality.contains(&PersonalityTrait::Territorial) { continue; } | ||
// Anything to defend against? | ||
for (target_entity, target_position) in potential_targets.iter() { | ||
if entity == *target_entity { continue; } | ||
if target_position.distance(position) < 5 { | ||
physical_body.danger = Some(Danger { danger_type: DangerType::Attacked, danger_source: Some(*target_entity) }); | ||
brain.remotivate(); | ||
break; | ||
} | ||
} | ||
brain.motivation = Some(Motivation::Meander); | ||
brain.task = None; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters