diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/map/script.c | 4 | ||||
-rw-r--r-- | src/map/utils/formatutils.c | 105 | ||||
-rw-r--r-- | src/map/utils/formatutils.h | 9 |
4 files changed, 118 insertions, 2 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index e46f894..b73454d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -37,6 +37,8 @@ MAP_SRC = map/clif.c \ map/session.c \ map/session.h \ map/sessionext.h \ + map/utils/formatutils.c \ + map/utils/formatutils.h \ common/interfaces.c \ common/interfaces.h diff --git a/src/map/script.c b/src/map/script.c index 3b09e88..7c53e8e 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -23,11 +23,11 @@ #include "map/send.h" #include "map/session.h" #include "map/sessionext.h" +#include "map/utils/formatutils.h" BUILDIN(l) { - // for now not translate and not use format parameters - script_pushstr(st, aStrdup(script_getstr(st, 2))); + format_sub(st, 1); return true; } diff --git a/src/map/utils/formatutils.c b/src/map/utils/formatutils.c new file mode 100644 index 0000000..741b2a9 --- /dev/null +++ b/src/map/utils/formatutils.c @@ -0,0 +1,105 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "../../../../common/HPMi.h" +#include "../../../../common/malloc.h" +#include "../../../../common/mmo.h" +#include "../../../../common/socket.h" +#include "../../../../common/strlib.h" +#include "../../../../map/script.h" + +#include "../../../../map/chrif.h" +#include "../../../../map/clif.h" +#include "../../../../map/npc.h" +#include "../../../../map/pc.h" +#include "../../../../map/script.h" +#include "../../../../map/quest.h" + +#include "map/utils/formatutils.h" +#include "map/lang.h" + +int format_sub(struct script_state* st, int translate) +{ + TBL_PC *sd = NULL; + if (translate) + sd = script->rid2sd(st); + + if (!script_hasdata(st, 3)) + { + if (sd) + { + if (translate == 2) + { + char *buf = aCalloc (strlen(script_getstr(st, 2)) + 3, sizeof(char)); + strcpy (buf, script_getstr(st, 2)); + if (sd->status.sex) + strcat (buf, "#1"); + else + strcat (buf, "#0"); + script_pushstr(st, aStrdup(lang_pctrans(buf, sd))); + aFree (buf); + } + else + { + script_pushstr(st, aStrdup(lang_pctrans(script_getstr(st, 2), sd))); + } + } + else + { + script_pushstr(st, aStrdup(script_getstr(st, 2))); + } + return 1; + } + + char *line = (char *) aCalloc (550, sizeof (char)); + if (sd) + { + if (translate == 2) + { + char *buf = aCalloc (strlen(script_getstr(st, 2)) + 3, sizeof(char)); + strcpy (buf, script_getstr(st, 2)); + if (sd->status.sex) + strcat (buf, "#1"); + else + strcat (buf, "#0"); + strcpy(line, lang_pctrans(buf, sd)); + aFree (buf); + } + else + { + strcpy(line, lang_pctrans(script_getstr(st, 2), sd)); + } + } + else + { + strcpy(line, script_getstr(st, 2)); + } + + char *ptr = line; + int idx = 3; + int sz = strlen(line); + while (script_hasdata(st, idx)) + { + char *tmp = strstr(ptr, "@@"); + if (!tmp) + break; + char *item = script_getstr(st, idx); + int len = strlen(item); + if (len > 50) + break; + sz += len - 2; + if (sz > 490) + break; + memmove(tmp + len, tmp + 2, strlen(tmp + 2)); + memcpy(tmp, item, len); + ptr = tmp + len; + idx ++; + } + + script_pushstr(st, line); + return 0; +} diff --git a/src/map/utils/formatutils.h b/src/map/utils/formatutils.h new file mode 100644 index 0000000..361ad84 --- /dev/null +++ b/src/map/utils/formatutils.h @@ -0,0 +1,9 @@ +// Copyright (c) Copyright (c) Hercules Dev Team, licensed under GNU GPL. +// Copyright (c) 2014 Evol developers + +#ifndef EVOL_MAP_UTILS_FORMATUTILS +#define EVOL_MAP_UTILS_FORMATUTILS + +int format_sub(struct script_state* st, int translate); + +#endif // EVOL_MAP_UTILS_FORMATUTILS |