xs_ager.lsl 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. // :CATEGORY:XS Quail
  2. // :NAME:XS Pet Quail Modified
  3. // :AUTHOR:Xundra Snowpaw, Ferd Frederix
  4. // :CREATED:2013-09-06
  5. // :EDITED:2014-01-17 11:32:47
  6. // :ID:987
  7. // :NUM:1415
  8. // :REV:1
  9. // :WORLD:Second Life, Opensim
  10. // :DESCRIPTION:
  11. // XS Pet Modified Ager script
  12. // :CODE:
  13. // DESCRIPTION:
  14. // Modified Pet Quail
  15. // Version .24 10-3-2011
  16. // script by Xundra Snowpaw
  17. // mods by Ferd Frederix
  18. // Allows arbitrary growth without any constants or prim limits
  19. // 2 tunable parameters for aging time and maximum growth time
  20. //
  21. // New BSD License: http://www.opensource.org/licenses/bsd-license.php
  22. // Copyright (c) 2010, Xundra Snowpaw
  23. // All rights reserved.
  24. //
  25. // Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  26. //* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  27. //* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  28. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. ////////////////////////////////////////////////////////////////////
  30. // tunables - you can modify these based on your pet
  31. float secs_to_grow = 86400; // grow daily = 86400
  32. integer MAX = 7; // gorw for 7 days, then stop
  33. ///// GLOBAL LINK CONSTANTS extracted from original source //////
  34. ///
  35. // if you change anything, you change it everywhere and in a list in XS_Debug
  36. ///
  37. integer LINK_AGE_START = 800; // when quail is rezzed and secret_number, is sent by brain to breeder, eater and informatic get booted up
  38. integer LINK_FOOD_CONSUME = 900; // from movement to brain when close to food, brain then consumes a random amount up to 10000
  39. integer LINK_FOODMINUS = 901; // xs_brain receives FOOD_CONSUME, decrement hunger (eat)
  40. integer LINK_HUNGRY = 903; // sent by eater (string)hunger_amount, checks each hour
  41. integer LINK_HAMOUNT = 904; // hunger_amount = (integer)str,m updates the hunger amount in scripts
  42. integer LINK_SET_HOME = 910; // loc ^ dist
  43. integer LINK_MOVER = 911; // tell mover to rest for str seconds
  44. integer LINK_FOODIE_CLR = 920; // clear all food_bowl_keys and contents
  45. integer LINK_FOODIE = 921; // send FOOD_LOCATION coordinates to movement
  46. integer LINK_COLOR1 = 930; // colour1
  47. integer LINK_COLOR2 = 931; // colour2
  48. integer LINK_SEX = 932; // sex
  49. integer LINK_SHINE = 933; // shine
  50. integer LINK_GLOW = 934; // glow
  51. integer LINK_GEN = 935; // generation
  52. integer LINK_RESET_SIZE = 936; // reset size to 1
  53. integer LINK_MAGE = 940; // xs_brain sends, xs_ager consumes, adds str to age, if older than 7 days, will grow the animal
  54. integer LINK_DAYTIME = 941; // xs_ager consumes, starts a timer of 86,400 seconds in xs_ager
  55. integer LINK_GET_AGE = 942; // get age from xs_ager and sent it on channel 943
  56. integer LINK_PUT_AGE = 943; // print age from xs_ager
  57. integer LINK_PACKAGE = 950; // look for a cryo_crate
  58. integer LINK_SEEK_FEMALE = 960; // MALE_BREED_CALL
  59. integer LINK_MALE_BREED_CALL = 961; // triggered by LINK_SEEK_FEMALE
  60. integer LINK_SIGNAL_ELIGIBLE = 962; // sent by female when hears LINK_MALE_BREED_CALL
  61. integer LINK_FEMALE_ELIGIBLE = 963; // sent when it hears in chat FEMALE_ELIGIBLE
  62. integer LINK_CALL_MALE = 964; // if LINK_FEMALE_ELIGIBLE && looking_for_female
  63. integer LINK_MALE_ON_THE_WAY = 965; // triggered by LINK_CALL_MALE
  64. integer LINK_FEMALE_LOCATION = 966; // female location, sends coordinates of a female
  65. integer LINK_RQST_BREED = 967; // sent when close enough to male/female
  66. integer LINK_CALL_MALE_INFO = 968; // ****** BUG ***** read, but never sent by anybody!!!!!
  67. // see line 557 and 636 of xs_brain which make calls and also xs_breeding which receives LINK_MALE_INFO.
  68. integer LINK_MALE_INFO = 969;
  69. integer LINK_LAY_EGG = 970; // llRezObject("XS Egg"
  70. integer LINK_BREED_FAIL = 971; // key = father, failed, timed out
  71. integer LINK_PREGNANT = 972; // chick is preggers
  72. integer LINK_SLEEPING = 990; // close eyes
  73. integer LINK_UNSLEEPING = 991; // open eyes
  74. integer LINK_SOUND = 1001; // plays a sound if enabled
  75. integer LINK_SPECIAL = 1010; // xs_special, is str = "Normal", removes script
  76. integer LINK_PREGNANCY_TIME = 5000; // in seconds as str
  77. integer LINK_SLEEP = 7999; // disable sleep by parameter
  78. integer LINK_TIMER = 8000; // scan for food bowl about every 1800 seconds
  79. integer LINK_DIE = 9999; // death
  80. ///////// end global Link constants ////////
  81. // END //
  82. integer debug = FALSE;
  83. integer age; // age in days
  84. float GROWTH_AMOUNT = 0.10; // 10% size increase
  85. DEBUG(string msg)
  86. {
  87. if (debug)
  88. llOwnerSay(llGetScriptName() + " : " + msg);
  89. }
  90. float cur_scale = 1.0;
  91. list link_scales = [];
  92. list link_positions = [];
  93. integer scanLinkset()
  94. {
  95. integer link_qty = llGetNumberOfPrims();
  96. integer link_idx;
  97. vector link_pos;
  98. vector link_scale;
  99. //script made specifically for linksets, not for single prims
  100. if (link_qty > 1)
  101. {
  102. //link numbering in linksets starts with 1
  103. for (link_idx=1; link_idx <= link_qty; link_idx++)
  104. {
  105. link_pos=llList2Vector(llGetLinkPrimitiveParams(link_idx,[PRIM_POSITION]),0);
  106. link_scale=llList2Vector(llGetLinkPrimitiveParams(link_idx,[PRIM_SIZE]),0);
  107. link_scales += [link_scale];
  108. link_positions += [(link_pos-llGetRootPosition())/llGetRootRotation()];
  109. }
  110. }
  111. else
  112. {
  113. llOwnerSay("error: this script doesn't work for non-linked objects");
  114. return FALSE;
  115. }
  116. return TRUE;
  117. }
  118. resizeObject(float scale)
  119. {
  120. integer link_qty = llGetNumberOfPrims();
  121. integer link_idx;
  122. vector new_size;
  123. vector new_pos;
  124. if (link_qty > 1)
  125. {
  126. //link numbering in linksets starts with 1
  127. for (link_idx=1; link_idx <= link_qty; link_idx++)
  128. {
  129. new_size = scale * llList2Vector(link_scales, link_idx-1);
  130. new_pos = scale * llList2Vector(link_positions, link_idx-1);
  131. if (link_idx == 1)
  132. {
  133. //because we don't really want to move the root prim as it moves the whole object
  134. llSetLinkPrimitiveParamsFast(link_idx, [PRIM_SIZE, new_size]);
  135. }
  136. else
  137. {
  138. llSetLinkPrimitiveParamsFast(link_idx, [PRIM_SIZE, new_size, PRIM_POSITION, new_pos]);
  139. }
  140. }
  141. }
  142. }
  143. default
  144. {
  145. state_entry()
  146. {
  147. scanLinkset();
  148. }
  149. link_message(integer sender, integer num, string str, key id)
  150. {
  151. if (num == LINK_AGE_START) {
  152. state running;
  153. }
  154. }
  155. }
  156. state running
  157. {
  158. state_entry()
  159. {
  160. age = 0;
  161. }
  162. timer()
  163. {
  164. llMessageLinked(LINK_SET, LINK_MAGE, "1", "");
  165. }
  166. link_message(integer sender, integer num, string str, key id)
  167. {
  168. if (num == LINK_GET_AGE) {
  169. llMessageLinked(LINK_SET, LINK_PUT_AGE, (string)age, "");
  170. } else
  171. if (num == LINK_DAYTIME) {
  172. llSetTimerEvent(secs_to_grow); // 86400.0
  173. } else
  174. if (num == LINK_RESET_SIZE)
  175. {
  176. cur_scale = 1.0;
  177. resizeObject(cur_scale);
  178. age = 0;
  179. }
  180. if (num == LINK_MAGE) {
  181. integer prev_age = age;
  182. integer size_age;
  183. age += (integer) str; // add 1, typically
  184. if (prev_age == 0 && age > MAX) {
  185. size_age = MAX;
  186. } else {
  187. size_age = age;
  188. }
  189. if (size_age > 0 && size_age <= 7) {
  190. // grow to the correct proportion
  191. llMessageLinked(LINK_SET, LINK_MOVER, "1", ""); // tell mover to rest for 5 seconds
  192. cur_scale = cur_scale * (GROWTH_AMOUNT + 1.0); // new size is 110%, 120%, etc of the original size
  193. DEBUG("Growing " + (string) cur_scale);
  194. resizeObject(cur_scale);
  195. }
  196. }
  197. }
  198. }