aboutsummaryrefslogtreecommitdiff
path: root/server/src/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/state.rs')
-rw-r--r--server/src/state.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/server/src/state.rs b/server/src/state.rs
index 343d130f..2b112913 100644
--- a/server/src/state.rs
+++ b/server/src/state.rs
@@ -17,11 +17,13 @@
*/
use crate::{
data::DataIndex,
+ entity::bot::BotDriver,
server::{Server, ServerState},
ConnectionID,
};
use anyhow::{anyhow, bail, Result};
use clap::{Parser, ValueEnum};
+use hurrycurry_bot::algos::ALGO_CONSTRUCTORS;
use hurrycurry_client_lib::Game;
use hurrycurry_protocol::{Message, PacketC, PacketS, PlayerID};
use log::{debug, trace};
@@ -70,6 +72,8 @@ enum Command {
Item { name: String },
/// Reload the resource index
ReloadIndex,
+ #[clap(alias = "summon-bot", alias = "spawn-bot")]
+ CreateBot { algo: String, name: Option<String> },
/// Reload the current map
#[clap(alias = "r")]
Reload,
@@ -300,6 +304,18 @@ impl State {
})
.ok();
}
+ Command::CreateBot { algo, name } => {
+ let (aname, cons) = ALGO_CONSTRUCTORS
+ .iter()
+ .find(|(name, _)| *name == algo.as_str())
+ .ok_or(anyhow!("algo name unknown"))?;
+ let algo = cons();
+ self.server.entities.push(Box::new(BotDriver::new(
+ format!("{}-bot", name.unwrap_or((*aname).to_owned())),
+ 51,
+ algo,
+ )));
+ }
}
Ok(())
}