#[cfg(test)]
#[path = "../../tests/tf2/objectives/train_watcher.rs"]
mod tests;
use super::{CaptureArea, Objective, ObjectiveError};
use crate::Server;
use crate::entities::Entity;
use crate::inputs::InputValue;
use std::ffi::{CString, c_int};
#[doc(alias("team_train_watcher", "CTeamTrainWatcher", "payload", "cart"))]
#[derive(Debug, Clone, Copy)]
pub struct TrainWatcher<'s>(Objective<'s>);
impl<'s> TrainWatcher<'s> {
pub fn new(server: Server<'s>, entity: Entity<'s>) -> Result<Self, ObjectiveError> {
Objective::new(server, entity, c"CTeamTrainWatcher", "team_train_watcher").map(Self)
}
#[doc(alias("m_bTrainCanRecede", "train_can_recede"))]
pub fn can_recede(self) -> Result<bool, ObjectiveError> {
self.0
.bool_field(c"CTeamTrainWatcher", c"m_bTrainCanRecede")
}
#[doc(alias("m_nNumCappers", "GetCapperCount"))]
pub fn cappers(self) -> Result<c_int, ObjectiveError> {
self.0.get(c"m_nNumCappers")
}
#[doc(alias("Disable"))]
pub fn disable(self) -> Result<(), ObjectiveError> {
self.0.input(c"Disable", InputValue::Void)
}
#[doc(alias("Enable"))]
pub fn enable(self) -> Result<(), ObjectiveError> {
self.0.input(c"Enable", InputValue::Void)
}
pub fn entity(self) -> Entity<'s> {
self.0.entity()
}
#[doc(alias("m_bHandleTrainMovement", "handle_train_movement"))]
pub fn handles_train_movement(self) -> Result<bool, ObjectiveError> {
self.0
.bool_field(c"CTeamTrainWatcher", c"m_bHandleTrainMovement")
}
#[doc(alias("m_bDisabled", "StartDisabled", "IsDisabled"))]
pub fn is_disabled(self) -> Result<bool, ObjectiveError> {
self.0.bool_field(c"CTeamTrainWatcher", c"m_bDisabled")
}
#[doc(alias("m_flTotalProgress", "GetTrainProgress"))]
pub fn progress(self) -> Result<f32, ObjectiveError> {
self.0.get(c"m_flTotalProgress")
}
#[doc(alias("m_nTrainRecedeTime", "train_recede_time"))]
pub fn recede_delay(self) -> Result<Option<c_int>, ObjectiveError> {
let seconds = self
.0
.int_field(c"CTeamTrainWatcher", c"m_nTrainRecedeTime")?;
Ok((seconds > 0).then_some(seconds))
}
#[doc(alias("m_flRecedeTime"))]
pub fn recede_time(self) -> Result<Option<f32>, ObjectiveError> {
let time: f32 = self.0.get(c"m_flRecedeTime")?;
Ok((time > 0.0).then_some(time))
}
#[doc(alias("SetTrainCanRecede"))]
pub fn set_can_recede(self, can: bool) -> Result<(), ObjectiveError> {
self.0.input(c"SetTrainCanRecede", InputValue::Bool(can))
}
#[doc(alias("SetNumTrainCappers"))]
pub fn set_cappers(
self,
cappers: c_int,
area: Option<CaptureArea<'_>>,
) -> Result<(), ObjectiveError> {
let caller = area.map_or(self.0.entity(), CaptureArea::entity);
self.0.input_from(
c"SetNumTrainCappers",
InputValue::Int(cappers),
caller,
caller,
)
}
#[doc(alias("SetTrainRecedeTime"))]
pub fn set_recede_delay(self, seconds: c_int) -> Result<(), ObjectiveError> {
self.0
.input(c"SetTrainRecedeTime", InputValue::Int(seconds))
}
#[doc(alias("SetTrainRecedeTimeAndUpdate"))]
pub fn set_recede_delay_and_restart(self, seconds: c_int) -> Result<(), ObjectiveError> {
self.0
.input(c"SetTrainRecedeTimeAndUpdate", InputValue::Int(seconds))
}
#[doc(alias("SetSpeedForwardModifier"))]
pub fn set_speed_forward_modifier(self, modifier: f32) -> Result<(), ObjectiveError> {
self.0
.input(c"SetSpeedForwardModifier", InputValue::Float(modifier))
}
#[doc(alias("m_flSpeedForwardModifier"))]
pub fn speed_forward_modifier(self) -> Result<f32, ObjectiveError> {
self.0
.float_field(c"CTeamTrainWatcher", c"m_flSpeedForwardModifier")
}
#[doc(alias("m_iTrainSpeedLevel"))]
pub fn speed_level(self) -> Result<c_int, ObjectiveError> {
self.0.get(c"m_iTrainSpeedLevel")
}
pub fn train(self) -> Result<Option<Entity<'s>>, ObjectiveError> {
let name = self.train_name()?;
super::find_by_name(self.0.server(), &name, |_, entity| Ok(entity))
}
#[doc(alias("m_iszTrain", "train"))]
pub fn train_name(self) -> Result<CString, ObjectiveError> {
self.0.string_key(c"CTeamTrainWatcher", c"train")
}
}