#[cfg(test)]
#[path = "../../tests/tf2/objectives/capture_area.rs"]
mod tests;
use super::{ControlPoint, Objective, ObjectiveError};
use crate::Server;
use crate::entities::Entity;
use crate::inputs::InputValue;
use crate::tf2::scoreboard::ScoringTeam;
use std::ffi::{CStr, CString};
#[doc(alias("trigger_capture_area", "CTriggerAreaCapture"))]
#[derive(Debug, Clone, Copy)]
pub struct CaptureArea<'s>(Objective<'s>);
impl<'s> CaptureArea<'s> {
pub fn new(server: Server<'s>, entity: Entity<'s>) -> Result<Self, ObjectiveError> {
Objective::new(
server,
entity,
c"CTriggerAreaCapture",
"trigger_capture_area",
)
.map(Self)
}
#[doc(alias("CaptureCurrentCP"))]
pub fn capture_current_point(self) -> Result<(), ObjectiveError> {
self.0.input(c"CaptureCurrentCP", InputValue::Void)
}
#[doc(alias("m_flCapTime", "area_time_to_cap"))]
pub fn capture_time(self) -> Result<f32, ObjectiveError> {
self.0.float_field(c"CTriggerAreaCapture", c"m_flCapTime")
}
pub fn control_point(self) -> Result<Option<ControlPoint<'s>>, ObjectiveError> {
let name = self.control_point_name()?;
super::find_by_name(self.0.server(), &name, ControlPoint::new)
}
#[doc(alias("m_iszCapPointName", "area_cap_point"))]
pub fn control_point_name(self) -> Result<CString, ObjectiveError> {
self.0.string_key(c"CTriggerAreaCapture", c"area_cap_point")
}
#[doc(alias("Disable"))]
pub fn disable(self) -> Result<(), ObjectiveError> {
self.0.input(c"Disable", InputValue::Void)
}
#[doc(alias("DisableAndEndTouch", "EndTouch"))]
pub fn disable_and_end_touch(self) -> Result<(), ObjectiveError> {
self.0.input(c"DisableAndEndTouch", 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_bDisabled", "StartDisabled"))]
pub fn is_disabled(self) -> Result<bool, ObjectiveError> {
self.0.bool_field(c"CBaseTrigger", c"m_bDisabled")
}
#[doc(alias("SetControlPoint", "area_cap_point"))]
pub fn set_control_point(self, name: &CStr) -> Result<(), ObjectiveError> {
self.0.input(c"SetControlPoint", InputValue::String(name))?;
self.0.set_key_value(c"area_cap_point", name)
}
#[doc(alias("SetTeamCanCap", "team_cancap_2", "team_cancap_3"))]
pub fn set_team_can_capture(self, team: ScoringTeam, can: bool) -> Result<(), ObjectiveError> {
let value = CString::new(format!("{} {}", team.to_raw(), u8::from(can)))
.expect("integers format without NUL bytes");
self.0.input(c"SetTeamCanCap", InputValue::String(&value))
}
#[doc(alias("Toggle"))]
pub fn toggle(self) -> Result<(), ObjectiveError> {
self.0.input(c"Toggle", InputValue::Void)
}
}