File: comm_order.cpp

package info (click to toggle)
freespace2 25.0.0~rc11%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 47,232 kB
  • sloc: cpp: 657,500; ansic: 22,305; sh: 293; python: 200; makefile: 198; xml: 181
file content (83 lines) | stat: -rw-r--r-- 2,523 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

#include "comm_order.h"
#include "hud/hudsquadmsg.h"

namespace scripting::api {

//**********HANDLE: mission goals
ADE_OBJ_NO_MULTI(l_Comm_Item, int, "comm_item", "Comm Item handle");

ADE_VIRTVAR(Name, l_Comm_Item, nullptr, "The name of the comm item", "string", "The comm item name")
{
	int current;
	if (!ade_get_args(L, "o", l_Comm_Item.Get(&current))) {
		return ADE_RETURN_NIL;
	}

	if (ADE_SETTING_VAR) {
		LuaError(L, "This property is read only.");
	}

	return ade_set_args(L, "s", MsgItems[current].text.c_str());
}

ADE_VIRTVAR(Active, l_Comm_Item, nullptr, "Whether or not the item is active", "boolean", "The active status")
{
	int current;
	if (!ade_get_args(L, "o", l_Comm_Item.Get(&current))) {
		return ADE_RETURN_NIL;
	}

	if (ADE_SETTING_VAR) {
		LuaError(L, "This property is read only.");
	}

	if (MsgItems[current].active > 0) {
		return ADE_RETURN_TRUE;
	}

	return ADE_RETURN_FALSE;
}

// Yes, it's a little silly to get this this way. Adding a getter to the mission library was an option but for that I'd
// have to be sure the title is always set which is fine but mostly it just felt out of place. Having this here keeps all
// comm menu code neat and tidy right here. I also thought about adding it as a parameter of the On HUD Comm Menu Open hook
// but that method wouldn't update as the player moves through the menu since the hook only runs once.
ADE_FUNC(getMenuTitle, l_Comm_Item, nullptr, "Gets the current title of the menu. Will be the same for all currently valid comm items.", "string", "The menu title")
{
	int current = -1;

	if (!ade_get_args(L, "o", l_Comm_Item.Get(&current)))
		return ADE_RETURN_FALSE;

	return ade_set_args(L, "s", Squad_msg_title);
}

ADE_FUNC(selectItem, l_Comm_Item, nullptr, "Selects the item and either proceeds to the next menu or issues the order", "boolean", "Returns true if successful, false otherwise")
{
	int current = -1;

	if (!ade_get_args(L, "o", l_Comm_Item.Get(&current)))
		return ADE_RETURN_FALSE;

	if (current < 0 || current >= Num_menu_items) {
		LuaError(L, "Lua tried to select squad message that is not valid!");
		return ADE_RETURN_FALSE;
	}

	Hud_set_lua_key(current);

	return ADE_RETURN_TRUE;
}

ADE_FUNC(isValid, l_Comm_Item, nullptr, "Detect if the handle is valid", "boolean", "true if valid, false otherwise")
{
	int current = -1;

	if (!ade_get_args(L, "o", l_Comm_Item.Get(&current)))
		return ADE_RETURN_FALSE;

	return ade_set_args(L, "b", (current >= 0) && (current < Num_menu_items));
}

} // namespace scripting::api