@@ -27,7 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
27
27
#include " server.h"
28
28
29
29
void ScriptApiEnv::environment_OnGenerated (v3s16 minp, v3s16 maxp,
30
- u32 blockseed)
30
+ u32 blockseed)
31
31
{
32
32
SCRIPTAPI_PRECHECKHEADER
33
33
@@ -44,7 +44,7 @@ void ScriptApiEnv::environment_OnGenerated(v3s16 minp, v3s16 maxp,
44
44
void ScriptApiEnv::environment_Step (float dtime)
45
45
{
46
46
SCRIPTAPI_PRECHECKHEADER
47
- // infostream<< "scriptapi_environment_step"<< std::endl;
47
+ // infostream << "scriptapi_environment_step" << std::endl;
48
48
49
49
// Get core.registered_globalsteps
50
50
lua_getglobal (L, " core" );
@@ -58,7 +58,7 @@ void ScriptApiEnv::environment_Step(float dtime)
58
58
}
59
59
}
60
60
61
- void ScriptApiEnv::player_event (ServerActiveObject* player, std::string type)
61
+ void ScriptApiEnv::player_event (ServerActiveObject * player, const std::string & type)
62
62
{
63
63
SCRIPTAPI_PRECHECKHEADER
64
64
@@ -82,7 +82,7 @@ void ScriptApiEnv::player_event(ServerActiveObject* player, std::string type)
82
82
void ScriptApiEnv::initializeEnvironment (ServerEnvironment *env)
83
83
{
84
84
SCRIPTAPI_PRECHECKHEADER
85
- verbosestream<< " scriptapi_add_environment" << std::endl;
85
+ verbosestream << " scriptapi_add_environment" << std::endl;
86
86
setEnv (env);
87
87
88
88
/*
@@ -94,68 +94,66 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env)
94
94
lua_getfield (L, -1 , " registered_abms" );
95
95
int registered_abms = lua_gettop (L);
96
96
97
- if (lua_istable (L, registered_abms)){
98
- int table = lua_gettop (L);
99
- lua_pushnil (L);
100
- while (lua_next (L, table) != 0 ){
101
- // key at index -2 and value at index -1
102
- int id = lua_tonumber (L, -2 );
103
- int current_abm = lua_gettop (L);
104
-
105
- std::set<std::string> trigger_contents;
106
- lua_getfield (L, current_abm, " nodenames" );
107
- if (lua_istable (L, -1 )){
108
- int table = lua_gettop (L);
109
- lua_pushnil (L);
110
- while (lua_next (L, table) != 0 ){
111
- // key at index -2 and value at index -1
112
- luaL_checktype (L, -1 , LUA_TSTRING);
113
- trigger_contents.insert (lua_tostring (L, -1 ));
114
- // removes value, keeps key for next iteration
115
- lua_pop (L, 1 );
116
- }
117
- } else if (lua_isstring (L, -1 )){
97
+ if (!lua_istable (L, registered_abms)) {
98
+ lua_pop (L, 1 );
99
+ throw LuaError (" core.registered_abms was not a lua table, as expected." );
100
+ }
101
+ lua_pushnil (L);
102
+ while (lua_next (L, registered_abms)) {
103
+ // key at index -2 and value at index -1
104
+ int id = lua_tonumber (L, -2 );
105
+ int current_abm = lua_gettop (L);
106
+
107
+ std::set<std::string> trigger_contents;
108
+ lua_getfield (L, current_abm, " nodenames" );
109
+ if (lua_istable (L, -1 )) {
110
+ int table = lua_gettop (L);
111
+ lua_pushnil (L);
112
+ while (lua_next (L, table)) {
113
+ // key at index -2 and value at index -1
114
+ luaL_checktype (L, -1 , LUA_TSTRING);
118
115
trigger_contents.insert (lua_tostring (L, -1 ));
116
+ // removes value, keeps key for next iteration
117
+ lua_pop (L, 1 );
119
118
}
120
- lua_pop (L, 1 );
121
-
122
- std::set<std::string> required_neighbors;
123
- lua_getfield (L, current_abm, " neighbors" );
124
- if (lua_istable (L, -1 )){
125
- int table = lua_gettop (L);
126
- lua_pushnil (L);
127
- while (lua_next (L, table) != 0 ){
128
- // key at index -2 and value at index -1
129
- luaL_checktype (L, -1 , LUA_TSTRING);
130
- required_neighbors.insert (lua_tostring (L, -1 ));
131
- // removes value, keeps key for next iteration
132
- lua_pop (L, 1 );
133
- }
134
- } else if (lua_isstring (L, -1 )){
119
+ } else if (lua_isstring (L, -1 )) {
120
+ trigger_contents.insert (lua_tostring (L, -1 ));
121
+ }
122
+ lua_pop (L, 1 );
123
+
124
+ std::set<std::string> required_neighbors;
125
+ lua_getfield (L, current_abm, " neighbors" );
126
+ if (lua_istable (L, -1 )) {
127
+ int table = lua_gettop (L);
128
+ lua_pushnil (L);
129
+ while (lua_next (L, table)) {
130
+ // key at index -2 and value at index -1
131
+ luaL_checktype (L, -1 , LUA_TSTRING);
135
132
required_neighbors.insert (lua_tostring (L, -1 ));
133
+ // removes value, keeps key for next iteration
134
+ lua_pop (L, 1 );
136
135
}
137
- lua_pop (L, 1 );
136
+ } else if (lua_isstring (L, -1 )) {
137
+ required_neighbors.insert (lua_tostring (L, -1 ));
138
+ }
139
+ lua_pop (L, 1 );
138
140
139
- float trigger_interval = 10.0 ;
140
- getfloatfield (L, current_abm, " interval" , trigger_interval);
141
+ float trigger_interval = 10.0 ;
142
+ getfloatfield (L, current_abm, " interval" , trigger_interval);
141
143
142
- int trigger_chance = 50 ;
143
- getintfield (L, current_abm, " chance" , trigger_chance);
144
+ int trigger_chance = 50 ;
145
+ getintfield (L, current_abm, " chance" , trigger_chance);
144
146
145
- bool simple_catch_up = true ;
146
- getboolfield (L, current_abm, " catch_up" , simple_catch_up);
147
+ bool simple_catch_up = true ;
148
+ getboolfield (L, current_abm, " catch_up" , simple_catch_up);
147
149
148
- LuaABM *abm = new LuaABM (L, id, trigger_contents, required_neighbors,
149
- trigger_interval, trigger_chance, simple_catch_up);
150
+ LuaABM *abm = new LuaABM (L, id, trigger_contents, required_neighbors,
151
+ trigger_interval, trigger_chance, simple_catch_up);
150
152
151
- env->addActiveBlockModifier (abm);
153
+ env->addActiveBlockModifier (abm);
152
154
153
- // removes value, keeps key for next iteration
154
- lua_pop (L, 1 );
155
- }
156
- } else {
155
+ // removes value, keeps key for next iteration
157
156
lua_pop (L, 1 );
158
- throw LuaError (" core.registered_abms was not a lua table, as expected." );
159
157
}
160
158
lua_pop (L, 1 );
161
159
0 commit comments