diff options
-rw-r--r-- | src/emap/craft.c | 31 | ||||
-rw-r--r-- | src/emap/craft.h | 1 | ||||
-rw-r--r-- | src/emap/init.c | 1 | ||||
-rw-r--r-- | src/emap/script.c | 8 | ||||
-rw-r--r-- | src/emap/script.h | 1 |
5 files changed, 36 insertions, 6 deletions
diff --git a/src/emap/craft.c b/src/emap/craft.c index 69f2547..c790836 100644 --- a/src/emap/craft.c +++ b/src/emap/craft.c @@ -32,20 +32,27 @@ void do_init_craft(void) craftvar_db = idb_alloc(DB_OPT_RELEASE_BOTH); } -static int delete_craft_sub(DBKey key __attribute__ ((unused)), - DBData *data, - va_list args __attribute__ ((unused))) +static void delete_craft_var(struct craft_vardata *craft) { - struct craft_vardata *craft = DB->data2ptr(data); if (!craft) - return 0; - + return; int index; for (index = 0; index < craft_inventory_size; index ++) { struct craft_slot *slot = &craft->slots[index]; VECTOR_CLEAR(slot->items); } +} + +static int delete_craft_sub(DBKey key __attribute__ ((unused)), + DBData *data, + va_list args __attribute__ ((unused))) +{ + struct craft_vardata *craft = DB->data2ptr(data); + if (!craft) + return 0; + + delete_craft_var(craft); return 0; } @@ -255,3 +262,15 @@ void craft_dump(TBL_PC *sd, const int id) } } } + +void craft_delete(const int id) +{ + struct craft_vardata *craft = idb_get(craftvar_db, id); + if (!craft) + { + ShowError("Craft object with id %d not exists.\n", id); + return; + } + delete_craft_var(craft); + idb_remove(craftvar_db, id); +} diff --git a/src/emap/craft.h b/src/emap/craft.h index 1930763..fd9c3d2 100644 --- a/src/emap/craft.h +++ b/src/emap/craft.h @@ -32,5 +32,6 @@ bool craft_checkstr(TBL_PC *sd, const char *craftstr); int str_to_craftvar(TBL_PC *sd, const char *craftstr); struct craft_vardata *craft_str_to_craft(const char *craftstr); void craft_dump(TBL_PC *sd, const int id); +void craft_delete(const int id); #endif // EVOL_MAP_CRAFT diff --git a/src/emap/init.c b/src/emap/init.c index 18b5dfc..6719503 100644 --- a/src/emap/init.c +++ b/src/emap/init.c @@ -102,6 +102,7 @@ HPExport void plugin_init (void) addScriptCommand("requestcraft", "v*", requestCraft); addScriptCommand("initcraft", "s", initCraft); addScriptCommand("dumpcraft", "i", dumpCraft); + addScriptCommand("deletecraft", "i", deleteCraft); addScriptCommand("getq", "i", getq); addScriptCommand("setq", "ii", setq); addScriptCommand("setnpcdir", "*", setNpcDir); diff --git a/src/emap/script.c b/src/emap/script.c index 9df0e14..6cf911c 100644 --- a/src/emap/script.c +++ b/src/emap/script.c @@ -1887,3 +1887,11 @@ BUILDIN(dumpCraft) craft_dump(sd, script_getnum(st, 2)); return true; } + +BUILDIN(deleteCraft) +{ + getSD() + + craft_delete(script_getnum(st, 2)); + return true; +} diff --git a/src/emap/script.h b/src/emap/script.h index 3b0548e..1c4b846 100644 --- a/src/emap/script.h +++ b/src/emap/script.h @@ -67,5 +67,6 @@ BUILDIN(delCells); BUILDIN(setSkin); BUILDIN(initCraft); BUILDIN(dumpCraft); +BUILDIN(deleteCraft); #endif // EVOL_MAP_SCRIPT |