コード例 #1
0
ファイル: map.c プロジェクト: isfos/naev
/**
 * @brief Selects the system in the map.
 *
 *    @param sys System to select.
 */
void map_select( StarSystem *sys, char shifted )
{
    unsigned int wid;
    int i;

    wid = window_get(MAP_WDWNAME);

    if (sys == NULL) {
        map_selectCur();
    }
    else {
        map_selected = sys - systems_stack;

        /* select the current system and make a path to it */
        if (!shifted) {
            if (map_path)
                free(map_path);
            map_path  = NULL;
            map_npath = 0;
        }

        /* Try to make path if is reachable. */
        if (space_sysReachable(sys)) {
            if (!shifted) {
                map_path = map_getJumpPath( &map_npath,
                                            cur_system->name, sys->name, 0 , NULL );
            }
            else {
                map_path = map_getJumpPath( &map_npath,
                                            cur_system->name, sys->name, 0 , map_path );
            }

            if (map_npath==0)
                hyperspace_target = -1;
            else  {
                /* see if it is a valid hyperspace target */
                for (i=0; i<cur_system->njumps; i++) {
                    if (map_path[0] == system_getIndex(cur_system->jumps[i])) {
                        planet_target     = -1; /* override planet_target */
                        hyperspace_target = i;
                        break;
                    }
                }
            }
        }
        else { /* unreachable. */
            hyperspace_target = -1;
        }
    }

    map_update(wid);
}
コード例 #2
0
ファイル: nlua_system.c プロジェクト: JKtheSlacker/naev
/**
 * @brief Gets jump distance from current system, or to another.
 *
 * Does different things depending on the parameter type:
 *    - nil : Gets distance from current system.
 *    - string : Gets distance from system matching name.
 *    - system : Gets distance from system
 *
 * @usage d = sys:jumpDist() -- Distance from current system.
 * @usage d = sys:jumpDist( "Draygar" ) -- Distance from system Draygar.
 * @usage d = sys:jumpDist( another_sys ) -- Distance from system another_sys.
 *
 *    @luaparam s System to get distance from.
 *    @luaparam param See description.
 *    @luaparam hidden Whether or not to consider hidden jumps.
 *    @luareturn Number of jumps to system.
 * @luafunc jumpDist( s, param, hidden )
 */
static int systemL_jumpdistance( lua_State *L )
{
   StarSystem *sys, *sysp;
   StarSystem **s;
   int jumps;
   const char *start, *goal;
   int h;

   sys = luaL_validsystem(L,1);
   start = sys->name;
   h   = lua_toboolean(L,3);

   if (lua_gettop(L) > 1) {
      if (lua_isstring(L,2))
         goal = lua_tostring(L,2);
      else if (lua_issystem(L,2)) {
         sysp = luaL_validsystem(L,2);
         goal = sysp->name;
      }
      else NLUA_INVALID_PARAMETER(L);
   }
   else
      goal = cur_system->name;

   s = map_getJumpPath( &jumps, start, goal, 1, h, NULL );
   free(s);

   lua_pushnumber(L,jumps);
   return 1;
}
コード例 #3
0
ファイル: nlua_system.c プロジェクト: nenau/naev
/**
 * @brief Gets jump path from current system, or to another.
 *
 * Does different things depending on the parameter type:
 *    - nil : Gets path from current system.
 *    - string : Gets path from system matching name.
 *    - system : Gets path from system
 *
 * @usage jumps = sys:jumpPath() -- Path to current system.
 * @usage jumps = sys:jumpPath( "Draygar" ) -- Path from current sys to Draygar.
 * @usage jumps = system.jumpPath( "Draygar", another_sys ) -- Path from Draygar to another_sys.
 *
 *    @luatparam System s System to get path from.
 *    @luatparam nil|string|System param See description.
 *    @luatparam[opt=false] boolean hidden Whether or not to consider hidden jumps.
 *    @luatreturn {Jump,...} Table of jumps.
 * @luafunc jumpPath( s, param, hidden )
 */
static int systemL_jumpPath( lua_State *L )
{
   LuaJump lj;
   StarSystem *sys, *sysp;
   StarSystem **s;
   int i, sid, jumps, pushed, h;
   const char *start, *goal;

   h   = lua_toboolean(L,3);

   /* Foo to Bar */
   if (lua_gettop(L) > 1) {
      sys   = luaL_validsystem(L,1);
      start = sys->name;
      sid   = sys->id;

      if (lua_isstring(L,2))
         goal = lua_tostring(L,2);
      else if (lua_issystem(L,2)) {
         sysp = luaL_validsystem(L,2);
         goal = sysp->name;
      }
      else NLUA_INVALID_PARAMETER(L);
   }
   /* Current to Foo */
   else {
      start = cur_system->name;
      sid   = cur_system->id;
      sys   = luaL_validsystem(L,1);
      goal  = sys->name;
   }

   s = map_getJumpPath( &jumps, start, goal, 1, h, NULL );
   if (s == NULL)
      return 0;

   /* Create the jump table. */
   lua_newtable(L);
   pushed = 0;

   /* Map path doesn't contain the start system, push it manually. */
   lj.srcid  = sid;
   lj.destid = s[0]->id;

   lua_pushnumber(L, ++pushed); /* key. */
   lua_pushjump(L, lj);         /* value. */
   lua_rawset(L, -3);

   for (i=0; i<(jumps - 1); i++) {
      lj.srcid  = s[i]->id;
      lj.destid = s[i+1]->id;

      lua_pushnumber(L, ++pushed); /* key. */
      lua_pushjump(L, lj);         /* value. */
      lua_rawset(L, -3);
   }
   free(s);

   return 1;
}