aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/unit_patrol.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 12:27:06 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 12:27:06 +0300
commitc846377ead77ef7184cdeddd25c3f2c9d76a6736 (patch)
tree6980b05a3fa7ea41b26f64c40ad1fef91849af23 /crates/fparkan-runtime/src/unit_patrol.rs
parent7dd027fd5130daf532cd2214a6d9689293bb2c86 (diff)
downloadfparkan-c846377ead77ef7184cdeddd25c3f2c9d76a6736.tar.xz
fparkan-c846377ead77ef7184cdeddd25c3f2c9d76a6736.zip
feat(ui): send warbots to recharge from the strategic panel
Verify LTW-3 approaches the generator and clears its recharge status after leaving from the stock Two Fortresses start. Reuse authored building passages and shared Control replenishment, with a licensed test for refilling an empty magazine.
Diffstat (limited to 'crates/fparkan-runtime/src/unit_patrol.rs')
-rw-r--r--crates/fparkan-runtime/src/unit_patrol.rs41
1 files changed, 30 insertions, 11 deletions
diff --git a/crates/fparkan-runtime/src/unit_patrol.rs b/crates/fparkan-runtime/src/unit_patrol.rs
index 48e4924a..6a230135 100644
--- a/crates/fparkan-runtime/src/unit_patrol.rs
+++ b/crates/fparkan-runtime/src/unit_patrol.rs
@@ -2,7 +2,7 @@ use super::{
animal_migration::{flight_clearance, AnimalMigration},
autodemo::{MOBILE_UNIT, PLANT_CLASS},
boarding::WARBOT_CLASS,
- building_passage::CapturePassage,
+ building_passage::BuildingPassage,
factory_release::FactoryDeparture,
flight_altitude::FlightClearance,
ground_support::GroundSupport,
@@ -22,6 +22,7 @@ use fparkan_world::{set_transform, transform_state};
use std::collections::{BTreeMap, HashSet, VecDeque};
mod orders;
+mod recharge;
mod search_and_destroy;
pub(super) use orders::supports_order;
pub(super) use orders::UnitOrder;
@@ -58,11 +59,12 @@ pub(super) struct PatrollingUnit {
retry_ms: u32,
attack: Option<ObjectHandle>,
search: Option<search_and_destroy::Search>,
+ recharge: Option<recharge::Recharge>,
attack_target: Option<(ObjectHandle, usize)>,
raid_factory: Option<(ObjectHandle, usize)>,
ground_support: Option<Option<GroundSupport>>,
capture_target: Option<ObjectHandle>,
- capture_passage: Option<CapturePassage>,
+ building_passage: Option<BuildingPassage>,
animal_clearance: Option<f32>,
}
@@ -200,14 +202,16 @@ impl UnitPatrol {
if let Some(unit) = self.units.iter_mut().find(|unit| unit.handle == handle) {
unit.raid_factory = None;
unit.capture_target = None;
- unit.capture_passage = None;
+ unit.building_passage = None;
let was_attacking = unit.attack_target.take().is_some();
let was_moving = unit.destinations.take().is_some();
let was_searching = unit.search.take().is_some();
+ let was_recharging = unit.recharge.take().is_some();
if unit.center_object.take().is_some()
|| was_moving
|| was_attacking
|| was_searching
+ || was_recharging
|| unit.center != center
|| unit.radius != radius
{
@@ -231,11 +235,12 @@ impl UnitPatrol {
retry_ms: 0,
attack: None,
search: None,
+ recharge: None,
attack_target: None,
raid_factory: None,
ground_support: None,
capture_target: None,
- capture_passage: None,
+ building_passage: None,
animal_clearance: None,
});
true
@@ -273,12 +278,12 @@ impl UnitPatrol {
handle: ObjectHandle,
building: ObjectHandle,
destination: [f32; 2],
- passage: Option<CapturePassage>,
+ passage: Option<BuildingPassage>,
) {
self.move_to(world, handle, destination, false);
if let Some(unit) = self.units.iter_mut().find(|unit| unit.handle == handle) {
unit.capture_target = Some(building);
- unit.capture_passage = passage;
+ unit.building_passage = passage;
}
}
@@ -321,7 +326,7 @@ impl UnitPatrol {
) -> impl Iterator<Item = (usize, f32)> + '_ {
self.units
.iter()
- .filter_map(|unit| unit.capture_passage.as_ref())
+ .filter_map(|unit| unit.building_passage.as_ref())
.filter(move |route| route.building == building)
.filter_map(|route| route.opening)
}
@@ -493,11 +498,12 @@ impl UnitPatrol {
retry_ms: 0,
attack: None,
search: None,
+ recharge: None,
attack_target: None,
raid_factory: None,
ground_support: None,
capture_target: None,
- capture_passage: None,
+ building_passage: None,
animal_clearance: None,
})
.collect();
@@ -541,9 +547,10 @@ impl UnitPatrol {
.as_ref()
.is_none_or(|items| !items.is_empty())
|| unit
- .capture_passage
+ .building_passage
.as_ref()
- .is_some_and(|route| !route.legs.is_empty()))
+ .is_some_and(|route| !route.legs.is_empty())
+ || unit.recharge.is_some())
&& unit.center(world).is_some()
});
let seconds = now_ms.saturating_sub(state.clock_ms) as f32 * 0.001;
@@ -586,6 +593,18 @@ impl UnitPatrol {
.animal_clearance
.map(|_| true)
.or_else(|| chassis.get(&original_id).and_then(|flags| flags.can_fly));
+ if unit.recharge.is_some()
+ && (seconds == 0.0
+ || !unit.advance_recharge(
+ world,
+ mission,
+ now_ms,
+ from,
+ traffic.radius(unit.handle),
+ ))
+ {
+ continue;
+ }
if let Some(destinations) = &mut unit.destinations {
if destinations
.front()
@@ -596,7 +615,7 @@ impl UnitPatrol {
unit.retry_ms = 0;
}
if destinations.is_empty() {
- if let Some(route) = &mut unit.capture_passage {
+ if let Some(route) = &mut unit.building_passage {
if transform_state(world, route.building).is_err() {
route.legs.clear();
continue;