Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
buxx committed May 15, 2024
1 parent 2d47a9c commit cdf7c3d
Show file tree
Hide file tree
Showing 36 changed files with 678 additions and 102 deletions.
196 changes: 196 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,27 @@
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
"name": "face_to_face1",
"cargo": {
"args": [
"build",
"--bin=face_to_face1",
"--package=examples",
],
"filter": {
"name": "face_to_face1",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
Expand Down Expand Up @@ -943,5 +964,180 @@
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
"name": "face_to_face_with_one_side_brickwall1 --release",
"cargo": {
"args": [
"build",
"--bin=face_to_face_with_one_side_brickwall1",
"--package=examples",
"--release"
],
"filter": {
"name": "face_to_face_with_one_side_brickwall1",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
"name": "face_to_face_with_one_side_brickwall2 --release",
"cargo": {
"args": [
"build",
"--bin=face_to_face_with_one_side_brickwall2",
"--package=examples",
"--release"
],
"filter": {
"name": "face_to_face_with_one_side_brickwall2",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
"name": "face_to_face_with_one_side_brickwall3 --release",
"cargo": {
"args": [
"build",
"--bin=face_to_face_with_one_side_brickwall3",
"--package=examples",
"--release"
],
"filter": {
"name": "face_to_face_with_one_side_brickwall3",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
"name": "face_to_face_opaque1 --release",
"cargo": {
"args": [
"build",
"--bin=face_to_face_opaque1",
"--package=examples",
"--release"
],
"filter": {
"name": "face_to_face_opaque1",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
"name": "face_to_face_opaque2 --release",
"cargo": {
"args": [
"build",
"--bin=face_to_face_opaque2",
"--package=examples",
"--release"
],
"filter": {
"name": "face_to_face_opaque2",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
"name": "running_with_one_side_brickwall1 --release",
"cargo": {
"args": [
"build",
"--bin=running_with_one_side_brickwall1",
"--package=examples",
"--release"
],
"filter": {
"name": "running_with_one_side_brickwall1",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
"name": "walking_with_one_side_brickwall1 --release",
"cargo": {
"args": [
"build",
"--bin=walking_with_one_side_brickwall1",
"--package=examples",
"--release"
],
"filter": {
"name": "walking_with_one_side_brickwall1",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
{
"type": "lldb",
"request": "launch",
"name": "walking_with_one_side_brickwall1",
"cargo": {
"args": [
"build",
"--bin=walking_with_one_side_brickwall1",
"--package=examples",
],
"filter": {
"name": "walking_with_one_side_brickwall1",
"kind": "bin"
}
},
"args": [],
"cwd": "${workspaceFolder}",
"env": {
"RUST_BACKTRACE": "1"
}
},
]
}
3 changes: 2 additions & 1 deletion battle_core/src/behavior/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use serde::{Deserialize, Serialize};
pub mod feeling;
pub mod gesture;

#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
pub enum Body {
StandUp,
Crouched,
Expand Down Expand Up @@ -148,6 +148,7 @@ impl Behavior {

pub fn posture(&self) -> Posture {
// TODO : posture can be different on same behavior (like with SuppressFire, EngageSoldier)
// FIXME: Clarify which usage with `Body` !!
match self {
Behavior::MoveTo(_) | Behavior::MoveFastTo(_) | Behavior::Idle(_) => Posture::StandUp,
Behavior::Defend(_)
Expand Down
10 changes: 9 additions & 1 deletion battle_core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use strum::IntoEnumIterator;
pub const DEFAULT_SERVER_REP_ADDRESS: &str = "tcp://0.0.0.0:4255";
pub const DEFAULT_SERVER_PUB_ADDRESS: &str = "tcp://0.0.0.0:4256";
///
pub const TARGET_CYCLE_DURATION_US: u64 = 16666;
pub const TARGET_FPS: u64 = 60;
pub const SOLDIER_UPDATE_FREQ: u64 = 1;
pub const FLAGS_UPDATE_FREQ: u64 = 120;
Expand Down Expand Up @@ -41,7 +42,7 @@ pub const VISIBILITY_DEAD_MODIFIER: f32 = 0.0;
pub const VISIBILITY_UNCONSCIOUS_MODIFIER: f32 = 0.0;
///
pub const TILE_TYPE_OPACITY_SHORT_GRASS: f32 = 0.0;
pub const TILE_TYPE_OPACITY_MIDDLE_GRASS: f32 = 0.008;
pub const TILE_TYPE_OPACITY_MIDDLE_GRASS: f32 = 0.002;
pub const TILE_TYPE_OPACITY_HIGH_GRASS: f32 = 0.1;
pub const TILE_TYPE_OPACITY_DIRT: f32 = 0.0;
pub const TILE_TYPE_OPACITY_CONCRETE: f32 = 0.0;
Expand Down Expand Up @@ -87,6 +88,7 @@ pub const COVER_DISTANCE: i32 = 6;
// Visibility computing must consider firsts tiles differently
pub const VISIBILITY_FIRSTS: usize = 6;
pub const VISIBLE_STARTS_AT: f32 = 0.5;
pub const TARGET_ALTERATION_BY_OPACITY_FACTOR: f32 = 10.;
// When compute visibility, configure here each pixels step of line which me considered
pub const VISIBILITY_PIXEL_STEPS: usize = 5;
// When compute coverage, configure here each pixels step of line which me considered
Expand All @@ -103,6 +105,7 @@ pub const CAN_STANDUP_AFTER: u64 = TARGET_FPS * 60 * 10;
#[derive(Debug, Clone)]
pub struct ServerConfig {
pub send_debug_points: bool,
pub target_cycle_duration_us: u64,
pub flags_update_freq: u64,
pub soldier_update_freq: u64,
pub soldier_animate_freq: u64,
Expand All @@ -115,6 +118,7 @@ pub struct ServerConfig {
pub feeling_decreasing_freq: u64,
pub visibility_firsts: usize,
pub visible_starts_at: f32,
pub target_alteration_by_opacity_factor: f32,
pub visibility_idle_standup_modifier: f32,
pub visibility_idle_crouch_modifier: f32,
pub visibility_idle_lying_modifier: f32,
Expand Down Expand Up @@ -167,6 +171,7 @@ impl Default for ServerConfig {

Self {
send_debug_points: false,
target_cycle_duration_us: TARGET_CYCLE_DURATION_US,
/// Frequency of flags update

Check failure on line 175 in battle_core/src/config.rs

View workflow job for this annotation

GitHub Actions / 🛃 Clippy

unused doc comment

Check warning on line 175 in battle_core/src/config.rs

View workflow job for this annotation

GitHub Actions / 🧪 Test Suite

unused doc comment

Check warning on line 175 in battle_core/src/config.rs

View workflow job for this annotation

GitHub Actions / 🔎 Check

unused doc comment
flags_update_freq: FLAGS_UPDATE_FREQ,
/// Frequency of soldier update :

Check failure on line 177 in battle_core/src/config.rs

View workflow job for this annotation

GitHub Actions / 🛃 Clippy

unused doc comment

Check warning on line 177 in battle_core/src/config.rs

View workflow job for this annotation

GitHub Actions / 🧪 Test Suite

unused doc comment

Check warning on line 177 in battle_core/src/config.rs

View workflow job for this annotation

GitHub Actions / 🔎 Check

unused doc comment
Expand Down Expand Up @@ -194,6 +199,7 @@ impl Default for ServerConfig {
///
visibility_firsts: VISIBILITY_FIRSTS,
visible_starts_at: VISIBLE_STARTS_AT,
target_alteration_by_opacity_factor: TARGET_ALTERATION_BY_OPACITY_FACTOR,

visibility_idle_standup_modifier: VISIBILITY_IDLE_STANDUP_MODIFIER,
visibility_idle_crouch_modifier: VISIBILITY_IDLE_CROUCH_MODIFIER,
Expand Down Expand Up @@ -337,6 +343,7 @@ impl ServerConfig {
pub fn react(&mut self, message: &ChangeConfigMessage) {
match message {
ChangeConfigMessage::SendDebugPoints(v) => self.send_debug_points = *v,
ChangeConfigMessage::TargetCycleDuration(v) => self.target_cycle_duration_us = *v,
ChangeConfigMessage::SoldierUpdateFreq(v) => self.soldier_update_freq = *v,
ChangeConfigMessage::SoldierAnimateFreq(v) => self.soldier_animate_freq = *v,
ChangeConfigMessage::InteriorsUpdateFreq(v) => self.interiors_update_freq = *v,
Expand Down Expand Up @@ -410,6 +417,7 @@ impl Default for GuiConfig {
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum ChangeConfigMessage {
SendDebugPoints(bool),
TargetCycleDuration(u64),
SoldierUpdateFreq(u64),
SoldierAnimateFreq(u64),
InteriorsUpdateFreq(u64),
Expand Down
17 changes: 17 additions & 0 deletions battle_core/src/entity/soldier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,23 @@ impl Soldier {
let weapon_animation_type = WeaponAnimationType::from(&animation_type);
(animation_type, weapon_animation_type)
}

pub fn body(&self) -> Body {
match self.behavior {
Behavior::MoveTo(_) => Body::StandUp,
Behavior::MoveFastTo(_) => Body::StandUp,
Behavior::SneakTo(_) => Body::Lying,
Behavior::DriveTo(_) => Body::Crouched,
Behavior::RotateTo(_) => Body::Crouched,
Behavior::Idle(body) => body,
Behavior::Defend(_) => Body::Lying,
Behavior::Hide(_) => Body::Lying,
Behavior::Dead => Body::Lying,
Behavior::Unconscious => Body::Lying,
Behavior::SuppressFire(_) => Body::Lying,
Behavior::EngageSoldier(_) => Body::Lying,
}
}
}

impl From<&SoldierDeployment> for Soldier {
Expand Down
6 changes: 3 additions & 3 deletions battle_core/src/map/terrain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fmt::Display, str::FromStr};

use crate::{game::posture::Posture, types::Coverage};

#[derive(Clone)]
#[derive(Clone, Debug)]
pub enum TileType {
ShortGrass,
MiddleGrass,
Expand Down Expand Up @@ -113,14 +113,14 @@ impl TileType {
TileType::Mud => Some(Coverage(0.3)),
TileType::Concrete => None,
TileType::BrickWall => Some(Coverage(0.8)),
TileType::Trunk => Some(Coverage(0.9)),
TileType::Trunk => Some(Coverage(0.7)),
TileType::Water => None,
TileType::DeepWater => None,
TileType::Underbrush => None,
TileType::LightUnderbrush => None,
TileType::MiddleWoodLogs => Some(Coverage(0.7)),
TileType::Hedge => Some(Coverage(0.15)),
TileType::MiddleRock => Some(Coverage(0.9)),
TileType::MiddleRock => Some(Coverage(0.75)),
},
}
}
Expand Down
29 changes: 24 additions & 5 deletions battle_core/src/physics/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,37 @@ impl<'a> SoldierCovered<'a> {
}
}

pub fn compute(&self) -> bool {
pub fn compute(&self, force_target_tile: bool) -> bool {
// Make bullet path from the end to get target soldier tiles
let pixels = Bresenham::new(
(
self.bullet_fire.from().x as isize,
self.bullet_fire.from().y as isize,
),
(
self.bullet_fire.to().x as isize,
self.bullet_fire.to().y as isize,
),
(
self.bullet_fire.from().x as isize,
self.bullet_fire.from().y as isize,
),
);

if force_target_tile {
let target_grid_point = self
.map
.grid_point_from_world_point(&self.soldier.world_point());

if let Some(tile) = self
.map
.terrain_tiles()
.get((target_grid_point.y * self.map.width() as i32 + target_grid_point.x) as usize)
{
if let Some(coverage) = tile.type_().coverage(&self.soldier.behavior().posture()) {
let mut rng = rand::thread_rng();
let value: f32 = rng.gen();
return value <= coverage.0;
}
}
}

let mut visited_grid_points = vec![];
for (pixel_x, pixel_y) in pixels.step_by(COVERAGE_PIXEL_STEPS) {
let grid_point = self
Expand Down
Loading

0 comments on commit cdf7c3d

Please sign in to comment.