}
+static SQInteger SSector_set_gravity_wrapper(HSQUIRRELVM vm)
+{
+ SQUserPointer data;
+ if(SQ_FAILED(sq_getinstanceup(vm, 1, &data, 0))) {
+ sq_throwerror(vm, _SC("'set_gravity' called without instance"));
+ return SQ_ERROR;
+ }
+ Scripting::SSector* _this = reinterpret_cast<Scripting::SSector*> (data);
+ SQFloat arg0;
+ if(SQ_FAILED(sq_getfloat(vm, 2, &arg0))) {
+ sq_throwerror(vm, _SC("Argument 1 not a float"));
+ return SQ_ERROR;
+ }
+
+ try {
+ _this->set_gravity(static_cast<float> (arg0));
+
+ return 0;
+
+ } catch(std::exception& e) {
+ sq_throwerror(vm, e.what());
+ return SQ_ERROR;
+ } catch(...) {
+ sq_throwerror(vm, _SC("Unexpected exception while executing function 'set_gravity'"));
+ return SQ_ERROR;
+ }
+
+}
+
static SQInteger LevelTime_release_hook(SQUserPointer ptr, SQInteger )
{
Scripting::LevelTime* _this = reinterpret_cast<Scripting::LevelTime*> (ptr);
throw SquirrelError(v, "Couldn't register function 'get_ambient_blue'");
}
+ sq_pushstring(v, "set_gravity", -1);
+ sq_newclosure(v, &SSector_set_gravity_wrapper, 0);
+ if(SQ_FAILED(sq_createslot(v, -3))) {
+ throw SquirrelError(v, "Couldn't register function 'set_gravity'");
+ }
+
if(SQ_FAILED(sq_createslot(v, -3))) {
throw SquirrelError(v, "Couldn't register class 'SSector'");
}
{
return ambient_light.blue;
}
+
+void
+Sector::set_gravity(float gravity)
+{
+ log_warning << "Changing a Sector's gravitational constant might have unforseen side-effects" << std::endl;
+
+ this->gravity = gravity;
+
+ for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) {
+ GameObject* game_object = *i;
+ if(!game_object) continue;
+ if(!game_object->is_valid()) continue;
+ UsesPhysic *physics_object = dynamic_cast<UsesPhysic*>(game_object);
+ if (!physics_object) continue;
+
+ physics_object->physic.set_gravity(gravity);
+ }
+}
+
float get_ambient_green();
float get_ambient_blue();
+ /**
+ * set gravity throughout sector
+ */
+ void set_gravity(float gravity);
+
private:
Level* level; /**< Parent level containing this sector */
uint32_t collision_tile_attributes(const Rect& dest) const;