inheritance.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <html>
  2. <head>
  3. <link href="../tutorial.css" rel="stylesheet" type="text/css">
  4. </head>
  5. <body>
  6. <div class="header">
  7. The NakedMud Tutorial :: Inheritance
  8. </div>
  9. <!-- content starts here -->
  10. <div class="content-wrap"><div class="content-body-wrap"><div class="content">
  11. <div class="head">Abstract Contents</div>
  12. <div class="info">
  13. You may have noticed that certain zone contents are flagged as abstract. The
  14. very first editor option for rooms, objects, and mobiles is whether or not they
  15. are abstract. If a game content is abstract it means it is a real game
  16. content, but it cannot actually exist in the game on its own. Abstract contents
  17. are used for inheritance, which is the topic of this section. They supply
  18. important information about 'child' contents that inherit from them, but they
  19. themselves can never actually exist.
  20. </div>
  21. <div class="head">Inheritance</div>
  22. <div class="info">
  23. Distinct rooms, objects, and mobiles often share common features. When this
  24. commonality must be defined separately for each case, it becomes a hassle. Even
  25. worse is when it is decided that this commonality needs to be changed. NakedMud
  26. supports inheritance for rooms, objects, and mobiles -- unique versions of
  27. zone contents can inherit from a parent version, automatically copying over
  28. all features of the parent to the child.
  29. <p></p>
  30. One application of inheritance is to store all generic information about city
  31. streets in a parent room, and then have individual rooms within the city
  32. inherit from the parent. Here is an example of a parent location called
  33. mainstreet, from which specific locations along the street will inherit.
  34. <pre class="mud">
  35. [mainstreet@moonhaven]
  36. 1) Abstract: yes
  37. 2) Inherits from prototypes:
  38. 3) Name
  39. Main Street
  40. 4) Description
  41. The street is nicely kept cobblestone. Buildings of various sizes dot the
  42. north and south sides of the street. [if is_night()] The doors and windows on
  43. most are shut, suggesting the town has gone to bed for the night.[/if] [if
  44. is_evening() or is_night()] Flames flicker at the tops of tall polls lining
  45. either side of the streeet. They give the street basic illumination.[/if]
  46. L) Land type [City]
  47. B) Set Bits:
  48. Z) Room can be reset: no
  49. R) Room reset menu
  50. X) Extra descriptions menu
  51. T) Trigger menu
  52. E) Edit exit
  53. F) Fill exit
  54. north : nowhere east : nowhere
  55. south : nowhere west : nowhere
  56. up : nowhere down : nowhere
  57. northeast : nowhere southeast : nowhere
  58. southwest : nowhere northwest : nowhere
  59. C) Extra code
  60. Enter choice, ? [topic] for help, or Q to quit:
  61. </pre>
  62. Once the parent is created, new rooms can be edited and set to inherit from this
  63. room. Each one that does will, by default, gain all of the information of the
  64. parent. The information can also be extended. For instance, names can be
  65. over-written and descriptions can be added to. Here is an example that inherits
  66. from mainstreet, changes its name, and adds to its description.
  67. <pre class="mud">
  68. [mainstreet01@moonhaven]
  69. 1) Abstract: no
  70. 2) Inherits from prototypes:
  71. <font class="highlight">mainstreet</font>
  72. 3) Name
  73. <font class="highlight">Mainstreet, Before the Tavern</font>
  74. 4) Description
  75. <font class="highlight">A large tavern can be seen on the north side of the street. [if is_evening()
  76. or is_night()] Silhouettes of moving people are projected against the smoky
  77. windows of the tavern from inside lights.[/if] The sound of music emits from
  78. within.</font>
  79. L) Land type [leave unchanged]
  80. B) Set Bits:
  81. Z) Room can be reset: no
  82. R) Room reset menu
  83. X) Extra descriptions menu
  84. T) Trigger menu
  85. E) Edit exit
  86. F) Fill exit
  87. north : tavern east : nowhere
  88. south : nowhere west : nowhere
  89. up : nowhere down : nowhere
  90. northeast : nowhere southeast : nowhere
  91. southwest : nowhere northwest : nowhere
  92. C) Extra code
  93. Enter choice, ? [topic] for help, or Q to quit:
  94. </pre>
  95. Note that in this example, the name is changed but the description is only
  96. <i>added to</i>. When using inheritance, editing a child's decription will
  97. add to the parent's, not erase what was previously there. Other descriptive
  98. fields that are edited will be overwritten. If you would prefer not to overwrite
  99. a field, simply leave it blank in the editor.
  100. </div>
  101. <div class="head">Heirarchical Inheritance</div>
  102. <div class="info">
  103. When a parent is inherited from, all contents the parent inherits from are also
  104. implicitly inherited. In this sense, inheritance is heirarchical. One way this
  105. can applied is to make all lines of inheritance trace back to a single unique
  106. content -- a generic content, so to say. If you ever want to globally apply new
  107. functionality to a room, you can then simply add it to the generic room and all
  108. other rooms will automatically have it.
  109. <p></p>
  110. If your mud implements a death system, one use of this would be to supply a
  111. generic trigger that handles a person's death, while still leaving open the
  112. possibility that certain rooms might change how death is handled by replacing
  113. that trigger. To give a
  114. classic example, some DIKU muds implement deathtraps. Normally, if a player
  115. were to die, their corpse might be transfered to a graveyard for easy access.
  116. However, if a player were to die in a deathtrap, their corpse remains in the
  117. trap. And what if you want variations of death traps? Often these sort of
  118. extentions are supplied within the game's code, using bits or flags to mark
  119. important information. NakedMud allows you to have different rooms, mobiles,
  120. and objects that exhibit different behaviors through inheritance instead. The
  121. game code need never be touched.
  122. <p></p>
  123. Here is an example from my mud; all chains of inheritance for rooms are rooted
  124. at a single room: generic_room@templates. This room specifies a generic trigger
  125. to run when someone dies, and assigns a location to transfer their corpse to.
  126. <pre class="mud">
  127. [generic_room@templates]
  128. 1) Abstract: yes
  129. 2) Inherits from prototypes:
  130. 3) Name
  131. 4) Description
  132. L) Land type [leave unchanged]
  133. B) Set Bits:
  134. Z) Room can be reset: no
  135. R) Room reset menu
  136. X) Extra descriptions menu
  137. T) Trigger menu
  138. E) Edit exit
  139. F) Fill exit
  140. north : nowhere east : nowhere
  141. south : nowhere west : nowhere
  142. up : nowhere down : nowhere
  143. northeast : nowhere southeast : nowhere
  144. southwest : nowhere northwest : nowhere
  145. C) Extra code
  146. <font class="highlight">me.attach("generic_death@templates")
  147. me.setvar("graveyard", "graveyard@templates")</font>
  148. </pre>
  149. All rooms that inherit from generic_room@templates have the trigger,
  150. generic_death@templates attached to them. Whenever a player dies in a room
  151. inheriting from this one, their corpse is created and transfered to
  152. the standard graveyard. However, these are properties of the <i>room</i> not
  153. the game. So another room that inherits from this one can easily change the
  154. death behavior -- say, moving the corpse somewhere else -- by setting the
  155. graveyard variable to something new. For instance, an inherited room that had
  156. this line of extra code would leave the corpse where it is:
  157. <pre class="mud">
  158. C) Extra code
  159. <font class="highlight">me.setvar("graveyard", me.proto)</font>
  160. </pre>
  161. Or perhaps you want a room where death is handled in a completely different
  162. manner. Maybe you want dying to be the neccessary event to progress in a quest
  163. -- for instance, in a trial of courage. Then you could detach the generic
  164. death trigger and attach your own special one that doesn't let players die, but
  165. instead transfers them in-tact to the next area of the quest.
  166. <pre class="mud">
  167. C) Extra code
  168. <font class="highlight">me.detach("generic_death@templates")
  169. me.attach("trial_of_courage_death@myzone")</font>
  170. </pre>
  171. </div>
  172. <div class="head">Multiple Inheritance</div>
  173. <div class="info">
  174. Game contents can inherit from more than one parent. Rooms, objects, and mobiles
  175. can be chimeras -- blends of multiple things, but not tracable back to a single
  176. unique lineage. Defining multiple inheritance, like single inheritance, is done
  177. through the OLC editors. However instead of supplying a single parent, any
  178. number of parents are entered, comma separated.
  179. <pre class="mud">
  180. [black_beetle@moonhaven]
  181. 1) Abstract: no
  182. 2) Inherits from prototypes:
  183. <font class="highlight">generic_mob@templates, beetle@templates, hostile@templates</font>
  184. </pre>
  185. For instance, suppose you want to design a zone of beetles. All of those
  186. beetles are beetles, and thus share a unique set of properties which you might
  187. define in beetle@templates. However, some beetles might also be hostile, and
  188. have an additional hostile behavior associated with them. You could set this up
  189. as a heirarchy, so there were two classes, one called hostile_beetle which some
  190. of the beetles inherited from another another called friendly_beetle which the
  191. others inherited from, both of which inherit from beetle. This would be a
  192. valid approach.
  193. <p></p>
  194. But if you have other creatures that could also be hostile -- trolls,
  195. necromancers, mothers -- and it would be cumbersome to make a hostile heirarchy
  196. for every individual type of creature. With multiple inheritance, you can just
  197. cut to the chase and have a separate template, hostile, that any creature can
  198. inherit from to gain scripted, hostile behavior.
  199. <p></p>
  200. The one caveat with multiple inheritance is that you have to be aware of
  201. the fact that one parent may override information set by another parent (names,
  202. attaching and detaching scripts, changing races and genders, etc). Parent
  203. information is applied serially, first in the list to last in the list. So the
  204. last parent processed is the one whose information you can gaurantee will be
  205. represented in the child. However, with careful design this should be a
  206. non-issue.
  207. </div>
  208. <!-- content ends here-->
  209. </div></div></div>
  210. <!-- navigation starts here -->
  211. <div class="nav-wrap"><div class="nav">
  212. <iframe src="nav.html" height="100%" width="100%" scrolling=no frameborder=0>
  213. </iframe>
  214. <!-- navigation ends here -->
  215. </div></div>
  216. <!--div class="footer">Edit Date: Nov 15, 2008. By Geoff Hollis</div-->
  217. </body>
  218. </html>