xs_movement.lsl 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. // xs_movement ( for walking on a globe )
  2. // this replaces xs_movement
  3. // Version 0.32 12-03-2011
  4. // added ENCRYPT global variable
  5. /////////////////////////////////////////////////////////////////////
  6. // This code is licensed as Creative Commons Attribution/NonCommercial/Share Alike
  7. // See http://creativecommons.org/licenses/by-nc-sa/3.0/
  8. // Noncommercial -- You may not use this work for commercial purposes
  9. // If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
  10. // This means that you cannot sell this code but you may share this code.
  11. // You must attribute authorship to me and leave this notice intact.
  12. //
  13. // Exception: I am allowing this script to be sold inside an original build.
  14. // You are not selling the script, you are selling the build.
  15. // Ferd Frederix
  16. // Based on code from Xundra Snowpaw
  17. // New BSD License: http://www.opensource.org/licenses/bsd-license.php
  18. // Copyright (c) 2010, Xundra Snowpaw
  19. // All rights reserved.
  20. //
  21. // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  22. //* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  23. //* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
  24. // in the documentationand/or other materials provided with the distribution.
  25. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  26. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
  27. // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  29. // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  30. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ////////////////////////////////////////////////////////////////////
  32. ///////////////////////////////////////////////
  33. // COPY FROM GLOBAL CONSTANTS FILE LOCATED IN Debug Folder
  34. // INCLUDE THESE IN ALL SCRIPTS //
  35. // XS_pet constants and names
  36. ///// GLOBAL CONSTANTS extracted from original source //////
  37. //
  38. // if you change any of these constants, change it everywhere and in a list in XS_Debug so it can print them
  39. //
  40. float VERSION = 0.28;
  41. integer ENCRYPT = FALSE; // set to TRUE to encrypt all data, Opensim prefers FALSE
  42. key YOUR_UUID = ""; // if you add a UUID for your avatar here, you can change it later
  43. // and other alts or friends can edit and make these pets
  44. // If you leave it blank, only the creator can work on them
  45. string Animal = "Troubot"; // was 'Quail', must be the name of your animal
  46. string Egg = "Nut and Bolt"; // was 'XS Egg', must be the name of your egg
  47. string Crate = "Transport UFO"; // was XS-Cryocrate
  48. string HomeObject = "Home Flag"; // was "XS Home Object
  49. string SECRET_PASSWORD = "top secret robot"; // must use one unique to any animal
  50. integer SECRET_NUMBER = 99999; // any number thats a secret
  51. integer MaxAge = 7; // can get prggers in 7 days
  52. integer UNITS_OF_FOOD = 168; // food bowl food
  53. float secs_to_grow = 86400; // grow daily = 86400
  54. // global listeners
  55. integer FOOD_CHANNEL = -999191;
  56. integer ANIMAL_CHANNEL = -999192;
  57. integer EGG_CHANNEL = -999193;
  58. integer HOME_CHANNEL = -999194;
  59. integer BOX_CHANNEL = -999195;
  60. integer ACC_CHANNEL = -999196;
  61. integer UPDATE_CHANNEL = -999197;
  62. integer API_CHANNEL = -999198;
  63. // global prim animation linkmessages on channel 1
  64. // these are the prim animations played for each type of possible animation
  65. string ANI_STAND = "stand"; // default standing animation
  66. string ANI_WALKL = "left"; // triggers Left foot and righrt arm walk animation
  67. string ANI_WALKR = "right"; // triggers Right foot and left arm walk animation
  68. string ANI_SLEEP = "sleep"; // Sleeping
  69. string ANI_WAVE = "wave"; // Calling for sex, needs help with food, etc.
  70. // global link messages to control the animal
  71. integer LINK_AGE_START = 800; // when quail is rezzed and secret_number, is sent by brain to breeder, eater and informatic get booted up
  72. integer LINK_FOOD_CONSUME = 900; // from movement to brain when close to food, brain then consumes a random amount up to 10000
  73. integer LINK_FOODMINUS = 901; // xs_brain receives FOOD_CONSUME, decrement hunger (eat)
  74. integer LINK_HUNGRY = 903; // sent by eater (string)hunger_amount, checks each hour
  75. integer LINK_HAMOUNT = 904; // hunger_amount = (integer)str,m updates the hunger amount in scripts
  76. integer LINK_SET_HOME = 910; // loc ^ dist
  77. integer LINK_MOVER = 911; // tell mover to rest for str seconds
  78. integer LINK_FOODIE_CLR = 920; // clear all food_bowl_keys and contents
  79. integer LINK_FOODIE = 921; // send FOOD_LOCATION coordinates to movement
  80. integer LINK_COLOR1 = 930; // colour1
  81. integer LINK_COLOR2 = 931; // colour2
  82. integer LINK_SEX = 932; // sex
  83. integer LINK_SHINE = 933; // shine
  84. integer LINK_GLOW = 934; // glow
  85. integer LINK_GEN = 935; // generation
  86. integer LINK_RESET_SIZE = 936; // reset size to 1
  87. integer LINK_MAGE = 940; // xs_brain sends, xs_ager consumes, adds str to age, if older than 7 days, will grow the animal
  88. integer LINK_DAYTIME = 941; // xs_ager consumes, starts a timer of 86,400 seconds in xs_ager
  89. integer LINK_GET_AGE = 942; // get age from xs_ager and sent it on channel 943
  90. integer LINK_PUT_AGE = 943; // print age from xs_ager
  91. integer LINK_PACKAGE = 950; // look for a cryo_crate
  92. integer LINK_SEEK_FEMALE = 960; // MALE_BREED_CALL
  93. integer LINK_MALE_BREED_CALL = 961; // triggered by LINK_SEEK_FEMALE
  94. integer LINK_SIGNAL_ELIGIBLE = 962; // sent by female when hears LINK_MALE_BREED_CALL
  95. integer LINK_FEMALE_ELIGIBLE = 963; // sent when it hears in chat FEMALE_ELIGIBLE
  96. integer LINK_CALL_MALE = 964; // if LINK_FEMALE_ELIGIBLE && looking_for_female
  97. integer LINK_MALE_ON_THE_WAY = 965; // triggered by LINK_CALL_MALE
  98. integer LINK_FEMALE_LOCATION = 966; // female location, sends coordinates of a female
  99. integer LINK_RQST_BREED = 967; // sent when close enough to male/female
  100. integer LINK_CALL_MALE_INFO = 968; // sent by xs_breeding, this line of code was in error in v.24 of xs_breeding see line 557 and 636 of xs_brain which make calls and also xs_breeding which receives LINK_MALE_INFO.
  101. integer LINK_MALE_INFO = 969;
  102. integer LINK_LAY_EGG = 970; // llRezObject("XS Egg"
  103. integer LINK_BREED_FAIL = 971; // key = father, failed, timed out
  104. integer LINK_PREGNANT = 972; // chick is preggers
  105. integer LINK_SOUND_OFF= 974; // sound is off
  106. integer LINK_SOUND_ON= 973; // sound is on
  107. integer LINK_SLEEPING = 990; // close eyes
  108. integer LINK_UNSLEEPING = 991; // open eyes
  109. integer LINK_SOUND = 1001; // plays a sound if enabled
  110. integer LINK_SPECIAL = 1010; // xs_special, is str = "Normal", removes script
  111. integer LINK_PREGNANCY_TIME = 5000; // in seconds as str
  112. integer LINK_SLEEP = 7999; // disable sleep by parameter
  113. integer LINK_TIMER = 8000; // scan for food bowl about every 1800 seconds
  114. integer LINK_DIE = 9999; // death
  115. ///////// end global Link constants ////////
  116. ///////////// END OF COPIED CODE ////////////
  117. float GROWTH_AMOUNT = 0.10;
  118. vector home_location;
  119. float roam_distance;
  120. list food_bowls;
  121. list food_bowl_keys;
  122. list food_bowl_time;
  123. vector destination;
  124. integer sex_dest = 0;
  125. integer food_dest = 0;
  126. float tolerance = 0.15;
  127. float increment = 0.1;
  128. integer rest;
  129. integer age;
  130. float zoffset;
  131. integer sleep_last_check ;
  132. integer sound_on;
  133. integer sleep_disabled;
  134. //new mover on a sphere
  135. float RADIUS = 1.0;
  136. rotation gOrient;
  137. list gSilly_walks;
  138. integer gCounter;
  139. GetNewPos()
  140. {
  141. // start over and calc a new walk
  142. gSilly_walks = [];
  143. float x = llFrand(5) + 5;
  144. float y = llFrand(5) + 5;
  145. float z = llFrand(5) + 5;
  146. if (llFrand(2) > 1)
  147. x = 1-x;
  148. if (llFrand(2) > 1)
  149. y = 1-z;
  150. if (llFrand(2) > 1)
  151. z = 1-z;
  152. rotation delta = llEuler2Rot(<x,y,z> * DEG_TO_RAD);
  153. integer STEPS = llCeil( llFrand(10)) + 1;
  154. integer i;
  155. for (i = 0; i < STEPS; i++)
  156. {
  157. vector unitpos = llRot2Fwd( gOrient );
  158. vector pos = home_location + unitpos * RADIUS;
  159. gSilly_walks += pos;
  160. gSilly_walks += gOrient;
  161. gOrient = gOrient * delta;
  162. }
  163. }
  164. face_target(vector lookat) {
  165. rotation rot = llGetRot() * llRotBetween(<1.0 ,0.0 ,0.0 > * llGetRot(), lookat - llGetPos());
  166. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WALKL, "");
  167. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WALKR, "");
  168. // vector nine = <180,0,0> * DEG_TO_RAD;
  169. // rotation new = llEuler2Rot(nine);
  170. llSetRot(rot);
  171. llSleep(.1);
  172. rot = llGetRot() * llRotBetween(<0.0 ,0.0 ,1.0 > * llGetRot(), home_location - llGetPos());
  173. llSetRot(rot);
  174. }
  175. integer sleeping()
  176. {
  177. vector sun = llGetSunDirection();
  178. if (!sleep_disabled) {
  179. if (sun.z < 0) {
  180. if (sleep_last_check == 0) {
  181. // close eyes
  182. llMessageLinked(LINK_SET, LINK_SLEEPING, "", "");
  183. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_SLEEP, "");
  184. }
  185. sleep_last_check = 1;
  186. } else {
  187. if (sleep_last_check == 1) {
  188. // open eyes
  189. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  190. llMessageLinked(LINK_SET, LINK_UNSLEEPING, "", "");
  191. }
  192. sleep_last_check = 0;
  193. }
  194. return sleep_last_check;
  195. } else {
  196. if (sleep_last_check == 1) {
  197. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  198. llMessageLinked(LINK_SET, LINK_UNSLEEPING, "", "");
  199. sleep_last_check = 0;
  200. }
  201. return 0;
  202. }
  203. }
  204. default
  205. {
  206. link_message(integer sender, integer num, string str, key id)
  207. {
  208. //llOwnerSay((string)num + "^" + (string)str);
  209. if (num == LINK_AGE_START) {
  210. state running;
  211. }
  212. }
  213. }
  214. state running
  215. {
  216. state_entry()
  217. {
  218. gOrient = ZERO_ROTATION;
  219. home_location = <0,0,0>;
  220. roam_distance = 0;
  221. destination = <0,0,0>;
  222. age = 0;
  223. sleep_last_check = 0;
  224. sound_on = 1;
  225. }
  226. timer()
  227. {
  228. if (!sleeping())
  229. {
  230. if (sound_on) {
  231. llMessageLinked(LINK_SET, LINK_SOUND, "", "");
  232. }
  233. sound_on = !sound_on;
  234. if (rest > 0) {
  235. // llSetText((string) rest,<1,0,0>,1);
  236. rest--;
  237. return;
  238. }
  239. if (llVecDist( destination, llGetPos()) <= tolerance || destination == <0,0,0>)
  240. {
  241. // if at food_destination send 900 msg
  242. if (food_dest > 0) {
  243. llMessageLinked(LINK_SET, LINK_FOOD_CONSUME, (string)food_dest, llList2Key(food_bowl_keys, 0));
  244. }
  245. if (sex_dest > 0) {
  246. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WAVE, "");
  247. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  248. llMessageLinked(LINK_SET, LINK_RQST_BREED, "", "");
  249. }
  250. // pick a new destination
  251. sex_dest = 0;
  252. food_dest = 0;
  253. }
  254. integer walkLength = llGetListLength(gSilly_walks);
  255. if ( walkLength > 0)
  256. {
  257. vector pos = llList2Vector(gSilly_walks,0);
  258. rotation orient = llList2Rot(gSilly_walks,1);
  259. gCounter++;
  260. face_target(pos);
  261. llSetPos(pos);
  262. //llSetRot(orient);
  263. gSilly_walks = llDeleteSubList(gSilly_walks,0,1); // we have walked in those shoes
  264. }
  265. else
  266. {
  267. GetNewPos();
  268. rest = (integer)llFrand(12.0); // 1 minute rest
  269. //llOwnerSay("resting for " + (string) rest);
  270. }
  271. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WALKL, "");
  272. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WALKR, "");
  273. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  274. }
  275. }
  276. link_message(integer sender, integer num, string str, key id)
  277. {
  278. // llOwnerSay((string)num + "^" + (string)str);
  279. if (num == LINK_HUNGRY) {
  280. if (sex_dest == 0) {
  281. // move to food bowl, then send 900
  282. if (llGetListLength(food_bowl_keys) > 0) {
  283. if (roam_distance == 0 || home_location == <0,0,0>) {
  284. llOwnerSay("I'm hungry, but I'm not homed so I can not move! Attempting to use Jedi Mind Powers to teleport food to my belly.");
  285. llMessageLinked(LINK_SET, LINK_FOOD_CONSUME, str, llList2Key(food_bowl_keys, 0));
  286. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  287. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WAVE, "");
  288. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  289. } else {
  290. // find nearest food bowl
  291. integer i;
  292. destination = (vector)llList2String(food_bowls, 0);
  293. for (i=1;i<llGetListLength(food_bowls);i++) {
  294. if (llVecDist(destination, llGetPos()) > llVecDist((vector)llList2String(food_bowls, i), llGetPos())) {
  295. destination = (vector)llList2String(food_bowls, i);
  296. }
  297. }
  298. destination.z = home_location.z + zoffset;
  299. // set destination,
  300. // face it
  301. face_target(destination);
  302. food_dest = (integer)str;
  303. rest = 0;
  304. //llMessageLinked(LINK_SET, LINK_FOOD_CONSUME, str, llList2Key(food_bowl_keys, 0));
  305. }
  306. } else {
  307. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  308. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WAVE, "");
  309. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  310. llOwnerSay("I'm hungry, but I can't seem to find any food bowls at present.");
  311. }
  312. }
  313. } else
  314. if (num == LINK_SET_HOME) {
  315. list values = llParseString2List(str, ["^"], []);
  316. home_location = (vector)llList2String(values, 0);
  317. RADIUS = llList2Float(values, 1)/2;
  318. //llOwnerSay("location:" + (string) home_location + " " + "distance:" + (string) roam_distance);
  319. vector current_loc = llGetPos();
  320. food_bowls = [];
  321. food_bowl_keys = [];
  322. food_bowl_time = [];
  323. destination = <0,0,0>;
  324. food_dest = 0;
  325. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  326. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WAVE, "");
  327. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  328. GetNewPos();
  329. llSetTimerEvent(4.0);
  330. llOwnerSay("Homed");
  331. } else
  332. if (num == LINK_MOVER) {
  333. if (rest < (integer)str) {
  334. rest = (integer)str;
  335. }
  336. } else
  337. if (num == LINK_FOODIE_CLR) {
  338. food_bowls = [];
  339. food_bowl_keys = [];
  340. food_bowl_time = [];
  341. } else
  342. if (num == LINK_FOODIE) {
  343. vector food_loc = (vector)str;
  344. if (llVecDist(home_location, food_loc) <= roam_distance && llFabs(llFabs(home_location.z) - llFabs(food_loc.z)) < 2) {
  345. if(llListFindList(food_bowls, (list)str) == -1) {
  346. integer id_pos = llListFindList(food_bowl_keys, (list)id);
  347. if (id_pos == -1) {
  348. food_bowls += str;
  349. food_bowl_keys += id;
  350. food_bowl_time += llGetUnixTime();
  351. } else {
  352. food_bowls = llListReplaceList(food_bowls, [str], id_pos, id_pos);
  353. food_bowl_time = llListReplaceList(food_bowl_time, [llGetUnixTime()], id_pos, id_pos);
  354. }
  355. }
  356. integer iter;
  357. iter = 0;
  358. while(iter<llGetListLength(food_bowls)) {
  359. if (llGetUnixTime() - llList2Integer(food_bowl_time, iter) > 3600) {//3600
  360. food_bowls = llDeleteSubList(food_bowls, iter, iter);
  361. food_bowl_keys = llDeleteSubList(food_bowl_keys, iter, iter);
  362. food_bowl_time = llDeleteSubList(food_bowl_time, iter, iter);
  363. } else {
  364. iter++;
  365. }
  366. }
  367. if (llGetListLength(food_bowls) > 0) {
  368. llMessageLinked(LINK_SET, LINK_TIMER, "", "");
  369. }
  370. }
  371. } else
  372. if (num == LINK_FEMALE_LOCATION) {
  373. destination = (vector)str;
  374. face_target(destination);
  375. rest = 0;
  376. food_dest = 0;
  377. sex_dest = 1;
  378. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  379. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WAVE, "");
  380. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  381. } else
  382. if (num == LINK_MAGE) {
  383. integer heightm;
  384. age += (integer)str;
  385. heightm = age;
  386. if (heightm > MaxAge)
  387. heightm = MaxAge;
  388. float new_scale = (GROWTH_AMOUNT * heightm) + 1.0;
  389. float legsz = LegLength * new_scale;
  390. float legso = LegOffset * new_scale;
  391. zoffset = 0 ;// no offset
  392. } else
  393. if (num == LINK_SLEEP) {
  394. sleep_disabled = (integer)str;
  395. }
  396. }
  397. }