· 8 years ago · Nov 17, 2017, 02:54 PM
1//=================================================================================================
2//
3// ████████╗██╗██████╗ ██╗████████╗██╗ ██╗ ██████╗███████╗
4// ╚â•â•██╔â•â•â•██║██╔â•â•██╗██║╚â•â•██╔â•â•â•██║ ██║ ██╔â•â•â•â•â•╚â•â•███╔â•
5// ██║ ██║██████╔â•██║ ██║ ███████║ ██║ ███╔â•
6// ██║ ██║██╔â•â•██╗██║ ██║ ██╔â•â•██║ ██║ ███╔â•
7// ██║ ██║██║ ██║██║ ██║ ██║ ██║██╗╚██████╗███████╗
8// ╚â•╠╚â•â•╚â•╠╚â•â•╚â•╠╚â•╠╚â•╠╚â•â•╚â•╠╚â•â•â•â•â•â•╚â•â•â•â•â•â•â•
9//
10//=================================================================================================
11// Project CREATURES AI 2017 - Secondlife
12// name: Agent Direct Control - movement, by hud basic communication
13// author: Tirith Abrasax (tirithcz) (C) 2017 ~ All Right Reserved
14// tirithcz@gmail.com
15// version: 1.01
16// 1.03 - add hud CMDs list
17// 1.05 - fixed bugs in lslEditor
18////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
19
20//=================================================================================================
21// HUD - COMMANDS
22// Category Name Params Response
23//=================================================================================================
24// MOTION Move
25// MOTION TurnRight
26// MOTION TurnLeft
27// MOTION Up
28// MOTION Down
29// MOTION Roll
30// MOTION Pitch
31// MOTION GoHome
32// MOTION SetHomeToHere
33// MOTION GetHome
34// MOTION PointAtNearestAvatar
35// MOTION PointAtOwner
36// MOTION PointInDirection
37// MOTION GetDirection
38// MOTION SetDirection
39// LOOKS SetColor
40// LOOKS GetColor
41// LOOKS SetAlpha
42// LOOKS SetGlow
43// LOOKS SetSizeTo
44// LOOKS SetSizeBy
45// LOOKS GetSize
46// LOOKS PlaySound
47// PERCEPTION GetDistanceToNearestAvatar
48// PERCEPTION GetDistanceToOwner
49// PERCEPTION GetNumberOfAvatarsNeaby
50// PERCEPTION GetDistanceToNearestObject
51// PERCEPTION GetDistanceToNearestAgent
52// NEEDS GetNeeds
53// NEEDS SetNeeds
54// NEEDS GetState
55// NEEDS SetState
56// NEEDS SetPose
57// NEEDS SetAnimation
58// NEEDS SetActivityLevel
59// NEEDS GetActivityLevel
60// NEEDS GetInfo
61// NEEDS SetID
62// NEEDS SetName
63// NEEDS SetSex
64// NEEDS GetSex
65// NEEDS SetAge
66// NEEDS GetAge
67// NEEDS ShowTitle
68// NEEDS HideTitle
69// NEEDS ShowParticles
70// AI getLocations
71// AI getTasks
72// AI clearTasks
73// AI clearLocaltions
74// AI getStates
75// AI pathfindingOn
76// AI pathfindingOff
77// AI pathfindingWander
78// AI pathfindingPatrol
79// AI pathfindingFollow
80// AI pathfindingFlee
81// AI GetPathfindingStatus
82// AI searchForObjects
83// AI searchForAgents
84// AI timerOn
85// AI timerOff
86// AI permissionAll
87// AI permissionGroup
88// AI permissionOwner
89// AI pathfindingOn
90// AI getAge
91// AI setAge
92// AI setAgeMax
93// AI pregnantOn
94// AI pregnantOff
95// AI particlesObjectsOn
96// AI particlesObjectsOff
97// AI particlesAgentsOn
98// AI particlesAgentsOff
99// AI particlesRayCastOn
100// AI particlesRayCastOff
101
102//=================================================================================================
103
104
105////////// CONSTANTS ///////////////**//////////////////////////////////////////////////////////////////////////////
106////////// --> !! DO NOT CHANGE !! <--/////////////////////////////////////////////////////////////////////////////////
107 integer CHANNEL_HUD = 1212; // channel for HUD <--> Agent Communication
108 integer CHANNEL_CHAT = 0; // channel for listening written command (neaby chat)
109 integer CHANNEL_AGENTS = -8686; // channel for Agent <--> Agent/Objects Communication
110 integer SECRET_KEY = 456454645;
111 key creatorKey = "baa77d51-e4e2-42a6-b8a8-72dbc4663d65";
112 string creatorName = "tirithcz";
113 integer isDebug = TRUE; // debugging
114////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
115 key http_request_id = NULL_KEY;
116 string URL_SERVER = "http://tirith.cz/creatures-ai/";
117 string URL_PHP_DB = "lsl2db.php";
118 string URL_PHP_AJAX = "ajax.php";
119 string URL_PHP_UPDATE = "update.php";
120 string URL_PHP_TEXTURE = "textures.php";
121 string URL_PHP_LOG = "log/log.php";
122////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
123////////// VARIABLES - AGENT LIFE ATTRIBUTES ///////////////////////////////////////////////////////////////////////
124 string AGENT_NAME = "Noname"; // Agent Name
125 float AGENT_AGE = 0; // age of agent ( = days / 24 )
126 float AGENT_AGE_MAX = 4*24; // 96hours(4days)
127 integer agentDieTimeOut = 60*40; // TimeOut for SAFETY - 20minut to die (seconds)
128 float AGENT_SIZE = 1; // size of agent - desired (adult)
129 vector AGENT_SIZE_VECTOR = <1,1,1>; // - in vector value
130 float currentSize = 0; // current agent size
131 integer sex = 0; // SEX: 0..male, 1..female
132 integer species = 0; // Species: 0 .. non
133 // 1 .. dog
134 // 2 .. cat
135 // 3 .. kralik / home rabbit
136 // 8 .. fish
137 // 9 .. rat
138 // 10 .. chicken
139 // 11 .. sheep
140 // 12 .. goat
141 // 13 .. cow
142 // 14 .. pig
143 // 15 .. horse
144 // 20 .. bird
145 // 21 .. owl
146 // 22 .. eagle
147 // 23 .. pigeon
148 // 24 .. duck
149 // 30 .. deer
150 // 31 .. rabbit
151 // 32 .. tarsk (boar)
152 // 33 .. wolf
153 // 34 .. bear
154 // 35 .. wild dog
155////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
156////////// AGENT INTERNAL NEEDS ///////////////////////////////////////////////////////////////////////////////////
157 float happy = 100.0; // Happines 0 .. 100.0 (decrementing)
158 float energy = 100.0; // Energy 0 .. 100.0 (decrementing)
159 float food = 0; // value of food (eaten food)
160 float glucose = 0.0; // value of glucose (turned from food) energy storage
161
162 float blader = 0.0; // Bladder 0 .. 100.0 (incrementing)
163 float anger = 0.0; // MOOD ANGER 0 .. 100.0 (incrementing)
164 float fun = 50.0; // MOOD FUN 0 .. 100.0 (decrementing)
165 float social = 0.0; // SOCIAL 0 .. 100.0 (decrementing)
166 float mischievous = 0.0; // NEED FOR MISCHIEF 0 .. 100.0 (incrementing)
167 float health = 100.0; // HEALTH 0 .. 100.0 (decrementing)
168 float strength = 10.0; // STRENGHT / FORCE - may increase by training
169////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
170 integer needsReportTimeout = 30; // timeout - how offten send needs info to owner HUD (seconds)
171 string AGENT_STATE = "null"; // active agent STATE,
172 // STATES: 00 .. DEAD
173 // 01 .. UPDATING / SYSTEM / FROZEN
174 // 02 .. SLEEP
175 // 03 .. ILL / SICK
176 // 03 .. RESTING
177 // 04 .. LIE ON GROUND (watching)
178 // 05 .. EATING (same for drinking)
179 // 10 .. WALK
180 // WALK_TO_AVATAR
181 // WALK_TO_LOCATION
182 // WALK_TO_OBJECT
183 // WALK_TO_AGENT
184 // WALK_TO_OWNER
185 // WALK_TO_FOOD
186 // WALK_TO_HOME
187 // 12 .. WANDERING
188 // .. FOLLOW
189 // FOLLOW_AVATAR
190 // FOLLOW_AGENT
191 // FOLLOW_FRIEND
192 // FOLLOW_OWNER
193 // .. FLEE
194 // FLEE_FROM_AGENT
195 // FLEE_FROM_ATTACKER
196 // FLEE_FROM_AVATAR
197 // .. APPROACHING
198 // .. JUMP
199 // .. PLAY_WITH
200 // .. PET_BY_AVATAR
201 // .. RUN
202 // .. FLEE_FROM
203 // .. PEE
204 // .. SNIFFING
205 // .. LICKING
206 // .. BARK
207 // .. WATCHING
208 // .. ATTACKING
209 // .. SWIM
210 // .. HEADING_HOME
211 // .. SEEKING_MATE
212 string AGENT_PREVIOUS_STATE; // previous agent STATE
213 list listAgentStates; // Stack of previous + current Agent states (state+duration+time)
214 list listAgentTasks; // Stack of ACTIVE TASKS (task+priority+gain+duration+done(%)+timeCreated)
215 list listAgentLocation; // Stack of Locations (locationType + posXYZ + Gain(needs), lastVisit,TTL)
216 list listAgentToucher; // Stack of previous touchers (toucher+face+velocity+time)
217 integer AGENT_ACTIVITY_VALUE= 3; // Level how active can be agent 0 .. dead/sleep, 5 .. max, default 3
218 string AGENT_TITLE = "";
219 vector AGENT_TITLE_COLOR = <0,1,0>; // Color of agent TITLE
220 float AGENT_TITLE_ALPHA = 1.0; // Transparency for TITLE (0..invisible, 1..max)
221 integer IS_TIMER_ACTIVE = 0;
222////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
223////////// POSITION / HOME - DECLARATION VARIABLES ///////////////////////////////////////////////////////////////
224 string command = ""; // active command
225 string msg = ""; // raw received message
226 string commandCurrent = ""; // current active command - during running else empty
227 string commandLast = ""; // last received Command
228 integer isCommandRun = FALSE; // flag if running command
229 integer isCommandSend = FALSE; // flag if command was sent
230 integer isBroadcast = FALSE; // agent broadcasting
231 integer isBroadcastRequest = FALSE; // agent broadcasting --> request was SENT
232 integer isBreadcastResponse = FALSE; // agent boardcasting --> receieved answer
233 integer timeLastBroadcast = 0; // time of last broadcasting
234////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
235////////// AGENT BREEDING - MATTING ////////////////////////////////////////////////////////////////////////////////
236 integer isMate = 0; // flag - have agent own MATE ?
237 key mateKey; // UUID of Mate Agent
238 integer ageAdult = 4; // FIXME - age when adult (minutes)
239 integer ageOld = 20; // age when is elder
240 integer isPregnant = FALSE; // flag - if IS_PREGNANT
241 integer pregnantDuration = 5; // FIXME - duration of pregnancy (minutes)
242 integer pregnantPause = 10; // pause duration between two pregrancies
243 float pregnantChance = 0.6; // change probrability to get pregnant
244 integer isMateInRange = FALSE; // flag - IF IS MATE IN RANGE
245////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
246 string posRegion = "null"; // current Agent position - region name
247 float posX = 0; // current agent position - X
248 float posY = 0; // current agent position - Y
249 float posZ = 0; // current agent position - Z
250 float direction = 0; // current agent direction (looking at) ° (degress 0-359) 0=north
251 string homeRegion = "null"; // agent home - region name
252 float homeX = 0; // agent home - X
253 float homeY = 0; // agent home - Y
254 float homeZ = 0; // agent home - Z
255 integer isHomeSet = 0; // flag IF home is SET
256 float returnHomeTimeout = -1; // when timeout become zero agent move to Home Location automaticly
257 // -1 = disabled
258////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
259////////// SENSING - PERCEPTION VALUES ///////////////////////////////////////////////////////////////////////////
260 integer SENCE_NEAREST_AVATAR_DISTANCE = 0; //
261 integer SENCE_NEAREST_AVATAR_COUNT = 0;
262 integer SENCE_OWNER_DISTANCE = 0;
263 integer SENCE_NEAREST_AGENT = 0;
264 integer SENCE_NEAREST_OBJECT = 0;
265 integer SENCE_NEAREST_FOOD = 0;
266 integer SENCE_NEAREST_WATER = 0;
267 integer SENCE_NEAREST_HOME = 0;
268
269 integer isFollowAvatar = FALSE; // flag - cmd: follow avatar
270 integer isFleeFromAvatar = FALSE; // flag - cmd: flee from avatar
271 integer isWander = FALSE; // flag - cmd: wandering
272 integer isShowTitle = TRUE; // flag - display title
273 integer isCommentToChat = FALSE; // flag - send (debug) comments to chat (all)
274 integer isCommentToOwner = TRUE; // flag - send (debug) comments to chat (owner only)
275 integer isPermissionPublic = FALSE; // permission to interact - Public
276 integer isPermissionGroup = FALSE; // permission to interact - Group
277 integer isTouchShowTitle = TRUE; // show title on touch for 20 seconds
278 integer isTouchGiveHUD = FALSE; // give Command HUD on touch
279 integer isTouchShowDistance = TRUE; // show particles - max distance to walk (area)
280 integer isSayTouchInfo = TRUE; // say touch info to chat
281 integer isParticlesObjects = TRUE; // show particles when communicate with Interactive Objects
282 integer isParticlesAgents = TRUE; // show particles when communicate with other Agents
283 integer isParticlesServer = TRUE; // show particles when communicate with SERVER (HTTP)
284 integer isParticlesOwnerHUD = TRUE; // show particles when communicate with Owner HUD
285 integer isParticlesRaycast = 0;
286 integer isConsumeFood = TRUE; // consume food
287
288 integer isPathfinding = FALSE; // Pathfinding active
289 integer isAgeDie = TRUE; // die when too old (age >= ageMax)
290 integer isAging = TRUE; // aging
291////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
292////////// PHYSICAL REPRESENTATION - In Virtual World //////////////////////////////////////////////////////////////
293 //float AGENT_SIZE = 1.0; //
294 float AGENT_SIZE_CHILD = 0.3;
295 float AGENT_SIZE_ADULT = 1.0;
296 float AGENT_SIZE_OLD = 0.9;
297 float SIZE_VARIABLITITY = 15.0; // possible variablitity of agent size (in percent %)
298 vector AGENT_COLOR = <1,1,1>;
299 float AGENT_GHOST = 0.0; // Agent transparency
300 float AGENT_GLOW = 0.0; // Agent glow
301 string AGENT_TEXTURE = ""; // agent texture - NAME or UUID
302 string AGENT_EGG = ""; // agent EGG - for birth internal object ( NAME or UUID )
303
304////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
305////////// TIMER VARIABLES ///////////////////////////////////////////////////////////////////////////////////////
306 integer TIMER_MODE = 0; // 0 .. OFF, 1 .. ACTIVE, 2 .. REST, 3 .. SLEEP
307 integer timerGapActive = 5; // timer interval - active (in seconds)
308 integer timerGapRest = 10; // timer interval - rest (in seconds)
309 integer timerGapSleep = 30; // timer interval - sleep (in seconds)
310 integer timerActiveDuration = 60*2; // duration active timer mode (in seconds)
311 integer timerRestDuration = 60*4; // duration rest timer mode (in seconds)
312 integer timerSleepDuration = 60*10;// duration sleep timer mode (in seconds)
313 integer timerCountActive = 0; // counter when timer is in - Active Mode
314 integer timerCountRest = 0; // counter when timer is in - Rest Mode
315 integer timerCountSleep = 0; // counter when timer is in - Sleep Mode
316 integer timerCountBroadcast = 0; // counter since last agent's broadcasting - agent <--> agent / interactive_objects
317 integer timerCountSendInfoHUD = 0; // counter since last send info to owner's HUD
318 integer timerCountSendINfoServer = 0; // counter since last send info to Server (HTTP)
319 integer timerCountSendInfoOwner = 0;
320 integer timerCountAging = 0; // counter for Age - aging interval (when age = age + 1)
321 integer timerCountUpdateNeeds = 0; // counter for updating needs
322 integer timerCountAnimation = 0; // counter for internal animations
323 integer timerCountWaitForReply = 0; // counter how long wait for reply from Agent,Interactive Object, HUD
324 integer COMM_REPLY_TIMEOUT = 20; // timeout for waiting for reply after BROADCAST, ASK, SEND MSG to Interactive Objects
325 integer COMM_SERVER_TIMEOUT = 60*2; // timeout for agent <--> PHP_SERVER
326 integer COMM_MENU_TIMEOUT = 60; // timeout for User Menu
327 integer COMM_COMMAND_TIMEOUT = 20; //
328////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
329 float walk_velocity = 1.2; // velocity WALK (meter per second)
330 float run_velocity = 2.5; // velocity RUN (meters per second)
331 float flee_velocity = 2.6; // velocity FLEE (running from attacker, meters per second)
332 float attack = 10.0; // Attack Level - Force
333 float defence = 8.0; // Defence Level
334 float healthCurrent = health;
335 float fleeDistance = 15; // minimal flee distance
336 float fleeDuration = 6; // minimal flee duration (seconds)
337 float followDuration = 40; // max follow duration (seconds)
338 float energyRecoverRate = 1.2; // energy recover rate
339 float energyConsumeWalk = 1.1; // how much energy cost - walk
340 float energyConsumeRun = 3; // how much energy cost - run
341 float energyConsumePlay = 1.8; // how much energy cost - playing (with toy, agent, avatar)
342 float energyConsumeAttack = 4.3; // how much energy cost attacking/defending (battle)
343////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
344////////// PRIVATE FUNCTIONS /////////////////////////////////////////////////////////////////////////////////////
345
346//====================================================================
347string left(string src, string divider) {
348 integer index = llSubStringIndex( src, divider );
349 if(~index)
350 return llDeleteSubString( src, index, -1);
351 return src;
352}
353
354//====================================================================
355string right(string src, string divider) {
356 integer index = llSubStringIndex( src, divider );
357 if(~index)
358 return llDeleteSubString( src, 0, index + llStringLength(divider) - 1);
359 return src;
360}
361
362
363//====================================================================
364string strReplace(string str, string search, string replace) {
365 return llDumpList2String(llParseStringKeepNulls((str = "") + str, [search], []), replace);
366}
367
368integer random_integer(integer min, integer max){
369 return min + (integer)(llFrand(max - min + 1));
370}
371
372//======================================================================================================================
373//
374//======================================================================================================================
375titleShow(){
376 if((isShowTitle==1)||(isTouchShowTitle==1)){
377 string title = (string)AGENT_NAME + " ";
378 if( AGENT_SEX = 0) title = title + "♂\n";
379 if( AGENT_SEX = 1) title = title + "♀\n";
380 title = title + "Age: " + (string)AGENT_AGE ;
381 if( AGENT_AGE < ageAdult){ title = title + " (child)";}
382 if( AGENT_AGE > ageOld) { title = title + " (elder)";}
383 title = title + "\n";
384 title = title + "Energy: " + (string)energy + " Food:" + (string)food + " Glucose:"+glucose+ "\n";
385 title = title + "Happy: " + (string)happy+ " Fun:" + (string)fun+ " Social:"+social+ "\n";
386 title = title + "Health: " + (string)health+ " Strength:" + (string)strength+ " Blader:"+blader+ "\n";
387 title = title + "Need for Mischief:" + (string)mischievous;
388 if( isMate==1) title = title + " (have Mate)";
389 AGENT_TITLE = TITLE;
390 llSetTitle( title , AGENT_TITLE_COLOR, AGENT_TITLE_ALPHA);
391 }
392
393
394}
395titleHide(){
396 llSetText( "", AGENT_TITLE_COLOR, AGENT_TITLE_ALPHA );
397}
398
399//======================================================================================================================
400//
401//======================================================================================================================
402setSize(float size){
403}
404string agentGetSize(){
405 llRegionSay(CHANNEL_HUD, "REPLY|ID=|SIZE="+(string)position+"|DIRECTION="+(string)vRadBase);
406 return (string)llGetObjectDesc();
407}
408setSizeDefault(){
409
410}
411getPos(){
412 vector position = llGetPos();
413 posX = position.X;
414 posY = position.Y;
415 posZ = position.Z;
416 vector vRadBase = llRot2Euler( llGetRot() );
417 llRegionSay(CHANNEL_HUD, "REPLY|ID=|POSITION="+(string)position+"|DIRECTION="+(string)vRadBase);
418}
419setPos(vector inputPos){
420 llSetPos(inputPos);
421}
422
423////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
424////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
425////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
426
427
428//=====================================================================================================
429// move(steps)
430// move object a number of steps (meters) along its current heading
431// forward is along the positive x axis
432// if the pen is down, create a line segment along the path traveled
433// the line is positioned by its center, which is placed halfway back along the path
434//=====================================================================================================
435move(float steps)
436{
437 vector fwd = llRot2Fwd(llGetRot()) * steps;
438 llSetPos(llGetPos() + fwd);
439 if (penState == TRUE) {
440 if (llGetInventoryType("lineSegment") == INVENTORY_NONE) {
441 llSay(0, "Oops! To draw a line, my inventory needs a lineSegment. You can get one from the Scratch Inventory Box.");
442 } else {
443 integer randomID = llRound(llFrand(99999999));
444 llRezObject("lineSegment", llGetPos()-fwd/2, <0,0,0>, llGetRot(), randomID);
445 llSay(1, (string)randomID + ":set length:"+ (string)llFabs(steps));
446 llSay(1, (string)randomID + ":set color:" + (string)penColor);
447 }
448 }
449}
450
451
452//=====================================================================================================
453// turnRight(float angle)
454// turn angle degrees clockwise around the local z axis
455//=====================================================================================================
456turnRight(float angle)
457{
458 angle *= -1;
459 rotation newRot = llEuler2Rot(<0,0,angle> * DEG_TO_RAD);
460 llSetRot(newRot*llGetRot());
461}
462
463//=====================================================================================================
464// turnLeft(float angle)
465// turn angle degrees counterclockwise around the local z axis
466//=====================================================================================================
467turnLeft(float angle)
468{
469 rotation newRot = llEuler2Rot(<0,0,angle> * DEG_TO_RAD);
470 llSetRot(newRot*llGetRot());
471}
472
473
474//=====================================================================================================
475// up(float steps)
476// move up along the global z axis by steps meters - does not leave a line segment
477//=====================================================================================================
478up(float steps)
479{
480 llSetPos(llGetPos()+<0,0,steps>);
481}
482
483
484//=====================================================================================================
485//down(float steps)
486//move down along the global z axis by steps meters
487//does not leave a line segment
488//=====================================================================================================
489down(float steps)
490{
491 llSetPos(llGetPos()+<0,0,-1*steps>);
492}
493
494//=====================================================================================================
495// turnPitch(float angle)
496// turn angle degrees upward around the local y axis
497//=====================================================================================================
498turnPitch(float angle)
499{
500 angle *= -1;
501 rotation newRot = llEuler2Rot(<0,angle,0> * DEG_TO_RAD);
502 llSetRot(newRot*llGetRot());
503}
504
505//=====================================================================================================
506// float getHeading()
507// return the current heading in the xy plane in degrees
508//=====================================================================================================
509float getHeading() {
510 return llRot2Angle(llGetRot())*RAD_TO_DEG;
511}
512
513
514//=====================================================================================================
515// setHeading(float angle)
516// set the heading in the xy plane in degrees
517//=====================================================================================================
518setHeading(float angle) {
519 vector newVec = <0, 0, angle*DEG_TO_RAD>;
520 rotation newRot = llEuler2Rot(newVec);
521 llSetRot(newRot);
522}
523
524
525//=====================================================================================================
526// turnRoll(float angle)
527// turn angle degrees clockwise around the local x axis
528//=====================================================================================================
529turnRoll(float angle)
530{
531 rotation newRot = llEuler2Rot(<angle,0,0> * DEG_TO_RAD);
532 llSetRot(newRot*llGetRot());
533}
534
535//=====================================================================================================
536pointTowardNearestAv()
537{
538 vector myPos = llGetPos();
539 float xdiff = myPos.x - nearestAvPosition.x;
540 float ydiff = myPos.y - nearestAvPosition.y;
541 float angle = llAtan2(xdiff, ydiff) * RAD_TO_DEG;
542 setHeading(270 - angle);
543}
544
545//=====================================================================================================
546pointTowardOwner()
547{
548 vector myPos = llGetPos();
549 float xdiff = myPos.x - ownerPosition.x;
550 float ydiff = myPos.y - ownerPosition.y;
551 float angle = llAtan2(xdiff, ydiff) * RAD_TO_DEG;
552 setHeading(270 - angle);
553}
554
555
556
557
558////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
559////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
560////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
561
562//=====================================================================================================
563// changeSizeBy(float change)
564// change the size of an object by a percentage of its original size
565//=====================================================================================================
566changeSizeBy(float change)
567{
568 sizePercent += change;
569 vector newScale = originalScale*(sizePercent/100);
570 llSetScale(newScale);
571}
572
573
574
575//=====================================================================================================
576// levelOut()
577// remove the x and y rotation components, so that the object is
578// level with respect to the ground
579//=====================================================================================================
580levelOut()
581{
582 vector myVec = llRot2Euler(llGetRot());
583 vector newVec = <0, 0, myVec.z>;
584 rotation newRot = llEuler2Rot(newVec);
585 llSetRot(newRot);
586}
587
588
589//=====================================================================================================
590// goHome()
591// move the object back to its home position
592// home is set the the position of the object when it is created,
593// and can be set to a new position using setHomeHere()
594//=====================================================================================================
595goHome()
596{
597 llSetPos(home);
598 //levelOut();
599}
600
601//=====================================================================================================
602// setHomeHere()
603// set the home position to the current position
604//=====================================================================================================
605setHomeHere()
606{
607 home = llGetPos();
608}
609
610
611
612////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
613////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
614////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
615
616//========================================================================================================
617//
618//========================================================================================================
619update_needs(){
620
621}
622
623//========================================================================================================
624//
625//========================================================================================================
626listenHUD(integer channel, string name, key id, string msg){
627 if(channel == CHANNEL_HUD){
628 // decode msg from hud
629 list items = llParseString2List(msg, ["|"], []);
630 if(llGetListLength(testList)>1){
631
632 }
633 msg = llToUpper(msg);
634 msg =
635 msgLeft = left("Colour=Brown", "="); //value == "Colour"
636 msgRight = right("Colour=Brown", "="); //value == "Brown"
637 msgLeft = llToUpper( msgLeft );
638 debug("msg: " + msgLeft + " = "+ msgRight);
639 // IF TREE CMDS
640 //---------------------------------------------------
641 if( msgLeft == "MOVE"){
642
643 move((float)msgRight)
644 }
645 //---------------------------------------------------
646 if( msgLeft == "TURNLEFT"){
647 turnRight((float) msgRight);
648 }
649 //
650 if( msgLeft == "TURNRIGHT"){
651 turnLeft((float) msgRight);
652 }
653 //---------------------------------------------------
654 if( msgLeft == "UP"){
655 up((float) msgRight);
656 }
657 //---------------------------------------------------
658 if( msgLeft == "DOWN"){
659 down((float) msgRight);
660 }
661 //---------------------------------------------------
662 if( msgLeft == "ROLL"){
663 }
664 //---------------------------------------------------
665 if( msgLeft == "PITCH"){
666 }
667 //---------------------------------------------------
668 if( msgLeft == "GO_HOME"){
669 }
670 //---------------------------------------------------
671 if( msgLeft == "SET_HOME"){
672 positionHome = llGetPos();
673 homeX = positionHome.x;
674 homeY = positionHome.y;
675 homeZ = positionHome.z;
676 homeRegion = llGetRegionName();
677
678 }
679 //---------------------------------------------------
680 if( msgLeft == "POINT_TOWARD_NEAREST_AVATAR"){
681
682 }
683 //---------------------------------------------------
684 if( msgLeft == "POINT_TOWARD_OWNER"){
685 pointTowardOwner();
686 }
687 //---------------------------------------------------
688 if( msgLeft == "POINT_IN_DIRECTION"){
689 }
690 //---------------------------------------------------
691 if( msgLeft == "SAY"){
692 }
693 //---------------------------------------------------
694 if( msgLeft == "SHOW_TITLE"){
695 }
696 //---------------------------------------------------
697 if( msgLeft == "HIDE_TITLE"){
698 }
699 //---------------------------------------------------
700 if( msgLeft == "SAY"){
701 }
702 //---------------------------------------------------
703 if( msgLeft == "SET_COLOR"){
704 }
705 //---------------------------------------------------
706 if( msgLeft == "SET_ALPHA"){
707 }
708 //---------------------------------------------------
709 if( msgLeft == "SET_GLOW"){
710 }
711 //---------------------------------------------------
712 if( msgLeft == "SET_SIZE"){
713 }
714 //---------------------------------------------------
715 if( msgLeft == "GET_SIZE"){
716 }
717 //---------------------------------------------------
718 if( msgLeft == "PLAY_SOUND"){
719 }
720 //---------------------------------------------------
721 if( msgLeft == "GET_DISTANCE_NEAREST_AVATAR"){
722 }
723 //---------------------------------------------------
724 if( msgLeft == "GET_DISTANCE_OWNER"){
725 }
726 //---------------------------------------------------
727 if( msgLeft == "GET_POS"){
728 }
729 //---------------------------------------------------
730 if( msgLeft == "SET_POS"){
731 }
732 //---------------------------------------------------
733 if( msgLeft == "GET_NEAREST_AVATAR_COUNT"){
734 }
735 //---------------------------------------------------
736 if( msgLeft == "GET_DISTANCE_NEAREST_OBJECT"){
737 }
738 //---------------------------------------------------
739 if( msgLeft == "GET_TOUCHER"){
740 }
741 //---------------------------------------------------
742 if( msgLeft == "GET_TEXTURE"){
743 }
744 //---------------------------------------------------
745 if( msgLeft == "SET_TEXTURE"){
746 }
747 //---------------------------------------------------
748 if( msgLeft == "SHOW_PARTICLES_OBJECTS"){
749 }
750 if( msgLeft == "SHOW_PARTICLES_AGENTS"){
751 }
752 if( msgLeft == "SHOW_PARTICLES_SERVER"){
753 }
754 if( msgLeft == "SHOW_PARTICLES_OWNERHUD"){
755 }
756 }
757}
758
759//========================================================================================================
760//
761//========================================================================================================
762listenWORLD(integer channel, string name, key id, string msg)
763{
764 ;
765}
766
767
768
769
770////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
771////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
772////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
773
774
775
776//========================================================================================================
777// INIT ALL VARIABLES AND START LISTENERS -
778//========================================================================================================
779initAll() {
780 // Init internal variables ---------------------------------------
781 ownerKey = llGetOwner();
782 ownerName = llGetDisplayName(ownerKey);
783 // Init AGENT Variables ------------------------------------------
784 AGENT_ID = random_integer(10000,99999);
785 AGENT_NAME = "Noname";
786 AGENT_KEY = llGetKey();
787 AGENT_AGE = 0;
788 AGENT_SIZE_VECTOR = llGetScale();
789 currentSize = AGENT_SIZE_VECTOR;
790 AGENT_COLOR = llGetColor(ALL_SIDES);
791 AGENT_GHOST = llGetAlpha(ALL_SIDES);
792 AGENT_GLOW = llGetTexture(ALL_SIDES);
793 AGENT_TEXTURE = llGetTexture(ALL_SIDES);
794 // Init Listeners -----------------------------------------------
795 handleListenHud = llListen(CHANNEL_HUD, "", ownerKey, "");
796 handleListenChat = llListen(CHANNEL_CHAT, "", NULL_KEY, "");
797 handleListenAgents = llListen(CHANNEL_AGENTS, "", NULL_KEY, "");
798 // Init NEEDS ---------------------------------------------------
799 isMate = 0;
800 isConsumeFood = 0;
801 isPathfinding = 0;
802 isAgeDie = 0;
803 isAging = 0;
804 isPermissionPublic = 1;
805 isPermissionGroup = 1;
806
807 // Init APPEREANCE ----------------------------------------------
808 posRegion = llGetRegionName();
809 position = llGetPos();
810 posX = position.x;
811 posY = position.Y;
812 posZ = position.Z;
813 PosRotation = llGetRot();
814 if(isShowTitle==1){
815 titleShow();
816 }else{
817 titleHide();
818 }
819
820 // Init TIMER ---------------------------------------------------
821 TIMER_MODE = 0;
822 timerCountActive = 0;
823 timerCountRest = 0;
824 timerCountSleep = 0;
825 timerCountBroadcast = 0;
826 timerCountSendInfoHUD = 0;
827
828 timerCountAging = 0;
829 timerCountWaitForReply = 0;
830
831
832}
833
834//======================================================================================================================
835debug(string input){
836 if(isDebug==1){
837 llOwnerSay(input);
838 }
839}
840
841////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
842////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
843///////////////////////////////// START OF REAL WORLD - LSL EVENTS ////////////////////////////////////////////////////
844////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
845default
846{
847 //============================================================================
848 on_rez(integer param)
849 {
850 initAll();
851 }
852
853
854 //============================================================================
855 state_entry()
856 {
857 initAll();
858
859 }
860
861 //============================================================================
862 touch_start(integer total_number)
863 {
864 // Send agent ID to user HUD ----------------------
865 llRegionSay(CHANNEL_HUD, "ID="+(string)AGENT_ID+"|NAME="+AGENT_NAME+"|KEY="+(string)AGENT_KEY);
866 debug("ID="+(string)AGENT_ID+"|NAME="+AGENT_NAME+"|KEY="+(string)AGENT_KEY);
867
868 // IF flag title --> show TITLE -------------------
869 if( isTouchShowTitle ==1 ){
870 }
871
872 // call sensor - once -----------------------------
873 llSensor( "", NULL_KEY, ( AGENT | PASSIVE | ACTIVE ), 25.0, PI );
874
875
876 }
877
878 //============================================================================
879 listen(integer channel, string name, key id, string msg)
880 {
881 // CHANNEL_HUD ------------------------------------
882 if(channel == CHANNEL_HUD){
883 listenHUD(channel, name, id, msg);
884 }
885
886 // CHANNEL_AGENTS ---------------------------------
887 if(channel == CHANNEL_AGENTS){
888
889 }
890 // CHANNEL_CHAT -----------------------------------
891
892 }
893
894
895
896 //============================================================================
897 timer()
898 {
899
900 // --------------------------------------------------------
901 // TEST ACTIVE MODE DURATION ------------------------------
902 if(( timerCountActive < timerActiveDuration )&&(TIMER_MODE==1)){
903 timerCountActive = timerCountActive + 1;
904 // if timer count = duration for active mod --> set rest mode
905 if(timerCountActive=timerActiveDuration){
906 llSetTimerEvent(timerGapRest);
907 TIMER_MODE = 2;
908 timerCountRest = 0;
909 timerCountRest = 0;
910 }
911 }
912 // TEST REST MODE DURATION ------------------------------
913 if(() timerCountRest < timerRestDuration )&&(TIMER_MODE==2)){
914 timerCountRest = timerCountRest + 1;
915 if(timerCountRest==timerRestDuration){
916 llSetTimerEvent(timerGapSleep);
917 TIMER_MODE = 3;
918 timerCountRest = 0;
919 timerCountSleep = 0;
920 }
921 }
922 // other counters ----------------------------------------
923 if( TIMER_MODE == 1) { // ACTIVE - 5s
924 timerCountUpdateNeeds = timerCountUpdateNeeds + 1;
925 timerCountBroadcast = timerCountBroadcast + 1;
926 timerCountAging = timerCountAging + 5;
927 }
928 if( TIMER_MODE == 2) { // REST - 10s
929 timerCountUpdateNeeds = timerCountUpdateNeeds + 2;
930 timerCountBroadcast = timerCountBroadcast + 2;
931 timerCountAging = timerCountAging + 10;
932 }
933 if( TIMER_MODE == 3) { // SLEEP - 30s
934 timerCountUpdateNeeds = timerCountUpdateNeeds + 6;
935 timerCountBroadcast = timerCountBroadcast + 6;
936 timerCountAging = timerCountAging + 30;
937 }
938 // Timeout for Comm reply
939 if(timerCountWaitForReply>0){
940 timerCountWaitForReply = timerCountWaitForReply -1;
941 }
942
943 }
944
945
946
947
948 //============================================================================
949 // ANSWER OF HTTP RESPONSE
950 //============================================================================
951 http_response(key request_id, integer status, list metadata, string body)
952 {
953 if(http_request_id == request_id)
954 {
955 log("status: " + (string) status);
956 if (status == 400)
957 log("Bad Request");
958 if (status == 401)
959 log("Unauthorized");
960 if (status == 403)
961 log("Forbidden");
962 if (status == 404)
963 log("Page not found");
964 else if (status == 500)
965 log("Service not available");
966 else if (status >= 300)
967 log("Unknown error: " + (string) status);
968 else
969 display_result(body);
970 }
971 }
972}
973
974////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
975////////////////////////////// END OF KNOWN WOLRD //////////////////////////////////////////////////////////////
976////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
977
978
979// ---------------------------------------------------------------------------------------------------------------
980// Redistribution and use in source and binary forms, with or without modification,
981// are permitted provided that the following conditions are met:
982//
983// * Redistributions of source code must retain the above copyright notice,
984// this list of conditions and the following disclaimer.
985// * Redistributions in binary form must reproduce the above copyright notice,
986// this list of conditions and the following disclaimer in the documentation
987// and/or other materials provided with the distribution.
988// * The names of its contributors may not be used to endorse or promote products
989// derived from this software without specific prior written permission.
990//
991// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
992// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
993// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
994// IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
995// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
996// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
997// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
998// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
999// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
1000// OF SUCH DAMAGE.
1001// ---------------------------------------------------------------------------------------------------------------