summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2018-08-26 17:01:00 +0200
committerGitHub <noreply@github.com>2018-08-26 17:01:00 +0200
commit0630ea01ef687ba22f4600a2f32fb4d3e448dcb8 (patch)
treefc4889ced078a4b11ea5b507ee0b0eee3e7b9942 /src
parentadae3d4518a4eae5424a3bbff40d11d3eb90a52a (diff)
parent3a8705a28c5c9577e5a86584224d6252d0620ed8 (diff)
downloadhercules-0630ea01ef687ba22f4600a2f32fb4d3e448dcb8.tar.gz
hercules-0630ea01ef687ba22f4600a2f32fb4d3e448dcb8.tar.bz2
hercules-0630ea01ef687ba22f4600a2f32fb4d3e448dcb8.tar.xz
hercules-0630ea01ef687ba22f4600a2f32fb4d3e448dcb8.zip
Merge pull request #2162 from mekolat/setzone
add atcommand_setzone, and fix #2133
Diffstat (limited to 'src')
-rw-r--r--src/map/atcommand.c61
-rw-r--r--src/map/map.c28
-rw-r--r--src/map/map.h1
-rw-r--r--src/map/npc.c1
4 files changed, 90 insertions, 1 deletions
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index bedb58478..02b099742 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -1887,6 +1887,63 @@ ACMD(hair_color)
return true;
}
+ACMD(setzone)
+{
+ char zone_name[MAP_ZONE_MAPFLAG_LENGTH];
+ memset(zone_name, '\0', sizeof(zone_name));
+
+ char fmt_str[8] = "";
+ safesnprintf(fmt_str, 8, "%%%ds", MAP_ZONE_MAPFLAG_LENGTH - 1);
+
+ if (*message == '\0' || sscanf(message, fmt_str, zone_name) < 1) {
+ clif->message(fd, msg_fd(fd, 924)); // usage info
+ return false;
+ }
+
+ struct map_zone_data *zone = strdb_get(map->zone_db, zone_name);
+ const char *prev_zone_name = map->list[sd->bl.m].zone->name;
+
+ // handle special zones:
+ if (zone == NULL && strcmp(zone_name, MAP_ZONE_NORMAL_NAME) == 0) {
+ zone = &map->zone_all;
+ } else if (zone == NULL && strcmp(zone_name, MAP_ZONE_PK_NAME) == 0) {
+ zone = &map->zone_pk;
+ }
+
+ if (zone != NULL) {
+ if (map->list[sd->bl.m].zone != zone) {
+ if (strcmp(prev_zone_name, MAP_ZONE_PVP_NAME) == 0) {
+ atcommand_pvpoff(fd, sd, command, message, info);
+ } else if (strcmp(prev_zone_name, MAP_ZONE_GVG_NAME) == 0) {
+ atcommand_gvgoff(fd, sd, command, message, info);
+ } else if (strcmp(prev_zone_name, MAP_ZONE_CVC_NAME) == 0) {
+ atcommand_cvcoff(fd, sd, command, message, info);
+ }
+ } else {
+ safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 925), zone_name);
+ clif->message(fd, atcmd_output); // nothing to do
+ return false;
+ }
+
+ if (strcmp(zone_name, MAP_ZONE_PVP_NAME) == 0) {
+ atcommand_pvpon(fd, sd, command, message, info);
+ } else if (strcmp(zone_name, MAP_ZONE_GVG_NAME) == 0) {
+ atcommand_gvgon(fd, sd, command, message, info);
+ } else if (strcmp(zone_name, MAP_ZONE_CVC_NAME) == 0) {
+ atcommand_cvcon(fd, sd, command, message, info);
+ } else {
+ map->zone_change2(sd->bl.m, zone);
+ }
+ } else {
+ clif->message(fd, msg_fd(fd, 926)); // zone not found
+ return false;
+ }
+
+ safesnprintf(atcmd_output, sizeof(atcmd_output), msg_fd(fd, 927), prev_zone_name, zone_name);
+ clif->message(fd, atcmd_output); // changed successfully
+ return true;
+}
+
/*==========================================
* @go [city_number or city_name] - Updated by Harbin
*------------------------------------------*/
@@ -7688,7 +7745,7 @@ ACMD(mapflag)
CHECKFLAG(nojobexp); CHECKFLAG(nomobloot); CHECKFLAG(nomvploot); CHECKFLAG(nightenabled);
CHECKFLAG(nodrop); CHECKFLAG(novending); CHECKFLAG(loadevent);
CHECKFLAG(nochat); CHECKFLAG(partylock); CHECKFLAG(guildlock); CHECKFLAG(src4instance);
- CHECKFLAG(notomb); CHECKFLAG(nocashshop); CHECKFLAG(noviewid);
+ CHECKFLAG(notomb); CHECKFLAG(nocashshop); CHECKFLAG(noviewid); CHECKFLAG(town);
clif->message(sd->fd," ");
clif->message(sd->fd,msg_fd(fd,1312)); // Usage: "@mapflag monster_noteleport 1" (0=Off | 1=On)
clif->message(sd->fd,msg_fd(fd,1313)); // Type "@mapflag available" to list the available mapflags.
@@ -7730,6 +7787,7 @@ ACMD(mapflag)
SETFLAG(nomvploot); SETFLAG(nightenabled); SETFLAG(nodrop); SETFLAG(novending);
SETFLAG(loadevent); SETFLAG(nochat); SETFLAG(partylock); SETFLAG(guildlock);
SETFLAG(src4instance); SETFLAG(notomb); SETFLAG(nocashshop); SETFLAG(noviewid);
+ SETFLAG(town);
clif->message(sd->fd, msg_fd(fd, 1314)); // Invalid flag name or flag.
@@ -10033,6 +10091,7 @@ static void atcommand_basecommands(void)
ACMD_DEF(joinclan),
ACMD_DEF(leaveclan),
ACMD_DEF(reloadclans),
+ ACMD_DEF(setzone),
};
int i;
diff --git a/src/map/map.c b/src/map/map.c
index ce8f4cdf5..343f219b8 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -3690,6 +3690,33 @@ static void do_final_maps(void)
map->zone_db_clear();
}
+
+static void map_zonedb_reload(void)
+{
+ // first, reset maps to their initial zones:
+ for (int i = 0; i < map->count; i++) {
+ map->zone_remove(i);
+
+ if (battle_config.pk_mode) {
+ map->list[i].flag.pvp = 1;
+ map->list[i].zone = &map->zone_pk;
+ } else {
+ map->list[i].flag.pvp = 0;
+ map->list[i].zone = &map->zone_all;
+ }
+
+ map->list[i].prev_zone = map->list[i].zone;
+ }
+
+ // now it's safe to remove the zones:
+ map->zone_db_clear();
+
+ // then reload everything from scratch:
+ map->zone_db = strdb_alloc(DB_OPT_DUP_KEY | DB_OPT_RELEASE_DATA, MAP_ZONE_NAME_LENGTH);
+ map->read_zone_db();
+}
+
+
/// Initializes map flags and adjusts them depending on configuration.
static void map_flags_init(void)
{
@@ -6804,6 +6831,7 @@ void map_defaults(void)
map->zone_apply = map_zone_apply;
map->zone_change = map_zone_change;
map->zone_change2 = map_zone_change2;
+ map->zone_reload = map_zonedb_reload;
map->getcell = map_getcell;
map->setgatcell = map_setgatcell;
diff --git a/src/map/map.h b/src/map/map.h
index 207fef2ce..cf3a4e57c 100644
--- a/src/map/map.h
+++ b/src/map/map.h
@@ -1216,6 +1216,7 @@ END_ZEROED_BLOCK;
void (*zone_apply) (int m, struct map_zone_data *zone, const char* start, const char* buffer, const char* filepath);
void (*zone_change) (int m, struct map_zone_data *zone, const char* start, const char* buffer, const char* filepath);
void (*zone_change2) (int m, struct map_zone_data *zone);
+ void (*zone_reload) (void);
int (*getcell) (int16 m, const struct block_list *bl, int16 x, int16 y, cell_chk cellchk);
void (*setgatcell) (int16 m, int16 x, int16 y, int gat);
diff --git a/src/map/npc.c b/src/map/npc.c
index a49fb08eb..b93b2b6f4 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -4980,6 +4980,7 @@ static int npc_reload(void)
instance->reload();
+ map->zone_reload();
map->zone_init();
npc->motd = npc->name2id("HerculesMOTD"); /* [Ind/Hercules] */