2 * nazghul - an old-school RPG engine
3 * Copyright (C) 2007 Gordon McNutt
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Foundation, Inc., 59 Temple Place,
17 * Suite 330, Boston, MA 02111-1307 USA
20 * gmcnutt@users.sourceforge.net
28 //#ifdef HAVE_MALLOC_H
33 static void skill_del(struct skill *skill)
37 assert(!skill->refcount);
45 closure_unref(skill->yuse);
47 if (skill->can_yuse) {
48 closure_unref(skill->can_yuse);
51 /* delete the list of tools */
52 node_list_unlink_and_unref(&skill->tools);
54 /* delete the list of materials */
55 elem = skill->materials.next;
56 while (elem != &skill->materials) {
57 struct list *tmp = elem->next;
65 struct skill *skill_new(void)
67 struct skill *skill = (struct skill*)calloc(1, sizeof(*skill));
69 list_init(&skill->list);
70 node_init(&skill->tools);
71 list_init(&skill->materials);
76 void skill_set_name(struct skill *skill, char *val)
82 skill->name = strdup(val);
86 void skill_set_desc(struct skill *skill, char *val)
92 skill->desc = strdup(val);
96 void skill_ref(struct skill *skill)
101 void skill_unref(struct skill *skill)
103 assert(skill->refcount > 0);
105 if (!skill->refcount) {
110 void skill_add_tool(struct skill *skill, void *objtype)
112 struct node *node = node_new(objtype);
113 node_add(&skill->tools, node);
116 void skill_add_material(struct skill *skill, void *objtype, int quan)
118 struct skill_material *mat;
119 mat = (struct skill_material*)calloc(1, sizeof(*mat));
121 mat->objtype = objtype;
122 mat->quantity = quan;
123 list_add(&skill->materials, &mat->list);