Esempio n. 1
0
/**
 * @brief Gets all the systems within a radius
 *
 * @usage for _,s in ipairs( withinRadius() ) do -- Iterate over found systems.
 *
 *    @luaparam x coord of search centre
 *    @luaparam y coord of search centre
 *    @luaparam radius of the search
 *    @luareturn An ordered table with all the found systems.
 * @luafunc withinRadius( x,y,radius )
 */
static int systemL_withinradius( lua_State *L )
{
    int i, id = 1;
    LuaSystem sysp;
    int systems_nstack ;
    StarSystem *systems_stack= system_getAll( &systems_nstack );
    
    double centreX = luaL_checknumber(L,1);
    double centreY = luaL_checknumber(L,2);
    long radius = luaL_checknumber(L,3);

    long distX,distY;
    
    /* Push all adjacent systems. */
    lua_newtable(L);
    
    for (i=0; i<systems_nstack; i++) {
        distX=systems_stack[i].pos.x-centreX;
        distY=systems_stack[i].pos.y-centreY;
        if (abs(distX)<radius && abs(distY)<radius) {//safety in case of overflow on very large squared distances
        	if (distX*distX+distY*distY<radius*radius) {
        		sysp = system_index(&systems_stack[i]);
        		lua_pushnumber(L,id); /* key. */
        		lua_pushsystem(L,sysp); /* value. */
        		lua_rawset(L,-3);
        		id++;
        	}
        }
    }
    
    return 1;
}
Esempio n. 2
0
/**
 * @brief Clears the claims on all systems.
 */
void claim_clear (void)
{
   StarSystem *sys;
   int nsys;
   int i;

   /* Clears all the flags. */
   sys = system_getAll( &nsys );
   for (i=0; i<nsys; i++)
      sys_rmFlag( &sys[i], SYSTEM_CLAIMED );
}
Esempio n. 3
0
/**
 * @brief Saves all the star systems.
 *
 *    @return 0 on success.
 */
int dsys_saveAll (void)
{
   int i;
   int nsys;
   StarSystem *sys;

   sys = system_getAll( &nsys );

   /* Write systems. */
   for (i=0; i<nsys; i++)
      dsys_saveSystem( &sys[i] );

   return 0;
}
Esempio n. 4
0
/**
 * @brief Gets all the systems.
 *    @luatreturn {System,...} A list of all the systems.
 * @luafunc getAll()
 */
static int systemL_getAll( lua_State *L )
{
   StarSystem *sys;
   int i, ind, n;

   lua_newtable(L);
   sys = system_getAll( &n );

   ind = 1;
   for (i=0; i<n; i++) {
      lua_pushnumber( L, ind++ );
      lua_pushsystem( L, system_index( &sys[i] ) );
      lua_settable(   L, -3 );
   }
   return 1;
}