summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2016-01-25 23:38:17 +0300
committerAndrei Karas <akaras@inbox.ru>2016-01-25 23:38:17 +0300
commitd062c9fba109a3821e67e4e6c6cabd772b8c2bf5 (patch)
tree5be63aad33baa61916428443d1477d7e5bff59bc /src
parentb77735473db348a65b749a79549852713f142dc1 (diff)
parent15bca8fb8a113a030b5dfad1fcb146005a7e4d9d (diff)
downloadhercules-d062c9fba109a3821e67e4e6c6cabd772b8c2bf5.tar.gz
hercules-d062c9fba109a3821e67e4e6c6cabd772b8c2bf5.tar.bz2
hercules-d062c9fba109a3821e67e4e6c6cabd772b8c2bf5.tar.xz
hercules-d062c9fba109a3821e67e4e6c6cabd772b8c2bf5.zip
Merge pull request #1124 from MishimaHaruna/constdb2doc
Constdb2doc plugin (doc/constants.md)
Diffstat (limited to 'src')
-rw-r--r--src/map/script.c40
-rw-r--r--src/map/script.h1
-rw-r--r--src/plugins/constdb2doc.c197
3 files changed, 231 insertions, 7 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 5a3d1507f..ca53b6f6d 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2322,6 +2322,15 @@ void read_constdb(void)
ShowWarning("read_constdb: Invalid constant name %s. Skipping.\n", name);
continue;
}
+ if (strcmp(name, "comment__") == 0) {
+ const char *comment = libconfig->setting_get_string(t);
+ if (comment == NULL)
+ continue;
+ if (*comment == '\0')
+ comment = NULL;
+ script->constdb_comment(comment);
+ continue;
+ }
if (config_setting_is_aggregate(t)) {
int i32;
if (!libconfig->setting_lookup_int(t, "Value", &i32)) {
@@ -2342,9 +2351,22 @@ void read_constdb(void)
}
script->set_constant(name, value, is_parameter, is_deprecated);
}
+ script->constdb_comment(NULL);
libconfig->destroy(&constants_conf);
}
+/**
+ * Sets the current constdb comment.
+ *
+ * This function does nothing (used by plugins only)
+ *
+ * @param comment The comment to set (NULL to unset)
+ */
+void script_constdb_comment(const char *comment)
+{
+ (void)comment;
+}
+
// Standard UNIX tab size is 8
#define TAB_SIZE 8
#define update_tabstop(tabstop,chars) \
@@ -20820,9 +20842,11 @@ void script_label_add(int key, int pos) {
**/
void script_hardcoded_constants(void)
{
+ script->constdb_comment("Boolean");
script->set_constant("true", 1, false, false);
script->set_constant("false", 0, false, false);
- /* server defines */
+
+ script->constdb_comment("Server defines");
script->set_constant("PACKETVER",PACKETVER,false, false);
script->set_constant("MAX_LEVEL",MAX_LEVEL,false, false);
script->set_constant("MAX_STORAGE",MAX_STORAGE,false, false);
@@ -20834,7 +20858,7 @@ void script_hardcoded_constants(void)
script->set_constant("MAX_CHAT_USERS",MAX_CHAT_USERS,false, false);
script->set_constant("MAX_REFINE",MAX_REFINE,false, false);
- /* status options */
+ script->constdb_comment("status options");
script->set_constant("Option_Nothing",OPTION_NOTHING,false, false);
script->set_constant("Option_Sight",OPTION_SIGHT,false, false);
script->set_constant("Option_Hide",OPTION_HIDE,false, false);
@@ -20860,11 +20884,11 @@ void script_hardcoded_constants(void)
script->set_constant("Option_Hanbok",OPTION_HANBOK,false, false);
script->set_constant("Option_Oktoberfest",OPTION_OKTOBERFEST,false, false);
- /* status option compounds */
+ script->constdb_comment("status option compounds");
script->set_constant("Option_Dragon",OPTION_DRAGON,false, false);
script->set_constant("Option_Costume",OPTION_COSTUME,false, false);
- /* send_target */
+ script->constdb_comment("send_target");
script->set_constant("ALL_CLIENT",ALL_CLIENT,false, false);
script->set_constant("ALL_SAMEMAP",ALL_SAMEMAP,false, false);
script->set_constant("AREA",AREA,false, false);
@@ -20898,7 +20922,7 @@ void script_hardcoded_constants(void)
script->set_constant("BG_AREA_WOS",BG_AREA_WOS,false, false);
script->set_constant("BG_QUEUE",BG_QUEUE,false, false);
- /* LOOK_ constants, use in setlook/changelook script commands */
+ script->constdb_comment("LOOK_ constants, use in setlook/changelook script commands");
script->set_constant("LOOK_BASE", LOOK_BASE, false, false);
script->set_constant("LOOK_HAIR", LOOK_HAIR, false, false);
script->set_constant("LOOK_WEAPON", LOOK_WEAPON, false, false);
@@ -20914,7 +20938,7 @@ void script_hardcoded_constants(void)
script->set_constant("LOOK_ROBE", LOOK_ROBE, false, false);
script->set_constant("LOOK_BODY2", LOOK_BODY2, false, false);
- /* Equip Position in Bits, use with *getiteminfo type 5, or @inventorylist_equip */
+ script->constdb_comment("Equip Position in Bits, use with *getiteminfo type 5, or @inventorylist_equip");
script->set_constant("EQP_HEAD_LOW", EQP_HEAD_LOW, false, false);
script->set_constant("EQP_HEAD_MID", EQP_HEAD_MID, false, false);
script->set_constant("EQP_HEAD_TOP", EQP_HEAD_TOP, false, false);
@@ -20937,7 +20961,7 @@ void script_hardcoded_constants(void)
script->set_constant("EQP_SHADOW_ACC_R", EQP_SHADOW_ACC_R, false, false);
script->set_constant("EQP_SHADOW_ACC_L", EQP_SHADOW_ACC_L, false, false);
- /* Renewal */
+ script->constdb_comment("Renewal");
#ifdef RENEWAL
script->set_constant("RENEWAL", 1, false, false);
#else
@@ -20973,6 +20997,7 @@ void script_hardcoded_constants(void)
#else
script->set_constant("RENEWAL_ASPD", 0, false, false);
#endif
+ script->constdb_comment(NULL);
}
/**
@@ -21150,6 +21175,7 @@ void script_defaults(void) {
script->parse_expr = parse_expr;
script->parse_line = parse_line;
script->read_constdb = read_constdb;
+ script->constdb_comment = script_constdb_comment;
script->print_line = script_print_line;
script->errorwarning_sub = script_errorwarning_sub;
script->set_reg = set_reg;
diff --git a/src/map/script.h b/src/map/script.h
index dbb0f8a03..e6164092e 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -726,6 +726,7 @@ struct script_interface {
const char* (*parse_expr) (const char *p);
const char* (*parse_line) (const char *p);
void (*read_constdb) (void);
+ void (*constdb_comment) (const char *comment);
const char* (*print_line) (StringBuf *buf, const char *p, const char *mark, int line);
void (*errorwarning_sub) (StringBuf *buf, const char *src, const char *file, int start_line, const char *error_msg, const char *error_pos);
int (*set_reg) (struct script_state *st, struct map_session_data *sd, int64 num, const char *name, const void *value, struct reg_db *ref);
diff --git a/src/plugins/constdb2doc.c b/src/plugins/constdb2doc.c
new file mode 100644
index 000000000..1d5f37ad5
--- /dev/null
+++ b/src/plugins/constdb2doc.c
@@ -0,0 +1,197 @@
+/**
+ * This file is part of Hercules.
+ * http://herc.ws - http://github.com/HerculesWS/Hercules
+ *
+ * Copyright (C) 2016 Hercules Dev Team
+ * Copyright (C) 2016 Haru <haru@dotalux.com>
+ *
+ * Hercules is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/// db/constants.conf -> doc/constants.md generator plugin
+
+#include "common/hercules.h"
+//#include "common/memmgr.h"
+#include "common/nullpo.h"
+#include "common/strlib.h"
+#include "map/itemdb.h"
+#include "map/mob.h"
+#include "map/script.h"
+#include "map/skill.h"
+
+#include "common/HPMDataCheck.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <sys/stat.h>
+
+#define OUTPUTFILENAME "doc" PATHSEP_STR "constants.md"
+
+HPExport struct hplugin_info pinfo = {
+ "constdb2doc", // Plugin name
+ SERVER_TYPE_MAP, // Which server types this plugin works with?
+ "0.1", // Plugin version
+ HPM_VERSION, // HPM Version (don't change, macro is automatically updated)
+};
+
+FILE *out_fp;
+bool torun = false;
+
+/// To override script_constdb_comment
+void constdb2doc_constdb_comment(const char *comment)
+{
+ nullpo_retv(out_fp);
+ if (comment == NULL)
+ fprintf(out_fp, "\n");
+ else
+ fprintf(out_fp, "\n### %s\n\n", comment);
+}
+
+/// To override script_set_constant, called by script_read_constdb
+void constdb2doc_script_set_constant(const char *name, int value, bool is_parameter, bool is_deprecated)
+{
+ nullpo_retv(out_fp);
+
+ if (is_parameter)
+ fprintf(out_fp, "- `%s`: [param]%s\n", name, is_deprecated ? " **(DEPRECATED)**" : "");
+ else
+ fprintf(out_fp, "- `%s`: %d%s\n", name, value, is_deprecated ? " **(DEPRECATED)**" : "");
+}
+
+void constdb2doc_constdb(void)
+{
+ void (*script_set_constant) (const char* name, int value, bool is_parameter, bool is_deprecated) = NULL;
+ void (*script_constdb_comment) (const char *comment) = NULL;
+
+ nullpo_retv(out_fp);
+
+ /* Link */
+ script_set_constant = script->set_constant;
+ script->set_constant = constdb2doc_script_set_constant;
+ script_constdb_comment = script->constdb_comment;
+ script->constdb_comment = constdb2doc_constdb_comment;
+
+ /* Run */
+ fprintf(out_fp, "## Constants (db/constants.conf)\n\n");
+ script->read_constdb();
+ fprintf(out_fp, "\n");
+
+ fprintf(out_fp, "## Hardcoded Constants (source)\n\n");
+ script->hardcoded_constants();
+ fprintf(out_fp, "\n");
+
+ /* Unlink */
+ script->set_constant = script_set_constant;
+ script->constdb_comment = script_constdb_comment;
+}
+
+void constdb2doc_skilldb(void)
+{
+ int i;
+
+ nullpo_retv(out_fp);
+
+ fprintf(out_fp, "## Skills (db/"DBPATH"skill_db.txt)\n\n");
+ for (i = 1; i < MAX_SKILL_DB; i++) {
+ if (skill->dbs->db[i].name[0] != '\0')
+ fprintf(out_fp, "- `%s`: %d\n", skill->dbs->db[i].name, skill->dbs->db[i].nameid);
+ }
+ fprintf(out_fp, "\n");
+}
+
+void constdb2doc_mobdb(void)
+{
+ int i;
+
+ nullpo_retv(out_fp);
+
+ fprintf(out_fp, "## Mobs (db/"DBPATH"mob_db.txt)\n\n");
+ for (i = 0; i < MAX_MOB_DB; i++) {
+ struct mob_db *md = mob->db(i);
+ if (md == mob->dummy || md->sprite[0] == '\0')
+ continue;
+ fprintf(out_fp, "- `%s`: %d\n", md->sprite, i);
+ }
+ fprintf(out_fp, "\n");
+}
+
+/// Cloned from itemdb_search
+struct item_data *constdb2doc_itemdb_search(int nameid)
+{
+ if (nameid >= 0 && nameid < ARRAYLENGTH(itemdb->array))
+ return itemdb->array[nameid];
+
+ return idb_get(itemdb->other, nameid);
+}
+
+void constdb2doc_itemdb(void)
+{
+ int i;
+
+ nullpo_retv(out_fp);
+
+ fprintf(out_fp, "## Items (db/"DBPATH"item_db.conf)\n");
+ for (i = 0; i < ARRAYLENGTH(itemdb->array); i++) {
+ struct item_data *id = constdb2doc_itemdb_search(i);
+ if (id == NULL || id->name[0] == '\0')
+ continue;
+ fprintf(out_fp, "- `%s`: %d\n", id->name, id->nameid);
+ }
+ fprintf(out_fp, "\n");
+}
+
+void do_constdb2doc(void)
+{
+ /* File Type Detector */
+ if ((out_fp = fopen(OUTPUTFILENAME, "wt+")) == NULL) {
+ ShowError("do_constdb2doc: Unable to open output file.\n");
+ return;
+ }
+
+ fprintf(out_fp,
+ "# Constants\n\n"
+ "> This document contains all the constants available to the script engine.\n\n");
+
+ constdb2doc_constdb();
+
+ constdb2doc_skilldb();
+
+ constdb2doc_mobdb();
+
+ constdb2doc_itemdb();
+
+ fprintf(out_fp, "> End of list\n");
+
+ fclose(out_fp);
+}
+CPCMD(constdb2doc) {
+ do_constdb2doc();
+}
+CMDLINEARG(constdb2doc)
+{
+ map->minimal = torun = true;
+ return true;
+}
+HPExport void server_preinit(void) {
+ addArg("--constdb2doc", false, constdb2doc, NULL);
+}
+HPExport void plugin_init(void) {
+ addCPCommand("server:tools:constdb2doc", constdb2doc);
+}
+HPExport void server_online(void) {
+ if (torun)
+ do_constdb2doc();
+}