forked from pioneerspacesim/pioneer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LuaComms.cpp
118 lines (103 loc) · 2.36 KB
/
LuaComms.cpp
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
// Copyright © 2008-2018 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
#include "LuaComms.h"
#include "LuaObject.h"
#include "LuaUtils.h"
#include "Pi.h"
#include "ShipCpanel.h"
#include "GameLog.h"
/*
* Interface: Comms
*
* Player communication functions.
*/
/*
* Function: Message
*
* Post a message to the player's control panel.
*
* > Comms.Message(message, from)
*
* Parameters:
*
* message - the message text to post
*
* from - optional; who the message is from (person, ship, etc)
*
* Example:
*
* > Comms.Message("Please repair my ship.", "Gary Jones")
*
* Availability:
*
* alpha 10
*
* Status:
*
* experimental
*/
static int l_comms_message(lua_State *l)
{
if (!Pi::game || !Pi::game->GetCpan())
luaL_error(l, "Control panel does not exist.");
std::string msg = luaL_checkstring(l, 1);
std::string from;
if (lua_gettop(l) >= 2)
from = luaL_checkstring(l, 2);
Pi::game->log->Add(from, msg, GameLog::Priority::PRIORITY_NORMAL);
return 0;
}
/*
* Function: ImportantMessage
*
* Post an important message to the player's control panel.
*
* > Comms.ImportantMessage(message, from)
*
* The only difference between this and <Message> is that if multiple messages
* arrive at the same time, the important ones will be shown first.
*
* Parameters:
*
* message - the message text to post
*
* from - optional; who the message is from (person, ship, etc)
*
* Example:
*
* > Comms.ImportantMessage("Prepare to die!", "AB-1234")
*
* Availability:
*
* alpha 10
*
* Status:
*
* experimental
*/
static int l_comms_important_message(lua_State *l)
{
if (!Pi::game || !Pi::game->GetCpan())
luaL_error(l, "Control panel does not exist.");
std::string msg = luaL_checkstring(l, 1);
std::string from;
if (lua_gettop(l) >= 2)
from = luaL_checkstring(l, 2);
Pi::game->log->Add(from, msg, GameLog::Priority::PRIORITY_ALERT);
return 0;
}
void LuaComms::Register()
{
lua_State *l = Lua::manager->GetLuaState();
LUA_DEBUG_START(l);
static const luaL_Reg l_methods[] = {
{ "Message", l_comms_message },
{ "ImportantMessage", l_comms_important_message },
{ 0, 0 }
};
lua_getfield(l, LUA_REGISTRYINDEX, "CoreImports");
LuaObjectBase::CreateObject(l_methods, 0, 0);
lua_setfield(l, -2, "Comms");
lua_pop(l, 1);
LUA_DEBUG_END(l, 0);
}