Exemple #1
0
/**
 * @brief Sets the mission marker on the system.  If no parameters are passed it
 * unsets the current marker.
 *
 * There are basically three different types of markers:
 *
 *  - "misc" : These markers are for unique or non-standard missions.
 *  - "cargo" : These markers are for regular cargo hauling missions.
 *  - "rush" : These markers are for timed missions.
 *
 * @usage misn.setMarker() -- Clears the marker
 * @usage misn.setMarker( sys, "misc" ) -- Misc mission marker.
 * @usage misn.setMarker( sys, "cargo" ) -- Cargo mission marker.
 * @usage misn.setMarker( sys, "rush" ) -- Rush mission marker.
 *
 *    @luaparam sys System to mark.  Unmarks if no parameter or nil is passed.
 *    @luaparam type Optional parameter that specifies mission type.  Can be one of
 *          "misc", "rush" or "cargo".
 * @luafunc setMarker( sys, type )
 */
static int misn_setMarker( lua_State *L )
{
   const char *str;
   LuaSystem *sys;

   /* No parameter clears the marker */
   if (lua_gettop(L)==0) {
      if (cur_mission->sys_marker != NULL)
         free(cur_mission->sys_marker);
      mission_sysMark(); /* Clear the marker */
   }

   /* Passing in a Star System */
   sys = luaL_checksystem(L,1);
   sys = lua_tosystem(L,1);
   cur_mission->sys_marker = strdup(sys->s->name);

   /* Get the type. */
   if (lua_gettop(L) > 1) {
      str = luaL_checkstring(L,2);
      if (strcmp(str, "misc")==0)
         cur_mission->sys_markerType = SYSMARKER_MISC;
      else if (strcmp(str, "rush")==0)
         cur_mission->sys_markerType = SYSMARKER_RUSH;
      else if (strcmp(str, "cargo")==0)
         cur_mission->sys_markerType = SYSMARKER_CARGO;
      else
         NLUA_DEBUG("Unknown marker type: %s", str);
   }

   mission_sysMark(); /* mark the system */

   return 0;
}
Exemple #2
0
/**
 * @brief Hooks the function to a specific pilot.
 *
 * You can hook to different actions.  Curently hook system only supports:<br />
 *    - "death" : triggered when pilot dies.<br />
 *    - "board" : triggered when pilot is boarded.<br />
 *    - "disable" : triggered when pilot is disabled.<br />
 *    - "jump" : triggered when pilot jumps to hyperspace.<br />
 *    - "hail" : triggered when pilot is hailed.<br />
 *    - "attacked" : triggered when the pilot is attacked in manual control <br />
 *    - "idle" : triggered when the pilot becomes idle in manual control <br />
 *
 *    @luaparam pilot Pilot identifier to hook.
 *    @luaparam type One of the supported hook types.
 *    @luaparam funcname Name of function to run when hook is triggered.
 *    @luareturn Hook identifier.
 * @luafunc pilot( pilot, type, funcname )
 */
static int hook_pilot( lua_State *L )
{
   unsigned int h;
   LuaPilot *p;
   int type;
   const char *hook_type;

   /* Parameters. */
   p           = luaL_checkpilot(L,1);
   hook_type   = luaL_checkstring(L,2);

   /* Check to see if hook_type is valid */
   if (strcmp(hook_type,"death")==0)         type = PILOT_HOOK_DEATH;
   else if (strcmp(hook_type,"board")==0)    type = PILOT_HOOK_BOARD;
   else if (strcmp(hook_type,"disable")==0)  type = PILOT_HOOK_DISABLE;
   else if (strcmp(hook_type,"jump")==0)     type = PILOT_HOOK_JUMP;
   else if (strcmp(hook_type,"hail")==0)     type = PILOT_HOOK_HAIL;
   else if (strcmp(hook_type,"attacked")==0) type = PILOT_HOOK_ATTACKED;
   else if (strcmp(hook_type,"idle")==0)     type = PILOT_HOOK_IDLE;
   else { /* hook_type not valid */
      NLUA_DEBUG("Invalid pilot hook type: '%s'", hook_type);
      return 0;
   }

   /* actually add the hook */
   h = hook_generic( L, hook_type, 3 );
   pilot_addHook( pilot_get(p->pilot), type, h );

   return 0;
}