[Add] Random number generator to lua/ai.
This commit is contained in:
parent
943cbecf70
commit
6dad718ef2
@ -88,3 +88,14 @@ createvect(number x, number y)
|
|||||||
-- y coord of the vector.
|
-- y coord of the vector.
|
||||||
-- return pointer to the Vec2
|
-- return pointer to the Vec2
|
||||||
|
|
||||||
|
say(string message)
|
||||||
|
-- Make the pilot say something to the player.
|
||||||
|
-- message - string to output.
|
||||||
|
-- return nil
|
||||||
|
|
||||||
|
rng(number low, number high)
|
||||||
|
-- Return a random number between low and high.
|
||||||
|
-- low - minimum to return.
|
||||||
|
-- high - maximum to return
|
||||||
|
-- return random number between low and high.
|
||||||
|
|
||||||
|
21
src/ai.c
21
src/ai.c
@ -11,6 +11,7 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "physics.h"
|
#include "physics.h"
|
||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
|
#include "rng.h"
|
||||||
#include "ai.h"
|
#include "ai.h"
|
||||||
|
|
||||||
// == AI ======================================================
|
// == AI ======================================================
|
||||||
@ -77,11 +78,12 @@ static int ai_accel(lua_State* L); // accel(number); nuimber <= 1.
|
|||||||
static int ai_turn(lua_State* L); // turn(number); abs(number) <= 1.
|
static int ai_turn(lua_State* L); // turn(number); abs(number) <= 1.
|
||||||
static int ai_face(lua_State* L); // face(number/pointer)
|
static int ai_face(lua_State* L); // face(number/pointer)
|
||||||
static int ai_brake(lua_State* L); // Brake()
|
static int ai_brake(lua_State* L); // Brake()
|
||||||
|
// Combat.
|
||||||
|
static int ai_shoot(lua_State* L); // shoot(number) number = 1,2,3.
|
||||||
// Misc.
|
// Misc.
|
||||||
static int ai_createvect(lua_State* L); // createvect(number, number)
|
static int ai_createvect(lua_State* L); // createvect(number, number)
|
||||||
static int ai_say(lua_State* L); // say(string)
|
static int ai_say(lua_State* L); // say(string)
|
||||||
// Combat.
|
static int ai_rng(lua_State* L); // rng(number, number)
|
||||||
static int ai_shoot(lua_State* L); // shoot(number) number = 1,2,3.
|
|
||||||
|
|
||||||
// Global Lua interpreter.
|
// Global Lua interpreter.
|
||||||
static lua_State* L = NULL;
|
static lua_State* L = NULL;
|
||||||
@ -133,6 +135,7 @@ int ai_init(void) {
|
|||||||
// Misc.
|
// Misc.
|
||||||
lua_register(L, "createvect", ai_createvect);
|
lua_register(L, "createvect", ai_createvect);
|
||||||
lua_register(L, "say", ai_say);
|
lua_register(L, "say", ai_say);
|
||||||
|
lua_register(L, "rng", ai_rng);
|
||||||
|
|
||||||
char* buf = pack_readfile(DATA, "../scripts/ai/test.lua", NULL);
|
char* buf = pack_readfile(DATA, "../scripts/ai/test.lua", NULL);
|
||||||
|
|
||||||
@ -366,6 +369,7 @@ static int ai_createvect(lua_State* L) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Have the pilot say something to player.
|
||||||
static int ai_say(lua_State* L) {
|
static int ai_say(lua_State* L) {
|
||||||
MIN_ARGS(1);
|
MIN_ARGS(1);
|
||||||
|
|
||||||
@ -375,6 +379,19 @@ static int ai_say(lua_State* L) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return a number between low and high.
|
||||||
|
static int ai_rng(lua_State* L) {
|
||||||
|
MIN_ARGS(2);
|
||||||
|
|
||||||
|
int l, h;
|
||||||
|
|
||||||
|
if(lua_isnumber(L,1)) l = (int)lua_tonumber(L, 1);
|
||||||
|
if(lua_isnumber(L,1)) h = (int)lua_tonumber(L, 2);
|
||||||
|
|
||||||
|
lua_pushnumber(L, RNG(l,h));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Pew pew.. Says the pilot.
|
// Pew pew.. Says the pilot.
|
||||||
static int ai_shoot(lua_State* L) {
|
static int ai_shoot(lua_State* L) {
|
||||||
int n = 1;
|
int n = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user