diff options
| author | metamuffin <metamuffin@disroot.org> | 2024-08-13 19:44:23 +0200 | 
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2024-08-13 19:44:23 +0200 | 
| commit | f24a9001ef0fafcdbcf20e23eef67f4b71dcf3a5 (patch) | |
| tree | fa5a27b29f54acfef803713dc16a3631008df25c /server/src | |
| parent | 3f3c38326128518c653f1b731c28d028c2a45c40 (diff) | |
| download | hurrycurry-f24a9001ef0fafcdbcf20e23eef67f4b71dcf3a5.tar hurrycurry-f24a9001ef0fafcdbcf20e23eef67f4b71dcf3a5.tar.bz2 hurrycurry-f24a9001ef0fafcdbcf20e23eef67f4b71dcf3a5.tar.zst | |
summonbot command
Diffstat (limited to 'server/src')
| -rw-r--r-- | server/src/state.rs | 16 | 
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(())      } | 
