コード例 #1
0
ファイル: nlua_faction.c プロジェクト: Anatolis/naev
/**
 * @brief __eq (equality) metamethod for factions.
 *
 * You can use the '=' operator within Lua to compare factions with this.
 *
 * @usage if f == faction.get( "Dvaered" ) then
 *
 *    @luaparam f Faction comparing.
 *    @luaparam comp faction to compare against.
 *    @luareturn true if both factions are the same.
 * @luafunc __eq( f, comp )
 */
static int factionL_eq( lua_State *L )
{
   int a, b;
   a = luaL_validfaction(L,1);
   b = luaL_validfaction(L,2);
   lua_pushboolean(L, a == b);
   return 1;
}
コード例 #2
0
ファイル: nlua_faction.c プロジェクト: Anatolis/naev
/**
 * @brief Checks to see if f is an ally of a.
 *
 * @usage if f:areAllies( faction.get( "Pirate" ) ) then
 *
 *    @luaparam f Faction to check against.
 *    @luaparam a Faction to check if is an enemy.
 *    @luareturn true if they are enemies, false if they aren't.
 * @luafunc areAllies( f, a )
 */
static int factionL_areallies( lua_State *L )
{
   int f, ff;
   f  = luaL_validfaction(L,1);
   ff = luaL_validfaction(L,2);

   lua_pushboolean(L, areAllies( f, ff ));
   return 1;
}
コード例 #3
0
ファイル: nlua_faction.c プロジェクト: Anatolis/naev
/**
 * @brief Gets the faction's long name.
 *
 * @usage longname = f:longname()
 *    @luaparam f Faction to get long name of.
 *    @luareturn The long name of the faction.
 * @luafunc longname( f )
 */
static int factionL_longname( lua_State *L )
{
   int f;
   f = luaL_validfaction(L,1);
   lua_pushstring(L, faction_longname(f));
   return 1;
}
コード例 #4
0
ファイル: nlua_system.c プロジェクト: nenau/naev
/**
 * @brief Gets the presence in the system.
 *
 * Possible parameters are besides a faction:<br/>
 *  - "all": Gets the sum of all the presences.<br />
 *  - "friendly": Gets the sum of all the friendly presences.<br />
 *  - "hostile": Gets the sum of all the hostile presences.<br />
 *  - "neutral": Gets the sum of all the neutral presences.<br />
 *
 * @usage p = sys:presence( f ) -- Gets the presence of a faction f
 * @usage p = sys:presence( "all" ) -- Gets the sum of all the presences
 * @usage if sys:presence("friendly") > sys:presence("hostile") then -- Checks to see if the system is dominantly friendly
 *
 *    @luatparam System s System to get presence level of.
 *    @luatreturn number The presence level in sys (absolute value).
 * @luafunc presence( s )
 */
static int systemL_presence( lua_State *L )
{
   StarSystem *sys;
   int *fct;
   int nfct;
   double presence, v;
   int i, f, used;
   const char *cmd;

   /* Get parameters. */
   sys = luaL_validsystem(L, 1);

   /* Allow fall-through. */
   used = 0;

   /* Get the second parameter. */
   if (lua_isstring(L, 2)) {
      /* A string command has been given. */
      cmd  = lua_tostring(L, 2);
      nfct = 0;
      used = 1;

      /* Check the command string and get the appropriate faction group.*/
      if(strcmp(cmd, "all") == 0)
         fct = faction_getGroup(&nfct, 0);
      else if(strcmp(cmd, "friendly") == 0)
         fct = faction_getGroup(&nfct, 1);
      else if(strcmp(cmd, "hostile") == 0)
         fct = faction_getGroup(&nfct, 3);
      else if(strcmp(cmd, "neutral") == 0)
         fct = faction_getGroup(&nfct, 2);
      else /* Invalid command string. */
         used = 0;
   }

   if (!used) {
      /* A faction id was given. */
      f      = luaL_validfaction(L, 2);
      nfct   = 1;
      fct    = malloc(sizeof(int));
      fct[0] = f;
   }

   /* Add up the presence values. */
   presence = 0;
   for(i=0; i<nfct; i++) {
      /* Only count positive presences. */
      v = system_getPresence( sys, fct[i] );
      if (v > 0)
         presence += v;
   }

   /* Clean up after ourselves. */
   free(fct);

   /* Push it back to Lua. */
   lua_pushnumber(L, presence);
   return 1;
}
コード例 #5
0
ファイル: nlua_faction.c プロジェクト: Anatolis/naev
/**
 * @brief Modifies the player's standing with the faction.
 *
 * Does not affect other faction standings and is not processed by the faction
 *  Lua script, so it indicates exactly the amount to be changed.
 *
 * @usage f:modPlayerRaw( 10 )
 *
 *    @luaparam f Faction to modify player's standing with.
 *    @luaparam mod The modifier to modify faction by.
 * @luafunc modPlayerRaw( f, mod )
 */
static int factionL_modplayerraw( lua_State *L )
{
   int f;
   double n;

   f = luaL_validfaction(L,1);
   n = luaL_checknumber(L,2);
   faction_modPlayerRaw( f, n );

   return 0;
}
コード例 #6
0
ファイル: nlua_faction.c プロジェクト: Anatolis/naev
/**
 * @brief Modifies the player's standing with the faction.
 *
 * Does not affect other faction standings.
 *
 * @usage f:modPlayerSingle( 10 )
 *
 *    @luaparam f Faction to modify player's standing with.
 *    @luaparam mod The modifier to modify faction by.
 * @luafunc modPlayerSingle( f, mod )
 */
static int factionL_modplayersingle( lua_State *L )
{
   int f;
   double n;

   f = luaL_validfaction(L,1);
   n = luaL_checknumber(L,2);
   faction_modPlayerSingle( f, n, "script" );

   return 0;
}
コード例 #7
0
ファイル: nlua_faction.c プロジェクト: Kinniken/naev
/**
 * @brief Sets a faction's known state.
 *
 * @usage f:setKnown( false ) -- Makes faction unknown.
 *    @luatparam Faction f Faction to set known.
 *    @luatparam[opt=false] boolean b Whether or not to set as known.
 * @luafunc setKnown( f, b )
 */
static int factionL_setknown( lua_State *L )
{
   int b, fac;

   fac = luaL_validfaction(L, 1);
   b   = lua_toboolean(L, 2);

   faction_setKnown( fac, b );

   return 0;
}
コード例 #8
0
ファイル: nlua_faction.c プロジェクト: Kinniken/naev
/**
 * @brief Gets the faction colour.
 *
 *    @luatparam Faction f Faction to get colour from.
 *    @luatreturn Colour|nil The faction colour or nil if not applicable.
 * @luafunc colour( f )
 */
static int factionL_colour( lua_State *L )
{
   int lf;
   const glColour *col;
   lf = luaL_validfaction(L,1);
   col = faction_getColour(lf);
   if (col == NULL)
      return 0;
   lua_pushcolour( L, *col );
   return 1;
}
コード例 #9
0
ファイル: nlua_faction.c プロジェクト: Kinniken/naev
/**
 * @brief Gets the tiny faction logo which is 24x24 or smaller.
 *
 *    @luatparam Faction f Faction to get logo from.
 *    @luatreturn Tex The tiny faction logo or nil if not applicable.
 * @luafunc logoTiny( f )
 */
static int factionL_logoTiny( lua_State *L )
{
   int lf;
   glTexture *tex;
   lf = luaL_validfaction(L,1);
   tex = faction_logoTiny( lf );
   if (tex == NULL)
      return 0;
   lua_pushtex( L, gl_dupTexture( tex ) );
   return 1;
}
コード例 #10
0
ファイル: nlua_faction.c プロジェクト: Kinniken/naev
/**
 * @brief Sets the player's standing with the faction.
 *
 * @usage f:setPlayerStanding(70) -- Make player an ally
 *
 *    @luatparam Faction f Faction to set the player's standing for.
 *    @luatparam number value Value to set the player's standing to (from -100 to 100).
 * @luafunc setPlayerStanding( f, value )
 */
static int factionL_setplayerstanding( lua_State *L )
{
   int f;
   double n;

   f = luaL_validfaction( L, 1 );
   n = luaL_checknumber( L, 2 );
   faction_setPlayer( f, n );

   return 0;
}
コード例 #11
0
ファイル: nlua_faction.c プロジェクト: Anatolis/naev
/**
 * @brief Gets the faction colour.
 *
 *    @luaparam f Faction to get colour from.
 *    @luareturn The faction colour or nil if not applicable.
 * @luafunc colour( f )
 */
static int factionL_colour( lua_State *L )
{
   int lf;
   LuaColour lc;
   glColour *col;
   lf = luaL_validfaction(L,1);
   col = faction_getColour(lf);
   if (col == NULL)
      return 0;
   memcpy( &lc.col, col, sizeof(glColour) );
   lua_pushcolour( L, lc );
   return 1;
}
コード例 #12
0
ファイル: nlua_faction.c プロジェクト: Anatolis/naev
/**
 * @brief Gets the small faction logo which is 64x64 or smaller.
 *
 *    @luaparam f Faction to get logo from.
 *    @luareturn The small faction logo or nil if not applicable.
 * @luafunc logoSmall( f )
 */
static int factionL_logoSmall( lua_State *L )
{
   int lf;
   LuaTex lt;
   glTexture *tex;
   lf = luaL_validfaction(L,1);
   tex = faction_logoSmall( lf );
   if (tex == NULL)
      return 0;
   lt.tex = gl_dupTexture( tex );
   lua_pushtex( L, lt );
   return 1;
}
コード例 #13
0
ファイル: nlua_faction.c プロジェクト: Anatolis/naev
/**
 * @brief Gets the player's standing with the faction.
 *
 * @usage if f:playerStanding() > 70 then -- Player is an ally
 *
 *    @luaparam f Faction to get player's standing with.
 *    @luareturn The value of the standing and the human readable string.
 * @luafunc playerStanding( f )
 */
static int factionL_playerstanding( lua_State *L )
{
   int f;
   double n;

   f = luaL_validfaction(L,1);
   n = faction_getPlayer(f);

   lua_pushnumber(L, n);
   lua_pushstring(L, faction_getStanding(n));

   return 2;
}
コード例 #14
0
ファイル: nlua_faction.c プロジェクト: Kinniken/naev
/**
 * @brief Gets the allies of the faction.
 *
 * @usage for k,v in pairs(f:allies()) do -- Iterate over faction allies
 *
 *    @luatparam Faction f Faction to get allies of.
 *    @luatreturn {Faction,...} A table containing the allies of the faction.
 * @luafunc allies( f )
 */
static int factionL_allies( lua_State *L )
{
   int i, n, f;
   int *factions;

   f = luaL_validfaction(L,1);

   /* Push the enemies in a table. */
   lua_newtable(L);
   factions = faction_getAllies( f, &n );
   for (i=0; i<n; i++) {
      lua_pushnumber(L, i+1); /* key */
      lua_pushfaction(L, factions[i]); /* value */
      lua_rawset(L, -3);
   }

   return 1;
}
コード例 #15
0
ファイル: nlua_faction.c プロジェクト: Kinniken/naev
/**
 * @brief Checks to see if a faction is known by the player.
 *
 * @usage b = f:known()
 *
 *    @luatparam Faction f Faction to check if the player knows.
 *    @luatreturn boolean true if the player knows the faction.
 * @luafunc known( f )
 */
static int factionL_isknown( lua_State *L )
{
   int fac = luaL_validfaction(L, 1);
   lua_pushboolean(L, faction_isKnown(fac));
   return 1;
}