1 /*
2 LUA_HUD_OBJECTS.CPP
3
4 Copyright (C) 2009 by Jeremiah Morris
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 This license is contained in the file "COPYING",
17 which is included with this source code; it is available online at
18 http://www.gnu.org/licenses/gpl.html
19
20 Implements Lua HUD objects and globals
21 */
22
23 #include "lua_hud_objects.h"
24 #include "lua_objects.h"
25 #include "lua_map.h"
26 #include "lua_templates.h"
27
28 #include "items.h"
29 #include "player.h"
30 #include "motion_sensor.h"
31 #include "screen.h"
32 #include "shell.h"
33 #include "alephversion.h"
34 #include "HUDRenderer.h"
35 #include "HUDRenderer_Lua.h"
36 #include "network.h"
37 #include "FontHandler.h"
38 #include "render.h"
39 #include "Image_Blitter.h"
40 #include "OGL_Blitter.h"
41 #include "fades.h"
42 #include "OGL_Faders.h"
43 #include "Shape_Blitter.h"
44 #include "collection_definition.h"
45 #include "FileHandler.h"
46 #include "Crosshairs.h"
47
48 #include <boost/bind.hpp>
49 #include <boost/shared_ptr.hpp>
50 #include <algorithm>
51 #include <cmath>
52 #include <unordered_map>
53
54 #ifdef HAVE_LUA
55
56 extern struct view_data *world_view;
57
58 const float AngleConvert = 360/float(FULL_CIRCLE);
59
60 extern collection_definition *get_collection_definition(short);
61
62 extern bool use_lua_hud_crosshairs;
63
Lua_Collection_Get_Bitmap_Count(lua_State * L)64 static int Lua_Collection_Get_Bitmap_Count(lua_State *L)
65 {
66 collection_definition *collection = get_collection_definition(Lua_Collection::Index(L, 1));
67 lua_pushnumber(L, collection->bitmap_count);
68 return 1;
69 }
70
71 const luaL_Reg Lua_Collection_Get[] = {
72 {"bitmap_count", Lua_Collection_Get_Bitmap_Count},
73 {0, 0},
74 };
75
76
77 char Lua_InterfaceColor_Name[] = "interface_color";
78 char Lua_InterfaceColors_Name[] = "InterfaceColors";
79
80 char Lua_InterfaceFont_Name[] = "interface_font";
81 char Lua_InterfaceFonts_Name[] = "InterfaceFonts";
82
83 char Lua_InterfaceRect_Name[] = "interface_rect";
84 char Lua_InterfaceRects_Name[] = "InterfaceRects";
85
86 char Lua_InventorySection_Name[] = "inventory_section";
87 char Lua_InventorySections_Name[] = "InventorySections";
88
89 char Lua_RendererType_Name[] = "renderer_type";
90 char Lua_RendererTypes_Name[] = "RendererTypes";
91 #define NUMBER_OF_RENDERER_TYPES 2
92
93 char Lua_SensorBlipType_Name[] = "sensor_blip_type";
94 char Lua_SensorBlipTypes_Name[] = "SensorBlipTypes";
95
96 char Lua_TextureType_Name[] = "texture_type";
97 char Lua_TextureTypes_Name[] = "TextureTypes";
98
99 char Lua_SizePref_Name[] = "size_preference";
100 typedef L_Enum<Lua_SizePref_Name> Lua_SizePreference;
101
102 char Lua_SizePrefs_Name[] = "SizePreferences";
103 typedef L_EnumContainer<Lua_SizePrefs_Name, Lua_SizePreference> Lua_SizePreferences;
104 #define NUMBER_OF_SIZE_PREFERENCES 3
105
106 char Lua_FadeEffectType_Name[] = "fade_effect_type";
107 typedef L_Enum<Lua_FadeEffectType_Name> Lua_FadeEffectType;
108
109 char Lua_FadeEffectTypes_Name[] = "FadeEffectTypes";
110 typedef L_EnumContainer<Lua_FadeEffectTypes_Name, Lua_FadeEffectType> Lua_FadeEffectTypes;
111
112 char Lua_MaskingMode_Name[] = "masking_mode";
113 typedef L_Enum<Lua_MaskingMode_Name> Lua_MaskingMode;
114
115 char Lua_MaskingModes_Name[] = "MaskingModes";
116 typedef L_EnumContainer<Lua_MaskingModes_Name, Lua_MaskingMode> Lua_MaskingModes;
117
118 extern char Lua_DifficultyType_Name[];
119 typedef L_Enum<Lua_DifficultyType_Name> Lua_DifficultyType;
120
121 extern char Lua_DifficultyTypes_Name[];
122 typedef L_EnumContainer<Lua_DifficultyTypes_Name, Lua_DifficultyType> Lua_DifficultyTypes;
123
124 extern char Lua_GameType_Name[];
125 typedef L_Enum<Lua_GameType_Name> Lua_GameType;
126
127 extern char Lua_GameTypes_Name[];
128 typedef L_EnumContainer<Lua_GameTypes_Name, Lua_GameType> Lua_GameTypes;
129
130 extern char Lua_ItemType_Name[];
Lua_ItemType_Get_Ball(lua_State * L)131 static int Lua_ItemType_Get_Ball(lua_State *L)
132 {
133 lua_pushboolean(L, (get_item_kind(Lua_ItemType::Index(L, 1)) == _ball));
134 return 1;
135 }
136 const luaL_Reg Lua_ItemType_Get[] = {
137 {"ball", Lua_ItemType_Get_Ball},
138 {0, 0}
139 };
140
141 extern char Lua_PlayerColor_Name[];
142 typedef L_Enum<Lua_PlayerColor_Name> Lua_PlayerColor;
143
144 extern char Lua_PlayerColors_Name[];
145 typedef L_EnumContainer<Lua_PlayerColors_Name, Lua_PlayerColor> Lua_PlayerColors;
146
147 extern char Lua_ScoringMode_Name[];
148 typedef L_Enum<Lua_ScoringMode_Name> Lua_ScoringMode;
149
150 extern char Lua_ScoringModes_Name[];
151 typedef L_Container<Lua_ScoringModes_Name, Lua_ScoringMode> Lua_ScoringModes;
152
153 extern char Lua_WeaponType_Name[];
154 typedef L_Enum<Lua_WeaponType_Name> Lua_WeaponType;
155
156 extern char Lua_WeaponTypes_Name[];
157 typedef L_EnumContainer<Lua_WeaponTypes_Name, Lua_WeaponType> Lua_WeaponTypes;
158
159
Lua_HUDColor_Lookup(lua_State * L,int pos,int idx,const char * name1,const char * name2)160 static float Lua_HUDColor_Lookup(lua_State *L, int pos, int idx, const char *name1, const char *name2)
161 {
162 float ret = 1.0f;
163
164 lua_pushstring(L, name1);
165 lua_gettable(L, pos);
166 if (lua_isnil(L, -1))
167 {
168 lua_pop(L, 1);
169 lua_pushstring(L, name2);
170 lua_gettable(L, pos);
171 }
172 if (lua_isnil(L, -1))
173 {
174 lua_pop(L, 1);
175 lua_pushinteger(L, idx);
176 lua_gettable(L, pos);
177 }
178 if (!lua_isnil(L, -1))
179 ret = static_cast<float>(lua_tonumber(L, -1));
180 lua_pop(L, 1);
181 return ret;
182 }
183
Lua_HUDColor_Get_R(lua_State * L,int pos)184 static float Lua_HUDColor_Get_R(lua_State *L, int pos)
185 {
186 return Lua_HUDColor_Lookup(L, pos, 1, "r", "red");
187 }
188
Lua_HUDColor_Get_G(lua_State * L,int pos)189 static float Lua_HUDColor_Get_G(lua_State *L, int pos)
190 {
191 return Lua_HUDColor_Lookup(L, pos, 2, "g", "green");
192 }
193
Lua_HUDColor_Get_B(lua_State * L,int pos)194 static float Lua_HUDColor_Get_B(lua_State *L, int pos)
195 {
196 return Lua_HUDColor_Lookup(L, pos, 3, "b", "blue");
197 }
198
Lua_HUDColor_Get_A(lua_State * L,int pos)199 static float Lua_HUDColor_Get_A(lua_State *L, int pos)
200 {
201 return Lua_HUDColor_Lookup(L, pos, 4, "a", "alpha");
202 }
203
204
205 char Lua_Image_Name[] = "image";
206 typedef L_ObjectClass<Lua_Image_Name, Image_Blitter *> Lua_Image;
207
208 char Lua_Image_Crop_Rect_Name[] = "image_crop_rect";
209 class Lua_Image_Crop_Rect : public L_Class<Lua_Image_Crop_Rect_Name>
210 {
211 public:
212 static Image_Blitter *Object(lua_State *L, int index);
213 };
214
Object(lua_State * L,int index)215 Image_Blitter *Lua_Image_Crop_Rect::Object(lua_State *L, int index)
216 {
217 return Lua_Image::ObjectAtIndex(L, Lua_Image_Crop_Rect::Index(L, index));
218 }
219
Lua_Image_Crop_Rect_Get_X(lua_State * L)220 static int Lua_Image_Crop_Rect_Get_X(lua_State *L)
221 {
222 lua_pushnumber(L, Lua_Image_Crop_Rect::Object(L, 1)->crop_rect.x);
223 return 1;
224 }
225
Lua_Image_Crop_Rect_Get_Y(lua_State * L)226 static int Lua_Image_Crop_Rect_Get_Y(lua_State *L)
227 {
228 lua_pushnumber(L, Lua_Image_Crop_Rect::Object(L, 1)->crop_rect.y);
229 return 1;
230 }
231
Lua_Image_Crop_Rect_Get_Width(lua_State * L)232 static int Lua_Image_Crop_Rect_Get_Width(lua_State *L)
233 {
234 lua_pushnumber(L, Lua_Image_Crop_Rect::Object(L, 1)->crop_rect.w);
235 return 1;
236 }
237
Lua_Image_Crop_Rect_Get_Height(lua_State * L)238 static int Lua_Image_Crop_Rect_Get_Height(lua_State *L)
239 {
240 lua_pushnumber(L, Lua_Image_Crop_Rect::Object(L, 1)->crop_rect.h);
241 return 1;
242 }
243
Lua_Image_Crop_Rect_Set_X(lua_State * L)244 static int Lua_Image_Crop_Rect_Set_X(lua_State *L)
245 {
246 Lua_Image_Crop_Rect::Object(L, 1)->crop_rect.x = lua_tonumber(L, 2);
247 return 0;
248 }
249
Lua_Image_Crop_Rect_Set_Y(lua_State * L)250 static int Lua_Image_Crop_Rect_Set_Y(lua_State *L)
251 {
252 Lua_Image_Crop_Rect::Object(L, 1)->crop_rect.y = lua_tonumber(L, 2);
253 return 0;
254 }
255
Lua_Image_Crop_Rect_Set_Width(lua_State * L)256 static int Lua_Image_Crop_Rect_Set_Width(lua_State *L)
257 {
258 Lua_Image_Crop_Rect::Object(L, 1)->crop_rect.w = lua_tonumber(L, 2);
259 return 0;
260 }
261
Lua_Image_Crop_Rect_Set_Height(lua_State * L)262 static int Lua_Image_Crop_Rect_Set_Height(lua_State *L)
263 {
264 Lua_Image_Crop_Rect::Object(L, 1)->crop_rect.h = lua_tonumber(L, 2);
265 return 0;
266 }
267
268 const luaL_Reg Lua_Image_Crop_Rect_Get[] = {
269 {"x", Lua_Image_Crop_Rect_Get_X},
270 {"y", Lua_Image_Crop_Rect_Get_Y},
271 {"width", Lua_Image_Crop_Rect_Get_Width},
272 {"height", Lua_Image_Crop_Rect_Get_Height},
273 {0, 0}
274 };
275
276 const luaL_Reg Lua_Image_Crop_Rect_Set[] = {
277 {"x", Lua_Image_Crop_Rect_Set_X},
278 {"y", Lua_Image_Crop_Rect_Set_Y},
279 {"width", Lua_Image_Crop_Rect_Set_Width},
280 {"height", Lua_Image_Crop_Rect_Set_Height},
281 {0, 0}
282 };
283
284
Lua_Image_Get_Width(lua_State * L)285 static int Lua_Image_Get_Width(lua_State *L)
286 {
287 lua_pushnumber(L, Lua_Image::Object(L, 1)->Width());
288 return 1;
289 }
290
Lua_Image_Get_Height(lua_State * L)291 static int Lua_Image_Get_Height(lua_State *L)
292 {
293 lua_pushnumber(L, Lua_Image::Object(L, 1)->Height());
294 return 1;
295 }
296
Lua_Image_Get_Unscaled_Width(lua_State * L)297 static int Lua_Image_Get_Unscaled_Width(lua_State *L)
298 {
299 lua_pushnumber(L, Lua_Image::Object(L, 1)->UnscaledWidth());
300 return 1;
301 }
302
Lua_Image_Get_Unscaled_Height(lua_State * L)303 static int Lua_Image_Get_Unscaled_Height(lua_State *L)
304 {
305 lua_pushnumber(L, Lua_Image::Object(L, 1)->UnscaledHeight());
306 return 1;
307 }
308
Lua_Image_Get_Tint(lua_State * L)309 static int Lua_Image_Get_Tint(lua_State *L)
310 {
311 lua_newtable(L);
312 lua_pushstring(L, "r");
313 lua_pushnumber(L, Lua_Image::Object(L, 1)->tint_color_r);
314 lua_settable(L, -3);
315 lua_pushstring(L, "g");
316 lua_pushnumber(L, Lua_Image::Object(L, 1)->tint_color_g);
317 lua_settable(L, -3);
318 lua_pushstring(L, "b");
319 lua_pushnumber(L, Lua_Image::Object(L, 1)->tint_color_b);
320 lua_settable(L, -3);
321 lua_pushstring(L, "a");
322 lua_pushnumber(L, Lua_Image::Object(L, 1)->tint_color_a);
323 lua_settable(L, -3);
324 return 1;
325 }
326
327
Lua_Image_Get_Rotation(lua_State * L)328 static int Lua_Image_Get_Rotation(lua_State *L)
329 {
330 lua_pushnumber(L, Lua_Image::Object(L, 1)->rotation);
331 return 1;
332 }
333
Lua_Image_Get_Crop_Rect(lua_State * L)334 static int Lua_Image_Get_Crop_Rect(lua_State *L)
335 {
336 Lua_Image_Crop_Rect::Push(L, Lua_Image::Index(L, 1));
337 return 1;
338 }
339
Lua_Image_Rescale(lua_State * L)340 int Lua_Image_Rescale(lua_State *L)
341 {
342 Lua_Image::Object(L, 1)->Rescale(lua_tonumber(L, 2), lua_tonumber(L, 3));
343 return 0;
344 }
345
Lua_Image_Draw(lua_State * L)346 int Lua_Image_Draw(lua_State *L)
347 {
348 Lua_HUDInstance()->draw_image(Lua_Image::Object(L, 1), lua_tonumber(L, 2), lua_tonumber(L, 3));
349 return 0;
350 }
351
352 const luaL_Reg Lua_Image_Get[] = {
353 {"width", Lua_Image_Get_Width},
354 {"height", Lua_Image_Get_Height},
355 {"unscaled_width", Lua_Image_Get_Unscaled_Width},
356 {"unscaled_height", Lua_Image_Get_Unscaled_Height},
357 {"tint_color", Lua_Image_Get_Tint},
358 {"rotation", Lua_Image_Get_Rotation},
359 {"crop_rect", Lua_Image_Get_Crop_Rect},
360 {"rescale", L_TableFunction<Lua_Image_Rescale>},
361 {"draw", L_TableFunction<Lua_Image_Draw>},
362 {0, 0}
363 };
364
Lua_Image_Set_Tint(lua_State * L)365 static int Lua_Image_Set_Tint(lua_State *L)
366 {
367 Lua_Image::Object(L, 1)->tint_color_r = Lua_HUDColor_Get_R(L, 2);
368 Lua_Image::Object(L, 1)->tint_color_g = Lua_HUDColor_Get_G(L, 2);
369 Lua_Image::Object(L, 1)->tint_color_b = Lua_HUDColor_Get_B(L, 2);
370 Lua_Image::Object(L, 1)->tint_color_a = Lua_HUDColor_Get_A(L, 2);
371 return 0;
372 }
373
Lua_Image_Set_Rotation(lua_State * L)374 static int Lua_Image_Set_Rotation(lua_State *L)
375 {
376 Lua_Image::Object(L, 1)->rotation = lua_tonumber(L, 2);
377 return 0;
378 }
379
380 const luaL_Reg Lua_Image_Set[] = {
381 {"tint_color", Lua_Image_Set_Tint},
382 {"rotation", Lua_Image_Set_Rotation},
383 {0, 0}
384 };
385
Lua_Image_GC(lua_State * L)386 static int Lua_Image_GC(lua_State *L)
387 {
388 delete Lua_Image::Object(L, 1);
389 Lua_Image::Invalidate(L, Lua_Image::Index(L, 1));
390 return 0;
391 }
392
393 const luaL_Reg Lua_Image_Metatable[] = {
394 {"__gc", Lua_Image_GC},
395 {0, 0}
396 };
397
398 char Lua_Images_Name[] = "Images";
399 typedef L_Class<Lua_Images_Name> Lua_Images;
400
Lua_Images_New(lua_State * L)401 int Lua_Images_New(lua_State *L)
402 {
403 // read resource argument
404 lua_pushstring(L, "resource");
405 lua_gettable(L, 1);
406 if (!lua_isnil(L, -1))
407 {
408 int resource_id = lua_tointeger(L, -1);
409
410 // blitter from image
411 #ifdef HAVE_OPENGL
412 Image_Blitter *blitter = (get_screen_mode()->acceleration != _no_acceleration) ? new OGL_Blitter() : new Image_Blitter();
413 #else
414 Image_Blitter *blitter = new Image_Blitter();
415 #endif
416 if (!blitter->Load(resource_id))
417 {
418 lua_pushnil(L);
419 delete blitter;
420 return 1;
421 }
422 Lua_Image::Push(L, blitter);
423 return 1;
424 }
425
426 // read path argument
427 char path[256] = "";
428 lua_pushstring(L, "path");
429 lua_gettable(L, 1);
430 if (lua_isstring(L, -1))
431 {
432 strncpy(path, lua_tostring(L, -1), 256);
433 path[255] = 0;
434 }
435 lua_pop(L, 1);
436 // path is required
437 if (!strlen(path))
438 {
439 lua_pushnil(L);
440 return 1;
441 }
442
443 // read mask argument
444 char mask[256] = "";
445 lua_pushstring(L, "mask");
446 lua_gettable(L, 1);
447 if (lua_isstring(L, -1))
448 {
449 strncpy(mask, lua_tostring(L, -1), 256);
450 path[255] = 0;
451 }
452 lua_pop(L, 1);
453
454 std::string search_path = L_Get_Search_Path(L);
455
456 // path into file spec
457 FileSpecifier File;
458 if (search_path.size())
459 {
460 if (!File.SetNameWithPath(path, search_path))
461 {
462 lua_pushnil(L);
463 return 1;
464 }
465 }
466 else
467 {
468 if (!File.SetNameWithPath(path))
469 {
470 lua_pushnil(L);
471 return 1;
472 }
473 }
474
475 // image with file spec
476 ImageDescriptor image;
477 if (!image.LoadFromFile(File, ImageLoader_Colors, 0))
478 {
479 lua_pushnil(L);
480 return 1;
481 }
482
483 // mask (we don't care if it fails)
484 if (strlen(mask))
485 {
486 if (search_path.size())
487 {
488 if (File.SetNameWithPath(mask, search_path))
489 {
490 image.LoadFromFile(File, ImageLoader_Opacity, 0);
491 }
492 }
493 else
494 {
495 if (File.SetNameWithPath(mask))
496 {
497 image.LoadFromFile(File, ImageLoader_Opacity, 0);
498 }
499 }
500 }
501
502 // blitter from image
503 #ifdef HAVE_OPENGL
504 Image_Blitter *blitter = (get_screen_mode()->acceleration != _no_acceleration) ? new OGL_Blitter() : new Image_Blitter();
505 #else
506 Image_Blitter *blitter = new Image_Blitter();
507 #endif
508 if (!blitter->Load(image))
509 {
510 lua_pushnil(L);
511 delete blitter;
512 return 1;
513 }
514 Lua_Image::Push(L, blitter);
515 return 1;
516 }
517
518 const luaL_Reg Lua_Images_Get[] = {
519 {"new", L_TableFunction<Lua_Images_New>},
520 {0, 0}
521 };
522
523
524 char Lua_Shape_Name[] = "shape";
525 typedef L_ObjectClass<Lua_Shape_Name, Shape_Blitter *> Lua_Shape;
526
527 char Lua_Shape_Crop_Rect_Name[] = "shape_crop_rect";
528 class Lua_Shape_Crop_Rect : public L_Class<Lua_Shape_Crop_Rect_Name>
529 {
530 public:
531 static Shape_Blitter *Object(lua_State *L, int index);
532 };
533
Object(lua_State * L,int index)534 Shape_Blitter *Lua_Shape_Crop_Rect::Object(lua_State *L, int index)
535 {
536 return Lua_Shape::ObjectAtIndex(L, Lua_Shape_Crop_Rect::Index(L, index));
537 }
538
Lua_Shape_Crop_Rect_Get_X(lua_State * L)539 static int Lua_Shape_Crop_Rect_Get_X(lua_State *L)
540 {
541 lua_pushnumber(L, Lua_Shape_Crop_Rect::Object(L, 1)->crop_rect.x);
542 return 1;
543 }
544
Lua_Shape_Crop_Rect_Get_Y(lua_State * L)545 static int Lua_Shape_Crop_Rect_Get_Y(lua_State *L)
546 {
547 lua_pushnumber(L, Lua_Shape_Crop_Rect::Object(L, 1)->crop_rect.y);
548 return 1;
549 }
550
Lua_Shape_Crop_Rect_Get_Width(lua_State * L)551 static int Lua_Shape_Crop_Rect_Get_Width(lua_State *L)
552 {
553 lua_pushnumber(L, Lua_Shape_Crop_Rect::Object(L, 1)->crop_rect.w);
554 return 1;
555 }
556
Lua_Shape_Crop_Rect_Get_Height(lua_State * L)557 static int Lua_Shape_Crop_Rect_Get_Height(lua_State *L)
558 {
559 lua_pushnumber(L, Lua_Shape_Crop_Rect::Object(L, 1)->crop_rect.h);
560 return 1;
561 }
562
Lua_Shape_Crop_Rect_Set_X(lua_State * L)563 static int Lua_Shape_Crop_Rect_Set_X(lua_State *L)
564 {
565 Lua_Shape_Crop_Rect::Object(L, 1)->crop_rect.x = lua_tonumber(L, 2);
566 return 0;
567 }
568
Lua_Shape_Crop_Rect_Set_Y(lua_State * L)569 static int Lua_Shape_Crop_Rect_Set_Y(lua_State *L)
570 {
571 Lua_Shape_Crop_Rect::Object(L, 1)->crop_rect.y = lua_tonumber(L, 2);
572 return 0;
573 }
574
Lua_Shape_Crop_Rect_Set_Width(lua_State * L)575 static int Lua_Shape_Crop_Rect_Set_Width(lua_State *L)
576 {
577 Lua_Shape_Crop_Rect::Object(L, 1)->crop_rect.w = lua_tonumber(L, 2);
578 return 0;
579 }
580
Lua_Shape_Crop_Rect_Set_Height(lua_State * L)581 static int Lua_Shape_Crop_Rect_Set_Height(lua_State *L)
582 {
583 Lua_Shape_Crop_Rect::Object(L, 1)->crop_rect.h = lua_tonumber(L, 2);
584 return 0;
585 }
586
587 const luaL_Reg Lua_Shape_Crop_Rect_Get[] = {
588 {"x", Lua_Shape_Crop_Rect_Get_X},
589 {"y", Lua_Shape_Crop_Rect_Get_Y},
590 {"width", Lua_Shape_Crop_Rect_Get_Width},
591 {"height", Lua_Shape_Crop_Rect_Get_Height},
592 {0, 0}
593 };
594
595 const luaL_Reg Lua_Shape_Crop_Rect_Set[] = {
596 {"x", Lua_Shape_Crop_Rect_Set_X},
597 {"y", Lua_Shape_Crop_Rect_Set_Y},
598 {"width", Lua_Shape_Crop_Rect_Set_Width},
599 {"height", Lua_Shape_Crop_Rect_Set_Height},
600 {0, 0}
601 };
602
603
Lua_Shape_Get_Width(lua_State * L)604 static int Lua_Shape_Get_Width(lua_State *L)
605 {
606 lua_pushnumber(L, Lua_Shape::Object(L, 1)->Width());
607 return 1;
608 }
609
Lua_Shape_Get_Height(lua_State * L)610 static int Lua_Shape_Get_Height(lua_State *L)
611 {
612 lua_pushnumber(L, Lua_Shape::Object(L, 1)->Height());
613 return 1;
614 }
615
Lua_Shape_Get_Unscaled_Width(lua_State * L)616 static int Lua_Shape_Get_Unscaled_Width(lua_State *L)
617 {
618 lua_pushnumber(L, Lua_Shape::Object(L, 1)->UnscaledWidth());
619 return 1;
620 }
621
Lua_Shape_Get_Unscaled_Height(lua_State * L)622 static int Lua_Shape_Get_Unscaled_Height(lua_State *L)
623 {
624 lua_pushnumber(L, Lua_Shape::Object(L, 1)->UnscaledHeight());
625 return 1;
626 }
627
Lua_Shape_Get_Tint(lua_State * L)628 static int Lua_Shape_Get_Tint(lua_State *L)
629 {
630 lua_newtable(L);
631 lua_pushstring(L, "r");
632 lua_pushnumber(L, Lua_Shape::Object(L, 1)->tint_color_r);
633 lua_settable(L, -3);
634 lua_pushstring(L, "g");
635 lua_pushnumber(L, Lua_Shape::Object(L, 1)->tint_color_g);
636 lua_settable(L, -3);
637 lua_pushstring(L, "b");
638 lua_pushnumber(L, Lua_Shape::Object(L, 1)->tint_color_b);
639 lua_settable(L, -3);
640 lua_pushstring(L, "a");
641 lua_pushnumber(L, Lua_Shape::Object(L, 1)->tint_color_a);
642 lua_settable(L, -3);
643 return 1;
644 }
645
646
Lua_Shape_Get_Rotation(lua_State * L)647 static int Lua_Shape_Get_Rotation(lua_State *L)
648 {
649 lua_pushnumber(L, Lua_Shape::Object(L, 1)->rotation);
650 return 1;
651 }
652
Lua_Shape_Get_Crop_Rect(lua_State * L)653 static int Lua_Shape_Get_Crop_Rect(lua_State *L)
654 {
655 Lua_Shape_Crop_Rect::Push(L, Lua_Shape::Index(L, 1));
656 return 1;
657 }
658
Lua_Shape_Rescale(lua_State * L)659 int Lua_Shape_Rescale(lua_State *L)
660 {
661 Lua_Shape::Object(L, 1)->Rescale(lua_tonumber(L, 2), lua_tonumber(L, 3));
662 return 0;
663 }
664
Lua_Shape_Draw(lua_State * L)665 int Lua_Shape_Draw(lua_State *L)
666 {
667 Lua_HUDInstance()->draw_shape(Lua_Shape::Object(L, 1), lua_tonumber(L, 2), lua_tonumber(L, 3));
668 return 0;
669 }
670
671 const luaL_Reg Lua_Shape_Get[] = {
672 {"width", Lua_Shape_Get_Width},
673 {"height", Lua_Shape_Get_Height},
674 {"unscaled_width", Lua_Shape_Get_Unscaled_Width},
675 {"unscaled_height", Lua_Shape_Get_Unscaled_Height},
676 {"tint_color", Lua_Shape_Get_Tint},
677 {"rotation", Lua_Shape_Get_Rotation},
678 {"crop_rect", Lua_Shape_Get_Crop_Rect},
679 {"rescale", L_TableFunction<Lua_Shape_Rescale>},
680 {"draw", L_TableFunction<Lua_Shape_Draw>},
681 {0, 0}
682 };
683
Lua_Shape_Set_Tint(lua_State * L)684 static int Lua_Shape_Set_Tint(lua_State *L)
685 {
686 Lua_Shape::Object(L, 1)->tint_color_r = Lua_HUDColor_Get_R(L, 2);
687 Lua_Shape::Object(L, 1)->tint_color_g = Lua_HUDColor_Get_G(L, 2);
688 Lua_Shape::Object(L, 1)->tint_color_b = Lua_HUDColor_Get_B(L, 2);
689 Lua_Shape::Object(L, 1)->tint_color_a = Lua_HUDColor_Get_A(L, 2);
690 return 0;
691 }
692
Lua_Shape_Set_Rotation(lua_State * L)693 static int Lua_Shape_Set_Rotation(lua_State *L)
694 {
695 Lua_Shape::Object(L, 1)->rotation = lua_tonumber(L, 2);
696 return 0;
697 }
698
699 const luaL_Reg Lua_Shape_Set[] = {
700 {"tint_color", Lua_Shape_Set_Tint},
701 {"rotation", Lua_Shape_Set_Rotation},
702 {0, 0}
703 };
704
Lua_Shape_GC(lua_State * L)705 static int Lua_Shape_GC(lua_State *L)
706 {
707 delete Lua_Shape::Object(L, 1);
708 Lua_Shape::Invalidate(L, Lua_Shape::Index(L, 1));
709 return 0;
710 }
711
712 const luaL_Reg Lua_Shape_Metatable[] = {
713 {"__gc", Lua_Shape_GC},
714 {0, 0}
715 };
716
717 char Lua_Shapes_Name[] = "Shapes";
718 typedef L_Class<Lua_Shapes_Name> Lua_Shapes;
719
Lua_Shapes_New(lua_State * L)720 int Lua_Shapes_New(lua_State *L)
721 {
722 // read collection argument
723 short collection_index = NONE;
724 lua_pushstring(L, "collection");
725 lua_gettable(L, 1);
726 if (!lua_isnil(L, -1))
727 collection_index = Lua_Collection::ToIndex(L, -1);
728 lua_pop(L, 1);
729
730 // read texture_index argument
731 short texture_index = NONE;
732 lua_pushstring(L, "texture_index");
733 lua_gettable(L, 1);
734 if (!lua_isnil(L, -1))
735 {
736 texture_index = static_cast<short>(lua_tonumber(L, 2));
737 if (texture_index < 0 || texture_index >= MAXIMUM_SHAPES_PER_COLLECTION)
738 return luaL_error(L, "texture_index: invalid texture index");
739 }
740 lua_pop(L, 1);
741
742 // read type argument
743 short texture_type = 0;
744 lua_pushstring(L, "type");
745 lua_gettable(L, 1);
746 if (!lua_isnil(L, -1))
747 texture_type = Lua_TextureType::ToIndex(L, -1);
748 lua_pop(L, 1);
749
750 // read texture_index argument
751 short clut_index = 0;
752 lua_pushstring(L, "color_table");
753 lua_gettable(L, 1);
754 if (!lua_isnil(L, -1))
755 {
756 clut_index = static_cast<short>(lua_tonumber(L, 2));
757 if (clut_index < 0 || clut_index >= MAXIMUM_CLUTS_PER_COLLECTION)
758 return luaL_error(L, "color_table: invalid clut index");
759 }
760 lua_pop(L, 1);
761
762 // blitter from shape info
763 Shape_Blitter *blitter = new Shape_Blitter(collection_index, texture_index, texture_type, clut_index);
764 if (!blitter->Width())
765 {
766 lua_pushnil(L);
767 delete blitter;
768 return 1;
769 }
770 Lua_Shape::Push(L, blitter);
771 return 1;
772 }
773
774 const luaL_Reg Lua_Shapes_Get[] = {
775 {"new", L_TableFunction<Lua_Shapes_New>},
776 {0, 0}
777 };
778
779
780 char Lua_Font_Name[] = "font"; // "font"
781 class Lua_Font : public L_ObjectClass<Lua_Font_Name, FontSpecifier *>
782 {
783 public:
784 float m_font_scale;
785
786 static Lua_Font *Push(lua_State *L, FontSpecifier *fs);
787 static float Scale(lua_State *L, int index);
788 static void SetScale(lua_State *L, int index, float new_scale);
789 };
790
Push(lua_State * L,FontSpecifier * fs)791 Lua_Font *Lua_Font::Push(lua_State *L, FontSpecifier *fs)
792 {
793 Lua_Font *t = L_ObjectClass::Push<Lua_Font>(L, fs);
794 if (t)
795 {
796 t->m_font_scale = 1.0;
797 }
798
799 return t;
800 }
801
Scale(lua_State * L,int index)802 float Lua_Font::Scale(lua_State *L, int index)
803 {
804 Lua_Font *t = static_cast<Lua_Font *>(Instance(L, index));
805 if (!t) luaL_typerror(L, index, Lua_Font_Name);
806 return t->m_font_scale;
807 }
808
SetScale(lua_State * L,int index,float new_scale)809 void Lua_Font::SetScale(lua_State *L, int index, float new_scale)
810 {
811 Lua_Font *t = static_cast<Lua_Font *>(Instance(L, index));
812 if (!t) luaL_typerror(L, index, Lua_Font_Name);
813 t->m_font_scale = new_scale;
814 }
815
Lua_Font_Measure_Text(lua_State * L)816 int Lua_Font_Measure_Text(lua_State *L)
817 {
818 if (!lua_isstring(L, 2))
819 luaL_error(L, "measure_text: incorrect argument type");
820
821 lua_pushnumber(L, Lua_Font::Object(L, 1)->TextWidth(lua_tostring(L, 2)) * Lua_Font::Scale(L, 1));
822 lua_pushnumber(L, Lua_Font::Object(L, 1)->LineSpacing * Lua_Font::Scale(L, 1));
823 return 2;
824 }
825
Lua_Font_Draw_Text(lua_State * L)826 int Lua_Font_Draw_Text(lua_State *L)
827 {
828 if (!lua_isstring(L, 2))
829 luaL_error(L, "draw_text: incorrect argument type");
830
831 const char *str = lua_tostring(L, 2);
832 float x = static_cast<float>(lua_tonumber(L, 3));
833 float y = static_cast<float>(lua_tonumber(L, 4));
834 float r = Lua_HUDColor_Get_R(L, 5);
835 float g = Lua_HUDColor_Get_G(L, 5);
836 float b = Lua_HUDColor_Get_B(L, 5);
837 float a = Lua_HUDColor_Get_A(L, 5);
838
839 Lua_HUDInstance()->draw_text(Lua_Font::Object(L, 1),
840 str,
841 x, y, r, g, b, a,
842 Lua_Font::Scale(L, 1));
843 return 0;
844 }
845
Lua_Font_Get_Size(lua_State * L)846 static int Lua_Font_Get_Size(lua_State *L)
847 {
848 lua_pushnumber(L, Lua_Font::Object(L, 1)->Size * Lua_Font::Scale(L, 1));
849 return 1;
850 }
851
Lua_Font_Get_Style(lua_State * L)852 static int Lua_Font_Get_Style(lua_State *L)
853 {
854 lua_pushnumber(L, Lua_Font::Object(L, 1)->Style);
855 return 1;
856 }
857
Lua_Font_Get_File(lua_State * L)858 static int Lua_Font_Get_File(lua_State *L)
859 {
860 const std::string& f = Lua_Font::Object(L, 1)->File;
861 if (f[0] == '#')
862 lua_pushnil(L);
863 else
864 lua_pushstring(L, f.c_str());
865 return 1;
866 }
867
Lua_Font_Get_ID(lua_State * L)868 static int Lua_Font_Get_ID(lua_State *L)
869 {
870 lua_pushnil(L);
871 return 1;
872 }
873
Lua_Font_Get_Line_Height(lua_State * L)874 static int Lua_Font_Get_Line_Height(lua_State *L)
875 {
876 lua_pushnumber(L, Lua_Font::Object(L, 1)->LineSpacing * Lua_Font::Scale(L, 1));
877 return 1;
878 }
879
Lua_Font_Get_Scale(lua_State * L)880 static int Lua_Font_Get_Scale(lua_State *L)
881 {
882 lua_pushnumber(L, Lua_Font::Scale(L, 1));
883 return 1;
884 }
885
886 const luaL_Reg Lua_Font_Get[] = {
887 {"size", Lua_Font_Get_Size},
888 {"style", Lua_Font_Get_Style},
889 {"file", Lua_Font_Get_File},
890 {"id", Lua_Font_Get_ID},
891 {"line_height", Lua_Font_Get_Line_Height},
892 {"scale", Lua_Font_Get_Scale},
893 {"measure_text", L_TableFunction<Lua_Font_Measure_Text>},
894 {"draw_text", L_TableFunction<Lua_Font_Draw_Text>},
895 {0, 0}
896 };
897
Lua_Font_Set_Scale(lua_State * L)898 static int Lua_Font_Set_Scale(lua_State *L)
899 {
900 Lua_Font::SetScale(L, 1, lua_tonumber(L, 2));
901 return 0;
902 }
903
904 const luaL_Reg Lua_Font_Set[] = {
905 {"scale", Lua_Font_Set_Scale},
906 {0, 0}
907 };
908
Lua_Font_GC(lua_State * L)909 static int Lua_Font_GC(lua_State *L)
910 {
911 delete Lua_Font::Object(L, 1);
912 Lua_Font::Invalidate(L, Lua_Font::Index(L, 1));
913 return 0;
914 }
915
916 const luaL_Reg Lua_Font_Metatable[] = {
917 {"__gc", Lua_Font_GC},
918 {0, 0}
919 };
920
921
922 char Lua_Fonts_Name[] = "Fonts"; // "Fonts"
923 typedef L_Class<Lua_Fonts_Name> Lua_Fonts;
924
Lua_Fonts_New(lua_State * L)925 int Lua_Fonts_New(lua_State *L)
926 {
927 FontSpecifier f = {"Monaco", 12, styleNormal, 0, "mono"};
928
929 lua_pushstring(L, "interface");
930 lua_gettable(L, 1);
931 if (!lua_isnil(L, -1))
932 f = get_interface_font(Lua_InterfaceFont::ToIndex(L, -1));
933 lua_pop(L, 1);
934
935 lua_pushstring(L, "file");
936 lua_gettable(L, 1);
937 if (lua_isstring(L, -1))
938 {
939 f.File = lua_tostring(L, -1);
940 }
941 lua_pop(L, 1);
942
943 lua_pushstring(L, "size");
944 lua_gettable(L, 1);
945 if (!lua_isnil(L, -1))
946 f.Size = lua_tointeger(L, -1);
947 lua_pop(L, 1);
948
949 lua_pushstring(L, "style");
950 lua_gettable(L, 1);
951 if (!lua_isnil(L, -1))
952 f.Style = lua_tointeger(L, -1);
953 lua_pop(L, 1);
954
955 std::string search_path = L_Get_Search_Path(L);
956 std::unique_ptr<ScopedSearchPath> ssp;
957 if (search_path.size())
958 {
959 ssp.reset(new ScopedSearchPath(DirectorySpecifier(search_path)));
960 }
961
962 FontSpecifier *ff = new FontSpecifier(f);
963 ff->Init();
964 #ifdef HAVE_OPENGL
965 if (alephone::Screen::instance()->openGL())
966 ff->OGL_Reset(true);
967 #endif
968 if (ff->LineSpacing <= 0)
969 {
970 lua_pushnil(L);
971 delete ff;
972 return 1;
973 }
974
975 Lua_Font::Push(L, ff);
976 return 1;
977 }
978
979 const luaL_Reg Lua_Fonts_Get[] = {
980 {"new", L_TableFunction<Lua_Fonts_New>},
981 {0, 0}
982 };
983
984
985 char Lua_HUDPlayer_Item_Name[] = "item";
986 typedef L_Class<Lua_HUDPlayer_Item_Name> Lua_HUDPlayer_Item;
987
Lua_HUDPlayer_Item_Get_Count(lua_State * L)988 static int Lua_HUDPlayer_Item_Get_Count(lua_State *L)
989 {
990 int item_type = Lua_HUDPlayer_Item::Index(L, 1);
991
992 int item_count = current_player->items[item_type];
993 if (item_count == NONE) item_count = 0;
994 lua_pushnumber(L, item_count);
995 return 1;
996 }
997
Lua_HUDPlayer_Item_Get_Section(lua_State * L)998 static int Lua_HUDPlayer_Item_Get_Section(lua_State *L)
999 {
1000 int item_type = Lua_HUDPlayer_Item::Index(L, 1);
1001
1002 Lua_InventorySection::Push(L, get_item_kind(item_type));
1003 return 1;
1004 }
1005
Lua_HUDPlayer_Item_Get_Singular(lua_State * L)1006 static int Lua_HUDPlayer_Item_Get_Singular(lua_State *L)
1007 {
1008 int item_type = Lua_HUDPlayer_Item::Index(L, 1);
1009 char tmp[256];
1010 tmp[0] = 0;
1011 get_item_name(tmp, item_type, false);
1012 lua_pushstring(L, tmp);
1013 return 1;
1014 }
1015
Lua_HUDPlayer_Item_Get_Plural(lua_State * L)1016 static int Lua_HUDPlayer_Item_Get_Plural(lua_State *L)
1017 {
1018 int item_type = Lua_HUDPlayer_Item::Index(L, 1);
1019 char tmp[256];
1020 tmp[0] = 0;
1021 get_item_name(tmp, item_type, true);
1022 lua_pushstring(L, tmp);
1023 return 1;
1024 }
1025
Lua_HUDPlayer_Item_Get_Type(lua_State * L)1026 static int Lua_HUDPlayer_Item_Get_Type(lua_State *L)
1027 {
1028 Lua_ItemType::Push(L, Lua_HUDPlayer_Item::Index(L, 1));
1029 return 1;
1030 }
1031
Lua_HUDPlayer_Item_Get_Valid(lua_State * L)1032 static int Lua_HUDPlayer_Item_Get_Valid(lua_State *L)
1033 {
1034 int item_type = Lua_HUDPlayer_Item::Index(L, 1);
1035 lua_pushboolean(L, item_valid_in_current_environment(item_type));
1036 return 1;
1037 }
1038
1039 const luaL_Reg Lua_HUDPlayer_Item_Get[] = {
1040 {"count", Lua_HUDPlayer_Item_Get_Count},
1041 {"inventory_section", Lua_HUDPlayer_Item_Get_Section},
1042 {"singular", Lua_HUDPlayer_Item_Get_Singular},
1043 {"plural", Lua_HUDPlayer_Item_Get_Plural},
1044 {"type", Lua_HUDPlayer_Item_Get_Type},
1045 {"valid", Lua_HUDPlayer_Item_Get_Valid},
1046 {0, 0}
1047 };
1048
1049
1050
1051 char Lua_HUDPlayer_Items_Name[] = "player_items";
1052 typedef L_Class<Lua_HUDPlayer_Items_Name> Lua_HUDPlayer_Items;
1053
Lua_HUDPlayer_Items_Get(lua_State * L)1054 static int Lua_HUDPlayer_Items_Get(lua_State *L)
1055 {
1056 Lua_HUDPlayer_Item::Push(L, Lua_ItemType::ToIndex(L, 2));
1057 return 1;
1058 }
1059
Lua_HUDPlayer_Items_Length(lua_State * L)1060 static int Lua_HUDPlayer_Items_Length(lua_State *L)
1061 {
1062 lua_pushnumber(L, NUMBER_OF_DEFINED_ITEMS);
1063 return 1;
1064 }
1065
1066 const luaL_Reg Lua_HUDPlayer_Items_Metatable[] = {
1067 {"__index", Lua_HUDPlayer_Items_Get},
1068 {"__len", Lua_HUDPlayer_Items_Length},
1069 {0, 0}
1070 };
1071
1072 char Lua_HUDPlayer_Weapon_Trigger_Bullet_Name[] = "player_weapon_trigger_bullet";
1073 class Lua_HUDPlayer_Weapon_Trigger_Bullet : public L_Class<Lua_HUDPlayer_Weapon_Trigger_Bullet_Name>
1074 {
1075 public:
1076 int16 m_weapon_index;
1077
1078 static Lua_HUDPlayer_Weapon_Trigger_Bullet *Push(lua_State *L, int16 weapon_index, int16 index);
1079 static int16 WeaponIndex(lua_State *L, int index);
1080 static struct weapon_interface_ammo_data *AmmoData(lua_State *L, int index);
1081 };
1082
Push(lua_State * L,int16 weapon_index,int16 index)1083 Lua_HUDPlayer_Weapon_Trigger_Bullet *Lua_HUDPlayer_Weapon_Trigger_Bullet::Push(lua_State *L, int16 weapon_index, int16 index)
1084 {
1085 Lua_HUDPlayer_Weapon_Trigger_Bullet *t = L_Class::Push<Lua_HUDPlayer_Weapon_Trigger_Bullet>(L, index);
1086 if (t)
1087 {
1088 t->m_weapon_index = weapon_index;
1089 }
1090
1091 return t;
1092 }
1093
WeaponIndex(lua_State * L,int index)1094 int16 Lua_HUDPlayer_Weapon_Trigger_Bullet::WeaponIndex(lua_State *L, int index)
1095 {
1096 Lua_HUDPlayer_Weapon_Trigger_Bullet *t = static_cast<Lua_HUDPlayer_Weapon_Trigger_Bullet*>(Instance(L, index));
1097 if (!t) luaL_typerror(L, index, Lua_HUDPlayer_Weapon_Trigger_Bullet_Name);
1098 return t->m_weapon_index;
1099 }
1100
AmmoData(lua_State * L,int index)1101 struct weapon_interface_ammo_data *Lua_HUDPlayer_Weapon_Trigger_Bullet::AmmoData(lua_State *L, int index)
1102 {
1103 return &weapon_interface_definitions[Lua_HUDPlayer_Weapon_Trigger_Bullet::WeaponIndex(L, index)]
1104 .ammo_data[Lua_HUDPlayer_Weapon_Trigger_Bullet::Index(L, index)];
1105 }
1106
Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_X(lua_State * L)1107 static int Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_X(lua_State *L)
1108 {
1109 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Bullet::AmmoData(L, 1);
1110 lua_pushinteger(L, wia->screen_left);
1111 return 1;
1112 }
1113
Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Y(lua_State * L)1114 static int Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Y(lua_State *L)
1115 {
1116 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Bullet::AmmoData(L, 1);
1117 lua_pushinteger(L, wia->screen_top);
1118 return 1;
1119 }
1120
Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Width(lua_State * L)1121 static int Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Width(lua_State *L)
1122 {
1123 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Bullet::AmmoData(L, 1);
1124 lua_pushinteger(L, wia->delta_x);
1125 return 1;
1126 }
1127
Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Height(lua_State * L)1128 static int Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Height(lua_State *L)
1129 {
1130 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Bullet::AmmoData(L, 1);
1131 lua_pushinteger(L, wia->delta_y);
1132 return 1;
1133 }
1134
Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Across(lua_State * L)1135 static int Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Across(lua_State *L)
1136 {
1137 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Bullet::AmmoData(L, 1);
1138 lua_pushinteger(L, wia->ammo_across);
1139 return 1;
1140 }
1141
Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Down(lua_State * L)1142 static int Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Down(lua_State *L)
1143 {
1144 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Bullet::AmmoData(L, 1);
1145 lua_pushinteger(L, wia->ammo_down);
1146 return 1;
1147 }
1148
Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_RTL(lua_State * L)1149 static int Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_RTL(lua_State *L)
1150 {
1151 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Bullet::AmmoData(L, 1);
1152 lua_pushboolean(L, wia->right_to_left);
1153 return 1;
1154 }
1155
Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Frame(lua_State * L)1156 static int Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Frame(lua_State *L)
1157 {
1158 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Bullet::AmmoData(L, 1);
1159 if (wia->bullet == UNONE)
1160 lua_pushnil(L);
1161 else
1162 lua_pushinteger(L, wia->bullet);
1163 return 1;
1164 }
1165
Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Empty_Frame(lua_State * L)1166 static int Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Empty_Frame(lua_State *L)
1167 {
1168 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Bullet::AmmoData(L, 1);
1169 if (wia->empty_bullet == UNONE)
1170 lua_pushnil(L);
1171 else
1172 lua_pushinteger(L, wia->empty_bullet);
1173 return 1;
1174 }
1175
1176 const luaL_Reg Lua_HUDPlayer_Weapon_Trigger_Bullet_Get[] = {
1177 {"x", Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_X},
1178 {"y", Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Y},
1179 {"width", Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Width},
1180 {"height", Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Height},
1181 {"across", Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Across},
1182 {"down", Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Down},
1183 {"right_to_left", Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_RTL},
1184 {"texture_index", Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Frame},
1185 {"empty_texture_index", Lua_HUDPlayer_Weapon_Trigger_Bullet_Get_Empty_Frame},
1186 {0, 0}
1187 };
1188
1189
1190 char Lua_HUDPlayer_Weapon_Trigger_Energy_Name[] = "player_weapon_trigger_energy";
1191 class Lua_HUDPlayer_Weapon_Trigger_Energy : public L_Class<Lua_HUDPlayer_Weapon_Trigger_Energy_Name>
1192 {
1193 public:
1194 int16 m_weapon_index;
1195
1196 static Lua_HUDPlayer_Weapon_Trigger_Energy *Push(lua_State *L, int16 weapon_index, int16 index);
1197 static int16 WeaponIndex(lua_State *L, int index);
1198 static struct weapon_interface_ammo_data *AmmoData(lua_State *L, int index);
1199 };
1200
Push(lua_State * L,int16 weapon_index,int16 index)1201 Lua_HUDPlayer_Weapon_Trigger_Energy *Lua_HUDPlayer_Weapon_Trigger_Energy::Push(lua_State *L, int16 weapon_index, int16 index)
1202 {
1203 Lua_HUDPlayer_Weapon_Trigger_Energy *t = L_Class::Push<Lua_HUDPlayer_Weapon_Trigger_Energy>(L, index);
1204 if (t)
1205 {
1206 t->m_weapon_index = weapon_index;
1207 }
1208
1209 return t;
1210 }
1211
WeaponIndex(lua_State * L,int index)1212 int16 Lua_HUDPlayer_Weapon_Trigger_Energy::WeaponIndex(lua_State *L, int index)
1213 {
1214 Lua_HUDPlayer_Weapon_Trigger_Energy *t = static_cast<Lua_HUDPlayer_Weapon_Trigger_Energy*>(Instance(L, index));
1215 if (!t) luaL_typerror(L, index, Lua_HUDPlayer_Weapon_Trigger_Energy_Name);
1216 return t->m_weapon_index;
1217 }
1218
AmmoData(lua_State * L,int index)1219 struct weapon_interface_ammo_data *Lua_HUDPlayer_Weapon_Trigger_Energy::AmmoData(lua_State *L, int index)
1220 {
1221 return &weapon_interface_definitions[Lua_HUDPlayer_Weapon_Trigger_Energy::WeaponIndex(L, index)]
1222 .ammo_data[Lua_HUDPlayer_Weapon_Trigger_Energy::Index(L, index)];
1223 }
1224
Lua_HUDPlayer_Weapon_Trigger_Energy_Get_X(lua_State * L)1225 static int Lua_HUDPlayer_Weapon_Trigger_Energy_Get_X(lua_State *L)
1226 {
1227 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Energy::AmmoData(L, 1);
1228 lua_pushinteger(L, wia->screen_left);
1229 return 1;
1230 }
1231
Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Y(lua_State * L)1232 static int Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Y(lua_State *L)
1233 {
1234 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Energy::AmmoData(L, 1);
1235 lua_pushinteger(L, wia->screen_top);
1236 return 1;
1237 }
1238
Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Width(lua_State * L)1239 static int Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Width(lua_State *L)
1240 {
1241 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Energy::AmmoData(L, 1);
1242 lua_pushinteger(L, wia->delta_x);
1243 return 1;
1244 }
1245
Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Height(lua_State * L)1246 static int Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Height(lua_State *L)
1247 {
1248 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Energy::AmmoData(L, 1);
1249 lua_pushinteger(L, wia->delta_y);
1250 return 1;
1251 }
1252
Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Max(lua_State * L)1253 static int Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Max(lua_State *L)
1254 {
1255 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Energy::AmmoData(L, 1);
1256 lua_pushinteger(L, wia->ammo_across);
1257 return 1;
1258 }
1259
Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Full_Color(lua_State * L)1260 static int Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Full_Color(lua_State *L)
1261 {
1262 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Energy::AmmoData(L, 1);
1263 Lua_InterfaceColor::Push(L, wia->bullet);
1264 return 1;
1265 }
1266
Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Empty_Color(lua_State * L)1267 static int Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Empty_Color(lua_State *L)
1268 {
1269 struct weapon_interface_ammo_data *wia = Lua_HUDPlayer_Weapon_Trigger_Energy::AmmoData(L, 1);
1270 Lua_InterfaceColor::Push(L, wia->empty_bullet);
1271 return 1;
1272 }
1273
1274 const luaL_Reg Lua_HUDPlayer_Weapon_Trigger_Energy_Get[] = {
1275 {"x", Lua_HUDPlayer_Weapon_Trigger_Energy_Get_X},
1276 {"y", Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Y},
1277 {"width", Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Width},
1278 {"height", Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Height},
1279 {"maximum", Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Max},
1280 {"color", Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Full_Color},
1281 {"empty_color", Lua_HUDPlayer_Weapon_Trigger_Energy_Get_Empty_Color},
1282 {0, 0}
1283 };
1284
1285
1286 char Lua_HUDPlayer_Weapon_Trigger_Name[] = "player_weapon_trigger";
1287
1288
1289 class Lua_HUDPlayer_Weapon_Trigger : public L_Class<Lua_HUDPlayer_Weapon_Trigger_Name>
1290 {
1291 public:
1292 int16 m_weapon_index;
1293
1294 static Lua_HUDPlayer_Weapon_Trigger *Push(lua_State *L, int16 weapon_index, int16 index);
1295 static int16 WeaponIndex(lua_State *L, int index);
1296 };
1297
Push(lua_State * L,int16 weapon_index,int16 index)1298 Lua_HUDPlayer_Weapon_Trigger *Lua_HUDPlayer_Weapon_Trigger::Push(lua_State *L, int16 weapon_index, int16 index)
1299 {
1300 Lua_HUDPlayer_Weapon_Trigger *t = L_Class::Push<Lua_HUDPlayer_Weapon_Trigger>(L, index);
1301 if (t)
1302 {
1303 t->m_weapon_index = weapon_index;
1304 }
1305
1306 return t;
1307 }
1308
WeaponIndex(lua_State * L,int index)1309 int16 Lua_HUDPlayer_Weapon_Trigger::WeaponIndex(lua_State *L, int index)
1310 {
1311 Lua_HUDPlayer_Weapon_Trigger *t = static_cast<Lua_HUDPlayer_Weapon_Trigger*>(Instance(L, index));
1312 if (!t) luaL_typerror(L, index, Lua_HUDPlayer_Weapon_Trigger_Name);
1313 return t->m_weapon_index;
1314 }
1315
Lua_HUDPlayer_Weapon_Trigger_Get_Rounds(lua_State * L)1316 static int Lua_HUDPlayer_Weapon_Trigger_Get_Rounds(lua_State *L)
1317 {
1318 short rounds = get_player_weapon_ammo_count(
1319 current_player_index,
1320 Lua_HUDPlayer_Weapon_Trigger::WeaponIndex(L, 1),
1321 Lua_HUDPlayer_Weapon_Trigger::Index(L, 1));
1322 lua_pushnumber(L, rounds);
1323 return 1;
1324 }
1325
Lua_HUDPlayer_Weapon_Trigger_Get_Total_Rounds(lua_State * L)1326 static int Lua_HUDPlayer_Weapon_Trigger_Get_Total_Rounds(lua_State *L)
1327 {
1328 short rounds = get_player_weapon_ammo_maximum(
1329 current_player_index,
1330 Lua_HUDPlayer_Weapon_Trigger::WeaponIndex(L, 1),
1331 Lua_HUDPlayer_Weapon_Trigger::Index(L, 1));
1332 lua_pushnumber(L, rounds);
1333 return 1;
1334 }
1335
Lua_HUDPlayer_Weapon_Trigger_Get_Ammo_Type(lua_State * L)1336 static int Lua_HUDPlayer_Weapon_Trigger_Get_Ammo_Type(lua_State *L)
1337 {
1338 int16 t = get_player_weapon_ammo_type(
1339 current_player_index,
1340 Lua_HUDPlayer_Weapon_Trigger::WeaponIndex(L, 1),
1341 Lua_HUDPlayer_Weapon_Trigger::Index(L, 1));
1342 Lua_ItemType::Push(L, t);
1343 return 1;
1344 }
1345
Lua_HUDPlayer_Weapon_Trigger_Get_Weapon_Drawn(lua_State * L)1346 static int Lua_HUDPlayer_Weapon_Trigger_Get_Weapon_Drawn(lua_State *L)
1347 {
1348 bool t = get_player_weapon_drawn(
1349 current_player_index,
1350 Lua_HUDPlayer_Weapon_Trigger::WeaponIndex(L, 1),
1351 Lua_HUDPlayer_Weapon_Trigger::Index(L, 1));
1352 lua_pushboolean(L, t);
1353 return 1;
1354 }
1355
Lua_HUDPlayer_Weapon_Trigger_Get_Bullet(lua_State * L)1356 static int Lua_HUDPlayer_Weapon_Trigger_Get_Bullet(lua_State *L)
1357 {
1358 int wep_idx = Lua_HUDPlayer_Weapon_Trigger::WeaponIndex(L, 1);
1359 int trig_idx = Lua_HUDPlayer_Weapon_Trigger::Index(L, 1);
1360 struct weapon_interface_ammo_data *wia = &weapon_interface_definitions[wep_idx].ammo_data[trig_idx];
1361 if (wia->type == _uses_bullets)
1362 Lua_HUDPlayer_Weapon_Trigger_Bullet::Push(L, wep_idx, trig_idx);
1363 else
1364 lua_pushnil(L);
1365 return 1;
1366 }
1367
Lua_HUDPlayer_Weapon_Trigger_Get_Energy(lua_State * L)1368 static int Lua_HUDPlayer_Weapon_Trigger_Get_Energy(lua_State *L)
1369 {
1370 int wep_idx = Lua_HUDPlayer_Weapon_Trigger::WeaponIndex(L, 1);
1371 int trig_idx = Lua_HUDPlayer_Weapon_Trigger::Index(L, 1);
1372 struct weapon_interface_ammo_data *wia = &weapon_interface_definitions[wep_idx].ammo_data[trig_idx];
1373 if (wia->type == _uses_energy)
1374 Lua_HUDPlayer_Weapon_Trigger_Energy::Push(L, wep_idx, trig_idx);
1375 else
1376 lua_pushnil(L);
1377 return 1;
1378 }
1379
1380 const luaL_Reg Lua_HUDPlayer_Weapon_Trigger_Get[] = {
1381 {"rounds", Lua_HUDPlayer_Weapon_Trigger_Get_Rounds},
1382 {"total_rounds", Lua_HUDPlayer_Weapon_Trigger_Get_Total_Rounds},
1383 {"ammo_type", Lua_HUDPlayer_Weapon_Trigger_Get_Ammo_Type},
1384 {"weapon_drawn", Lua_HUDPlayer_Weapon_Trigger_Get_Weapon_Drawn},
1385 {"bullet_display", Lua_HUDPlayer_Weapon_Trigger_Get_Bullet},
1386 {"energy_display", Lua_HUDPlayer_Weapon_Trigger_Get_Energy},
1387 {0, 0}
1388 };
1389
1390 char Lua_HUDPlayer_Weapon_Name[] = "player_weapon";
1391 typedef L_Class<Lua_HUDPlayer_Weapon_Name> Lua_HUDPlayer_Weapon;
1392
1393 template<int trigger>
get_hudweapon_trigger(lua_State * L)1394 static int get_hudweapon_trigger(lua_State *L)
1395 {
1396 Lua_HUDPlayer_Weapon_Trigger::Push(L, Lua_HUDPlayer_Weapon::Index(L, 1), trigger);
1397 return 1;
1398 }
1399
1400 char Lua_HUDPlayer_Weapon_SingleShape_Name[] = "player_weapon_singleshape";
1401 typedef L_Class<Lua_HUDPlayer_Weapon_SingleShape_Name> Lua_HUDPlayer_Weapon_SingleShape;
1402
Lua_HUDPlayer_Weapon_SingleShape_Get_Frame(lua_State * L)1403 static int Lua_HUDPlayer_Weapon_SingleShape_Get_Frame(lua_State *L)
1404 {
1405 struct weapon_interface_data *wid = &weapon_interface_definitions[Lua_HUDPlayer_Weapon_SingleShape::Index(L, 1)];
1406 lua_pushinteger(L, wid->weapon_panel_shape);
1407 return 1;
1408 }
1409
Lua_HUDPlayer_Weapon_SingleShape_Get_X(lua_State * L)1410 static int Lua_HUDPlayer_Weapon_SingleShape_Get_X(lua_State *L)
1411 {
1412 struct weapon_interface_data *wid = &weapon_interface_definitions[Lua_HUDPlayer_Weapon_SingleShape::Index(L, 1)];
1413 lua_pushinteger(L, wid->standard_weapon_panel_left);
1414 return 1;
1415 }
1416
Lua_HUDPlayer_Weapon_SingleShape_Get_Y(lua_State * L)1417 static int Lua_HUDPlayer_Weapon_SingleShape_Get_Y(lua_State *L)
1418 {
1419 struct weapon_interface_data *wid = &weapon_interface_definitions[Lua_HUDPlayer_Weapon_SingleShape::Index(L, 1)];
1420 lua_pushinteger(L, wid->standard_weapon_panel_top);
1421 return 1;
1422 }
1423
1424 const luaL_Reg Lua_HUDPlayer_Weapon_SingleShape_Get[] = {
1425 {"texture_index", Lua_HUDPlayer_Weapon_SingleShape_Get_Frame},
1426 {"x", Lua_HUDPlayer_Weapon_SingleShape_Get_X},
1427 {"y", Lua_HUDPlayer_Weapon_SingleShape_Get_Y},
1428 {0, 0}
1429 };
1430
1431 char Lua_HUDPlayer_Weapon_MultShape_Name[] = "player_weapon_multshape";
1432 typedef L_Class<Lua_HUDPlayer_Weapon_MultShape_Name> Lua_HUDPlayer_Weapon_MultShape;
1433
Lua_HUDPlayer_Weapon_MultShape_Get_Frame(lua_State * L)1434 static int Lua_HUDPlayer_Weapon_MultShape_Get_Frame(lua_State *L)
1435 {
1436 struct weapon_interface_data *wid = &weapon_interface_definitions[Lua_HUDPlayer_Weapon_MultShape::Index(L, 1)];
1437 lua_pushinteger(L, wid->multiple_shape);
1438 return 1;
1439 }
1440
Lua_HUDPlayer_Weapon_MultShape_Get_X(lua_State * L)1441 static int Lua_HUDPlayer_Weapon_MultShape_Get_X(lua_State *L)
1442 {
1443 struct weapon_interface_data *wid = &weapon_interface_definitions[Lua_HUDPlayer_Weapon_MultShape::Index(L, 1)];
1444 lua_pushinteger(L, wid->standard_weapon_panel_left + wid->multiple_delta_x);
1445 return 1;
1446 }
1447
Lua_HUDPlayer_Weapon_MultShape_Get_Y(lua_State * L)1448 static int Lua_HUDPlayer_Weapon_MultShape_Get_Y(lua_State *L)
1449 {
1450 struct weapon_interface_data *wid = &weapon_interface_definitions[Lua_HUDPlayer_Weapon_MultShape::Index(L, 1)];
1451 lua_pushinteger(L, wid->standard_weapon_panel_top + wid->multiple_delta_y);
1452 return 1;
1453 }
1454
1455 const luaL_Reg Lua_HUDPlayer_Weapon_MultShape_Get[] = {
1456 {"texture_index", Lua_HUDPlayer_Weapon_MultShape_Get_Frame},
1457 {"x", Lua_HUDPlayer_Weapon_MultShape_Get_X},
1458 {"y", Lua_HUDPlayer_Weapon_MultShape_Get_Y},
1459 {0, 0}
1460 };
1461
1462 char Lua_HUDPlayer_Weapon_UnusableShape_Name[] = "player_weapon_unusableshape";
1463 typedef L_Class<Lua_HUDPlayer_Weapon_UnusableShape_Name> Lua_HUDPlayer_Weapon_UnusableShape;
1464
Lua_HUDPlayer_Weapon_UnusableShape_Get_Frame(lua_State * L)1465 static int Lua_HUDPlayer_Weapon_UnusableShape_Get_Frame(lua_State *L)
1466 {
1467 struct weapon_interface_data *wid = &weapon_interface_definitions[Lua_HUDPlayer_Weapon_UnusableShape::Index(L, 1)];
1468 lua_pushinteger(L, wid->multiple_unusable_shape);
1469 return 1;
1470 }
1471
Lua_HUDPlayer_Weapon_UnusableShape_Get_X(lua_State * L)1472 static int Lua_HUDPlayer_Weapon_UnusableShape_Get_X(lua_State *L)
1473 {
1474 struct weapon_interface_data *wid = &weapon_interface_definitions[Lua_HUDPlayer_Weapon_UnusableShape::Index(L, 1)];
1475 lua_pushinteger(L, wid->standard_weapon_panel_left + wid->multiple_delta_x);
1476 return 1;
1477 }
1478
Lua_HUDPlayer_Weapon_UnusableShape_Get_Y(lua_State * L)1479 static int Lua_HUDPlayer_Weapon_UnusableShape_Get_Y(lua_State *L)
1480 {
1481 struct weapon_interface_data *wid = &weapon_interface_definitions[Lua_HUDPlayer_Weapon_UnusableShape::Index(L, 1)];
1482 lua_pushinteger(L, wid->standard_weapon_panel_top + wid->multiple_delta_y);
1483 return 1;
1484 }
1485
1486 const luaL_Reg Lua_HUDPlayer_Weapon_UnusableShape_Get[] = {
1487 {"texture_index", Lua_HUDPlayer_Weapon_UnusableShape_Get_Frame},
1488 {"x", Lua_HUDPlayer_Weapon_UnusableShape_Get_X},
1489 {"y", Lua_HUDPlayer_Weapon_UnusableShape_Get_Y},
1490 {0, 0}
1491 };
1492
Lua_HUDPlayer_Weapon_Get_SingleShape(lua_State * L)1493 static int Lua_HUDPlayer_Weapon_Get_SingleShape(lua_State *L)
1494 {
1495 short idx = Lua_HUDPlayer_Weapon::Index(L, 1);
1496 struct weapon_interface_data *wid = &weapon_interface_definitions[idx];
1497 if (wid->weapon_panel_shape == UNONE)
1498 lua_pushnil(L);
1499 else
1500 Lua_HUDPlayer_Weapon_SingleShape::Push(L, idx);
1501 return 1;
1502 }
1503
Lua_HUDPlayer_Weapon_Get_MultShape(lua_State * L)1504 static int Lua_HUDPlayer_Weapon_Get_MultShape(lua_State *L)
1505 {
1506 short idx = Lua_HUDPlayer_Weapon::Index(L, 1);
1507 struct weapon_interface_data *wid = &weapon_interface_definitions[idx];
1508 if (!wid->multi_weapon || wid->multiple_shape == UNONE)
1509 lua_pushnil(L);
1510 else
1511 Lua_HUDPlayer_Weapon_MultShape::Push(L, idx);
1512 return 1;
1513 }
1514
Lua_HUDPlayer_Weapon_Get_UnusableShape(lua_State * L)1515 static int Lua_HUDPlayer_Weapon_Get_UnusableShape(lua_State *L)
1516 {
1517 short idx = Lua_HUDPlayer_Weapon::Index(L, 1);
1518 struct weapon_interface_data *wid = &weapon_interface_definitions[idx];
1519 if (!wid->multi_weapon || wid->multiple_unusable_shape == UNONE)
1520 lua_pushnil(L);
1521 else
1522 Lua_HUDPlayer_Weapon_UnusableShape::Push(L, idx);
1523 return 1;
1524 }
1525
1526 char Lua_HUDPlayer_Weapon_Name_Rect_Name[] = "player_weapon_name_rect";
1527 typedef L_Class<Lua_HUDPlayer_Weapon_Name_Rect_Name> Lua_HUDPlayer_Weapon_Name_Rect;
1528
Lua_HUDPlayer_Weapon_Name_Rect_Get_X(lua_State * L)1529 static int Lua_HUDPlayer_Weapon_Name_Rect_Get_X(lua_State *L)
1530 {
1531 struct weapon_interface_data *wid = &weapon_interface_definitions[Lua_HUDPlayer_Weapon_Name_Rect::Index(L, 1)];
1532 short startx = wid->weapon_name_start_x;
1533 if (startx == NONE)
1534 {
1535 screen_rectangle *r = get_interface_rectangle(_weapon_display_rect);
1536 startx = r->left;
1537 }
1538 lua_pushnumber(L, startx);
1539 return 1;
1540 }
1541
Lua_HUDPlayer_Weapon_Name_Rect_Get_Width(lua_State * L)1542 static int Lua_HUDPlayer_Weapon_Name_Rect_Get_Width(lua_State *L)
1543 {
1544 struct weapon_interface_data *wid = &weapon_interface_definitions[Lua_HUDPlayer_Weapon_Name_Rect::Index(L, 1)];
1545 short startx = wid->weapon_name_start_x;
1546 short endx = wid->weapon_name_end_x;
1547 if (startx == NONE || endx == NONE)
1548 {
1549 screen_rectangle *r = get_interface_rectangle(_weapon_display_rect);
1550 if (startx == NONE)
1551 startx = r->left;
1552 if (endx == NONE)
1553 endx = r->right;
1554 }
1555 lua_pushnumber(L, endx - startx);
1556 return 1;
1557 }
1558
Lua_HUDPlayer_Weapon_Name_Rect_Get_Y(lua_State * L)1559 static int Lua_HUDPlayer_Weapon_Name_Rect_Get_Y(lua_State *L)
1560 {
1561 struct weapon_interface_data *wid = &weapon_interface_definitions[Lua_HUDPlayer_Weapon_Name_Rect::Index(L, 1)];
1562 lua_pushnumber(L, wid->weapon_name_start_y);
1563 return 1;
1564 }
1565
Lua_HUDPlayer_Weapon_Name_Rect_Get_Height(lua_State * L)1566 static int Lua_HUDPlayer_Weapon_Name_Rect_Get_Height(lua_State *L)
1567 {
1568 struct weapon_interface_data *wid = &weapon_interface_definitions[Lua_HUDPlayer_Weapon_Name_Rect::Index(L, 1)];
1569 lua_pushnumber(L, wid->weapon_name_end_y - wid->weapon_name_start_y);
1570 return 1;
1571 }
1572
1573 const luaL_Reg Lua_HUDPlayer_Weapon_Name_Rect_Get[] = {
1574 {"x", Lua_HUDPlayer_Weapon_Name_Rect_Get_X},
1575 {"y", Lua_HUDPlayer_Weapon_Name_Rect_Get_Y},
1576 {"width", Lua_HUDPlayer_Weapon_Name_Rect_Get_Width},
1577 {"height", Lua_HUDPlayer_Weapon_Name_Rect_Get_Height},
1578 {0, 0}
1579 };
1580
1581
Lua_HUDPlayer_Weapon_Get_Name_Rect(lua_State * L)1582 static int Lua_HUDPlayer_Weapon_Get_Name_Rect(lua_State *L)
1583 {
1584 Lua_HUDPlayer_Weapon_Name_Rect::Push(L, Lua_HUDPlayer_Weapon::Index(L, 1));
1585 return 1;
1586 }
1587
Lua_HUDPlayer_Weapon_Get_Type(lua_State * L)1588 static int Lua_HUDPlayer_Weapon_Get_Type(lua_State *L)
1589 {
1590 Lua_WeaponType::Push(L, Lua_HUDPlayer_Weapon::Index(L, 1));
1591 return 1;
1592 }
1593
Lua_HUDPlayer_Weapon_Get_Name(lua_State * L)1594 static int Lua_HUDPlayer_Weapon_Get_Name(lua_State *L)
1595 {
1596 int weapon = Lua_HUDPlayer_Weapon::Index(L, 1);
1597 char tmp[256];
1598 tmp[0] = 0;
1599
1600 if (weapon != _weapon_ball)
1601 {
1602 #define strWEAPON_NAME_LIST 137
1603 getcstr(tmp, strWEAPON_NAME_LIST, weapon);
1604 }
1605 else
1606 {
1607 short item_index;
1608
1609 /* Which ball do they actually have? */
1610 for (item_index = BALL_ITEM_BASE;
1611 item_index < BALL_ITEM_BASE + MAXIMUM_NUMBER_OF_PLAYERS;
1612 ++item_index)
1613 {
1614 if (current_player->items[item_index] > 0) break;
1615 }
1616 assert(item_index != BALL_ITEM_BASE + MAXIMUM_NUMBER_OF_PLAYERS);
1617 get_item_name(tmp, item_index, false);
1618 }
1619 lua_pushstring(L, tmp);
1620 return 1;
1621 }
1622
1623 const luaL_Reg Lua_HUDPlayer_Weapon_Get[] = {
1624 {"primary", get_hudweapon_trigger<_primary_weapon>},
1625 {"secondary", get_hudweapon_trigger<_secondary_weapon>},
1626 {"type", Lua_HUDPlayer_Weapon_Get_Type},
1627 {"name", Lua_HUDPlayer_Weapon_Get_Name},
1628 {"name_rect", Lua_HUDPlayer_Weapon_Get_Name_Rect},
1629 {"shape", Lua_HUDPlayer_Weapon_Get_SingleShape},
1630 {"multiple_shape", Lua_HUDPlayer_Weapon_Get_MultShape},
1631 {"multiple_unusable_shape", Lua_HUDPlayer_Weapon_Get_UnusableShape},
1632 {0, 0}
1633 };
1634
1635 extern player_weapon_data *get_player_weapon_data(const short player_index);
1636 extern bool player_has_valid_weapon(short player_index);
1637
1638 char Lua_HUDPlayer_Weapons_Name[] = "player_weapons";
1639 typedef L_Class<Lua_HUDPlayer_Weapons_Name> Lua_HUDPlayer_Weapons;
1640
1641 extern bool can_wield_weapons[MAXIMUM_NUMBER_OF_NETWORK_PLAYERS];
1642
Lua_HUDPlayer_Weapons_Get(lua_State * L)1643 static int Lua_HUDPlayer_Weapons_Get(lua_State *L)
1644 {
1645 bool string_arg = lua_isstring(L, 2) && !lua_isnumber(L, 2);
1646 if (string_arg && (strcmp(lua_tostring(L, 2), "current") == 0))
1647 {
1648 if (player_has_valid_weapon(current_player_index))
1649 {
1650 player_weapon_data *weapon_data = get_player_weapon_data(current_player_index);
1651 Lua_HUDPlayer_Weapon::Push(L, weapon_data->current_weapon);
1652 }
1653 else
1654 {
1655 lua_pushnil(L);
1656 }
1657 }
1658 else if (string_arg && (strcmp(lua_tostring(L, 2), "desired") == 0))
1659 {
1660 player_weapon_data *weapon_data = get_player_weapon_data(current_player_index);
1661 if (weapon_data->desired_weapon != NONE)
1662 {
1663 Lua_HUDPlayer_Weapon::Push(L, weapon_data->desired_weapon);
1664 }
1665 else
1666 {
1667 lua_pushnil(L);
1668 }
1669 }
1670 else
1671 {
1672 int index = Lua_WeaponType::ToIndex(L, 2);
1673 Lua_HUDPlayer_Weapon::Push(L, index);
1674 }
1675
1676 return 1;
1677 }
1678
Lua_HUDPlayer_Weapons_Length(lua_State * L)1679 static int Lua_HUDPlayer_Weapons_Length(lua_State *L)
1680 {
1681 lua_pushnumber(L, MAXIMUM_NUMBER_OF_WEAPONS);
1682 return 1;
1683 }
1684
1685 const luaL_Reg Lua_HUDPlayer_Weapons_Metatable[] = {
1686 {"__index", Lua_HUDPlayer_Weapons_Get},
1687 {"__len", Lua_HUDPlayer_Weapons_Length},
1688 {0, 0}
1689 };
1690
1691 char Lua_HUDPlayer_Section_Name[] = "player_section";
1692 typedef L_Class<Lua_HUDPlayer_Section_Name> Lua_HUDPlayer_Section;
1693
Lua_HUDPlayer_Section_Get_Name(lua_State * L)1694 static int Lua_HUDPlayer_Section_Get_Name(lua_State *L)
1695 {
1696 char tmp[256];
1697 tmp[0] = 0;
1698 get_header_name(tmp, Lua_HUDPlayer_Section::Index(L, 1));
1699 lua_pushstring(L, tmp);
1700 return 1;
1701 }
1702
Lua_HUDPlayer_Section_Get_Type(lua_State * L)1703 static int Lua_HUDPlayer_Section_Get_Type(lua_State *L)
1704 {
1705 Lua_InventorySection::Push(L, Lua_HUDPlayer_Section::Index(L, 1));
1706 return 1;
1707 }
1708
1709 const luaL_Reg Lua_HUDPlayer_Section_Get[] = {
1710 {"name", Lua_HUDPlayer_Section_Get_Name},
1711 {"type", Lua_HUDPlayer_Section_Get_Type},
1712 {0, 0}
1713 };
1714
1715 char Lua_HUDPlayer_Sections_Name[] = "player_sections";
1716 typedef L_Class<Lua_HUDPlayer_Sections_Name> Lua_HUDPlayer_Sections;
1717
Lua_HUDPlayer_Sections_Get(lua_State * L)1718 static int Lua_HUDPlayer_Sections_Get(lua_State *L)
1719 {
1720 if (lua_isstring(L, 2) && strcmp(lua_tostring(L, 2), "current") == 0)
1721 {
1722 Lua_HUDPlayer_Section::Push(L, GET_CURRENT_INVENTORY_SCREEN(current_player));
1723 }
1724 else
1725 {
1726 int index = Lua_InventorySection::ToIndex(L, 2);
1727 Lua_HUDPlayer_Section::Push(L, index);
1728 }
1729
1730 return 1;
1731 }
1732
Lua_HUDPlayer_Sections_Length(lua_State * L)1733 static int Lua_HUDPlayer_Sections_Length(lua_State *L)
1734 {
1735 lua_pushnumber(L, NUMBER_OF_ITEM_TYPES + 1);
1736 return 1;
1737 }
1738
1739 const luaL_Reg Lua_HUDPlayer_Sections_Metatable[] = {
1740 {"__index", Lua_HUDPlayer_Sections_Get},
1741 {"__len", Lua_HUDPlayer_Sections_Length},
1742 {0, 0}
1743 };
1744
1745 char Lua_HUDCompass_Name[] = "compass";
1746 typedef L_Class<Lua_HUDCompass_Name> Lua_HUDCompass;
1747
Lua_HUDCompass_Get_NE(lua_State * L)1748 static int Lua_HUDCompass_Get_NE(lua_State *L)
1749 {
1750 lua_pushboolean(L, get_network_compass_state(current_player_index) & _network_compass_ne);
1751 return 1;
1752 }
1753
Lua_HUDCompass_Get_NW(lua_State * L)1754 static int Lua_HUDCompass_Get_NW(lua_State *L)
1755 {
1756 lua_pushboolean(L, get_network_compass_state(current_player_index) & _network_compass_nw);
1757 return 1;
1758 }
1759
Lua_HUDCompass_Get_SE(lua_State * L)1760 static int Lua_HUDCompass_Get_SE(lua_State *L)
1761 {
1762 lua_pushboolean(L, get_network_compass_state(current_player_index) & _network_compass_se);
1763 return 1;
1764 }
1765
Lua_HUDCompass_Get_SW(lua_State * L)1766 static int Lua_HUDCompass_Get_SW(lua_State *L)
1767 {
1768 lua_pushboolean(L, get_network_compass_state(current_player_index) & _network_compass_sw);
1769 return 1;
1770 }
1771
1772 const luaL_Reg Lua_HUDCompass_Get[] = {
1773 {"ne", Lua_HUDCompass_Get_NE},
1774 {"northeast", Lua_HUDCompass_Get_NE},
1775 {"nw", Lua_HUDCompass_Get_NW},
1776 {"northwest", Lua_HUDCompass_Get_NW},
1777 {"se", Lua_HUDCompass_Get_SE},
1778 {"southeast", Lua_HUDCompass_Get_SE},
1779 {"sw", Lua_HUDCompass_Get_SW},
1780 {"southwest", Lua_HUDCompass_Get_SW},
1781 {0, 0}
1782 };
1783
1784 char Lua_MotionSensor_Blip_Name[] = "sensor_blip";
1785 typedef L_Class<Lua_MotionSensor_Blip_Name> Lua_MotionSensor_Blip;
1786
Lua_MotionSensor_Blip_Get_Type(lua_State * L)1787 static int Lua_MotionSensor_Blip_Get_Type(lua_State *L)
1788 {
1789 blip_info info = Lua_HUDInstance()->entity_blip(Lua_MotionSensor_Blip::Index(L, 1));
1790 Lua_SensorBlipType::Push(L, info.mtype);
1791 return 1;
1792 }
1793
Lua_MotionSensor_Blip_Get_Intensity(lua_State * L)1794 static int Lua_MotionSensor_Blip_Get_Intensity(lua_State *L)
1795 {
1796 blip_info info = Lua_HUDInstance()->entity_blip(Lua_MotionSensor_Blip::Index(L, 1));
1797 lua_pushnumber(L, info.intensity);
1798 return 1;
1799 }
1800
Lua_MotionSensor_Blip_Get_Distance(lua_State * L)1801 static int Lua_MotionSensor_Blip_Get_Distance(lua_State *L)
1802 {
1803 blip_info info = Lua_HUDInstance()->entity_blip(Lua_MotionSensor_Blip::Index(L, 1));
1804 lua_pushnumber(L, info.distance / 1024.0);
1805 return 1;
1806 }
1807
Lua_MotionSensor_Blip_Get_Direction(lua_State * L)1808 static int Lua_MotionSensor_Blip_Get_Direction(lua_State *L)
1809 {
1810 blip_info info = Lua_HUDInstance()->entity_blip(Lua_MotionSensor_Blip::Index(L, 1));
1811 lua_pushnumber(L, info.direction * AngleConvert);
1812 return 1;
1813 }
1814
1815 const luaL_Reg Lua_MotionSensor_Blip_Get[] = {
1816 {"type", Lua_MotionSensor_Blip_Get_Type},
1817 {"intensity", Lua_MotionSensor_Blip_Get_Intensity},
1818 {"distance", Lua_MotionSensor_Blip_Get_Distance},
1819 {"direction", Lua_MotionSensor_Blip_Get_Direction},
1820 {"yaw", Lua_MotionSensor_Blip_Get_Direction},
1821 {0, 0}
1822 };
1823
Lua_MotionSensor_Blip_Valid(int16 index)1824 static bool Lua_MotionSensor_Blip_Valid(int16 index)
1825 {
1826 return index >= 0 && index < Lua_HUDInstance()->entity_blip_count();
1827 }
1828
1829 char Lua_MotionSensor_Blips_Name[] = "sensor_blips";
1830 typedef L_Class<Lua_MotionSensor_Blips_Name> Lua_MotionSensor_Blips;
1831
Lua_MotionSensor_Blips_Get(lua_State * L)1832 static int Lua_MotionSensor_Blips_Get(lua_State *L)
1833 {
1834 Lua_MotionSensor_Blip::Push(L, lua_tointeger(L, 2));
1835 return 1;
1836 }
1837
Lua_MotionSensor_Blips_Length(lua_State * L)1838 static int Lua_MotionSensor_Blips_Length(lua_State *L)
1839 {
1840 lua_pushnumber(L, Lua_HUDInstance()->entity_blip_count());
1841 return 1;
1842 }
1843
1844 const luaL_Reg Lua_MotionSensor_Blips_Metatable[] = {
1845 {"__index", Lua_MotionSensor_Blips_Get},
1846 {"__len", Lua_MotionSensor_Blips_Length},
1847 {0, 0}
1848 };
1849
1850
1851 char Lua_MotionSensor_Name[] = "motion_sensor";
1852 typedef L_Class<Lua_MotionSensor_Name> Lua_MotionSensor;
1853
1854 extern bool MotionSensorActive;
1855
Lua_MotionSensor_Get_Active(lua_State * L)1856 static int Lua_MotionSensor_Get_Active(lua_State *L)
1857 {
1858 lua_pushboolean(L, !(GET_GAME_OPTIONS() & _motion_sensor_does_not_work) && MotionSensorActive);
1859 return 1;
1860 }
1861
Lua_MotionSensor_Get_Blips(lua_State * L)1862 static int Lua_MotionSensor_Get_Blips(lua_State *L)
1863 {
1864 Lua_MotionSensor_Blips::Push(L, Lua_MotionSensor::Index(L, 1));
1865 return 1;
1866 }
1867
1868 const luaL_Reg Lua_MotionSensor_Get[] = {
1869 {"active", Lua_MotionSensor_Get_Active},
1870 {"blips", Lua_MotionSensor_Get_Blips},
1871 {0, 0}
1872 };
1873
1874 char Lua_HUDTexturePalette_Slot_Name[] = "hud_texture_palette_slot";
1875 typedef L_Class<Lua_HUDTexturePalette_Slot_Name> Lua_HUDTexturePalette_Slot;
1876
Lua_HUDTexturePalette_Slot_Get_Collection(lua_State * L)1877 static int Lua_HUDTexturePalette_Slot_Get_Collection(lua_State *L)
1878 {
1879 int index = Lua_HUDTexturePalette_Slot::Index(L, 1);
1880 shape_descriptor shape = LuaTexturePaletteTexture(index);
1881 if (shape == UNONE)
1882 return 0;
1883
1884 lua_pushnumber(L, GET_COLLECTION(GET_DESCRIPTOR_COLLECTION(shape)));
1885 return 1;
1886 }
1887
Lua_HUDTexturePalette_Slot_Get_Texture(lua_State * L)1888 static int Lua_HUDTexturePalette_Slot_Get_Texture(lua_State *L)
1889 {
1890 int index = Lua_HUDTexturePalette_Slot::Index(L, 1);
1891 shape_descriptor shape = LuaTexturePaletteTexture(index);
1892 if (shape == UNONE)
1893 return 0;
1894
1895 lua_pushnumber(L, GET_DESCRIPTOR_SHAPE(shape));
1896 return 1;
1897 }
1898
Lua_HUDTexturePalette_Slot_Get_Type(lua_State * L)1899 static int Lua_HUDTexturePalette_Slot_Get_Type(lua_State *L)
1900 {
1901 int index = Lua_HUDTexturePalette_Slot::Index(L, 1);
1902 shape_descriptor shape = LuaTexturePaletteTexture(index);
1903 if (shape == UNONE)
1904 return 0;
1905
1906 Lua_TextureType::Push(L, LuaTexturePaletteTextureType(index));
1907 return 1;
1908 }
1909
1910 const luaL_Reg Lua_HUDTexturePalette_Slot_Get[] = {
1911 {"collection", Lua_HUDTexturePalette_Slot_Get_Collection},
1912 {"texture_index", Lua_HUDTexturePalette_Slot_Get_Texture},
1913 {"type", Lua_HUDTexturePalette_Slot_Get_Type},
1914 {0, 0}
1915 };
1916
Lua_HUDTexturePalette_Slot_Valid(int16 index)1917 static bool Lua_HUDTexturePalette_Slot_Valid(int16 index)
1918 {
1919 return index >= 0 && index < LuaTexturePaletteSize();
1920 }
1921
1922 char Lua_HUDTexturePalette_Slots_Name[] = "hud_texture_palette_slots";
1923 typedef L_Class<Lua_HUDTexturePalette_Slots_Name> Lua_HUDTexturePalette_Slots;
1924
Lua_HUDTexturePalette_Slots_Get(lua_State * L)1925 static int Lua_HUDTexturePalette_Slots_Get(lua_State *L)
1926 {
1927 if (lua_isnumber(L, 2))
1928 {
1929 int index = static_cast<int>(lua_tonumber(L, 2));
1930 if (index >= 0 && index < LuaTexturePaletteSize())
1931 Lua_HUDTexturePalette_Slot::Push(L, index);
1932 else
1933 lua_pushnil(L);
1934 }
1935 else
1936 lua_pushnil(L);
1937
1938 return 1;
1939 }
1940
Lua_HUDTexturePalette_Slots_Length(lua_State * L)1941 static int Lua_HUDTexturePalette_Slots_Length(lua_State *L)
1942 {
1943 lua_pushnumber(L, LuaTexturePaletteSize());
1944 return 1;
1945 }
1946
1947 const luaL_Reg Lua_HUDTexturePalette_Slots_Metatable[] = {
1948 {"__index", Lua_HUDTexturePalette_Slots_Get},
1949 {"__len", Lua_HUDTexturePalette_Slots_Length},
1950 {0, 0}
1951 };
1952
1953 char Lua_HUDTexturePalette_Name[] = "hud_texture_palette";
1954 typedef L_Class<Lua_HUDTexturePalette_Name> Lua_HUDTexturePalette;
1955
Lua_HUDTexturePalette_Get_Size(lua_State * L)1956 static int Lua_HUDTexturePalette_Get_Size(lua_State *L)
1957 {
1958 lua_pushnumber(L, LuaTexturePaletteSize());
1959 return 1;
1960 }
1961
Lua_HUDTexturePalette_Get_Selected(lua_State * L)1962 static int Lua_HUDTexturePalette_Get_Selected(lua_State *L)
1963 {
1964 if (LuaTexturePaletteSize() < 1)
1965 return 0;
1966
1967 int selected = LuaTexturePaletteSelected();
1968 if (selected < 0)
1969 return 0;
1970
1971 lua_pushnumber(L, selected);
1972 return 1;
1973 }
1974
Lua_HUDTexturePalette_Get_Slots(lua_State * L)1975 static int Lua_HUDTexturePalette_Get_Slots(lua_State *L)
1976 {
1977 Lua_HUDTexturePalette_Slots::Push(L, Lua_HUDTexturePalette::Index(L, 1));
1978 return 1;
1979 }
1980
1981 const luaL_Reg Lua_HUDTexturePalette_Get[] = {
1982 {"size", Lua_HUDTexturePalette_Get_Size},
1983 {"highlight", Lua_HUDTexturePalette_Get_Selected},
1984 {"slots", Lua_HUDTexturePalette_Get_Slots},
1985 {0, 0}
1986 };
1987
1988
1989 char Lua_HUDPlayer_Name[] = "Player";
1990 typedef L_Class<Lua_HUDPlayer_Name> Lua_HUDPlayer;
1991
Lua_HUDPlayer_Get_Color(lua_State * L)1992 static int Lua_HUDPlayer_Get_Color(lua_State *L)
1993 {
1994 Lua_PlayerColor::Push(L, current_player->color);
1995 return 1;
1996 }
1997
Lua_HUDPlayer_Get_Dead(lua_State * L)1998 static int Lua_HUDPlayer_Get_Dead(lua_State *L)
1999 {
2000 lua_pushboolean(L, (PLAYER_IS_DEAD(current_player) || PLAYER_IS_TOTALLY_DEAD(current_player)));
2001 return 1;
2002 }
2003
Lua_HUDPlayer_Get_Respawn_Duration(lua_State * L)2004 static int Lua_HUDPlayer_Get_Respawn_Duration(lua_State *L)
2005 {
2006 if (PLAYER_IS_DEAD(current_player) &&
2007 PLAYER_IS_TOTALLY_DEAD(current_player) &&
2008 (current_player->variables.action==_player_stationary||dynamic_world->player_count==1))
2009 lua_pushinteger(L, current_player->reincarnation_delay);
2010 else
2011 lua_pushnil(L); // I'm not dead yet!
2012 return 1;
2013 }
2014
Lua_HUDPlayer_Get_Energy(lua_State * L)2015 static int Lua_HUDPlayer_Get_Energy(lua_State *L)
2016 {
2017 lua_pushnumber(L, current_player->suit_energy);
2018 return 1;
2019 }
2020
Lua_HUDPlayer_Get_Direction(lua_State * L)2021 static int Lua_HUDPlayer_Get_Direction(lua_State *L)
2022 {
2023 double angle = FIXED_INTEGERAL_PART(current_player->variables.direction) * AngleConvert;
2024 lua_pushnumber(L, angle);
2025 return 1;
2026 }
2027
Lua_HUDPlayer_Get_Elevation(lua_State * L)2028 static int Lua_HUDPlayer_Get_Elevation(lua_State *L)
2029 {
2030 double angle = FIXED_INTEGERAL_PART(current_player->variables.elevation) * AngleConvert;
2031 lua_pushnumber(L, angle);
2032 return 1;
2033 }
2034
2035 char Lua_HUDPlayer_Velocity_Name[] = "velocity";
2036 typedef L_Class<Lua_HUDPlayer_Velocity_Name> Lua_HUDPlayer_Velocity;
2037
Lua_HUDPlayer_Velocity_Get_Forward(lua_State * L)2038 static int Lua_HUDPlayer_Velocity_Get_Forward(lua_State *L)
2039 {
2040 double diff_x = (current_player->variables.position.x - current_player->variables.last_position.x) / (double)FIXED_ONE;
2041 double diff_y = (current_player->variables.position.y - current_player->variables.last_position.y) / (double)FIXED_ONE;
2042 double dir = (360.0 - (FIXED_INTEGERAL_PART(current_player->variables.direction) * AngleConvert)) * M_PI / 180.0;
2043
2044 lua_pushnumber(L, (diff_x * cos(dir)) + (-diff_y * sin(dir)));
2045 return 1;
2046 }
2047
Lua_HUDPlayer_Velocity_Get_Perpendicular(lua_State * L)2048 static int Lua_HUDPlayer_Velocity_Get_Perpendicular(lua_State *L)
2049 {
2050 double diff_x = (current_player->variables.position.x - current_player->variables.last_position.x) / (double)FIXED_ONE;
2051 double diff_y = (current_player->variables.position.y - current_player->variables.last_position.y) / (double)FIXED_ONE;
2052 double dir = (360.0 - (FIXED_INTEGERAL_PART(current_player->variables.direction) * AngleConvert)) * M_PI / 180.0;
2053
2054 lua_pushnumber(L, (diff_x * sin(dir)) + (diff_y * cos(dir)));
2055 return 1;
2056 }
2057
Lua_HUDPlayer_Velocity_Get_Vertical(lua_State * L)2058 static int Lua_HUDPlayer_Velocity_Get_Vertical(lua_State *L)
2059 {
2060 lua_pushnumber(L, (current_player->variables.position.z - current_player->variables.last_position.z) / (double)FIXED_ONE);
2061 return 1;
2062 }
2063
2064 const luaL_Reg Lua_HUDPlayer_Velocity_Get[] = {
2065 {"forward", Lua_HUDPlayer_Velocity_Get_Forward},
2066 {"perpendicular", Lua_HUDPlayer_Velocity_Get_Perpendicular},
2067 {"vertical", Lua_HUDPlayer_Velocity_Get_Vertical},
2068 {0, 0}
2069 };
2070
Lua_HUDPlayer_Get_Velocity(lua_State * L)2071 static int Lua_HUDPlayer_Get_Velocity(lua_State *L)
2072 {
2073 Lua_HUDPlayer_Velocity::Push(L, Lua_HUDPlayer::Index(L, 1));
2074 return 1;
2075 }
2076
Lua_HUDPlayer_Get_Microphone(lua_State * L)2077 static int Lua_HUDPlayer_Get_Microphone(lua_State *L)
2078 {
2079 lua_pushboolean(L, current_netgame_allows_microphone() &&
2080 (dynamic_world->speaking_player_index == local_player_index));
2081 return 1;
2082 }
2083
Lua_HUDPlayer_Get_Items(lua_State * L)2084 static int Lua_HUDPlayer_Get_Items(lua_State *L)
2085 {
2086 Lua_HUDPlayer_Items::Push(L, Lua_HUDPlayer::Index(L, 1));
2087 return 1;
2088 }
2089
Lua_HUDPlayer_Get_Name(lua_State * L)2090 static int Lua_HUDPlayer_Get_Name(lua_State *L)
2091 {
2092 lua_pushstring(L, current_player->name);
2093 return 1;
2094 }
2095
Lua_HUDPlayer_Get_Oxygen(lua_State * L)2096 static int Lua_HUDPlayer_Get_Oxygen(lua_State *L)
2097 {
2098 lua_pushnumber(L, current_player->suit_oxygen);
2099 return 1;
2100 }
2101
Lua_HUDPlayer_Get_Team(lua_State * L)2102 static int Lua_HUDPlayer_Get_Team(lua_State *L)
2103 {
2104 Lua_PlayerColor::Push(L, current_player->team);
2105 return 1;
2106 }
2107
Lua_HUDPlayer_Get_Sections(lua_State * L)2108 static int Lua_HUDPlayer_Get_Sections(lua_State *L)
2109 {
2110 Lua_HUDPlayer_Sections::Push(L, Lua_HUDPlayer::Index(L, 1));
2111 return 1;
2112 }
2113
Lua_HUDPlayer_Get_Weapons(lua_State * L)2114 static int Lua_HUDPlayer_Get_Weapons(lua_State *L)
2115 {
2116 Lua_HUDPlayer_Weapons::Push(L, Lua_HUDPlayer::Index(L, 1));
2117 return 1;
2118 }
2119
Lua_HUDPlayer_Get_Motion(lua_State * L)2120 static int Lua_HUDPlayer_Get_Motion(lua_State *L)
2121 {
2122 Lua_MotionSensor::Push(L, 1);
2123 return 1;
2124 }
2125
Lua_HUDPlayer_Get_Compass(lua_State * L)2126 static int Lua_HUDPlayer_Get_Compass(lua_State *L)
2127 {
2128 Lua_HUDCompass::Push(L, 1);
2129 return 1;
2130 }
2131
Lua_HUDPlayer_Get_Zoom(lua_State * L)2132 static int Lua_HUDPlayer_Get_Zoom(lua_State *L)
2133 {
2134 lua_pushboolean(L, GetTunnelVision());
2135 return 1;
2136 }
2137
Lua_HUDPlayer_Get_Texture_Palette(lua_State * L)2138 static int Lua_HUDPlayer_Get_Texture_Palette(lua_State *L)
2139 {
2140 Lua_HUDTexturePalette::Push(L, 1);
2141 return 1;
2142 }
2143
2144 const luaL_Reg Lua_HUDPlayer_Get[] = {
2145 {"color", Lua_HUDPlayer_Get_Color},
2146 {"dead", Lua_HUDPlayer_Get_Dead},
2147 {"direction", Lua_HUDPlayer_Get_Direction},
2148 {"yaw", Lua_HUDPlayer_Get_Direction},
2149 {"elevation", Lua_HUDPlayer_Get_Elevation},
2150 {"pitch", Lua_HUDPlayer_Get_Elevation},
2151 {"velocity", Lua_HUDPlayer_Get_Velocity},
2152 {"energy", Lua_HUDPlayer_Get_Energy},
2153 {"life", Lua_HUDPlayer_Get_Energy},
2154 {"microphone_active", Lua_HUDPlayer_Get_Microphone},
2155 {"items", Lua_HUDPlayer_Get_Items},
2156 {"name", Lua_HUDPlayer_Get_Name},
2157 {"oxygen", Lua_HUDPlayer_Get_Oxygen},
2158 {"team", Lua_HUDPlayer_Get_Team},
2159 {"inventory_sections", Lua_HUDPlayer_Get_Sections},
2160 {"weapons", Lua_HUDPlayer_Get_Weapons},
2161 {"motion_sensor", Lua_HUDPlayer_Get_Motion},
2162 {"compass", Lua_HUDPlayer_Get_Compass},
2163 {"zoom_active", Lua_HUDPlayer_Get_Zoom},
2164 {"texture_palette", Lua_HUDPlayer_Get_Texture_Palette},
2165 {"respawn_duration", Lua_HUDPlayer_Get_Respawn_Duration},
2166 {0, 0}
2167 };
2168
2169
2170 char Lua_Screen_Clip_Rect_Name[] = "clip_rect";
2171 typedef L_Class<Lua_Screen_Clip_Rect_Name> Lua_Screen_Clip_Rect;
2172
Lua_Screen_Clip_Rect_Get_X(lua_State * L)2173 static int Lua_Screen_Clip_Rect_Get_X(lua_State *L)
2174 {
2175 lua_pushnumber(L, alephone::Screen::instance()->lua_clip_rect.x);
2176 return 1;
2177 }
2178
Lua_Screen_Clip_Rect_Get_Y(lua_State * L)2179 static int Lua_Screen_Clip_Rect_Get_Y(lua_State *L)
2180 {
2181 lua_pushnumber(L, alephone::Screen::instance()->lua_clip_rect.y);
2182 return 1;
2183 }
2184
Lua_Screen_Clip_Rect_Get_Width(lua_State * L)2185 static int Lua_Screen_Clip_Rect_Get_Width(lua_State *L)
2186 {
2187 lua_pushnumber(L, alephone::Screen::instance()->lua_clip_rect.w);
2188 return 1;
2189 }
2190
Lua_Screen_Clip_Rect_Get_Height(lua_State * L)2191 static int Lua_Screen_Clip_Rect_Get_Height(lua_State *L)
2192 {
2193 lua_pushnumber(L, alephone::Screen::instance()->lua_clip_rect.h);
2194 return 1;
2195 }
2196
Lua_Screen_Clip_Rect_Set_X(lua_State * L)2197 static int Lua_Screen_Clip_Rect_Set_X(lua_State *L)
2198 {
2199 alephone::Screen::instance()->lua_clip_rect.x = lua_tointeger(L, 2);
2200 return 0;
2201 }
2202
Lua_Screen_Clip_Rect_Set_Y(lua_State * L)2203 static int Lua_Screen_Clip_Rect_Set_Y(lua_State *L)
2204 {
2205 alephone::Screen::instance()->lua_clip_rect.y = lua_tointeger(L, 2);
2206 return 0;
2207 }
2208
Lua_Screen_Clip_Rect_Set_Width(lua_State * L)2209 static int Lua_Screen_Clip_Rect_Set_Width(lua_State *L)
2210 {
2211 alephone::Screen::instance()->lua_clip_rect.w = lua_tointeger(L, 2);
2212 return 0;
2213 }
2214
Lua_Screen_Clip_Rect_Set_Height(lua_State * L)2215 static int Lua_Screen_Clip_Rect_Set_Height(lua_State *L)
2216 {
2217 alephone::Screen::instance()->lua_clip_rect.h = lua_tointeger(L, 2);
2218 return 0;
2219 }
2220
2221 const luaL_Reg Lua_Screen_Clip_Rect_Get[] = {
2222 {"x", Lua_Screen_Clip_Rect_Get_X},
2223 {"y", Lua_Screen_Clip_Rect_Get_Y},
2224 {"width", Lua_Screen_Clip_Rect_Get_Width},
2225 {"height", Lua_Screen_Clip_Rect_Get_Height},
2226 {0, 0}
2227 };
2228
2229 const luaL_Reg Lua_Screen_Clip_Rect_Set[] = {
2230 {"x", Lua_Screen_Clip_Rect_Set_X},
2231 {"y", Lua_Screen_Clip_Rect_Set_Y},
2232 {"width", Lua_Screen_Clip_Rect_Set_Width},
2233 {"height", Lua_Screen_Clip_Rect_Set_Height},
2234 {0, 0}
2235 };
2236
2237 char Lua_Screen_World_Rect_Name[] = "world_rect";
2238 typedef L_Class<Lua_Screen_World_Rect_Name> Lua_Screen_World_Rect;
2239
Lua_Screen_World_Rect_Get_X(lua_State * L)2240 static int Lua_Screen_World_Rect_Get_X(lua_State *L)
2241 {
2242 lua_pushnumber(L, alephone::Screen::instance()->lua_view_rect.x);
2243 return 1;
2244 }
2245
Lua_Screen_World_Rect_Get_Y(lua_State * L)2246 static int Lua_Screen_World_Rect_Get_Y(lua_State *L)
2247 {
2248 lua_pushnumber(L, alephone::Screen::instance()->lua_view_rect.y);
2249 return 1;
2250 }
2251
Lua_Screen_World_Rect_Get_Width(lua_State * L)2252 static int Lua_Screen_World_Rect_Get_Width(lua_State *L)
2253 {
2254 lua_pushnumber(L, alephone::Screen::instance()->lua_view_rect.w);
2255 return 1;
2256 }
2257
Lua_Screen_World_Rect_Get_Height(lua_State * L)2258 static int Lua_Screen_World_Rect_Get_Height(lua_State *L)
2259 {
2260 lua_pushnumber(L, alephone::Screen::instance()->lua_view_rect.h);
2261 return 1;
2262 }
2263
Lua_Screen_World_Rect_Set_X(lua_State * L)2264 static int Lua_Screen_World_Rect_Set_X(lua_State *L)
2265 {
2266 alephone::Screen::instance()->lua_view_rect.x = lua_tointeger(L, 2);
2267 return 0;
2268 }
2269
Lua_Screen_World_Rect_Set_Y(lua_State * L)2270 static int Lua_Screen_World_Rect_Set_Y(lua_State *L)
2271 {
2272 alephone::Screen::instance()->lua_view_rect.y = lua_tointeger(L, 2);
2273 return 0;
2274 }
2275
Lua_Screen_World_Rect_Set_Width(lua_State * L)2276 static int Lua_Screen_World_Rect_Set_Width(lua_State *L)
2277 {
2278 alephone::Screen::instance()->lua_view_rect.w = lua_tointeger(L, 2);
2279 return 0;
2280 }
2281
Lua_Screen_World_Rect_Set_Height(lua_State * L)2282 static int Lua_Screen_World_Rect_Set_Height(lua_State *L)
2283 {
2284 alephone::Screen::instance()->lua_view_rect.h = lua_tointeger(L, 2);
2285 return 0;
2286 }
2287
2288 const luaL_Reg Lua_Screen_World_Rect_Get[] = {
2289 {"x", Lua_Screen_World_Rect_Get_X},
2290 {"y", Lua_Screen_World_Rect_Get_Y},
2291 {"width", Lua_Screen_World_Rect_Get_Width},
2292 {"height", Lua_Screen_World_Rect_Get_Height},
2293 {0, 0}
2294 };
2295
2296 const luaL_Reg Lua_Screen_World_Rect_Set[] = {
2297 {"x", Lua_Screen_World_Rect_Set_X},
2298 {"y", Lua_Screen_World_Rect_Set_Y},
2299 {"width", Lua_Screen_World_Rect_Set_Width},
2300 {"height", Lua_Screen_World_Rect_Set_Height},
2301 {0, 0}
2302 };
2303
2304 char Lua_Screen_Map_Rect_Name[] = "map_rect";
2305 typedef L_Class<Lua_Screen_Map_Rect_Name> Lua_Screen_Map_Rect;
2306
Lua_Screen_Map_Rect_Get_X(lua_State * L)2307 static int Lua_Screen_Map_Rect_Get_X(lua_State *L)
2308 {
2309 lua_pushnumber(L, alephone::Screen::instance()->lua_map_rect.x);
2310 return 1;
2311 }
2312
Lua_Screen_Map_Rect_Get_Y(lua_State * L)2313 static int Lua_Screen_Map_Rect_Get_Y(lua_State *L)
2314 {
2315 lua_pushnumber(L, alephone::Screen::instance()->lua_map_rect.y);
2316 return 1;
2317 }
2318
Lua_Screen_Map_Rect_Get_Width(lua_State * L)2319 static int Lua_Screen_Map_Rect_Get_Width(lua_State *L)
2320 {
2321 lua_pushnumber(L, alephone::Screen::instance()->lua_map_rect.w);
2322 return 1;
2323 }
2324
Lua_Screen_Map_Rect_Get_Height(lua_State * L)2325 static int Lua_Screen_Map_Rect_Get_Height(lua_State *L)
2326 {
2327 lua_pushnumber(L, alephone::Screen::instance()->lua_map_rect.h);
2328 return 1;
2329 }
2330
Lua_Screen_Map_Rect_Set_X(lua_State * L)2331 static int Lua_Screen_Map_Rect_Set_X(lua_State *L)
2332 {
2333 alephone::Screen::instance()->lua_map_rect.x = lua_tointeger(L, 2);
2334 return 0;
2335 }
2336
Lua_Screen_Map_Rect_Set_Y(lua_State * L)2337 static int Lua_Screen_Map_Rect_Set_Y(lua_State *L)
2338 {
2339 alephone::Screen::instance()->lua_map_rect.y = lua_tointeger(L, 2);
2340 return 0;
2341 }
2342
Lua_Screen_Map_Rect_Set_Width(lua_State * L)2343 static int Lua_Screen_Map_Rect_Set_Width(lua_State *L)
2344 {
2345 alephone::Screen::instance()->lua_map_rect.w = lua_tointeger(L, 2);
2346 return 0;
2347 }
2348
Lua_Screen_Map_Rect_Set_Height(lua_State * L)2349 static int Lua_Screen_Map_Rect_Set_Height(lua_State *L)
2350 {
2351 alephone::Screen::instance()->lua_map_rect.h = lua_tointeger(L, 2);
2352 return 0;
2353 }
2354
2355 const luaL_Reg Lua_Screen_Map_Rect_Get[] = {
2356 {"x", Lua_Screen_Map_Rect_Get_X},
2357 {"y", Lua_Screen_Map_Rect_Get_Y},
2358 {"width", Lua_Screen_Map_Rect_Get_Width},
2359 {"height", Lua_Screen_Map_Rect_Get_Height},
2360 {0, 0}
2361 };
2362
2363 const luaL_Reg Lua_Screen_Map_Rect_Set[] = {
2364 {"x", Lua_Screen_Map_Rect_Set_X},
2365 {"y", Lua_Screen_Map_Rect_Set_Y},
2366 {"width", Lua_Screen_Map_Rect_Set_Width},
2367 {"height", Lua_Screen_Map_Rect_Set_Height},
2368 {0, 0}
2369 };
2370
2371 char Lua_Screen_Term_Rect_Name[] = "term_rect";
2372 typedef L_Class<Lua_Screen_Term_Rect_Name> Lua_Screen_Term_Rect;
2373
Lua_Screen_Term_Rect_Get_X(lua_State * L)2374 static int Lua_Screen_Term_Rect_Get_X(lua_State *L)
2375 {
2376 lua_pushnumber(L, alephone::Screen::instance()->lua_term_rect.x);
2377 return 1;
2378 }
2379
Lua_Screen_Term_Rect_Get_Y(lua_State * L)2380 static int Lua_Screen_Term_Rect_Get_Y(lua_State *L)
2381 {
2382 lua_pushnumber(L, alephone::Screen::instance()->lua_term_rect.y);
2383 return 1;
2384 }
2385
Lua_Screen_Term_Rect_Get_Width(lua_State * L)2386 static int Lua_Screen_Term_Rect_Get_Width(lua_State *L)
2387 {
2388 lua_pushnumber(L, alephone::Screen::instance()->lua_term_rect.w);
2389 return 1;
2390 }
2391
Lua_Screen_Term_Rect_Get_Height(lua_State * L)2392 static int Lua_Screen_Term_Rect_Get_Height(lua_State *L)
2393 {
2394 lua_pushnumber(L, alephone::Screen::instance()->lua_term_rect.h);
2395 return 1;
2396 }
2397
Lua_Screen_Term_Rect_Set_X(lua_State * L)2398 static int Lua_Screen_Term_Rect_Set_X(lua_State *L)
2399 {
2400 alephone::Screen::instance()->lua_term_rect.x = lua_tointeger(L, 2);
2401 return 0;
2402 }
2403
Lua_Screen_Term_Rect_Set_Y(lua_State * L)2404 static int Lua_Screen_Term_Rect_Set_Y(lua_State *L)
2405 {
2406 alephone::Screen::instance()->lua_term_rect.y = lua_tointeger(L, 2);
2407 return 0;
2408 }
2409
Lua_Screen_Term_Rect_Set_Width(lua_State * L)2410 static int Lua_Screen_Term_Rect_Set_Width(lua_State *L)
2411 {
2412 alephone::Screen::instance()->lua_term_rect.w = lua_tointeger(L, 2);
2413 return 0;
2414 }
2415
Lua_Screen_Term_Rect_Set_Height(lua_State * L)2416 static int Lua_Screen_Term_Rect_Set_Height(lua_State *L)
2417 {
2418 alephone::Screen::instance()->lua_term_rect.h = lua_tointeger(L, 2);
2419 return 0;
2420 }
2421
2422 const luaL_Reg Lua_Screen_Term_Rect_Get[] = {
2423 {"x", Lua_Screen_Term_Rect_Get_X},
2424 {"y", Lua_Screen_Term_Rect_Get_Y},
2425 {"width", Lua_Screen_Term_Rect_Get_Width},
2426 {"height", Lua_Screen_Term_Rect_Get_Height},
2427 {0, 0}
2428 };
2429
2430 const luaL_Reg Lua_Screen_Term_Rect_Set[] = {
2431 {"x", Lua_Screen_Term_Rect_Set_X},
2432 {"y", Lua_Screen_Term_Rect_Set_Y},
2433 {"width", Lua_Screen_Term_Rect_Set_Width},
2434 {"height", Lua_Screen_Term_Rect_Set_Height},
2435 {0, 0}
2436 };
2437
2438 char Lua_Screen_FOV_Name[] = "field_of_view";
2439 typedef L_Class<Lua_Screen_FOV_Name> Lua_Screen_FOV;
2440
Lua_Screen_FOV_Get_Horizontal(lua_State * L)2441 static int Lua_Screen_FOV_Get_Horizontal(lua_State *L)
2442 {
2443 float factor = 1.0f;
2444 if (get_screen_mode()->acceleration == _opengl_acceleration)
2445 factor = 1.3f;
2446 lua_pushnumber(L, world_view->half_cone * 2.0f / factor);
2447 return 1;
2448 }
2449
Lua_Screen_FOV_Get_Vertical(lua_State * L)2450 static int Lua_Screen_FOV_Get_Vertical(lua_State *L)
2451 {
2452 float factor = 1.0f;
2453 if (get_screen_mode()->acceleration == _opengl_acceleration)
2454 factor = 1.3f;
2455 lua_pushnumber(L, world_view->half_vertical_cone * 2.0f / factor);
2456 return 1;
2457 }
2458
Lua_Screen_FOV_Get_Fix(lua_State * L)2459 static int Lua_Screen_FOV_Get_Fix(lua_State *L)
2460 {
2461 lua_pushboolean(L, View_FOV_FixHorizontalNotVertical());
2462 return 1;
2463 }
2464
2465 const luaL_Reg Lua_Screen_FOV_Get[] = {
2466 {"horizontal", Lua_Screen_FOV_Get_Horizontal},
2467 {"vertical", Lua_Screen_FOV_Get_Vertical},
2468 {"fix_h_not_v", Lua_Screen_FOV_Get_Fix},
2469 {0, 0}
2470 };
2471
2472 const luaL_Reg Lua_Screen_FOV_Set[] = {
2473 {0, 0}
2474 };
2475
2476 char Lua_Screen_Crosshairs_Name[] = "crosshairs";
2477 typedef L_Class<Lua_Screen_Crosshairs_Name> Lua_Screen_Crosshairs;
2478
Lua_Screen_Crosshairs_Get_Active(lua_State * L)2479 static int Lua_Screen_Crosshairs_Get_Active(lua_State *L)
2480 {
2481 lua_pushboolean(L, NetAllowCrosshair() && Crosshairs_IsActive());
2482 return 1;
2483 }
2484
Lua_Screen_Crosshairs_Get_LuaHUD(lua_State * L)2485 static int Lua_Screen_Crosshairs_Get_LuaHUD(lua_State *L)
2486 {
2487 lua_pushboolean(L, use_lua_hud_crosshairs);
2488 return 1;
2489 }
2490
Lua_Screen_Crosshairs_Set_LuaHUD(lua_State * L)2491 static int Lua_Screen_Crosshairs_Set_LuaHUD(lua_State *L)
2492 {
2493 use_lua_hud_crosshairs = lua_toboolean(L, 2);
2494 return 0;
2495 }
2496
2497 const luaL_Reg Lua_Screen_Crosshairs_Get[] = {
2498 {"active", Lua_Screen_Crosshairs_Get_Active},
2499 {"lua_hud", Lua_Screen_Crosshairs_Get_LuaHUD},
2500 {0, 0}
2501 };
2502
2503 const luaL_Reg Lua_Screen_Crosshairs_Set[] = {
2504 {"lua_hud", Lua_Screen_Crosshairs_Set_LuaHUD},
2505 {0, 0}
2506 };
2507
2508 char Lua_Screen_Name[] = "Screen";
2509 typedef L_Class<Lua_Screen_Name> Lua_Screen;
2510
Lua_Screen_Get_Width(lua_State * L)2511 static int Lua_Screen_Get_Width(lua_State *L)
2512 {
2513 lua_pushnumber(L, alephone::Screen::instance()->window_width());
2514 return 1;
2515 }
2516
Lua_Screen_Get_Height(lua_State * L)2517 static int Lua_Screen_Get_Height(lua_State *L)
2518 {
2519 lua_pushnumber(L, alephone::Screen::instance()->window_height());
2520 return 1;
2521 }
2522
Lua_Screen_Get_Renderer(lua_State * L)2523 static int Lua_Screen_Get_Renderer(lua_State *L)
2524 {
2525 Lua_RendererType::Push(L, get_screen_mode()->acceleration);
2526 return 1;
2527 }
2528
Lua_Screen_Get_Term_Size(lua_State * L)2529 static int Lua_Screen_Get_Term_Size(lua_State *L)
2530 {
2531 Lua_SizePreference::Push(L, get_screen_mode()->term_scale_level);
2532 return 1;
2533 }
2534
Lua_Screen_Get_HUD_Size(lua_State * L)2535 static int Lua_Screen_Get_HUD_Size(lua_State *L)
2536 {
2537 Lua_SizePreference::Push(L, get_screen_mode()->hud_scale_level);
2538 return 1;
2539 }
2540
Lua_Screen_Get_Clip_Rect(lua_State * L)2541 static int Lua_Screen_Get_Clip_Rect(lua_State *L)
2542 {
2543 Lua_Screen_Clip_Rect::Push(L, Lua_Screen::Index(L, 1));
2544 return 1;
2545 }
2546
Lua_Screen_Get_World_Rect(lua_State * L)2547 static int Lua_Screen_Get_World_Rect(lua_State *L)
2548 {
2549 Lua_Screen_World_Rect::Push(L, Lua_Screen::Index(L, 1));
2550 return 1;
2551 }
2552
Lua_Screen_Get_Map_Rect(lua_State * L)2553 static int Lua_Screen_Get_Map_Rect(lua_State *L)
2554 {
2555 Lua_Screen_Map_Rect::Push(L, Lua_Screen::Index(L, 1));
2556 return 1;
2557 }
2558
Lua_Screen_Get_Term_Rect(lua_State * L)2559 static int Lua_Screen_Get_Term_Rect(lua_State *L)
2560 {
2561 Lua_Screen_Term_Rect::Push(L, Lua_Screen::Index(L, 1));
2562 return 1;
2563 }
2564
Lua_Screen_Get_Map_Active(lua_State * L)2565 static int Lua_Screen_Get_Map_Active(lua_State *L)
2566 {
2567 lua_pushboolean(L, world_view->overhead_map_active);
2568 return 1;
2569 }
2570
Lua_Screen_Get_Map_Overlay(lua_State * L)2571 static int Lua_Screen_Get_Map_Overlay(lua_State *L)
2572 {
2573 lua_pushboolean(L, map_is_translucent());
2574 return 1;
2575 }
2576
Lua_Screen_Get_Term_Active(lua_State * L)2577 static int Lua_Screen_Get_Term_Active(lua_State *L)
2578 {
2579 lua_pushboolean(L, world_view->terminal_mode_active);
2580 return 1;
2581 }
2582
Lua_Screen_Get_FOV(lua_State * L)2583 static int Lua_Screen_Get_FOV(lua_State *L)
2584 {
2585 Lua_Screen_FOV::Push(L, Lua_Screen::Index(L, 1));
2586 return 1;
2587 }
2588
Lua_Screen_Get_Crosshairs(lua_State * L)2589 static int Lua_Screen_Get_Crosshairs(lua_State *L)
2590 {
2591 Lua_Screen_Crosshairs::Push(L, Lua_Screen::Index(L, 1));
2592 return 1;
2593 }
2594
Lua_Screen_Get_Masking_Mode(lua_State * L)2595 static int Lua_Screen_Get_Masking_Mode(lua_State *L)
2596 {
2597 Lua_MaskingMode::Push(L, Lua_HUDInstance()->masking_mode());
2598 return 1;
2599 }
2600
Lua_Screen_Set_Masking_Mode(lua_State * L)2601 static int Lua_Screen_Set_Masking_Mode(lua_State *L)
2602 {
2603 Lua_HUDInstance()->set_masking_mode(Lua_MaskingMode::ToIndex(L, 2));
2604 return 0;
2605 }
2606
Lua_Screen_Clear_Mask(lua_State * L)2607 int Lua_Screen_Clear_Mask(lua_State *L)
2608 {
2609 Lua_HUDInstance()->clear_mask();
2610 return 0;
2611 }
2612
Lua_Screen_Fill_Rect(lua_State * L)2613 int Lua_Screen_Fill_Rect(lua_State *L)
2614 {
2615 float x = static_cast<float>(lua_tonumber(L, 1));
2616 float y = static_cast<float>(lua_tonumber(L, 2));
2617 float w = static_cast<float>(lua_tonumber(L, 3));
2618 float h = static_cast<float>(lua_tonumber(L, 4));
2619 float r = Lua_HUDColor_Get_R(L, 5);
2620 float g = Lua_HUDColor_Get_G(L, 5);
2621 float b = Lua_HUDColor_Get_B(L, 5);
2622 float a = Lua_HUDColor_Get_A(L, 5);
2623
2624 Lua_HUDInstance()->fill_rect(x, y, w, h, r, g, b, a);
2625 return 0;
2626 }
2627
Lua_Screen_Frame_Rect(lua_State * L)2628 int Lua_Screen_Frame_Rect(lua_State *L)
2629 {
2630 float x = static_cast<float>(lua_tonumber(L, 1));
2631 float y = static_cast<float>(lua_tonumber(L, 2));
2632 float w = static_cast<float>(lua_tonumber(L, 3));
2633 float h = static_cast<float>(lua_tonumber(L, 4));
2634 float r = Lua_HUDColor_Get_R(L, 5);
2635 float g = Lua_HUDColor_Get_G(L, 5);
2636 float b = Lua_HUDColor_Get_B(L, 5);
2637 float a = Lua_HUDColor_Get_A(L, 5);
2638 float thickness = static_cast<float>(lua_tonumber(L, 6));
2639
2640 Lua_HUDInstance()->frame_rect(x, y, w, h, r, g, b, a, thickness);
2641 return 0;
2642 }
2643
2644 const luaL_Reg Lua_Screen_Get[] = {
2645 {"width", Lua_Screen_Get_Width},
2646 {"height", Lua_Screen_Get_Height},
2647 {"renderer", Lua_Screen_Get_Renderer},
2648 {"clip_rect", Lua_Screen_Get_Clip_Rect},
2649 {"world_rect", Lua_Screen_Get_World_Rect},
2650 {"map_rect", Lua_Screen_Get_Map_Rect},
2651 {"term_rect", Lua_Screen_Get_Term_Rect},
2652 {"map_active", Lua_Screen_Get_Map_Active},
2653 {"map_overlay_active", Lua_Screen_Get_Map_Overlay},
2654 {"term_active", Lua_Screen_Get_Term_Active},
2655 {"hud_size_preference", Lua_Screen_Get_HUD_Size},
2656 {"term_size_preference", Lua_Screen_Get_Term_Size},
2657 {"field_of_view", Lua_Screen_Get_FOV},
2658 {"crosshairs", Lua_Screen_Get_Crosshairs},
2659 {"masking_mode", Lua_Screen_Get_Masking_Mode},
2660 {"clear_mask", L_TableFunction<Lua_Screen_Clear_Mask>},
2661 {"fill_rect", L_TableFunction<Lua_Screen_Fill_Rect>},
2662 {"frame_rect", L_TableFunction<Lua_Screen_Frame_Rect>},
2663 {0, 0}
2664 };
2665
2666 const luaL_Reg Lua_Screen_Set[] = {
2667 {"masking_mode", Lua_Screen_Set_Masking_Mode},
2668 {0, 0}
2669 };
2670
2671
2672 char Lua_HUDGame_Player_Name[] = "game_player";
2673 typedef L_Class<Lua_HUDGame_Player_Name> Lua_HUDGame_Player;
2674
Lua_HUDGame_Player_Get_Color(lua_State * L)2675 static int Lua_HUDGame_Player_Get_Color(lua_State *L)
2676 {
2677 Lua_PlayerColor::Push(L, get_player_data(Lua_HUDGame_Player::Index(L, 1))->color);
2678 return 1;
2679 }
2680
Lua_HUDGame_Player_Get_Team(lua_State * L)2681 static int Lua_HUDGame_Player_Get_Team(lua_State *L)
2682 {
2683 Lua_PlayerColor::Push(L, get_player_data(Lua_HUDGame_Player::Index(L, 1))->team);
2684 return 1;
2685 }
2686
Lua_HUDGame_Player_Get_Name(lua_State * L)2687 static int Lua_HUDGame_Player_Get_Name(lua_State *L)
2688 {
2689 lua_pushstring(L, get_player_data(Lua_HUDGame_Player::Index(L, 1))->name);
2690 return 1;
2691 }
2692
Lua_HUDGame_Player_Get_Local(lua_State * L)2693 static int Lua_HUDGame_Player_Get_Local(lua_State *L)
2694 {
2695 lua_pushboolean(L, Lua_HUDGame_Player::Index(L, 1) == local_player_index);
2696 return 1;
2697 }
2698
Lua_HUDGame_Player_Get_Active(lua_State * L)2699 static int Lua_HUDGame_Player_Get_Active(lua_State *L)
2700 {
2701 lua_pushboolean(L, Lua_HUDGame_Player::Index(L, 1) == current_player_index);
2702 return 1;
2703 }
2704
Lua_HUDGame_Player_Get_Kills(lua_State * L)2705 static int Lua_HUDGame_Player_Get_Kills(lua_State *L)
2706 {
2707 short player_index = Lua_HUDGame_Player::Index(L, 1);
2708 struct player_data* player = get_player_data(player_index);
2709 lua_pushnumber(L, player->total_damage_given.kills - player->damage_taken[player_index].kills);
2710 return 1;
2711 }
2712
Lua_HUDGame_Player_Get_Ranking(lua_State * L)2713 static int Lua_HUDGame_Player_Get_Ranking(lua_State *L)
2714 {
2715 short kills, deaths;
2716 lua_pushnumber(L, get_player_net_ranking(Lua_HUDGame_Player::Index(L, 1), &kills, &deaths, false));
2717 return 1;
2718 }
2719
2720 const luaL_Reg Lua_HUDGame_Player_Get[] = {
2721 {"color", Lua_HUDGame_Player_Get_Color},
2722 {"team", Lua_HUDGame_Player_Get_Team},
2723 {"name", Lua_HUDGame_Player_Get_Name},
2724 {"local_", Lua_HUDGame_Player_Get_Local},
2725 {"active", Lua_HUDGame_Player_Get_Active},
2726 {"kills", Lua_HUDGame_Player_Get_Kills},
2727 {"ranking", Lua_HUDGame_Player_Get_Ranking},
2728 {0, 0}
2729 };
2730
Lua_HUDGame_Player_Valid(int16 index)2731 static bool Lua_HUDGame_Player_Valid(int16 index)
2732 {
2733 return index >= 0 && index < dynamic_world->player_count;
2734 }
2735
2736 char Lua_HUDGame_Players_Name[] = "game_players";
2737 typedef L_Class<Lua_HUDGame_Players_Name> Lua_HUDGame_Players;
2738
Lua_HUDGame_Players_Get(lua_State * L)2739 static int Lua_HUDGame_Players_Get(lua_State *L)
2740 {
2741 Lua_HUDGame_Player::Push(L, lua_tointeger(L, 2));
2742 return 1;
2743 }
2744
Lua_HUDGame_Players_Length(lua_State * L)2745 static int Lua_HUDGame_Players_Length(lua_State *L)
2746 {
2747 lua_pushnumber(L, dynamic_world->player_count);
2748 return 1;
2749 }
2750
2751 const luaL_Reg Lua_HUDGame_Players_Metatable[] = {
2752 {"__index", Lua_HUDGame_Players_Get},
2753 {"__len", Lua_HUDGame_Players_Length},
2754 {0, 0}
2755 };
2756
2757
2758 char Lua_HUDGame_Name[] = "Game";
2759 typedef L_Class<Lua_HUDGame_Name> Lua_HUDGame;
2760
Lua_HUDGame_Get_Players(lua_State * L)2761 static int Lua_HUDGame_Get_Players(lua_State *L)
2762 {
2763 Lua_HUDGame_Players::Push(L, Lua_HUDGame::Index(L, 1));
2764 return 1;
2765 }
2766
Lua_HUDGame_Get_Difficulty(lua_State * L)2767 static int Lua_HUDGame_Get_Difficulty(lua_State *L)
2768 {
2769 Lua_DifficultyType::Push(L, dynamic_world->game_information.difficulty_level);
2770 return 1;
2771 }
2772
Lua_HUDGame_Get_Kill_Limit(lua_State * L)2773 static int Lua_HUDGame_Get_Kill_Limit(lua_State *L)
2774 {
2775 if (GET_GAME_OPTIONS() & _game_has_kill_limit)
2776 {
2777 switch (GET_GAME_TYPE())
2778 {
2779 case _game_of_kill_monsters:
2780 case _game_of_cooperative_play:
2781 case _game_of_king_of_the_hill:
2782 case _game_of_kill_man_with_ball:
2783 case _game_of_tag:
2784 lua_pushnumber(L, dynamic_world->game_information.kill_limit);
2785 return 1;
2786 }
2787 }
2788 lua_pushnil(L);
2789 return 1;
2790 }
2791
Lua_HUDGame_Get_Time_Remaining(lua_State * L)2792 static int Lua_HUDGame_Get_Time_Remaining(lua_State* L)
2793 {
2794 if(dynamic_world->game_information.game_time_remaining > 999 * 30)
2795 lua_pushnil(L);
2796 else
2797 lua_pushnumber(L, dynamic_world->game_information.game_time_remaining);
2798 return 1;
2799 }
2800
Lua_HUDGame_Get_Ticks(lua_State * L)2801 static int Lua_HUDGame_Get_Ticks(lua_State *L)
2802 {
2803 lua_pushnumber(L, dynamic_world->tick_count);
2804 return 1;
2805 }
2806
Lua_HUDGame_Get_Type(lua_State * L)2807 static int Lua_HUDGame_Get_Type(lua_State *L)
2808 {
2809 Lua_GameType::Push(L, GET_GAME_TYPE());
2810 return 1;
2811 }
2812
2813 extern int game_scoring_mode;
Lua_HUDGame_Get_Scoring_Mode(lua_State * L)2814 static int Lua_HUDGame_Get_Scoring_Mode(lua_State *L)
2815 {
2816 Lua_ScoringMode::Push(L, game_scoring_mode);
2817 return 1;
2818 }
2819
Lua_HUDGame_Get_Version(lua_State * L)2820 static int Lua_HUDGame_Get_Version(lua_State *L)
2821 {
2822 lua_pushstring(L, A1_DATE_VERSION);
2823 return 1;
2824 }
2825
2826 extern int Lua_Game_Deserialize(lua_State* L);
2827
2828 const luaL_Reg Lua_HUDGame_Get[] = {
2829 {"deserialize", L_TableFunction<Lua_Game_Deserialize>},
2830 {"difficulty", Lua_HUDGame_Get_Difficulty},
2831 {"kill_limit", Lua_HUDGame_Get_Kill_Limit},
2832 {"time_remaining", Lua_HUDGame_Get_Time_Remaining},
2833 {"scoring_mode", Lua_HUDGame_Get_Scoring_Mode},
2834 {"ticks", Lua_HUDGame_Get_Ticks},
2835 {"type", Lua_HUDGame_Get_Type},
2836 {"version", Lua_HUDGame_Get_Version},
2837 {"players", Lua_HUDGame_Get_Players},
2838 {0, 0}
2839 };
2840
2841 char Lua_HUDLevel_Stash_Name[] = "LevelStash";
2842 typedef L_Class<Lua_HUDLevel_Stash_Name> Lua_HUDLevel_Stash;
2843
2844 extern std::unordered_map<std::string, std::string> lua_stash;
2845
Lua_HUDLevel_Stash_Get(lua_State * L)2846 static int Lua_HUDLevel_Stash_Get(lua_State* L)
2847 {
2848 if (!lua_isstring(L, 2))
2849 return luaL_error(L, "stash: incorrect argument type");
2850
2851 auto it = lua_stash.find(lua_tostring(L, 2));
2852 if (it != lua_stash.end())
2853 {
2854 lua_pushlstring(L, it->second.data(), it->second.size());
2855 }
2856 else
2857 {
2858 lua_pushnil(L);
2859 }
2860
2861 return 1;
2862 }
2863
2864 const luaL_Reg Lua_HUDLevel_Stash_Metatable[] = {
2865 {"__index", Lua_HUDLevel_Stash_Get},
2866 {0, 0}
2867 };
2868
2869
2870
2871 char Lua_HUDLevel_Name[] = "Level";
2872 typedef L_Class<Lua_HUDLevel_Name> Lua_HUDLevel;
2873
Lua_HUDLevel_Get_Name(lua_State * L)2874 static int Lua_HUDLevel_Get_Name(lua_State *L)
2875 {
2876 lua_pushstring(L, static_world->level_name);
2877 return 1;
2878 }
2879
Lua_HUDLevel_Get_Index(lua_State * L)2880 static int Lua_HUDLevel_Get_Index(lua_State *L)
2881 {
2882 lua_pushinteger(L, dynamic_world->current_level_number);
2883 return 1;
2884 }
2885
Lua_HUDLevel_Get_Map_Checksum(lua_State * L)2886 static int Lua_HUDLevel_Get_Map_Checksum(lua_State *L)
2887 {
2888 #if !defined(DISABLE_NETWORKING)
2889 if (game_is_networked)
2890 lua_pushinteger(L, ((game_info *) NetGetGameData())->parent_checksum);
2891 else
2892 #endif
2893 lua_pushinteger(L, get_current_map_checksum());
2894 return 1;
2895 }
2896
Lua_HUDLevel_Get_Stash(lua_State * L)2897 static int Lua_HUDLevel_Get_Stash(lua_State* L)
2898 {
2899 Lua_HUDLevel_Stash::Push(L, 0);
2900 return 1;
2901 }
2902
2903 const luaL_Reg Lua_HUDLevel_Get[] = {
2904 {"name", Lua_HUDLevel_Get_Name},
2905 {"index", Lua_HUDLevel_Get_Index},
2906 {"map_checksum", Lua_HUDLevel_Get_Map_Checksum},
2907 {"stash", Lua_HUDLevel_Get_Stash},
2908 {0, 0}
2909 };
2910
2911
2912 char Lua_HUDLighting_Fader_Name[] = "lighting_fader";
2913 typedef L_Class<Lua_HUDLighting_Fader_Name> Lua_HUDLighting_Fader;
2914
Lua_HUDLighting_Fader_Get_Active(lua_State * L)2915 static int Lua_HUDLighting_Fader_Get_Active(lua_State *L)
2916 {
2917 bool active = false;
2918 #ifdef HAVE_OPENGL
2919 if (OGL_FaderActive())
2920 {
2921 OGL_Fader *fader = GetOGL_FaderQueueEntry(Lua_HUDLighting_Fader::Index(L, 1));
2922 if (fader && fader->Type != NONE && fader->Color[3] > 0.01)
2923 active = true;
2924 }
2925 #endif
2926 lua_pushboolean(L, active);
2927 return 1;
2928 }
2929
2930
Lua_HUDLighting_Fader_Get_Type(lua_State * L)2931 static int Lua_HUDLighting_Fader_Get_Type(lua_State *L)
2932 {
2933 #ifdef HAVE_OPENGL
2934 if (OGL_FaderActive())
2935 {
2936 OGL_Fader *fader = GetOGL_FaderQueueEntry(Lua_HUDLighting_Fader::Index(L, 1));
2937 if (fader && fader->Type != NONE && fader->Color[3] > 0.01)
2938 {
2939 Lua_FadeEffectType::Push(L, fader->Type);
2940 return 1;
2941 }
2942 }
2943 #endif
2944 lua_pushnil(L);
2945 return 1;
2946 }
2947
Lua_HUDLighting_Fader_Get_Color(lua_State * L)2948 static int Lua_HUDLighting_Fader_Get_Color(lua_State *L)
2949 {
2950 #ifdef HAVE_OPENGL
2951 if (OGL_FaderActive())
2952 {
2953 OGL_Fader *fader = GetOGL_FaderQueueEntry(Lua_HUDLighting_Fader::Index(L, 1));
2954 if (fader && fader->Type != NONE && fader->Color[3] > 0.01)
2955 {
2956 lua_newtable(L);
2957 lua_pushstring(L, "r");
2958 lua_pushnumber(L, std::min(1.f, std::max(0.f, fader->Color[0])));
2959 lua_settable(L, -3);
2960 lua_pushstring(L, "g");
2961 lua_pushnumber(L, std::min(1.f, std::max(0.f, fader->Color[1])));
2962 lua_settable(L, -3);
2963 lua_pushstring(L, "b");
2964 lua_pushnumber(L, std::min(1.f, std::max(0.f, fader->Color[2])));
2965 lua_settable(L, -3);
2966 lua_pushstring(L, "a");
2967 lua_pushnumber(L, std::min(1.f, std::max(0.f, fader->Color[3])));
2968 lua_settable(L, -3);
2969 return 1;
2970 }
2971 }
2972 #endif
2973 lua_pushnil(L);
2974 return 1;
2975 }
2976
2977 const luaL_Reg Lua_HUDLighting_Fader_Get[] = {
2978 {"active", Lua_HUDLighting_Fader_Get_Active},
2979 {"type", Lua_HUDLighting_Fader_Get_Type},
2980 {"color", Lua_HUDLighting_Fader_Get_Color},
2981 {0, 0}
2982 };
2983
2984 char Lua_HUDLighting_Name[] = "Lighting";
2985 typedef L_Class<Lua_HUDLighting_Name> Lua_HUDLighting;
2986
Lua_HUDLighting_Get_Ambient(lua_State * L)2987 static int Lua_HUDLighting_Get_Ambient(lua_State *L)
2988 {
2989 lua_pushnumber(L, get_light_intensity(get_polygon_data(world_view->origin_polygon_index)->floor_lightsource_index)/65535.f);
2990 return 1;
2991 }
2992
Lua_HUDLighting_Get_Weapon(lua_State * L)2993 static int Lua_HUDLighting_Get_Weapon(lua_State *L)
2994 {
2995 lua_pushnumber(L, PIN(current_player->weapon_intensity - NATURAL_LIGHT_INTENSITY, 0, FIXED_ONE)/float(FIXED_ONE));
2996 return 1;
2997 }
2998
Lua_HUDLighting_Get_Liquid_Fader(lua_State * L)2999 static int Lua_HUDLighting_Get_Liquid_Fader(lua_State *L)
3000 {
3001 Lua_HUDLighting_Fader::Push(L, FaderQueue_Liquid);
3002 return 1;
3003 }
3004
Lua_HUDLighting_Get_Damage_Fader(lua_State * L)3005 static int Lua_HUDLighting_Get_Damage_Fader(lua_State *L)
3006 {
3007 Lua_HUDLighting_Fader::Push(L, FaderQueue_Other);
3008 return 1;
3009 }
3010
3011 const luaL_Reg Lua_HUDLighting_Get[] = {
3012 {"ambient_light", Lua_HUDLighting_Get_Ambient},
3013 {"weapon_flash", Lua_HUDLighting_Get_Weapon},
3014 {"liquid_fader", Lua_HUDLighting_Get_Liquid_Fader},
3015 {"damage_fader", Lua_HUDLighting_Get_Damage_Fader},
3016 {0, 0}
3017 };
3018
3019
Lua_InterfaceColor_Get_R(lua_State * L)3020 static int Lua_InterfaceColor_Get_R(lua_State *L)
3021 {
3022 rgb_color clr = get_interface_color(Lua_InterfaceColor::Index(L, 1));
3023 lua_pushnumber(L, clr.red / 65535.0);
3024 return 1;
3025 }
3026
Lua_InterfaceColor_Get_G(lua_State * L)3027 static int Lua_InterfaceColor_Get_G(lua_State *L)
3028 {
3029 rgb_color clr = get_interface_color(Lua_InterfaceColor::Index(L, 1));
3030 lua_pushnumber(L, clr.green / 65535.0);
3031 return 1;
3032 }
3033
Lua_InterfaceColor_Get_B(lua_State * L)3034 static int Lua_InterfaceColor_Get_B(lua_State *L)
3035 {
3036 rgb_color clr = get_interface_color(Lua_InterfaceColor::Index(L, 1));
3037 lua_pushnumber(L, clr.blue / 65535.0);
3038 return 1;
3039 }
3040
Lua_InterfaceColor_Get_A(lua_State * L)3041 static int Lua_InterfaceColor_Get_A(lua_State *L)
3042 {
3043 lua_pushnumber(L, 1.0);
3044 return 1;
3045 }
3046
3047 const luaL_Reg Lua_InterfaceColor_Get[] = {
3048 {"r", Lua_InterfaceColor_Get_R},
3049 {"g", Lua_InterfaceColor_Get_G},
3050 {"b", Lua_InterfaceColor_Get_B},
3051 {"a", Lua_InterfaceColor_Get_A},
3052 {"red", Lua_InterfaceColor_Get_R},
3053 {"green", Lua_InterfaceColor_Get_G},
3054 {"blue", Lua_InterfaceColor_Get_B},
3055 {"alpha", Lua_InterfaceColor_Get_A},
3056 {0, 0}
3057 };
3058
3059
Lua_InterfaceRect_Get_X(lua_State * L)3060 static int Lua_InterfaceRect_Get_X(lua_State *L)
3061 {
3062 screen_rectangle *r = get_interface_rectangle(Lua_InterfaceRect::Index(L, 1));
3063 lua_pushnumber(L, r->left);
3064 return 1;
3065 }
3066
Lua_InterfaceRect_Get_Y(lua_State * L)3067 static int Lua_InterfaceRect_Get_Y(lua_State *L)
3068 {
3069 screen_rectangle *r = get_interface_rectangle(Lua_InterfaceRect::Index(L, 1));
3070 lua_pushnumber(L, r->top);
3071 return 1;
3072 }
3073
Lua_InterfaceRect_Get_Width(lua_State * L)3074 static int Lua_InterfaceRect_Get_Width(lua_State *L)
3075 {
3076 screen_rectangle *r = get_interface_rectangle(Lua_InterfaceRect::Index(L, 1));
3077 lua_pushnumber(L, r->right - r->left);
3078 return 1;
3079 }
3080
Lua_InterfaceRect_Get_Height(lua_State * L)3081 static int Lua_InterfaceRect_Get_Height(lua_State *L)
3082 {
3083 screen_rectangle *r = get_interface_rectangle(Lua_InterfaceRect::Index(L, 1));
3084 lua_pushnumber(L, r->bottom - r->top);
3085 return 1;
3086 }
3087
3088 const luaL_Reg Lua_InterfaceRect_Get[] = {
3089 {"x", Lua_InterfaceRect_Get_X},
3090 {"y", Lua_InterfaceRect_Get_Y},
3091 {"width", Lua_InterfaceRect_Get_Width},
3092 {"height", Lua_InterfaceRect_Get_Height},
3093 {0, 0}
3094 };
3095
3096
3097
3098 extern bool collection_loaded(short);
3099
Lua_HUDObjects_register(lua_State * L)3100 int Lua_HUDObjects_register(lua_State *L)
3101 {
3102 Lua_Collection::Register(L, Lua_Collection_Get, 0, 0, Lua_Collection_Mnemonics);
3103 Lua_Collection::Valid = collection_loaded;
3104
3105 Lua_Collections::Register(L);
3106 Lua_Collections::Length = Lua_Collections::ConstantLength(MAXIMUM_COLLECTIONS);
3107
3108 Lua_DifficultyType::Register(L, 0, 0, 0, Lua_DifficultyType_Mnemonics);
3109 Lua_DifficultyType::Valid = Lua_DifficultyType::ValidRange(NUMBER_OF_GAME_DIFFICULTY_LEVELS);
3110
3111 Lua_DifficultyTypes::Register(L);
3112 Lua_DifficultyTypes::Length = Lua_DifficultyTypes::ConstantLength(NUMBER_OF_GAME_DIFFICULTY_LEVELS);
3113
3114 Lua_FadeEffectType::Register(L, 0, 0, 0, Lua_FadeEffectType_Mnemonics);
3115 Lua_FadeEffectType::Valid = Lua_FadeEffectType::ValidRange(NUMBER_OF_FADER_FUNCTIONS);
3116
3117 Lua_FadeEffectTypes::Register(L);
3118 Lua_FadeEffectTypes::Length = Lua_FadeEffectTypes::ConstantLength(NUMBER_OF_FADER_FUNCTIONS);
3119
3120 Lua_MaskingMode::Register(L, 0, 0, 0, Lua_MaskingMode_Mnemonics);
3121 Lua_MaskingMode::Valid = Lua_MaskingMode::ValidRange(NUMBER_OF_LUA_MASKING_MODES);
3122
3123 Lua_MaskingModes::Register(L);
3124 Lua_MaskingModes::Length = Lua_MaskingModes::ConstantLength(NUMBER_OF_LUA_MASKING_MODES);
3125
3126 Lua_GameType::Register(L, 0, 0, 0, Lua_GameType_Mnemonics);
3127 Lua_GameType::Valid = Lua_GameType::ValidRange(NUMBER_OF_GAME_TYPES);
3128
3129 Lua_GameTypes::Register(L);
3130 Lua_GameTypes::Length = Lua_GameTypes::ConstantLength(NUMBER_OF_GAME_TYPES);
3131
3132 Lua_InterfaceColor::Register(L, Lua_InterfaceColor_Get, 0, 0, Lua_InterfaceColor_Mnemonics);
3133 Lua_InterfaceColor::Valid = Lua_InterfaceColor::ValidRange(NUMBER_OF_INTERFACE_COLORS);
3134
3135 Lua_InterfaceColors::Register(L);
3136 Lua_InterfaceColors::Length = Lua_InterfaceColors::ConstantLength(NUMBER_OF_INTERFACE_COLORS);
3137
3138 Lua_InterfaceRect::Register(L, Lua_InterfaceRect_Get, 0, 0, Lua_InterfaceRect_Mnemonics);
3139 Lua_InterfaceRect::Valid = Lua_InterfaceRect::ValidRange(NUMBER_OF_INTERFACE_RECTANGLES);
3140
3141 Lua_InterfaceRects::Register(L);
3142 Lua_InterfaceRects::Length = Lua_InterfaceRects::ConstantLength(NUMBER_OF_INTERFACE_RECTANGLES);
3143
3144 Lua_InterfaceFont::Register(L, 0, 0, 0, Lua_InterfaceFont_Mnemonics);
3145 Lua_InterfaceFont::Valid = Lua_InterfaceFont::ValidRange(NUMBER_OF_INTERFACE_FONTS);
3146
3147 Lua_InterfaceFonts::Register(L);
3148 Lua_InterfaceFonts::Length = Lua_InterfaceFonts::ConstantLength(NUMBER_OF_INTERFACE_FONTS);
3149
3150 Lua_InventorySection::Register(L, 0, 0, 0, Lua_InventorySection_Mnemonics);
3151 Lua_InventorySection::Valid = Lua_InventorySection::ValidRange(NUMBER_OF_ITEM_TYPES + 1);
3152
3153 Lua_InventorySections::Register(L);
3154 Lua_InventorySections::Length = Lua_InventorySections::ConstantLength(NUMBER_OF_ITEM_TYPES + 1);
3155
3156 Lua_ItemType::Register(L, Lua_ItemType_Get, 0, 0, Lua_ItemType_Mnemonics);
3157 Lua_ItemType::Valid = Lua_ItemType::ValidRange(NUMBER_OF_DEFINED_ITEMS);
3158
3159 Lua_ItemTypes::Register(L);
3160 Lua_ItemTypes::Length = Lua_ItemTypes::ConstantLength(NUMBER_OF_DEFINED_ITEMS);
3161
3162 Lua_PlayerColor::Register(L, 0, 0, 0, Lua_PlayerColor_Mnemonics);
3163 Lua_PlayerColor::Valid = Lua_PlayerColor::ValidRange(NUMBER_OF_TEAM_COLORS);
3164
3165 Lua_PlayerColors::Register(L);
3166 Lua_PlayerColors::Length = Lua_PlayerColors::ConstantLength((int16) NUMBER_OF_TEAM_COLORS);
3167
3168 Lua_RendererType::Register(L, 0, 0, 0, Lua_RendererType_Mnemonics);
3169 Lua_RendererType::Valid = Lua_RendererType::ValidRange(NUMBER_OF_RENDERER_TYPES);
3170
3171 Lua_RendererTypes::Register(L);
3172 Lua_RendererTypes::Length = Lua_RendererTypes::ConstantLength(NUMBER_OF_RENDERER_TYPES);
3173
3174 Lua_ScoringMode::Register(L, 0, 0, 0, Lua_ScoringMode_Mnemonics);
3175 Lua_ScoringMode::Valid = Lua_ScoringMode::ValidRange(NUMBER_OF_GAME_SCORING_MODES);
3176
3177 Lua_ScoringModes::Register(L);
3178 Lua_ScoringModes::Length = Lua_ScoringModes::ConstantLength(NUMBER_OF_GAME_SCORING_MODES);
3179
3180 Lua_SizePreference::Register(L, 0, 0, 0, Lua_SizePref_Mnemonics);
3181 Lua_SizePreference::Valid = Lua_SizePreference::ValidRange(NUMBER_OF_SIZE_PREFERENCES);
3182
3183 Lua_SizePreferences::Register(L);
3184 Lua_SizePreferences::Length = Lua_SizePreferences::ConstantLength(NUMBER_OF_SIZE_PREFERENCES);
3185
3186 Lua_SensorBlipType::Register(L, 0, 0, 0, Lua_SensorBlipType_Mnemonics);
3187 Lua_SensorBlipType::Valid = Lua_SensorBlipType::ValidRange(NUMBER_OF_MDISPTYPES);
3188
3189 Lua_SensorBlipTypes::Register(L);
3190 Lua_SensorBlipTypes::Length = Lua_SensorBlipTypes::ConstantLength(NUMBER_OF_MDISPTYPES);
3191
3192 Lua_TextureType::Register(L, 0, 0, 0, Lua_TextureType_Mnemonics);
3193 Lua_TextureType::Valid = Lua_TextureType::ValidRange(NUMBER_OF_LUA_TEXTURE_TYPES);
3194
3195 Lua_TextureTypes::Register(L);
3196 Lua_TextureTypes::Length = Lua_TextureTypes::ConstantLength(NUMBER_OF_LUA_TEXTURE_TYPES);
3197
3198 Lua_WeaponType::Register(L, 0, 0, 0, Lua_WeaponType_Mnemonics);
3199 Lua_WeaponType::Valid = Lua_WeaponType::ValidRange(MAXIMUM_NUMBER_OF_WEAPONS);
3200
3201 Lua_WeaponTypes::Register(L);
3202 Lua_WeaponTypes::Length = Lua_WeaponTypes::ConstantLength((int16) MAXIMUM_NUMBER_OF_WEAPONS);
3203
3204 Lua_HUDPlayer_Weapon::Register(L, Lua_HUDPlayer_Weapon_Get);
3205 Lua_HUDPlayer_Weapon::Valid = Lua_HUDPlayer_Weapon::ValidRange(MAXIMUM_NUMBER_OF_WEAPONS);
3206
3207 Lua_HUDPlayer_Weapons::Register(L, 0, 0, Lua_HUDPlayer_Weapons_Metatable);
3208
3209 Lua_HUDPlayer_Section::Register(L, Lua_HUDPlayer_Section_Get);
3210 Lua_HUDPlayer_Section::Valid = Lua_HUDPlayer_Section::ValidRange(NUMBER_OF_ITEM_TYPES + 1);
3211
3212 Lua_HUDPlayer_Sections::Register(L, 0, 0, Lua_HUDPlayer_Sections_Metatable);
3213
3214 Lua_HUDPlayer_Weapon_Trigger_Bullet::Register(L, Lua_HUDPlayer_Weapon_Trigger_Bullet_Get);
3215 Lua_HUDPlayer_Weapon_Trigger_Bullet::Valid = Lua_HUDPlayer_Weapon_Trigger_Bullet::ValidRange((int) _secondary_weapon + 1);
3216
3217 Lua_HUDPlayer_Weapon_Trigger_Energy::Register(L, Lua_HUDPlayer_Weapon_Trigger_Energy_Get);
3218 Lua_HUDPlayer_Weapon_Trigger_Energy::Valid = Lua_HUDPlayer_Weapon_Trigger_Energy::ValidRange((int) _secondary_weapon + 1);
3219
3220 Lua_HUDPlayer_Weapon_Trigger::Register(L, Lua_HUDPlayer_Weapon_Trigger_Get);
3221 Lua_HUDPlayer_Weapon_Trigger::Valid = Lua_HUDPlayer_Weapon_Trigger::ValidRange((int) _secondary_weapon + 1);
3222
3223 Lua_HUDPlayer_Weapon_Name_Rect::Register(L, Lua_HUDPlayer_Weapon_Name_Rect_Get);
3224 Lua_HUDPlayer_Weapon_Name_Rect::Valid = Lua_HUDPlayer_Weapon::Valid;
3225
3226 Lua_HUDPlayer_Weapon_SingleShape::Register(L, Lua_HUDPlayer_Weapon_SingleShape_Get);
3227 Lua_HUDPlayer_Weapon_SingleShape::Valid = Lua_HUDPlayer_Weapon::Valid;
3228
3229 Lua_HUDPlayer_Weapon_MultShape::Register(L, Lua_HUDPlayer_Weapon_MultShape_Get);
3230 Lua_HUDPlayer_Weapon_MultShape::Valid = Lua_HUDPlayer_Weapon::Valid;
3231
3232 Lua_HUDPlayer_Weapon_UnusableShape::Register(L, Lua_HUDPlayer_Weapon_UnusableShape_Get);
3233 Lua_HUDPlayer_Weapon_UnusableShape::Valid = Lua_HUDPlayer_Weapon::Valid;
3234
3235 Lua_HUDPlayer_Item::Register(L, Lua_HUDPlayer_Item_Get);
3236 Lua_HUDPlayer_Item::Valid = Lua_HUDPlayer_Item::ValidRange(NUMBER_OF_DEFINED_ITEMS);
3237
3238 Lua_HUDPlayer_Items::Register(L, 0, 0, Lua_HUDPlayer_Items_Metatable);
3239
3240 Lua_MotionSensor_Blip::Register(L, Lua_MotionSensor_Blip_Get);
3241 Lua_MotionSensor_Blip::Valid = Lua_MotionSensor_Blip_Valid;
3242
3243 Lua_MotionSensor_Blips::Register(L, 0, 0, Lua_MotionSensor_Blips_Metatable);
3244
3245 Lua_MotionSensor::Register(L, Lua_MotionSensor_Get);
3246
3247 Lua_HUDCompass::Register(L, Lua_HUDCompass_Get);
3248
3249 Lua_HUDTexturePalette_Slot::Register(L, Lua_HUDTexturePalette_Slot_Get);
3250 Lua_HUDTexturePalette_Slot::Valid = Lua_HUDTexturePalette_Slot_Valid;
3251
3252 Lua_HUDTexturePalette_Slots::Register(L, 0, 0, Lua_HUDTexturePalette_Slots_Metatable);
3253
3254 Lua_HUDTexturePalette::Register(L, Lua_HUDTexturePalette_Get);
3255
3256 Lua_HUDPlayer_Velocity::Register(L, Lua_HUDPlayer_Velocity_Get);
3257
3258 Lua_HUDPlayer::Register(L, Lua_HUDPlayer_Get);
3259 Lua_HUDPlayer::Push(L, 0);
3260 lua_setglobal(L, Lua_HUDPlayer_Name);
3261
3262 Lua_Screen_Clip_Rect::Register(L, Lua_Screen_Clip_Rect_Get, Lua_Screen_Clip_Rect_Set);
3263 Lua_Screen_World_Rect::Register(L, Lua_Screen_World_Rect_Get, Lua_Screen_World_Rect_Set);
3264 Lua_Screen_Map_Rect::Register(L, Lua_Screen_Map_Rect_Get, Lua_Screen_Map_Rect_Set);
3265 Lua_Screen_Term_Rect::Register(L, Lua_Screen_Term_Rect_Get, Lua_Screen_Term_Rect_Set);
3266 Lua_Screen_FOV::Register(L, Lua_Screen_FOV_Get, Lua_Screen_FOV_Set);
3267 Lua_Screen_Crosshairs::Register(L, Lua_Screen_Crosshairs_Get, Lua_Screen_Crosshairs_Set);
3268
3269 Lua_Screen::Register(L, Lua_Screen_Get, Lua_Screen_Set);
3270 Lua_Screen::Push(L, 0);
3271 lua_setglobal(L, Lua_Screen_Name);
3272
3273 Lua_HUDGame_Player::Register(L, Lua_HUDGame_Player_Get);
3274 Lua_HUDGame_Player::Valid = Lua_HUDGame_Player_Valid;
3275
3276 Lua_HUDGame_Players::Register(L, 0, 0, Lua_HUDGame_Players_Metatable);
3277
3278 Lua_HUDGame::Register(L, Lua_HUDGame_Get);
3279 Lua_HUDGame::Push(L, 0);
3280 lua_setglobal(L, Lua_HUDGame_Name);
3281
3282 Lua_HUDLevel_Stash::Register(L, 0, 0, Lua_HUDLevel_Stash_Metatable);
3283
3284 Lua_HUDLevel::Register(L, Lua_HUDLevel_Get);
3285 Lua_HUDLevel::Push(L, 0);
3286 lua_setglobal(L, Lua_HUDLevel_Name);
3287
3288 Lua_Font::Register(L, Lua_Font_Get, Lua_Font_Set, Lua_Font_Metatable);
3289
3290 Lua_Fonts::Register(L, Lua_Fonts_Get);
3291 Lua_Fonts::Push(L, 0);
3292 lua_setglobal(L, Lua_Fonts_Name);
3293
3294 Lua_Image_Crop_Rect::Register(L, Lua_Image_Crop_Rect_Get, Lua_Image_Crop_Rect_Set);
3295 Lua_Image_Crop_Rect::Valid = Lua_Image::Valid;
3296
3297 Lua_Image::Register(L, Lua_Image_Get, Lua_Image_Set, Lua_Image_Metatable);
3298
3299 Lua_Images::Register(L, Lua_Images_Get);
3300 Lua_Images::Push(L, 0);
3301 lua_setglobal(L, Lua_Images_Name);
3302
3303 Lua_Shape_Crop_Rect::Register(L, Lua_Shape_Crop_Rect_Get, Lua_Shape_Crop_Rect_Set);
3304 Lua_Shape_Crop_Rect::Valid = Lua_Shape::Valid;
3305
3306 Lua_Shape::Register(L, Lua_Shape_Get, Lua_Shape_Set, Lua_Shape_Metatable);
3307
3308 Lua_Shapes::Register(L, Lua_Shapes_Get);
3309 Lua_Shapes::Push(L, 0);
3310 lua_setglobal(L, Lua_Shapes_Name);
3311
3312 Lua_HUDLighting_Fader::Register(L, Lua_HUDLighting_Fader_Get);
3313 Lua_HUDLighting_Fader::Valid = Lua_HUDLighting_Fader::ValidRange(NUMBER_OF_FADER_QUEUE_ENTRIES);
3314
3315 Lua_HUDLighting::Register(L, Lua_HUDLighting_Get);
3316 Lua_HUDLighting::Push(L, 0);
3317 lua_setglobal(L, Lua_HUDLighting_Name);
3318
3319 return 0;
3320 }
3321
3322 #endif
3323