PennMUSH Community

Ticket #7610: create-dbref.patch.txt

File create-dbref.patch.txt, 8.1 kB (added by Talvo, 4 months ago)

Extends @create syntax to @create <name>[=<cost>[,<dbref>]] and create(<name>[,<cost>[,<dbref>]])

Line 
1 *** src/cmds.c.orig Fri Oct  5 23:36:32 2007
2 --- src/cmds.c  Fri Jun  6 02:32:49 2008
3 ***************
4 *** 194,200 ****
5  
6   COMMAND(cmd_create)
7   {
8 !   do_create(player, arg_left, parse_integer(arg_right));
9   }
10  
11   COMMAND(cmd_clone)
12 --- 194,212 ----
13  
14   COMMAND(cmd_create)
15   {
16 !
17 !   int cost = 0;
18 !   char *newdbref;
19 !
20 !   if (args_right[1] && *args_right[1])
21 !     cost = parse_integer(args_right[1]);
22 !
23 !   if (args_right[2] && *args_right[2])
24 !     newdbref = args_right[2];
25 !   else
26 !     newdbref = (char *) NULL;
27 !
28 !   do_create(player, arg_left, cost, newdbref);
29   }
30  
31   COMMAND(cmd_clone)
32 *** src/command.c.orig  Fri Oct  5 23:36:32 2007
33 --- src/command.c   Fri Jun  6 02:32:49 2008
34 ***************
35 *** 99,105 ****
36     {"@CPATTR", "CONVERT NOFLAGCOPY", cmd_cpattr,
37      CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_RS_ARGS,
38      0, 0},
39 !   {"@CREATE", NULL, cmd_create, CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_NOGAGGED,
40      0, 0},
41     {"@CLONE", "PRESERVE", cmd_clone, CMD_T_ANY | CMD_T_NOGAGGED | CMD_T_EQSPLIT,
42      0, 0},
43 --- 99,106 ----
44     {"@CPATTR", "CONVERT NOFLAGCOPY", cmd_cpattr,
45      CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_RS_ARGS,
46      0, 0},
47 !   {"@CREATE", NULL, cmd_create,
48 !    CMD_T_ANY | CMD_T_EQSPLIT | CMD_T_RS_ARGS | CMD_T_NOGAGGED,
49      0, 0},
50     {"@CLONE", "PRESERVE", cmd_clone, CMD_T_ANY | CMD_T_NOGAGGED | CMD_T_EQSPLIT,
51      0, 0},
52 *** src/create.c.orig   Tue Jun 12 23:21:48 2007
53 --- src/create.c    Fri Jun  6 02:32:49 2008
54 ***************
55 *** 424,433 ****
56    * \param player the enactor.
57    * \param name name of thing to create.
58    * \param cost pennies spent in creation.
59    * \return dbref of new thing, or NOTHING.
60    */
61   dbref
62 ! do_create(dbref player, char *name, int cost)
63   {
64     dbref loc;
65     dbref thing;
66 --- 424,434 ----
67    * \param player the enactor.
68    * \param name name of thing to create.
69    * \param cost pennies spent in creation.
70 +  * \paran newdbref the (unparsed) dbref to give the object, or NULL to use the next free
71    * \return dbref of new thing, or NOTHING.
72    */
73   dbref
74 ! do_create(dbref player, char *name, int cost, char *newdbref)
75   {
76     dbref loc;
77     dbref thing;
78 ***************
79 *** 441,446 ****
80 --- 442,466 ----
81     } else if (cost < OBJECT_COST) {
82       cost = OBJECT_COST;
83     }
84 +
85 +   if (newdbref && *newdbref) {
86 +     /* move newdbref to the start of the free list */
87 +     if (!has_flag_by_name(player, "WIZARD", NOTYPE)) {
88 +       notify(player, T("Permission denied."));
89 +       return NOTHING;
90 +     }
91 +     thing = parse_dbref(newdbref);
92 +     if (thing == NOTHING || !GoodObject(thing) || !IsGarbage(thing)) {
93 +       notify(player, T("That is not a valid dbref."));
94 +       return NOTHING;
95 +     }
96 +
97 +     if (!make_first_free(thing)) {
98 +       notify(player, T("Unable to create object with that dbref."));
99 +       return NOTHING;
100 +     }
101 +   }
102 +
103     if (can_pay_fees(player, cost)) {
104       /* create the object */
105       thing = new_object();
106 *** src/destroy.c.orig  Mon Jul  9 04:50:12 2007
107 --- src/destroy.c   Fri Jun  6 02:32:50 2008
108 ***************
109 *** 879,884 ****
110 --- 879,910 ----
111     giveto(Owner(thing), EXIT_COST);
112   }
113  
114 + /** If object is in the free list, move it to the very beginning.
115 +  * \param object dbref of object to move
116 +  * \return 1 if object is moved successfully, 0 otherwise
117 +  */
118 + int
119 + make_first_free(dbref object)
120 + {
121 +   dbref curr;
122 +   dbref prev = NOTHING;
123 +
124 +   if (first_free == NOTHING || !GoodObject(object) || !IsGarbage(object))
125 +     return 0;                   // no garbage, or object isn't garbage
126 +   else if (first_free == object)
127 +     return 1;                   // object is already at the head of the queue
128 +   for (curr = first_free; Next(curr); curr = Next(curr)) {
129 +     if (curr == object) {
130 +       Next(prev) = Next(curr);
131 +       Next(curr) = first_free;
132 +       first_free = curr;
133 +       return 1;
134 +     } else
135 +       prev = curr;
136 +   }
137 +   return 0;
138 +
139 + }
140  
141   /** Return a cleaned up object off the free list or NOTHING.
142    * \return a garbage object or NOTHING.
143 *** hdrs/externs.h.orig Fri Oct  5 23:36:32 2007
144 --- hdrs/externs.h  Fri Jun  6 02:32:57 2008
145 ***************
146 *** 261,267 ****
147  
148   /* From create.c */
149   dbref do_dig(dbref player, const char *name, char **argv, int tport);
150 ! dbref do_create(dbref player, char *name, int cost);
151   dbref do_real_open(dbref player, const char *direction,
152                      const char *linkto, dbref pseudo);
153   void do_open(dbref player, const char *direction, char **links);
154 --- 261,267 ----
155  
156   /* From create.c */
157   dbref do_dig(dbref player, const char *name, char **argv, int tport);
158 ! dbref do_create(dbref player, char *name, int cost, char *newdbref);
159   dbref do_real_open(dbref player, const char *direction,
160                      const char *linkto, dbref pseudo);
161   void do_open(dbref player, const char *direction, char **links);
162 ***************
163 *** 654,659 ****
164 --- 654,660 ----
165   /* From destroy.c */
166       void do_undestroy(dbref player, char *name);
167       dbref free_get(void);
168 +     int make_first_free(dbref object);
169       void fix_free_list(void);
170       void purge(void);
171       void do_purge(dbref player);
172 *** src/function.c.orig Fri Jun  6 02:32:50 2008
173 --- src/function.c  Fri Jun  6 02:36:03 2008
174 ***************
175 *** 380,386 ****
176     {"CONVUTCSECS", fun_convsecs, 1, 1, FN_REG},
177     {"CONVTIME", fun_convtime, 1, 1, FN_REG},
178     {"COR", fun_cor, 2, INT_MAX, FN_NOPARSE},
179 !   {"CREATE", fun_create, 1, 2, FN_REG},
180     {"CSECS", fun_csecs, 1, 1, FN_REG},
181     {"CTIME", fun_ctime, 1, 2, FN_REG},
182     {"DEC", fun_dec, 1, 1, FN_REG},
183 --- 380,386 ----
184     {"CONVUTCSECS", fun_convsecs, 1, 1, FN_REG},
185     {"CONVTIME", fun_convtime, 1, 1, FN_REG},
186     {"COR", fun_cor, 2, INT_MAX, FN_NOPARSE},
187 !   {"CREATE", fun_create, 1, 3, FN_REG},
188     {"CSECS", fun_csecs, 1, 1, FN_REG},
189     {"CTIME", fun_ctime, 1, 2, FN_REG},
190     {"DEC", fun_dec, 1, 1, FN_REG},
191 *** src/fundb.c.orig    Mon Jul  9 04:50:12 2007
192 --- src/fundb.c Fri Jun  6 02:35:39 2008
193 ***************
194 *** 1955,1961 ****
195       cost = parse_integer(args[1]);
196     else
197       cost = OBJECT_COST;
198 !   safe_dbref(do_create(executor, args[0], cost), buff, bp);
199   }
200  
201   /* ARGSUSED */
202 --- 1955,1961 ----
203       cost = parse_integer(args[1]);
204     else
205       cost = OBJECT_COST;
206 !   safe_dbref(do_create(executor, args[0], cost, args[2]), buff, bp);
207   }
208  
209   /* ARGSUSED */
210 *** game/txt/hlp/penncmd.hlp.orig   Fri Oct  5 23:36:32 2007
211 --- game/txt/hlp/penncmd.hlp    Fri Jun  6 02:39:02 2008
212 ***************
213 *** 811,817 ****
214  
215   See also: ATTRIBUTES, NON-STANDARD ATTRIBUTES
216   & @create
217 !   @create <name> [=<cost>]
218  
219     Creates a thing with the specified name. Creating a thing costs
220     a certain amount of MUSH money, which usually defaults to 10 pennies.
221 --- 811,817 ----
222  
223   See also: ATTRIBUTES, NON-STANDARD ATTRIBUTES
224   & @create
225 !   @create <name>[=<cost>[,<dbref>]]
226  
227     Creates a thing with the specified name. Creating a thing costs
228     a certain amount of MUSH money, which usually defaults to 10 pennies.
229 ***************
230 *** 821,826 ****
231 --- 821,830 ----
232     Once you have created a thing, you can use it as a PUPPET, to store
233     USER-DEFINED COMMANDS, or just as a prop. Some MUSHes choose to limit
234     the number of objects that players can create by setting a QUOTA.
235 +   
236 +   Wizards can also specify the dbref of a garbage object to use when
237 +   creating the object. Otherwise, the object is given the next
238 +   available dbref.
239    
240   See also: give, @quota, MONEY
241   & @dbck
242 *** game/txt/hlp/pennfunc.hlp.orig  Fri Oct  5 23:36:32 2007
243 --- game/txt/hlp/pennfunc.hlp   Fri Jun  6 02:39:42 2008
244 ***************
245 *** 874,883 ****
246  
247   See also: @pcreate
248   & CREATE()
249 !   create(<object>, <cost>)
250    
251     This function creates an object with name <object> for <cost> pennies,
252 !   and returns the dbref number of the created object.
253  
254     This is a side-effect function and may not be enabled on some MUSHes.
255   & CTIME()
256 --- 874,884 ----
257  
258   See also: @pcreate
259   & CREATE()
260 !   create(<object>[, <cost>[, <dbref>]])
261    
262     This function creates an object with name <object> for <cost> pennies,
263 !   and returns the dbref number of the created object. Wizards may also
264 !   specify a <dbref>, as per @create.
265  
266     This is a side-effect function and may not be enabled on some MUSHes.
267   & CTIME()