diff --git a/Cargo.lock b/Cargo.lock index 4e16425..1aef5fa 100755 --- a/Cargo.lock +++ b/Cargo.lock @@ -1687,35 +1687,6 @@ dependencies = [ "ui_range_indicator", ] -[[package]] -name = "building_ramtower" -version = "0.1.0" -dependencies = [ - "avian3d", - "bevy", - "building", - "combat", - "combat_damagers", - "inhabitant_endrake", - "resources", - "state", - "upgrade", -] - -[[package]] -name = "building_suncannon" -version = "0.1.0" -dependencies = [ - "avian3d", - "bevy", - "building", - "combat", - "combat_damagers", - "resources", - "state", - "upgrade", -] - [[package]] name = "bumpalo" version = "3.19.0" @@ -2034,8 +2005,6 @@ dependencies = [ "building_core", "building_impaler", "building_placement", - "building_ramtower", - "building_suncannon", "camera", "combat", "combat_damagers", diff --git a/Cargo.toml b/Cargo.toml index f3664d2..2d871bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,6 +61,4 @@ ui_range_indicator = { path = "crates/ui_range_indicator" } inhabitant_simbert = { path = "crates/inhabitant_simbert" } inhabitant_endrake = { path = "crates/inhabitant_endrake" } resource_soul_spot = { path = "crates/resource_soul_spot" } -building_ramtower = { path = "crates/building_ramtower" } -building_suncannon = { path = "crates/building_suncannon" } #new internal crates go here diff --git a/assets/settings/input_map.ron b/assets/settings/input_map.ron index ed21f50..b82ce27 100755 --- a/assets/settings/input_map.ron +++ b/assets/settings/input_map.ron @@ -3,20 +3,20 @@ MouseButton(Middle): [ CameraOrbitEnable, ], - MouseButton(Right): [ - PlaceTower, - ], - MouseButton(Left): [ - CameraPanEnable, - ], KeyCode(ShiftLeft): [ MultiPlaceTower, ], + KeyCode(F1): [ + ToggleDebugUI, + ], + MouseButton(Right): [ + PlaceTower, + ], MouseScroll: [ CameraZoom, ], - KeyCode(F1): [ - ToggleDebugUI, + MouseButton(Left): [ + CameraPanEnable, ], MouseMovementX: [ CameraYaw, diff --git a/crates/building_ramtower/Cargo.toml b/crates/building_ramtower/Cargo.toml deleted file mode 100644 index 8e8cb9f..0000000 --- a/crates/building_ramtower/Cargo.toml +++ /dev/null @@ -1,19 +0,0 @@ -[package] -name = "building_ramtower" -version = "0.1.0" -edition = "2024" - -[dependencies] -bevy = { workspace = true } -avian3d = { workspace = true } - -state = { path = "../state" } -combat = { path = "../combat" } -building = { path = "../building" } -resources = { path = "../resources" } -combat_damagers = { path = "../combat_damagers" } -upgrade = { path = "../upgrade" } -inhabitant_endrake = { path = "../inhabitant_endrake" } - -[lints] -workspace = true diff --git a/crates/building_ramtower/src/lib.rs b/crates/building_ramtower/src/lib.rs deleted file mode 100644 index 75767eb..0000000 --- a/crates/building_ramtower/src/lib.rs +++ /dev/null @@ -1,286 +0,0 @@ -//bevy system signatures often violate these rules -#![allow(clippy::type_complexity)] -#![allow(clippy::too_many_arguments)] - -use std::{cmp::Ordering, f32, time::Duration}; - -use avian3d::prelude::{Collider, GravityScale, LinearVelocity, RigidBody}; -use bevy::prelude::*; -use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding}; -use combat::{ - Defense, Health, Range, Team, - projectiles::{Fire, Projectile, ProjectileLauncher}, -}; -use combat_damagers::ContactDamage; -use inhabitant_endrake::Endrake; -use resources::{Cost, Quantity}; -use upgrade::{Upgrade, UpgradeApplied, UpgradeTree}; - -pub struct BuildingRamtowerPlugin; - -impl Plugin for BuildingRamtowerPlugin { - fn build(&self, app: &mut App) { - app.add_systems(Startup, register).add_observer(populate); - } -} - -#[derive(Component)] -pub struct Ramtower { - pub prioritize_endrakes: bool, - pub shot_velocity: f32, -} - -#[derive(Resource)] -struct BuildingResources { - mesh: Handle, - material: Handle, - projectile_mesh: Handle, - projectile_material: Handle, - projectile_collider: Collider, - info_entity: Entity, -} - -const SIZE: UVec3 = UVec3::new(1, 4, 1); -const PROJ_SIZE: Vec3 = Vec3::new(0.5, 0.5, 2.0); - -fn register( - mut commands: Commands, - mut meshes: ResMut>, - mut materials: ResMut>, -) { - let mesh = meshes.add(Cuboid::from_size(SIZE.as_vec3())); - let base_material = StandardMaterial { - base_color: Color::srgb_u8(152, 174, 174), - metallic: 0.2, - perceptual_roughness: 0.6, - ..default() - }; - let material = materials.add(base_material.clone()); - let preview_material = materials.add(StandardMaterial { - alpha_mode: AlphaMode::Blend, - base_color: base_material.base_color.with_alpha(PREVIEW_ALPHA), - ..base_material - }); - let projectile_material = materials.add(StandardMaterial { - base_color: Color::srgb_u8(86, 106, 106), - metallic: 1.0, - perceptual_roughness: 0.0, - emissive: Color::srgb_u8(86, 106, 106).to_linear() * 0.3, - ..default() - }); - - let info = commands.spawn_empty().id(); - let test_unlocks = vec![ - commands - .spawn(( - Name::new("Endrake Assassain"), - Upgrade { - description: - "Ramtower will prioritize destroying Endrakes. Deals even more damage." - .to_string(), - cost: Quantity { - souls: 50, - bones: 20, - }, - unlocks: vec![], - }, - )) - .observe( - |trigger: Trigger, - mut query: Query<(&mut Ramtower, &mut ProjectileLauncher)>| { - if let Ok((mut ramtower, mut launcher)) = - query.get_mut(trigger.event().building) - { - ramtower.prioritize_endrakes = true; - launcher.damage *= 1.5; - } - }, - ) - .id(), - commands - .spawn(( - Name::new("Fortification"), - Upgrade { - description: "Fortified battering rams significantly more damage. Defense increases as well.".to_string(), - cost: Quantity { - souls: 50, - bones: 10, - }, - unlocks: vec![], - }, - )) - .observe( - |trigger: Trigger, mut query: Query<(&mut ProjectileLauncher, &mut Defense)>| { - if let Ok((mut launcher, mut defense)) = query.get_mut(trigger.event().building) { - launcher.damage *= 2.; - defense.amount += 5.; - } - }, - ) - .id(), - ]; - let upgrades = vec![ - commands - .spawn(( - Name::new("More Force"), - Upgrade { - description: "Battering rams move faster and can be launched farther." - .to_string(), - cost: Quantity { - souls: 25, - bones: 10, - }, - unlocks: test_unlocks, - }, - )) - .observe( - |trigger: Trigger, - mut query: Query<(&mut Ramtower, &mut Range)>| { - if let Ok((mut ramtower, mut range)) = query.get_mut(trigger.event().building) { - ramtower.shot_velocity += 20.; - range.0 *= 1.5; - } - }, - ) - .id(), - ]; - let preview = commands - .spawn(( - BuildingPreview { info }, - Visibility::Hidden, - Mesh3d(mesh.clone()), - MeshMaterial3d(preview_material), - )) - .id(); - commands.entity(info).insert(( - BuildingInfo { - preview, - size: SIZE, - unlocked: true, - }, - Range(10.0), - Health::new(10.0), - Defense::new(4.0), - UpgradeTree { upgrades }, - Cost(Quantity { - souls: 5, - bones: 15, - }), - Name::new("Ramtower"), - )); - commands.insert_resource(BuildingResources { - mesh: mesh, - material: material.clone(), - projectile_material: projectile_material, - projectile_mesh: meshes.add(Cuboid::from_size(PROJ_SIZE)), - projectile_collider: Collider::cuboid(PROJ_SIZE.x, PROJ_SIZE.y, PROJ_SIZE.z), - info_entity: info, - }); -} - -fn populate( - trigger: Trigger, - mut commands: Commands, - res: Res, -) { - if trigger.event().info != res.info_entity { - return; - } - commands - .entity(trigger.target()) - .insert(( - Ramtower { - prioritize_endrakes: false, - shot_velocity: 20., - }, - ContactDamage::new(2.0), - ProjectileLauncher { - custom_targeting: true, - ..ProjectileLauncher::new( - Duration::from_secs(1), - 50.0, - Vec3::Y * (SIZE.y as f32 + 0.5), - Duration::from_secs(10), - 0., - ) - }, - Mesh3d(res.mesh.clone()), - MeshMaterial3d(res.material.clone()), - )) - .observe(on_fire); -} - -fn on_fire( - trigger: Trigger, - query: Query<(&GlobalTransform, &Team, &Ramtower)>, - mut commands: Commands, - res: Res, - enemy_query: Query<(&Team, &GlobalTransform, Option<&Endrake>)>, -) { - let Ok(( - gtf, - team, - Ramtower { - prioritize_endrakes: prioritize_endrake, - shot_velocity, - }, - )) = query.get(trigger.target()) - else { - return; - }; - let Some((target_pos, _endrake)) = trigger - .event() - .enemies_in_range - .iter() - .filter_map(|e| { - enemy_query - .get(*e) - .ok() - .and_then(|(enemy_team, enemy_gtf, opt_endrake)| { - if enemy_team != team { - Some((enemy_gtf.translation(), opt_endrake)) - } else { - None - } - }) - }) - .min_by(|(a, a_e), (b, b_e)| { - if *prioritize_endrake { - // put endrakes first - if a_e.is_some() && b_e.is_none() { - Ordering::Less - } else if a_e.is_none() && b_e.is_some() { - Ordering::Greater - } else { - // default to distance if both are endrakes - gtf.translation() - .distance_squared(*a) - .total_cmp(>f.translation().distance_squared(*b)) - } - } else { - // default to closest by distance - gtf.translation() - .distance_squared(*a) - .total_cmp(>f.translation().distance_squared(*b)) - } - }) - else { - info!("no closest enemy, is someone on the wrong physics layer for their team?"); - return; - }; - let delta = (target_pos - trigger.event().spawn_pos).normalize_or_zero(); - commands.spawn(( - RigidBody::Dynamic, - trigger.event().team, - Health::new(1.0), - GravityScale(0.0), - ContactDamage::projectile(trigger.event().damage, f32::INFINITY), - Transform::from_translation(trigger.event().spawn_pos).looking_at(target_pos, Vec3::Y), - Projectile::from(&trigger.event().launcher), - Projectile::collision_layers(trigger.event().team), - LinearVelocity(delta * shot_velocity), - res.projectile_collider.clone(), - MeshMaterial3d(res.projectile_material.clone()), - Mesh3d(res.projectile_mesh.clone()), - )); -} diff --git a/crates/building_suncannon/Cargo.toml b/crates/building_suncannon/Cargo.toml deleted file mode 100644 index c828985..0000000 --- a/crates/building_suncannon/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "building_suncannon" -version = "0.1.0" -edition = "2024" - -[dependencies] -bevy = { workspace = true } -avian3d = { workspace = true } - -state = { path = "../state" } -combat = { path = "../combat" } -building = { path = "../building" } -resources = { path = "../resources" } -combat_damagers = { path = "../combat_damagers" } -upgrade = { path = "../upgrade" } - -[lints] -workspace = true diff --git a/crates/building_suncannon/src/lib.rs b/crates/building_suncannon/src/lib.rs deleted file mode 100644 index 690732e..0000000 --- a/crates/building_suncannon/src/lib.rs +++ /dev/null @@ -1,312 +0,0 @@ -//bevy system signatures often violate these rules -#![allow(clippy::type_complexity)] -#![allow(clippy::too_many_arguments)] - -use std::{ - f32::{self, consts::PI}, - time::Duration, -}; - -use avian3d::prelude::*; -use bevy::prelude::*; -use building::{BuildingInfo, BuildingPreview, PREVIEW_ALPHA, PopulatePlacedBuilding}; -use combat::{ - Attacked, Defense, Died, Health, Range, Team, - projectiles::{Fire, Projectile, ProjectileLauncher, get_launch_vector}, -}; -use combat_damagers::ContactDamage; -use resources::{Cost, Quantity}; -use upgrade::{Upgrade, UpgradeApplied, UpgradeTree}; - -pub struct BuildingSuncannonPlugin; - -impl Plugin for BuildingSuncannonPlugin { - fn build(&self, app: &mut App) { - app.add_systems(Startup, register).add_observer(populate); - } -} - -#[derive(Component, Clone)] -pub struct Suncannon { - pub explosion_radius: f32, - pub explosion_damage: f32, - pub explosion_knockback: f32, - pub pellet_count: u32, - pub pellet_damage: f32, - pub pellet_speed: f32, -} - -#[derive(Component)] -struct SuncannonProjectile(Suncannon); - -#[derive(Resource)] -struct BuildingResources { - mesh: Handle, - material: Handle, - projectile_mesh: Handle, - projectile_material: Handle, - projectile_collider: Collider, - info_entity: Entity, -} - -const SIZE: UVec3 = UVec3::new(3, 1, 3); -const PROJ_SIZE: Vec3 = Vec3::new(1.0, 1.0, 1.0); - -fn register( - mut commands: Commands, - mut meshes: ResMut>, - mut materials: ResMut>, -) { - let mesh = meshes.add(Cuboid::from_size(SIZE.as_vec3())); - let base_material = StandardMaterial { - base_color: Color::srgb_u8(173, 114, 57), - metallic: 0.8, - perceptual_roughness: 0.0, - emissive: Color::srgb_u8(173, 114, 57).to_linear(), - ..default() - }; - let material = materials.add(base_material.clone()); - let preview_material = materials.add(StandardMaterial { - alpha_mode: AlphaMode::Blend, - base_color: base_material.base_color.with_alpha(PREVIEW_ALPHA), - ..base_material - }); - let projectile_material = materials.add(StandardMaterial { - base_color: Color::srgb_u8(242, 151, 70), - metallic: 0.8, - perceptual_roughness: 0.0, - emissive: Color::srgb_u8(250, 211, 150).to_linear() * 5., - ..default() - }); - - let info = commands.spawn_empty().id(); - let tier3 = vec![ - commands - .spawn(( - Name::new("Sun Geyser"), - Upgrade { - description: "I AM THE SUN!".to_string(), - cost: Quantity { - souls: 1000, - bones: 0, - }, - unlocks: vec![], - }, - )) - .observe( - |trigger: Trigger, - mut query: Query<(&mut Range, &mut ProjectileLauncher, &mut Suncannon)>| { - if let Ok((mut range, mut launcher, mut suncannon)) = query.get_mut(trigger.event().building) { - range.0 += 10.; - let new_duration = launcher.fire_timer.duration() / 4; - launcher.set_interval(new_duration); - suncannon.pellet_damage *= 2.; - } - }, - ) - .id(), - ]; - let tier2 = vec![ - commands - .spawn(( - Name::new("Solar Power"), - Upgrade { - description: "I WILL PUSH THEM ALL BACK. (WITH FORCE)".to_string(), - cost: Quantity { - souls: 500, - bones: 0, - }, - unlocks: tier3, - }, - )) - .observe( - |trigger: Trigger, - mut query: Query<(&mut ProjectileLauncher, &mut Suncannon)>| { - if let Ok((mut launcher, mut suncannon)) = - query.get_mut(trigger.event().building) - { - launcher.damage *= 1.5; - suncannon.explosion_damage *= 2.; - suncannon.explosion_knockback *= 2.; - suncannon.pellet_damage *= 2.; - } - }, - ) - .id(), - ]; - let upgrades = vec![ - commands - .spawn(( - Name::new("Sun Pellets"), - Upgrade { - description: "THEY WILL EAT THIS! AND NOT LIKE IT!".to_string(), - cost: Quantity { - souls: 200, - bones: 0, - }, - unlocks: tier2, - }, - )) - .observe( - |trigger: Trigger, mut query: Query<&mut Suncannon>| { - if let Ok(mut suncannon) = query.get_mut(trigger.event().building) { - suncannon.pellet_count += 5; - } - }, - ) - .id(), - ]; - let preview = commands - .spawn(( - BuildingPreview { info }, - Visibility::Hidden, - Mesh3d(mesh.clone()), - MeshMaterial3d(preview_material), - )) - .id(); - commands.entity(info).insert(( - BuildingInfo { - preview, - size: SIZE, - unlocked: true, - }, - Range(20.0), - Health::new(50.0), - Defense::new(6.0), - UpgradeTree { upgrades }, - Cost(Quantity { - souls: 100, - bones: 15, - }), - Name::new("Suncannon"), - )); - commands.insert_resource(BuildingResources { - mesh: mesh, - material: material.clone(), - projectile_material: projectile_material, - projectile_mesh: meshes.add(Cuboid::from_size(PROJ_SIZE)), - projectile_collider: Collider::cuboid(PROJ_SIZE.x, PROJ_SIZE.y, PROJ_SIZE.z), - info_entity: info, - }); -} - -fn populate( - trigger: Trigger, - mut commands: Commands, - res: Res, -) { - if trigger.event().info != res.info_entity { - return; - } - commands - .entity(trigger.target()) - .insert(( - Suncannon { - explosion_radius: 10.0, - explosion_damage: 20.0, - explosion_knockback: 5.0, - pellet_count: 0, - pellet_damage: 10., - pellet_speed: 50., - }, - ContactDamage::new(2.0), - ProjectileLauncher::new( - Duration::from_secs(3), - 50.0, - Vec3::Y * (SIZE.y as f32 + 0.5), - Duration::from_secs(10), - 0., - ), - Mesh3d(res.mesh.clone()), - MeshMaterial3d(res.material.clone()), - )) - .observe(on_fire); -} - -fn on_fire( - trigger: Trigger, - query: Query<&Suncannon>, - mut commands: Commands, - res: Res, -) { - let Ok(suncannon) = query.get(trigger.target()) else { - return; - }; - let v = get_launch_vector( - trigger.event().spawn_pos, - trigger.event().target_pos, - 100.0, - 0.0, - ); - commands - .spawn(( - RigidBody::Dynamic, - trigger.event().team, - Health::new(1.0), - ContactDamage::projectile(trigger.event().damage, f32::INFINITY), - Transform::from_translation(trigger.event().spawn_pos), - Projectile::from(&trigger.event().launcher), - Projectile::collision_layers(trigger.event().team), - SuncannonProjectile(suncannon.clone()), - LinearVelocity(v), - res.projectile_collider.clone(), - MeshMaterial3d(res.projectile_material.clone()), - Mesh3d(res.projectile_mesh.clone()), - )) - .observe(on_projectile_explode); -} - -fn on_projectile_explode( - trigger: Trigger, - proj_query: Query<(&GlobalTransform, &Team, &SuncannonProjectile)>, - spatial_query: SpatialQuery, - res: Res, - mut enemy_query: Query<(&Team, &GlobalTransform, &mut ExternalImpulse)>, - mut commands: Commands, -) { - let Ok((gtf, team, projectile)) = proj_query.get(trigger.target()) else { - return; - }; - let enemies = spatial_query.shape_intersections( - &Collider::sphere(projectile.0.explosion_radius), - gtf.translation(), - Quat::default(), - &SpatialQueryFilter::from_mask(team.enemy_layers()), - ); - for enemy in enemies { - let Ok((enemy_team, enemy_gtf, mut enemy_v)) = enemy_query.get_mut(enemy) else { - continue; - }; - if enemy_team == team { - continue; - } - let knockback = (enemy_gtf.translation() - gtf.translation()).normalize_or_zero() - * projectile.0.explosion_knockback; - enemy_v.apply_impulse(knockback); - commands.entity(enemy).trigger(Attacked { - attacker: Some(trigger.target()), - amount: projectile.0.explosion_damage, - skip_invulnerability: true, - }); - } - for pellet in 0..projectile.0.pellet_count { - let angle = 2. * PI / (projectile.0.pellet_count as f32) * pellet as f32; - let v = Vec3::new(angle.sin(), 0., angle.cos()) * projectile.0.pellet_speed; - commands.spawn(( - RigidBody::Dynamic, - team.clone(), - Health::new(1.0), - ContactDamage::projectile(projectile.0.pellet_damage, f32::INFINITY), - Transform::from_translation(gtf.translation() + Vec3::Y * 0.1) - .with_scale(Vec3::splat(0.25)), - Projectile { - lifetime: Duration::from_secs(1), - }, - Projectile::collision_layers(*team), - LinearVelocity(v), - res.projectile_collider.clone(), - MeshMaterial3d(res.projectile_material.clone()), - Mesh3d(res.projectile_mesh.clone()), - )); - } -} diff --git a/crates/combat/src/projectiles.rs b/crates/combat/src/projectiles.rs index 0a60404..34b191b 100644 --- a/crates/combat/src/projectiles.rs +++ b/crates/combat/src/projectiles.rs @@ -59,8 +59,6 @@ pub struct ProjectileLauncher { pub spread: f32, pub lifetime: Duration, pub damage: f32, - /// will set fields in the fire event to be defaults, responsiblity of the building to set them up - pub custom_targeting: bool, } impl ProjectileLauncher { @@ -77,7 +75,6 @@ impl ProjectileLauncher { damage, fire_offset, lifetime, - custom_targeting: false, } } @@ -89,8 +86,6 @@ impl ProjectileLauncher { #[derive(Event)] pub struct Fire { pub target: Entity, - pub damage: f32, - pub enemies_in_range: Vec, pub target_pos: Vec3, pub spawn_pos: Vec3, pub launcher: ProjectileLauncher, @@ -128,22 +123,6 @@ fn fire_launcher( if enemies.is_empty() { continue; } - if launcher.custom_targeting { - launcher.fire_timer.reset(); - commands.trigger_targets( - Fire { - target: Entity::PLACEHOLDER, - damage: launcher.damage, - target_pos: Vec3::ZERO, - enemies_in_range: enemies, - spawn_pos: gtf.translation() + launcher.fire_offset, - launcher: launcher.clone(), - team: team.clone(), - }, - [launcher_entity], - ); - continue; - } let Some((closest_enemy, enemy_pos)) = enemies .iter() .filter_map(|e| { @@ -172,8 +151,6 @@ fn fire_launcher( Fire { target: closest_enemy, target_pos: enemy_pos, - damage: launcher.damage, - enemies_in_range: enemies, spawn_pos: gtf.translation() + launcher.fire_offset, launcher: launcher.clone(), team: team.clone(), diff --git a/crates/inhabitant_endrake/src/lib.rs b/crates/inhabitant_endrake/src/lib.rs index 871c3a0..b3815f1 100644 --- a/crates/inhabitant_endrake/src/lib.rs +++ b/crates/inhabitant_endrake/src/lib.rs @@ -5,7 +5,7 @@ use avian3d::prelude::*; use bevy::prelude::*; use building::Core; -use combat::{Defense, Health, Team}; +use combat::{Health, Team}; use combat_damagers::ContactDamage; use inhabitant::Inhabitant; use inhabitant_simbert::SpawnSimbert; @@ -85,7 +85,6 @@ fn spawn( }, transform.clone(), Health::new(2000.0 + 100. * phase.get().phase_count() as f32), - Defense::new(5.), // todo: change enemy health bar color to differentiate from buildings BarSettings { offset: HEIGHT + 0.5, diff --git a/crates/level/src/lib.rs b/crates/level/src/lib.rs index 51f83df..2c31519 100755 --- a/crates/level/src/lib.rs +++ b/crates/level/src/lib.rs @@ -149,8 +149,7 @@ fn setup( } fn spawn_enemies( - mut simbert_writer: EventWriter, - mut endrake_writer: EventWriter, + mut writer: EventWriter, core_query: Single<(&GlobalTransform, &Range), With>, phase_state: Res>, time: Res