Example #1
0
/**
 * @brief Modifies the player's standing without affecting others.
 *
 * Does not affect allies nor enemies and does not run through the Lua script.
 *
 *    @param f Faction whose standing to modify.
 *    @param mod Amount to modify standing by.
 *
 * @sa faction_modPlayer
 */
void faction_modPlayerRaw( int f, double mod )
{
   Faction *faction;
   HookParam hparam[3];

   if (!faction_isFaction(f)) {
      WARN("%d is an invalid faction", f);
      return;
   }

   faction = &faction_stack[f];
   faction->player += mod;
   /* Run hook if necessary. */
   hparam[0].type    = HOOK_PARAM_FACTION;
   hparam[0].u.lf.f  = f;
   hparam[1].type    = HOOK_PARAM_NUMBER;
   hparam[1].u.num   = mod;
   hparam[2].type    = HOOK_PARAM_SENTINEL;
   hooks_runParam( "standing", hparam );

   /* Sanitize just in case. */
   faction_sanitizePlayer( faction );

   /* Tell space the faction changed. */
   space_factionChange();
}
Example #2
0
/**
 * @brief Modifies the player's standing without affecting others.
 *
 * Does not affect allies nor enemies.
 *
 *    @param f Faction whose standing to modiy.
 *    @param mod Amount to modiy standing by.
 *
 * @sa faction_modPlayer
 */
void faction_modPlayerRaw( int f, double mod )
{
   Faction *faction;

   if (!faction_isFaction(f)) {
      WARN("%d is an invalid faction", f);
      return;
   }

   faction = &faction_stack[f];

   /* Make sure it's not static. */
   if (faction_isFlag(faction, FACTION_STATIC))
      return;

   faction->player += mod;
   faction_sanitizePlayer(faction);
}
Example #3
0
/**
 * @brief Mods player using the power of Lua.
 */
static void faction_modPlayerLua( int f, double mod, const char *source, int secondary )
{
   Faction *faction;
   lua_State *L;
   int errf;
   double old, delta;
   HookParam hparam[3];

   faction = &faction_stack[f];

   /* Make sure it's not static. */
   if (faction_isFlag(faction, FACTION_STATIC))
      return;

   L     = faction->state;
   old   = faction->player;

   if (L == NULL)
      faction->player += mod;
   else {
#if DEBUGGING
      lua_pushcfunction(L, nlua_errTrace);
      errf = -6;
#else /* DEBUGGING */
      errf = 0;
#endif /* DEBUGGING */

      /* Set up the function:
       * faction_hit( current, amount, source, secondary ) */
      lua_getglobal(   L, "faction_hit" );
      lua_pushnumber(  L, faction->player );
      lua_pushnumber(  L, mod );
      lua_pushstring(  L, source );
      lua_pushboolean( L, secondary );

      /* Call function. */
      if (lua_pcall( L, 4, 1, errf )) { /* An error occurred. */
         WARN("Faction '%s': %s", faction->name, lua_tostring(L,-1));
#if DEBUGGING
         lua_pop( L, 2 );
#else /* DEBUGGING */
         lua_pop( L, 1 );
#endif /* DEBUGGING */
         return;
      }

      /* Parse return. */
      if (!lua_isnumber( L, -1 ))
         WARN( "Lua script for faction '%s' did not return a number from 'faction_hit(...)'.", faction->name );
      else
         faction->player = lua_tonumber( L, -1 );
#if DEBUGGING
      lua_pop( L, 2 );
#else /* DEBUGGING */
      lua_pop( L, 1 );
#endif /* DEBUGGING */
   }

   /* Sanitize just in case. */
   faction_sanitizePlayer( faction );

   /* Run hook if necessary. */
   delta = faction->player - old;
   if (fabs(delta) > 1e-10) {
      hparam[0].type    = HOOK_PARAM_FACTION;
      hparam[0].u.lf.f  = f;
      hparam[1].type    = HOOK_PARAM_NUMBER;
      hparam[1].u.num   = delta;
      hparam[2].type    = HOOK_PARAM_SENTINEL;
      hooks_runParam( "standing", hparam );

      /* Tell space the faction changed. */
      space_factionChange();
   }
}