예제 #1
0
/**
 * @brief Check systems for equality.
 *
 * Allows you to use the '=' operator in Lua with systems.
 *
 * @usage if sys == system.get( "Draygar" ) then -- Do something
 *
 *    @luaparam s System comparing.
 *    @luaparam comp System to compare against.
 *    @luareturn true if both systems are the same.
 * @luafunc __eq( s, comp )
 */
static int systemL_eq( lua_State *L )
{
   LuaSystem *a, *b;
   a = luaL_checksystem(L,1);
   b = luaL_checksystem(L,2);
   if (a->id == b->id)
      lua_pushboolean(L,1);
   else
      lua_pushboolean(L,0);
   return 1;
}
예제 #2
0
파일: nlua_misn.c 프로젝트: pegue/naev
/**
 * @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;
}
예제 #3
0
파일: nlua_system.c 프로젝트: reynir/naev
/**
 * @brief Gets system at index raising an error if type doesn't match.
 *
 *    @param L Lua state to get system from.
 *    @param ind Index position of system.
 *    @return The System at ind.
 */
StarSystem* luaL_validsystem( lua_State *L, int ind )
{
    LuaSystem *ls;
    StarSystem *s;
    ls = luaL_checksystem( L, ind );
    s  = system_getIndex( ls->id );
    if (s == NULL) {
        NLUA_ERROR( L, "System is invalid" );
        return NULL;
    }
    return s;
}
예제 #4
0
파일: nlua_player.c 프로젝트: Delll/naev
/**
 * @brief Teleports the player to a new system.
 *
 * Does not change the position nor velocity of the player, which will probably be wrong in the new system.
 *
 * @usage player.teleport( system.get("Arcanis") ) -- Teleports the player to arcanis.
 *
 *    @luaparam sys System to teleport the player to.
 * @luafunc teleport( sys )
 */
static int playerL_teleport( lua_State *L )
{
   LuaSystem *sys;

   /* Get a system. */
   sys = luaL_checksystem(L,1);

   /* Go to the new system. */
   space_init( sys->s->name );

   /* Run hooks - order is important. */
   hooks_run( "jumpout" );
   hooks_run( "jumpin" );
   hooks_run( "enter" );

   /* Map gets deformed when jumping this way. */
   map_clear();

   return 0;
}
예제 #5
0
파일: nlua_misn.c 프로젝트: Elderman/naev
/**
 * @brief Moves a marker to a new system.
 *
 * @usage misn.markerMove( my_marker, system.get("Delta Pavonis") )
 *
 *    @luaparam id ID of the mission marker to move.
 *    @luaparam sys System to move the marker to.
 * @luafunc markerMove( id, sys )
 */
static int misn_markerMove( lua_State *L )
{
   int id;
   LuaSystem *sys;
   MissionMarker *marker;
   int i, n;
   Mission *cur_mission;

   /* Handle parameters. */
   id    = luaL_checkinteger( L, 1 );
   sys   = luaL_checksystem( L, 2 );

   cur_mission = misn_getFromLua(L);

   /* Mission must have markers. */
   if (cur_mission->markers == NULL) {
      NLUA_ERROR( L, "Mission has no markers set!" );
      return 0;
   }

   /* Check id. */
   marker = NULL;
   n = array_size( cur_mission->markers );
   for (i=0; i<n; i++) {
      if (id == cur_mission->markers[i].id) {
         marker = &cur_mission->markers[i];
         break;
      }
   }
   if (marker == NULL) {
      NLUA_ERROR( L, "Mission does not have a marker with id '%d'", id );
      return 0;
   }

   /* Update system. */
   marker->sys = sys->id;

   /* Update system markers. */
   mission_sysMark();
   return 0;
}
예제 #6
0
/**
 * @brief Gets system (or system name) at index raising an error if type doesn't match.
 *
 *    @param L Lua state to get system from.
 *    @param ind Index position of system.
 *    @return The System at ind.
 */
StarSystem* luaL_validsystem( lua_State *L, int ind )
{
   LuaSystem *ls;
   StarSystem *s;

   if (lua_issystem(L, ind)) {
      ls = luaL_checksystem(L, ind);
      s = system_getIndex( ls->id );
   }
   else if (lua_isstring(L, ind))
      s = system_get( lua_tostring(L, ind) );
   else {
      luaL_typerror(L, ind, FACTION_METATABLE);
      return NULL;
   }

   if (s == NULL)
      NLUA_ERROR(L, "System is invalid");

   return s;
}
예제 #7
0
파일: nlua_misn.c 프로젝트: Elderman/naev
/**
 * @brief Adds a new marker.
 *
 * @usage my_marker = misn.markerAdd( system.get("Gamma Polaris"), "low" )
 *
 * Valid marker types are:<br/>
 *  - "plot": Important plot marker.<br/>
 *  - "high": High importance mission marker (lower than plot).<br/>
 *  - "low": Low importance mission marker (lower than high).<br/>
 *  - "computer": Mission computer marker.<br/>
 *
 *    @luaparam sys System to mark.
 *    @luaparam type Colouring scheme to use.
 *    @luareturn A marker ID to be used with markerMove and markerRm.
 * @luafunc markerAdd( sys, type )
 */
static int misn_markerAdd( lua_State *L )
{
   int id;
   LuaSystem *sys;
   const char *stype;
   SysMarker type;
   Mission *cur_mission;

   /* Check parameters. */
   sys   = luaL_checksystem( L, 1 );
   stype = luaL_checkstring( L, 2 );

   /* Handle types. */
   if (strcmp(stype, "computer")==0)
      type = SYSMARKER_COMPUTER;
   else if (strcmp(stype, "low")==0)
      type = SYSMARKER_LOW;
   else if (strcmp(stype, "high")==0)
      type = SYSMARKER_HIGH;
   else if (strcmp(stype, "plot")==0)
      type = SYSMARKER_PLOT;
   else {
      NLUA_ERROR(L, "Unknown marker type: %s", stype);
      return 0;
   }

   cur_mission = misn_getFromLua(L);

   /* Add the marker. */
   id = mission_addMarker( cur_mission, -1, sys->id, type );

   /* Update system markers. */
   mission_sysMark();

   /* Return the ID. */
   lua_pushnumber( L, id );
   return 1;
}