Skip to main content

ObserverGame

Struct ObserverGame 

Source
#[repr(C, packed(1))]
pub struct ObserverGame { pub in_game: bool, pub clock_ms: u32, pub active_player_count: u8, pub game_name: PaddedString<MAX_GAME_NAME_LENGTH>, pub map_name: PaddedString<MAX_MAP_NAME_LENGTH>, }
Expand description

Game-wide state exposed by the Warcraft III Stats Observer API.

Fields§

§in_game: bool

true while a game is in progress.

§clock_ms: u32

Elapsed game time in milliseconds. Use Self::time for a strongly-typed Duration.

§active_player_count: u8

Number of valid entries in crate::ObserverData::players.

§game_name: PaddedString<MAX_GAME_NAME_LENGTH>

Name of the current game / lobby.

§map_name: PaddedString<MAX_MAP_NAME_LENGTH>

Name of the map currently being played.

Implementations§

Source§

impl ObserverGame

Source

pub fn time(&self) -> Duration

Returns the elapsed game time as a Duration.

Examples found in repository?
examples/stats.rs (line 22)
5fn main() {
6    let od = match ObserverHandle::new() {
7        Ok(od) => od,
8        Err(e) => {
9            eprintln!("Error opening observer API. Is Warcraft3 running? Error: {e:?}");
10            return;
11        }
12    };
13
14    println!("version: {}", { od.version });
15    println!("refresh rate: {}", { od.refresh_rate });
16
17    let game = &od.game;
18
19    println!("in game: {:?}", game.in_game);
20    println!(
21        "time: {:02}:{:02}",
22        game.time().as_secs() / 60,
23        game.time().as_secs() % 60
24    );
25    println!("active player count: {:?}", game.active_player_count);
26    println!("game name: {}", game.game_name);
27    println!("map name: {}", game.map_name);
28
29    loop {
30        for player in od.players.iter().take(od.game.active_player_count as usize) {
31            println!("{} has {} gold {} lumber", player.name, { player.gold }, {
32                player.lumber
33            });
34        }
35        println!();
36        std::thread::sleep(Duration::from_millis(od.refresh_rate as u64));
37    }
38}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.