naev 0.10.4
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 <lauxlib.h>
15#include "nlua_spob.h"
16
17#include "array.h"
18#include "land.h"
19#include "land_outfits.h"
20#include "log.h"
21#include "map.h"
22#include "map_overlay.h"
23#include "nlua_colour.h"
24#include "nlua_commodity.h"
25#include "nlua_faction.h"
26#include "nlua_outfit.h"
27#include "nlua_ship.h"
28#include "nlua_system.h"
29#include "nlua_tex.h"
30#include "nlua_time.h"
31#include "nlua_vec2.h"
32#include "nluadef.h"
33#include "nmath.h"
34#include "nstring.h"
35#include "rng.h"
36
37/* Spob metatable methods */
38static int spobL_cur( lua_State *L );
39static int spobL_get( lua_State *L );
40static int spobL_getS( lua_State *L );
41static int spobL_getLandable( lua_State *L );
42static int spobL_getAll( lua_State *L );
43static int spobL_system( lua_State *L );
44static int spobL_eq( lua_State *L );
45static int spobL_name( lua_State *L );
46static int spobL_nameRaw( lua_State *L );
47static int spobL_population( lua_State *L );
48static int spobL_radius( lua_State *L );
49static int spobL_faction( lua_State *L );
50static int spobL_colour( lua_State *L );
51static int spobL_class( lua_State *L );
52static int spobL_classLong( lua_State *L );
53static int spobL_position( lua_State *L );
54static int spobL_services( lua_State *L );
55static int spobL_flags( lua_State *L );
56static int spobL_canland( lua_State *L );
57static int spobL_landOverride( lua_State *L );
58static int spobL_getLandOverride( lua_State *L );
59static int spobL_gfxSpace( lua_State *L );
60static int spobL_gfxExterior( lua_State *L );
61static int spobL_shipsSold( lua_State *L );
62static int spobL_outfitsSold( lua_State *L );
63static int spobL_commoditiesSold( lua_State *L );
64static int spobL_isBlackMarket( lua_State *L );
65static int spobL_isKnown( lua_State *L );
66static int spobL_setKnown( lua_State *L );
67static int spobL_recordCommodityPriceAtTime( lua_State *L );
68static int spobL_tags( lua_State *L );
69static const luaL_Reg spob_methods[] = {
70 { "cur", spobL_cur },
71 { "get", spobL_get },
72 { "getS", spobL_getS },
73 { "getLandable", spobL_getLandable },
74 { "getAll", spobL_getAll },
75 { "system", spobL_system },
76 { "__eq", spobL_eq },
77 { "__tostring", spobL_name },
78 { "name", spobL_name },
79 { "nameRaw", spobL_nameRaw },
80 { "population", spobL_population },
81 { "radius", spobL_radius },
82 { "faction", spobL_faction },
83 { "colour", spobL_colour },
84 { "class", spobL_class },
85 { "classLong", spobL_classLong },
86 { "pos", spobL_position },
87 { "services", spobL_services },
88 { "flags", spobL_flags },
89 { "canLand", spobL_canland },
90 { "landOverride", spobL_landOverride },
91 { "getLandOverride", spobL_getLandOverride },
92 { "gfxSpace", spobL_gfxSpace },
93 { "gfxExterior", spobL_gfxExterior },
94 { "shipsSold", spobL_shipsSold },
95 { "outfitsSold", spobL_outfitsSold },
96 { "commoditiesSold", spobL_commoditiesSold },
97 { "blackmarket", spobL_isBlackMarket },
98 { "known", spobL_isKnown },
99 { "setKnown", spobL_setKnown },
100 { "recordCommodityPriceAtTime", spobL_recordCommodityPriceAtTime },
101 { "tags", spobL_tags },
102 {0,0}
103};
111int nlua_loadSpob( nlua_env env )
112{
113 nlua_register(env, SPOB_METATABLE, spob_methods, 1);
114 return 0; /* No error */
115}
116
139LuaSpob lua_tospob( lua_State *L, int ind )
140{
141 return *((LuaSpob*) lua_touserdata(L,ind));
142}
150LuaSpob luaL_checkspob( lua_State *L, int ind )
151{
152 if (lua_isspob(L,ind))
153 return lua_tospob(L,ind);
154 luaL_typerror(L, ind, SPOB_METATABLE);
155 return 0;
156}
164Spob* luaL_validspob( lua_State *L, int ind )
165{
166 LuaSpob lp;
167 Spob *p;
168
169 if (lua_isspob(L, ind)) {
170 lp = luaL_checkspob(L, ind);
171 p = spob_getIndex(lp);
172 }
173 else if (lua_isstring(L, ind))
174 p = spob_get( lua_tostring(L, ind) );
175 else {
176 luaL_typerror(L, ind, SPOB_METATABLE);
177 return NULL;
178 }
179
180 if (p == NULL)
181 NLUA_ERROR(L, _("Spob is invalid"));
182
183 return p;
184}
192LuaSpob* lua_pushspob( lua_State *L, LuaSpob spob )
193{
194 LuaSpob *p = (LuaSpob*) lua_newuserdata(L, sizeof(LuaSpob));
195 *p = spob;
196 luaL_getmetatable(L, SPOB_METATABLE);
197 lua_setmetatable(L, -2);
198 return p;
199}
207int lua_isspob( lua_State *L, int ind )
208{
209 int ret;
210
211 if (lua_getmetatable(L,ind)==0)
212 return 0;
213 lua_getfield(L, LUA_REGISTRYINDEX, SPOB_METATABLE);
214
215 ret = 0;
216 if (lua_rawequal(L, -1, -2)) /* does it have the correct mt? */
217 ret = 1;
218
219 lua_pop(L, 2); /* remove both metatables */
220 return ret;
221}
222
232static int spobL_cur( lua_State *L )
233{
234 LuaSystem sys;
235 if (land_spob == NULL) {
236 NLUA_ERROR(L,_("Attempting to get landed spob when player not landed."));
237 return 0; /* Not landed. */
238 }
241 lua_pushsystem(L,sys);
242 return 2;
243}
244
245static int spobL_getBackend( lua_State *L, int system, int landable )
246{
247 int *factions;
248 char **spobs;
249 const char *rndspob;
250 Spob *pnt;
251
252 rndspob = NULL;
253 spobs = NULL;
254
255 /* If boolean return random. */
256 if (lua_isboolean(L,1)) {
257 pnt = spob_get( space_getRndSpob(landable, 0, NULL) );
258 rndspob = pnt->name;
259 }
260
261 /* Get a spob by faction */
262 else if (lua_isfaction(L,1)) {
263 factions = array_create( int );
264 array_push_back( &factions, lua_tofaction(L,1) );
265 spobs = space_getFactionSpob( factions, landable );
266 array_free( factions );
267 }
268
269 /* Get a spob by name */
270 else if (lua_isstring(L,1)) {
271 rndspob = lua_tostring(L,1);
272
273 if (landable) {
274 pnt = spob_get( rndspob );
275 if (pnt == NULL) {
276 NLUA_ERROR(L, _("Spob '%s' not found in stack"), rndspob);
277 return 0;
278 }
279
280 /* Check if can land. */
281 spob_updateLand( pnt );
282 if (!pnt->can_land)
283 return 0;
284 }
285 }
286
287 /* Get a spob from faction list */
288 else if (lua_istable(L,1)) {
289 /* Get table length and preallocate. */
290 factions = array_create_size( int, lua_objlen(L,1) );
291 /* Load up the table. */
292 lua_pushnil(L);
293 while (lua_next(L, -2) != 0) {
294 if (lua_isfaction(L, -1))
295 array_push_back( &factions, lua_tofaction(L, -1) );
296 lua_pop(L,1);
297 }
298
299 /* get the spobs */
300 spobs = space_getFactionSpob( factions, landable );
301 array_free(factions);
302 }
303
304 /* Just get a spob. */
305 else if (lua_isspob(L,1)) {
306 pnt = luaL_validspob( L, 1 );
307 if (landable) {
308 /* Check if can land. */
309 spob_updateLand( pnt );
310 if (!pnt->can_land)
311 return 0;
312 }
313 rndspob = pnt->name;
314 }
315
316 else
317 NLUA_INVALID_PARAMETER(L); /* Bad Parameter */
318
319 /* Pick random spob */
320 if (rndspob == NULL) {
321 arrayShuffle( (void**)spobs );
322
323 for (int i=0; i<array_size(spobs); i++) {
324 if (landable) {
325 /* Check landing. */
326 pnt = spob_get( spobs[i] );
327 if (pnt == NULL)
328 continue;
329
330 spob_updateLand( pnt );
331 if (!pnt->can_land)
332 continue;
333 }
334
335 rndspob = spobs[i];
336 break;
337 }
338 }
339 array_free(spobs);
340
341 /* No suitable spob found */
342 if (rndspob == NULL && array_size( spobs ) == 0)
343 return 0;
344
345 /* Push the spob */
346 pnt = spob_get(rndspob); /* The real spob */
347 if (pnt == NULL) {
348 NLUA_ERROR(L, _("Spob '%s' not found in stack"), rndspob);
349 return 0;
350 }
351 lua_pushspob(L,spob_index( pnt ));
352 if (system) {
353 LuaSystem sys;
354 const char *sysname = spob_getSystem( 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
382static int spobL_get( lua_State *L )
383{
384 return spobL_getBackend( L, 0, 0 );
385}
386
406static int spobL_getS( lua_State *L )
407{
408 return spobL_getBackend( L, 1, 0 );
409}
410
422static int spobL_getLandable( lua_State *L )
423{
424 return spobL_getBackend( L, 1, 1 );
425}
426
433static int spobL_getAll( lua_State *L )
434{
435 Spob *p = spob_getAll();
436 int n = 1;
437 int all_spob = lua_toboolean(L,1);
438 lua_newtable(L);
439 for (int i=0; i<array_size(p); i++) {
440 if (!all_spob && !spob_hasSystem(&p[i]))
441 continue;
442 lua_pushspob( L, spob_index( &p[i] ) );
443 lua_rawseti( L, -2, n++ );
444 }
445 return 1;
446}
447
454static int spobL_system( lua_State *L )
455{
456 LuaSystem sys;
457 Spob *p = luaL_validspob(L,1);
458 const char *sysname = spob_getSystem( p->name );
459 if (sysname == NULL)
460 return 0;
461 sys = system_index( system_get( sysname ) );
462 lua_pushsystem( L, sys );
463 return 1;
464}
465
476static int spobL_eq( lua_State *L )
477{
478 LuaSpob a, b;
479 a = luaL_checkspob(L,1);
480 b = luaL_checkspob(L,2);
481 lua_pushboolean(L,(a == b));
482 return 1;
483}
484
500static int spobL_name( lua_State *L )
501{
502 Spob *p = luaL_validspob(L,1);
503 lua_pushstring(L, spob_name(p));
504 return 1;
505}
506
519static int spobL_nameRaw( lua_State *L )
520{
521 Spob *p = luaL_validspob(L,1);
522 lua_pushstring(L, p->name);
523 return 1;
524}
525
533static int spobL_population( lua_State *L )
534{
535 Spob *p = luaL_validspob(L,1);
536 lua_pushnumber(L,p->population);
537 return 1;
538}
539
548static int spobL_radius( lua_State *L )
549{
550 Spob *p = luaL_validspob(L,1);
551 /* Ensure graphics measurements are available. */
552 if (p->radius < 0.)
553 spob_gfxLoad(p);
554 lua_pushnumber(L,p->radius);
555 return 1;
556}
557
566static int spobL_faction( lua_State *L )
567{
568 Spob *p = luaL_validspob(L,1);
569 if (p->presence.faction < 0)
570 return 0;
571 lua_pushfaction(L, p->presence.faction);
572 return 1;
573}
574
584static int spobL_colour( lua_State *L )
585{
586 Spob *p = luaL_validspob(L,1);
587 const glColour *col = spob_getColour( p );
588 lua_pushcolour( L, *col );
589 return 1;
590}
591
603static int spobL_class(lua_State *L )
604{
605 Spob *p = luaL_validspob(L,1);
606 lua_pushstring(L,p->class);
607 return 1;
608}
609
618static int spobL_classLong(lua_State *L )
619{
620 Spob *p = luaL_validspob(L,1);
621 lua_pushstring(L, spob_getClassName(p->class));
622 return 1;
623}
624
645static int spobL_services( lua_State *L )
646{
647 Spob *p = luaL_validspob(L,1);
648 /* Return result in table */
649 lua_newtable(L);
650 /* allows syntax like foo = spob.get("foo"); if foo["bar"] then ... end */
651 for (int i=1; i<SPOB_SERVICES_MAX; i<<=1) {
652 if (spob_hasService(p, i)) {
653 char lower[STRMAX_SHORT];
654 const char *name = spob_getServiceName(i);
655 size_t len = strlen(name) + 1;
656 snprintf( lower, MIN(len,sizeof(lower)), "%c%s", tolower(name[0]), &name[1] );
657
658 /* GUI depends on this returning the service name. */
659 lua_pushstring(L, _(name));
660 lua_setfield(L, -2, lower );
661 }
662 }
663 return 1;
664}
665
677static int spobL_flags( lua_State *L )
678{
679 Spob *p = luaL_validspob(L,1);
680 lua_newtable(L);
681 if (spob_isFlag( p, SPOB_NOMISNSPAWN )) {
682 lua_pushstring(L, "nomissionspawn");
683 lua_pushboolean(L, 1);
684 lua_settable(L,-3);
685 }
686 return 1;
687}
688
697static int spobL_canland( lua_State *L )
698{
699 Spob *p = luaL_validspob(L,1);
700 spob_updateLand( p );
701 lua_pushboolean( L, p->can_land );
702 return 1;
703}
704
713static int spobL_landOverride( lua_State *L )
714{
715 Spob *p = luaL_validspob(L,1);
716 int old = p->land_override;
717
718 p->land_override = !!lua_toboolean(L,2);
719
720 /* If the value has changed, re-run the landing Lua next frame. */
721 if (p->land_override != old)
723
724 return 0;
725}
726
735static int spobL_getLandOverride( lua_State *L )
736{
737 Spob *p = luaL_validspob(L,1);
738 lua_pushboolean(L, p->land_override);
739 return 1;
740}
741
750static int spobL_position( lua_State *L )
751{
752 Spob *p = luaL_validspob(L,1);
753 lua_pushvector(L, p->pos);
754 return 1;
755}
756
765static int spobL_gfxSpace( lua_State *L )
766{
767 glTexture *tex;
768 Spob *p = luaL_validspob(L,1);
769 if (p->gfx_space == NULL) { /* Not loaded. */
770 /* If the spob has no texture, just return nothing. */
771 if (p->gfx_spaceName == NULL)
772 return 0;
773 tex = gl_newImage( p->gfx_spaceName, OPENGL_TEX_MIPMAPS );
774 }
775 else
776 tex = gl_dupTexture( p->gfx_space );
777 lua_pushtex( L, tex );
778 return 1;
779}
780
789static int spobL_gfxExterior( lua_State *L )
790{
791 Spob *p = luaL_validspob(L,1);
792
793 /* If no exterior image just return nothing instead of crashing. */
794 if (p->gfx_exterior==NULL)
795 return 0;
796
797 lua_pushtex( L, gl_newImage( p->gfx_exterior, 0 ) );
798 return 1;
799}
800
808static int spobL_shipsSold( lua_State *L )
809{
810 Spob *p = luaL_validspob(L,1);
811 Ship **s = tech_getShip( p->tech );
812
813 /* Push results in a table. */
814 lua_newtable(L);
815 for (int i=0; i<array_size(s); i++) {
816 lua_pushship(L,s[i]); /* value = LuaShip */
817 lua_rawseti(L,-2,i+1); /* store the value in the table */
818 }
819
820 array_free(s);
821 return 1;
822}
823
831static int spobL_outfitsSold( lua_State *L )
832{
833 Spob *p = luaL_validspob(L,1);
834 Outfit **o = tech_getOutfit( p->tech );
835
836 /* Push results in a table. */
837 lua_newtable(L);
838 for (int i=0; i<array_size(o); i++) {
839 lua_pushoutfit(L,o[i]); /* value = LuaOutfit */
840 lua_rawseti(L,-2,i+1); /* store the value in the table */
841 }
842
843 array_free(o);
844 return 1;
845}
846
854static int spobL_commoditiesSold( lua_State *L )
855{
856 /* Get result and tech. */
857 Spob *p = luaL_validspob(L,1);
858
859 /* Push results in a table. */
860 lua_newtable(L);
861 for (int i=0; i<array_size(p->commodities); i++) {
862 lua_pushcommodity(L,p->commodities[i]); /* value = LuaCommodity */
863 lua_rawseti(L,-2,i+1); /* store the value in the table */
864 }
865
866 return 1;
867}
868
878static int spobL_isBlackMarket( lua_State *L )
879{
880 Spob *p = luaL_validspob(L,1);
881 lua_pushboolean(L, spob_hasService(p, SPOB_SERVICE_BLACKMARKET));
882 return 1;
883}
884
894static int spobL_isKnown( lua_State *L )
895{
896 Spob *s = luaL_validspob(L,1);
897 lua_pushboolean(L, spob_isKnown(s));
898 return 1;
899}
900
909static int spobL_setKnown( lua_State *L )
910{
911 Spob *p = luaL_validspob(L,1);
912 int b = lua_toboolean(L, 2);
913
914 int changed = (b != (int)spob_isKnown(p));
915
916 if (b)
917 spob_setKnown( p );
918 else
919 spob_rmFlag( p, SPOB_KNOWN );
920
921 if (changed) {
922 ovr_refresh();
923 /* Update outfits image array. */
925 }
926
927 return 0;
928}
929
938static int spobL_recordCommodityPriceAtTime( lua_State *L )
939{
940 Spob *p = luaL_validspob(L,1);
941 ntime_t t = luaL_validtime(L, 2);
943 return 0;
944}
945
955static int spobL_tags( lua_State *L )
956{
957 Spob *p = luaL_validspob(L,1);
958 lua_newtable(L);
959 for (int i=0; i<array_size(p->tags); i++) {
960 lua_pushstring(L,p->tags[i]);
961 lua_pushboolean(L,1);
962 lua_rawset(L,-3);
963 }
964 return 1;
965}
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
Definition: array.h:158
#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:168
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
Definition: array.h:129
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
Definition: array.h:93
Spob * land_spob
Definition: land.c:82
void outfits_updateEquipmentOutfits(void)
Updates the outfitter and equipment outfit image arrays.
Definition: land_outfits.c:523
Header file with generic functions and naev-specifics.
#define MIN(x, y)
Definition: naev.h:40
glColour * lua_pushcolour(lua_State *L, glColour colour)
Pushes a colour on the stack.
Definition: nlua_colour.c:103
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.
Definition: nlua_faction.c:192
int lua_isfaction(lua_State *L, int ind)
Checks to see if ind is a faction.
Definition: nlua_faction.c:208
LuaFaction lua_tofaction(lua_State *L, int ind)
Gets faction at index.
Definition: nlua_faction.c:155
const Outfit ** lua_pushoutfit(lua_State *L, const Outfit *outfit)
Pushes a outfit on the stack.
Definition: nlua_outfit.c:160
const Ship ** lua_pushship(lua_State *L, const Ship *ship)
Pushes a ship on the stack.
Definition: nlua_ship.c:164
static int spobL_getLandOverride(lua_State *L)
Gets the land override status for a spob.
Definition: nlua_spob.c:735
static int spobL_commoditiesSold(lua_State *L)
Gets the commodities sold at a spob.
Definition: nlua_spob.c:854
static int spobL_gfxExterior(lua_State *L)
Gets the texture of the spob in exterior.
Definition: nlua_spob.c:789
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:584
LuaSpob lua_tospob(lua_State *L, int ind)
This module allows you to handle the spobs from Lua.
Definition: nlua_spob.c:139
static int spobL_getLandable(lua_State *L)
Gets a spob only if it's landable.
Definition: nlua_spob.c:422
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:433
static int spobL_radius(lua_State *L)
Gets the spob's radius.
Definition: nlua_spob.c:548
static int spobL_population(lua_State *L)
Gets the spob's population.
Definition: nlua_spob.c:533
static int spobL_eq(lua_State *L)
You can use the '==' operator within Lua to compare spobs with this.
Definition: nlua_spob.c:476
static int spobL_outfitsSold(lua_State *L)
Gets the outfits sold at a spob.
Definition: nlua_spob.c:831
static int spobL_flags(lua_State *L)
Checks for spob flags.
Definition: nlua_spob.c:677
LuaSpob luaL_checkspob(lua_State *L, int ind)
Gets spob at index raising an error if isn't a spob.
Definition: nlua_spob.c:150
static int spobL_landOverride(lua_State *L)
Lets player land on a spob no matter what. The override lasts until the player jumps or lands.
Definition: nlua_spob.c:713
static const luaL_Reg spob_methods[]
Definition: nlua_spob.c:69
static int spobL_faction(lua_State *L)
Gets the spob's faction.
Definition: nlua_spob.c:566
static int spobL_gfxSpace(lua_State *L)
Gets the texture of the spob in space.
Definition: nlua_spob.c:765
static int spobL_shipsSold(lua_State *L)
Gets the ships sold at a spob.
Definition: nlua_spob.c:808
static int spobL_nameRaw(lua_State *L)
Gets the spob's raw (untranslated) name.
Definition: nlua_spob.c:519
static int spobL_isBlackMarket(lua_State *L)
Checks to see if a spob is a black market.
Definition: nlua_spob.c:878
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:454
static int spobL_classLong(lua_State *L)
Gets the spob's class in long human-readable format already translated.
Definition: nlua_spob.c:618
static int spobL_recordCommodityPriceAtTime(lua_State *L)
Records commodity prices at a given time, adding to players stats.
Definition: nlua_spob.c:938
static int spobL_get(lua_State *L)
Gets a spob.
Definition: nlua_spob.c:382
LuaSpob * lua_pushspob(lua_State *L, LuaSpob spob)
Pushes a spob on the stack.
Definition: nlua_spob.c:192
static int spobL_getS(lua_State *L)
Gets a spob and its corresponding system.
Definition: nlua_spob.c:406
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:697
static int spobL_class(lua_State *L)
Gets the spob's class.
Definition: nlua_spob.c:603
static int spobL_services(lua_State *L)
Checks for spob services.
Definition: nlua_spob.c:645
Spob * luaL_validspob(lua_State *L, int ind)
Gets a spob directly.
Definition: nlua_spob.c:164
int nlua_loadSpob(nlua_env env)
Loads the spob library.
Definition: nlua_spob.c:111
static int spobL_position(lua_State *L)
Gets the position of the spob in the system.
Definition: nlua_spob.c:750
static int spobL_setKnown(lua_State *L)
Sets a spobs's known state.
Definition: nlua_spob.c:909
static int spobL_tags(lua_State *L)
Gets the spob tags.
Definition: nlua_spob.c:955
static int spobL_name(lua_State *L)
Gets the spob's translated name.
Definition: nlua_spob.c:500
static int spobL_isKnown(lua_State *L)
Checks to see if a spob is known by the player.
Definition: nlua_spob.c:894
int lua_isspob(lua_State *L, int ind)
Checks to see if ind is a spob.
Definition: nlua_spob.c:207
static int spobL_cur(lua_State *L)
Gets the current spob - MUST BE LANDED.
Definition: nlua_spob.c:232
LuaSystem * lua_pushsystem(lua_State *L, LuaSystem sys)
Pushes a system on the stack.
Definition: nlua_system.c:185
glTexture ** lua_pushtex(lua_State *L, glTexture *texture)
Pushes a texture on the stack.
Definition: nlua_tex.c:130
ntime_t luaL_validtime(lua_State *L, int ind)
Gets a time directly.
Definition: nlua_time.c:115
vec2 * lua_pushvector(lua_State *L, vec2 vec)
Pushes a vector on the stack.
Definition: nlua_vec2.c:139
void arrayShuffle(void **array)
Randomly sorts an array (array.h) of pointers in place with the Fisher-Yates shuffle.
Definition: nmath.c:70
glTexture * gl_dupTexture(const glTexture *texture)
Duplicates a texture.
Definition: opengl_tex.c:809
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
Definition: opengl_tex.c:570
static const double a[]
Definition: rng.c:247
static const double b[]
Definition: rng.c:256
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:299
const glColour * spob_getColour(const Spob *p)
Gets the spob colour.
Definition: space.c:1875
Spob * spob_getAll(void)
Gets an array (array.h) of all spobs.
Definition: space.c:1063
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
Definition: space.c:1006
void space_factionChange(void)
Mark when a faction changes.
Definition: space.c:1344
const char * space_getRndSpob(int landable, unsigned int services, int(*filter)(Spob *p))
Gets the name of a random spob.
Definition: space.c:601
int spob_index(const Spob *p)
Gets the ID of a spob.
Definition: space.c:1055
int spob_hasSystem(const Spob *spb)
Get whether or not a spob has a system (i.e. is on the map).
Definition: space.c:966
StarSystem * system_get(const char *sysname)
Get the system from its name.
Definition: space.c:914
char * spob_getSystem(const char *spobname)
Get the name of a system from a spobname.
Definition: space.c:980
void spob_setKnown(Spob *p)
Sets a spob's known status, if it's real.
Definition: space.c:1071
void spob_updateLand(Spob *p)
Updates the land possibilities of a spob.
Definition: space.c:1896
void spob_gfxLoad(Spob *spob)
Loads a spob's graphics (and radius).
Definition: space.c:2019
Spob * spob_getIndex(int ind)
Gets spob by index.
Definition: space.c:1038
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
Definition: space.c:1705
const char * spob_getClassName(const char *class)
Gets the long class name for a spob.
Definition: space.c:213
char ** space_getFactionSpob(int *factions, int landable)
Gets the name of all the spobs that belong to factions.
Definition: space.c:558
const char * spob_getServiceName(int service)
Gets the (English) name for a service code.
Definition: space.c:165
int system_index(const StarSystem *sys)
Gets the index of a star system.
Definition: space.c:955
A ship outfit, depends radically on the type.
Definition: outfit.h:304
Represents a space ship.
Definition: ship.h:94
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Definition: space.h:88
int can_land
Definition: space.h:106
char * name
Definition: space.h:90
Abstraction for rendering sprite sheets.
Definition: opengl_tex.h:34
Ship ** tech_getShip(const tech_group_t *tech)
Gets all of the ships associated to a tech group.
Definition: tech.c:773
Outfit ** tech_getOutfit(const tech_group_t *tech)
Gets all of the outfits associated to a tech group.
Definition: tech.c:725