Second Life/Selfreplication: Unterschied zwischen den Versionen

aus Metalab Wiki, dem offenen Zentrum für meta-disziplinäre Magier und technisch-kreative Enthusiasten.
Zur Navigation springenZur Suche springen
K (Originalsource aus Vortrag)
Zeile 1: Zeile 1:
 +
== sourcecode ==
  
== code ==
+
=== selfrep.lsl ===
 
 
 
 
 
 
integer ttl = 3;
 
 
 
 
 
  
 +
// Global variables
 +
integer gintGeneration;                    // The Generation we are. Iterates with each replication.
 +
integer gintMaxGeneration = 5;              // Maximum allowed Generations. Replication stops at this Generation-Count.
 +
   
 +
vector gvecStandardNull = <9.5,0,0>;        // Position to rez Object to.
 +
rotation grotStandardNull = <0,0,0,0.0>;    // Rotation to rez Object to.
 +
 
 
  rez_child()
 
  rez_child()
 
  {
 
  {
  if(ttl > 0)
+
    // Check if we're allowed to create any more offspring
  {
+
    //llSay(0, "ok, rez!");
      integer ttl_child = ttl - 1;
+
    if(gintGeneration < gintMaxGeneration)
      llRezObject("1000er", llGetPos()+<1.5,0,0>, <0,0,0>, llEuler2Rot(<0,90,0> * DEG_TO_RAD) , ttl_child);
+
    {
  }
+
        // Satellite still over my land? 
 +
        if (llOverMyLand(llGetKey())) {
 +
            // if yes, rez the inventory-item at the distance of standardnull in front of us.
 +
            llRezObject("Metastasis Unit", (gvecStandardNull*llGetRot())+llGetPos(), ZERO_VECTOR, llGetRot(), gintGeneration+1);
 +
        }
 +
    }
 
  }
 
  }
 
+
 
 
 
 
  default
 
  default
 
  {
 
  {
 +
    // llRezObject throws event object_rez on the parent with the offspring as parameter 
 +
    object_rez(key child)
 +
    {
 +
        // Give copy of child to child
 +
        llGiveInventory(child, llKey2Name(child)); 
 +
    }
 +
   
 +
    // When rezzed, the event on_rez is called on me as the child
 +
    on_rez(integer pintGeneration)
 +
    {
 +
       
 +
        // Save child (this one) ttl;
 +
        gintGeneration = pintGeneration;
 +
       
 +
        // show the generation
 +
        llSetText((string)gintGeneration,<1,1,1>,1.0);
 +
        // llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
 +
    }
 +
 
 +
    link_message(integer sender_num, integer num, string msg, key id) {
 +
        if (msg == "replicate") {
 +
            rez_child();
 +
        }
 +
    }
 +
}
  
  touch_start(integer total_number)
 
  {
 
      rez_child();
 
  }
 
  
 +
=== sensor.lsl ===
  
  object_rez(key child)
+
 
  {
+
// boolean that keeps aggro/friendly mode.
      llGiveInventory(child, llKey2Name(child));  
+
integer intState = FALSE;
   }
+
    
 +
// the index for the
 +
integer intListenPointer = 0;
 
   
 
   
 +
// all needed rotations for a crystalline-form in an array
 +
list glRotations = [
 +
    // the six 2D-Plane rotations
 +
    <0,0,0>,
 +
    <0,0,60>,
 +
    <0,0,120>,
 +
    <0,0,180>,
 +
    <0,0,240>,
 +
    <0,0,300>,
 +
   
 +
    // the three upper rotations
 +
  <35,315,45>,
 +
  <35,45,135>,
 +
  <305,0,270>,
 +
 
 +
  // the three lower rotations
 +
  <35,315,225>,
 +
  <35,45,315>,
 +
  <305,0,90>
 +
  ];
 +
   
 +
   
 +
// the rotation-function.
 +
// rotates the entity to object to the next position in the global Rotations-Array
 +
object_rotateby() {
 +
         
 +
    rotation rotDelta;
 +
    rotation new_rot;   
 +
    integer intZufall =  (integer)llFrand(11.9);
 +
   
 +
    rotDelta = llEuler2Rot( llList2Vector(glRotations,intZufall) *  DEG_TO_RAD );
 +
    new_rot = ZERO_ROTATION * rotDelta;
 +
    llSetRot(new_rot);
 +
     
 +
    intListenPointer = intListenPointer + 1;
 +
    if (intListenPointer >= 11) intListenPointer = 0;
 +
}
 +
   
 +
object_init(integer pintOldPointer) {
 +
    llSetStatus(STATUS_PHYSICS,FALSE);
 +
    llListenRemove(pintOldPointer);
 +
    intListenPointer = llListen(0, "", llGetOwner(), "");
 +
    llSetTimerEvent(15);
 +
}
 +
 
 +
default
 +
{
 
    
 
    
  on_rez(integer ttl_in)
+
    state_entry()
  {
+
    {
      ttl = ttl_in;
+
        object_init(intListenPointer);
   }
+
    }
 
+
   
 
+
    on_rez(integer pintGeneration)
  changed(integer change)
+
    {
  {
+
        object_init(intListenPointer);
      if(change == CHANGED_INVENTORY)
+
       
      {
+
        if (pintGeneration>0) {
           rez_child();         
+
        // Children are aggro.
      }
+
              intState = TRUE; 
   }
+
        }
 +
    }
 +
   
 +
    sensor(integer total_number) // total_number is the number of avatars detected.
 +
    {
 +
        //llWhisper(0, (string)total_number + " debris-items detected - rotate 60 degrees" );
 +
        //object_rotateby();
 +
    }
 +
    
 +
    no_sensor() {
 +
       
 +
        if (intState) {
 +
            //llSay(0, "No debris detected, replicate");
 +
          llMessageLinked(LINK_THIS, 0, "replicate", "");
 +
        }
 +
    }
 +
   
 +
    // Because of the script-delay we have to connect the grand-child rezzing
 +
    // to the 'changed' event, which happens when someone (the parent) has
 +
    // given me (as the child) something (a copy of myself)
 +
    changed(integer change)
 +
    {
 +
        if(change == CHANGED_INVENTORY)
 +
        {
 +
           // rez_child();         
 +
        }
 +
    }
 +
       
 +
    timer() {
 +
        if (intState) {
 +
            object_rotateby();
 +
            llSensor("Metastasis Unit","", SCRIPTED, 12.5, PI_BY_TWO / 3);
 +
        }
 +
    }
 +
 
 +
    listen( integer channel, string name, key id, string message ){
 +
       
 +
        if (message == "metastasis off") {
 +
            intState = FALSE;
 +
            llSay(0, "Metastasis Unit offline: Service shutdown");
 +
        } else if (message == "metastasis on") {
 +
            intState = TRUE;   
 +
            llSay(0, "Metastasis Unit online: Service up");
 +
        } else if (message == "metastasis fall") {
 +
            intState = FALSE;   
 +
            llSay(0, "Metastasis Unit physics enabled");
 +
            llSetStatus(STATUS_PHYSICS,TRUE);
 +
        } else if (message == "metastasis delete") {
 +
            intState = FALSE;   
 +
            llSay(0, "Metastasis Unit self suicide");
 +
            llDie();
 +
        }
 +
    }
 +
         
 +
    // another quite funny feature.
 +
    //collision_start( integer num_detected) {
 +
    //   
 +
    //   llSetStatus(STATUS_PHYSICS,TRUE);
 +
    //}
 +
                     
 
  }
 
  }

Version vom 7. April 2007, 14:01 Uhr

sourcecode

selfrep.lsl

// Global variables
integer gintGeneration;                     // The Generation we are. Iterates with each replication.
integer gintMaxGeneration = 5;              // Maximum allowed Generations. Replication stops at this Generation-Count.
   
vector gvecStandardNull = <9.5,0,0>;        // Position to rez Object to.
rotation grotStandardNull = <0,0,0,0.0>;    // Rotation to rez Object to.
 
rez_child()
{
   // Check if we're allowed to create any more offspring
   //llSay(0, "ok, rez!");
   if(gintGeneration < gintMaxGeneration)
   {
       // Satellite still over my land?  
       if (llOverMyLand(llGetKey())) {
           // if yes, rez the inventory-item at the distance of standardnull in front of us.
           llRezObject("Metastasis Unit", (gvecStandardNull*llGetRot())+llGetPos(), ZERO_VECTOR, llGetRot(), gintGeneration+1);
       }
   }
}
 
default
{
   // llRezObject throws event object_rez on the parent with the offspring as parameter   
   object_rez(key child) 
   { 
       // Give copy of child to child
       llGiveInventory(child, llKey2Name(child));  
   } 
    
   // When rezzed, the event on_rez is called on me as the child
   on_rez(integer pintGeneration)
   {
       
       // Save child (this one) ttl;
       gintGeneration = pintGeneration;
       
       // show the generation
       llSetText((string)gintGeneration,<1,1,1>,1.0);
       // llSensorRepeat( "", "", AGENT, range, TWO_PI, rate );
   }
 
   link_message(integer sender_num, integer num, string msg, key id) {
       if (msg == "replicate") {
            rez_child(); 
       }
   }
}


sensor.lsl

// boolean that keeps aggro/friendly mode.
integer intState = FALSE;
  
// the index for the 
integer intListenPointer = 0;

// all needed rotations for a crystalline-form in an array
list glRotations = [
   // the six 2D-Plane rotations
   <0,0,0>,
   <0,0,60>,
   <0,0,120>,
   <0,0,180>,
   <0,0,240>,
   <0,0,300>,
   
   // the three upper rotations
  <35,315,45>,
  <35,45,135>,
  <305,0,270>,
  
  // the three lower rotations
  <35,315,225>,
  <35,45,315>,
  <305,0,90>
  ];
   
    
// the rotation-function.
// rotates the entity to object to the next position in the global Rotations-Array
object_rotateby() {
         
   rotation rotDelta;
   rotation new_rot;    
   integer intZufall =  (integer)llFrand(11.9);
   
   rotDelta = llEuler2Rot( llList2Vector(glRotations,intZufall) *  DEG_TO_RAD );
   new_rot = ZERO_ROTATION * rotDelta;
   llSetRot(new_rot);
      
   intListenPointer = intListenPointer + 1;
   if (intListenPointer >= 11) intListenPointer = 0;
}
    
object_init(integer pintOldPointer) {
   llSetStatus(STATUS_PHYSICS,FALSE);
   llListenRemove(pintOldPointer);
   intListenPointer = llListen(0, "", llGetOwner(), "");
   llSetTimerEvent(15);
}
  
default
{
 
   state_entry()
   {
        object_init(intListenPointer);
   }
   
   on_rez(integer pintGeneration)
   {
        object_init(intListenPointer);
       
       if (pintGeneration>0) {
       // Children are aggro.
             intState = TRUE;  
       }
   }
   
   sensor(integer total_number) // total_number is the number of avatars detected.
   {
       //llWhisper(0, (string)total_number + " debris-items detected - rotate 60 degrees" );
       //object_rotateby();
   }
  
   no_sensor() {
       
       if (intState) {
           //llSay(0, "No debris detected, replicate");
          llMessageLinked(LINK_THIS, 0, "replicate", "");
       }
   }
   
   // Because of the script-delay we have to connect the grand-child rezzing 
   // to the 'changed' event, which happens when someone (the parent) has
   // given me (as the child) something (a copy of myself)
   changed(integer change)
   {
       if(change == CHANGED_INVENTORY)
       {
          // rez_child();        
       }
   }
       
   timer() {
       if (intState) {
           object_rotateby(); 
           llSensor("Metastasis Unit","", SCRIPTED, 12.5, PI_BY_TWO / 3);
       }
   }
  
   listen( integer channel, string name, key id, string message ){
       
       if (message == "metastasis off") {
           intState = FALSE;
           llSay(0, "Metastasis Unit offline: Service shutdown");
       } else if (message == "metastasis on") {
           intState = TRUE;    
           llSay(0, "Metastasis Unit online: Service up");
       } else if (message == "metastasis fall") {
           intState = FALSE;    
           llSay(0, "Metastasis Unit physics enabled");
           llSetStatus(STATUS_PHYSICS,TRUE);
       } else if (message == "metastasis delete") {
           intState = FALSE;    
           llSay(0, "Metastasis Unit self suicide");
           llDie();
       }
   }
         
   // another quite funny feature. 
   //collision_start( integer num_detected) {
   //    
   //    llSetStatus(STATUS_PHYSICS,TRUE);
   //}
                      
}