/** * @brief Adds an outfit to the player's outfit list. * * @usage player.addOutfit( "Laser Cannon" ) -- Gives the player a laser cannon * @usage player.addOutfit( "Plasma Blaster", 2 ) -- Gives the player two plasma blasters * * @luaparam name Name of the outfit to give. * @luaparam q Optional parameter that sets the quantity to give (default 1). * @luafunc addOutfit( name, q ) */ static int playerL_addOutfit( lua_State *L ) { const char *str; Outfit *o; int q; /* Defaults. */ q = 1; /* Handle parameters. */ str = luaL_checkstring(L, 1); if (lua_gettop(L) > 1) q = luaL_checkint(L, 2); /* Get outfit. */ o = outfit_get( str ); if (o==NULL) { NLUA_ERROR(L, "Outfit '%s' not found.", str); return 0; } /* Add the outfits. */ player_addOutfit( o, q ); /* Update equipment list. */ outfits_updateEquipmentOutfits(); return 0; }
/** * @brief Sets a jump's known state. * * @usage j:setKnown( false ) -- Makes jump unknown. * @luaparam j Jump to set known. * @luaparam b Whether or not to set as known (defaults to true). * @luafunc setKnown( j, b ) */ static int jumpL_setKnown( lua_State *L ) { int b, offset, changed; JumpPoint *jp; jp = luaL_validjumpSystem(L, 1, &offset, NULL); /* True if boolean isn't supplied. */ if (lua_gettop(L) > offset) b = lua_toboolean(L, 1 + offset); else b = 1; changed = (b != (int)jp_isKnown(jp)); if (b) jp_setFlag( jp, JP_KNOWN ); else jp_rmFlag( jp, JP_KNOWN ); /* Update outfits image array. */ if (changed) outfits_updateEquipmentOutfits(); return 0; }
/** * @brief Removes an outfit from the player's outfit list. * * "all" will remove all outfits. * * @usage player.rmOutfit( "Plasma Blaster", 2 ) -- Removes two plasma blasters from the player * * @luaparam name Name of the outfit to give. * @luaparam q Optional parameter that sets the quantity to give (default 1). * @luafunc rmOutfit( name, q ) */ static int playerL_rmOutfit( lua_State *L ) { const char *str; char **outfits; Outfit *o; int i, q, noutfits; /* Defaults. */ q = 1; /* Handle parameters. */ str = luaL_checkstring(L, 1); if (lua_gettop(L) > 1) q = luaL_checkint(L, 2); if (strcmp(str,"all")==0) { noutfits = player_numOutfits(); /* Removing nothing is a bad idea. */ if (noutfits == 0) return 0; outfits = malloc( sizeof(char*) * noutfits ); player_getOutfits(outfits, NULL); for (i=0; i<noutfits; i++) { o = outfit_get(outfits[i]); q = player_outfitOwned(o); player_rmOutfit(o, q); /* Free memory. */ free( outfits[i] ); } /* Clean up. */ free(outfits); } else { /* Get outfit. */ o = outfit_get( str ); if (o==NULL) { NLUA_ERROR(L, "Outfit '%s' not found.", str); return 0; } /* Remove the outfits. */ player_rmOutfit( o, q ); } /* Update equipment list. */ outfits_updateEquipmentOutfits(); return 0; }
/** * @brief Sets a system's known state. * * @usage s:setKnown( false ) -- Makes system unknown. * @luatparam System s System to set known. * @luatparam[opt=false] boolean b Whether or not to set as known. * @luatparam[opt=false] boolean r Whether or not to iterate over the system's assets and jump points. * @luafunc setKnown( s, b, r ) */ static int systemL_setknown( lua_State *L ) { int b, r, i; StarSystem *sys; NLUA_CHECKRW(L); r = 0; sys = luaL_validsystem(L, 1); b = lua_toboolean(L, 2); if (lua_gettop(L) > 2) r = lua_toboolean(L, 3); if (b) sys_setFlag( sys, SYSTEM_KNOWN ); else sys_rmFlag( sys, SYSTEM_KNOWN ); if (r) { if (b) { for (i=0; i < sys->nplanets; i++) planet_setKnown( sys->planets[i] ); for (i=0; i < sys->njumps; i++) jp_setFlag( &sys->jumps[i], JP_KNOWN ); } else { for (i=0; i < sys->nplanets; i++) planet_rmFlag( sys->planets[i], PLANET_KNOWN ); for (i=0; i < sys->njumps; i++) jp_rmFlag( &sys->jumps[i], JP_KNOWN ); } } /* Update outfits image array. */ outfits_updateEquipmentOutfits(); return 0; }
/** * @brief Sets a planets's known state. * * @usage p:setKnown( false ) -- Makes planet unknown. * @luatparam Planet p Planet to set known. * @luatparam[opt=false] boolean b Whether or not to set as known. * @luafunc setKnown( p, b ) */ static int planetL_setKnown( lua_State *L ) { int b, changed; Planet *p; NLUA_CHECKRW(L); p = luaL_validplanet(L,1); b = lua_toboolean(L, 2); changed = (b != (int)planet_isKnown(p)); if (b) planet_setKnown( p ); else planet_rmFlag( p, PLANET_KNOWN ); /* Update outfits image array. */ if (changed) outfits_updateEquipmentOutfits(); return 0; }