File: rank.cpp

package info (click to toggle)
freespace2 24.2.0%2Brepack-3
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 43,740 kB
  • sloc: cpp: 595,005; ansic: 21,741; python: 1,174; sh: 457; makefile: 243; xml: 181
file content (122 lines) | stat: -rw-r--r-- 2,770 bytes parent folder | download | duplicates (2)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include "rank.h"

#include "stats/scoring.h"

namespace scripting {
namespace api {

rank_h::rank_h() : rank(-1) {}
rank_h::rank_h(int l_rank) : rank(l_rank) {}

rank_stuff* rank_h::getRank() const
{
	if (!isValid())
		return nullptr;

	return &Ranks[rank];
}

bool rank_h::isValid() const
{
	return rank >= 0 && rank < (int)Ranks.size();
}

//**********HANDLE: rank
ADE_OBJ(l_Rank, rank_h, "rank", "Rank handle");

ADE_FUNC(isValid, l_Rank, nullptr, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
{
	rank_h current;
	if (!ade_get_args(L, "o", l_Rank.Get(&current)))
		return ADE_RETURN_NIL;

	return ade_set_args(L, "b", current.isValid());
}

ADE_VIRTVAR(Name, l_Rank, nullptr, "The name of the rank", "string", "The name")
{
	rank_h current;
	if (!ade_get_args(L, "o", l_Rank.Get(&current))) {
		return ADE_RETURN_NIL;
	}
	if (!current.isValid()) {
		return ade_set_error(L, "s", "");
	}

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

	return ade_set_args(L, "s", current.getRank()->name);
}

ADE_VIRTVAR(AltName, l_Rank, nullptr, "The alt name of the rank", "string", "The alt name")
{
	rank_h current;
	if (!ade_get_args(L, "o", l_Rank.Get(&current))) {
		return ADE_RETURN_NIL;
	}
	if (!current.isValid()) {
		return ade_set_error(L, "s", "");
	}

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

	return ade_set_args(L, "s", current.getRank()->alt_name.c_str());
}

ADE_VIRTVAR(Title, l_Rank, nullptr, "The title of the rank", "string", "The title")
{
	rank_h current;
	if (!ade_get_args(L, "o", l_Rank.Get(&current))) {
		return ADE_RETURN_NIL;
	}
	if (!current.isValid()) {
		return ade_set_error(L, "s", "");
	}

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

	return ade_set_args(L, "s", current.getRank()->title.c_str());
}

ADE_VIRTVAR(Bitmap, l_Rank, nullptr, "The bitmap of the rank", "string", "The bitmap")
{
	rank_h current;
	if (!ade_get_args(L, "o", l_Rank.Get(&current))) {
		return ADE_RETURN_NIL;
	}
	if (!current.isValid()) {
		return ade_set_error(L, "s", "");
	}

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

	return ade_set_args(L, "s", current.getRank()->bitmap);
}

ADE_VIRTVAR(Index, l_Rank, nullptr, "The index of the rank within the Ranks list", "number", "The rank index")
{
	rank_h current;
	if (!ade_get_args(L, "o", l_Rank.Get(&current))) {
		return ADE_RETURN_NIL;
	}
	if (!current.isValid()) {
		return ade_set_error(L, "i", 0);
	}

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

	return ade_set_args(L, "i", current.rank + 1); // Convert to Lua's 1 based index system
}

} // namespace api
} // namespace scripting