1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #include "common/lua/lauxlib.h"
24 
25 #include "ultima/nuvie/actors/actor.h"
26 #include "ultima/nuvie/core/nuvie_defs.h"
27 #include "ultima/nuvie/misc/u6_misc.h"
28 #include "ultima/nuvie/script/script_actor.h"
29 #include "ultima/nuvie/core/player.h"
30 #include "ultima/nuvie/core/game.h"
31 #include "ultima/nuvie/core/effect.h"
32 #include "ultima/nuvie/actors/actor_manager.h"
33 #include "ultima/nuvie/actors/actor.h"
34 #include "ultima/nuvie/views/view_manager.h"
35 #include "ultima/nuvie/core/converse.h"
36 #include "ultima/nuvie/usecode/usecode.h"
37 #include "ultima/nuvie/views/portrait_view.h"
38 
39 namespace Ultima {
40 namespace Nuvie {
41 
42 ///
43 //@module script
44 
45 /***
46 An Actor object
47 @table Actor
48 @string[readonly] luatype This returns "actor"
49 @int[readonly] actor_num
50 @int align alignment
51 
52 - 0 = DEFAULT
53 - 1 = NEUTRAL
54 - 2 = EVIL
55 - 3 = GOOD
56 - 4 = CHAOTIC
57 
58 @bool[readonly] alive
59 @bool asleep
60 @int base_obj_n
61 @bool charmed
62 @bool cold (MD) bit 0 on the status flags. Set when the actor is cold.
63 @int combat_mode
64 @bool corpser_flag (U6) Has the actor been dragged underground by a corpser
65 @bool cursed
66 @int dex dexterity
67 @int direction The direction that the actor is facing.
68 
69 - 0 = NORTH
70 - 1 = EAST
71 - 2 = SOUTH
72 - 3 = WEST
73 - 4 = NORTHEAST
74 - 5 = SOUTHEAST
75 - 6 = SOUTHWEST
76 - 7 = NORTHWEST
77 - 8 = NONE
78 
79 @int exp experience
80 @int frame_n
81 @bool frenzy (MD) battle frenzy
82 @bool hit_flag Used by U6 to determine if an actor has been hit.
83 @int hp hit points
84 @bool hypoxia (MD) bit 6 on the obj flags. Tells if the actor is oxygen deprived
85 @bool[readonly] in_party Is the actor a mamber of the party?
86 @bool[readonly] in_vehicle Is the actor currently in a vehicle?
87 @int int intelligence
88 @int level
89 @int magic
90 @int[readonly] max_hp
91 @int mpts movement points
92 @string[readonly] name
93 @bool obj_flag_0 obj flag 0
94 @int obj_n
95 @int old_align Old alignment
96 @int[readonly] old_frame_n
97 @bool paralyzed
98 @bool poisoned
99 @bool protected
100 @int[readonly] sched_loc The location defined for the Actor's currently active schedule entry.
101 @int[readonly] sched_wt The worktype of the currently active schedule.
102 @int str strength
103 @bool[readonly] temp Is this a temporary actor?
104 @int[readonly] tile_num The tile number based on the obj_n + frame_n combination.
105 @bool visible Is the actor currently visible?
106 @int wt worktype
107 @field[readonly] xyz table containing location
108 
109  table format
110 ```
111 {["x"]=x, ["y"]=y, ["z"]=z}
112 ```
113 @int x
114 @int y
115 @int z
116 
117 */
118 
119 extern bool nscript_get_location_from_args(lua_State *L, uint16 *x, uint16 *y, uint8 *z, int lua_stack_offset = 1);
120 extern Obj *nscript_get_obj_from_args(lua_State *L, int lua_stack_offset);
121 extern void nscript_new_obj_var(lua_State *L, Obj *obj);
122 extern int nscript_obj_new(lua_State *L, Obj *obj);
123 extern int nscript_u6llist_iter(lua_State *L);
124 extern int nscript_init_u6link_iter(lua_State *L, U6LList *list, bool is_recursive);
125 
126 bool nscript_new_actor_var(lua_State *L, uint16 actor_num);
127 
128 static int nscript_actor_new(lua_State *L);
129 static int nscript_actor_clone(lua_State *L);
130 static int nscript_get_actor_from_num(lua_State *L);
131 
132 Actor *nscript_get_actor_from_args(lua_State *L, int lua_stack_offset = 1);
133 static int nscript_actor_set(lua_State *L);
134 static int nscript_actor_get(lua_State *L);
135 static int nscript_get_player_actor(lua_State *L);
136 static int nscript_actor_kill(lua_State *L);
137 static int nscript_actor_hit(lua_State *L);
138 static int nscript_actor_get_range(lua_State *L);
139 static int nscript_actor_resurrect(lua_State *L);
140 static int nscript_actor_inv_add_obj(lua_State *L);
141 static int nscript_actor_inv_remove_obj(lua_State *L);
142 static int nscript_actor_inv_remove_obj_qty(lua_State *L);
143 static int nscript_actor_inv_get_readied_obj_n(lua_State *L);
144 static int nscript_actor_inv_ready_obj(lua_State *L);
145 static int nscript_actor_inv_unready_obj(lua_State *L);
146 static int nscript_actor_inv_has_obj_n(lua_State *L);
147 static int nscript_actor_inv_get_obj_n(lua_State *L);
148 static int nscript_actor_inv_get_obj_total_qty(lua_State *L);
149 static int nscript_actor_move(lua_State *L);
150 static int nscript_actor_walk_path(lua_State *L);
151 static int nscript_actor_is_at_scheduled_location(lua_State *L);
152 static int nscript_actor_can_carry_obj(lua_State *L);
153 static int nscript_actor_can_carry_obj_weight(lua_State *L);
154 static int nscript_actor_black_fade_effect(lua_State *L);
155 static int nscript_actor_fade_out_effect(lua_State *L);
156 static int nscript_actor_show_portrait(lua_State *L);
157 static int nscript_actor_hide_portrait(lua_State *L);
158 static int nscript_actor_talk(lua_State *L);
159 static int nscript_actor_unlink_surrounding_objs(lua_State *L);
160 static int nscript_actor_use(lua_State *L);
161 static int nscript_actor_get_talk_flag(lua_State *L);
162 static int nscript_actor_set_talk_flag(lua_State *L);
163 static int nscript_actor_clear_talk_flag(lua_State *L);
164 static int nscript_actor_get_number_of_schedules(lua_State *L);
165 static int nscript_actor_get_schedule(lua_State *L);
166 
167 static const struct luaL_Reg nscript_actorlib_f[] = {
168 	{ "new", nscript_actor_new },
169 	{ "clone", nscript_actor_clone },
170 	{ "kill", nscript_actor_kill },
171 	{ "hit", nscript_actor_hit },
172 	{ "get_range", nscript_actor_get_range },
173 	{ "resurrect", nscript_actor_resurrect },
174 	{ "move", nscript_actor_move },
175 	{ "walk_path", nscript_actor_walk_path },
176 	{ "get", nscript_get_actor_from_num },
177 	{ "get_player_actor", nscript_get_player_actor },
178 	{ "inv_add_obj", nscript_actor_inv_add_obj },
179 	{ "inv_remove_obj", nscript_actor_inv_remove_obj },
180 	{ "inv_remove_obj_qty", nscript_actor_inv_remove_obj_qty },
181 	{ "inv_get_readied_obj_n", nscript_actor_inv_get_readied_obj_n },
182 	{ "inv_ready_obj", nscript_actor_inv_ready_obj },
183 	{ "inv_unready_obj", nscript_actor_inv_unready_obj },
184 	{ "inv_has_obj_n", nscript_actor_inv_has_obj_n },
185 	{ "inv_get_obj_n", nscript_actor_inv_get_obj_n },
186 	{ "inv_get_obj_total_qty", nscript_actor_inv_get_obj_total_qty },
187 	{ "is_at_scheduled_location", nscript_actor_is_at_scheduled_location },
188 	{ "can_carry_obj", nscript_actor_can_carry_obj },
189 	{ "can_carry_obj_weight", nscript_actor_can_carry_obj_weight },
190 	{ "black_fade_effect", nscript_actor_black_fade_effect },
191 	{ "fade_out", nscript_actor_fade_out_effect },
192 	{ "show_portrait", nscript_actor_show_portrait },
193 	{ "hide_portrait", nscript_actor_hide_portrait },
194 	{ "talk", nscript_actor_talk },
195 	{ "unlink_surrounding_objs", nscript_actor_unlink_surrounding_objs },
196 	{ "use", nscript_actor_use },
197 	{ "get_talk_flag", nscript_actor_get_talk_flag },
198 	{ "set_talk_flag", nscript_actor_set_talk_flag },
199 	{ "clear_talk_flag", nscript_actor_clear_talk_flag },
200 	{ "get_number_of_schedules", nscript_actor_get_number_of_schedules },
201 	{ "get_schedule", nscript_actor_get_schedule },
202 
203 	{ NULL, NULL }
204 };
205 static const struct luaL_Reg nscript_actorlib_m[] = {
206 	{ "__index", nscript_actor_get },
207 	{ "__newindex", nscript_actor_set },
208 	{ NULL, NULL }
209 };
210 
211 
212 //Actor variables - must be in alphabetical order
213 static const char *actor_set_vars[] = {
214 	"align",
215 	"asleep",
216 	"base_obj_n",
217 	"charmed",
218 	"cold",
219 	"combat_mode",
220 	"corpser_flag",
221 	"cursed",
222 	"dex",
223 	"direction",
224 	"exp",
225 	"frame_n",
226 	"frenzy",
227 	"hit_flag",
228 	"hp",
229 	"hypoxia",
230 	"int",
231 	"level",
232 	"magic",
233 	"mpts",
234 	"obj_flag_0",
235 	"obj_n",
236 	"old_align",
237 	"paralyzed",
238 	"poisoned",
239 	"protected",
240 	"str",
241 	"visible",
242 	"wt",
243 	"x",
244 	"y",
245 	"z"
246 };
247 
248 //Actor variables - must be in alphabetical order
249 static const char *actor_get_vars[] = {
250 	"actor_num",
251 	"align",
252 	"alive",
253 	"asleep",
254 	"base_obj_n",
255 	"charmed",
256 	"cold",
257 	"combat_mode",
258 	"corpser_flag",
259 	"cursed",
260 	"dex",
261 	"direction",
262 	"exp",
263 	"frame_n",
264 	"frenzy",
265 	"hit_flag",
266 	"hp",
267 	"hypoxia",
268 	"in_party",
269 	"in_vehicle",
270 	"int",
271 	"level",
272 	"luatype",
273 	"magic",
274 	"max_hp",
275 	"mpts",
276 	"name",
277 	"obj_flag_0",
278 	"obj_n",
279 	"old_align",
280 	"old_frame_n",
281 	"paralyzed",
282 	"poisoned",
283 	"protected",
284 	"sched_loc",
285 	"sched_wt",
286 	"str",
287 	"temp",
288 	"tile_num",
289 	"visible",
290 	"wt",
291 	"x",
292 	"xyz",
293 	"y",
294 	"z"
295 };
296 
297 //Actor set
298 static int nscript_actor_set_align(Actor *actor, lua_State *L);
299 static int nscript_actor_set_asleep_flag(Actor *actor, lua_State *L);
300 static int nscript_actor_set_base_obj_n(Actor *actor, lua_State *L);
301 static int nscript_actor_set_charmed_flag(Actor *actor, lua_State *L);
302 static int nscript_actor_set_cold_flag(Actor *actor, lua_State *L);
303 static int nscript_actor_set_combat_mode(Actor *actor, lua_State *L);
304 static int nscript_actor_set_corpser_flag(Actor *actor, lua_State *L);
305 static int nscript_actor_set_cursed_flag(Actor *actor, lua_State *L);
306 static int nscript_actor_set_dexterity(Actor *actor, lua_State *L);
307 static int nscript_actor_set_direction(Actor *actor, lua_State *L);
308 static int nscript_actor_set_exp(Actor *actor, lua_State *L);
309 static int nscript_actor_set_frame_n(Actor *actor, lua_State *L);
310 static int nscript_actor_set_frenzy(Actor *actor, lua_State *L);
311 static int nscript_actor_set_hit(Actor *actor, lua_State *L);
312 static int nscript_actor_set_hp(Actor *actor, lua_State *L);
313 static int nscript_actor_set_hypoxia(Actor *actor, lua_State *L);
314 static int nscript_actor_set_intelligence(Actor *actor, lua_State *L);
315 static int nscript_actor_set_level(Actor *actor, lua_State *L);
316 static int nscript_actor_set_magic(Actor *actor, lua_State *L);
317 static int nscript_actor_set_movement_pts(Actor *actor, lua_State *L);
318 static int nscript_actor_set_obj_flag_0(Actor *actor, lua_State *L);
319 static int nscript_actor_set_obj_n(Actor *actor, lua_State *L);
320 static int nscript_actor_set_old_align(Actor *actor, lua_State *L);
321 static int nscript_actor_set_paralyzed_flag(Actor *actor, lua_State *L);
322 static int nscript_actor_set_poisoned_flag(Actor *actor, lua_State *L);
323 static int nscript_actor_set_protected_flag(Actor *actor, lua_State *L);
324 static int nscript_actor_set_strength(Actor *actor, lua_State *L);
325 static int nscript_actor_set_visible_flag(Actor *actor, lua_State *L);
326 static int nscript_actor_set_worktype(Actor *actor, lua_State *L);
327 static int nscript_actor_set_x(Actor *actor, lua_State *L);
328 static int nscript_actor_set_y(Actor *actor, lua_State *L);
329 static int nscript_actor_set_z(Actor *actor, lua_State *L);
330 
331 int (*actor_set_func[])(Actor *, lua_State *) = {
332 	nscript_actor_set_align,
333 	nscript_actor_set_asleep_flag,
334 	nscript_actor_set_base_obj_n,
335 	nscript_actor_set_charmed_flag,
336 	nscript_actor_set_cold_flag,
337 	nscript_actor_set_combat_mode,
338 	nscript_actor_set_corpser_flag,
339 	nscript_actor_set_cursed_flag,
340 	nscript_actor_set_dexterity,
341 	nscript_actor_set_direction,
342 	nscript_actor_set_exp,
343 	nscript_actor_set_frame_n,
344 	nscript_actor_set_frenzy,
345 	nscript_actor_set_hit,
346 	nscript_actor_set_hp,
347 	nscript_actor_set_hypoxia,
348 	nscript_actor_set_intelligence,
349 	nscript_actor_set_level,
350 	nscript_actor_set_magic,
351 	nscript_actor_set_movement_pts,
352 	nscript_actor_set_obj_flag_0,
353 	nscript_actor_set_obj_n,
354 	nscript_actor_set_old_align,
355 	nscript_actor_set_paralyzed_flag,
356 	nscript_actor_set_poisoned_flag,
357 	nscript_actor_set_protected_flag,
358 	nscript_actor_set_strength,
359 	nscript_actor_set_visible_flag,
360 	nscript_actor_set_worktype,
361 	nscript_actor_set_x,
362 	nscript_actor_set_y,
363 	nscript_actor_set_z
364 };
365 
366 //Actor get
367 static int nscript_actor_get_actor_num(Actor *actor, lua_State *L);
368 static int nscript_actor_get_align(Actor *actor, lua_State *L);
369 static int nscript_actor_get_alive(Actor *actor, lua_State *L);
370 static int nscript_actor_get_asleep_flag(Actor *actor, lua_State *L);
371 static int nscript_actor_get_base_obj_n(Actor *actor, lua_State *L);
372 static int nscript_actor_get_charmed_flag(Actor *actor, lua_State *L);
373 static int nscript_actor_get_cold_flag(Actor *actor, lua_State *L);
374 static int nscript_actor_get_combat_mode(Actor *actor, lua_State *L);
375 static int nscript_actor_get_corpser_flag(Actor *actor, lua_State *L);
376 static int nscript_actor_get_cursed_flag(Actor *actor, lua_State *L);
377 static int nscript_actor_get_dexterity(Actor *actor, lua_State *L);
378 static int nscript_actor_get_direction(Actor *actor, lua_State *L);
379 static int nscript_actor_get_exp(Actor *actor, lua_State *L);
380 static int nscript_actor_get_frame_n(Actor *actor, lua_State *L);
381 static int nscript_actor_get_frenzy(Actor *actor, lua_State *L);
382 static int nscript_actor_get_hit_flag(Actor *actor, lua_State *L);
383 static int nscript_actor_get_hp(Actor *actor, lua_State *L);
384 static int nscript_actor_get_hypoxia(Actor *actor, lua_State *L);
385 static int nscript_actor_get_in_party_status(Actor *actor, lua_State *L);
386 static int nscript_actor_get_in_vehicle(Actor *actor, lua_State *L);
387 static int nscript_actor_get_intelligence(Actor *actor, lua_State *L);
388 static int nscript_actor_get_level(Actor *actor, lua_State *L);
389 static int nscript_actor_get_luatype(Actor *actor, lua_State *L);
390 static int nscript_actor_get_magic(Actor *actor, lua_State *L);
391 static int nscript_actor_get_max_hp(Actor *actor, lua_State *L);
392 static int nscript_actor_get_movement_pts(Actor *actor, lua_State *L);
393 static int nscript_actor_get_name(Actor *actor, lua_State *L);
394 static int nscript_actor_get_obj_flag_0(Actor *actor, lua_State *L);
395 static int nscript_actor_get_obj_n(Actor *actor, lua_State *L);
396 static int nscript_actor_get_old_align(Actor *actor, lua_State *L);
397 static int nscript_actor_get_old_frame_n(Actor *actor, lua_State *L);
398 static int nscript_actor_get_paralyzed_flag(Actor *actor, lua_State *L);
399 static int nscript_actor_get_poisoned_flag(Actor *actor, lua_State *L);
400 static int nscript_actor_get_protected_flag(Actor *actor, lua_State *L);
401 static int nscript_actor_get_sched_loc(Actor *actor, lua_State *L);
402 static int nscript_actor_get_sched_worktype(Actor *actor, lua_State *L);
403 static int nscript_actor_get_strength(Actor *actor, lua_State *L);
404 static int nscript_actor_get_temp_status(Actor *actor, lua_State *L);
405 static int nscript_actor_get_tile_num(Actor *actor, lua_State *L);
406 static int nscript_actor_get_visible_flag(Actor *actor, lua_State *L);
407 static int nscript_actor_get_worktype(Actor *actor, lua_State *L);
408 static int nscript_actor_get_x(Actor *actor, lua_State *L);
409 static int nscript_actor_get_xyz(Actor *actor, lua_State *L);
410 static int nscript_actor_get_y(Actor *actor, lua_State *L);
411 static int nscript_actor_get_z(Actor *actor, lua_State *L);
412 
413 int (*actor_get_func[])(Actor *, lua_State *) = {
414 	nscript_actor_get_actor_num,
415 	nscript_actor_get_align,
416 	nscript_actor_get_alive,
417 	nscript_actor_get_asleep_flag,
418 	nscript_actor_get_base_obj_n,
419 	nscript_actor_get_charmed_flag,
420 	nscript_actor_get_cold_flag,
421 	nscript_actor_get_combat_mode,
422 	nscript_actor_get_corpser_flag,
423 	nscript_actor_get_cursed_flag,
424 	nscript_actor_get_dexterity,
425 	nscript_actor_get_direction,
426 	nscript_actor_get_exp,
427 	nscript_actor_get_frame_n,
428 	nscript_actor_get_frenzy,
429 	nscript_actor_get_hit_flag,
430 	nscript_actor_get_hp,
431 	nscript_actor_get_hypoxia,
432 	nscript_actor_get_in_party_status,
433 	nscript_actor_get_in_vehicle,
434 	nscript_actor_get_intelligence,
435 	nscript_actor_get_level,
436 	nscript_actor_get_luatype,
437 	nscript_actor_get_magic,
438 	nscript_actor_get_max_hp,
439 	nscript_actor_get_movement_pts,
440 	nscript_actor_get_name,
441 	nscript_actor_get_obj_flag_0,
442 	nscript_actor_get_obj_n,
443 	nscript_actor_get_old_align,
444 	nscript_actor_get_old_frame_n,
445 	nscript_actor_get_paralyzed_flag,
446 	nscript_actor_get_poisoned_flag,
447 	nscript_actor_get_protected_flag,
448 	nscript_actor_get_sched_loc,
449 	nscript_actor_get_sched_worktype,
450 	nscript_actor_get_strength,
451 	nscript_actor_get_temp_status,
452 	nscript_actor_get_tile_num,
453 	nscript_actor_get_visible_flag,
454 	nscript_actor_get_worktype,
455 	nscript_actor_get_x,
456 	nscript_actor_get_xyz,
457 	nscript_actor_get_y,
458 	nscript_actor_get_z
459 };
460 
461 
462 static int nscript_map_get_actor(lua_State *L);
463 static int nscript_update_actor_schedules(lua_State *L);
464 
465 static int nscript_actor_inv(lua_State *L);
466 
nscript_init_actor(lua_State * L)467 void nscript_init_actor(lua_State *L) {
468 	luaL_newmetatable(L, "nuvie.Actor");
469 
470 	luaL_register(L, NULL, nscript_actorlib_m);
471 
472 	luaL_register(L, "Actor", nscript_actorlib_f);
473 
474 	lua_pushcfunction(L, nscript_map_get_actor);
475 	lua_setglobal(L, "map_get_actor");
476 
477 	lua_pushcfunction(L, nscript_update_actor_schedules);
478 	lua_setglobal(L, "update_actor_schedules");
479 
480 	lua_pushcfunction(L, nscript_actor_inv);
481 	lua_setglobal(L, "actor_inventory");
482 }
483 
nscript_new_actor_var(lua_State * L,uint16 actor_num)484 bool nscript_new_actor_var(lua_State *L, uint16 actor_num) {
485 	uint16 *userdata;
486 
487 	userdata = (uint16 *)lua_newuserdata(L, sizeof(uint16));
488 
489 	luaL_getmetatable(L, "nuvie.Actor");
490 	lua_setmetatable(L, -2);
491 
492 	*userdata = actor_num;
493 
494 	return true;
495 }
496 
497 /***
498 Create a new temporary Actor.
499 @function Actor.new
500 @int obj_n
501 @int[opt=0] x
502 @int[opt=0] y
503 @int[opt=0] z
504 @int[opt=NEUTRAL] alignment
505 @int[opt=8] worktype
506 @treturn Actor|nil
507 @within Actor
508  */
nscript_actor_new(lua_State * L)509 static int nscript_actor_new(lua_State *L) {
510 	Actor *actor;
511 	uint16 obj_n = 0;
512 	uint16 x = 0;
513 	uint16 y = 0;
514 	uint8 z = 0;
515 	uint8 alignment = ACTOR_ALIGNMENT_NEUTRAL;
516 	uint8 worktype = ACTOR_WT_ASSAULT; //FIXME this may be U6 specific.
517 
518 	int nargs = lua_gettop(L);
519 
520 	if (nargs > 1) { // do we have arguments?
521 		uint8 i = nargs;
522 
523 		if (i) {
524 			if (!lua_isnil(L, 1))
525 				obj_n = (uint16)lua_tointeger(L, 1);
526 			i--;
527 		}
528 
529 		if (i) {
530 			if (!lua_isnil(L, 2))
531 				x = (uint16)lua_tointeger(L, 2);
532 			i--;
533 		}
534 
535 		if (i) {
536 			if (!lua_isnil(L, 3))
537 				y = (uint16)lua_tointeger(L, 3);
538 			i--;
539 		}
540 
541 		if (i) {
542 			if (!lua_isnil(L, 4))
543 				z = (uint8)lua_tointeger(L, 4);
544 			i--;
545 		}
546 
547 		if (i) {
548 			if (!lua_isnil(L, 5))
549 				alignment = (uint8)lua_tointeger(L, 5);
550 			i--;
551 		}
552 
553 		if (i) {
554 			if (!lua_isnil(L, 6))
555 				worktype = (uint8)lua_tointeger(L, 6);
556 			i--;
557 		}
558 
559 		//init here.
560 		if (Game::get_game()->get_actor_manager()->create_temp_actor(obj_n, NO_OBJ_STATUS, x, y, z, alignment, worktype, &actor) == false)
561 			return 0;
562 
563 		//create the new lua Actor variable
564 		if (nscript_new_actor_var(L, actor->get_actor_num()) == false)
565 			return 0;
566 	}
567 
568 	return 1;
569 }
570 
571 /***
572 Clone an actor as a new temporary actor.
573 @function Actor.clone
574 @tparam Actor actor Actor to clone
575 @tparam MapCoord|x,y,z location Location to place newly cloned actor.
576 @within Actor
577  */
nscript_actor_clone(lua_State * L)578 static int nscript_actor_clone(lua_State *L) {
579 	Actor *actor, *new_actor;
580 	uint16 x, y;
581 	uint8 z;
582 
583 	actor = nscript_get_actor_from_args(L);
584 	if (actor == NULL)
585 		return 0;
586 
587 	if (nscript_get_location_from_args(L, &x, &y, &z, 2) == false)
588 		return 0;
589 
590 	int stack_offset = lua_istable(L, 2) ? 3 : 5;
591 
592 	if (lua_gettop(L) >= stack_offset) {
593 		//FIXME clone into existing actor here.
594 	}
595 	if (Game::get_game()->get_actor_manager()->clone_actor(actor, &new_actor, MapCoord(x, y, z))) {
596 		if (nscript_new_actor_var(L, actor->get_actor_num()) == true)
597 			return 1;
598 	}
599 
600 	return 0;
601 }
602 
603 /***
604 Get an Actor object from an actor number
605 @function Actor.get
606 @int actor_number
607 @treturn Actor
608 @within Actor
609  */
nscript_get_actor_from_num(lua_State * L)610 static int nscript_get_actor_from_num(lua_State *L) {
611 	uint16 actor_num;
612 	actor_num = (uint16)lua_tointeger(L, 1);
613 
614 	assert(actor_num < ACTORMANAGER_MAX_ACTORS);
615 	nscript_new_actor_var(L, actor_num);
616 
617 	return 1;
618 }
619 
nscript_get_actor_from_args(lua_State * L,int lua_stack_offset)620 Actor *nscript_get_actor_from_args(lua_State *L, int lua_stack_offset) {
621 	Actor *actor = NULL;
622 
623 	if (lua_isuserdata(L, lua_stack_offset)) {
624 		uint16 *actor_num = (uint16 *)luaL_checkudata(L, lua_stack_offset, "nuvie.Actor");
625 		if (actor_num != NULL)
626 			actor = Game::get_game()->get_actor_manager()->get_actor(*actor_num);
627 	} else {
628 		actor = Game::get_game()->get_actor_manager()->get_actor((uint16)lua_tointeger(L, lua_stack_offset));
629 	}
630 
631 	return actor;
632 }
633 
634 /***
635 Get the current player Actor object
636 @function Actor.get_player_actor
637 @treturn Actor
638 @within Actor
639  */
nscript_get_player_actor(lua_State * L)640 static int nscript_get_player_actor(lua_State *L) {
641 	Actor *player_actor = Game::get_game()->get_player()->get_actor();
642 
643 	nscript_new_actor_var(L, player_actor->get_actor_num());
644 	return 1;
645 }
646 
nscript_actor_set(lua_State * L)647 static int nscript_actor_set(lua_State *L) {
648 	Actor *actor;
649 	const char *key;
650 
651 	actor = nscript_get_actor_from_args(L);
652 	if (actor == NULL)
653 		return 0;
654 
655 	key = lua_tostring(L, 2);
656 
657 	int idx = str_bsearch(actor_set_vars, sizeof(actor_set_vars) / sizeof(actor_set_vars[0]), (const char *)key);
658 	if (idx == -1)
659 		return 0;
660 
661 	(*actor_set_func[idx])(actor, L);
662 
663 	return 0;
664 }
665 
nscript_actor_set_align(Actor * actor,lua_State * L)666 static int nscript_actor_set_align(Actor *actor, lua_State *L) {
667 	actor->set_alignment((uint8)lua_tointeger(L, 3));
668 	return 0;
669 }
670 
nscript_actor_set_asleep_flag(Actor * actor,lua_State * L)671 static int nscript_actor_set_asleep_flag(Actor *actor, lua_State *L) {
672 	actor->set_asleep(lua_toboolean(L, 3));
673 	return 0;
674 }
675 
nscript_actor_set_charmed_flag(Actor * actor,lua_State * L)676 static int nscript_actor_set_charmed_flag(Actor *actor, lua_State *L) {
677 	actor->set_charmed(lua_toboolean(L, 3));
678 	return 0;
679 }
680 
nscript_actor_set_cold_flag(Actor * actor,lua_State * L)681 static int nscript_actor_set_cold_flag(Actor *actor, lua_State *L) {
682 	actor->set_status_flag(ACTOR_MD_STATUS_FLAG_COLD, lua_toboolean(L, 3));
683 	return 0;
684 }
685 
nscript_actor_set_combat_mode(Actor * actor,lua_State * L)686 static int nscript_actor_set_combat_mode(Actor *actor, lua_State *L) {
687 	actor->set_combat_mode((uint8)lua_tointeger(L, 3));
688 	return 0;
689 }
690 
nscript_actor_set_corpser_flag(Actor * actor,lua_State * L)691 static int nscript_actor_set_corpser_flag(Actor *actor, lua_State *L) {
692 	actor->set_corpser_flag(lua_toboolean(L, 3));
693 	return 0;
694 }
695 
nscript_actor_set_cursed_flag(Actor * actor,lua_State * L)696 static int nscript_actor_set_cursed_flag(Actor *actor, lua_State *L) {
697 	actor->set_cursed(lua_toboolean(L, 3));
698 	return 0;
699 }
700 
nscript_actor_set_dexterity(Actor * actor,lua_State * L)701 static int nscript_actor_set_dexterity(Actor *actor, lua_State *L) {
702 	actor->set_dexterity((uint8)lua_tointeger(L, 3));
703 	return 0;
704 }
705 
nscript_actor_set_direction(Actor * actor,lua_State * L)706 static int nscript_actor_set_direction(Actor *actor, lua_State *L) {
707 	actor->set_direction((uint8)lua_tointeger(L, 3));
708 	return 0;
709 }
710 
nscript_actor_set_exp(Actor * actor,lua_State * L)711 static int nscript_actor_set_exp(Actor *actor, lua_State *L) {
712 	actor->set_exp((uint16)lua_tointeger(L, 3));
713 	return 0;
714 }
715 
nscript_actor_set_frame_n(Actor * actor,lua_State * L)716 static int nscript_actor_set_frame_n(Actor *actor, lua_State *L) {
717 	actor->set_frame_n((uint16)lua_tointeger(L, 3));
718 	return 0;
719 }
720 
nscript_actor_set_frenzy(Actor * actor,lua_State * L)721 static int nscript_actor_set_frenzy(Actor *actor, lua_State *L) {
722 	actor->set_obj_flag(ACTOR_MD_OBJ_FLAG_FRENZY, lua_toboolean(L, 3));
723 	return 0;
724 }
725 
nscript_actor_set_hp(Actor * actor,lua_State * L)726 static int nscript_actor_set_hp(Actor *actor, lua_State *L) {
727 	actor->set_hp((uint8)lua_tointeger(L, 3));
728 	return 0;
729 }
730 
nscript_actor_set_hypoxia(Actor * actor,lua_State * L)731 static int nscript_actor_set_hypoxia(Actor *actor, lua_State *L) {
732 	actor->set_obj_flag(ACTOR_MD_OBJ_FLAG_HYPOXIA, lua_toboolean(L, 3)); //MD uses object bit 6 which is cursed in U6.
733 	return 0;
734 }
735 
nscript_actor_set_hit(Actor * actor,lua_State * L)736 static int nscript_actor_set_hit(Actor *actor, lua_State *L) {
737 	actor->set_hit_flag(lua_toboolean(L, 3));
738 	return 0;
739 }
740 
nscript_actor_set_intelligence(Actor * actor,lua_State * L)741 static int nscript_actor_set_intelligence(Actor *actor, lua_State *L) {
742 	actor->set_intelligence((uint8)lua_tointeger(L, 3));
743 	return 0;
744 }
745 
nscript_actor_set_level(Actor * actor,lua_State * L)746 static int nscript_actor_set_level(Actor *actor, lua_State *L) {
747 	actor->set_level((uint8)lua_tointeger(L, 3));
748 	return 0;
749 }
750 
nscript_actor_set_magic(Actor * actor,lua_State * L)751 static int nscript_actor_set_magic(Actor *actor, lua_State *L) {
752 	actor->set_magic((uint8)lua_tointeger(L, 3));
753 	return 0;
754 }
755 
nscript_actor_set_movement_pts(Actor * actor,lua_State * L)756 static int nscript_actor_set_movement_pts(Actor *actor, lua_State *L) {
757 	actor->set_moves_left((sint8)lua_tointeger(L, 3));
758 	return 0;
759 }
760 
nscript_actor_set_obj_flag_0(Actor * actor,lua_State * L)761 static int nscript_actor_set_obj_flag_0(Actor *actor, lua_State *L) {
762 	actor->set_obj_flag(0, (bool)lua_toboolean(L, 3));
763 	return 0;
764 }
765 
nscript_actor_set_obj_n(Actor * actor,lua_State * L)766 static int nscript_actor_set_obj_n(Actor *actor, lua_State *L) {
767 	actor->set_obj_n((uint16)lua_tointeger(L, 3));
768 	return 0;
769 }
770 
nscript_actor_set_old_align(Actor * actor,lua_State * L)771 static int nscript_actor_set_old_align(Actor *actor, lua_State *L) {
772 	actor->set_old_alignment((sint8)lua_tointeger(L, 3));
773 	return 0;
774 }
775 
nscript_actor_set_base_obj_n(Actor * actor,lua_State * L)776 static int nscript_actor_set_base_obj_n(Actor *actor, lua_State *L) {
777 	actor->change_base_obj_n((uint16)lua_tointeger(L, 3));
778 	return 0;
779 }
780 
nscript_actor_set_paralyzed_flag(Actor * actor,lua_State * L)781 static int nscript_actor_set_paralyzed_flag(Actor *actor, lua_State *L) {
782 	actor->set_paralyzed((bool)lua_toboolean(L, 3));
783 	return 0;
784 }
785 
nscript_actor_set_poisoned_flag(Actor * actor,lua_State * L)786 static int nscript_actor_set_poisoned_flag(Actor *actor, lua_State *L) {
787 	actor->set_poisoned(lua_toboolean(L, 3));
788 	return 0;
789 }
790 
nscript_actor_set_protected_flag(Actor * actor,lua_State * L)791 static int nscript_actor_set_protected_flag(Actor *actor, lua_State *L) {
792 	actor->set_protected(lua_toboolean(L, 3));
793 	return 0;
794 }
795 
nscript_actor_set_strength(Actor * actor,lua_State * L)796 static int nscript_actor_set_strength(Actor *actor, lua_State *L) {
797 	actor->set_strength((uint8)lua_tointeger(L, 3));
798 	return 0;
799 }
800 
nscript_actor_set_visible_flag(Actor * actor,lua_State * L)801 static int nscript_actor_set_visible_flag(Actor *actor, lua_State *L) {
802 	actor->set_invisible(!lua_toboolean(L, 3)); //negate value before passing back to actor.
803 	return 0;
804 }
805 
nscript_actor_set_worktype(Actor * actor,lua_State * L)806 static int nscript_actor_set_worktype(Actor *actor, lua_State *L) {
807 	actor->set_worktype((uint8)lua_tointeger(L, 3));
808 	return 0;
809 }
810 
nscript_actor_set_x(Actor * actor,lua_State * L)811 static int nscript_actor_set_x(Actor *actor, lua_State *L) {
812 	//actor->set_x((uint16)lua_tointeger(L, 3));
813 	return 0;
814 }
815 
nscript_actor_set_y(Actor * actor,lua_State * L)816 static int nscript_actor_set_y(Actor *actor, lua_State *L) {
817 	//actor->set_y((uint16)lua_tointeger(L, 3));
818 	return 0;
819 }
820 
nscript_actor_set_z(Actor * actor,lua_State * L)821 static int nscript_actor_set_z(Actor *actor, lua_State *L) {
822 	//actor->set_z((uint8)lua_tointeger(L, 3));
823 	return 0;
824 }
825 
nscript_actor_get(lua_State * L)826 static int nscript_actor_get(lua_State *L) {
827 	Actor *actor;
828 	const char *key;
829 
830 	actor = nscript_get_actor_from_args(L);
831 	if (actor == NULL)
832 		return 0;
833 
834 	key = lua_tostring(L, 2);
835 
836 	int idx = str_bsearch(actor_get_vars, sizeof(actor_get_vars) / sizeof(actor_get_vars[0]), key);
837 	if (idx == -1)
838 		return 0;
839 
840 	return (*actor_get_func[idx])(actor, L);
841 }
842 
nscript_actor_get_actor_num(Actor * actor,lua_State * L)843 static int nscript_actor_get_actor_num(Actor *actor, lua_State *L) {
844 	lua_pushinteger(L, actor->get_actor_num());
845 	return 1;
846 }
847 
nscript_actor_get_align(Actor * actor,lua_State * L)848 static int nscript_actor_get_align(Actor *actor, lua_State *L) {
849 	lua_pushinteger(L, actor->get_alignment());
850 	return 1;
851 }
852 
nscript_actor_get_alive(Actor * actor,lua_State * L)853 static int nscript_actor_get_alive(Actor *actor, lua_State *L) {
854 	lua_pushboolean(L, actor->is_alive());
855 	return 1;
856 }
857 
nscript_actor_get_asleep_flag(Actor * actor,lua_State * L)858 static int nscript_actor_get_asleep_flag(Actor *actor, lua_State *L) {
859 	lua_pushboolean(L, (int)actor->is_sleeping());
860 	return 1;
861 }
862 
nscript_actor_get_base_obj_n(Actor * actor,lua_State * L)863 static int nscript_actor_get_base_obj_n(Actor *actor, lua_State *L) {
864 	lua_pushinteger(L, actor->get_base_obj_n());
865 	return 1;
866 }
867 
nscript_actor_get_cursed_flag(Actor * actor,lua_State * L)868 static int nscript_actor_get_cursed_flag(Actor *actor, lua_State *L) {
869 	lua_pushboolean(L, (int)actor->is_cursed());
870 	return 1;
871 }
872 
nscript_actor_get_combat_mode(Actor * actor,lua_State * L)873 static int nscript_actor_get_combat_mode(Actor *actor, lua_State *L) {
874 	lua_pushinteger(L, actor->get_combat_mode());
875 	return 1;
876 }
877 
nscript_actor_get_charmed_flag(Actor * actor,lua_State * L)878 static int nscript_actor_get_charmed_flag(Actor *actor, lua_State *L) {
879 	lua_pushboolean(L, (int)actor->is_charmed());
880 	return 1;
881 }
882 
nscript_actor_get_cold_flag(Actor * actor,lua_State * L)883 static int nscript_actor_get_cold_flag(Actor *actor, lua_State *L) {
884 	lua_pushboolean(L, (int)actor->get_status_flag(ACTOR_MD_STATUS_FLAG_COLD));
885 	return 1;
886 }
887 
nscript_actor_get_corpser_flag(Actor * actor,lua_State * L)888 static int nscript_actor_get_corpser_flag(Actor *actor, lua_State *L) {
889 	lua_pushboolean(L, (int)actor->get_corpser_flag());
890 	return 1;
891 }
892 
nscript_actor_get_dexterity(Actor * actor,lua_State * L)893 static int nscript_actor_get_dexterity(Actor *actor, lua_State *L) {
894 	lua_pushinteger(L, actor->get_dexterity());
895 	return 1;
896 }
897 
nscript_actor_get_direction(Actor * actor,lua_State * L)898 static int nscript_actor_get_direction(Actor *actor, lua_State *L) {
899 	lua_pushinteger(L, actor->get_direction());
900 	return 1;
901 }
902 
nscript_actor_get_exp(Actor * actor,lua_State * L)903 static int nscript_actor_get_exp(Actor *actor, lua_State *L) {
904 	lua_pushinteger(L, actor->get_exp());
905 	return 1;
906 }
907 
nscript_actor_get_frame_n(Actor * actor,lua_State * L)908 static int nscript_actor_get_frame_n(Actor *actor, lua_State *L) {
909 	lua_pushinteger(L, actor->get_frame_n());
910 	return 1;
911 }
912 
nscript_actor_get_frenzy(Actor * actor,lua_State * L)913 static int nscript_actor_get_frenzy(Actor *actor, lua_State *L) {
914 	lua_pushboolean(L, actor->get_obj_flag(ACTOR_MD_OBJ_FLAG_FRENZY));
915 	return 1;
916 }
917 
nscript_actor_get_hit_flag(Actor * actor,lua_State * L)918 static int nscript_actor_get_hit_flag(Actor *actor, lua_State *L) {
919 	lua_pushboolean(L, (int)actor->is_hit());
920 	return 1;
921 }
922 
nscript_actor_get_hp(Actor * actor,lua_State * L)923 static int nscript_actor_get_hp(Actor *actor, lua_State *L) {
924 	lua_pushinteger(L, actor->get_hp());
925 	return 1;
926 }
927 
nscript_actor_get_hypoxia(Actor * actor,lua_State * L)928 static int nscript_actor_get_hypoxia(Actor *actor, lua_State *L) {
929 	lua_pushboolean(L, (int)actor->get_obj_flag(ACTOR_MD_OBJ_FLAG_HYPOXIA));
930 	return 1;
931 }
932 
nscript_actor_get_in_party_status(Actor * actor,lua_State * L)933 static int nscript_actor_get_in_party_status(Actor *actor, lua_State *L) {
934 	lua_pushboolean(L, (int)actor->is_in_party());
935 	return 1;
936 }
937 
nscript_actor_get_in_vehicle(Actor * actor,lua_State * L)938 static int nscript_actor_get_in_vehicle(Actor *actor, lua_State *L) {
939 	lua_pushboolean(L, (int)actor->is_in_vehicle());
940 	return 1;
941 }
942 
nscript_actor_get_intelligence(Actor * actor,lua_State * L)943 static int nscript_actor_get_intelligence(Actor *actor, lua_State *L) {
944 	lua_pushinteger(L, actor->get_intelligence());
945 	return 1;
946 }
947 
nscript_actor_get_level(Actor * actor,lua_State * L)948 static int nscript_actor_get_level(Actor *actor, lua_State *L) {
949 	lua_pushinteger(L, actor->get_level());
950 	return 1;
951 }
952 
nscript_actor_get_luatype(Actor * actor,lua_State * L)953 static int nscript_actor_get_luatype(Actor *actor, lua_State *L) {
954 	lua_pushstring(L, "actor");
955 	return 1;
956 }
957 
nscript_actor_get_magic(Actor * actor,lua_State * L)958 static int nscript_actor_get_magic(Actor *actor, lua_State *L) {
959 	lua_pushinteger(L, actor->get_magic());
960 	return 1;
961 }
962 
nscript_actor_get_max_hp(Actor * actor,lua_State * L)963 static int nscript_actor_get_max_hp(Actor *actor, lua_State *L) {
964 	lua_pushinteger(L, actor->get_maxhp());
965 	return 1;
966 }
967 
nscript_actor_get_movement_pts(Actor * actor,lua_State * L)968 static int nscript_actor_get_movement_pts(Actor *actor, lua_State *L) {
969 	lua_pushinteger(L, actor->get_moves_left());
970 	return 1;
971 }
972 
nscript_actor_get_name(Actor * actor,lua_State * L)973 static int nscript_actor_get_name(Actor *actor, lua_State *L) {
974 	lua_pushstring(L, actor->get_name());
975 	return 1;
976 }
977 
nscript_actor_get_obj_flag_0(Actor * actor,lua_State * L)978 static int nscript_actor_get_obj_flag_0(Actor *actor, lua_State *L) {
979 	lua_pushboolean(L, actor->get_obj_flag(0));
980 	return 1;
981 }
982 
nscript_actor_get_obj_n(Actor * actor,lua_State * L)983 static int nscript_actor_get_obj_n(Actor *actor, lua_State *L) {
984 	lua_pushinteger(L, actor->get_obj_n());
985 	return 1;
986 }
987 
nscript_actor_get_old_frame_n(Actor * actor,lua_State * L)988 static int nscript_actor_get_old_frame_n(Actor *actor, lua_State *L) {
989 	lua_pushinteger(L, actor->get_old_frame_n());
990 	return 1;
991 }
992 
nscript_actor_get_old_align(Actor * actor,lua_State * L)993 static int nscript_actor_get_old_align(Actor *actor, lua_State *L) {
994 	lua_pushinteger(L, actor->get_old_alignment());
995 	return 1;
996 }
997 
nscript_actor_get_paralyzed_flag(Actor * actor,lua_State * L)998 static int nscript_actor_get_paralyzed_flag(Actor *actor, lua_State *L) {
999 	lua_pushboolean(L, (int)actor->is_paralyzed());
1000 	return 1;
1001 }
1002 
nscript_actor_get_poisoned_flag(Actor * actor,lua_State * L)1003 static int nscript_actor_get_poisoned_flag(Actor *actor, lua_State *L) {
1004 	lua_pushboolean(L, (int)actor->is_poisoned());
1005 	return 1;
1006 }
1007 
nscript_actor_get_protected_flag(Actor * actor,lua_State * L)1008 static int nscript_actor_get_protected_flag(Actor *actor, lua_State *L) {
1009 	lua_pushboolean(L, (int)actor->is_protected());
1010 	return 1;
1011 }
1012 
nscript_actor_get_sched_loc(Actor * actor,lua_State * L)1013 static int nscript_actor_get_sched_loc(Actor *actor, lua_State *L) {
1014 	MapCoord sched_loc;
1015 
1016 	if (actor->get_schedule_location(&sched_loc) == false)
1017 		return 0;
1018 
1019 	lua_newtable(L);
1020 	lua_pushstring(L, "x");
1021 	lua_pushinteger(L, sched_loc.x);
1022 	lua_settable(L, -3);
1023 
1024 	lua_pushstring(L, "y");
1025 	lua_pushinteger(L, sched_loc.y);
1026 	lua_settable(L, -3);
1027 
1028 	lua_pushstring(L, "z");
1029 	lua_pushinteger(L, sched_loc.z);
1030 	lua_settable(L, -3);
1031 
1032 	return 1;
1033 }
1034 
nscript_actor_get_sched_worktype(Actor * actor,lua_State * L)1035 static int nscript_actor_get_sched_worktype(Actor *actor, lua_State *L) {
1036 	lua_pushinteger(L, actor->get_sched_worktype());
1037 	return 1;
1038 }
1039 
nscript_actor_get_strength(Actor * actor,lua_State * L)1040 static int nscript_actor_get_strength(Actor *actor, lua_State *L) {
1041 	lua_pushinteger(L, actor->get_strength());
1042 	return 1;
1043 }
1044 
nscript_actor_get_temp_status(Actor * actor,lua_State * L)1045 static int nscript_actor_get_temp_status(Actor *actor, lua_State *L) {
1046 	lua_pushboolean(L, (int)actor->is_temp());
1047 	return 1;
1048 }
1049 
nscript_actor_get_tile_num(Actor * actor,lua_State * L)1050 static int nscript_actor_get_tile_num(Actor *actor, lua_State *L) {
1051 	Tile *tile = actor->get_tile();
1052 
1053 	lua_pushinteger(L, (int)tile->tile_num);
1054 	return 1;
1055 }
1056 
nscript_actor_get_visible_flag(Actor * actor,lua_State * L)1057 static int nscript_actor_get_visible_flag(Actor *actor, lua_State *L) {
1058 	lua_pushboolean(L, (int)(actor->is_invisible() ? false : true));
1059 	return 1;
1060 }
1061 
nscript_actor_get_worktype(Actor * actor,lua_State * L)1062 static int nscript_actor_get_worktype(Actor *actor, lua_State *L) {
1063 	lua_pushinteger(L, actor->get_worktype());
1064 	return 1;
1065 }
1066 
nscript_actor_get_x(Actor * actor,lua_State * L)1067 static int nscript_actor_get_x(Actor *actor, lua_State *L) {
1068 	lua_pushinteger(L, actor->get_x());
1069 	return 1;
1070 }
1071 
nscript_actor_get_xyz(Actor * actor,lua_State * L)1072 static int nscript_actor_get_xyz(Actor *actor, lua_State *L) {
1073 	lua_newtable(L);
1074 	lua_pushstring(L, "x");
1075 	lua_pushinteger(L, actor->get_x());
1076 	lua_settable(L, -3);
1077 
1078 	lua_pushstring(L, "y");
1079 	lua_pushinteger(L, actor->get_y());
1080 	lua_settable(L, -3);
1081 
1082 	lua_pushstring(L, "z");
1083 	lua_pushinteger(L, actor->get_z());
1084 	lua_settable(L, -3);
1085 
1086 	return 1;
1087 }
1088 
nscript_actor_get_y(Actor * actor,lua_State * L)1089 static int nscript_actor_get_y(Actor *actor, lua_State *L) {
1090 	lua_pushinteger(L, actor->get_y());
1091 	return 1;
1092 }
1093 
nscript_actor_get_z(Actor * actor,lua_State * L)1094 static int nscript_actor_get_z(Actor *actor, lua_State *L) {
1095 	lua_pushinteger(L, actor->get_z());
1096 	return 1;
1097 }
1098 
1099 /***
1100 Call the C++ Actor::die() method
1101 @function Actor.kill
1102 @tparam Actor actor
1103 @bool[opt=true] create_body Create a dead body on the map?
1104 @within Actor
1105  */
nscript_actor_kill(lua_State * L)1106 static int nscript_actor_kill(lua_State *L) {
1107 	Actor *actor;
1108 	bool create_body = true;
1109 
1110 	actor = nscript_get_actor_from_args(L);
1111 	if (actor == NULL)
1112 		return 0;
1113 
1114 	if (lua_gettop(L) >= 2)
1115 		create_body = (bool)lua_toboolean(L, 2);
1116 
1117 	actor->die(create_body);
1118 
1119 	return 0;
1120 }
1121 
1122 /***
1123 Call the C++ Actor::hit() method
1124 @function ultima/nuvie/actors/actor.hit
1125 @tparam Actor actor
1126 @int damage
1127 @within Actor
1128  */
nscript_actor_hit(lua_State * L)1129 static int nscript_actor_hit(lua_State *L) {
1130 	Actor *actor;
1131 	uint8 damage;
1132 
1133 	actor = nscript_get_actor_from_args(L);
1134 	if (actor == NULL)
1135 		return 0;
1136 
1137 	damage = (uint8)luaL_checkinteger(L, 2);
1138 
1139 	actor->hit(damage, true); //force hit
1140 
1141 	return 0;
1142 }
1143 
1144 /***
1145 Calls the get_combat_range script function with the wrapped absolute x,y distances to the target
1146 @function Actor.get_range
1147 @tparam Actor actor
1148 @int target_x
1149 @int target_y
1150 @treturn int range
1151 @within Actor
1152  */
nscript_actor_get_range(lua_State * L)1153 static int nscript_actor_get_range(lua_State *L) {
1154 	Actor *actor;
1155 	actor = nscript_get_actor_from_args(L);
1156 	if (actor == NULL)
1157 		return 0;
1158 	uint16 target_x = (uint16) luaL_checkinteger(L, 2);
1159 	uint16 target_y = (uint16) luaL_checkinteger(L, 3);
1160 	lua_pushinteger(L, actor->get_range(target_x, target_y));
1161 	return 1;
1162 }
1163 
1164 /***
1165 Move actor to location.
1166 @function Actor.move
1167 @tparam Actor actor
1168 @tparam MapCoord|x,y,z location
1169 @treturn bool Returns true is the move was successful. False if the move fails.
1170 @within Actor
1171  */
nscript_actor_move(lua_State * L)1172 static int nscript_actor_move(lua_State *L) {
1173 	Actor *actor;
1174 	uint16 x, y;
1175 	uint8 z;
1176 
1177 	actor = nscript_get_actor_from_args(L);
1178 	if (actor == NULL)
1179 		return 0;
1180 
1181 	if (nscript_get_location_from_args(L, &x, &y, &z, 2) == false)
1182 		return 0;
1183 
1184 	lua_pushboolean(L, (int)actor->move(x, y, z));
1185 
1186 	return 1;
1187 }
1188 
1189 /***
1190 Move the actor one space along their pathfinding path.
1191 @function Actor.walk_path
1192 @tparam Actor actor
1193 @within Actor
1194  */
nscript_actor_walk_path(lua_State * L)1195 static int nscript_actor_walk_path(lua_State *L) {
1196 	Actor *actor = nscript_get_actor_from_args(L);
1197 	if (actor == NULL)
1198 		return 0;
1199 
1200 	actor->update(); //FIXME this should be specific to pathfinding.
1201 
1202 	return 0;
1203 }
1204 
1205 /***
1206 Checks to see if the actor is currently at their scheduled worktype location.
1207 @function Actor.is_at_scheduled_location
1208 @tparam Actor actor
1209 @treturn bool
1210 @within Actor
1211  */
nscript_actor_is_at_scheduled_location(lua_State * L)1212 static int nscript_actor_is_at_scheduled_location(lua_State *L) {
1213 	Actor *actor = nscript_get_actor_from_args(L);
1214 	if (actor == NULL)
1215 		return 0;
1216 
1217 	lua_pushboolean(L, actor->is_at_scheduled_location());
1218 	return 1;
1219 }
1220 
1221 /***
1222 Checks to see if the actor can carry an object.
1223 It first checks that the object is get-able then checks that
1224 the actor can physically carry the object's weight.
1225 @function Actor.can_carry_obj
1226 @tparam Actor actor
1227 @tparam Obj object
1228 @treturn bool
1229 @within Actor
1230  */
nscript_actor_can_carry_obj(lua_State * L)1231 static int nscript_actor_can_carry_obj(lua_State *L) {
1232 	Actor *actor = nscript_get_actor_from_args(L);
1233 	if (actor == NULL)
1234 		return 0;
1235 
1236 	Obj *obj = nscript_get_obj_from_args(L, 2);
1237 	if (obj == NULL)
1238 		return 0;
1239 
1240 	lua_pushboolean(L, (int)actor->can_carry_object(obj));
1241 	return 1;
1242 }
1243 
1244 /***
1245 Checks to see if the actor can carry an object's weight.
1246 @function Actor.can_carry_obj_weight
1247 @tparam Actor actor
1248 @tparam Obj object
1249 @treturn bool
1250 @within Actor
1251  */
nscript_actor_can_carry_obj_weight(lua_State * L)1252 static int nscript_actor_can_carry_obj_weight(lua_State *L) {
1253 	if (Game::get_game()->using_hackmove())
1254 		return 1;
1255 	Actor *actor = nscript_get_actor_from_args(L);
1256 	if (actor == NULL)
1257 		return 0;
1258 
1259 	Obj *obj = nscript_get_obj_from_args(L, 2);
1260 	if (obj == NULL)
1261 		return 0;
1262 
1263 	lua_pushboolean(L, (int)actor->can_carry_weight(obj));
1264 	return 1;
1265 }
1266 
1267 /***
1268 Fade the black pixels in the actor's tile to a specified color.
1269 @function Actor.black_fade_effect
1270 @tparam Actor actor
1271 @int fade_color
1272 @int fade_speed
1273 @within Actor
1274  */
nscript_actor_black_fade_effect(lua_State * L)1275 static int nscript_actor_black_fade_effect(lua_State *L) {
1276 	Actor *actor = nscript_get_actor_from_args(L);
1277 	uint8 fade_color = (uint8)lua_tointeger(L, 2);
1278 	uint16 fade_speed = (uint8)lua_tointeger(L, 3);
1279 
1280 	if (actor != NULL) {
1281 		AsyncEffect *e = new AsyncEffect(new TileBlackFadeEffect(actor, fade_color, fade_speed));
1282 		e->run();
1283 	}
1284 
1285 	return 0;
1286 }
1287 
1288 /***
1289 Pixel fade out the actor's tile to nothing.
1290 @function Actor.fade_out
1291 @tparam Actor actor
1292 @int fade_speed
1293 @within Actor
1294  */
nscript_actor_fade_out_effect(lua_State * L)1295 static int nscript_actor_fade_out_effect(lua_State *L) {
1296 	Actor *actor = nscript_get_actor_from_args(L);
1297 	uint16 fade_speed = (uint8)lua_tointeger(L, 2);
1298 
1299 	if (actor != NULL) {
1300 		AsyncEffect *e = new AsyncEffect(new TileFadeEffect(actor, fade_speed));
1301 		e->run();
1302 	}
1303 
1304 	return 0;
1305 }
1306 
1307 /***
1308 Display the actor's portrait
1309 @function Actor.show_portrait
1310 @tparam Actor actor
1311 @within Actor
1312  */
nscript_actor_show_portrait(lua_State * L)1313 static int nscript_actor_show_portrait(lua_State *L) {
1314 	Actor *actor = nscript_get_actor_from_args(L);
1315 	if (actor == NULL)
1316 		return 0;
1317 
1318 	Game::get_game()->get_view_manager()->set_portrait_mode(actor, actor->get_name());
1319 
1320 	return 0;
1321 }
1322 
1323 /***
1324 Hide the actor's portrait.
1325 The party view is shown if in original UI mode.
1326 @function ultima/nuvie/actors/actor.hide_portrait
1327 @tparam Actor actor
1328 @within Actor
1329  */
nscript_actor_hide_portrait(lua_State * L)1330 static int nscript_actor_hide_portrait(lua_State *L) {
1331 	if (Game::get_game()->is_new_style())
1332 		Game::get_game()->get_view_manager()->get_portrait_view()->Hide();
1333 	else
1334 		Game::get_game()->get_view_manager()->set_party_mode();
1335 
1336 	return 0;
1337 }
1338 
1339 /***
1340 Talk to actor. The script will pause until the conversation has ended.
1341 @function Actor.talk
1342 @tparam Actor actor
1343 @within Actor
1344  */
nscript_actor_talk(lua_State * L)1345 static int nscript_actor_talk(lua_State *L) {
1346 	Actor *actor = nscript_get_actor_from_args(L);
1347 	if (actor == NULL)
1348 		return 0;
1349 
1350 	Game::get_game()->get_converse()->start(actor);
1351 	Game::get_game()->update_until_converse_finished();
1352 	return 0;
1353 }
1354 
1355 /***
1356 For multi-tile actors, disconnect their surrounding objects.
1357 @function Actor.unlink_surrounding_objs
1358 @tparam Actor actor
1359 @bool make_temp Should the objects be made temporary?
1360 @within Actor
1361  */
nscript_actor_unlink_surrounding_objs(lua_State * L)1362 static int nscript_actor_unlink_surrounding_objs(lua_State *L) {
1363 	Actor *actor = nscript_get_actor_from_args(L);
1364 	if (actor == NULL)
1365 		return 0;
1366 
1367 	bool make_temp_obj = lua_toboolean(L, 2);
1368 
1369 	actor->unlink_surrounding_objects(make_temp_obj);
1370 
1371 	return 0;
1372 }
1373 
1374 /***
1375 Call the C++ actor usecode logic.
1376 @function Actor.use
1377 @tparam Actor actor
1378 @within Actor
1379  */
nscript_actor_use(lua_State * L)1380 static int nscript_actor_use(lua_State *L) {
1381 	UseCode *usecode = Game::get_game()->get_usecode();
1382 	Actor *actor = nscript_get_actor_from_args(L);
1383 	if (actor == NULL)
1384 		return 0;
1385 
1386 	Obj *my_obj = actor->make_obj();
1387 	usecode->use_obj(my_obj, actor);
1388 	delete_obj(my_obj);
1389 
1390 	return 0;
1391 }
1392 
1393 /***
1394 Resurrect a dead actor. If the actor's body is not on the map then the actor will
1395 be placed at a random map location around the player.
1396 @function Actor.resurrect
1397 @tparam Actor actor
1398 @tparam MapCoord|x,y,z location Location to put the resurrected actor on the map
1399 @tparam Obj body_obj The dead actor's body object.
1400 @within Actor
1401  */
nscript_actor_resurrect(lua_State * L)1402 static int nscript_actor_resurrect(lua_State *L) {
1403 	Actor *actor;
1404 	MapCoord loc;
1405 
1406 	actor = nscript_get_actor_from_args(L);
1407 	if (actor == NULL)
1408 		return 0;
1409 
1410 	if (nscript_get_location_from_args(L, &loc.x, &loc.y, &loc.z, 2) == false)
1411 		return 0;
1412 	Obj *obj = nscript_get_obj_from_args(L, 5);
1413 	bool toss = (obj->is_in_inventory() || obj->is_in_container());
1414 	if (toss)
1415 		loc = Game::get_game()->get_player()->get_actor()->get_location();
1416 
1417 	actor->resurrect(loc, obj);
1418 	if (toss) {
1419 		ActorManager *actor_manager = Game::get_game()->get_actor_manager();
1420 		if (!actor_manager->toss_actor(actor, 2, 2))
1421 			actor_manager->toss_actor(actor, 4, 4);
1422 	}
1423 	return 0;
1424 }
1425 
1426 /***
1427 Add an object to the actor's inventory.
1428 @function Actor.inv_add_obj
1429 @tparam Actor actor
1430 @tparam Obj obj
1431 @bool[opt=false] stack_objs Should we stack obj.qty into existing objects?
1432 @within Actor
1433  */
nscript_actor_inv_add_obj(lua_State * L)1434 static int nscript_actor_inv_add_obj(lua_State *L) {
1435 	Actor *actor;
1436 	bool stack_objs = false;
1437 
1438 	actor = nscript_get_actor_from_args(L);
1439 	if (actor == NULL)
1440 		return 0;
1441 
1442 	Obj **s_obj = (Obj **)luaL_checkudata(L, 2, "nuvie.Obj");
1443 	Obj *obj;
1444 
1445 	obj = *s_obj;
1446 
1447 	if (lua_gettop(L) >= 3) {
1448 		stack_objs = lua_toboolean(L, 3);
1449 	}
1450 
1451 	actor->inventory_add_object(obj, NULL, stack_objs);
1452 
1453 	return 0;
1454 }
1455 
1456 /***
1457 Remove an object from the actor's inventory
1458 @function Actor.inv_remove_obj
1459 @tparam Actor actor
1460 @tparam Obj obj
1461 @within Actor
1462  */
nscript_actor_inv_remove_obj(lua_State * L)1463 static int nscript_actor_inv_remove_obj(lua_State *L) {
1464 	Actor *actor;
1465 
1466 	actor = nscript_get_actor_from_args(L);
1467 	if (actor == NULL)
1468 		return 0;
1469 
1470 	Obj **s_obj = (Obj **)luaL_checkudata(L, 2, "nuvie.Obj");
1471 	Obj *obj;
1472 
1473 	obj = *s_obj;
1474 
1475 
1476 	actor->inventory_remove_obj(obj);
1477 
1478 	return 0;
1479 }
1480 
1481 /***
1482 Remove a number of stackable objects from the actor's inventory
1483 @function Actor.inv_remove_obj_qty
1484 @tparam Actor actor
1485 @int obj_n Type of object to remove.
1486 @int qty Number of objects to remove.
1487 @treturn int returns the number of objects actually removed. This may be less than were requested.
1488 @within Actor
1489  */
nscript_actor_inv_remove_obj_qty(lua_State * L)1490 static int nscript_actor_inv_remove_obj_qty(lua_State *L) {
1491 	Actor *actor;
1492 
1493 	actor = nscript_get_actor_from_args(L);
1494 	if (actor == NULL)
1495 		return 0;
1496 
1497 	uint16 obj_n = (uint16)lua_tointeger(L, 2);
1498 	uint16 qty = (uint16)lua_tointeger(L, 3);
1499 
1500 
1501 	lua_pushinteger(L, actor->inventory_del_object(obj_n, qty, 0));
1502 
1503 	return 1;
1504 }
1505 
1506 /***
1507 Returns the obj_n the object that is readied at a given location.
1508 @function Actor.inv_get_readied_obj_n
1509 @tparam Actor actor
1510 @int location
1511 
1512 - 0 = HEAD
1513 - 1 = NECK
1514 - 2 = BODY
1515 - 3 = ARM
1516 - 4 = ARM_2
1517 - 5 = HAND
1518 - 6 = HAND_2
1519 - 7 = FOOT
1520 
1521 @treturn int returns obj_n or -1 if nothing is readied at the specified location.
1522 @within Actor
1523  */
nscript_actor_inv_get_readied_obj_n(lua_State * L)1524 static int nscript_actor_inv_get_readied_obj_n(lua_State *L) {
1525 	Actor *actor = nscript_get_actor_from_args(L);
1526 	if (actor == NULL) {
1527 		lua_pushinteger(L, -1);
1528 		return 1;
1529 	}
1530 	uint8 location = (uint8)lua_tointeger(L, 2);
1531 	lua_pushinteger(L, actor->inventory_get_readied_obj_n(location));
1532 	return 1;
1533 }
1534 
1535 /***
1536 Ready an object from the actor's inventory.
1537 @function Actor.inv_ready_obj
1538 @tparam Actor actor
1539 @tparam Obj obj
1540 @within Actor
1541  */
nscript_actor_inv_ready_obj(lua_State * L)1542 static int nscript_actor_inv_ready_obj(lua_State *L) {
1543 	Actor *actor;
1544 	MapCoord loc;
1545 
1546 	actor = nscript_get_actor_from_args(L);
1547 	if (actor == NULL)
1548 		return 0;
1549 
1550 	Obj **s_obj = (Obj **)luaL_checkudata(L, 2, "nuvie.Obj");
1551 	Obj *obj;
1552 
1553 	obj = *s_obj;
1554 
1555 	actor->add_readied_object(obj);
1556 
1557 	return 0;
1558 }
1559 
1560 /***
1561 Unready an object from the actor.
1562 First attempt to unready object using usecode. If there is no unready usecode then just unready the object normally.
1563 @function Actor.inv_unready_obj
1564 @tparam Actor actor
1565 @tparam Obj obj
1566 @within Actor
1567  */
nscript_actor_inv_unready_obj(lua_State * L)1568 static int nscript_actor_inv_unready_obj(lua_State *L) {
1569 	Actor *actor;
1570 
1571 	actor = nscript_get_actor_from_args(L);
1572 	if (actor == NULL)
1573 		return 0;
1574 
1575 	Obj **s_obj = (Obj **)luaL_checkudata(L, 2, "nuvie.Obj");
1576 	Obj *obj;
1577 
1578 	obj = *s_obj;
1579 
1580 	UseCode *usecode = Game::get_game()->get_usecode();
1581 
1582 	//try to unready via usecode.
1583 	if (usecode->has_readycode(obj) && (usecode->ready_obj(obj, actor) == false)) {
1584 		return 0;
1585 	}
1586 
1587 	actor->remove_readied_object(obj);
1588 
1589 	return 0;
1590 }
1591 
1592 /***
1593 Check if the actor has an object of type obj_n in their inventory.
1594 @function Actor.inv_has_obj_n
1595 @tparam Actor actor
1596 @int obj_n object number to search for
1597 @treturn bool
1598 @within Actor
1599  */
nscript_actor_inv_has_obj_n(lua_State * L)1600 static int nscript_actor_inv_has_obj_n(lua_State *L) {
1601 	Actor *actor;
1602 	uint16 obj_n;
1603 
1604 	actor = nscript_get_actor_from_args(L);
1605 	if (actor == NULL)
1606 		return 0;
1607 
1608 	obj_n = (uint16)luaL_checkinteger(L, 2);
1609 
1610 	lua_pushboolean(L, (int)actor->inventory_has_object(obj_n, 0, false));
1611 
1612 	return 1;
1613 }
1614 
1615 /***
1616 Get the first object of type obj_n from the actor's inventory.
1617 @function Actor.inv_get_obj_n
1618 @tparam Actor actor
1619 @int obj_n object number to search for
1620 @int[opt] frame_n search on frame number
1621 @int[opt] quality search on object quality
1622 @treturn Obj returns an object or nil if no match was found
1623 @within Actor
1624  */
nscript_actor_inv_get_obj_n(lua_State * L)1625 static int nscript_actor_inv_get_obj_n(lua_State *L) {
1626 	Actor *actor;
1627 	uint16 obj_n;
1628 	uint8 frame_n = 0;
1629 	uint8 quality = 0;
1630 	bool match_frame_n = false;
1631 	bool match_quality = false;
1632 	Obj *obj;
1633 	actor = nscript_get_actor_from_args(L);
1634 	if (actor == NULL)
1635 		return 0;
1636 
1637 	obj_n = (uint16)luaL_checkinteger(L, 2);
1638 
1639 	if (lua_gettop(L) >= 3 && !lua_isnil(L, 3)) {
1640 		frame_n = (uint8)luaL_checkinteger(L, 3);
1641 		match_frame_n = true;
1642 	}
1643 
1644 	if (lua_gettop(L) >= 4 && !lua_isnil(L, 4)) {
1645 		quality = (uint8)luaL_checkinteger(L, 4);
1646 		match_quality = true;
1647 	}
1648 
1649 	obj = actor->inventory_get_object(obj_n, quality, match_quality, frame_n, match_frame_n);
1650 
1651 	if (obj) {
1652 		nscript_new_obj_var(L, obj);
1653 		return 1;
1654 	}
1655 
1656 	return 0;
1657 }
1658 
1659 /***
1660 Get the total number of objects of type obj_n in the actor's inventory
1661 @function Actor.inv_get_obj_total_qty
1662 @tparam Actor actor
1663 @int obj_n object number to search for
1664 @treturn int
1665 @within Actor
1666  */
nscript_actor_inv_get_obj_total_qty(lua_State * L)1667 static int nscript_actor_inv_get_obj_total_qty(lua_State *L) {
1668 	Actor *actor;
1669 	uint16 obj_n;
1670 
1671 	actor = nscript_get_actor_from_args(L);
1672 	if (actor == NULL)
1673 		return 0;
1674 
1675 	obj_n = (uint16)luaL_checkinteger(L, 2);
1676 
1677 	lua_pushinteger(L, actor->inventory_count_object(obj_n));
1678 
1679 	return 1;
1680 }
1681 
1682 /***
1683 Get the actor at map location.
1684 @function map_get_actor
1685 @tparam MapCoord|x,y,z location
1686 @tparam[opt] Actor excluded_actor Actor to be excluded from search results
1687 @treturn Actor returns the actor or nil if no actor was found
1688 @within Actor
1689  */
nscript_map_get_actor(lua_State * L)1690 static int nscript_map_get_actor(lua_State *L) {
1691 	ActorManager *actor_manager = Game::get_game()->get_actor_manager();
1692 	Actor *actor;
1693 
1694 	uint16 x, y;
1695 	uint8 z;
1696 
1697 	if (nscript_get_location_from_args(L, &x, &y, &z) == false)
1698 		return 0;
1699 	Actor *excluded_actor = NULL;
1700 	void *p = lua_touserdata(L, 4); // avoid error warnings when null
1701 	if (p != NULL)
1702 		excluded_actor = nscript_get_actor_from_args(L, 4);
1703 
1704 	actor = actor_manager->get_actor(x, y, z, true, excluded_actor);
1705 
1706 	if (actor == NULL)
1707 		return 0;
1708 
1709 	if (nscript_new_actor_var(L, actor->get_actor_num()) == false)
1710 		return 0;
1711 
1712 	return 1;
1713 }
1714 
1715 /***
1716 Update all actor schedules.
1717 Schedules change on the hour.
1718 @function update_actor_schedules
1719 @bool[opt=false] teleport_actors Should actors teleport to their new scheduled location?
1720 @within Actor
1721  */
nscript_update_actor_schedules(lua_State * L)1722 static int nscript_update_actor_schedules(lua_State *L) {
1723 	bool teleport;
1724 	if (lua_gettop(L) >= 1)
1725 		teleport = (bool)lua_toboolean(L, 1);
1726 	else
1727 		teleport = false;
1728 	ActorManager *actor_manager = Game::get_game()->get_actor_manager();
1729 	actor_manager->updateSchedules(teleport);
1730 	return 0;
1731 }
1732 
1733 /***
1734 Iterate through objects in the actor's inventory.
1735 @function actor_inventory
1736 @tparam Actor actor
1737 @bool[opt=false] is_recursive should we search containers inside the inventory?
1738 @usage
1739    local ac = 0
1740    local obj
1741 
1742    for obj in actor_inventory(actor) do
1743 	  if obj.readied then
1744 		 local armour = armour_tbl[obj.obj_n]
1745 		 if armour ~= nil then
1746 			ac = ac + armour
1747 		 end
1748 	  end
1749    end
1750 @within Actor
1751  */
nscript_actor_inv(lua_State * L)1752 static int nscript_actor_inv(lua_State *L) {
1753 	Actor *actor;
1754 	bool is_recursive = false;
1755 
1756 	actor = nscript_get_actor_from_args(L);
1757 	if (actor == NULL)
1758 		return 0;
1759 
1760 	if (lua_gettop(L) >= 2)
1761 		is_recursive = lua_toboolean(L, 2);
1762 
1763 	U6LList *inv = actor->get_inventory_list();
1764 
1765 	return nscript_init_u6link_iter(L, inv, is_recursive);
1766 }
1767 
1768 /***
1769 Set one of the actor's talk flags
1770 @function Actor.set_talk_flag
1771 @tparam Actor actor
1772 @int flag The flag to set. 0..7
1773 @within Actor
1774  */
nscript_actor_set_talk_flag(lua_State * L)1775 static int nscript_actor_set_talk_flag(lua_State *L) {
1776 	Actor *actor;
1777 	actor = nscript_get_actor_from_args(L);
1778 	if (actor == NULL)
1779 		return 0;
1780 	actor->set_flag((uint8)lua_tointeger(L, 2));
1781 	return 0;
1782 }
1783 
1784 /***
1785 Get the value of one of the actor's talk flags
1786 @function Actor.get_talk_flag
1787 @tparam Actor actor
1788 @int flag The flag to get. 0..7
1789 @treturn bool returns the flag value
1790 @within Actor
1791  */
nscript_actor_get_talk_flag(lua_State * L)1792 static int nscript_actor_get_talk_flag(lua_State *L) {
1793 	Actor *actor;
1794 	actor = nscript_get_actor_from_args(L);
1795 	if (actor == NULL)
1796 		return 0;
1797 	lua_pushboolean(L, actor->get_flag((uint8)lua_tointeger(L, 2)));
1798 
1799 	return 1;
1800 }
1801 
1802 /***
1803 Clear one of the actor's talk flags
1804 @function Actor.clear_talk_flag
1805 @tparam Actor actor
1806 @int flag The flag to clear. 0..7
1807 @within Actor
1808  */
nscript_actor_clear_talk_flag(lua_State * L)1809 static int nscript_actor_clear_talk_flag(lua_State *L) {
1810 	Actor *actor;
1811 	actor = nscript_get_actor_from_args(L);
1812 	if (actor == NULL)
1813 		return 0;
1814 	actor->clear_flag((uint8)lua_tointeger(L, 2));
1815 	return 0;
1816 }
1817 
1818 /***
1819 Get the number of schedule entries
1820 @function Actor.get_number_of_schedules
1821 @tparam Actor actor
1822 @treturn int
1823 @within Actor
1824  */
nscript_actor_get_number_of_schedules(lua_State * L)1825 static int nscript_actor_get_number_of_schedules(lua_State *L) {
1826 	Actor *actor = nscript_get_actor_from_args(L);
1827 	if (actor == NULL)
1828 		return 0;
1829 
1830 	lua_pushinteger(L, actor->get_number_of_schedules());
1831 	return 1;
1832 }
1833 
1834 /***
1835 Get an Actor schedule entry
1836 @function Actor.get_schedule
1837 @tparam Actor actor
1838 @int index The index of the schedule to retrieve
1839 @treturn Schedule
1840 @within Actor
1841  */
nscript_actor_get_schedule(lua_State * L)1842 static int nscript_actor_get_schedule(lua_State *L) {
1843 	Actor *actor = nscript_get_actor_from_args(L);
1844 	if (actor == NULL)
1845 		return 0;
1846 
1847 	Schedule *schedule = actor->get_schedule((uint8)lua_tointeger(L, 2));
1848 
1849 	lua_newtable(L);
1850 	lua_pushstring(L, "day_of_week");
1851 	lua_pushinteger(L, schedule->day_of_week);
1852 	lua_settable(L, -3);
1853 
1854 	lua_pushstring(L, "worktype");
1855 	lua_pushinteger(L, schedule->worktype);
1856 	lua_settable(L, -3);
1857 
1858 	lua_pushstring(L, "x");
1859 	lua_pushinteger(L, schedule->x);
1860 	lua_settable(L, -3);
1861 
1862 	lua_pushstring(L, "y");
1863 	lua_pushinteger(L, schedule->y);
1864 	lua_settable(L, -3);
1865 
1866 	lua_pushstring(L, "z");
1867 	lua_pushinteger(L, schedule->z);
1868 	lua_settable(L, -3);
1869 
1870 	return 1;
1871 }
1872 
1873 } // End of namespace Nuvie
1874 } // End of namespace Ultima
1875