File: briefing.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 (148 lines) | stat: -rw-r--r-- 3,230 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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148

#include "briefing.h"
#include "team.h"

namespace scripting {
namespace api {

brief_stage_h::brief_stage_h() : br_brief(-1), br_stage(-1) {}

brief_stage_h::brief_stage_h(int brief, int stage) : br_brief(brief), br_stage(stage) {}

bool brief_stage_h::isValid() const
{
	return br_brief >= 0 && br_stage >= 0;
}

brief_stage* brief_stage_h::getStage() const
{
	return &Briefings[br_brief].stages[br_stage];
}

//**********HANDLE: briefing
ADE_OBJ(l_BriefStage, brief_stage_h, "briefing_stage", "Briefing stage handle");

ADE_VIRTVAR(Text, l_BriefStage, nullptr, "The text of the stage", "string", "The text")
{
	brief_stage_h stage;
	if (!ade_get_args(L, "o", l_BriefStage.Get(&stage))) {
		return ADE_RETURN_NIL;
	}

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

	return ade_set_args(L, "s", stage.getStage()->text);
}

ADE_VIRTVAR(AudioFilename,
	l_BriefStage,
	nullptr,
	"The filename of the audio file to play",
	"string",
	"The file name")
{
	brief_stage_h stage;
	if (!ade_get_args(L, "o", l_BriefStage.Get(&stage))) {
		return ADE_RETURN_NIL;
	}

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

	return ade_set_args(L, "s", stage.getStage()->voice);
}

ADE_VIRTVAR(hasForwardCut,
	l_BriefStage,
	nullptr,
	"If the stage has a forward cut flag",
	"boolean",
	"true if the stage is set to cut to the next stage, false otherwise")
{
	brief_stage_h stage;
	if (!ade_get_args(L, "o", l_BriefStage.Get(&stage))) {
		return ADE_RETURN_NIL;
	}

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

	if (stage.getStage()->flags & BS_FORWARD_CUT) {
		return ADE_RETURN_TRUE;
	} else {
		return ADE_RETURN_FALSE;
	}
}

ADE_VIRTVAR(hasBackwardCut,
	l_BriefStage,
	nullptr,
	"If the stage has a backward cut flag",
	"boolean",
	"true if the stage is set to cut to the previous stage, false otherwise")
{
	brief_stage_h stage;
	if (!ade_get_args(L, "o", l_BriefStage.Get(&stage))) {
		return ADE_RETURN_NIL;
	}

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

	if (stage.getStage()->flags & BS_BACKWARD_CUT) {
		return ADE_RETURN_TRUE;
	} else {
		return ADE_RETURN_FALSE;
	}
}

//**********HANDLE: briefing
ADE_OBJ_NO_MULTI(l_Brief, int, "briefing", "Briefing handle");

ADE_INDEXER(l_Brief,
	"number index",
	"The list of stages in the briefing.",
	"briefing_stage",
	"The stage at the specified location.")
{
	int briefIdx;
	int index = -1;
	if (!ade_get_args(L, "oi", l_Brief.Get(&briefIdx), &index)) {
		return ADE_RETURN_NIL;
	}

	if (briefIdx < 0)
		return ADE_RETURN_NIL;

	briefing* brief = &Briefings[briefIdx];

	--index;

	if (index < 0 || index >= brief->num_stages) {
		LuaError(L, "Invalid index %d, only have %d entries.", index + 1, brief->num_stages);
		return ADE_RETURN_NIL;
	}

	return ade_set_args(L, "o", l_BriefStage.Set(brief_stage_h(briefIdx, index)));
}

ADE_FUNC(__len, l_Brief, nullptr, "The number of stages in the briefing", "number", "The number of stages.")
{
	int brief;
	if (!ade_get_args(L, "o", l_Brief.Get(&brief))) {
		return ADE_RETURN_NIL;
	}

	if (brief < 0)
		return ADE_RETURN_NIL;

	return ade_set_args(L, "i", Briefings[brief].num_stages);
}

} // namespace api
} // namespace scripting