naev 0.12.5
nlua_spob.c
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
10#include "naev.h"
11
12#include <ctype.h>
13#include <lauxlib.h>
15
16#include "nlua_spob.h"
17
18#include "array.h"
19#include "land.h"
20#include "land_outfits.h"
21#include "map_overlay.h"
22#include "nlua_colour.h"
23#include "nlua_commodity.h"
24#include "nlua_faction.h"
25#include "nlua_outfit.h"
26#include "nlua_ship.h"
27#include "nlua_system.h"
28#include "nlua_tex.h"
29#include "nlua_time.h"
30#include "nlua_vec2.h"
31#include "nluadef.h"
32#include "nmath.h"
33
34/* Spob metatable methods */
35static int spobL_cur( lua_State *L );
36static int spobL_get( lua_State *L );
37static int spobL_getS( lua_State *L );
38static int spobL_getLandable( lua_State *L );
39static int spobL_getAll( lua_State *L );
40static int spobL_system( lua_State *L );
41static int spobL_eq( lua_State *L );
42static int spobL_name( lua_State *L );
43static int spobL_nameRaw( lua_State *L );
44static int spobL_population( lua_State *L );
45static int spobL_radius( lua_State *L );
46static int spobL_faction( lua_State *L );
47static int spobL_reputation( lua_State *L );
48static int spobL_colour( lua_State *L );
49static int spobL_colourChar( lua_State *L );
50static int spobL_class( lua_State *L );
51static int spobL_classLong( lua_State *L );
52static int spobL_position( lua_State *L );
53static int spobL_services( lua_State *L );
54static int spobL_flags( lua_State *L );
55static int spobL_canland( lua_State *L );
56static int spobL_landAllow( lua_State *L );
57static int spobL_landDeny( lua_State *L );
58static int spobL_getLandAllow( lua_State *L );
59static int spobL_getLandDeny( lua_State *L );
60static int spobL_gfxSpace( lua_State *L );
61static int spobL_gfxExterior( lua_State *L );
62static int spobL_gfxExteriorPath( lua_State *L );
63static int spobL_gfxComm( lua_State *L );
64static int spobL_shipsSold( lua_State *L );
65static int spobL_outfitsSold( lua_State *L );
66static int spobL_commoditiesSold( lua_State *L );
67static int spobL_isBlackMarket( lua_State *L );
68static int spobL_isKnown( lua_State *L );
69static int spobL_setKnown( lua_State *L );
70static int spobL_isHostile( lua_State *L );
71static int spobL_setHostile( lua_State *L );
72static int spobL_recordCommodityPriceAtTime( lua_State *L );
73static int spobL_tags( lua_State *L );
74
75static const luaL_Reg spob_methods[] = {
76 { "cur", spobL_cur },
77 { "get", spobL_get },
78 { "getS", spobL_getS },
79 { "getLandable", spobL_getLandable },
80 { "getAll", spobL_getAll },
81 { "system", spobL_system },
82 { "__eq", spobL_eq },
83 { "__tostring", spobL_name },
84 { "name", spobL_name },
85 { "nameRaw", spobL_nameRaw },
86 { "population", spobL_population },
87 { "radius", spobL_radius },
88 { "faction", spobL_faction },
89 { "reputation", spobL_reputation },
90 { "colour", spobL_colour },
91 { "colourChar", spobL_colourChar },
92 { "class", spobL_class },
93 { "classLong", spobL_classLong },
94 { "pos", spobL_position },
95 { "services", spobL_services },
96 { "flags", spobL_flags },
97 { "canLand", spobL_canland },
98 { "landAllow", spobL_landAllow },
99 { "landDeny", spobL_landDeny },
100 { "getLandAllow", spobL_getLandAllow },
101 { "getLandDeny", spobL_getLandDeny },
102 { "gfxSpace", spobL_gfxSpace },
103 { "gfxExterior", spobL_gfxExterior },
104 { "gfxExteriorPath", spobL_gfxExteriorPath },
105 { "gfxComm", spobL_gfxComm },
106 { "shipsSold", spobL_shipsSold },
107 { "outfitsSold", spobL_outfitsSold },
108 { "commoditiesSold", spobL_commoditiesSold },
109 { "blackmarket", spobL_isBlackMarket },
110 { "known", spobL_isKnown },
111 { "setKnown", spobL_setKnown },
112 { "hostile", spobL_isHostile },
113 { "setHostile", spobL_setHostile },
114 { "recordCommodityPriceAtTime", spobL_recordCommodityPriceAtTime },
115 { "tags", spobL_tags },
116 { 0, 0 } };
117
124int nlua_loadSpob( nlua_env env )
125{
126 nlua_register( env, SPOB_METATABLE, spob_methods, 1 );
127 return 0; /* No error */
128}
129
152LuaSpob lua_tospob( lua_State *L, int ind )
153{
154 return *( (LuaSpob *)lua_touserdata( L, ind ) );
155}
156
163LuaSpob luaL_checkspob( lua_State *L, int ind )
164{
165 if (lua_isspob( L, ind ))
166 return lua_tospob( L, ind );
167 luaL_typerror( L, ind, SPOB_METATABLE );
168 return 0;
169}
170
177Spob *luaL_validspob( lua_State *L, int ind )
178{
179 Spob *p;
180
181 if (lua_isspob( L, ind )) {
182 LuaSpob lp = luaL_checkspob( L, ind );
183 p = spob_getIndex( lp );
184 } else if (lua_isstring( L, ind ))
185 p = spob_get( lua_tostring( L, ind ) );
186 else {
187 luaL_typerror( L, ind, SPOB_METATABLE );
188 return NULL;
189 }
190
191 if (p == NULL)
192 NLUA_ERROR( L, _( "Spob is invalid" ) );
193
194 return p;
195}
196
203LuaSpob *lua_pushspob( lua_State *L, LuaSpob spob )
204{
205 LuaSpob *p = (LuaSpob *)lua_newuserdata( L, sizeof( LuaSpob ) );
206 *p = spob;
207 luaL_getmetatable( L, SPOB_METATABLE );
208 lua_setmetatable( L, -2 );
209 return p;
210}
211
218int lua_isspob( lua_State *L, int ind )
219{
220 int ret;
221
222 if (lua_getmetatable( L, ind ) == 0)
223 return 0;
224 lua_getfield( L, LUA_REGISTRYINDEX, SPOB_METATABLE );
225
226 ret = 0;
227 if (lua_rawequal( L, -1, -2 )) /* does it have the correct mt? */
228 ret = 1;
229
230 lua_pop( L, 2 ); /* remove both metatables */
231 return ret;
232}
233
243static int spobL_cur( lua_State *L )
244{
245 LuaSystem sys;
246 if (land_spob == NULL)
247 return NLUA_ERROR(
248 L, _( "Attempting to get landed spob when player not landed." ) );
251 lua_pushsystem( L, sys );
252 return 2;
253}
254
255static int spobL_getBackend( lua_State *L, int system, int landable )
256{
257 char **spobs;
258 const char *rndspob;
259 Spob *pnt;
260
261 rndspob = NULL;
262 spobs = NULL;
263
264 /* If boolean return random. */
265 if (lua_isboolean( L, 1 )) {
266 pnt = spob_get( space_getRndSpob( landable, 0, NULL ) );
267 rndspob = pnt->name;
268 }
269 /* Get a spob by faction */
270 else if (lua_isfaction( L, 1 )) {
271 int *factions = array_create( int );
272 array_push_back( &factions, lua_tofaction( L, 1 ) );
273 spobs = space_getFactionSpob( factions, landable );
274 array_free( factions );
275 }
276 /* Get a spob by name */
277 else if (lua_isstring( L, 1 )) {
278 rndspob = lua_tostring( L, 1 );
279
280 if (landable) {
281 pnt = spob_get( rndspob );
282 if (pnt == NULL)
283 return NLUA_ERROR( L, _( "Spob '%s' not found in stack" ),
284 rndspob );
285
286 /* Check if can land. */
287 spob_updateLand( pnt );
288 if (!pnt->can_land)
289 return 0;
290 }
291 }
292 /* Get a spob from faction list */
293 else if (lua_istable( L, 1 )) {
294 /* Get table length and preallocate. */
295 int *factions = array_create_size( int, lua_objlen( L, 1 ) );
296 /* Load up the table. */
297 lua_pushnil( L );
298 while (lua_next( L, -2 ) != 0) {
299 if (lua_isfaction( L, -1 ))
300 array_push_back( &factions, lua_tofaction( L, -1 ) );
301 lua_pop( L, 1 );
302 }
303
304 /* get the spobs */
305 spobs = space_getFactionSpob( factions, landable );
306 array_free( factions );
307 }
308 /* Just get a spob. */
309 else if (lua_isspob( L, 1 )) {
310 pnt = luaL_validspob( L, 1 );
311 if (landable) {
312 /* Check if can land. */
313 spob_updateLand( pnt );
314 if (!pnt->can_land)
315 return 0;
316 }
317 rndspob = pnt->name;
318 } else
319 NLUA_INVALID_PARAMETER( L, 1 ); /* Bad Parameter */
320
321 /* Pick random spob */
322 if (rndspob == NULL) {
323 arrayShuffle( (void **)spobs );
324
325 for (int i = 0; i < array_size( spobs ); i++) {
326 if (landable) {
327 /* Check landing. */
328 pnt = spob_get( spobs[i] );
329 if (pnt == NULL)
330 continue;
331
332 spob_updateLand( pnt );
333 if (!pnt->can_land)
334 continue;
335 }
336
337 rndspob = spobs[i];
338 break;
339 }
340 }
341 array_free( spobs );
342
343 /* No suitable spob found */
344 if (rndspob == NULL && array_size( spobs ) == 0)
345 return 0;
346
347 /* Push the spob */
348 pnt = spob_get( rndspob ); /* The real spob */
349 if (pnt == NULL)
350 return NLUA_ERROR( L, _( "Spob '%s' not found in stack" ), rndspob );
351 lua_pushspob( L, spob_index( pnt ) );
352 if (system) {
353 LuaSystem sys;
354 const char *sysname = spob_getSystemName( rndspob );
355 if (sysname == NULL)
356 return 1;
357 sys = system_index( system_get( sysname ) );
358 lua_pushsystem( L, sys );
359 return 2;
360 }
361 return 1;
362}
363
384static int spobL_get( lua_State *L )
385{
386 return spobL_getBackend( L, 0, 0 );
387}
388
410static int spobL_getS( lua_State *L )
411{
412 return spobL_getBackend( L, 1, 0 );
413}
414
426static int spobL_getLandable( lua_State *L )
427{
428 return spobL_getBackend( L, 1, 1 );
429}
430
438static int spobL_getAll( lua_State *L )
439{
440 Spob *p = spob_getAll();
441 int n = 1;
442 int all_spob = lua_toboolean( L, 1 );
443 lua_newtable( L );
444 for (int i = 0; i < array_size( p ); i++) {
445 if (!all_spob && !spob_hasSystem( &p[i] ))
446 continue;
447 lua_pushspob( L, spob_index( &p[i] ) );
448 lua_rawseti( L, -2, n++ );
449 }
450 return 1;
451}
452
460static int spobL_system( lua_State *L )
461{
462 LuaSystem sys;
463 const Spob *p = luaL_validspob( L, 1 );
464 const char *sysname = spob_getSystemName( p->name );
465 if (sysname == NULL)
466 return 0;
467 sys = system_index( system_get( sysname ) );
468 lua_pushsystem( L, sys );
469 return 1;
470}
471
482static int spobL_eq( lua_State *L )
483{
484 LuaSpob a, b;
485 a = luaL_checkspob( L, 1 );
486 b = luaL_checkspob( L, 2 );
487 lua_pushboolean( L, ( a == b ) );
488 return 1;
489}
490
507static int spobL_name( lua_State *L )
508{
509 const Spob *p = luaL_validspob( L, 1 );
510 lua_pushstring( L, spob_name( p ) );
511 return 1;
512}
513
526static int spobL_nameRaw( lua_State *L )
527{
528 Spob *p = luaL_validspob( L, 1 );
529 lua_pushstring( L, p->name );
530 return 1;
531}
532
540static int spobL_population( lua_State *L )
541{
542 Spob *p = luaL_validspob( L, 1 );
543 lua_pushnumber( L, p->population );
544 return 1;
545}
546
555static int spobL_radius( lua_State *L )
556{
557 Spob *p = luaL_validspob( L, 1 );
558 /* Ensure graphics measurements are available. */
559 if (p->radius < 0.)
560 spob_gfxLoad( p );
561 lua_pushnumber( L, p->radius );
562 return 1;
563}
564
573static int spobL_faction( lua_State *L )
574{
575 const Spob *p = luaL_validspob( L, 1 );
576 if (p->presence.faction < 0)
577 return 0;
578 lua_pushfaction( L, p->presence.faction );
579 return 1;
580}
581
589static int spobL_reputation( lua_State *L )
590{
591 const Spob *spb = luaL_validspob( L, 1 );
592 const StarSystem *sys = spob_getSystem( spb );
593 lua_pushnumber( L,
595 return 1;
596}
597
608static int spobL_colour( lua_State *L )
609{
610 const Spob *p = luaL_validspob( L, 1 );
611 const glColour *col = spob_getColour( p );
612 lua_pushcolour( L, *col );
613 return 1;
614}
615
627static int spobL_colourChar( lua_State *L )
628{
629 const Spob *p = luaL_validspob( L, 1 );
630 char str[2];
631 str[0] = spob_getColourChar( p );
632 str[1] = '\0';
633 lua_pushstring( L, str );
634 return 1;
635}
636
648static int spobL_class( lua_State *L )
649{
650 Spob *p = luaL_validspob( L, 1 );
651 lua_pushstring( L, p->class );
652 return 1;
653}
654
665static int spobL_classLong( lua_State *L )
666{
667 const Spob *p = luaL_validspob( L, 1 );
668 lua_pushstring( L, spob_getClassName( p->class ) );
669 return 1;
670}
671
692static int spobL_services( lua_State *L )
693{
694 const Spob *p = luaL_validspob( L, 1 );
695 /* Return result in table */
696 lua_newtable( L );
697 /* allows syntax like foo = spob.get("foo"); if foo["bar"] then ... end */
698 for (int i = 1; i < SPOB_SERVICES_MAX; i <<= 1) {
699 if (spob_hasService( p, i )) {
700 char lower[STRMAX_SHORT];
701 const char *name = spob_getServiceName( i );
702 size_t len = strlen( name ) + 1;
703 snprintf( lower, MIN( len, sizeof( lower ) ), "%c%s",
704 tolower( name[0] ), &name[1] );
705
706 /* GUI depends on this returning the service name. */
707 lua_pushstring( L, _( name ) );
708 lua_setfield( L, -2, lower );
709 }
710 }
711 return 1;
712}
713
725static int spobL_flags( lua_State *L )
726{
727 const Spob *p = luaL_validspob( L, 1 );
728 lua_newtable( L );
729 if (spob_isFlag( p, SPOB_NOMISNSPAWN )) {
730 lua_pushstring( L, "nomissionspawn" );
731 lua_pushboolean( L, 1 );
732 lua_settable( L, -3 );
733 }
734 return 1;
735}
736
745static int spobL_canland( lua_State *L )
746{
747 Spob *p = luaL_validspob( L, 1 );
748 spob_updateLand( p ); /* Update to make sure it's correct. */
749 lua_pushboolean( L, p->can_land );
750 return 1;
751}
752
753static int landAllowDeny( lua_State *L, int allowdeny )
754{
755 Spob *p = luaL_validspob( L, 1 );
756 int old = p->land_override;
757 p->land_override = allowdeny * !!lua_toboolean( L, 2 );
758 /* Set the message as necessary. */
759 free( p->land_msg );
760 p->land_msg = NULL;
761 if (!lua_isnoneornil( L, 3 ))
762 p->land_msg = strdup( luaL_checkstring( L, 3 ) );
763
764 /* If the value has changed, re-run the landing Lua next frame. */
765 if (p->land_override != old)
767 return 0;
768}
769
783static int spobL_landAllow( lua_State *L )
784{
785 return landAllowDeny( L, +1 );
786}
787
801static int spobL_landDeny( lua_State *L )
802{
803 return landAllowDeny( L, -1 );
804}
805
814static int spobL_getLandAllow( lua_State *L )
815{
816 const Spob *p = luaL_validspob( L, 1 );
817 lua_pushboolean( L, p->land_override > 0 );
818 return 1;
819}
820
829static int spobL_getLandDeny( lua_State *L )
830{
831 const Spob *p = luaL_validspob( L, 1 );
832 lua_pushboolean( L, p->land_override < 0 );
833 return 1;
834}
835
844static int spobL_position( lua_State *L )
845{
846 const Spob *p = luaL_validspob( L, 1 );
847 lua_pushvector( L, p->pos );
848 return 1;
849}
850
859static int spobL_gfxSpace( lua_State *L )
860{
861 glTexture *tex;
862 const Spob *p = luaL_validspob( L, 1 );
863 if (p->gfx_space == NULL) { /* Not loaded. */
864 /* If the spob has no texture, just return nothing. */
865 if (p->gfx_spaceName == NULL)
866 return 0;
867 tex = gl_newImage( p->gfx_spaceName, OPENGL_TEX_MIPMAPS );
868 } else
869 tex = gl_dupTexture( p->gfx_space );
870 lua_pushtex( L, tex );
871 return 1;
872}
873
882static int spobL_gfxExterior( lua_State *L )
883{
884 const Spob *p = luaL_validspob( L, 1 );
885
886 /* If no exterior image just return nothing instead of crashing. */
887 if (p->gfx_exterior == NULL)
888 return 0;
889
890 lua_pushtex( L, gl_newImage( p->gfx_exterior, 0 ) );
891 return 1;
892}
893
901static int spobL_gfxExteriorPath( lua_State *L )
902{
903 const Spob *p = luaL_validspob( L, 1 );
904 lua_pushstring( L, p->gfx_exteriorPath );
905 return 1;
906}
907
916static int spobL_gfxComm( lua_State *L )
917{
918 const Spob *p = luaL_validspob( L, 1 );
919 if (p->gfx_comm == NULL)
920 return spobL_gfxSpace( L );
921 lua_pushtex( L, gl_newImage( p->gfx_comm, 0 ) );
922 return 1;
923}
924
933static int spobL_shipsSold( lua_State *L )
934{
935 const Spob *p = luaL_validspob( L, 1 );
936 Ship **s = tech_getShip( p->tech );
937
938 /* Push results in a table. */
939 lua_newtable( L );
940 for (int i = 0; i < array_size( s ); i++) {
941 lua_pushship( L, s[i] ); /* value = LuaShip */
942 lua_rawseti( L, -2, i + 1 ); /* store the value in the table */
943 }
944
945 array_free( s );
946 return 1;
947}
948
957static int spobL_outfitsSold( lua_State *L )
958{
959 const Spob *p = luaL_validspob( L, 1 );
960 Outfit **o = tech_getOutfit( p->tech );
961
962 /* Push results in a table. */
963 lua_newtable( L );
964 for (int i = 0; i < array_size( o ); i++) {
965 lua_pushoutfit( L, o[i] ); /* value = LuaOutfit */
966 lua_rawseti( L, -2, i + 1 ); /* store the value in the table */
967 }
968
969 array_free( o );
970 return 1;
971}
972
981static int spobL_commoditiesSold( lua_State *L )
982{
983 /* Get result and tech. */
984 Spob *p = luaL_validspob( L, 1 );
985
986 /* Push results in a table. */
987 lua_newtable( L );
988 for (int i = 0; i < array_size( p->commodities ); i++) {
989 lua_pushcommodity( L, p->commodities[i] ); /* value = LuaCommodity */
990 lua_rawseti( L, -2, i + 1 ); /* store the value in the table */
991 }
992
993 return 1;
994}
995
1005static int spobL_isBlackMarket( lua_State *L )
1006{
1007 const Spob *p = luaL_validspob( L, 1 );
1008 lua_pushboolean( L, spob_hasService( p, SPOB_SERVICE_BLACKMARKET ) );
1009 return 1;
1010}
1011
1021static int spobL_isKnown( lua_State *L )
1022{
1023 const Spob *s = luaL_validspob( L, 1 );
1024 lua_pushboolean( L, spob_isKnown( s ) );
1025 return 1;
1026}
1027
1036static int spobL_setKnown( lua_State *L )
1037{
1038 Spob *p = luaL_validspob( L, 1 );
1039 int b = lua_toboolean( L, 2 );
1040
1041 int changed = ( b != (int)spob_isKnown( p ) );
1042
1043 if (b)
1044 spob_setKnown( p );
1045 else
1046 spob_rmFlag( p, SPOB_KNOWN );
1047
1048 if (changed) {
1049 ovr_refresh();
1050 /* Update outfits image array. */
1052 }
1053
1054 return 0;
1055}
1056
1064static int spobL_isHostile( lua_State *L )
1065{
1066 const Spob *p = luaL_validspob( L, 1 );
1067 lua_pushboolean( L, spob_isFlag( p, SPOB_HOSTILE ) );
1068 return 1;
1069}
1070
1078static int spobL_setHostile( lua_State *L )
1079{
1080 Spob *p = luaL_validspob( L, 1 );
1081 if (lua_toboolean( L, 2 ))
1082 spob_setFlag( p, SPOB_HOSTILE );
1083 else
1084 spob_rmFlag( p, SPOB_HOSTILE );
1085 return 0;
1086}
1087
1096static int spobL_recordCommodityPriceAtTime( lua_State *L )
1097{
1098 const Spob *p = luaL_validspob( L, 1 );
1099 ntime_t t = luaL_validtime( L, 2 );
1101 return 0;
1102}
1103
1116static int spobL_tags( lua_State *L )
1117{
1118 const Spob *p = luaL_validspob( L, 1 );
1119 return nlua_helperTags( L, 2, p->tags );
1120}
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
Definition array.h:170
#define array_create_size(basic_type, capacity)
Creates a new dynamic array of ‘basic_type’ with an initial capacity.
Definition array.h:102
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Definition array.h:179
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
Definition array.h:134
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
Definition array.h:93
Spob * land_spob
Definition land.c:87
void outfits_updateEquipmentOutfits(void)
Updates the outfitter and equipment outfit image arrays.
Header file with generic functions and naev-specifics.
#define MIN(x, y)
Definition naev.h:39
int nlua_helperTags(lua_State *L, int idx, char *const *tags)
Helper function to deal with tags.
Definition nlua.c:1118
glColour * lua_pushcolour(lua_State *L, glColour colour)
Pushes a colour on the stack.
Commodity ** lua_pushcommodity(lua_State *L, Commodity *commodity)
Pushes a commodity on the stack.
LuaFaction * lua_pushfaction(lua_State *L, LuaFaction faction)
Pushes a faction on the stack.
int lua_isfaction(lua_State *L, int ind)
Checks to see if ind is a faction.
LuaFaction lua_tofaction(lua_State *L, int ind)
Gets faction at index.
const Outfit ** lua_pushoutfit(lua_State *L, const Outfit *outfit)
Pushes a outfit on the stack.
const Ship ** lua_pushship(lua_State *L, const Ship *ship)
Pushes a ship on the stack.
Definition nlua_ship.c:193
static int spobL_getLandAllow(lua_State *L)
Gets the land allow override status for a spob.
Definition nlua_spob.c:814
static int spobL_reputation(lua_State *L)
Gets the local reputation of the faction at a spob.
Definition nlua_spob.c:589
static int spobL_commoditiesSold(lua_State *L)
Gets the commodities sold at a spob.
Definition nlua_spob.c:981
static int spobL_gfxExterior(lua_State *L)
Gets the texture of the spob in exterior.
Definition nlua_spob.c:882
static int spobL_colour(lua_State *L)
Gets a spob's colour based on its friendliness or hostility to the player.
Definition nlua_spob.c:608
LuaSpob lua_tospob(lua_State *L, int ind)
This module allows you to handle the spobs from Lua.
Definition nlua_spob.c:152
static int spobL_isHostile(lua_State *L)
Checks to see if a spob currently has the hostile flag set.
Definition nlua_spob.c:1064
static int spobL_landDeny(lua_State *L)
Disallows a player from landing on a spob. The override lasts until the player jumps or lands.
Definition nlua_spob.c:801
static int spobL_setHostile(lua_State *L)
Sets the hostile flag of a spob.
Definition nlua_spob.c:1078
static int spobL_getLandable(lua_State *L)
Gets a spob only if it's landable.
Definition nlua_spob.c:426
static int spobL_getAll(lua_State *L)
Gets all the spobs. Lua function parameter: boolean all_spob Whether or not to get all Spob,...
Definition nlua_spob.c:438
static int spobL_radius(lua_State *L)
Gets the spob's radius.
Definition nlua_spob.c:555
static int spobL_population(lua_State *L)
Gets the spob's population.
Definition nlua_spob.c:540
static int spobL_eq(lua_State *L)
You can use the '==' operator within Lua to compare spobs with this.
Definition nlua_spob.c:482
static int spobL_outfitsSold(lua_State *L)
Gets the outfits sold at a spob.
Definition nlua_spob.c:957
static int spobL_flags(lua_State *L)
Checks for spob flags.
Definition nlua_spob.c:725
LuaSpob luaL_checkspob(lua_State *L, int ind)
Gets spob at index raising an error if isn't a spob.
Definition nlua_spob.c:163
static int spobL_colourChar(lua_State *L)
Gets a spob's colour based on its friendliness or hostility to the player.
Definition nlua_spob.c:627
static const luaL_Reg spob_methods[]
Definition nlua_spob.c:75
static int spobL_getLandDeny(lua_State *L)
Gets the land deny override status for a spob.
Definition nlua_spob.c:829
static int spobL_faction(lua_State *L)
Gets the spob's faction.
Definition nlua_spob.c:573
static int spobL_gfxSpace(lua_State *L)
Gets the texture of the spob in space.
Definition nlua_spob.c:859
static int spobL_shipsSold(lua_State *L)
Gets the ships sold at a spob.
Definition nlua_spob.c:933
static int spobL_nameRaw(lua_State *L)
Gets the spob's raw (untranslated) name.
Definition nlua_spob.c:526
static int spobL_isBlackMarket(lua_State *L)
Checks to see if a spob is a black market.
Definition nlua_spob.c:1005
static int spobL_system(lua_State *L)
Gets the system corresponding to a spob. Lua function parameter: Spob p Spob to get system of....
Definition nlua_spob.c:460
static int spobL_classLong(lua_State *L)
Gets the spob's class in long human-readable format already translated.
Definition nlua_spob.c:665
static int spobL_recordCommodityPriceAtTime(lua_State *L)
Records commodity prices at a given time, adding to players stats.
Definition nlua_spob.c:1096
static int spobL_get(lua_State *L)
Gets a spob.
Definition nlua_spob.c:384
LuaSpob * lua_pushspob(lua_State *L, LuaSpob spob)
Pushes a spob on the stack.
Definition nlua_spob.c:203
static int spobL_getS(lua_State *L)
Gets a spob and its corresponding system.
Definition nlua_spob.c:410
static int spobL_canland(lua_State *L)
Gets whether or not the player can land on the spob (or bribe it).
Definition nlua_spob.c:745
static int spobL_class(lua_State *L)
Gets the spob's class.
Definition nlua_spob.c:648
static int spobL_gfxComm(lua_State *L)
Gets the texture of the spob for the communication window.
Definition nlua_spob.c:916
static int spobL_gfxExteriorPath(lua_State *L)
Gets the path of the spob in exterior.
Definition nlua_spob.c:901
static int spobL_services(lua_State *L)
Checks for spob services.
Definition nlua_spob.c:692
Spob * luaL_validspob(lua_State *L, int ind)
Gets a spob directly.
Definition nlua_spob.c:177
int nlua_loadSpob(nlua_env env)
Loads the spob library.
Definition nlua_spob.c:124
static int spobL_position(lua_State *L)
Gets the position of the spob in the system.
Definition nlua_spob.c:844
static int spobL_setKnown(lua_State *L)
Sets a spobs's known state.
Definition nlua_spob.c:1036
static int spobL_tags(lua_State *L)
Gets the spob tags.
Definition nlua_spob.c:1116
static int spobL_name(lua_State *L)
Gets the spob's translated name.
Definition nlua_spob.c:507
static int spobL_isKnown(lua_State *L)
Checks to see if a spob is known by the player.
Definition nlua_spob.c:1021
int lua_isspob(lua_State *L, int ind)
Checks to see if ind is a spob.
Definition nlua_spob.c:218
static int spobL_cur(lua_State *L)
Gets the current spob - MUST BE LANDED.
Definition nlua_spob.c:243
static int spobL_landAllow(lua_State *L)
Allows the player land on a spob no matter what. The override lasts until the player jumps or lands.
Definition nlua_spob.c:783
LuaSystem * lua_pushsystem(lua_State *L, LuaSystem sys)
Pushes a system on the stack.
glTexture ** lua_pushtex(lua_State *L, glTexture *texture)
Pushes a texture on the stack.
Definition nlua_tex.c:129
ntime_t luaL_validtime(lua_State *L, int ind)
Gets a time directly.
Definition nlua_time.c:112
vec2 * lua_pushvector(lua_State *L, vec2 vec)
Pushes a vector on the stack.
Definition nlua_vec2.c:145
void arrayShuffle(void **array)
Randomly sorts an array (array.h) of pointers in place with the Fisher-Yates shuffle.
Definition nmath.c:68
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
Definition opengl_tex.c:891
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
Definition opengl_tex.c:587
void spob_averageSeenPricesAtTime(const Spob *p, const ntime_t tupdate)
Adds cost of commodities on spob p to known statistics at time t.
Definition space.c:321
const glColour * spob_getColour(const Spob *p)
Gets the spob colour.
Definition space.c:2009
Spob * spob_getAll(void)
Gets an array (array.h) of all spobs.
Definition space.c:1166
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
Definition space.c:1107
void space_factionChange(void)
Mark when a faction changes.
Definition space.c:1460
const char * space_getRndSpob(int landable, unsigned int services, int(*filter)(Spob *p))
Gets the name of a random spob.
Definition space.c:666
int spob_index(const Spob *p)
Gets the ID of a spob.
Definition space.c:1158
double system_getReputationOrGlobal(const StarSystem *sys, int faction)
Gets the local reputation of the player in a system or returns the global standing.
Definition space.c:4518
int spob_hasSystem(const Spob *spb)
Get whether or not a spob has a system (i.e. is on the map).
Definition space.c:1060
char spob_getColourChar(const Spob *p)
Gets the spob colour char.
Definition space.c:1966
StarSystem * system_get(const char *sysname)
Get the system from its name.
Definition space.c:1007
void spob_setKnown(Spob *p)
Sets a spob's known status, if it's real.
Definition space.c:1174
void spob_updateLand(Spob *p)
Updates the land possibilities of a spob.
Definition space.c:2031
void spob_gfxLoad(Spob *spob)
Loads a spob's graphics (and radius).
Definition space.c:2206
Spob * spob_getIndex(int ind)
Gets spob by index.
Definition space.c:1140
const char * spob_getSystemName(const char *spobname)
Get the name of a system from a spobname.
Definition space.c:1082
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
Definition space.c:1834
const char * spob_getClassName(const char *class)
Gets the long class name for a spob.
Definition space.c:226
const char * spob_getServiceName(int service)
Gets the (English) name for a service code.
Definition space.c:169
StarSystem * spob_getSystem(const Spob *spob)
Gets the system a spob is in.
Definition space.c:1071
char ** space_getFactionSpob(const int *factions, int landable)
Gets the name of all the spobs that belong to factions.
Definition space.c:623
int system_index(const StarSystem *sys)
Gets the index of a star system.
Definition space.c:1049
A ship outfit, depends radically on the type.
Definition outfit.h:372
Represents a space ship.
Definition ship.h:97
int faction
Definition space.h:79
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Definition space.h:102
int can_land
Definition space.h:125
char * name
Definition space.h:105
SpobPresence presence
Definition space.h:121
Abstraction for rendering sprite sheets.
Definition opengl_tex.h:43
Ship ** tech_getShip(const tech_group_t *tech)
Gets all of the ships associated to a tech group.
Definition tech.c:887
Outfit ** tech_getOutfit(const tech_group_t *tech)
Gets all of the outfits associated to a tech group.
Definition tech.c:839