xs_movement_globe plugin.lsl 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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. llSetRot(rot);
  169. llSleep(.1);
  170. rot = llGetRot() * llRotBetween(<0.0 ,0.0 ,1.0 > * llGetRot(), home_location - llGetPos());
  171. llSetRot(rot);
  172. }
  173. integer sleeping()
  174. {
  175. vector sun = llGetSunDirection();
  176. if (!sleep_disabled) {
  177. if (sun.z < 0) {
  178. if (sleep_last_check == 0) {
  179. // close eyes
  180. llMessageLinked(LINK_SET, LINK_SLEEPING, "", "");
  181. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_SLEEP, "");
  182. }
  183. sleep_last_check = 1;
  184. } else {
  185. if (sleep_last_check == 1) {
  186. // open eyes
  187. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  188. llMessageLinked(LINK_SET, LINK_UNSLEEPING, "", "");
  189. }
  190. sleep_last_check = 0;
  191. }
  192. return sleep_last_check;
  193. } else {
  194. if (sleep_last_check == 1) {
  195. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  196. llMessageLinked(LINK_SET, LINK_UNSLEEPING, "", "");
  197. sleep_last_check = 0;
  198. }
  199. return 0;
  200. }
  201. }
  202. default
  203. {
  204. link_message(integer sender, integer num, string str, key id)
  205. {
  206. if (num == LINK_AGE_START) {
  207. state running;
  208. }
  209. }
  210. }
  211. state running
  212. {
  213. state_entry()
  214. {
  215. gOrient = ZERO_ROTATION;
  216. home_location = <0,0,0>;
  217. roam_distance = 0;
  218. destination = <0,0,0>;
  219. age = 0;
  220. sleep_last_check = 0;
  221. sound_on = 1;
  222. }
  223. timer()
  224. {
  225. if (!sleeping())
  226. {
  227. if (sound_on) {
  228. llMessageLinked(LINK_SET, LINK_SOUND, "", "");
  229. }
  230. sound_on = !sound_on;
  231. if (rest > 0) {
  232. // llSetText((string) rest,<1,0,0>,1);
  233. rest--;
  234. return;
  235. }
  236. if (llVecDist( destination, llGetPos()) <= tolerance || destination == <0,0,0>)
  237. {
  238. // if at food_destination send 900 msg
  239. if (food_dest > 0) {
  240. llMessageLinked(LINK_SET, LINK_FOOD_CONSUME, (string)food_dest, llList2Key(food_bowl_keys, 0));
  241. }
  242. if (sex_dest > 0) {
  243. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  244. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WAVE, "");
  245. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  246. llMessageLinked(LINK_SET, LINK_RQST_BREED, "", "");
  247. }
  248. // pick a new destination
  249. sex_dest = 0;
  250. food_dest = 0;
  251. }
  252. integer walkLength = llGetListLength(gSilly_walks);
  253. if ( walkLength > 0)
  254. {
  255. vector pos = llList2Vector(gSilly_walks,0);
  256. rotation orient = llList2Rot(gSilly_walks,1);
  257. gCounter++;
  258. face_target(pos);
  259. llSetPos(pos);
  260. //llSetRot(orient);
  261. gSilly_walks = llDeleteSubList(gSilly_walks,0,1); // we have walked in those shoes
  262. }
  263. else
  264. {
  265. GetNewPos();
  266. rest = (integer)llFrand(12.0); // 1 minute rest
  267. //llOwnerSay("resting for " + (string) rest);
  268. }
  269. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  270. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WALKL, "");
  271. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WALKR, "");
  272. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  273. }
  274. }
  275. link_message(integer sender, integer num, string str, key id)
  276. {
  277. if (num == LINK_HUNGRY) {
  278. if (sex_dest == 0) {
  279. // move to food bowl, then send 900
  280. if (llGetListLength(food_bowl_keys) > 0) {
  281. if (roam_distance == 0 || home_location == <0,0,0>) {
  282. 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.");
  283. llMessageLinked(LINK_SET, LINK_FOOD_CONSUME, str, llList2Key(food_bowl_keys, 0));
  284. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  285. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WAVE, "");
  286. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  287. } else {
  288. // find nearest food bowl
  289. integer i;
  290. destination = (vector)llList2String(food_bowls, 0);
  291. for (i=1;i<llGetListLength(food_bowls);i++) {
  292. if (llVecDist(destination, llGetPos()) > llVecDist((vector)llList2String(food_bowls, i), llGetPos())) {
  293. destination = (vector)llList2String(food_bowls, i);
  294. }
  295. }
  296. destination.z = home_location.z + zoffset;
  297. // set destination,
  298. // face it
  299. face_target(destination);
  300. food_dest = (integer)str;
  301. rest = 0;
  302. //llMessageLinked(LINK_SET, LINK_FOOD_CONSUME, str, llList2Key(food_bowl_keys, 0));
  303. }
  304. } else {
  305. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  306. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WAVE, "");
  307. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  308. llOwnerSay("I'm hungry, but I can't seem to find any food bowls at present.");
  309. }
  310. }
  311. } else
  312. if (num == LINK_SET_HOME) {
  313. list values = llParseString2List(str, ["^"], []);
  314. home_location = (vector)llList2String(values, 0);
  315. roam_distance = llList2Float(values, 1);
  316. vector current_loc = llGetPos();
  317. food_bowls = [];
  318. food_bowl_keys = [];
  319. food_bowl_time = [];
  320. destination = <0,0,0>;
  321. food_dest = 0;
  322. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  323. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WAVE, "");
  324. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  325. GetNewPos();
  326. llSetTimerEvent(2.0);
  327. llOwnerSay("Homed");
  328. } else
  329. if (num == LINK_MOVER) {
  330. if (rest < (integer)str) {
  331. rest = (integer)str;
  332. }
  333. } else
  334. if (num == LINK_FOODIE_CLR) {
  335. food_bowls = [];
  336. food_bowl_keys = [];
  337. food_bowl_time = [];
  338. } else
  339. if (num == LINK_FOODIE) {
  340. vector food_loc = (vector)str;
  341. if (llVecDist(home_location, food_loc) <= roam_distance && llFabs(llFabs(home_location.z) - llFabs(food_loc.z)) < 2) {
  342. if(llListFindList(food_bowls, (list)str) == -1) {
  343. integer id_pos = llListFindList(food_bowl_keys, (list)id);
  344. if (id_pos == -1) {
  345. food_bowls += str;
  346. food_bowl_keys += id;
  347. food_bowl_time += llGetUnixTime();
  348. } else {
  349. food_bowls = llListReplaceList(food_bowls, [str], id_pos, id_pos);
  350. food_bowl_time = llListReplaceList(food_bowl_time, [llGetUnixTime()], id_pos, id_pos);
  351. }
  352. }
  353. integer iter;
  354. iter = 0;
  355. while(iter<llGetListLength(food_bowls)) {
  356. if (llGetUnixTime() - llList2Integer(food_bowl_time, iter) > 3600) {//3600
  357. food_bowls = llDeleteSubList(food_bowls, iter, iter);
  358. food_bowl_keys = llDeleteSubList(food_bowl_keys, iter, iter);
  359. food_bowl_time = llDeleteSubList(food_bowl_time, iter, iter);
  360. } else {
  361. iter++;
  362. }
  363. }
  364. if (llGetListLength(food_bowls) > 0) {
  365. llMessageLinked(LINK_SET, LINK_TIMER, "", "");
  366. }
  367. }
  368. } else
  369. if (num == LINK_FEMALE_LOCATION) {
  370. destination = (vector)str;
  371. face_target(destination);
  372. rest = 0;
  373. food_dest = 0;
  374. sex_dest = 1;
  375. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  376. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_WAVE, "");
  377. llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  378. } else
  379. if (num == LINK_MAGE) {
  380. integer heightm;
  381. age += (integer)str;
  382. heightm = age;
  383. if (heightm > MaxAge)
  384. heightm = MaxAge;
  385. float new_scale = (GROWTH_AMOUNT * heightm) + 1.0;
  386. float legsz = LegLength * new_scale;
  387. float legso = LegOffset * new_scale;
  388. zoffset = 0 ;// no offset
  389. } else
  390. if (num == LINK_SLEEP) {
  391. sleep_disabled = (integer)str;
  392. }
  393. }
  394. }