rust/lib-hwengine-future/src/lib.rs
branchtransitional_engine
changeset 16039 a236360669cc
parent 16035 0caa3dfb3ba2
child 16040 6c5b3c576fc6
--- a/rust/lib-hwengine-future/src/lib.rs	Wed Sep 18 14:10:51 2024 +0200
+++ b/rust/lib-hwengine-future/src/lib.rs	Sun Oct 27 17:00:17 2024 +0100
@@ -1,3 +1,5 @@
+mod ai;
+
 use integral_geometry::{Point, Size};
 
 use landgen::{
@@ -10,6 +12,7 @@
 use mapgen::{theme::Theme, MapGenerator};
 use std::fs;
 use std::{ffi::CStr, path::Path};
+use ai::*;
 
 #[repr(C)]
 pub struct GameField {
@@ -43,7 +46,7 @@
         landgen_parameters: None,
     });
 
-    Box::leak(game_field)
+    Box::into_raw(game_field)
 }
 
 #[no_mangle]
@@ -83,7 +86,7 @@
         landgen_parameters: Some(params),
     });
 
-    Box::leak(game_field)
+    Box::into_raw(game_field)
 }
 
 #[no_mangle]
@@ -123,7 +126,7 @@
         landgen_parameters: Some(params),
     });
 
-    Box::leak(game_field)
+    Box::into_raw(game_field)
 }
 
 #[no_mangle]
@@ -166,7 +169,7 @@
         landgen_parameters: Some(params),
     });
 
-    Box::leak(game_field)
+    Box::into_raw(game_field)
 }
 
 #[no_mangle]
@@ -244,3 +247,28 @@
 pub extern "C" fn dispose_game_field(game_field: *mut GameField) {
     unsafe { drop(Box::from_raw(game_field)) };
 }
+
+#[no_mangle]
+pub extern "C" fn create_ai(game_field: &GameField) -> *mut AI {
+    Box::into_raw(Box::new(AI::new(game_field)))
+}
+
+#[no_mangle]
+pub extern "C" fn ai_clear_team(ai: &mut AI) {
+    *ai.get_team_mut() = vec![];
+}
+
+#[no_mangle]
+pub extern "C" fn ai_add_team_hedgehog(ai: &mut AI, x: f32, y: f32) {
+    ai.get_team_mut().push(Hedgehog{x, y});
+}
+
+#[no_mangle]
+pub extern "C" fn ai_think(ai: &AI) {
+
+}
+
+#[no_mangle]
+pub extern "C" fn dispose_ai(ai: *mut AI) {
+    unsafe { drop(Box::from_raw(ai)) };
+}
\ No newline at end of file