PageRenderTime 11ms CodeModel.GetById 9ms app.highlight 1ms RepoModel.GetById 0ms app.codeStats 0ms

/AuroraDocs/Vehicles/Boat.lsl

https://bitbucket.org/VirtualReality/software-testing
Unknown | 133 lines | 110 code | 23 blank | 0 comment | 0 complexity | e8e10d671ce5958b27e523d0eb399411 MD5 | raw file
  1//Simple boat that works with the new SLFeeling Physics Engine (mod from encog)
  2
  3float forward_power = 25; 
  4float reverse_power = -15;
  5float turning_ratio = 5.0; 
  6string sit_message = "Ride"; 
  7string not_owner_message = "You are not the owner of this vehicle ..."; 
  8
  9default
 10{
 11    state_entry()
 12    {
 13        llSetSitText(sit_message);
 14        llSitTarget(<0.2,0,0.45>, ZERO_ROTATION );
 15        
 16        llSetCameraEyeOffset(<-12, 0.0, 5.0>);
 17        llSetCameraAtOffset(<1.0, 0.0, 2.0>);
 18        
 19        llSetVehicleFlags(0);
 20        llSetVehicleType(VEHICLE_TYPE_BOAT);
 21        llSetVehicleFlags(VEHICLE_FLAG_HOVER_UP_ONLY | VEHICLE_FLAG_HOVER_WATER_ONLY);
 22        llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <1, 1, 1> );
 23        llSetVehicleFloatParam( VEHICLE_ANGULAR_FRICTION_TIMESCALE, 2 );
 24        
 25    llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0>);
 26    llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1);
 27    llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.05);
 28        
 29        llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, 1 );
 30        llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 1 );
 31        llSetVehicleFloatParam( VEHICLE_HOVER_HEIGHT, 0.5);
 32        llSetVehicleFloatParam( VEHICLE_HOVER_EFFICIENCY,1 );
 33        llSetVehicleFloatParam( VEHICLE_HOVER_TIMESCALE, 2.0 );
 34        llSetVehicleFloatParam( VEHICLE_BUOYANCY, 1 );
 35        llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.5 );
 36        llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 3 );
 37        llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.5 );
 38        llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 10 );
 39        llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 4 );
 40        llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.5 );
 41        llSetVehicleFloatParam( VEHICLE_BANKING_EFFICIENCY, 0.9 );
 42        llSetVehicleFloatParam( VEHICLE_BANKING_MIX, 1 );
 43        llSetVehicleFloatParam( VEHICLE_BANKING_TIMESCALE, 7 );
 44        llSetVehicleRotationParam( VEHICLE_REFERENCE_FRAME, ZERO_ROTATION );
 45    }
 46    
 47    changed(integer change)
 48    {
 49        
 50        
 51        if (change & CHANGED_LINK)
 52        {
 53            
 54            key agent = llAvatarOnSitTarget();
 55            if (agent)
 56            {                
 57                if (agent != llGetOwner())
 58                {
 59                    llSay(0, not_owner_message);
 60                    llUnSit(agent);
 61                    llPushObject(agent, <0,0,50>, ZERO_VECTOR, FALSE);
 62                }
 63                else
 64                {
 65                                        
 66                    llMessageLinked(LINK_ALL_CHILDREN , 0, "start", NULL_KEY);
 67                    llSleep(.4);
 68                    llSetStatus(STATUS_PHYSICS, TRUE);
 69                    llSleep(.1);
 70                    llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
 71
 72                }
 73            }
 74            else
 75            {
 76                llSetStatus(STATUS_PHYSICS, FALSE);
 77                llSleep(.1);
 78                llMessageLinked(LINK_ALL_CHILDREN , 0, "stop", NULL_KEY);
 79                llSleep(.4);
 80                llReleaseControls();
 81                llTargetOmega(<0,0,0>,PI,0);
 82                
 83                llResetScript();
 84            }
 85        }
 86        
 87    }
 88    
 89    run_time_permissions(integer perm)
 90    {
 91        if (perm)
 92        {
 93            llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_DOWN | CONTROL_UP | CONTROL_RIGHT | 
 94                            CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT, TRUE, FALSE);
 95        }
 96    }
 97    
 98    control(key id, integer level, integer edge)
 99    {
100        integer reverse=1;
101        vector angular_motor;
102        
103        vector vel = llGetVel();
104        float speed = llVecMag(vel);
105
106        if(level & CONTROL_FWD)
107        {
108            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <forward_power,0,0>);
109            reverse=1;
110        }
111        if(level & CONTROL_BACK)
112        {
113            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <reverse_power,0,0>);
114            reverse = -1;
115        }
116
117        if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
118        {
119            angular_motor.z -= speed / turning_ratio * reverse;
120            angular_motor.x += 20;
121        }
122        
123        if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
124        {
125            angular_motor.z += speed / turning_ratio * reverse;
126            angular_motor.x -= 20;
127        }
128
129        llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
130
131    }   
132    
133}