use crate::ffi;
impl ffi::LiveDataPacket {
pub fn cars(&self) -> impl Iterator<Item = &ffi::PlayerInfo> {
self.GameCars.iter().take(self.NumCars as usize)
}
pub fn match_score(&self) -> [i32; 2] {
let mut result = [0, 0];
for car in self.cars() {
result[car.Team as usize] += car.Score.Goals;
}
result
}
}
impl ffi::MatchSettings {
#[doc(hidden)]
#[deprecated(note = "this method has been renamed to `rlbot_vs_allstar`")]
pub fn simple_1v1(rlbot_name: &str, allstar_name: &str) -> Self {
Self::rlbot_vs_allstar(rlbot_name, allstar_name)
}
pub fn rlbot_vs_allstar(rlbot_name: &str, allstar_name: &str) -> Self {
let mut result = ffi::MatchSettings {
NumPlayers: 2,
..Default::default()
};
result.PlayerConfiguration[0].Bot = true;
result.PlayerConfiguration[0].RLBotControlled = true;
result.PlayerConfiguration[0].set_name(rlbot_name);
result.PlayerConfiguration[1].Bot = true;
result.PlayerConfiguration[1].BotSkill = 1.0;
result.PlayerConfiguration[1].set_name(allstar_name);
result.PlayerConfiguration[1].Team = 1;
result
}
pub fn allstar_vs_allstar(blue_name: &str, orange_name: &str) -> Self {
let mut result = ffi::MatchSettings {
NumPlayers: 2,
..Default::default()
};
result.PlayerConfiguration[0].Bot = true;
result.PlayerConfiguration[0].BotSkill = 1.0;
result.PlayerConfiguration[0].set_name(blue_name);
result.PlayerConfiguration[1].Bot = true;
result.PlayerConfiguration[1].BotSkill = 1.0;
result.PlayerConfiguration[1].set_name(orange_name);
result.PlayerConfiguration[1].Team = 1;
result
}
}
impl ffi::PlayerConfiguration {
pub fn set_name(&mut self, name: &str) {
for (i, cp) in name.encode_utf16().enumerate() {
self.Name[i] = cp;
}
}
}