1 //originally written by Davide Byron
2 //this code is released under the GPLv3
4 // Reacts to E_NO_SENSOR event
5 // Produces R_SUB_ENERGY events
6 // makes the creature move in the direction of a detected active object at the cost of some energy
8 // the creature tryies to reach the object and will use an energy amount proportional to the
9 // distance covered with the movement.
10 // if there is not enough energy the creature will succed in moving but die soon after if the reached
11 // object does not provide food.
13 //dedicated to Mealea, thanks for the passion you put into things and for being able to pass it on to me :)
16 //integer E_AT_TARGET = 9;
17 //integer E_NOT_AT_TARGET = 10;
18 integer E_NO_SENSOR
= 5;
19 integer R_MOD_ENERGY
= 11;
20 //cage boundaries expressed in region absolute coords
21 //you might want to customize them
22 integer CAGE_MIN_X
= 1;
23 integer CAGE_MAX_X
= 249;
24 integer CAGE_MIN_Y
= 1;
25 integer CAGE_MAX_Y
= 249;
26 integer CAGE_MIN_Z
= 1;
27 integer CAGE_MAX_Z
= 100;
31 //global vars for the creature, can be subjected to evolution one day...
32 i
//target we're pointing at
33 integer CurrentTarget
;
34 //how many seconds to reach the point of interest
36 //treshold for the at target event
37 float Proximity
= 1.0;
38 //how far can we go in a single movement
39 float MaxStepLength
= 40.0;
40 //used to calculate energy consumption, the higher the value, the less the energy required
41 float EnergyDividendum
= 100;
48 //generates a random float number ranging from -range to range
49 float myRand( float range
)
51 float sign
= llFrand(2.1);
52 float random
= llFrand( range
+ 0.1 );
62 //deny moving out of a definite "cage"
63 //mostly used for debug
64 vector checkCageLimit( vector pos
)
66 if( pos
.x
< CAGE_MIN_X
)
68 if( pos
.x
> CAGE_MAX_X
)
70 if( pos
.y
< CAGE_MIN_Y
)
72 if( pos
.y
> CAGE_MAX_Y
)
74 if( pos
.z
< CAGE_MIN_Z
)
76 if( llGround( pos
- llGetPos() ) > pos
.z
)
77 pos
.z
= llGround( pos
- llGetPos() ) + 0.1;
78 if( pos
.z
> CAGE_MAX_Z
)
100 //phantom is needed to avoid collision, they cause too much lag
101 llSetStatus(STATUS_PHANTOM
, TRUE
);
102 //physical is needed to use physical moving functions
103 llSetStatus(STATUS_PHYSICS
, TRUE
);
110 link_message( integer sender_num
, integer num
, string str
, key id
)
112 //the creature sees nothing, so move at random...
113 if( num
== E_NO_SENSOR
)
115 //calculates the new position
116 vector newPosition
= llGetPos();
117 newPosition
.x
= newPosition
.x
+ myRand(MaxStepLength
);
118 newPosition
.y
= newPosition
.y
+ myRand(MaxStepLength
);
119 newPosition
.z
= newPosition
.z
+ myRand(MaxStepLength
);
121 newPosition
= checkCageLimit( newPosition
);
124 CurrentTarget
= llTarget( newPosition
, Proximity
);
125 //ask for energy substraction due to movement
126 llMessageLinked(LINK_SET
, R_MOD_ENERGY
, (string)(-llVecDist(llGetPos(), newPosition
)/10), "");
128 llLookAt( newPosition
, Force
, Dump
);
130 llMoveToTarget( newPosition
, Speed
);
137 //this has no use as of today, probably will be removed.
138 at_target(integer tnum
, vector targetpos
, vector ourpos
)
140 //notice the at_target event
141 //llMessageLinked(LINK_SET, E_AT_TARGET, "", "");
147 //this has no use as of today, probably will be removed.
150 //notice the not_at_target event
151 //llMessageLinked(LINK_SET, E_NOT_AT_TARGET, "", "");