diff options
author | Haru <haru@dotalux.com> | 2013-08-27 08:08:34 +0200 |
---|---|---|
committer | Haru <haru@dotalux.com> | 2013-11-05 04:17:39 +0100 |
commit | 97001710c06ed7053d18c8baaac602eb563b64b3 (patch) | |
tree | a4f08884917a5934e9b7ba66b39cd5e25db92e54 /src/map/npc.c | |
parent | 0a5abb6de766be6a5068da08eb6477e343f2d7b3 (diff) | |
download | hercules-97001710c06ed7053d18c8baaac602eb563b64b3.tar.gz hercules-97001710c06ed7053d18c8baaac602eb563b64b3.tar.bz2 hercules-97001710c06ed7053d18c8baaac602eb563b64b3.tar.xz hercules-97001710c06ed7053d18c8baaac602eb563b64b3.zip |
Introducing the Hercules Standalone Script Syntax Checker
- Added a command line argument '--script-check' to check a script's
syntax without running the server (and without requiring a SQL
connection). Usage: ./map-server --script-check /path/to/the/script.txt
- For convenience, a script-checker bash script is provided, to set the
path correctly when called from a different directory. Usage:
/path/to/Hercules/script-checker /path/to/the/script/to/check.txt
- While the script checker will supposedly work under windows as well,
no convenience scripts are currently provided for platforms other than
UNIX (feel free to open a pull request with a .bat launcher or
whatever you like)
- Integration with IDEs or text editors is possible. In fact, I already
have a fully functional plugin for vim (through vim-syntastic), and if
there's enough interest, I'll publish it. - screenshot: http://d.pr/i/NOBD
- If you want an online checker, http://haru.ws/scriptchecker/ is
running this code, without modifications and will be kept up to date
(without any warranty though.)
- Special thanks to Ind, Yommy, Streusel, who helped making this
possible, in a way or another.
Diffstat (limited to 'src/map/npc.c')
-rw-r--r-- | src/map/npc.c | 69 |
1 files changed, 36 insertions, 33 deletions
diff --git a/src/map/npc.c b/src/map/npc.c index d78b3f8d4..9330d59d3 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1253,6 +1253,7 @@ int npc_buysellsel(struct map_session_data* sd, int id, int type) { } return 0; } + /*========================================== * Cash Shop Buy List *------------------------------------------*/ @@ -3498,8 +3499,7 @@ const char* npc_parse_mapflag(char* w1, char* w2, char* w3, char* w4, const char //Read file and create npc/func/mapflag/monster... accordingly. //@runOnInit should we exec OnInit when it's done ? -void npc_parsesrcfile(const char* filepath, bool runOnInit) -{ +int npc_parsesrcfile(const char* filepath, bool runOnInit) { int16 m, x, y; int lines = 0; FILE* fp; @@ -3512,7 +3512,7 @@ void npc_parsesrcfile(const char* filepath, bool runOnInit) if( fp == NULL ) { ShowError("npc_parsesrcfile: File not found '%s'.\n", filepath); - return; + return -1; } fseek(fp, 0, SEEK_END); len = ftell(fp); @@ -3525,7 +3525,7 @@ void npc_parsesrcfile(const char* filepath, bool runOnInit) ShowError("npc_parsesrcfile: Failed to read file '%s' - %s\n", filepath, strerror(errno)); aFree(buffer); fclose(fp); - return; + return -1; } fclose(fp); @@ -3660,7 +3660,7 @@ void npc_parsesrcfile(const char* filepath, bool runOnInit) } aFree(buffer); - return; + return 0; } int npc_script_event(struct map_session_data* sd, enum npce_event type) @@ -3937,8 +3937,7 @@ static void npc_debug_warps(void) { /*========================================== * npc initialization *------------------------------------------*/ -int do_init_npc(void) -{ +int do_init_npc(bool minimal) { struct npc_src_list *file; int i; @@ -3965,43 +3964,47 @@ int do_init_npc(void) npc->name_db = strdb_alloc(DB_OPT_BASE, NAME_LENGTH); npc->path_db = strdb_alloc(DB_OPT_DUP_KEY|DB_OPT_RELEASE_DATA, 0); - npc->timer_event_ers = ers_new(sizeof(struct timer_event_data),"clif.c::timer_event_ers",ERS_OPT_NONE); - npc_last_npd = NULL; npc_last_path = NULL; npc_last_ref = NULL; - // process all npc files - ShowStatus("Loading NPCs...\r"); - for( file = npc->src_files; file != NULL; file = file->next ) { - ShowStatus("Loading NPC file: %s"CL_CLL"\r", file->name); - npc->parsesrcfile(file->name,false); + if (!minimal) { + npc->timer_event_ers = ers_new(sizeof(struct timer_event_data),"clif.c::timer_event_ers",ERS_OPT_NONE); + + // process all npc files + ShowStatus("Loading NPCs...\r"); + for( file = npc->src_files; file != NULL; file = file->next ) { + ShowStatus("Loading NPC file: %s"CL_CLL"\r", file->name); + npc->parsesrcfile(file->name,false); + } + ShowInfo ("Done loading '"CL_WHITE"%d"CL_RESET"' NPCs:"CL_CLL"\n" + "\t-'"CL_WHITE"%d"CL_RESET"' Warps\n" + "\t-'"CL_WHITE"%d"CL_RESET"' Shops\n" + "\t-'"CL_WHITE"%d"CL_RESET"' Scripts\n" + "\t-'"CL_WHITE"%d"CL_RESET"' Spawn sets\n" + "\t-'"CL_WHITE"%d"CL_RESET"' Mobs Cached\n" + "\t-'"CL_WHITE"%d"CL_RESET"' Mobs Not Cached\n", + npc_id - START_NPC_NUM, npc_warp, npc_shop, npc_script, npc_mob, npc_cache_mob, npc_delay_mob); } - ShowInfo ("Done loading '"CL_WHITE"%d"CL_RESET"' NPCs:"CL_CLL"\n" - "\t-'"CL_WHITE"%d"CL_RESET"' Warps\n" - "\t-'"CL_WHITE"%d"CL_RESET"' Shops\n" - "\t-'"CL_WHITE"%d"CL_RESET"' Scripts\n" - "\t-'"CL_WHITE"%d"CL_RESET"' Spawn sets\n" - "\t-'"CL_WHITE"%d"CL_RESET"' Mobs Cached\n" - "\t-'"CL_WHITE"%d"CL_RESET"' Mobs Not Cached\n", - npc_id - START_NPC_NUM, npc_warp, npc_shop, npc_script, npc_mob, npc_cache_mob, npc_delay_mob); itemdb->name_constants(); + + if (!minimal) { + map->zone_init(); - map->zone_init(); - - npc->motd = npc->name2id("HerculesMOTD"); /* [Ind/Hercules] */ + npc->motd = npc->name2id("HerculesMOTD"); /* [Ind/Hercules] */ - // set up the events cache - memset(script_event, 0, sizeof(script_event)); - npc->read_event_script(); + // set up the events cache + memset(script_event, 0, sizeof(script_event)); + npc->read_event_script(); - //Debug function to locate all endless loop warps. - if (battle_config.warp_point_debug) - npc->debug_warps(); + //Debug function to locate all endless loop warps. + if (battle_config.warp_point_debug) + npc->debug_warps(); - timer->add_func_list(npc->event_do_clock,"npc_event_do_clock"); - timer->add_func_list(npc->timerevent,"npc_timerevent"); + timer->add_func_list(npc->event_do_clock,"npc_event_do_clock"); + timer->add_func_list(npc->timerevent,"npc_timerevent"); + } // Init dummy NPC npc->fake_nd = (struct npc_data *)aCalloc(1,sizeof(struct npc_data)); |