xs_breeding.lsl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. // :CATEGORY:XS Pet
  2. // :NAME:XS Pet Robot
  3. // :AUTHOR:Ferd Frederix
  4. // :KEYWORDS: Pet,XS,breed,breedable,companion,Ozimal,Meeroo,Amaretto,critter,Fennux,Pets
  5. // :CREATED:2013-09-06
  6. // :EDITED:2014-01-30 12:24:21
  7. // :ID:988
  8. // :NUM:1464
  9. // :REV:0.46
  10. // :WORLD:Second Life, OpenSim
  11. // :DESCRIPTION:
  12. // XS Pet xs_breeding
  13. // :CODE:
  14. // xs_breeding
  15. // 9-18-2012 exposed some internal timers to make it easier to debug breeding
  16. // 12-26-2012 father = id; // was on a line by itself, probably a nasty bug
  17. // 3-14-2013 Added a check that integer rest nebver goes negative, or else the pet may stop walking forever.
  18. // Version 0.46 9-18-2013 xs_breeding now has a new variable to delay getting fertile by 1 day after laying an egg.
  19. // Version 0.47 - made the tunable a contants, not a calc.
  20. // tunable for this script
  21. float TIME_TO_WAIT = 86400; // 86400 secs = wait 1 day to get fertile again.
  22. // START OF COPIED file 'Global Constants.txt' from the Debug folder. It has to be the same in all files
  23. // If you change this in any script, change it in all of them, please. It works a lot better that way.
  24. // This is code based on Version 0.50 01-30-2014
  25. // For version history, see file revisions.txt
  26. //
  27. // LICENSE
  28. /////////////////////////////////////////////////////////////////////
  29. // This code is licensed as Creative Commons Attribution/NonCommercial/Share Alike
  30. // See http://creativecommons.org/liceses/by-nc-sa/3.0/
  31. // Noncommercial -- You may not use this work for commercial purposes, i.e., you cannot sell this script in any form, including derivatives.
  32. // 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.
  33. // This means that you cannot sell this or derivative code by itself, but you may share and use this code in any object or virtual world.
  34. // You must attribute authorship in the original scripts to Ferd Frederix and Xundra Snowpaw, and leave this notice intact.
  35. // You do not have to give back to the community any changes you make, however, code changes would be greatly appreciated!
  36. //
  37. // Exception: I am allowing this script to be used in an original build and sold with the build.
  38. // You are not selling the script, you are selling the build. If you want to sell these scripts, write your own or use the original at http://code.google.com/p/xspets/
  39. // Note: Xundra Snowpaw's license was 'New BSD' license and adding additional licenses is allowed.
  40. // Based on code from Xundra Snowpaw
  41. // New BSD License: http://www.opensource.org/licenses/bsd-license.php
  42. // Copyright (c) 2010, Xundra Snowpaw
  43. // All rights reserved.
  44. // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  45. //* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  46. //* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
  47. // in the documentationand/or other materials provided with the distribution.
  48. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  49. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
  50. // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  51. // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  52. // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  53. // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  54. ////////////////////////////////////////////////////////////////////
  55. // DEBUG - lets you see and hear wtf is happening
  56. integer debug = FALSE; // set to TRUE TO hear a lot of chat
  57. // This section has a few tuneable items that MUST be changed for any new pet
  58. // SECURITY
  59. string SECRET_PASSWORD = "top secret string"; // must use a password unique to any species of animal, when ENCRYPT= TRUE. Otherwise you will find Pet type A fucking pet type B.
  60. integer SECRET_NUMBER = 99999; // any number thats a secret, not necessary to change usually, this is used when pets are born and eggs are rezzed to establish a comm channel.
  61. integer ENCRYPT = TRUE; // set to TRUE to encrypt all data, Some Opensim worlds prefer FALSE due to parsing bugs, TRUE is the most secure. If FALSE you MUST change the FOOD_CHANNEL and other channels for different pets. or they will literally fuck each other.
  62. // if you add the UUID for your avatar here, you can change it later
  63. // and other alts or friends can change it too, and all of you can work on these pets.
  64. // If you leave it blank, only the creator of the root prim can work on these pets.
  65. key YOUR_UUID = "";
  66. // PET NAMES - YOU MUST CHANGE THEM HERE AND IN THE ROOT PRIM OF THE OBJECT - THEY MUST MATCH EXACTLY
  67. /////////////////////////
  68. string MaleName = "Troubot"; // Must be the name of your animal
  69. string FemaleName = "Troubot"; // The name of the female pet, if a different shape or prim count. Can be the same as the Male for pets like the robot that are unisex.
  70. string Egg = "Nut and Bolt"; // was 'XS Egg', must be the name of your egg
  71. string Crate = "Transport Spaceship"; // was XS-Cryocrate, must be the name of the crate you package pets in
  72. string HomeObject = "Home Flag"; // was "XS Home Object", must be the name of your Home Post indicator
  73. string EggCup = "Toolbox"; // was "XS Egg Cup", must be the name of your egg holder
  74. // any other object names are 'do not cares'.
  75. // NOTHING NEEDS TO BE CHANGED BELOW, BUT CAN BE CHANGED IF YOU DO IT EVERYWHERE
  76. // misc tunables
  77. float GROWTH_AMOUNT = 0.10; // 10% size increase each day for MaxAge days = 200% (double size after 7 days)
  78. integer MaxAge = 7; // stop growing in seven days. 10% growth compounded daily means that your pet will be 194% larger ( 2x, basically) in 7 days.
  79. integer UNITS_OF_FOOD = 168; // food bowl food qty, used by food bowl only
  80. float secs_to_grow = 86400; // grow daily = 86400 seconds
  81. float FOOD_BOWL_SCAN_INTERVAL = 10800.0; // look for food every 3 hours
  82. float fPregnancy = 172800.0; // how many seconds to lay an egg = 2 days or 48 hours.
  83. float MALE_TIMEOUT = 900.0 ; // in seconds, female waits this long in one spot for a male to arrive
  84. float SEX_WAIT = 10800.0; // How often they desire sex = 3 hours
  85. float fDaysToAdult = 7; // 7 days to become old enough to breed.
  86. integer SECONDS_BETWEEN_FOOD_NORMAL = 14400; // number of seconds to get hungry = 4 hours
  87. integer SECONDS_BETWEEN_FOOD_HUNGRY = 3600; // number of seconds before hunger count increases = 1 hour
  88. integer MAXIMUM_HUNGER = 30; // They die after a month with no food.
  89. // I control versions by Subversion Source Code Control. But the updater needs a version numbert in world.
  90. // This is the Protocol version. If you change this, then all pets with a lower version will be updated by the updater
  91. float VERSION = 0.50;
  92. // the leg sizes are safe to leave alone or set to 0 if you use a thin base prim, these are from the original Quail
  93. float LegLength = 0.064; // length of pet leg??? - not sure
  94. float LegOffset = 0.052399; // This is added to the Post Z to position the pet
  95. // the following are global constants and do not need to be changed
  96. // Prim animation linkmessages are sent by scripts on Link Message number 1
  97. // The strings are the names of the animations that are recorded.
  98. // No need to change them unless you want to change names of the animations when you run the prim animator, or you add additional link messages
  99. // If your pet walks, you need to record these names and save them in the notecard
  100. //
  101. // Example:
  102. // llMessageLinked(LINK_SET, LINK_ANIMATE, ANI_STAND, "");
  103. // The above line will play the pre-recorded 'stand up' animation "stand" using the animator script.
  104. // The following animations are used in the pet. You can add your own.
  105. string ANI_STAND = "stand"; // default standing animation
  106. string ANI_WALKL = "left"; // triggers Left foot and Right arm walk animation
  107. string ANI_WALKR = "right"; // triggers Right foot and Left arm walk animation
  108. string ANI_SLEEP = "sleep"; // Sleeping
  109. string ANI_WAVE = "wave"; // Calling for sex, needs help with food, etc.
  110. // Channel assignments
  111. // if you change any of these constants, change it everywhere and in the list in XS_Debug so it can print them
  112. // If you turn encryption FALSE, you MUST change these between species of pets are they will fuck with each other. Literally.
  113. integer FOOD_CHANNEL = -999191;
  114. integer ANIMAL_CHANNEL = -999192;
  115. integer EGG_CHANNEL = -999193;
  116. integer HOME_CHANNEL = -999194;
  117. integer BOX_CHANNEL = -999195;
  118. integer ACC_CHANNEL = -999196;
  119. integer UPDATE_CHANNEL = -999197;
  120. integer API_CHANNEL = -999198;
  121. // global link messages to control the animal, never any need to change these.
  122. // They are exposed here so they will be the same everywhere. This uses a bit of RAM, but who cares?
  123. integer LINK_ANIMATE = 1; // messages on num 1 are assumed to be directed at the prim animator.
  124. integer DECREASE_FOOD = 100; // used in the food bowl.
  125. integer LINK_AGE_START = 800; // when pety is rezzed and secret_number is sent by brain to breeder, eater and infomatic get booted up
  126. integer LINK_TEXTURE = 801; // ask for a new texture, or paint a color
  127. integer LINK_BREEDNAME = 802; // the name of the pet texture from the texture server notecard
  128. integer LINK_FOOD_CONSUME = 900; // from movement to brain when close to food, brain then consumes a random amount up to 10000
  129. integer LINK_FOODMINUS = 901; // xs_brain receives FOOD_CONSUME, decrement hunger (eat)
  130. integer LINK_HUNGRY = 903; // sent by eater (string)hunger_amount, checks each hour
  131. integer LINK_HAMOUNT = 904; // hunger_amount = (integer)str,m updates the hunger amount in scripts
  132. integer LINK_SET_HOME = 910; // loc ^ dist
  133. integer LINK_MOVER = 911; // tell mover to rest for str seconds
  134. integer LINK_FOODIE_CLR = 920; // clear all food_bowl_keys and contents
  135. integer LINK_FOODIE = 921; // send FOOD_LOCATION coordinates to movement
  136. integer LINK_COLOR1 = 930; // colour1
  137. integer LINK_COLOR2 = 931; // colour2
  138. integer LINK_SEX = 932; // sex
  139. integer LINK_SHINE = 933; // shine
  140. integer LINK_GLOW = 934; // glow
  141. integer LINK_GEN = 935; // generation
  142. integer LINK_RESET_SIZE = 936; // reset size to 1
  143. integer LINK_MAGE = 940; // xs_brain sends, xs_ager consumes, adds str to age, if older than 7 days, will grow the animal
  144. integer LINK_DAYTIME = 941; // xs_ager consumes, starts a timer of 86,400 seconds in xs_ager
  145. integer LINK_GET_AGE = 942; // get age from xs_ager and sent it on channel 943
  146. integer LINK_PUT_AGE = 943; // print age from xs_ager
  147. integer LINK_PACKAGE = 950; // look for a cryo_crate
  148. integer LINK_SEEK_FEMALE = 960; // MALE_BREED_CALL
  149. integer LINK_MALE_BREED_CALL = 961; // triggered by LINK_SEEK_FEMALE
  150. integer LINK_SIGNAL_ELIGIBLE = 962; // sent by female when hears LINK_MALE_BREED_CALL
  151. integer LINK_FEMALE_ELIGIBLE = 963; // sent when it hears in chat FEMALE_ELIGIBLE
  152. integer LINK_CALL_MALE = 964; // if LINK_FEMALE_ELIGIBLE && looking_for_female
  153. integer LINK_MALE_ON_THE_WAY = 965; // triggered by LINK_CALL_MALE
  154. integer LINK_FEMALE_LOCATION = 966; // female location, sends coordinates of a female
  155. integer LINK_RQST_BREED = 967; // sent when close enough to male/female
  156. 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.
  157. integer LINK_MALE_INFO = 969; // Breeding failed, sent info
  158. integer LINK_LAY_EGG = 970; // Rez Object(Egg...
  159. integer LINK_BREED_FAIL = 971; // key = father, failed, timed out
  160. integer LINK_PREGNANT = 972; // chick is preggers
  161. integer LINK_SOUND_OFF= 974; // sound is off
  162. integer LINK_SOUND_ON= 973; // sound is on
  163. integer LINK_SLEEPING = 990; // close eyes
  164. integer LINK_UNSLEEPING = 991; // open eyes
  165. integer LINK_SOUND = 1001; // plays a sound if enabled
  166. integer LINK_SPECIAL = 1010; // xs_special, if str = "Normal", removes script
  167. integer LINK_EFFECTS_ON = 2000; // particle effects in the packger
  168. integer LINK_PREGNANCY_TIME = 5000; // in seconds as str
  169. integer LINK_SLEEP = 7999; // disable sleep by parameter
  170. integer LINK_TIMER = 8000; // scan for food bowl about every 1800 seconds
  171. integer LINK_DIE = 9999; // death
  172. string Copyright = " (c)2014 by Ferd Frederix"; // You cannot change this line, but you can change the code that prints it!
  173. // See License agreements above.
  174. // Attribution is required, as these files are copyrighted.
  175. DEBUG ( string msg){
  176. if (debug) {
  177. llOwnerSay(llGetScriptName() + ":" + msg);
  178. }
  179. }
  180. ///////// end global Link constants ////////
  181. // END OF COPIED CODE
  182. // globals
  183. integer age; // age in days, starting at 0
  184. integer looking_for_female;
  185. key father;
  186. key mother;
  187. integer preg_time;
  188. default
  189. {
  190. link_message(integer sender, integer num, string str, key id)
  191. {
  192. if (num == LINK_AGE_START) {
  193. state running;
  194. }
  195. }
  196. }
  197. state running
  198. {
  199. state_entry()
  200. {
  201. age = 0;
  202. }
  203. link_message(integer sender, integer num, string str, key id)
  204. {
  205. if (num == LINK_SEX) {
  206. if (str == "1") {
  207. state male;
  208. } else {
  209. state female;
  210. }
  211. } else
  212. if (num == LINK_MAGE) {
  213. age += (integer)str;
  214. } else {
  215. if (num == LINK_PREGNANCY_TIME) {
  216. preg_time = (integer)str;
  217. if (preg_time != 0) {
  218. state pregnant;
  219. } else {
  220. state female;
  221. }
  222. }
  223. }
  224. }
  225. }
  226. state male
  227. {
  228. state_entry()
  229. {
  230. looking_for_female = 0;
  231. mother = NULL_KEY;
  232. father = NULL_KEY;
  233. llMessageLinked(LINK_SET, LINK_GET_AGE, "", "");
  234. if (age >= fDaysToAdult) {
  235. llSetTimerEvent(SEX_WAIT); // 3 hours
  236. }
  237. }
  238. link_message(integer sender, integer num, string str, key id)
  239. {
  240. if (num == LINK_PUT_AGE) {
  241. age = (integer)str;
  242. if (age >= fDaysToAdult) {
  243. llSetTimerEvent(SEX_WAIT);
  244. }
  245. } else
  246. if (num == LINK_MAGE) {
  247. age += (integer)str;
  248. if (age >= fDaysToAdult) {
  249. llSetTimerEvent(SEX_WAIT); // look ebvery 3 hours for a female
  250. }
  251. } else
  252. if (num == LINK_FEMALE_ELIGIBLE) {
  253. if (looking_for_female == 1) {
  254. looking_for_female = 0;
  255. mother = id;
  256. father = llGetKey();
  257. llMessageLinked(LINK_SET, LINK_CALL_MALE, "", mother);
  258. }
  259. } else
  260. if (num == LINK_RQST_BREED) {
  261. if (mother != NULL_KEY) {
  262. llMessageLinked(LINK_SET, LINK_CALL_MALE_INFO, "", mother); // V0.25 fix error by Ferd, was LINK_CALL_MALE, should be LINK_CALL_MALE_INFO
  263. }
  264. } else
  265. if (num == LINK_MALE_INFO) {
  266. state male;
  267. }
  268. }
  269. timer()
  270. {
  271. looking_for_female = 1;
  272. // look for an eligible female.
  273. llWhisper(0, llGetObjectName() + " gets a gleam in his eye.");
  274. llMessageLinked(LINK_SET, LINK_SEEK_FEMALE, "", "");
  275. }
  276. }
  277. state female
  278. {
  279. state_entry()
  280. {
  281. mother = NULL_KEY;
  282. father = NULL_KEY;
  283. if (age == 0) {
  284. llMessageLinked(LINK_SET, LINK_GET_AGE, "", "");
  285. }
  286. }
  287. link_message(integer sender, integer num, string str, key id)
  288. {
  289. if (num == LINK_MAGE) {
  290. age += (integer)str; // add to age
  291. } else
  292. if (num == LINK_MALE_BREED_CALL) {
  293. // signal I am eligible
  294. if (age >= fDaysToAdult && father == NULL_KEY) {
  295. llWhisper(0, llGetObjectName() + " blushes then bobs her head up and down.");
  296. llMessageLinked(LINK_SET, LINK_SIGNAL_ELIGIBLE, "", "");
  297. }
  298. } else
  299. if (num == LINK_MALE_ON_THE_WAY) {
  300. // male on the way, timeout in 15 minutes
  301. llSetTimerEvent(MALE_TIMEOUT); // 20 minutes
  302. father = id; // was on a line by itself, probably a nasty bug
  303. mother = llGetKey();
  304. llMessageLinked(LINK_SET, LINK_MOVER, (string) MALE_TIMEOUT, ""); // tell mover to rest for 20 minutes
  305. } else
  306. if (num == LINK_PREGNANT) {
  307. // pregnant
  308. llSetTimerEvent(0);
  309. preg_time = 0;
  310. state pregnant;
  311. } else
  312. if (num == LINK_MALE_INFO) {
  313. llSetTimerEvent(0);
  314. state female;
  315. } else
  316. if (num == LINK_PUT_AGE) {
  317. age = (integer)str;
  318. } else
  319. if (num == LINK_PREGNANCY_TIME) {
  320. preg_time = (integer)str;
  321. if (preg_time != 0) {
  322. state pregnant;
  323. }
  324. }
  325. }
  326. timer()
  327. {
  328. llSetTimerEvent(0);
  329. // fail
  330. llMessageLinked(LINK_SET, LINK_BREED_FAIL, "", father);
  331. state female;
  332. }
  333. }
  334. state pregnant
  335. {
  336. state_entry()
  337. {
  338. if (preg_time != 0) {
  339. llSetTimerEvent(fPregnancy - (float)(llGetUnixTime() - preg_time));
  340. } else {
  341. llSetTimerEvent(fPregnancy);
  342. }
  343. }
  344. timer()
  345. {
  346. // lay egg.
  347. llSetTimerEvent(0);
  348. llMessageLinked(LINK_SET, LINK_LAY_EGG, "", "");
  349. state Wait;
  350. }
  351. changed(integer change)
  352. {
  353. if (change & CHANGED_REGION_START)
  354. {
  355. llSetTimerEvent(fPregnancy);
  356. }
  357. }
  358. }
  359. state Wait
  360. {
  361. state_entry()
  362. {
  363. llSetTimerEvent(TIME_TO_WAIT);
  364. }
  365. timer()
  366. {
  367. llSetTimerEvent(0);
  368. state female;
  369. }
  370. changed(integer change)
  371. {
  372. if (change & CHANGED_REGION_START)
  373. {
  374. llSetTimerEvent(TIME_TO_WAIT);
  375. }
  376. }
  377. }