/** * @brief Initializes a new Solid. * * @param dest Solid to initialize. * @param mass Mass to set solid to. * @param dir Solid initial direction. * @param pos Initial solid position. * @param vel Initial solid velocity. */ void solid_init( Solid* dest, const double mass, const double dir, const Vector2d* pos, const Vector2d* vel, int update ) { memset(dest, 0, sizeof(Solid)); dest->mass = mass; /* Set direction velocity. */ dest->dir_vel = 0.; /* Set force. */ dest->thrust = 0.; /* Set direction. */ dest->dir = dir; if ((dest->dir > 2.*M_PI) || (dest->dir < 0.)) dest->dir = fmod(dest->dir, 2.*M_PI); /* Set velocity. */ if (vel == NULL) vectnull( &dest->vel ); else vectcpy( &dest->vel, vel ); /* Set position. */ if (pos == NULL) vectnull( &dest->pos ); else vectcpy( &dest->pos, pos); /* Misc. */ dest->speed_max = -1.; /* Negative is invalid. */ /* Handle update. */ switch (update) { case SOLID_UPDATE_RK4: dest->update = solid_update_rk4; break; case SOLID_UPDATE_EULER: dest->update = solid_update_euler; break; default: WARN("Solid initialization did not specify correct update function!"); dest->update = solid_update_rk4; break; } }
/** * @brief Clears all the currently running effects. */ void spfx_clear (void) { int i; /* Clear front layer */ for (i=spfx_nstack_front-1; i>=0; i--) spfx_destroy( spfx_stack_front, &spfx_nstack_front, i ); /* Clear back layer */ for (i=spfx_nstack_back-1; i>=0; i--) spfx_destroy( spfx_stack_back, &spfx_nstack_back, i ); /* Clear rumble */ shake_set = 0; shake_off = 1; shake_force_mod = 0.; vectnull( &shake_pos ); vectnull( &shake_vel ); }
/** * @brief Sets the pilot's position. * * @usage p:warp( vec2.new( 300, 200 ) ) * * @luaparam p Pilot to set the position of. * @luaparam pos Position to set. * @luafunc warp( p, pos ) */ static int pilotL_warp( lua_State *L ) { LuaPilot *p1; Pilot *p; LuaVector *v; /* Parse parameters */ p1 = luaL_checkpilot(L,1); p = pilot_get( p1->pilot ); v = luaL_checkvector(L,2); /* Pilot must exist. */ if (p == NULL) { NLUA_ERROR(L,"Pilot is invalid."); return 0; } /* Warp pilot to new position. */ vectcpy( &p->solid->pos, &v->vec ); vectnull( &p->solid->vel ); /* Clear velocity otherwise it's a bit weird. */ return 0; }
/** * @brief Adds a fleet to the system. * * You can then iterate over the pilots to change parameters like so: * @code * p = pilot.add( "Sml Trader Convoy" ) * for k,v in pairs(p) do * v:setHostile() * end * @endcode * * @usage p = pilot.add( "Pirate Hyena" ) -- Just adds the pilot (will jump in). * @usage p = pilot.add( "Trader Llama", "dummy" ) -- Overrides AI with dummy ai. * @usage p = pilot.add( "Sml Trader Convoy", "def", vec2.new( 1000, 200 ) ) -- Pilot won't jump in, will just appear. * @usage p = pilot.add( "Empire Pacifier", "def", vec2.new( 1000, 1000 ), true ) -- Have the pilot jump in. * * @luaparam fleetname Name of the fleet to add. * @luaparam ai If set will override the standard fleet AI. "def" means use default. * @luaparam pos Position to create pilots around instead of choosing randomly. * @luaparam jump true if pilots should jump in, false by default if pos is defined. * @luareturn Table populated with all the pilots created. The keys are ordered numbers. * @luafunc add( fleetname, ai, pos, jump ) */ static int pilot_addFleet( lua_State *L ) { NLUA_MIN_ARGS(1); Fleet *flt; const char *fltname, *fltai; int i, j; unsigned int p; double a; double d; Vector2d vv,vp, vn; FleetPilot *plt; LuaPilot lp; LuaVector *lv; int jump; /* Parse first argument - Fleet Name */ fltname = luaL_checkstring(L,1); /* Parse second argument - Fleet AI Override */ if (lua_gettop(L) > 1) { fltai = luaL_checkstring(L,2); if (strcmp(fltai, "def")==0) /* Check if set to default */ fltai = NULL; } else fltai = NULL; /* Parse third argument - Position */ if (lua_gettop(L) > 2) { lv = luaL_checkvector(L,3); } else lv = NULL; if (lua_gettop(L) > 3) { jump = lua_toboolean(L,4); } else { /* Only jump by default if not position was passed. */ if (lv==NULL) jump = 1; else jump = 0; } /* Needed to determine angle. */ vectnull(&vn); /* pull the fleet */ flt = fleet_get( fltname ); if (flt == NULL) { NLUA_ERROR(L,"Fleet '%s' doesn't exist.", fltname); return 0; } /* Use position passed if possible. */ if (lv != NULL) { if (!jump) vectcpy( &vp, &lv->vec ); else { /* Pilot is jumping in, we'll only use the vector angle. */ d = RNGF()*(HYPERSPACE_ENTER_MAX-HYPERSPACE_ENTER_MIN) + HYPERSPACE_ENTER_MIN; vect_pset( &vp, d, VANGLE(lv->vec) ); } } else { d = RNGF()*(HYPERSPACE_ENTER_MAX-HYPERSPACE_ENTER_MIN) + HYPERSPACE_ENTER_MIN; vect_pset( &vp, d, RNGF() * 2.*M_PI); } /* now we start adding pilots and toss ids into the table we return */ j = 0; lua_newtable(L); for (i=0; i<flt->npilots; i++) { plt = &flt->pilots[i]; if (RNG(0,100) <= plt->chance) { /* fleet displacement */ vect_cadd(&vp, RNG(75,150) * (RNG(0,1) ? 1 : -1), RNG(75,150) * (RNG(0,1) ? 1 : -1)); /* Set velocity only if no position is set.. */ if (lv != NULL) { if (jump) { a = vect_angle(&vp,&vn); vect_pset( &vv, HYPERSPACE_VEL, a ); } else { a = RNGF() * 2.*M_PI; vectnull( &vv ); } } else { /* Entering via hyperspace. */ a = vect_angle(&vp,&vn); vect_pset( &vv, HYPERSPACE_VEL, a ); } /* Make sure angle is sane. */ if (a < 0.) a += 2.*M_PI; /* Create the pilot. */ p = fleet_createPilot( flt, plt, a, &vp, &vv, fltai, 0 ); /* we push each pilot created into a table and return it */ lua_pushnumber(L,++j); /* index, starts with 1 */ lp.pilot = p; lua_pushpilot(L,lp); /* value = LuaPilot */ lua_rawset(L,-3); /* store the value in the table */ } } return 1; }