File: luaaisexp.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,716 kB
  • sloc: cpp: 595,001; ansic: 21,741; python: 1,174; sh: 457; makefile: 248; xml: 181
file content (85 lines) | stat: -rw-r--r-- 3,791 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
//
//

#include "luaaisexp.h"

namespace scripting {
namespace api {

lua_ai_sexp_h::lua_ai_sexp_h(sexp::LuaAISEXP* handle) : sexp_handle(handle) {
}
lua_ai_sexp_h::lua_ai_sexp_h() : sexp_handle(nullptr) {
}
bool lua_ai_sexp_h::isValid() const {
	return sexp_handle != nullptr;
}

ADE_OBJ(l_LuaAISEXP, lua_ai_sexp_h, "LuaAISEXP", "Lua AI SEXP handle");

inline int sexp_function_getset_helper(lua_State* L, void (sexp::LuaAISEXP::*setter)(const luacpp::LuaFunction&), luacpp::LuaFunction (sexp::LuaAISEXP::* getter)() const) {
	lua_ai_sexp_h lua_sexp;
	luacpp::LuaFunction action_arg;
	if (!ade_get_args(L, "o|u", l_LuaAISEXP.Get(&lua_sexp), &action_arg)) {
		return ADE_RETURN_NIL;
	}

	if (!lua_sexp.isValid()) {
		return ADE_RETURN_NIL;
	}

	if (ADE_SETTING_VAR) {
		Assertion(action_arg.isValid(), "Function reference must be valid!");

		(lua_sexp.sexp_handle->*setter)(action_arg);
	}

	auto action = (lua_sexp.sexp_handle->*getter)();
	return ade_set_args(L, "u", &action);
}

ADE_VIRTVAR(ActionEnter,
	l_LuaAISEXP,
	"function(ai_helper helper, any... args) => boolean action"
	"/* If a target parameter is specified, it will be the first object of args in form of an OSWPT type. The following arguments are the additional parameters. The additional parameters are nil if the order is given as a player order. */",
	"The action of this AI SEXP to be executed once when the AI receives this order. Return true if the AI goal is complete.",
	"function(ai_helper helper, any... args) => boolean action",
	"The action function or nil on error")
{
	return sexp_function_getset_helper(L, &sexp::LuaAISEXP::setActionEnter, &sexp::LuaAISEXP::getActionEnter);
}

ADE_VIRTVAR(ActionFrame,
	l_LuaAISEXP,
	"function(ai_helper helper, any... args) => boolean action"
	"/* If a target parameter is specified, it will be the first object of args in form of an OSWPT type. The following arguments are the additional parameters. The additional parameters are nil if the order is given as a player order. */",
	"The action of this AI SEXP to be executed each frame while active. Return true if the AI goal is complete.",
	"function(ai_helper helper, any... args) => boolean action",
	"The action function or nil on error")
{
	return sexp_function_getset_helper(L, &sexp::LuaAISEXP::setAction, &sexp::LuaAISEXP::getAction);
}

ADE_VIRTVAR(Achievability,
	l_LuaAISEXP,
	"function(ship ship, any... args) => enumeration achievable"
	"/* If a target parameter is specified, it will be the first object of args in form of an OSWPT type. The following arguments are the additional parameters. The additional parameters are nil if the order is given as a player order. */",
	"An optional function that specifies whether the AI mode is achieveable. Return LUAAI_ACHIEVABLE if it can be achieved, LUAAI_NOT_YET_ACHIEVABLE if it can be achieved later and execution should be delayed, and LUAAI_UNACHIEVABLE if the AI mode will never be achievable and should be cancelled. Assumes LUAAI_ACHIEVABLE if not specified.",
	"function(ship ship, any... args) => enumeration achievable",
	"The achievability function or nil on error")
{
	return sexp_function_getset_helper(L, &sexp::LuaAISEXP::setAchievable, &sexp::LuaAISEXP::getAchievable);
}

ADE_VIRTVAR(TargetRestrict,
	l_LuaAISEXP,
	"function(ship ship, oswpt | nil arg) => boolean validTarget",
	"An optional function that specifies whether a target is a valid target for a player order. Result must be true and the player order +Target Restrict: must be fulfilled for the target to be valid. Assumes true if not specified.",
	"function(ship ship, oswpt | nil arg) => boolean validTarget",
	"The target restrict function or nil on error")
{
	return sexp_function_getset_helper(L, &sexp::LuaAISEXP::setTargetRestrict, &sexp::LuaAISEXP::getTargetRestrict);
}

}
}