Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 1 | SYNOPSIS |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 2 | object clone_object(string name, ...) |
| 3 | object clone_object(object template, ...) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 4 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 5 | DESCRIPTION |
| 6 | Clone a new object from definition <name>, or alternatively from |
| 7 | the object <template>. In both cases, the new object is given |
| 8 | an unique name and returned. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 9 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 10 | The original used for cloning, called blueprint, should not be |
| 11 | used in the system, just for cloning. The cloned objects |
| 12 | contain only the data but the blueprint also the function code. |
| 13 | The blueprint is the one without a unique number at the end of |
| 14 | the object's name. The clone_object() function never |
| 15 | returns a blue print. |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 16 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 17 | If the <name> or <template> designates a cloned object itself, |
| 18 | the system looks up the blueprint object _by name_. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 19 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 20 | Any further arguments will be passed to the H_CREATE_CLONE |
| 21 | hook to initialize the cloned object. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 22 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 23 | If the blueprint exists and has a heart_beat(), clone_object() |
| 24 | turns it off. |
| 25 | |
| 26 | Note that the pathname must be complete, which means there are no |
| 27 | relative paths allowed. |
| 28 | |
| 29 | If strict euids are enforced, the cloning object must have |
| 30 | a non-zero euid. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 31 | |
| 32 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 33 | -- Variable Initialization -- |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 34 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 35 | In general, variables are initialized for blueprints and clones alike |
| 36 | with a call to the internal lfun __INIT(). |
| 37 | |
| 38 | However, if #pragma share_variables is in effect (either explicitely |
| 39 | given in the source or implicitly as runtime option), the values for |
| 40 | a clone's uninitialized variables are taken from the _current_ |
| 41 | variables of the object's blueprint. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 42 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 43 | In the absence of share_variables, variables without explicit |
| 44 | initializers are initialized to 0. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 45 | |
| 46 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 47 | EXAMPLES |
| 48 | // Clone a torch (filename in non-compat format) |
| 49 | object torch; |
| 50 | torch = clone_object("/obj/torch"); |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 51 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 52 | // Clone two keys (filename in compat format) |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 53 | object key1, key2; |
| 54 | key1 = clone_object(load_object("obj/key")); |
| 55 | key2 = clone_object(key1); |
| 56 | |
| 57 | // Create a specialized weapons blueprint. |
| 58 | --- std/weapon.c: --- |
| 59 | #pragma share_variables |
| 60 | int weapon_class = 1; |
| 61 | |
| 62 | --- broadsword.c: --- |
| 63 | inherit "/std/weapon"; |
| 64 | |
| 65 | int create() { |
| 66 | weapon_class = 2; |
| 67 | replace_program("/std/weapon"); |
| 68 | } |
| 69 | |
| 70 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 71 | HISTORY |
| 72 | Modified in LDMud 3.2.6 to take an object as argument. |
| 73 | LDMud 3.3.378 consolidated the variable initialization with the |
| 74 | share_variables pragma. |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 75 | |
Zesstra | 715ec20 | 2025-07-09 22:18:31 +0200 | [diff] [blame] | 76 | SEE ALSO |
Zesstra | d59c389 | 2019-11-28 20:53:39 +0100 | [diff] [blame] | 77 | blueprint(E), clonep(E), destruct(E), clones(E), load_name(E), |
| 78 | load_object(E), move_object(E), uids(C), program_name(E), pragma(LPC) |