Skip to main content

gizmo_scripting/
api_ai.rs

1//! AI API — Lua'ya sunulan Yapay Zeka navigasyon fonksiyonları
2//!
3//! Lua scriptlerinden NPC ve ajanlara gitmeleri gereken hedefleri ayarlamayı sağlar.
4
5use crate::commands::{CommandQueue, ScriptCommand};
6use gizmo_math::Vec3;
7use mlua::prelude::*;
8use std::sync::Arc;
9
10/// AI API fonksiyonlarını Lua'ya kaydeder
11pub fn register_ai_api(lua: &Lua, command_queue: Arc<CommandQueue>) -> Result<(), LuaError> {
12    let ai_table = lua.create_table()?;
13
14    // === SET TARGET ===
15    {
16        let cq = command_queue.clone();
17        ai_table.set(
18            "set_target",
19            lua.create_function(move |_, (id, x, y, z): (u32, f32, f32, f32)| {
20                cq.push(ScriptCommand::SetAiTarget(id, Vec3::new(x, y, z)));
21                Ok(())
22            })?,
23        )?;
24    }
25
26    // === CLEAR TARGET ===
27    {
28        let cq = command_queue.clone();
29        ai_table.set(
30            "clear_target",
31            lua.create_function(move |_, id: u32| {
32                cq.push(ScriptCommand::ClearAiTarget(id));
33                Ok(())
34            })?,
35        )?;
36    }
37
38    // === ADD AGENT ===
39    {
40        let cq = command_queue.clone();
41        ai_table.set(
42            "add_agent",
43            lua.create_function(move |_, id: u32| {
44                cq.push(ScriptCommand::AddNavAgent(id));
45                Ok(())
46            })?,
47        )?;
48    }
49
50    lua.globals().set("ai", ai_table)?;
51    Ok(())
52}