summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2013-02-09 01:51:36 -0800
committerBen Longbons <b.r.longbons@gmail.com>2013-02-12 20:21:34 -0800
commit80e36aa669274637bcd5956fbf4020dba1d4739c (patch)
tree2f5d3a63a5f7230ab73cd588e3493c0664a5a73b /src
parent83b2e0b3ceda907b7186acfcc56c214fc04d9c13 (diff)
downloadtmwa-80e36aa669274637bcd5956fbf4020dba1d4739c.tar.gz
tmwa-80e36aa669274637bcd5956fbf4020dba1d4739c.tar.bz2
tmwa-80e36aa669274637bcd5956fbf4020dba1d4739c.tar.xz
tmwa-80e36aa669274637bcd5956fbf4020dba1d4739c.zip
Strictify timers
Diffstat (limited to 'src')
-rw-r--r--src/char/char.cpp55
-rw-r--r--src/char/char.hpp4
-rw-r--r--src/char/inter.cpp10
-rw-r--r--src/common/core.cpp6
-rw-r--r--src/common/mmo.hpp8
-rw-r--r--src/common/nullpo.hpp2
-rw-r--r--src/common/socket.cpp10
-rw-r--r--src/common/socket.hpp4
-rw-r--r--src/common/timer.cpp288
-rw-r--r--src/common/timer.hpp78
-rw-r--r--src/common/timer.t.hpp28
-rw-r--r--src/login/login.cpp80
-rw-r--r--src/map/atcommand.cpp222
-rw-r--r--src/map/battle.cpp343
-rw-r--r--src/map/battle.hpp20
-rw-r--r--src/map/chrif.cpp14
-rw-r--r--src/map/clif.cpp1752
-rw-r--r--src/map/clif.hpp11
-rw-r--r--src/map/magic-expr.cpp2
-rw-r--r--src/map/magic-interpreter-base.cpp25
-rw-r--r--src/map/magic-interpreter.hpp2
-rw-r--r--src/map/magic-stmt.cpp116
-rw-r--r--src/map/map.cpp147
-rw-r--r--src/map/map.hpp110
-rw-r--r--src/map/map.t.hpp1
-rw-r--r--src/map/mob.cpp443
-rw-r--r--src/map/mob.hpp14
-rw-r--r--src/map/npc.cpp172
-rw-r--r--src/map/npc.hpp7
-rw-r--r--src/map/party.cpp10
-rw-r--r--src/map/path.cpp3
-rw-r--r--src/map/pc.cpp748
-rw-r--r--src/map/pc.hpp17
-rw-r--r--src/map/script.cpp67
-rw-r--r--src/map/skill.cpp479
-rw-r--r--src/map/skill.hpp22
-rw-r--r--src/map/skill.t.hpp67
37 files changed, 2005 insertions, 3382 deletions
diff --git a/src/char/char.cpp b/src/char/char.cpp
index 775ac69..7954655 100644
--- a/src/char/char.cpp
+++ b/src/char/char.cpp
@@ -37,7 +37,11 @@ int server_freezeflag[MAX_MAP_SERVERS]; // Map-server anti-freeze system. Cou
static
int anti_freeze_enable = 0;
static
-int ANTI_FREEZE_INTERVAL = 6;
+std::chrono::seconds ANTI_FREEZE_INTERVAL = std::chrono::seconds(6);
+
+constexpr
+std::chrono::milliseconds DEFAULT_AUTOSAVE_INTERVAL =
+ std::chrono::minutes(5);
// TODO replace all string forms of IP addresses with class instances
static
@@ -120,7 +124,8 @@ static
int char_num, char_max;
static
int max_connect_user = 0;
-int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
+static
+std::chrono::milliseconds autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
static
int start_zeny = 500;
static
@@ -569,7 +574,7 @@ void mmo_char_sync(void)
// Function to save (in a periodic way) datas in files
//----------------------------------------------------
static
-void mmo_char_sync_timer(timer_id, tick_t, custom_id_t, custom_data_t)
+void mmo_char_sync_timer(TimerData *, tick_t)
{
if (pid != 0)
{
@@ -784,7 +789,7 @@ int make_new_char(int fd, const uint8_t *dat)
char_dat[i].sp = char_dat[i].max_sp;
char_dat[i].status_point = 0;
char_dat[i].skill_point = 0;
- char_dat[i].option = Option(0x0000);
+ char_dat[i].option = static_cast<Option>(0x0000); // Option is only declared
char_dat[i].karma = 0;
char_dat[i].manner = 0;
char_dat[i].party_id = 0;
@@ -1097,7 +1102,7 @@ int mmo_char_send006b(int fd, struct char_session_data *sd)
WFIFOW(fd, j + 22) = find_equip_view(p, EPOS::GLOVES);
WFIFOW(fd, j + 24) = find_equip_view(p, EPOS::CAPE);
WFIFOW(fd, j + 26) = find_equip_view(p, EPOS::TORSO);
- WFIFOL(fd, j + 28) = uint16_t(p->option);
+ WFIFOL(fd, j + 28) = static_cast<uint16_t>(p->option);
WFIFOL(fd, j + 32) = p->karma;
WFIFOL(fd, j + 36) = p->manner;
@@ -1107,7 +1112,7 @@ int mmo_char_send006b(int fd, struct char_session_data *sd)
WFIFOW(fd, j + 44) = (p->max_hp > 0x7fff) ? 0x7fff : p->max_hp;
WFIFOW(fd, j + 46) = (p->sp > 0x7fff) ? 0x7fff : p->sp;
WFIFOW(fd, j + 48) = (p->max_sp > 0x7fff) ? 0x7fff : p->max_sp;
- WFIFOW(fd, j + 50) = DEFAULT_WALK_SPEED; // p->speed;
+ WFIFOW(fd, j + 50) = static_cast<uint16_t>(DEFAULT_WALK_SPEED.count()); // p->speed;
WFIFOW(fd, j + 52) = p->species;
WFIFOW(fd, j + 54) = p->hair;
// WFIFOW(fd,j+56) = p->weapon; // dont send weapon since TMW does not support it
@@ -1709,7 +1714,7 @@ void parse_tologin(int fd)
// Map-server anti-freeze system
//--------------------------------
static
-void map_anti_freeze_system(timer_id, tick_t, custom_id_t, custom_data_t)
+void map_anti_freeze_system(TimerData *, tick_t)
{
int i;
@@ -2576,7 +2581,7 @@ void parse_char(int fd)
WFIFOW(fd, 2 + 48) =
(char_dat[i].max_sp >
0x7fff) ? 0x7fff : char_dat[i].max_sp;
- WFIFOW(fd, 2 + 50) = DEFAULT_WALK_SPEED; // char_dat[i].speed;
+ WFIFOW(fd, 2 + 50) = static_cast<uint16_t>(DEFAULT_WALK_SPEED.count()); // char_dat[i].speed;
WFIFOW(fd, 2 + 52) = char_dat[i].species;
WFIFOW(fd, 2 + 54) = char_dat[i].hair;
@@ -2868,7 +2873,7 @@ int mapif_send(int fd, const uint8_t *buf, unsigned int len)
}
static
-void send_users_tologin(timer_id, tick_t, custom_id_t, custom_data_t)
+void send_users_tologin(TimerData *, tick_t)
{
int users = count_users();
uint8_t buf[16];
@@ -2887,7 +2892,7 @@ void send_users_tologin(timer_id, tick_t, custom_id_t, custom_data_t)
}
static
-void check_connect_login_server(timer_id, tick_t, custom_id_t, custom_data_t)
+void check_connect_login_server(TimerData *, tick_t)
{
if (login_fd <= 0 || session[login_fd] == NULL)
{
@@ -3137,8 +3142,8 @@ int char_config_read(const char *cfgName)
}
else if (w1 == "autosave_time")
{
- autosave_interval = atoi(w2.c_str()) * 1000;
- if (autosave_interval <= 0)
+ autosave_interval = std::chrono::seconds(atoi(w2.c_str()));
+ if (autosave_interval <= std::chrono::seconds::zero())
autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
}
else if (w1 == "start_point")
@@ -3222,9 +3227,9 @@ int char_config_read(const char *cfgName)
}
else if (w1 == "anti_freeze_interval")
{
- ANTI_FREEZE_INTERVAL = atoi(w2.c_str());
- if (ANTI_FREEZE_INTERVAL < 5)
- ANTI_FREEZE_INTERVAL = 5; // minimum 5 seconds
+ ANTI_FREEZE_INTERVAL = std::max(
+ std::chrono::seconds(atoi(w2.c_str())),
+ std::chrono::seconds(5));
}
else if (w1 == "import")
{
@@ -3294,21 +3299,17 @@ int do_init(int argc, char **argv)
char_fd = make_listen_port(char_port);
-// add_timer_func_list (check_connect_login_server, "check_connect_login_server");
-// add_timer_func_list (send_users_tologin, "send_users_tologin");
-// add_timer_func_list (mmo_char_sync_timer, "mmo_char_sync_timer");
-
- i = add_timer_interval(gettick() + 1000, check_connect_login_server, 0,
- 0, 10 * 1000);
- i = add_timer_interval(gettick() + 1000, send_users_tologin, 0, 0,
- 5 * 1000);
- i = add_timer_interval(gettick() + autosave_interval,
- mmo_char_sync_timer, 0, 0, autosave_interval);
+ add_timer_interval(gettick() + std::chrono::seconds(1),
+ check_connect_login_server, std::chrono::seconds(10));
+ add_timer_interval(gettick() + std::chrono::seconds(1),
+ send_users_tologin, std::chrono::seconds(5));
+ add_timer_interval(gettick() + autosave_interval,
+ mmo_char_sync_timer, autosave_interval);
if (anti_freeze_enable > 0)
{
-// add_timer_func_list (map_anti_freeze_system, "map_anti_freeze_system");
- i = add_timer_interval(gettick() + 1000, map_anti_freeze_system, 0, 0, ANTI_FREEZE_INTERVAL * 1000); // checks every X seconds user specifies
+ add_timer_interval(gettick() + std::chrono::seconds(1),
+ map_anti_freeze_system, ANTI_FREEZE_INTERVAL);
}
CHAR_LOG("The char-server is ready (Server is listening on the port %d).\n",
diff --git a/src/char/char.hpp b/src/char/char.hpp
index 4ba0b6b..be9167e 100644
--- a/src/char/char.hpp
+++ b/src/char/char.hpp
@@ -10,8 +10,6 @@ constexpr int MAX_MAP_SERVERS = 30;
#define LOGIN_LAN_CONF_NAME "conf/lan_support.conf"
-constexpr int DEFAULT_AUTOSAVE_INTERVAL = 300 * 1000;
-
struct mmo_map_server
{
long ip;
@@ -32,6 +30,4 @@ void char_log(const_string line);
#define CHAR_LOG(fmt, ...) \
char_log(static_cast<const std::string&>(STRPRINTF(fmt, ## __VA_ARGS__)))
-extern int autosave_interval;
-
#endif // CHAR_HPP
diff --git a/src/char/inter.cpp b/src/char/inter.cpp
index 884a506..3ca70e9 100644
--- a/src/char/inter.cpp
+++ b/src/char/inter.cpp
@@ -22,7 +22,7 @@
// Existence time of Wisp/page data (60 seconds)
// that is the waiting time of answers of all map-servers
-constexpr int WISDATA_TTL = 60 * 1000;
+constexpr std::chrono::minutes WISDATA_TTL = std::chrono::minutes(1);
// Number of elements of Wisp/page data deletion list
constexpr int WISDELLIST_MAX = 256;
@@ -58,7 +58,7 @@ int inter_recv_packet_length[] = {
struct WisData
{
int id, fd, count, len;
- unsigned long tick;
+ tick_t tick;
unsigned char src[24], dst[24], msg[1024];
};
static
@@ -335,11 +335,11 @@ int mapif_account_reg_reply(int fd, int account_id)
// Existence check of WISP data
static
-void check_ttl_wisdata_sub(db_key_t, db_val_t data, unsigned long tick)
+void check_ttl_wisdata_sub(db_key_t, db_val_t data, tick_t tick)
{
struct WisData *wd = (struct WisData *) data;
- if (DIFF_TICK(tick, wd->tick) > WISDATA_TTL
+ if (tick > wd->tick + WISDATA_TTL
&& wis_delnum < WISDELLIST_MAX)
wis_dellist[wis_delnum++] = wd->id;
}
@@ -347,7 +347,7 @@ void check_ttl_wisdata_sub(db_key_t, db_val_t data, unsigned long tick)
static
int check_ttl_wisdata(void)
{
- unsigned long tick = gettick();
+ tick_t tick = gettick();
int i;
do
diff --git a/src/common/core.cpp b/src/common/core.cpp
index 300f1cc..ae0e3eb 100644
--- a/src/common/core.cpp
+++ b/src/common/core.cpp
@@ -93,7 +93,11 @@ int main(int argc, char **argv)
while (runflag)
{
- do_sendrecv(do_timer(gettick_nocache()));
+ // TODO - if timers take a long time to run, this
+ // may wait too long in sendrecv
+ tick_t now = milli_clock::now();
+ interval_t next = do_timer(now);
+ do_sendrecv(next);
do_parsepacket();
}
}
diff --git a/src/common/mmo.hpp b/src/common/mmo.hpp
index 1bbb28a..f35064b 100644
--- a/src/common/mmo.hpp
+++ b/src/common/mmo.hpp
@@ -3,7 +3,7 @@
#define MMO_HPP
# include "sanity.hpp"
-
+# include "timer.t.hpp"
# include "utils.hpp"
constexpr int FIFOSIZE_SERVERLINK = 256 * 1024;
@@ -22,9 +22,9 @@ constexpr SkillID get_enum_max_value(SkillID) { return MAX_SKILL; }
constexpr int GLOBAL_REG_NUM = 96;
constexpr int ACCOUNT_REG_NUM = 16;
constexpr int ACCOUNT_REG2_NUM = 16;
-constexpr int DEFAULT_WALK_SPEED = 150;
-constexpr int MIN_WALK_SPEED = 0;
-constexpr int MAX_WALK_SPEED = 1000;
+constexpr interval_t DEFAULT_WALK_SPEED = std::chrono::milliseconds(150);
+constexpr interval_t MIN_WALK_SPEED = interval_t::zero();
+constexpr interval_t MAX_WALK_SPEED = std::chrono::seconds(1);
constexpr int MAX_STORAGE = 300;
constexpr int MAX_PARTY = 12;
diff --git a/src/common/nullpo.hpp b/src/common/nullpo.hpp
index 2d8644f..305448f 100644
--- a/src/common/nullpo.hpp
+++ b/src/common/nullpo.hpp
@@ -12,7 +12,7 @@
# ifndef BUG_FREE
# define nullpo_retr(ret, t) \
- if (nullpo_chk(__FILE__, __LINE__, __func__, t)) \
+ if (nullpo_chk(__FILE__, __LINE__, __PRETTY_FUNCTION__, t)) \
return ret;
# else // BUG_FREE
# define nullpo_retr(ret, t) /*t*/
diff --git a/src/common/socket.cpp b/src/common/socket.cpp
index 50c08a0..ac5a17d 100644
--- a/src/common/socket.cpp
+++ b/src/common/socket.cpp
@@ -332,7 +332,7 @@ void WFIFOSET(int fd, size_t len)
FPRINTF(stderr, "socket: %d wdata lost !!\n", fd), abort();
}
-void do_sendrecv(uint32_t next)
+void do_sendrecv(interval_t next_ms)
{
fd_set rfd = readfds, wfd;
FD_ZERO(&wfd);
@@ -342,8 +342,12 @@ void do_sendrecv(uint32_t next)
FD_SET(i, &wfd);
}
struct timeval timeout;
- timeout.tv_sec = next / 1000;
- timeout.tv_usec = next % 1000 * 1000;
+ {
+ std::chrono::seconds next_s = std::chrono::duration_cast<std::chrono::seconds>(next_ms);
+ std::chrono::microseconds next_us = next_ms - next_s;
+ timeout.tv_sec = next_s.count();
+ timeout.tv_usec = next_us.count();
+ }
if (select(fd_max, &rfd, &wfd, NULL, &timeout) <= 0)
return;
for (int i = 0; i < fd_max; i++)
diff --git a/src/common/socket.hpp b/src/common/socket.hpp
index 48caee5..c5db89c 100644
--- a/src/common/socket.hpp
+++ b/src/common/socket.hpp
@@ -7,6 +7,8 @@
# include <cstdio>
+# include "timer.t.hpp"
+
// Struct declaration
struct socket_data
@@ -69,7 +71,7 @@ void delete_session(int);
/// Make a the internal queues bigger
void realloc_fifo(int fd, size_t rfifo_size, size_t wfifo_size);
/// Update all sockets that can be read/written from the queues
-void do_sendrecv(uint32_t next);
+void do_sendrecv(interval_t next);
/// Call the parser function for every socket that has read data
void do_parsepacket(void);
diff --git a/src/common/timer.cpp b/src/common/timer.cpp
index 92d284c..219efd9 100644
--- a/src/common/timer.cpp
+++ b/src/common/timer.cpp
@@ -1,270 +1,148 @@
#include "timer.hpp"
+#include <sys/stat.h>
#include <sys/time.h>
+#include <cassert>
#include <cstring>
+#include <queue>
+
#include "cxxstdio.hpp"
#include "utils.hpp"
#include "../poison.hpp"
-static
-struct TimerData *timer_data;
-static
-uint32_t timer_data_max, timer_data_num;
-static
-timer_id *free_timer_list;
-static
-uint32_t free_timer_list_max, free_timer_list_pos;
+struct TimerData
+{
+ /// When it will be triggered
+ tick_t tick;
+ /// What will be done
+ timer_func func;
+ /// Repeat rate - 0 for oneshot
+ interval_t interval;
+};
+
+struct TimerCompare
+{
+ /// implement "less than"
+ bool operator() (TimerData *l, TimerData *r)
+ {
+ // C++ provides a max-heap, but we want
+ // the smallest tick to be the head (a min-heap).
+ return l->tick > r->tick;
+ }
+};
-/// Okay, I think I understand this structure now:
-/// the timer heap is a magic queue that allows inserting timers and then popping them in order
-/// designed to copy only log2(N) entries instead of N
-// timer_heap[0] is the size (greatest index into the heap)
-// timer_heap[1] is the first actual element
-// timer_heap_max increases 256 at a time and never decreases
-static
-uint32_t timer_heap_max = 0;
-/// FIXME: refactor the code to put the size in a separate variable
-//nontrivial because indices get multiplied
static
-timer_id *timer_heap = NULL;
+std::priority_queue<TimerData *, std::vector<TimerData *>, TimerCompare> timer_heap;
-static
-uint32_t gettick_cache;
-static
-uint8_t gettick_count = 0;
+tick_t gettick_cache;
-uint32_t gettick_nocache(void)
+tick_t milli_clock::now(void) noexcept
{
struct timeval tval;
// BUG: This will cause strange behavior if the system clock is changed!
// it should be reimplemented in terms of clock_gettime(CLOCK_MONOTONIC, )
gettimeofday(&tval, NULL);
- gettick_count = 255;
- return gettick_cache = tval.tv_sec * 1000 + tval.tv_usec / 1000;
-}
-
-uint32_t gettick(void)
-{
- if (gettick_count--)
- return gettick_cache;
- return gettick_nocache();
+ return gettick_cache = tick_t(std::chrono::seconds(tval.tv_sec)
+ + std::chrono::duration_cast<std::chrono::milliseconds>(
+ std::chrono::microseconds(tval.tv_usec)));
}
static
-void push_timer_heap(timer_id index)
+void push_timer_heap(TimerData *td)
{
- if (timer_heap == NULL || timer_heap[0] + 1 >= timer_heap_max)
- {
- timer_heap_max += 256;
- RECREATE(timer_heap, timer_id, timer_heap_max);
- memset(timer_heap + (timer_heap_max - 256), 0, sizeof(timer_id) * 256);
- }
-// timer_heap[0] is the greatest index into the heap, which increases
- timer_heap[0]++;
-
- timer_id h = timer_heap[0]-1, i = (h - 1) / 2;
- while (h)
- {
- // avoid wraparound problems, it really means this:
- // timer_data[index].tick >= timer_data[timer_heap[i+1]].tick
- if ( DIFF_TICK(timer_data[index].tick, timer_data[timer_heap[i+1]].tick) >= 0)
- break;
- timer_heap[h + 1] = timer_heap[i + 1];
- h = i;
- i = (h - 1) / 2;
- }
- timer_heap[h + 1] = index;
+ timer_heap.push(td);
}
static
-timer_id top_timer_heap(void)
+TimerData *top_timer_heap(void)
{
- if (!timer_heap || !timer_heap[0])
- return -1;
- return timer_heap[1];
+ if (timer_heap.empty())
+ return nullptr;
+ return timer_heap.top();
}
static
-timer_id pop_timer_heap(void)
+void pop_timer_heap(void)
{
- if (!timer_heap || !timer_heap[0])
- return -1;
- timer_id ret = timer_heap[1];
- timer_id last = timer_heap[timer_heap[0]];
- timer_heap[0]--;
-
- uint32_t h, k;
- for (h = 0, k = 2; k < timer_heap[0]; k = k * 2 + 2)
- {
- if (DIFF_TICK(timer_data[timer_heap[k + 1]].tick, timer_data[timer_heap[k]].tick) > 0)
- k--;
- timer_heap[h + 1] = timer_heap[k + 1], h = k;
- }
- if (k == timer_heap[0])
- timer_heap[h + 1] = timer_heap[k], h = k - 1;
-
- uint32_t i = (h - 1) / 2;
- while (h)
- {
- if (DIFF_TICK(timer_data[timer_heap[i + 1]].tick, timer_data[last].tick) <= 0)
- break;
- timer_heap[h + 1] = timer_heap[i + 1];
- h = i;
- i = (h - 1) / 2;
- }
- timer_heap[h + 1] = last;
-
- return ret;
+ timer_heap.pop();
}
-timer_id add_timer(tick_t tick, timer_func func, custom_id_t id, custom_data_t data)
+TimerData *add_timer(tick_t tick, timer_func func)
{
- timer_id i;
-
- if (free_timer_list_pos)
- {
- // Retrieve a freed timer id instead of a new one
- // I think it should be possible to avoid the loop somehow
- do
- {
- i = free_timer_list[--free_timer_list_pos];
- }
- while (i >= timer_data_num && free_timer_list_pos > 0);
- }
- else
- i = timer_data_num;
-
- // I have no idea what this is doing
- if (i >= timer_data_num)
- for (i = timer_data_num; i < timer_data_max && timer_data[i].type; i++)
- ;
- if (i >= timer_data_num && i >= timer_data_max)
- {
- if (timer_data_max == 0)
- {
- timer_data_max = 256;
- CREATE(timer_data, struct TimerData, timer_data_max);
- }
- else
- {
- timer_data_max += 256;
- RECREATE(timer_data, struct TimerData, timer_data_max);
- memset(timer_data + (timer_data_max - 256), 0,
- sizeof(struct TimerData) * 256);
- }
- }
- timer_data[i].tick = tick;
- timer_data[i].func = func;
- timer_data[i].id = id;
- timer_data[i].data = data;
- timer_data[i].type = TIMER_ONCE_AUTODEL;
- timer_data[i].interval = 1000;
- push_timer_heap(i);
- if (i >= timer_data_num)
- timer_data_num = i + 1;
- return i;
+ return add_timer_interval(tick, std::move(func), interval_t::zero());
}
-timer_id add_timer_interval(tick_t tick, timer_func func, custom_id_t id,
- custom_data_t data, interval_t interval)
+TimerData *add_timer_interval(tick_t tick, timer_func func, interval_t interval)
{
- timer_id tid = add_timer(tick, func, id, data);
- timer_data[tid].type = TIMER_INTERVAL;
- timer_data[tid].interval = interval;
- return tid;
+ assert (interval >= interval_t::zero());
+
+ TimerData *td = new TimerData();
+ td->tick = tick;
+ td->func = std::move(func);
+ td->interval = interval;
+ push_timer_heap(td);
+ return td;
}
-void delete_timer(timer_id id, timer_func func)
+static
+void do_nothing(TimerData *, tick_t)
{
- if (id == 0 || id >= timer_data_num)
- {
- FPRINTF(stderr, "delete_timer error : no such timer %d\n", id);
- abort();
- }
-#ifndef delete_timer
- if (timer_data[id].func != func)
- {
- FPRINTF(stderr, "Timer mismatch\n");
- abort();
- }
-#endif
- // "to let them disappear" - is this just in case?
- timer_data[id].func = NULL;
- timer_data[id].type = TIMER_ONCE_AUTODEL;
- timer_data[id].tick -= 60 * 60 * 1000;
}
-tick_t addtick_timer(timer_id tid, interval_t tick)
+void delete_timer(TimerData *td)
{
- return timer_data[tid].tick += tick;
-}
+ assert (td != nullptr);
-struct TimerData *get_timer(timer_id tid)
-{
- return &timer_data[tid];
+ td->func = do_nothing;
+ td->interval = interval_t::zero();
}
interval_t do_timer(tick_t tick)
{
- timer_id i;
/// Number of milliseconds until it calls this again
// this says to wait 1 sec if all timers get popped
- interval_t nextmin = 1000;
+ interval_t nextmin = std::chrono::seconds(1);
- while ((i = top_timer_heap()) != (timer_id)-1)
+ while (TimerData *td = top_timer_heap())
{
// while the heap is not empty and
- if (DIFF_TICK(timer_data[i].tick, tick) > 0)
+ if (td->tick > tick)
{
/// Return the time until the next timer needs to goes off
- nextmin = DIFF_TICK(timer_data[i].tick, tick);
+ nextmin = td->tick - tick;
break;
}
pop_timer_heap();
- if (timer_data[i].func)
- {
- if (DIFF_TICK(timer_data[i].tick, tick) < -1000)
- {
- // If we are too far past the requested tick, call with the current tick instead to fix reregistering problems
- timer_data[i].func(i, tick, timer_data[i].id, timer_data[i].data);
- }
- else
- {
- timer_data[i].func(i, timer_data[i].tick, timer_data[i].id, timer_data[i].data);
- }
- }
- switch (timer_data[i].type)
+
+ // If we are too far past the requested tick, call with the current tick instead to fix reregistering problems
+ if (td->tick + std::chrono::seconds(1) < tick)
+ td->func(td, tick);
+ else
+ td->func(td, td->tick);
+
+ if (td->interval == interval_t::zero())
{
- case TIMER_ONCE_AUTODEL:
- timer_data[i].type = TIMER_NONE;
- if (free_timer_list_pos >= free_timer_list_max)
- {
- free_timer_list_max += 256;
- RECREATE(free_timer_list, uint32_t, free_timer_list_max);
- memset(free_timer_list + (free_timer_list_max - 256),
- 0, 256 * sizeof(uint32_t));
- }
- free_timer_list[free_timer_list_pos++] = i;
- break;
- case TIMER_INTERVAL:
- if (DIFF_TICK(timer_data[i].tick, tick) < -1000)
- {
- timer_data[i].tick = tick + timer_data[i].interval;
- }
- else
- {
- timer_data[i].tick += timer_data[i].interval;
- }
- push_timer_heap(i);
- break;
+ delete td;
+ continue;
}
+ if (td->tick + std::chrono::seconds(1) < tick)
+ td->tick = tick + td->interval;
+ else
+ td->tick += td->interval;
+ push_timer_heap(td);
}
- if (nextmin < 10)
- nextmin = 10;
- return nextmin;
+ return std::max(nextmin, std::chrono::milliseconds(10));
+}
+
+tick_t file_modified(const char *name)
+{
+ struct stat buf;
+ if (stat(name, &buf))
+ return tick_t();
+ return tick_t(std::chrono::seconds(buf.st_mtime));
}
diff --git a/src/common/timer.hpp b/src/common/timer.hpp
index b00d48d..876d519 100644
--- a/src/common/timer.hpp
+++ b/src/common/timer.hpp
@@ -1,66 +1,46 @@
#ifndef TIMER_HPP
#define TIMER_HPP
+# include "timer.t.hpp"
+
# include "sanity.hpp"
-enum TIMER_TYPE
-{
- TIMER_NONE,
- TIMER_ONCE_AUTODEL,
- TIMER_INTERVAL,
-};
-/// This is needed to produce a signed result when 2 ticks are subtracted
-inline
-int32_t DIFF_TICK(int32_t a, int32_t b)
-{
- return a - b;
-}
+# include <chrono>
+# include <functional>
-// TODO replace with std::chrono::time_point and std::chrono::duration
-typedef uint32_t tick_t;
-typedef uint32_t interval_t;
-typedef uint32_t timer_id;
-// BUG: pointers are stored in here
-typedef int32_t custom_id_t;
-typedef int32_t custom_data_t;
-typedef void(*timer_func)(timer_id, tick_t, custom_id_t, custom_data_t);
+/// (to get additional arguments, use std::bind or a lambda).
+typedef std::function<void (TimerData *, tick_t)> timer_func;
-struct TimerData
+// updated automatically when using milli_clock::now()
+// which is done only by core.cpp
+extern tick_t gettick_cache;
+
+inline
+tick_t gettick(void)
{
- /// When it will be triggered
- tick_t tick;
- /// What will be done
- timer_func func;
- /// Arbitrary data. WARNING, callers are stupid and put pointers in here
- // Should we change to void* or intptr_t ?
- custom_id_t id;
- custom_data_t data;
- /// Type of timer - 0 initially
- enum TIMER_TYPE type;
- /// Repeat rate
- interval_t interval;
-};
+ return gettick_cache;
+}
-/// Server time, in milliseconds, since the epoch,
-/// but use of 32-bit integers means it wraps every 49 days.
-// The only external caller of this function is the core.c main loop, but that makes sense
-// in fact, it might make more sense if gettick() ALWAYS returned that cached value
-tick_t gettick_nocache(void);
-/// This function is called enough that it's worth caching the result for
-/// the next 255 times
-tick_t gettick(void);
+/// Schedule a one-shot timer at the given tick.
+/// The timer will automatically be freed after it is called
+/// (during a do_timer).
+TimerData *add_timer(tick_t t, timer_func f);
-timer_id add_timer(tick_t, timer_func, custom_id_t, custom_data_t);
-timer_id add_timer_interval(tick_t, timer_func, custom_id_t, custom_data_t, interval_t);
-//#define delete_timer(tid, func) delete_timer(tid)
-void delete_timer(timer_id, timer_func);
+/// Schedule a recurring timer initially at the given tick.
+/// The timer will automatically reregister itself, with the same
+/// opaque handle, every interval after the tick.
+/// It will never be freed unless you use delete_timer.
+TimerData *add_timer_interval(tick_t, timer_func, interval_t);
-tick_t addtick_timer(timer_id, interval_t);
-struct TimerData *get_timer(timer_id tid);
+/// Cancel the given timer.
+/// This doesn't actually remove it, it just resets the functor.
+/// and waits for the the tick to arrive in do_timer.
+void delete_timer(TimerData *);
/// Do all timers scheduled before tick, and return the number of milliseconds until the next timer happens
interval_t do_timer(tick_t tick);
-
+/// Stat a file, and return its modification time, truncated to seconds.
+tick_t file_modified(const char *name);
#endif // TIMER_HPP
diff --git a/src/common/timer.t.hpp b/src/common/timer.t.hpp
new file mode 100644
index 0000000..67d7450
--- /dev/null
+++ b/src/common/timer.t.hpp
@@ -0,0 +1,28 @@
+#ifndef TIMER_T_HPP
+#define TIMER_T_HPP
+
+# include <chrono>
+
+/// An implementation of the C++ "clock" concept, exposing
+/// durations in milliseconds.
+class milli_clock
+{
+public:
+ typedef std::chrono::milliseconds duration;
+ typedef duration::rep rep;
+ typedef duration::period period;
+ typedef std::chrono::time_point<milli_clock, duration> time_point;
+ static const bool is_steady = true; // assumed - not necessarily true
+
+ static time_point now() noexcept;
+};
+
+/// A point in time.
+typedef milli_clock::time_point tick_t;
+/// The difference between two points in time.
+typedef milli_clock::duration interval_t;
+
+/// Opaque type representing an active timer.
+struct TimerData;
+
+#endif // TIMER_T_HPP
diff --git a/src/login/login.cpp b/src/login/login.cpp
index 1618461..e2b64b8 100644
--- a/src/login/login.cpp
+++ b/src/login/login.cpp
@@ -1,5 +1,4 @@
#include <arpa/inet.h>
-#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -94,9 +93,9 @@ char login_log_unknown_packets_filename[1024] =
static
int save_unknown_packets = 0;
static
-long creation_time_GM_account_file;
+tick_t creation_time_GM_account_file;
static
-int gm_account_filename_check_timer = 15; // Timer to check if GM_account file has been changed and reload GM account automaticaly (in seconds; default: 15)
+std::chrono::seconds gm_account_filename_check_timer = std::chrono::seconds(15);
static
int display_parse_login = 0; // 0: no, 1: yes
@@ -114,7 +113,7 @@ int server_freezeflag[MAX_SERVERS]; // Char-server anti-freeze system. Counte
static
int anti_freeze_enable = 0;
static
-int ANTI_FREEZE_INTERVAL = 15;
+std::chrono::seconds ANTI_FREEZE_INTERVAL = std::chrono::seconds(15);
static
int login_fd;
@@ -255,16 +254,11 @@ int read_gm_account(void)
FILE *fp;
int c = 0;
int GM_level;
- struct stat file_stat;
free(gm_account_db);
gm_account_db = numdb_init();
- // get last modify time/date
- if (stat(GM_account_filename, &file_stat))
- creation_time_GM_account_file = 0; // error
- else
- creation_time_GM_account_file = file_stat.st_mtime;
+ creation_time_GM_account_file = file_modified(GM_account_filename);
if ((fp = fopen_(GM_account_filename, "r")) == NULL)
{
@@ -672,7 +666,7 @@ int mmo_auth_init(void)
std::string str = STRPRINTF("%s has %d accounts (%d GMs, %d servers)\n",
account_filename, auth_num, GM_count, server_count);
- PRINTF("%s: %s\n", __FUNCTION__, str);
+ PRINTF("%s: %s\n", __PRETTY_FUNCTION__, str);
LOGIN_LOG("%s\n", line);
return 0;
@@ -752,7 +746,7 @@ void mmo_auth_sync(void)
// we save periodicly on a timer.
//-----------------------------------------------------
static
-void check_auth_sync(timer_id, tick_t, custom_id_t, custom_data_t)
+void check_auth_sync(TimerData *, tick_t)
{
if (pid != 0)
{
@@ -828,20 +822,14 @@ void send_GM_accounts(void)
// Check if GM file account have been changed
//-----------------------------------------------------
static
-void check_GM_file(timer_id, tick_t, custom_id_t, custom_data_t)
+void check_GM_file(TimerData *, tick_t)
{
- struct stat file_stat;
- long new_time;
-
// if we would not check
- if (gm_account_filename_check_timer < 1)
+ if (gm_account_filename_check_timer == interval_t::zero())
return;
// get last modify time/date
- if (stat(GM_account_filename, &file_stat))
- new_time = 0; // error
- else
- new_time = file_stat.st_mtime;
+ tick_t new_time = file_modified(GM_account_filename);
if (new_time != creation_time_GM_account_file)
{
@@ -1073,7 +1061,7 @@ int mmo_auth(struct mmo_account *account, int fd)
// Char-server anti-freeze system
//-------------------------------
static
-void char_anti_freeze_system(timer_id, tick_t, custom_id_t, custom_data_t)
+void char_anti_freeze_system(TimerData *, tick_t)
{
int i;
@@ -3300,11 +3288,12 @@ void parse_login(int fd)
LOGIN_LOG("'ladmin': Sending request of the coding key (ip: %s)\n",
ip);
}
+ // TODO fix or get rid of this
// Creation of the coding key
memset(ld->md5key, '\0', sizeof(ld->md5key));
- ld->md5keylen = rand() % 4 + 12;
+ ld->md5keylen = MRAND(4) + 12;
for (int i = 0; i < ld->md5keylen; i++)
- ld->md5key[i] = rand() % 255 + 1;
+ ld->md5key[i] = MRAND(255) + 1;
RFIFOSKIP(fd, 2);
WFIFOW(fd, 0) = 0x01dc;
@@ -3780,7 +3769,7 @@ int login_config_read(const char *cfgName)
}
else if (w1 == "gm_account_filename_check_timer")
{
- gm_account_filename_check_timer = atoi(w2.c_str());
+ gm_account_filename_check_timer = std::chrono::seconds(atoi(w2.c_str()));
}
else if (w1 == "login_log_filename")
{
@@ -3905,9 +3894,9 @@ int login_config_read(const char *cfgName)
}
else if (w1 == "anti_freeze_interval")
{
- ANTI_FREEZE_INTERVAL = atoi(w2.c_str());
- if (ANTI_FREEZE_INTERVAL < 5)
- ANTI_FREEZE_INTERVAL = 5; // minimum 5 seconds
+ ANTI_FREEZE_INTERVAL = std::max(
+ std::chrono::seconds(atoi(w2.c_str())),
+ std::chrono::seconds(5));
}
else if (w1 == "import")
{
@@ -3986,17 +3975,17 @@ void display_conf_warnings(void)
login_port = 6900;
}
- if (gm_account_filename_check_timer < 0)
+ if (gm_account_filename_check_timer.count() < 0)
{
PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n");
PRINTF(" -> set to 15 sec (default).\n");
- gm_account_filename_check_timer = 15;
+ gm_account_filename_check_timer = std::chrono::seconds(15);
}
- else if (gm_account_filename_check_timer == 1)
+ else if (gm_account_filename_check_timer == std::chrono::seconds(1))
{
PRINTF("***WARNING: Invalid value for gm_account_filename_check_timer parameter.\n");
PRINTF(" -> set to 2 sec (minimum value).\n");
- gm_account_filename_check_timer = 2;
+ gm_account_filename_check_timer = std::chrono::seconds(2);
}
if (save_unknown_packets != 0 && save_unknown_packets != 1)
@@ -4156,11 +4145,11 @@ void save_config_in_log(void)
account_filename);
LOGIN_LOG("- with the GM accounts file name: '%s'.\n",
GM_account_filename);
- if (gm_account_filename_check_timer == 0)
+ if (gm_account_filename_check_timer == interval_t::zero())
LOGIN_LOG("- to NOT check GM accounts file modifications.\n");
else
LOGIN_LOG("- to check GM accounts file modifications every %d seconds.\n",
- gm_account_filename_check_timer);
+ (int)gm_account_filename_check_timer.count());
// not necessary to log the 'login_log_filename', we are inside :)
@@ -4303,17 +4292,15 @@ void term_func(void)
//------------------------------
int do_init(int argc, char **argv)
{
- int i, j;
-
// read login-server configuration
login_config_read((argc > 1) ? argv[1] : LOGIN_CONF_NAME);
display_conf_warnings(); // not in login_config_read, because we can use 'import' option, and display same message twice or more
save_config_in_log(); // not before, because log file name can be changed
login_lan_config_read((argc > 1) ? argv[1] : LAN_CONF_NAME);
- for (i = 0; i < AUTH_FIFO_SIZE; i++)
+ for (int i = 0; i < AUTH_FIFO_SIZE; i++)
auth_fifo[i].delflag = 1;
- for (i = 0; i < MAX_SERVERS; i++)
+ for (int i = 0; i < MAX_SERVERS; i++)
server_fd[i] = -1;
gm_account_db = numdb_init();
@@ -4324,24 +4311,19 @@ int do_init(int argc, char **argv)
set_defaultparse(parse_login);
login_fd = make_listen_port(login_port);
-// add_timer_func_list (check_auth_sync, "check_auth_sync");
- // Trigger auth sync every 5 minutes
- i = add_timer_interval(gettick() + 300000, check_auth_sync, 0, 0, 300000);
+ add_timer_interval(gettick() + std::chrono::minutes(5), check_auth_sync, std::chrono::minutes(5));
if (anti_freeze_enable > 0)
{
-// add_timer_func_list (char_anti_freeze_system, "char_anti_freeze_system");
- i = add_timer_interval(gettick() + 1000, char_anti_freeze_system, 0,
- 0, ANTI_FREEZE_INTERVAL * 1000);
+ add_timer_interval(gettick() + std::chrono::seconds(1), char_anti_freeze_system, ANTI_FREEZE_INTERVAL);
}
// add timer to check GM accounts file modification
- j = gm_account_filename_check_timer;
- if (j == 0) // if we would not to check, we check every 60 sec, just to have timer (if we change timer, is was not necessary to check if timer already exists)
- j = 60;
-// add_timer_func_list (check_GM_file, "check_GM_file");
- i = add_timer_interval(gettick() + j * 1000, check_GM_file, 0, 0, j * 1000); // every x sec we check if gm file has been changed
+ std::chrono::seconds j = gm_account_filename_check_timer;
+ if (j == interval_t::zero())
+ j = std::chrono::minutes(1);
+ add_timer_interval(gettick() + j, check_GM_file, j);
LOGIN_LOG("The login-server is ready (Server is listening on the port %d).\n",
login_port);
diff --git a/src/map/atcommand.cpp b/src/map/atcommand.cpp
index dd3aae8..6c82e65 100644
--- a/src/map/atcommand.cpp
+++ b/src/map/atcommand.cpp
@@ -10,6 +10,7 @@
#include "../common/mt_rand.hpp"
#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
+#include "../common/timer.hpp"
#include "../common/utils2.hpp"
#include "battle.hpp"
@@ -83,8 +84,6 @@ ATCOMMAND_FUNC(character_stats);
ATCOMMAND_FUNC(character_stats_all);
ATCOMMAND_FUNC(character_option);
ATCOMMAND_FUNC(character_save);
-ATCOMMAND_FUNC(night);
-ATCOMMAND_FUNC(day);
ATCOMMAND_FUNC(doom);
ATCOMMAND_FUNC(doommap);
ATCOMMAND_FUNC(raise);
@@ -158,7 +157,6 @@ ATCOMMAND_FUNC(leaves);
ATCOMMAND_FUNC(adjgmlvl); // by MouseJstr
ATCOMMAND_FUNC(adjcmdlvl); // by MouseJstr
ATCOMMAND_FUNC(trade); // by MouseJstr
-ATCOMMAND_FUNC(unmute); // [Valaris]
ATCOMMAND_FUNC(char_wipe); // [Fate]
ATCOMMAND_FUNC(set_magic); // [Fate]
ATCOMMAND_FUNC(magic_info); // [Fate]
@@ -241,8 +239,6 @@ AtCommandInfo atcommand_info[] = {
{AtCommand_CharacterOption, "@charoption", 60,
atcommand_character_option},
{AtCommand_CharacterSave, "@charsave", 60, atcommand_character_save},
- {AtCommand_Night, "@night", 80, atcommand_night},
- {AtCommand_Day, "@day", 80, atcommand_day},
{AtCommand_Doom, "@doom", 80, atcommand_doom},
{AtCommand_DoomMap, "@doommap", 80, atcommand_doommap},
{AtCommand_Raise, "@raise", 80, atcommand_raise},
@@ -328,7 +324,6 @@ AtCommandInfo atcommand_info[] = {
{AtCommand_AdjGmLvl, "@adjgmlvl", 99, atcommand_adjgmlvl},
{AtCommand_AdjCmdLvl, "@adjcmdlvl", 99, atcommand_adjcmdlvl},
{AtCommand_Trade, "@trade", 60, atcommand_trade},
- {AtCommand_UnMute, "@unmute", 60, atcommand_unmute}, // [Valaris]
{AtCommand_UnMute, "@charwipe", 60, atcommand_char_wipe}, // [Fate]
{AtCommand_SetMagic, "@setmagic", 99, atcommand_set_magic}, // [Fate]
{AtCommand_MagicInfo, "@magicinfo", 60, atcommand_magic_info}, // [Fate]
@@ -1360,12 +1355,13 @@ int atcommand_speed(const int fd, struct map_session_data *sd,
{
std::string output = STRPRINTF(
"Please, enter a speed value (usage: @speed <%d-%d>).",
- MIN_WALK_SPEED, MAX_WALK_SPEED);
+ static_cast<uint32_t>(MIN_WALK_SPEED.count()),
+ static_cast<uint32_t>(MAX_WALK_SPEED.count()));
clif_displaymessage(fd, output);
return -1;
}
- int speed = atoi(message);
+ interval_t speed = static_cast<interval_t>(atoi(message));
if (speed >= MIN_WALK_SPEED && speed <= MAX_WALK_SPEED)
{
sd->speed = speed;
@@ -1378,7 +1374,8 @@ int atcommand_speed(const int fd, struct map_session_data *sd,
{
std::string output = STRPRINTF(
"Please, enter a valid speed value (usage: @speed <%d-%d>).",
- MIN_WALK_SPEED, MAX_WALK_SPEED);
+ static_cast<uint32_t>(MIN_WALK_SPEED.count()),
+ static_cast<uint32_t>(MAX_WALK_SPEED.count()));
clif_displaymessage(fd, output);
return -1;
}
@@ -1534,8 +1531,8 @@ int atcommand_alive(const int fd, struct map_session_data *sd,
sd->status.hp = sd->status.max_hp;
sd->status.sp = sd->status.max_sp;
pc_setstand(sd);
- if (battle_config.pc_invincible_time > 0)
- pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
+ if (static_cast<interval_t>(battle_config.pc_invincible_time) > interval_t::zero())
+ pc_setinvincibletimer(sd, static_cast<interval_t>(battle_config.pc_invincible_time));
clif_updatestatus(sd, SP::HP);
clif_updatestatus(sd, SP::SP);
clif_resurrection(&sd->bl, 1);
@@ -1592,7 +1589,7 @@ int atcommand_heal(const int fd, struct map_session_data *sd,
}
if (hp < 0) // display like damage
- clif_damage(&sd->bl, &sd->bl, gettick(), 0, 0, -hp, 0, DamageType::RETURNED, 0);
+ clif_damage(&sd->bl, &sd->bl, gettick(), interval_t::zero(), interval_t::zero(), -hp, 0, DamageType::RETURNED, 0);
if (hp != 0 || sp != 0)
{
@@ -1934,11 +1931,10 @@ int atcommand_pvpoff(const int fd, struct map_session_data *sd,
{
if (sd->bl.m == pl_sd->bl.m)
{
- if (pl_sd->pvp_timer != -1)
+ if (pl_sd->pvp_timer)
{
- delete_timer(pl_sd->pvp_timer,
- pc_calc_pvprank_timer);
- pl_sd->pvp_timer = -1;
+ delete_timer(pl_sd->pvp_timer);
+ pl_sd->pvp_timer = nullptr;
}
}
}
@@ -1978,11 +1974,10 @@ int atcommand_pvpon(const int fd, struct map_session_data *sd,
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
{
- if (sd->bl.m == pl_sd->bl.m && pl_sd->pvp_timer == -1)
+ if (sd->bl.m == pl_sd->bl.m && !pl_sd->pvp_timer)
{
- pl_sd->pvp_timer = add_timer(gettick() + 200,
- pc_calc_pvprank_timer,
- pl_sd->bl.id, 0);
+ pl_sd->pvp_timer = add_timer(gettick() + std::chrono::milliseconds(200),
+ std::bind(pc_calc_pvprank_timer, ph::_1, ph::_2, pl_sd->bl.id));
pl_sd->pvp_rank = 0;
pl_sd->pvp_lastusers = 0;
pl_sd->pvp_point = 5;
@@ -2659,8 +2654,8 @@ int atcommand_revive(const int fd, struct map_session_data *sd,
{
pl_sd->status.hp = pl_sd->status.max_hp;
pc_setstand(pl_sd);
- if (battle_config.pc_invincible_time > 0)
- pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
+ if (static_cast<interval_t>(battle_config.pc_invincible_time) > interval_t::zero())
+ pc_setinvincibletimer(sd, static_cast<interval_t>(battle_config.pc_invincible_time));
clif_updatestatus(pl_sd, SP::HP);
clif_updatestatus(pl_sd, SP::SP);
clif_resurrection(&pl_sd->bl, 1);
@@ -3187,72 +3182,6 @@ int atcommand_character_save(const int fd, struct map_session_data *sd,
*
*------------------------------------------
*/
-int atcommand_night(const int fd, struct map_session_data *,
- const char *, const char *)
-{
- struct map_session_data *pl_sd;
- int i;
-
- if (night_flag != 1)
- {
- night_flag = 1; // 0=day, 1=night [Yor]
- for (i = 0; i < fd_max; i++)
- {
- if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
- && pl_sd->state.auth)
- {
- pl_sd->opt2 |= Opt2::BLIND;
- clif_changeoption(&pl_sd->bl);
- clif_displaymessage(pl_sd->fd, "Night has fallen.");
- }
- }
- }
- else
- {
- clif_displaymessage(fd, "Sorry, it's already the night. Impossible to execute the command.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
-int atcommand_day(const int fd, struct map_session_data *,
- const char *, const char *)
-{
- struct map_session_data *pl_sd;
- int i;
-
- if (night_flag != 0)
- {
- night_flag = 0; // 0=day, 1=night [Yor]
- for (i = 0; i < fd_max; i++)
- {
- if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
- && pl_sd->state.auth)
- {
- pl_sd->opt2 &= ~Opt2::BLIND;
- clif_changeoption(&pl_sd->bl);
- clif_displaymessage(pl_sd->fd, "Day has arrived.");
- }
- }
- }
- else
- {
- clif_displaymessage(fd, "Sorry, it's already the day. Impossible to execute the command.");
- return -1;
- }
-
- return 0;
-}
-
-/*==========================================
- *
- *------------------------------------------
- */
int atcommand_doom(const int fd, struct map_session_data *sd,
const char *, const char *)
{
@@ -4830,24 +4759,6 @@ int atcommand_disablenpc(const int fd, struct map_session_data *,
}
/*==========================================
- * time in txt for time command (by [Yor])
- *------------------------------------------
- */
-static
-std::string txt_time(unsigned int duration)
-{
- int days = duration / (60 * 60 * 24);
- duration -= (60 * 60 * 24 * days);
- int hours = duration / (60 * 60);
- duration -= (60 * 60 * hours);
- int minutes = duration / 60;
- int seconds = duration - (60 * minutes);
-
- return STRPRINTF("%d day(s), %d hour(s), %d minute(s), %d second(s)",
- days, hours, minutes, seconds);
-}
-
-/*==========================================
* @time/@date/@server_date/@serverdate/@server_time/@servertime: Display the date/time of the server (by [Yor]
* Calculation management of GM modification (@day/@night GM commands) is done
*------------------------------------------
@@ -4855,80 +4766,14 @@ std::string txt_time(unsigned int duration)
int atcommand_servertime(const int fd, struct map_session_data *,
const char *, const char *)
{
- struct TimerData *timer_data;
- struct TimerData *timer_data2;
-
timestamp_seconds_buffer tsbuf;
stamp_time(tsbuf);
std::string temp = STRPRINTF("Server time: %s", tsbuf);
clif_displaymessage(fd, temp);
- if (battle_config.night_duration == 0 && battle_config.day_duration == 0)
{
- if (night_flag == 0)
- clif_displaymessage(fd, "Game time: The game is in permanent daylight.");
- else
- clif_displaymessage(fd, "Game time: The game is in permanent night.");
- }
- else if (battle_config.night_duration == 0)
- if (night_flag == 1)
- { // we start with night
- timer_data = get_timer(day_timer_tid);
- temp = STRPRINTF("Game time: The game is actualy in night for %s.",
- txt_time((timer_data->tick - gettick()) / 1000));
- clif_displaymessage(fd, temp);
- clif_displaymessage(fd, "Game time: After, the game will be in permanent daylight.");
- }
- else
+ if (0 == 0)
clif_displaymessage(fd, "Game time: The game is in permanent daylight.");
- else if (battle_config.day_duration == 0)
- if (night_flag == 0)
- { // we start with day
- timer_data = get_timer(night_timer_tid);
- temp = STRPRINTF("Game time: The game is actualy in daylight for %s.",
- txt_time((timer_data->tick - gettick()) / 1000));
- clif_displaymessage(fd, temp);
- clif_displaymessage(fd, "Game time: After, the game will be in permanent night.");
- }
- else
- clif_displaymessage(fd, "Game time: The game is in permanent night.");
- else
- {
- if (night_flag == 0)
- {
- timer_data = get_timer(night_timer_tid);
- timer_data2 = get_timer(day_timer_tid);
- temp = STRPRINTF("Game time: The game is actualy in daylight for %s.",
- txt_time((timer_data->tick - gettick()) / 1000));
- clif_displaymessage(fd, temp);
- if (timer_data->tick > timer_data2->tick)
- temp = STRPRINTF("Game time: After, the game will be in night for %s.",
- txt_time((timer_data->interval - abs(timer_data->tick - timer_data2->tick)) / 1000));
- else
- temp = STRPRINTF("Game time: After, the game will be in night for %s.",
- txt_time(abs(timer_data->tick - timer_data2->tick) / 1000));
- clif_displaymessage(fd, temp);
- temp = STRPRINTF("Game time: A day cycle has a normal duration of %s.",
- txt_time(timer_data->interval / 1000));
- clif_displaymessage(fd, temp);
- }
- else
- {
- timer_data = get_timer(day_timer_tid);
- timer_data2 = get_timer(night_timer_tid);
- temp = STRPRINTF("Game time: The game is actualy in night for %s.",
- txt_time((timer_data->tick - gettick()) / 1000));
- clif_displaymessage(fd, temp);
- if (timer_data->tick > timer_data2->tick)
- temp = STRPRINTF("Game time: After, the game will be in daylight for %s.",
- txt_time((timer_data->interval - abs(timer_data->tick - timer_data2->tick)) / 1000));
- else
- temp = STRPRINTF("Game time: After, the game will be in daylight for %s.", txt_time(abs(timer_data->tick - timer_data2->tick) / 1000));
- clif_displaymessage(fd, temp);
- temp = STRPRINTF("Game time: A day cycle has a normal duration of %s.",
- txt_time(timer_data->interval / 1000));
- clif_displaymessage(fd, temp);
- }
}
return 0;
@@ -6332,7 +6177,7 @@ int atcommand_summon(const int, struct map_session_data *sd,
int y = 0;
int id = 0;
struct mob_data *md;
- unsigned int tick = gettick();
+ tick_t tick = gettick();
nullpo_retr(-1, sd);
@@ -6355,7 +6200,9 @@ int atcommand_summon(const int, struct map_session_data *sd,
md->master_id = sd->bl.id;
md->state.special_mob_ai = 1;
md->mode = mob_db[md->mob_class].mode | MobMode::AGGRESSIVE;
- md->deletetimer = add_timer(tick + 60000, mob_timer_delete, id, 0);
+ md->deletetimer = add_timer(tick + std::chrono::minutes(1),
+ std::bind(mob_timer_delete, ph::_1, ph::_2,
+ id));
clif_misceffect(&md->bl, 344);
}
@@ -6450,31 +6297,6 @@ int atcommand_trade(const int, struct map_session_data *sd,
return -1;
}
-/*===========================
- * @unmute [Valaris]
- *===========================
-*/
-int atcommand_unmute(const int, struct map_session_data *sd,
- const char *, const char *message)
-{
- struct map_session_data *pl_sd = NULL;
- if (!message || !*message)
- return -1;
-
- if ((pl_sd = map_nick2sd(message)) != NULL)
- {
- if (pl_sd->sc_data[StatusChange::SC_NOCHAT].timer != -1)
- {
- skill_status_change_end(&pl_sd->bl, StatusChange::SC_NOCHAT, -1);
- clif_displaymessage(sd->fd, "Player unmuted");
- }
- else
- clif_displaymessage(sd->fd, "Player is not muted");
- }
-
- return 0;
-}
-
/* Magic atcommands by Fate */
static
diff --git a/src/map/battle.cpp b/src/map/battle.cpp
index 605d637..fe8dfe4 100644
--- a/src/map/battle.cpp
+++ b/src/map/battle.cpp
@@ -61,9 +61,9 @@ int battle_get_class(struct block_list *bl)
DIR battle_get_dir(struct block_list *bl)
{
nullpo_retr(DIR::S, bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
return ((struct mob_data *) bl)->dir;
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->dir;
else
return DIR::S;
@@ -77,9 +77,9 @@ DIR battle_get_dir(struct block_list *bl)
int battle_get_lv(struct block_list *bl)
{
nullpo_ret(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
return ((struct mob_data *) bl)->stats[mob_stat::LV];
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->status.base_level;
else
return 0;
@@ -93,9 +93,9 @@ int battle_get_lv(struct block_list *bl)
int battle_get_range(struct block_list *bl)
{
nullpo_ret(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
return mob_db[((struct mob_data *) bl)->mob_class].range;
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->attackrange;
else
return 0;
@@ -109,9 +109,9 @@ int battle_get_range(struct block_list *bl)
int battle_get_hp(struct block_list *bl)
{
nullpo_retr(1, bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
return ((struct mob_data *) bl)->hp;
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->status.hp;
else
return 1;
@@ -185,9 +185,9 @@ int battle_get_agi(struct block_list *bl)
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
agi = ((struct mob_data *) bl)->stats[mob_stat::AGI];
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
agi = ((struct map_session_data *) bl)->paramc[ATTR::AGI];
if (agi < 0)
@@ -207,9 +207,9 @@ int battle_get_vit(struct block_list *bl)
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
vit = ((struct mob_data *) bl)->stats[mob_stat::VIT];
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
vit = ((struct map_session_data *) bl)->paramc[ATTR::VIT];
if (vit < 0)
@@ -229,9 +229,9 @@ int battle_get_int(struct block_list *bl)
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
int_ = ((struct mob_data *) bl)->stats[mob_stat::INT];
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
int_ = ((struct map_session_data *) bl)->paramc[ATTR::INT];
if (int_ < 0)
@@ -251,9 +251,9 @@ int battle_get_dex(struct block_list *bl)
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
dex = ((struct mob_data *) bl)->stats[mob_stat::DEX];
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
dex = ((struct map_session_data *) bl)->paramc[ATTR::DEX];
if (dex < 0)
@@ -273,16 +273,11 @@ int battle_get_luk(struct block_list *bl)
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
luk = ((struct mob_data *) bl)->stats[mob_stat::LUK];
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
luk = ((struct map_session_data *) bl)->paramc[ATTR::LUK];
- if (sc_data)
- {
- if (sc_data[StatusChange::SC_CURSE].timer != -1) // 呪い
- luk = 0;
- }
if (luk < 0)
luk = 0;
return luk;
@@ -301,16 +296,13 @@ int battle_get_flee(struct block_list *bl)
nullpo_retr(1, bl);
sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
+ if (bl->type == BL::PC)
flee = ((struct map_session_data *) bl)->flee;
else
flee = battle_get_agi(bl) + battle_get_lv(bl);
if (sc_data)
{
- if (sc_data[StatusChange::SC_BLIND].timer != -1 && bl->type != BL::PC)
- flee -= flee * 25 / 100;
-
if (battle_is_unarmed(bl))
flee += (skill_power_bl(bl, SkillID::TMW_BRAWLING) >> 3); // +25 for 200
flee += skill_power_bl(bl, SkillID::TMW_SPEED) >> 3;
@@ -333,16 +325,13 @@ int battle_get_hit(struct block_list *bl)
nullpo_retr(1, bl);
sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
+ if (bl->type == BL::PC)
hit = ((struct map_session_data *) bl)->hit;
else
hit = battle_get_dex(bl) + battle_get_lv(bl);
if (sc_data)
{
- if (sc_data[StatusChange::SC_BLIND].timer != -1 && bl->type != BL::PC) // 呪い
- hit -= hit * 25 / 100;
-
if (battle_is_unarmed(bl))
hit += (skill_power_bl(bl, SkillID::TMW_BRAWLING) >> 4); // +12 for 200
}
@@ -364,7 +353,7 @@ int battle_get_flee2(struct block_list *bl)
nullpo_retr(1, bl);
sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
+ if (bl->type == BL::PC)
{
flee2 = battle_get_luk(bl) + 10;
flee2 +=
@@ -397,7 +386,7 @@ int battle_get_critical(struct block_list *bl)
nullpo_retr(1, bl);
sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
+ if (bl->type == BL::PC)
{
critical = battle_get_luk(bl) * 2 + 10;
critical +=
@@ -425,7 +414,7 @@ int battle_get_baseatk(struct block_list *bl)
nullpo_retr(1, bl);
sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
+ if (bl->type == BL::PC)
batk = ((struct map_session_data *) bl)->base_atk; //設定されているbase_atk
else
{ //それ以外なら
@@ -434,11 +423,6 @@ int battle_get_baseatk(struct block_list *bl)
dstr = str / 10;
batk = dstr * dstr + str; //base_atkを計算する
}
- if (sc_data)
- { //状態異常あり
- if (sc_data[StatusChange::SC_CURSE].timer != -1) //呪われていたら
- batk -= batk * 25 / 100; //base_atkが25%減少
- }
if (batk < 1)
batk = 1; //base_atkは最低でも1
return batk;
@@ -457,16 +441,11 @@ int battle_get_atk(struct block_list *bl)
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
+ if (bl->type == BL::PC)
atk = ((struct map_session_data *) bl)->watk;
- else if (bl->type == BL::MOB && (struct mob_data *) bl)
+ else if (bl->type == BL::MOB)
atk = ((struct mob_data *) bl)->stats[mob_stat::ATK1];
- if (sc_data)
- {
- if (sc_data[StatusChange::SC_CURSE].timer != -1)
- atk -= atk * 25 / 100;
- }
if (atk < 0)
atk = 0;
return atk;
@@ -481,14 +460,8 @@ static
int battle_get_atk_(struct block_list *bl)
{
nullpo_ret(bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
- {
- int atk = ((struct map_session_data *) bl)->watk_;
-
- if (((struct map_session_data *) bl)->sc_data[StatusChange::SC_CURSE].timer != -1)
- atk -= atk * 25 / 100;
- return atk;
- }
+ if (bl->type == BL::PC)
+ return ((struct map_session_data *) bl)->watk_;
else
return 0;
}
@@ -502,19 +475,13 @@ static
int battle_get_atk2(struct block_list *bl)
{
nullpo_ret(bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
+ if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->watk2;
else
{
- eptr<struct status_change, StatusChange> sc_data = battle_get_sc_data(bl);
int atk2 = 0;
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
atk2 = ((struct mob_data *) bl)->stats[mob_stat::ATK2];
- if (sc_data)
- {
- if (sc_data[StatusChange::SC_CURSE].timer != -1)
- atk2 -= atk2 * 25 / 100;
- }
if (atk2 < 0)
atk2 = 0;
@@ -555,7 +522,7 @@ int battle_get_matk1(struct block_list *bl)
return matk;
}
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->matk1;
else
return 0;
@@ -577,7 +544,7 @@ int battle_get_matk2(struct block_list *bl)
return matk;
}
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->matk2;
else
return 0;
@@ -595,11 +562,11 @@ int battle_get_def(struct block_list *bl)
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
+ if (bl->type == BL::PC)
{
def = ((struct map_session_data *) bl)->def;
}
- else if (bl->type == BL::MOB && (struct mob_data *) bl)
+ else if (bl->type == BL::MOB)
{
def = ((struct mob_data *) bl)->stats[mob_stat::DEF];
}
@@ -609,13 +576,9 @@ int battle_get_def(struct block_list *bl)
if (sc_data)
{
//毒にかかっている時は減算
- if (sc_data[StatusChange::SC_POISON].timer != -1 && bl->type != BL::PC)
+ if (sc_data[StatusChange::SC_POISON].timer
+ && bl->type != BL::PC)
def = def * 75 / 100;
- //凍結、石化時は右シフト
- if (sc_data[StatusChange::SC_FREEZE].timer != -1
- || (sc_data[StatusChange::SC_STONE].timer != -1
- && sc_data[StatusChange::SC_STONE].val2 == 0))
- def >>= 1;
}
}
if (def < 0)
@@ -635,9 +598,9 @@ int battle_get_mdef(struct block_list *bl)
nullpo_ret(bl);
sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
+ if (bl->type == BL::PC)
mdef = ((struct map_session_data *) bl)->mdef;
- else if (bl->type == BL::MOB && (struct mob_data *) bl)
+ else if (bl->type == BL::MOB)
mdef = ((struct mob_data *) bl)->stats[mob_stat::MDEF];
if (mdef < 1000000)
@@ -645,17 +608,12 @@ int battle_get_mdef(struct block_list *bl)
if (sc_data)
{
//バリアー状態時はMDEF100
- if (mdef < 90 && sc_data[StatusChange::SC_MBARRIER].timer != -1)
+ if (mdef < 90 && sc_data[StatusChange::SC_MBARRIER].timer)
{
mdef += sc_data[StatusChange::SC_MBARRIER].val1;
if (mdef > 90)
mdef = 90;
}
- //凍結、石化時は1.25倍
- if (sc_data[StatusChange::SC_FREEZE].timer != -1
- || (sc_data[StatusChange::SC_STONE].timer != -1
- && sc_data[StatusChange::SC_STONE].val2 == 0))
- mdef = mdef * 125 / 100;
}
}
if (mdef < 0)
@@ -682,7 +640,8 @@ int battle_get_def2(struct block_list *bl)
if (sc_data)
{
- if (sc_data[StatusChange::SC_POISON].timer != -1 && bl->type != BL::PC)
+ if (sc_data[StatusChange::SC_POISON].timer
+ && bl->type != BL::PC)
def2 = def2 * 75 / 100;
}
if (def2 < 1)
@@ -720,26 +679,18 @@ int battle_get_mdef2(struct block_list *bl)
* Speedは小さいほうが移動速度が速い
*------------------------------------------
*/
-int battle_get_speed(struct block_list *bl)
+interval_t battle_get_speed(struct block_list *bl)
{
- nullpo_retr(1000, bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
+ nullpo_retr(std::chrono::seconds(1), bl);
+ if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->speed;
else
{
- eptr<struct status_change, StatusChange> sc_data = battle_get_sc_data(bl);
- int speed = 1000;
- if (bl->type == BL::MOB && (struct mob_data *) bl)
- speed = ((struct mob_data *) bl)->stats[mob_stat::SPEED];
+ interval_t speed = std::chrono::seconds(1);
+ if (bl->type == BL::MOB)
+ speed = static_cast<interval_t>(((struct mob_data *) bl)->stats[mob_stat::SPEED]);
- if (sc_data)
- {
- if (sc_data[StatusChange::SC_CURSE].timer != -1)
- speed = speed + 450;
- }
- if (speed < 1)
- speed = 1;
- return speed;
+ return std::max(speed, std::chrono::milliseconds(1));
}
}
@@ -748,115 +699,94 @@ int battle_get_speed(struct block_list *bl)
* aDelayは小さいほうが攻撃速度が速い
*------------------------------------------
*/
-int battle_get_adelay(struct block_list *bl)
+// TODO figure out what all the doubling is about
+interval_t battle_get_adelay(struct block_list *bl)
{
- nullpo_retr(4000, bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
- return (((struct map_session_data *) bl)->aspd << 1);
+ nullpo_retr(std::chrono::seconds(4), bl);
+ if (bl->type == BL::PC)
+ return ((struct map_session_data *) bl)->aspd * 2;
else
{
eptr<struct status_change, StatusChange> sc_data = battle_get_sc_data(bl);
- int adelay = 4000, aspd_rate = 100;
- if (bl->type == BL::MOB && (struct mob_data *) bl)
- adelay = ((struct mob_data *) bl)->stats[mob_stat::ADELAY];
+ interval_t adelay = std::chrono::seconds(4);
+ int aspd_rate = 100;
+ if (bl->type == BL::MOB)
+ adelay = static_cast<interval_t>(((struct mob_data *) bl)->stats[mob_stat::ADELAY]);
if (sc_data)
{
- if (sc_data[StatusChange::SC_SPEEDPOTION0].timer != -1)
+ if (sc_data[StatusChange::SC_SPEEDPOTION0].timer)
aspd_rate -= sc_data[StatusChange::SC_SPEEDPOTION0].val1;
// Fate's `haste' spell works the same as the above
- if (sc_data[StatusChange::SC_HASTE].timer != -1)
+ if (sc_data[StatusChange::SC_HASTE].timer)
aspd_rate -= sc_data[StatusChange::SC_HASTE].val1;
}
if (aspd_rate != 100)
adelay = adelay * aspd_rate / 100;
- if (adelay < battle_config.monster_max_aspd << 1)
- adelay = battle_config.monster_max_aspd << 1;
- return adelay;
+ return std::max(adelay, static_cast<interval_t>(battle_config.monster_max_aspd) * 2);
}
}
-int battle_get_amotion(struct block_list *bl)
+interval_t battle_get_amotion(struct block_list *bl)
{
- nullpo_retr(2000, bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
+ nullpo_retr(std::chrono::seconds(2), bl);
+ if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->amotion;
else
{
eptr<struct status_change, StatusChange> sc_data = battle_get_sc_data(bl);
- int amotion = 2000, aspd_rate = 100;
- if (bl->type == BL::MOB && (struct mob_data *) bl)
- amotion = mob_db[((struct mob_data *) bl)->mob_class].amotion;
+ interval_t amotion = std::chrono::seconds(2);
+ int aspd_rate = 100;
+ if (bl->type == BL::MOB)
+ amotion = static_cast<interval_t>(mob_db[((struct mob_data *) bl)->mob_class].amotion);
if (sc_data)
{
- if (sc_data[StatusChange::SC_SPEEDPOTION0].timer != -1)
+ if (sc_data[StatusChange::SC_SPEEDPOTION0].timer)
aspd_rate -= sc_data[StatusChange::SC_SPEEDPOTION0].val1;
- if (sc_data[StatusChange::SC_HASTE].timer != -1)
+ if (sc_data[StatusChange::SC_HASTE].timer)
aspd_rate -= sc_data[StatusChange::SC_HASTE].val1;
}
if (aspd_rate != 100)
amotion = amotion * aspd_rate / 100;
- if (amotion < battle_config.monster_max_aspd)
- amotion = battle_config.monster_max_aspd;
- return amotion;
+ return std::max(amotion, static_cast<interval_t>(battle_config.monster_max_aspd));
}
}
-int battle_get_dmotion(struct block_list *bl)
+interval_t battle_get_dmotion(struct block_list *bl)
{
- int ret;
- eptr<struct status_change, StatusChange> sc_data;
-
- nullpo_ret(bl);
- sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ nullpo_retr(interval_t::zero(), bl);
+ if (bl->type == BL::MOB)
{
- ret = mob_db[((struct mob_data *) bl)->mob_class].dmotion;
- if (battle_config.monster_damage_delay_rate != 100)
- ret = ret * battle_config.monster_damage_delay_rate / 400;
+ return static_cast<interval_t>(mob_db[((struct mob_data *) bl)->mob_class].dmotion);
}
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
{
- ret = ((struct map_session_data *) bl)->dmotion;
- if (battle_config.pc_damage_delay_rate != 100)
- ret = ret * battle_config.pc_damage_delay_rate / 400;
+ return ((struct map_session_data *) bl)->dmotion;
}
else
- return 2000;
-
- return ret;
+ return std::chrono::seconds(2);
}
LevelElement battle_get_element(struct block_list *bl)
{
LevelElement ret = {2, Element::neutral};
- eptr<struct status_change, StatusChange> sc_data;
nullpo_retr(ret, bl);
- sc_data = battle_get_sc_data(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl) // 10の位=Lv*2、1の位=属性
+ if (bl->type == BL::MOB) // 10の位=Lv*2、1の位=属性
ret = ((struct mob_data *) bl)->def_ele;
- if (sc_data)
- {
- if (sc_data[StatusChange::SC_FREEZE].timer != -1) // 凍結
- ret = LevelElement{2, Element::water};
- if (sc_data[StatusChange::SC_STONE].timer != -1 && sc_data[StatusChange::SC_STONE].val2 == 0)
- ret = LevelElement{2, Element::earth};
- }
-
return ret;
}
int battle_get_party_id(struct block_list *bl)
{
nullpo_ret(bl);
- if (bl->type == BL::PC && (struct map_session_data *) bl)
+ if (bl->type == BL::PC)
return ((struct map_session_data *) bl)->status.party_id;
- else if (bl->type == BL::MOB && (struct mob_data *) bl)
+ else if (bl->type == BL::MOB)
{
struct mob_data *md = (struct mob_data *) bl;
if (md->master_id > 0)
@@ -869,9 +799,9 @@ int battle_get_party_id(struct block_list *bl)
Race battle_get_race(struct block_list *bl)
{
nullpo_retr(Race::formless, bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
return mob_db[((struct mob_data *) bl)->mob_class].race;
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return Race::demihuman;
else
return Race::formless;
@@ -880,7 +810,7 @@ Race battle_get_race(struct block_list *bl)
MobMode battle_get_mode(struct block_list *bl)
{
nullpo_retr(MobMode::CAN_MOVE, bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
return mob_db[((struct mob_data *) bl)->mob_class].mode;
// とりあえず動くということで1
return MobMode::CAN_MOVE;
@@ -889,7 +819,7 @@ MobMode battle_get_mode(struct block_list *bl)
int battle_get_mexp(struct block_list *bl)
{
nullpo_ret(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
{
const struct mob_data *mob = (struct mob_data *) bl;
const int retval =
@@ -942,9 +872,9 @@ eptr<struct status_change, StatusChange> battle_get_sc_data(struct block_list *b
short *battle_get_sc_count(struct block_list *bl)
{
nullpo_retr(NULL, bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->sc_count;
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->sc_count;
return NULL;
}
@@ -952,9 +882,9 @@ short *battle_get_sc_count(struct block_list *bl)
Opt1 *battle_get_opt1(struct block_list *bl)
{
nullpo_ret(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->opt1;
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->opt1;
else if (bl->type == BL::NPC && (struct npc_data *) bl)
return &((struct npc_data *) bl)->opt1;
@@ -964,9 +894,9 @@ Opt1 *battle_get_opt1(struct block_list *bl)
Opt2 *battle_get_opt2(struct block_list *bl)
{
nullpo_ret(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->opt2;
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->opt2;
else if (bl->type == BL::NPC && (struct npc_data *) bl)
return &((struct npc_data *) bl)->opt2;
@@ -976,9 +906,9 @@ Opt2 *battle_get_opt2(struct block_list *bl)
Opt3 *battle_get_opt3(struct block_list *bl)
{
nullpo_ret(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->opt3;
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->opt3;
else if (bl->type == BL::NPC && (struct npc_data *) bl)
return &((struct npc_data *) bl)->opt3;
@@ -988,9 +918,9 @@ Opt3 *battle_get_opt3(struct block_list *bl)
Option *battle_get_option(struct block_list *bl)
{
nullpo_ret(bl);
- if (bl->type == BL::MOB && (struct mob_data *) bl)
+ if (bl->type == BL::MOB)
return &((struct mob_data *) bl)->option;
- else if (bl->type == BL::PC && (struct map_session_data *) bl)
+ else if (bl->type == BL::PC)
return &((struct map_session_data *) bl)->status.option;
else if (bl->type == BL::NPC && (struct npc_data *) bl)
return &((struct npc_data *) bl)->option;
@@ -1011,9 +941,6 @@ struct battle_delay_damage_
int battle_damage(struct block_list *bl, struct block_list *target,
int damage, int flag)
{
- eptr<struct status_change, StatusChange> sc_data = battle_get_sc_data(target);
- short *sc_count;
-
nullpo_ret(target); //blはNULLで呼ばれることがあるので他でチェック
if (damage == 0)
@@ -1031,22 +958,10 @@ int battle_damage(struct block_list *bl, struct block_list *target,
if (damage < 0)
return battle_heal(bl, target, -damage, 0, flag);
- if (!flag && (sc_count = battle_get_sc_count(target)) != NULL
- && *sc_count > 0)
- {
- // 凍結、石化、睡眠を消去
- if (sc_data[StatusChange::SC_FREEZE].timer != -1)
- skill_status_change_end(target, StatusChange::SC_FREEZE, -1);
- if (sc_data[StatusChange::SC_STONE].timer != -1 && sc_data[StatusChange::SC_STONE].val2 == 0)
- skill_status_change_end(target, StatusChange::SC_STONE, -1);
- if (sc_data[StatusChange::SC_SLEEP].timer != -1)
- skill_status_change_end(target, StatusChange::SC_SLEEP, -1);
- }
-
if (target->type == BL::MOB)
{ // MOB
struct mob_data *md = (struct mob_data *) target;
- if (md && md->skilltimer != -1 && md->state.skillcastcancel) // 詠唱妨害
+ if (md && md->skilltimer && md->state.skillcastcancel) // 詠唱妨害
skill_castcancel(target, 0);
return mob_damage(bl, md, damage, 0);
}
@@ -1230,8 +1145,6 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src,
if (cri < 1)
cri = 1;
}
- if (t_sc_data && t_sc_data[StatusChange::SC_SLEEP].timer != -1) // 睡眠中はクリティカルが倍に
- cri <<= 1;
if (ac_flag)
cri = 1000;
@@ -1349,11 +1262,7 @@ struct Damage battle_calc_mob_weapon_attack(struct block_list *src,
// 回避修正
if (hitrate < 1000000)
hitrate = ((hitrate > 95) ? 95 : ((hitrate < 5) ? 5 : hitrate));
- if (hitrate < 1000000 && // 必中攻撃
- (t_sc_data && (t_sc_data[StatusChange::SC_SLEEP].timer != -1 || // 睡眠は必中
- t_sc_data[StatusChange::SC_STAN].timer != -1 || // スタンは必中
- t_sc_data[StatusChange::SC_FREEZE].timer != -1 || (t_sc_data[StatusChange::SC_STONE].timer != -1 && t_sc_data[StatusChange::SC_STONE].val2 == 0)))) // 凍結は必中
- hitrate = 1000000;
+
if (type == DamageType::NORMAL && MRAND(100) >= hitrate)
{
damage = damage2 = 0;
@@ -1581,8 +1490,6 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
// カタールの場合、クリティカルを倍に
cri <<= 1;
cri -= battle_get_luk(target) * 3;
- if (t_sc_data && t_sc_data[StatusChange::SC_SLEEP].timer != -1) // 睡眠中はクリティカルが倍に
- cri <<= 1;
if (ac_flag)
cri = 1000;
}
@@ -1763,11 +1670,6 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
// 回避修正
hitrate = (hitrate < 5) ? 5 : hitrate;
- if (hitrate < 1000000 && // 必中攻撃
- (t_sc_data && (t_sc_data[StatusChange::SC_SLEEP].timer != -1 || // 睡眠は必中
- t_sc_data[StatusChange::SC_STAN].timer != -1 || // スタンは必中
- t_sc_data[StatusChange::SC_FREEZE].timer != -1 || (t_sc_data[StatusChange::SC_STONE].timer != -1 && t_sc_data[StatusChange::SC_STONE].val2 == 0)))) // 凍結は必中
- hitrate = 1000000;
if (type == DamageType::NORMAL && MRAND(100) >= hitrate)
{
damage = damage2 = 0;
@@ -1786,8 +1688,6 @@ struct Damage battle_calc_pc_weapon_attack(struct block_list *src,
// 星のかけら、気球の適用
damage += sd->star;
damage2 += sd->star_;
- damage += sd->spiritball * 3;
- damage2 += sd->spiritball * 3;
// >二刀流の左右ダメージ計算誰かやってくれぇぇぇぇえええ!
// >map_session_data に左手ダメージ(atk,atk2)追加して
@@ -2145,7 +2045,7 @@ struct Damage battle_calc_attack(BF attack_type,
*------------------------------------------
*/
ATK battle_weapon_attack(struct block_list *src, struct block_list *target,
- unsigned int tick, BCT)
+ tick_t tick)
{
struct map_session_data *sd = NULL;
eptr<struct status_change, StatusChange> t_sc_data = battle_get_sc_data(target);
@@ -2192,13 +2092,14 @@ ATK battle_weapon_attack(struct block_list *src, struct block_list *target,
wd = battle_calc_weapon_attack(src, target, SkillID::ZERO, 0, 0);
// significantly increase injuries for hasted characters
- if (wd.damage > 0 && (t_sc_data[StatusChange::SC_HASTE].timer != -1))
+ if (wd.damage > 0 && t_sc_data[StatusChange::SC_HASTE].timer)
{
wd.damage = (wd.damage * (16 + t_sc_data[StatusChange::SC_HASTE].val1)) >> 4;
}
if (wd.damage > 0
- && t_sc_data[StatusChange::SC_PHYS_SHIELD].timer != -1 && target->type == BL::PC)
+ && t_sc_data[StatusChange::SC_PHYS_SHIELD].timer
+ && target->type == BL::PC)
{
int reduction = t_sc_data[StatusChange::SC_PHYS_SHIELD].val1;
if (reduction > wd.damage)
@@ -2214,8 +2115,8 @@ ATK battle_weapon_attack(struct block_list *src, struct block_list *target,
wd.damage, wd.div_, wd.type, wd.damage2);
//二刀流左手とカタール追撃のミス表示(無理やり〜)
if (sd && sd->status.weapon >= 16 && wd.damage2 == 0)
- clif_damage(src, target, tick + 10, wd.amotion, wd.dmotion,
- 0, 1, DamageType::NORMAL, 0);
+ clif_damage(src, target, tick + std::chrono::milliseconds(10),
+ wd.amotion, wd.dmotion, 0, 1, DamageType::NORMAL, 0);
}
map_freeblock_lock();
@@ -2259,7 +2160,7 @@ ATK battle_weapon_attack(struct block_list *src, struct block_list *target,
{
if (wd.damage > 0 || wd.damage2 > 0)
{
- skill_additional_effect(src, target, SkillID::ZERO, 0, BF::WEAPON, tick);
+ skill_additional_effect(src, target, SkillID::ZERO, 0);
}
}
if (sd)
@@ -2350,7 +2251,7 @@ int battle_check_target(struct block_list *src, struct block_list *target,
}
if (target->type == BL::PC
- && ((struct map_session_data *) target)->invincible_timer != -1)
+ && ((struct map_session_data *) target)->invincible_timer)
return -1;
// Mobでmaster_idがあってspecial_mob_aiなら、召喚主を求める
@@ -2502,11 +2403,10 @@ int battle_config_read(const char *cfgName)
battle_config.skill_out_range_consume = 1;
battle_config.mob_skill_add_range = 0;
battle_config.pc_damage_delay = 1;
- battle_config.pc_damage_delay_rate = 100;
battle_config.defnotenemy = 1;
battle_config.random_monster_checklv = 1;
battle_config.attr_recover = 1;
- battle_config.flooritem_lifetime = LIFETIME_FLOORITEM * 1000;
+ battle_config.flooritem_lifetime = (int)std::chrono::duration_cast<std::chrono::milliseconds>(LIFETIME_FLOORITEM).count();
battle_config.item_auto_get = 0;
battle_config.drop_pickup_safety_zone = 20;
battle_config.item_first_get_time = 3000;
@@ -2541,7 +2441,6 @@ int battle_config_read(const char *cfgName)
battle_config.wp_rate = 100;
battle_config.pp_rate = 100;
battle_config.monster_active_enable = 1;
- battle_config.monster_damage_delay_rate = 100;
battle_config.monster_loot_type = 0;
battle_config.mob_skill_use = 1;
battle_config.mob_count_rate = 100;
@@ -2653,9 +2552,6 @@ int battle_config_read(const char *cfgName)
battle_config.pk_mode = 0; // [Valaris]
battle_config.multi_level_up = 0; // [Valaris]
battle_config.backstab_bow_penalty = 0; // Akaru
- battle_config.night_at_start = 0; // added by [Yor]
- battle_config.day_duration = 2 * 60 * 60 * 1000; // added by [Yor] (2 hours)
- battle_config.night_duration = 30 * 60 * 1000; // added by [Yor] (30 minutes)
battle_config.show_mob_hp = 0; // [Valaris]
battle_config.hack_info_GM_level = 60; // added by [Yor] (default: 60, GM level)
battle_config.any_warp_GM_min_level = 20; // added by [Yor]
@@ -2718,7 +2614,6 @@ int battle_config_read(const char *cfgName)
{"skill_out_range_consume", &battle_config.skill_out_range_consume},
{"monster_skill_add_range", &battle_config.mob_skill_add_range},
{"player_damage_delay", &battle_config.pc_damage_delay},
- {"player_damage_delay_rate", &battle_config.pc_damage_delay_rate},
{"defunit_not_enemy", &battle_config.defnotenemy},
{"random_monster_checklv", &battle_config.random_monster_checklv},
{"attribute_recover", &battle_config.attr_recover},
@@ -2759,7 +2654,6 @@ int battle_config_read(const char *cfgName)
{"weapon_produce_rate", &battle_config.wp_rate},
{"potion_produce_rate", &battle_config.pp_rate},
{"monster_active_enable", &battle_config.monster_active_enable},
- {"monster_damage_delay_rate", &battle_config.monster_damage_delay_rate},
{"monster_loot_type", &battle_config.monster_loot_type},
{"mob_skill_use", &battle_config.mob_skill_use},
{"mob_count_rate", &battle_config.mob_count_rate},
@@ -2869,9 +2763,6 @@ int battle_config_read(const char *cfgName)
{"pk_mode", &battle_config.pk_mode}, // [Valaris]
{"multi_level_up", &battle_config.multi_level_up}, // [Valaris]
{"backstab_bow_penalty", &battle_config.backstab_bow_penalty},
- {"night_at_start", &battle_config.night_at_start}, // added by [Yor]
- {"day_duration", &battle_config.day_duration}, // added by [Yor]
- {"night_duration", &battle_config.night_duration}, // added by [Yor]
{"show_mob_hp", &battle_config.show_mob_hp}, // [Valaris]
{"hack_info_GM_level", &battle_config.hack_info_GM_level}, // added by [Yor]
{"any_warp_GM_min_level", &battle_config.any_warp_GM_min_level}, // added by [Yor]
@@ -2884,7 +2775,6 @@ int battle_config_read(const char *cfgName)
{"max_cloth_color", &battle_config.max_cloth_color}, // added by [MouseJstr]
{"castrate_dex_scale", &battle_config.castrate_dex_scale}, // added by [MouseJstr]
{"area_size", &battle_config.area_size}, // added by [MouseJstr]
- {"muting_players", &battle_config.muting_players}, // added by [Apple]
{"chat_lame_penalty", &battle_config.chat_lame_penalty},
{"chat_spam_threshold", &battle_config.chat_spam_threshold},
{"chat_spam_flood", &battle_config.chat_spam_flood},
@@ -2923,8 +2813,8 @@ int battle_config_read(const char *cfgName)
if (--count == 0)
{
- if (battle_config.flooritem_lifetime < 1000)
- battle_config.flooritem_lifetime = LIFETIME_FLOORITEM * 1000;
+ if (static_cast<interval_t>(battle_config.flooritem_lifetime) < std::chrono::seconds(1))
+ battle_config.flooritem_lifetime = (int)std::chrono::duration_cast<std::chrono::milliseconds>(LIFETIME_FLOORITEM).count();
if (battle_config.restart_hp_rate < 0)
battle_config.restart_hp_rate = 0;
else if (battle_config.restart_hp_rate > 100)
@@ -2933,12 +2823,12 @@ int battle_config_read(const char *cfgName)
battle_config.restart_sp_rate = 0;
else if (battle_config.restart_sp_rate > 100)
battle_config.restart_sp_rate = 100;
- if (battle_config.natural_healhp_interval < NATURAL_HEAL_INTERVAL)
- battle_config.natural_healhp_interval = NATURAL_HEAL_INTERVAL;
- if (battle_config.natural_healsp_interval < NATURAL_HEAL_INTERVAL)
- battle_config.natural_healsp_interval = NATURAL_HEAL_INTERVAL;
- if (battle_config.natural_heal_skill_interval < NATURAL_HEAL_INTERVAL)
- battle_config.natural_heal_skill_interval = NATURAL_HEAL_INTERVAL;
+ if (battle_config.natural_healhp_interval < NATURAL_HEAL_INTERVAL.count())
+ battle_config.natural_healhp_interval = NATURAL_HEAL_INTERVAL.count();
+ if (battle_config.natural_healsp_interval < NATURAL_HEAL_INTERVAL.count())
+ battle_config.natural_healsp_interval = NATURAL_HEAL_INTERVAL.count();
+ if (battle_config.natural_heal_skill_interval < NATURAL_HEAL_INTERVAL.count())
+ battle_config.natural_heal_skill_interval = NATURAL_HEAL_INTERVAL.count();
if (battle_config.natural_heal_weight_rate < 50)
battle_config.natural_heal_weight_rate = 50;
if (battle_config.natural_heal_weight_rate > 101)
@@ -2994,15 +2884,6 @@ int battle_config_read(const char *cfgName)
if (battle_config.item_drop_mvp_max > 10000)
battle_config.item_drop_mvp_max = 10000; // End Addition
- if (battle_config.night_at_start < 0) // added by [Yor]
- battle_config.night_at_start = 0;
- else if (battle_config.night_at_start > 1) // added by [Yor]
- battle_config.night_at_start = 1;
- if (battle_config.day_duration < 0) // added by [Yor]
- battle_config.day_duration = 0;
- if (battle_config.night_duration < 0) // added by [Yor]
- battle_config.night_duration = 0;
-
if (battle_config.hack_info_GM_level < 0) // added by [Yor]
battle_config.hack_info_GM_level = 0;
else if (battle_config.hack_info_GM_level > 100)
diff --git a/src/map/battle.hpp b/src/map/battle.hpp
index c4b4601..263e3f6 100644
--- a/src/map/battle.hpp
+++ b/src/map/battle.hpp
@@ -3,6 +3,8 @@
#include "battle.t.hpp"
+#include "../common/timer.t.hpp"
+
#include "magic-interpreter.t.hpp"
#include "map.t.hpp"
#include "skill.t.hpp"
@@ -13,7 +15,7 @@ struct Damage
int damage, damage2;
DamageType type;
int div_;
- int amotion, dmotion;
+ interval_t amotion, dmotion;
BF flag;
ATK dmg_lv;
};
@@ -40,7 +42,7 @@ int battle_stopwalking(struct block_list *bl, int type);
// 通常攻撃処理まとめ
ATK battle_weapon_attack(struct block_list *bl, struct block_list *target,
- unsigned int tick, BCT flag);
+ tick_t tick);
int battle_is_unarmed(struct block_list *bl);
int battle_get_class(struct block_list *bl);
@@ -59,10 +61,10 @@ int battle_get_def(struct block_list *bl);
int battle_get_mdef(struct block_list *bl);
int battle_get_def2(struct block_list *bl);
int battle_get_mdef2(struct block_list *bl);
-int battle_get_speed(struct block_list *bl);
-int battle_get_adelay(struct block_list *bl);
-int battle_get_amotion(struct block_list *bl);
-int battle_get_dmotion(struct block_list *bl);
+interval_t battle_get_speed(struct block_list *bl);
+interval_t battle_get_adelay(struct block_list *bl);
+interval_t battle_get_amotion(struct block_list *bl);
+interval_t battle_get_dmotion(struct block_list *bl);
LevelElement battle_get_element(struct block_list *bl);
inline
Element battle_get_elem_type(struct block_list *bl)
@@ -102,7 +104,6 @@ extern struct Battle_Config
int skill_out_range_consume;
int mob_skill_add_range;
int pc_damage_delay;
- int pc_damage_delay_rate;
int defnotenemy;
int random_monster_checklv;
int attr_recover;
@@ -138,7 +139,6 @@ extern struct Battle_Config
int wp_rate;
int pp_rate;
int monster_active_enable;
- int monster_damage_delay_rate;
int monster_loot_type;
int mob_skill_use;
int mob_count_rate;
@@ -248,13 +248,9 @@ extern struct Battle_Config
int riding_weight;
int backstab_bow_penalty;
- int night_at_start; // added by [Yor]
- int day_duration; // added by [Yor]
- int night_duration; // added by [Yor]
int hack_info_GM_level; // added by [Yor]
int any_warp_GM_min_level; // added by [Yor]
int packet_ver_flag; // added by [Yor]
- int muting_players; // added by [Apple]
int min_hair_style; // added by [MouseJstr]
int max_hair_style; // added by [MouseJstr]
diff --git a/src/map/chrif.cpp b/src/map/chrif.cpp
index 360c054..9743072 100644
--- a/src/map/chrif.cpp
+++ b/src/map/chrif.cpp
@@ -7,6 +7,7 @@
#include "../common/cxxstdio.hpp"
#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
+#include "../common/timer.hpp"
#include "../common/utils.hpp"
#include "battle.hpp"
@@ -1160,7 +1161,7 @@ void chrif_parse(int fd)
*------------------------------------------
*/
static
-void send_users_tochar(timer_id, tick_t, custom_id_t, custom_data_t)
+void send_users_tochar(TimerData *, tick_t)
{
int users = 0, i;
struct map_session_data *sd;
@@ -1191,7 +1192,7 @@ void send_users_tochar(timer_id, tick_t, custom_id_t, custom_data_t)
*------------------------------------------
*/
static
-void check_connect_char_server(timer_id, tick_t, custom_id_t, custom_data_t)
+void check_connect_char_server(TimerData *, tick_t)
{
if (char_fd <= 0 || session[char_fd] == NULL)
{
@@ -1212,11 +1213,10 @@ void check_connect_char_server(timer_id, tick_t, custom_id_t, custom_data_t)
*/
int do_init_chrif (void)
{
-// add_timer_func_list (check_connect_char_server, "check_connect_char_server");
-// add_timer_func_list (send_users_tochar, "send_users_tochar");
- add_timer_interval(gettick() + 1000, check_connect_char_server, 0, 0,
- 10 * 1000);
- add_timer_interval(gettick() + 1000, send_users_tochar, 0, 0, 5 * 1000);
+ add_timer_interval(gettick() + std::chrono::seconds(1),
+ check_connect_char_server,
+ std::chrono::seconds(10));
+ add_timer_interval(gettick() + std::chrono::seconds(1), send_users_tochar, std::chrono::seconds(5));
return 0;
}
diff --git a/src/map/clif.cpp b/src/map/clif.cpp
index 65b5246..b0fef3a 100644
--- a/src/map/clif.cpp
+++ b/src/map/clif.cpp
@@ -11,6 +11,7 @@
#include "../common/mt_rand.hpp"
#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
+#include "../common/timer.hpp"
#include "../common/version.hpp"
#include "atcommand.hpp"
@@ -34,89 +35,49 @@
constexpr int EMOTE_IGNORED = 0x0e;
-static
-const int packet_len_table[0x220] = {
- 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-//#0x0040
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, -1, 55, 17, 3, 37, 46, -1, 23, -1, 3, 108, 3, 2,
- 3, 28, 19, 11, 3, -1, 9, 5, 54, 53, 58, 60, 41, 2, 6, 6,
-//#0x0080
- 7, 3, 2, 2, 2, 5, 16, 12, 10, 7, 29, 23, -1, -1, -1, 0, // 0x8b unknown... size 2 or 23?
- 7, 22, 28, 2, 6, 30, -1, -1, 3, -1, -1, 5, 9, 17, 17, 6,
- 23, 6, 6, -1, -1, -1, -1, 8, 7, 6, 7, 4, 7, 0, -1, 6,
- 8, 8, 3, 3, -1, 6, 6, -1, 7, 6, 2, 5, 6, 44, 5, 3,
-//#0x00C0
- 7, 2, 6, 8, 6, 7, -1, -1, -1, -1, 3, 3, 6, 6, 2, 27,
- 3, 4, 4, 2, -1, -1, 3, -1, 6, 14, 3, -1, 28, 29, -1, -1,
- 30, 30, 26, 2, 6, 26, 3, 3, 8, 19, 5, 2, 3, 2, 2, 2,
- 3, 2, 6, 8, 21, 8, 8, 2, 2, 26, 3, -1, 6, 27, 30, 10,
-
-//#0x0100
- 2, 6, 6, 30, 79, 31, 10, 10, -1, -1, 4, 6, 6, 2, 11, -1,
- 10, 39, 4, 10, 31, 35, 10, 18, 2, 13, 15, 20, 68, 2, 3, 16,
- 6, 14, -1, -1, 21, 8, 8, 8, 8, 8, 2, 2, 3, 4, 2, -1,
- 6, 86, 6, -1, -1, 7, -1, 6, 3, 16, 4, 4, 4, 6, 24, 26,
-//#0x0140
- 22, 14, 6, 10, 23, 19, 6, 39, 8, 9, 6, 27, -1, 2, 6, 6,
- 110, 6, -1, -1, -1, -1, -1, 6, -1, 54, 66, 54, 90, 42, 6, 42,
- -1, -1, -1, -1, -1, 30, -1, 3, 14, 3, 30, 10, 43, 14, 186, 182,
- 14, 30, 10, 3, -1, 6, 106, -1, 4, 5, 4, -1, 6, 7, -1, -1,
-//#0x0180
- 6, 3, 106, 10, 10, 34, 0, 6, 8, 4, 4, 4, 29, -1, 10, 6,
- 90, 86, 24, 6, 30, 102, 9, 4, 8, 4, 14, 10, -1, 6, 2, 6,
- 3, 3, 35, 5, 11, 26, -1, 4, 4, 6, 10, 12, 6, -1, 4, 4,
- 11, 7, -1, 67, 12, 18, 114, 6, 3, 6, 26, 26, 26, 26, 2, 3,
-//#0x01C0, Set 0x1d5=-1
- 2, 14, 10, -1, 22, 22, 4, 2, 13, 97, 0, 9, 9, 30, 6, 28,
- 8, 14, 10, 35, 6, -1, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6,
- 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1,
- -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10,
-//#0x200
- 26, -1, 26, 10, 18, 26, 11, 34, 14, 36, 10, 19, 10, -1, 24, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+// functions list. Rate is how many milliseconds are required between
+// calls. Packets exceeding this rate will be dropped. flood_rates in
+// map.h must be the same length as this table. rate 0 is default
+// rate -1 is unlimited
+
+typedef void (*clif_func)(int fd, struct map_session_data *sd);
+struct func_table
+{
+ interval_t rate;
+ int len;
+ clif_func func;
+
+ // ctor exists because interval_t must be explicit
+ func_table(int r, int l, clif_func f)
+ : rate(r), len(l), func(f)
+ {}
};
+constexpr int VAR = -1;
+
+extern // not really - defined below
+func_table clif_parse_func_table[0x0220];
+
+
// local define
enum class SendWho
{
ALL_CLIENT,
-#define ALL_CLIENT SendWho::ALL_CLIENT
ALL_SAMEMAP,
-#define ALL_SAMEMAP SendWho::ALL_SAMEMAP
AREA,
-#define AREA SendWho::AREA
AREA_WOS,
-#define AREA_WOS SendWho::AREA_WOS
AREA_WOC,
-#define AREA_WOC SendWho::AREA_WOC
AREA_WOSC,
-#define AREA_WOSC SendWho::AREA_WOSC
AREA_CHAT_WOC,
-#define AREA_CHAT_WOC SendWho::AREA_CHAT_WOC
- // temporary rename to avoid collision with BL::CHAT_
- CHAT_,
-#define CHAT_ SendWho::CHAT_
+ CHAT,
CHAT_WOS,
-#define CHAT_WOS SendWho::CHAT_WOS
PARTY,
-#define PARTY SendWho::PARTY
PARTY_WOS,
-#define PARTY_WOS SendWho::PARTY_WOS
PARTY_SAMEMAP,
-#define PARTY_SAMEMAP SendWho::PARTY_SAMEMAP
PARTY_SAMEMAP_WOS,
-#define PARTY_SAMEMAP_WOS SendWho::PARTY_SAMEMAP_WOS
PARTY_AREA,
-#define PARTY_AREA SendWho::PARTY_AREA
PARTY_AREA_WOS,
-#define PARTY_AREA_WOS SendWho::PARTY_AREA_WOS
SELF,
-#define SELF SendWho::SELF
};
inline
@@ -252,7 +213,7 @@ char *clif_validate_chat(struct map_session_data *sd, int type,
const char **message, size_t *message_len);
/*==========================================
- * clif_sendでAREA*指定時用
+ * clif_sendでSendWho::AREA*指定時用
*------------------------------------------
*/
static
@@ -264,12 +225,12 @@ void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len,
switch (type)
{
- case AREA_WOS:
+ case SendWho::AREA_WOS:
if (bl && bl == src_bl)
return;
break;
- case AREA_CHAT_WOC:
+ case SendWho::AREA_CHAT_WOC:
if (is_deaf(bl)
&& !(bl->type == BL::PC
&& pc_isGM((struct map_session_data *) src_bl)))
@@ -278,12 +239,12 @@ void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len,
return;
}
FALLTHROUGH;
- case AREA_WOC:
+ case SendWho::AREA_WOC:
if ((sd && sd->chatID) || (bl && bl == src_bl))
return;
break;
- case AREA_WOSC:
+ case SendWho::AREA_WOSC:
if ((sd) && sd->chatID
&& sd->chatID == ((struct map_session_data *) src_bl)->chatID)
return;
@@ -302,8 +263,9 @@ void clif_send_sub(struct block_list *bl, const unsigned char *buf, int len,
}
else
{
- if (packet_len_table[RBUFW(buf, 0)])
- { // packet must exist
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
+ {
+ // packet must exist
memcpy(WFIFOP(sd->fd, 0), buf, len);
WFIFOSET(sd->fd, len);
}
@@ -324,7 +286,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type)
struct party *p = NULL;
int x0 = 0, x1 = 0, y0 = 0, y1 = 0;
- if (type != ALL_CLIENT)
+ if (type != SendWho::ALL_CLIENT)
{
nullpo_ret(bl);
@@ -337,13 +299,13 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type)
switch (type)
{
- case AREA:
- case AREA_WOC:
- type = SELF;
+ case SendWho::AREA:
+ case SendWho::AREA_WOC:
+ type = SendWho::SELF;
break;
- case AREA_WOS:
- case AREA_WOSC:
+ case SendWho::AREA_WOS:
+ case SendWho::AREA_WOSC:
return 1;
default:
@@ -355,13 +317,13 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type)
switch (type)
{
- case ALL_CLIENT: // 全クライアントに送信
+ case SendWho::ALL_CLIENT: // 全クライアントに送信
for (i = 0; i < fd_max; i++)
{
if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL
&& sd->state.auth)
{
- if (packet_len_table[RBUFW(buf, 0)])
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
{ // packet must exist
memcpy(WFIFOP(i, 0), buf, len);
WFIFOSET(i, len);
@@ -369,13 +331,13 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type)
}
}
break;
- case ALL_SAMEMAP: // 同じマップの全クライアントに送信
+ case SendWho::ALL_SAMEMAP: // 同じマップの全クライアントに送信
for (i = 0; i < fd_max; i++)
{
if (session[i] && (sd = (struct map_session_data *)session[i]->session_data) != NULL
&& sd->state.auth && sd->bl.m == bl->m)
{
- if (packet_len_table[RBUFW(buf, 0)])
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
{ // packet must exist
memcpy(WFIFOP(i, 0), buf, len);
WFIFOSET(i, len);
@@ -383,21 +345,21 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type)
}
}
break;
- case AREA:
- case AREA_WOS:
- case AREA_WOC:
- case AREA_WOSC:
+ case SendWho::AREA:
+ case SendWho::AREA_WOS:
+ case SendWho::AREA_WOC:
+ case SendWho::AREA_WOSC:
map_foreachinarea(std::bind(clif_send_sub, ph::_1, buf, len, bl, type),
bl->m, bl->x - AREA_SIZE, bl->y - AREA_SIZE,
bl->x + AREA_SIZE, bl->y + AREA_SIZE, BL::PC);
break;
- case AREA_CHAT_WOC:
- map_foreachinarea(std::bind(clif_send_sub, ph::_1, buf, len, bl, AREA_CHAT_WOC),
+ case SendWho::AREA_CHAT_WOC:
+ map_foreachinarea(std::bind(clif_send_sub, ph::_1, buf, len, bl, SendWho::AREA_CHAT_WOC),
bl->m, bl->x - (AREA_SIZE), bl->y - (AREA_SIZE),
bl->x + (AREA_SIZE), bl->y + (AREA_SIZE), BL::PC);
break;
- case CHAT_:
- case CHAT_WOS:
+ case SendWho::CHAT:
+ case SendWho::CHAT_WOS:
cd = (struct chat_data *) bl;
if (bl->type == BL::PC)
{
@@ -410,10 +372,10 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type)
break;
for (i = 0; i < cd->users; i++)
{
- if (type == CHAT_WOS
+ if (type == SendWho::CHAT_WOS
&& cd->usersd[i] == (struct map_session_data *) bl)
continue;
- if (packet_len_table[RBUFW(buf, 0)])
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
{ // packet must exist
memcpy(WFIFOP(cd->usersd[i]->fd, 0), buf, len);
WFIFOSET(cd->usersd[i]->fd, len);
@@ -421,17 +383,17 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type)
}
break;
- case PARTY_AREA: // 同じ画面内の全パーティーメンバに送信
- case PARTY_AREA_WOS: // 自分以外の同じ画面内の全パーティーメンバに送信
+ case SendWho::PARTY_AREA: // 同じ画面内の全パーティーメンバに送信
+ case SendWho::PARTY_AREA_WOS: // 自分以外の同じ画面内の全パーティーメンバに送信
x0 = bl->x - AREA_SIZE;
y0 = bl->y - AREA_SIZE;
x1 = bl->x + AREA_SIZE;
y1 = bl->y + AREA_SIZE;
FALLTHROUGH;
- case PARTY: // 全パーティーメンバに送信
- case PARTY_WOS: // 自分以外の全パーティーメンバに送信
- case PARTY_SAMEMAP: // 同じマップの全パーティーメンバに送信
- case PARTY_SAMEMAP_WOS: // 自分以外の同じマップの全パーティーメンバに送信
+ case SendWho::PARTY: // 全パーティーメンバに送信
+ case SendWho::PARTY_WOS: // 自分以外の全パーティーメンバに送信
+ case SendWho::PARTY_SAMEMAP: // 同じマップの全パーティーメンバに送信
+ case SendWho::PARTY_SAMEMAP_WOS: // 自分以外の同じマップの全パーティーメンバに送信
if (bl->type == BL::PC)
{
sd = (struct map_session_data *) bl;
@@ -451,18 +413,18 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type)
{
if ((sd = p->member[i].sd) != NULL)
{
- if (sd->bl.id == bl->id && (type == PARTY_WOS ||
- type == PARTY_SAMEMAP_WOS
+ if (sd->bl.id == bl->id && (type == SendWho::PARTY_WOS ||
+ type == SendWho::PARTY_SAMEMAP_WOS
|| type ==
- PARTY_AREA_WOS))
+ SendWho::PARTY_AREA_WOS))
continue;
- if (type != PARTY && type != PARTY_WOS && bl->m != sd->bl.m) // マップチェック
+ if (type != SendWho::PARTY && type != SendWho::PARTY_WOS && bl->m != sd->bl.m) // マップチェック
continue;
- if ((type == PARTY_AREA || type == PARTY_AREA_WOS) &&
+ if ((type == SendWho::PARTY_AREA || type == SendWho::PARTY_AREA_WOS) &&
(sd->bl.x < x0 || sd->bl.y < y0 ||
sd->bl.x > x1 || sd->bl.y > y1))
continue;
- if (packet_len_table[RBUFW(buf, 0)])
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
{ // packet must exist
memcpy(WFIFOP(sd->fd, 0), buf, len);
WFIFOSET(sd->fd, len);
@@ -476,7 +438,7 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type)
{
if (sd->partyspy == p->party_id)
{
- if (packet_len_table[RBUFW(buf, 0)])
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
{ // packet must exist
memcpy(WFIFOP(sd->fd, 0), buf, len);
WFIFOSET(sd->fd, len);
@@ -486,9 +448,9 @@ int clif_send(const uint8_t *buf, int len, struct block_list *bl, SendWho type)
}
}
break;
- case SELF:
+ case SendWho::SELF:
sd = (struct map_session_data *) bl;
- if (packet_len_table[RBUFW(buf, 0)])
+ if (clif_parse_func_table[RBUFW(buf, 0)].len)
{ // packet must exist
memcpy(WFIFOP(sd->fd, 0), buf, len);
WFIFOSET(sd->fd, len);
@@ -526,11 +488,11 @@ int clif_authok(struct map_session_data *sd)
fd = sd->fd;
WFIFOW(fd, 0) = 0x73;
- WFIFOL(fd, 2) = gettick();
+ WFIFOL(fd, 2) = gettick().time_since_epoch().count();
WFIFOPOS(fd, 6, sd->bl.x, sd->bl.y);
WFIFOB(fd, 9) = 5;
WFIFOB(fd, 10) = 5;
- WFIFOSET(fd, packet_len_table[0x73]);
+ WFIFOSET(fd, clif_parse_func_table[0x73].len);
return 0;
}
@@ -546,7 +508,7 @@ int clif_authfail_fd(int fd, int type)
WFIFOW(fd, 0) = 0x81;
WFIFOL(fd, 2) = type;
- WFIFOSET(fd, packet_len_table[0x81]);
+ WFIFOSET(fd, clif_parse_func_table[0x81].len);
clif_setwaitclose(fd);
@@ -571,7 +533,7 @@ int clif_charselectok(int id)
fd = sd->fd;
WFIFOW(fd, 0) = 0xb3;
WFIFOB(fd, 2) = 1;
- WFIFOSET(fd, packet_len_table[0xb3]);
+ WFIFOSET(fd, clif_parse_func_table[0xb3].len);
return 0;
}
@@ -601,7 +563,7 @@ int clif_set009e(struct flooritem_data *fitem, uint8_t *buf)
WBUFB(buf, 14) = fitem->suby;
WBUFW(buf, 15) = fitem->item_data.amount;
- return packet_len_table[0x9e];
+ return clif_parse_func_table[0x9e].len;
}
/*==========================================
@@ -617,7 +579,7 @@ int clif_dropflooritem(struct flooritem_data *fitem)
if (fitem->item_data.nameid <= 0)
return 0;
clif_set009e(fitem, buf);
- clif_send(buf, packet_len_table[0x9e], &fitem->bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x9e].len, &fitem->bl, SendWho::AREA);
return 0;
}
@@ -637,12 +599,12 @@ int clif_clearflooritem(struct flooritem_data *fitem, int fd)
if (fd == 0)
{
- clif_send(buf, packet_len_table[0xa1], &fitem->bl, AREA);
+ clif_send(buf, clif_parse_func_table[0xa1].len, &fitem->bl, SendWho::AREA);
}
else
{
memcpy(WFIFOP(fd, 0), buf, 6);
- WFIFOSET(fd, packet_len_table[0xa1]);
+ WFIFOSET(fd, clif_parse_func_table[0xa1].len);
}
return 0;
@@ -663,35 +625,36 @@ int clif_clearchar(struct block_list *bl, BeingRemoveWhy type)
if (type == BeingRemoveWhy::DISGUISE)
{
WBUFB(buf, 6) = static_cast<uint8_t>(BeingRemoveWhy::GONE);
- clif_send(buf, packet_len_table[0x80], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x80].len, bl, SendWho::AREA);
}
else
{
WBUFB(buf, 6) = static_cast<uint8_t>(type);
- clif_send(buf, packet_len_table[0x80], bl,
- type == BeingRemoveWhy::DEAD ? AREA : AREA_WOS);
+ clif_send(buf, clif_parse_func_table[0x80].len, bl,
+ type == BeingRemoveWhy::DEAD ? SendWho::AREA : SendWho::AREA_WOS);
}
return 0;
}
static
-void clif_clearchar_delay_sub(timer_id, tick_t, custom_id_t id,
- custom_data_t data)
+void clif_clearchar_delay_sub(TimerData *, tick_t,
+ struct block_list *bl, BeingRemoveWhy type)
{
- struct block_list *bl = (struct block_list *) id;
-
- clif_clearchar(bl, static_cast<BeingRemoveWhy>(data));
+ clif_clearchar(bl, type);
map_freeblock(bl);
}
-int clif_clearchar_delay(unsigned int tick, struct block_list *bl, BeingRemoveWhy type)
+int clif_clearchar_delay(tick_t tick,
+ struct block_list *bl, BeingRemoveWhy type)
{
struct block_list *tmpbl;
CREATE(tmpbl, struct block_list, 1);
memcpy(tmpbl, bl, sizeof(struct block_list));
- add_timer(tick, clif_clearchar_delay_sub, (custom_id_t) tmpbl, static_cast<uint8_t>(type));
+ add_timer(tick,
+ std::bind(clif_clearchar_delay_sub, ph::_1, ph::_2,
+ tmpbl, type));
return 0;
}
@@ -708,23 +671,11 @@ int clif_clearchar_id(int id, BeingRemoveWhy type, int fd)
WBUFL(buf, 2) = id;
WBUFB(buf, 6) = static_cast<uint8_t>(type);
memcpy(WFIFOP(fd, 0), buf, 7);
- WFIFOSET(fd, packet_len_table[0x80]);
+ WFIFOSET(fd, clif_parse_func_table[0x80].len);
return 0;
}
-/*
-static
-int current_weapon(struct map_session_data *sd)
-{
- if (sd->attack_spell_override)
- return sd->attack_spell_look_override;
- else {
- return sd->status.weapon;
- }
-}
-*/
-
/*==========================================
*
*------------------------------------------
@@ -736,10 +687,10 @@ int clif_set0078(struct map_session_data *sd, unsigned char *buf)
WBUFW(buf, 0) = 0x1d8;
WBUFL(buf, 2) = sd->bl.id;
- WBUFW(buf, 6) = sd->speed;
- WBUFW(buf, 8) = uint16_t(sd->opt1);
- WBUFW(buf, 10) = uint16_t(sd->opt2);
- WBUFW(buf, 12) = uint16_t(sd->status.option);
+ WBUFW(buf, 6) = static_cast<uint16_t>(sd->speed.count());
+ WBUFW(buf, 8) = static_cast<uint16_t>(sd->opt1);
+ WBUFW(buf, 10) = static_cast<uint16_t>(sd->opt2);
+ WBUFW(buf, 12) = static_cast<uint16_t>(sd->status.option);
WBUFW(buf, 14) = sd->status.species;
WBUFW(buf, 16) = sd->status.hair;
if (sd->attack_spell_override)
@@ -791,7 +742,7 @@ int clif_set0078(struct map_session_data *sd, unsigned char *buf)
WBUFB(buf, 51) = sd->state.dead_sit;
WBUFW(buf, 52) = 0;
- return packet_len_table[0x1d8];
+ return clif_parse_func_table[0x1d8].len;
}
/*==========================================
@@ -805,10 +756,10 @@ int clif_set007b(struct map_session_data *sd, unsigned char *buf)
WBUFW(buf, 0) = 0x1da;
WBUFL(buf, 2) = sd->bl.id;
- WBUFW(buf, 6) = sd->speed;
- WBUFW(buf, 8) = uint16_t(sd->opt1);
- WBUFW(buf, 10) = uint16_t(sd->opt2);
- WBUFW(buf, 12) = uint16_t(sd->status.option);
+ WBUFW(buf, 6) = static_cast<uint16_t>(sd->speed.count());
+ WBUFW(buf, 8) = static_cast<uint16_t>(sd->opt1);
+ WBUFW(buf, 10) = static_cast<uint16_t>(sd->opt2);
+ WBUFW(buf, 12) = static_cast<uint16_t>(sd->status.option);
WBUFW(buf, 14) = sd->status.species;
WBUFW(buf, 16) = sd->status.hair;
if (sd->equip_index[EQUIP::WEAPON] >= 0
@@ -833,7 +784,7 @@ int clif_set007b(struct map_session_data *sd, unsigned char *buf)
else
WBUFW(buf, 20) = 0;
WBUFW(buf, 22) = sd->status.head_bottom;
- WBUFL(buf, 24) = gettick();
+ WBUFL(buf, 24) = gettick().time_since_epoch().count();
WBUFW(buf, 28) = sd->status.head_top;
WBUFW(buf, 30) = sd->status.head_mid;
WBUFW(buf, 32) = sd->status.hair_color;
@@ -850,7 +801,7 @@ int clif_set007b(struct map_session_data *sd, unsigned char *buf)
WBUFB(buf, 57) = 5;
WBUFW(buf, 58) = 0;
- return packet_len_table[0x1da];
+ return clif_parse_func_table[0x1da].len;
}
/*==========================================
@@ -862,16 +813,16 @@ int clif_mob0078(struct mob_data *md, unsigned char *buf)
{
int level;
- memset(buf, 0, packet_len_table[0x78]);
+ memset(buf, 0, clif_parse_func_table[0x78].len);
nullpo_ret(md);
WBUFW(buf, 0) = 0x78;
WBUFL(buf, 2) = md->bl.id;
- WBUFW(buf, 6) = battle_get_speed(&md->bl);
- WBUFW(buf, 8) = uint16_t(md->opt1);
- WBUFW(buf, 10) = uint16_t(md->opt2);
- WBUFW(buf, 12) = uint16_t(md->option);
+ WBUFW(buf, 6) = static_cast<uint16_t>(battle_get_speed(&md->bl).count());
+ WBUFW(buf, 8) = static_cast<uint16_t>(md->opt1);
+ WBUFW(buf, 10) = static_cast<uint16_t>(md->opt2);
+ WBUFW(buf, 12) = static_cast<uint16_t>(md->option);
WBUFW(buf, 14) = md->mob_class;
// snip: stuff do do with disguise as a PC
WBUFPOS(buf, 46, md->bl.x, md->bl.y);
@@ -885,7 +836,7 @@ int clif_mob0078(struct mob_data *md, unsigned char *buf)
battle_get_lv(&md->bl)) >
battle_config.max_lv) ? battle_config.max_lv : level;
- return packet_len_table[0x78];
+ return clif_parse_func_table[0x78].len;
}
/*==========================================
@@ -897,19 +848,19 @@ int clif_mob007b(struct mob_data *md, unsigned char *buf)
{
int level;
- memset(buf, 0, packet_len_table[0x7b]);
+ memset(buf, 0, clif_parse_func_table[0x7b].len);
nullpo_ret(md);
WBUFW(buf, 0) = 0x7b;
WBUFL(buf, 2) = md->bl.id;
- WBUFW(buf, 6) = battle_get_speed(&md->bl);
- WBUFW(buf, 8) = uint16_t(md->opt1);
- WBUFW(buf, 10) = uint16_t(md->opt2);
- WBUFW(buf, 12) = uint16_t(md->option);
+ WBUFW(buf, 6) = static_cast<uint16_t>(battle_get_speed(&md->bl).count());
+ WBUFW(buf, 8) = static_cast<uint16_t>(md->opt1);
+ WBUFW(buf, 10) = static_cast<uint16_t>(md->opt2);
+ WBUFW(buf, 12) = static_cast<uint16_t>(md->option);
WBUFW(buf, 14) = md->mob_class;
// snip: stuff for monsters disguised as PCs
- WBUFL(buf, 22) = gettick();
+ WBUFL(buf, 22) = gettick().time_since_epoch().count();
WBUFPOS2(buf, 50, md->bl.x, md->bl.y, md->to_x, md->to_y);
WBUFB(buf, 56) = 5;
@@ -919,7 +870,7 @@ int clif_mob007b(struct mob_data *md, unsigned char *buf)
battle_get_lv(&md->bl)) >
battle_config.max_lv) ? battle_config.max_lv : level;
- return packet_len_table[0x7b];
+ return clif_parse_func_table[0x7b].len;
}
/*==========================================
@@ -931,11 +882,11 @@ int clif_npc0078(struct npc_data *nd, unsigned char *buf)
{
nullpo_ret(nd);
- memset(buf, 0, packet_len_table[0x78]);
+ memset(buf, 0, clif_parse_func_table[0x78].len);
WBUFW(buf, 0) = 0x78;
WBUFL(buf, 2) = nd->bl.id;
- WBUFW(buf, 6) = nd->speed;
+ WBUFW(buf, 6) = static_cast<uint16_t>(nd->speed.count());
WBUFW(buf, 14) = nd->npc_class;
WBUFPOS(buf, 46, nd->bl.x, nd->bl.y);
// work around ICE in gcc 4.6
@@ -944,7 +895,7 @@ int clif_npc0078(struct npc_data *nd, unsigned char *buf)
WBUFB(buf, 49) = 5;
WBUFB(buf, 50) = 5;
- return packet_len_table[0x78];
+ return clif_parse_func_table[0x78].len;
}
/* These indices are derived from equip_pos in pc.c and some guesswork */
@@ -981,7 +932,7 @@ int clif_spawnpc(struct map_session_data *sd)
WBUFW(buf, 0) = 0x1d9;
WBUFW(buf, 51) = 0;
- clif_send(buf, packet_len_table[0x1d9], &sd->bl, AREA_WOS);
+ clif_send(buf, clif_parse_func_table[0x1d9].len, &sd->bl, SendWho::AREA_WOS);
if (map[sd->bl.m].flag.snow)
clif_specialeffect(&sd->bl, 162, 1);
@@ -1013,18 +964,18 @@ int clif_spawnnpc(struct npc_data *nd)
if (nd->npc_class < 0 || nd->flag & 1 || nd->npc_class == INVISIBLE_CLASS)
return 0;
- memset(buf, 0, packet_len_table[0x7c]);
+ memset(buf, 0, clif_parse_func_table[0x7c].len);
WBUFW(buf, 0) = 0x7c;
WBUFL(buf, 2) = nd->bl.id;
- WBUFW(buf, 6) = nd->speed;
+ WBUFW(buf, 6) = static_cast<uint16_t>(nd->speed.count());
WBUFW(buf, 20) = nd->npc_class;
WBUFPOS(buf, 36, nd->bl.x, nd->bl.y);
- clif_send(buf, packet_len_table[0x7c], &nd->bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x7c].len, &nd->bl, SendWho::AREA);
len = clif_npc0078(nd, buf);
- clif_send(buf, len, &nd->bl, AREA);
+ clif_send(buf, len, &nd->bl, SendWho::AREA);
return 0;
}
@@ -1047,7 +998,7 @@ int clif_spawn_fake_npc_for_player(struct map_session_data *sd, int fake_npc_id)
WFIFOW(fd, 12) = 0;
WFIFOW(fd, 20) = 127;
WFIFOPOS(fd, 36, sd->bl.x, sd->bl.y);
- WFIFOSET(fd, packet_len_table[0x7c]);
+ WFIFOSET(fd, clif_parse_func_table[0x7c].len);
WFIFOW(fd, 0) = 0x78;
WFIFOL(fd, 2) = fake_npc_id;
@@ -1061,7 +1012,7 @@ int clif_spawn_fake_npc_for_player(struct map_session_data *sd, int fake_npc_id)
WFIFOPOS(fd, 36, sd->bl.x, sd->bl.y);
WFIFOB(fd, 49) = 5;
WFIFOB(fd, 50) = 5;
- WFIFOSET(fd, packet_len_table[0x78]);
+ WFIFOSET(fd, clif_parse_func_table[0x78].len);
return 0;
}
@@ -1078,7 +1029,7 @@ int clif_spawnmob(struct mob_data *md)
nullpo_ret(md);
{
- memset(buf, 0, packet_len_table[0x7c]);
+ memset(buf, 0, clif_parse_func_table[0x7c].len);
WBUFW(buf, 0) = 0x7c;
WBUFL(buf, 2) = md->bl.id;
@@ -1088,11 +1039,11 @@ int clif_spawnmob(struct mob_data *md)
WBUFW(buf, 12) = uint16_t(md->option);
WBUFW(buf, 20) = md->mob_class;
WBUFPOS(buf, 36, md->bl.x, md->bl.y);
- clif_send(buf, packet_len_table[0x7c], &md->bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x7c].len, &md->bl, SendWho::AREA);
}
len = clif_mob0078(md, buf);
- clif_send(buf, len, &md->bl, AREA);
+ clif_send(buf, len, &md->bl, SendWho::AREA);
return 0;
}
@@ -1110,8 +1061,8 @@ int clif_servertick(struct map_session_data *sd)
fd = sd->fd;
WFIFOW(fd, 0) = 0x7f;
- WFIFOL(fd, 2) = sd->server_tick;
- WFIFOSET(fd, packet_len_table[0x7f]);
+ WFIFOL(fd, 2) = sd->server_tick.time_since_epoch().count();
+ WFIFOSET(fd, clif_parse_func_table[0x7f].len);
return 0;
}
@@ -1128,10 +1079,10 @@ int clif_walkok(struct map_session_data *sd)
fd = sd->fd;
WFIFOW(fd, 0) = 0x87;
- WFIFOL(fd, 2) = gettick();;
+ WFIFOL(fd, 2) = gettick().time_since_epoch().count();
WFIFOPOS2(fd, 6, sd->bl.x, sd->bl.y, sd->to_x, sd->to_y);
WFIFOB(fd, 11) = 0;
- WFIFOSET(fd, packet_len_table[0x87]);
+ WFIFOSET(fd, clif_parse_func_table[0x87].len);
return 0;
}
@@ -1149,7 +1100,7 @@ int clif_movechar(struct map_session_data *sd)
len = clif_set007b(sd, buf);
- clif_send(buf, len, &sd->bl, AREA_WOS);
+ clif_send(buf, len, &sd->bl, SendWho::AREA_WOS);
if (battle_config.save_clothcolor == 1 && sd->status.clothes_color > 0)
clif_changelook(&sd->bl, LOOK::CLOTHES_COLOR,
@@ -1173,8 +1124,10 @@ void clif_quitsave(int, struct map_session_data *sd)
*------------------------------------------
*/
static
-void clif_waitclose(timer_id, tick_t, custom_id_t id, custom_data_t)
+void clif_waitclose(TimerData *, tick_t, int id)
{
+ // TODO: what happens if the player disconnects
+ // and someone else connects?
if (session[id])
session[id]->eof = 1;
}
@@ -1185,7 +1138,9 @@ void clif_waitclose(timer_id, tick_t, custom_id_t id, custom_data_t)
*/
void clif_setwaitclose(int fd)
{
- add_timer(gettick() + 5000, clif_waitclose, fd, 0);
+ add_timer(gettick() + std::chrono::seconds(5),
+ std::bind(clif_waitclose, ph::_1, ph::_2,
+ fd));
}
/*==========================================
@@ -1204,7 +1159,7 @@ int clif_changemap(struct map_session_data *sd, const char *mapname, int x, int
memcpy(WFIFOP(fd, 2), mapname, 16);
WFIFOW(fd, 18) = x;
WFIFOW(fd, 20) = y;
- WFIFOSET(fd, packet_len_table[0x91]);
+ WFIFOSET(fd, clif_parse_func_table[0x91].len);
return 0;
}
@@ -1227,7 +1182,7 @@ int clif_changemapserver(struct map_session_data *sd, const char *mapname, int x
WFIFOW(fd, 20) = y;
WFIFOL(fd, 22) = ip.s_addr;
WFIFOW(fd, 26) = port;
- WFIFOSET(fd, packet_len_table[0x92]);
+ WFIFOSET(fd, clif_parse_func_table[0x92].len);
return 0;
}
@@ -1247,7 +1202,7 @@ int clif_fixpos(struct block_list *bl)
WBUFW(buf, 6) = bl->x;
WBUFW(buf, 8) = bl->y;
- clif_send(buf, packet_len_table[0x88], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x88].len, bl, SendWho::AREA);
return 0;
}
@@ -1265,7 +1220,7 @@ int clif_npcbuysell(struct map_session_data *sd, int id)
fd = sd->fd;
WFIFOW(fd, 0) = 0xc4;
WFIFOL(fd, 2) = id;
- WFIFOSET(fd, packet_len_table[0xc4]);
+ WFIFOSET(fd, clif_parse_func_table[0xc4].len);
return 0;
}
@@ -1366,7 +1321,7 @@ int clif_scriptnext(struct map_session_data *sd, int npcid)
fd = sd->fd;
WFIFOW(fd, 0) = 0xb5;
WFIFOL(fd, 2) = npcid;
- WFIFOSET(fd, packet_len_table[0xb5]);
+ WFIFOSET(fd, clif_parse_func_table[0xb5].len);
return 0;
}
@@ -1384,7 +1339,7 @@ int clif_scriptclose(struct map_session_data *sd, int npcid)
fd = sd->fd;
WFIFOW(fd, 0) = 0xb6;
WFIFOL(fd, 2) = npcid;
- WFIFOSET(fd, packet_len_table[0xb6]);
+ WFIFOSET(fd, clif_parse_func_table[0xb6].len);
return 0;
}
@@ -1422,7 +1377,7 @@ int clif_scriptinput(struct map_session_data *sd, int npcid)
fd = sd->fd;
WFIFOW(fd, 0) = 0x142;
WFIFOL(fd, 2) = npcid;
- WFIFOSET(fd, packet_len_table[0x142]);
+ WFIFOSET(fd, clif_parse_func_table[0x142].len);
return 0;
}
@@ -1440,7 +1395,7 @@ int clif_scriptinputstr(struct map_session_data *sd, int npcid)
fd = sd->fd;
WFIFOW(fd, 0) = 0x1d4;
WFIFOL(fd, 2) = npcid;
- WFIFOSET(fd, packet_len_table[0x1d4]);
+ WFIFOSET(fd, clif_parse_func_table[0x1d4].len);
return 0;
}
@@ -1464,7 +1419,7 @@ int clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x,
WFIFOL(fd, 14) = y;
WFIFOB(fd, 18) = id;
WFIFOL(fd, 19) = color;
- WFIFOSET(fd, packet_len_table[0x144]);
+ WFIFOSET(fd, clif_parse_func_table[0x144].len);
return 0;
}
@@ -1483,7 +1438,7 @@ int clif_cutin(struct map_session_data *sd, const char *image, int type)
WFIFOW(fd, 0) = 0x1b3;
memcpy(WFIFOP(fd, 2), image, 64);
WFIFOB(fd, 66) = type;
- WFIFOSET(fd, packet_len_table[0x1b3]);
+ WFIFOSET(fd, clif_parse_func_table[0x1b3].len);
return 0;
}
@@ -1573,7 +1528,7 @@ int clif_additem(struct map_session_data *sd, int n, int amount, PickupFail fail
WFIFOB(fd, 22) = uint8_t(fail);
}
- WFIFOSET(fd, packet_len_table[0xa0]);
+ WFIFOSET(fd, clif_parse_func_table[0xa0].len);
return 0;
}
@@ -1592,7 +1547,7 @@ int clif_delitem(struct map_session_data *sd, int n, int amount)
WFIFOW(fd, 2) = n + 2;
WFIFOW(fd, 4) = amount;
- WFIFOSET(fd, packet_len_table[0xaf]);
+ WFIFOSET(fd, clif_parse_func_table[0xaf].len);
return 0;
}
@@ -1863,7 +1818,7 @@ int clif_updatestatus(struct map_session_data *sd, SP type)
fd = sd->fd;
WFIFOW(fd, 0) = 0xb0;
- WFIFOW(fd, 2) = uint16_t(type);
+ WFIFOW(fd, 2) = static_cast<uint16_t>(type);
switch (type)
{
// 00b0
@@ -1871,14 +1826,15 @@ int clif_updatestatus(struct map_session_data *sd, SP type)
pc_checkweighticon(sd);
// is this because pc_checkweighticon can send other packets?
WFIFOW(fd, 0) = 0xb0;
- WFIFOW(fd, 2) = uint16_t(type);
+ WFIFOW(fd, 2) = static_cast<uint16_t>(type);
WFIFOL(fd, 4) = sd->weight;
break;
case SP::MAXWEIGHT:
WFIFOL(fd, 4) = sd->max_weight;
break;
case SP::SPEED:
- WFIFOL(fd, 4) = sd->speed;
+ // ...
+ WFIFOL(fd, 4) = static_cast<uint16_t>(sd->speed.count());
break;
case SP::BASELEVEL:
WFIFOL(fd, 4) = sd->status.base_level;
@@ -1914,7 +1870,7 @@ int clif_updatestatus(struct map_session_data *sd, SP type)
WFIFOL(fd, 4) = sd->status.sp;
break;
case SP::ASPD:
- WFIFOL(fd, 4) = sd->aspd;
+ WFIFOL(fd, 4) = static_cast<uint16_t>(sd->aspd.count());
break;
case SP::ATK1:
WFIFOL(fd, 4) = sd->base_atk + sd->watk;
@@ -2105,9 +2061,9 @@ int clif_changelook_towards(struct block_list *bl, LOOK type, int val,
WBUFW(buf, 9) = 0;
}
if (dstsd)
- clif_send(buf, packet_len_table[0x1d7], &dstsd->bl, SELF);
+ clif_send(buf, clif_parse_func_table[0x1d7].len, &dstsd->bl, SendWho::SELF);
else
- clif_send(buf, packet_len_table[0x1d7], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x1d7].len, bl, SendWho::AREA);
}
else
{
@@ -2117,9 +2073,9 @@ int clif_changelook_towards(struct block_list *bl, LOOK type, int val,
WBUFW(buf, 7) = val;
WBUFW(buf, 9) = 0;
if (dstsd)
- clif_send(buf, packet_len_table[0x1d7], &dstsd->bl, SELF);
+ clif_send(buf, clif_parse_func_table[0x1d7].len, &dstsd->bl, SendWho::SELF);
else
- clif_send(buf, packet_len_table[0x1d7], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x1d7].len, bl, SendWho::AREA);
}
return 0;
}
@@ -2166,7 +2122,7 @@ int clif_initialstatus(struct map_session_data *sd)
WFIFOW(fd, 40) = sd->status.karma;
WFIFOW(fd, 42) = sd->status.manner;
- WFIFOSET(fd, packet_len_table[0xbd]);
+ WFIFOSET(fd, clif_parse_func_table[0xbd].len);
clif_updatestatus(sd, SP::STR);
clif_updatestatus(sd, SP::AGI);
@@ -2198,7 +2154,7 @@ int clif_arrowequip(struct map_session_data *sd, int val)
WFIFOW(fd, 0) = 0x013c;
WFIFOW(fd, 2) = val + 2; //矢のアイテムID
- WFIFOSET(fd, packet_len_table[0x013c]);
+ WFIFOSET(fd, clif_parse_func_table[0x013c].len);
return 0;
}
@@ -2217,7 +2173,7 @@ int clif_arrow_fail(struct map_session_data *sd, int type)
WFIFOW(fd, 0) = 0x013b;
WFIFOW(fd, 2) = type;
- WFIFOSET(fd, packet_len_table[0x013b]);
+ WFIFOSET(fd, clif_parse_func_table[0x013b].len);
return 0;
}
@@ -2237,7 +2193,7 @@ int clif_statusupack(struct map_session_data *sd, SP type, int ok, int val)
WFIFOW(fd, 2) = uint16_t(type);
WFIFOB(fd, 4) = ok;
WFIFOB(fd, 5) = val;
- WFIFOSET(fd, packet_len_table[0xbc]);
+ WFIFOSET(fd, clif_parse_func_table[0xbc].len);
return 0;
}
@@ -2257,7 +2213,7 @@ int clif_equipitemack(struct map_session_data *sd, int n, EPOS pos, int ok)
WFIFOW(fd, 2) = n + 2;
WFIFOW(fd, 4) = uint16_t(pos);
WFIFOB(fd, 6) = ok;
- WFIFOSET(fd, packet_len_table[0xaa]);
+ WFIFOSET(fd, clif_parse_func_table[0xaa].len);
return 0;
}
@@ -2277,7 +2233,7 @@ int clif_unequipitemack(struct map_session_data *sd, int n, EPOS pos, int ok)
WFIFOW(fd, 2) = n + 2;
WFIFOW(fd, 4) = uint16_t(pos);
WFIFOB(fd, 6) = ok;
- WFIFOSET(fd, packet_len_table[0xac]);
+ WFIFOSET(fd, clif_parse_func_table[0xac].len);
return 0;
}
@@ -2296,7 +2252,7 @@ int clif_misceffect(struct block_list *bl, int type)
WBUFL(buf, 2) = bl->id;
WBUFL(buf, 6) = type;
- clif_send(buf, packet_len_table[0x19b], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x19b].len, bl, SendWho::AREA);
return 0;
}
@@ -2322,7 +2278,7 @@ int clif_changeoption(struct block_list *bl)
WBUFW(buf, 10) = uint16_t(option);
WBUFB(buf, 12) = 0; // ??
- clif_send(buf, packet_len_table[0x119], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x119].len, bl, SendWho::AREA);
return 0;
}
@@ -2343,7 +2299,7 @@ int clif_useitemack(struct map_session_data *sd, int index, int amount,
WFIFOW(fd, 2) = index + 2;
WFIFOW(fd, 4) = amount;
WFIFOB(fd, 6) = ok;
- WFIFOSET(fd, packet_len_table[0xa8]);
+ WFIFOSET(fd, clif_parse_func_table[0xa8].len);
}
else
{
@@ -2359,7 +2315,7 @@ int clif_useitemack(struct map_session_data *sd, int index, int amount,
WBUFL(buf, 6) = sd->bl.id;
WBUFW(buf, 10) = amount;
WBUFB(buf, 12) = ok;
- clif_send(buf, packet_len_table[0x1c8], &sd->bl, SELF);
+ clif_send(buf, clif_parse_func_table[0x1c8].len, &sd->bl, SendWho::SELF);
}
return 0;
@@ -2378,7 +2334,7 @@ int clif_traderequest(struct map_session_data *sd, const char *name)
fd = sd->fd;
WFIFOW(fd, 0) = 0xe5;
strcpy((char *)WFIFOP(fd, 2), name);
- WFIFOSET(fd, packet_len_table[0xe5]);
+ WFIFOSET(fd, clif_parse_func_table[0xe5].len);
return 0;
}
@@ -2396,7 +2352,7 @@ int clif_tradestart(struct map_session_data *sd, int type)
fd = sd->fd;
WFIFOW(fd, 0) = 0xe7;
WFIFOB(fd, 2) = type;
- WFIFOSET(fd, packet_len_table[0xe7]);
+ WFIFOSET(fd, clif_parse_func_table[0xe7].len);
return 0;
}
@@ -2478,7 +2434,7 @@ int clif_tradeadditem(struct map_session_data *sd,
WFIFOW(fd, 17) = sd->status.inventory[index].card[3];
}
}
- WFIFOSET(fd, packet_len_table[0xe9]);
+ WFIFOSET(fd, clif_parse_func_table[0xe9].len);
return 0;
}
@@ -2499,7 +2455,7 @@ int clif_tradeitemok(struct map_session_data *sd, int index, int amount,
WFIFOW(fd, 2) = index;
WFIFOW(fd, 4) = amount;
WFIFOB(fd, 6) = fail;
- WFIFOSET(fd, packet_len_table[0x1b1]);
+ WFIFOSET(fd, clif_parse_func_table[0x1b1].len);
return 0;
}
@@ -2517,7 +2473,7 @@ int clif_tradedeal_lock(struct map_session_data *sd, int fail)
fd = sd->fd;
WFIFOW(fd, 0) = 0xec;
WFIFOB(fd, 2) = fail; // 0=you 1=the other person
- WFIFOSET(fd, packet_len_table[0xec]);
+ WFIFOSET(fd, clif_parse_func_table[0xec].len);
return 0;
}
@@ -2534,7 +2490,7 @@ int clif_tradecancelled(struct map_session_data *sd)
fd = sd->fd;
WFIFOW(fd, 0) = 0xee;
- WFIFOSET(fd, packet_len_table[0xee]);
+ WFIFOSET(fd, clif_parse_func_table[0xee].len);
return 0;
}
@@ -2552,7 +2508,7 @@ int clif_tradecompleted(struct map_session_data *sd, int fail)
fd = sd->fd;
WFIFOW(fd, 0) = 0xf0;
WFIFOB(fd, 2) = fail;
- WFIFOSET(fd, packet_len_table[0xf0]);
+ WFIFOSET(fd, clif_parse_func_table[0xf0].len);
return 0;
}
@@ -2573,7 +2529,7 @@ int clif_updatestorageamount(struct map_session_data *sd,
WFIFOW(fd, 0) = 0xf2; // update storage amount
WFIFOW(fd, 2) = stor->storage_amount; //items
WFIFOW(fd, 4) = MAX_STORAGE; //items max
- WFIFOSET(fd, packet_len_table[0xf2]);
+ WFIFOSET(fd, clif_parse_func_table[0xf2].len);
return 0;
}
@@ -2636,7 +2592,7 @@ int clif_storageitemadded(struct map_session_data *sd, struct storage *stor,
else
WFIFOW(fd, 19) = stor->storage_[index].card[3];
}
- WFIFOSET(fd, packet_len_table[0xf4]);
+ WFIFOSET(fd, clif_parse_func_table[0xf4].len);
return 0;
}
@@ -2656,7 +2612,7 @@ int clif_storageitemremoved(struct map_session_data *sd, int index,
WFIFOW(fd, 0) = 0xf6; // Storage item removed
WFIFOW(fd, 2) = index + 1;
WFIFOL(fd, 4) = amount;
- WFIFOSET(fd, packet_len_table[0xf6]);
+ WFIFOSET(fd, clif_parse_func_table[0xf6].len);
return 0;
}
@@ -2673,7 +2629,7 @@ int clif_storageclose(struct map_session_data *sd)
fd = sd->fd;
WFIFOW(fd, 0) = 0xf8; // Storage Closed
- WFIFOSET(fd, packet_len_table[0xf8]);
+ WFIFOSET(fd, clif_parse_func_table[0xf8].len);
return 0;
}
@@ -2704,7 +2660,7 @@ void clif_getareachar_pc(struct map_session_data *sd,
nullpo_retv(sd);
nullpo_retv(dstsd);
- if (dstsd->walktimer != -1)
+ if (dstsd->walktimer)
{
len = clif_set007b(dstsd, static_cast<uint8_t *>(WFIFOP(sd->fd, 0)));
WFIFOSET(sd->fd, len);
@@ -2754,7 +2710,7 @@ int clif_movemob(struct mob_data *md)
nullpo_ret(md);
len = clif_mob007b(md, buf);
- clif_send(buf, len, &md->bl, AREA);
+ clif_send(buf, len, &md->bl, SendWho::AREA);
return 0;
}
@@ -2773,12 +2729,12 @@ int clif_fixmobpos(struct mob_data *md)
if (md->state.state == MS::WALK)
{
len = clif_mob007b(md, buf);
- clif_send(buf, len, &md->bl, AREA);
+ clif_send(buf, len, &md->bl, SendWho::AREA);
}
else
{
len = clif_mob0078(md, buf);
- clif_send(buf, len, &md->bl, AREA);
+ clif_send(buf, len, &md->bl, SendWho::AREA);
}
return 0;
@@ -2795,15 +2751,15 @@ int clif_fixpcpos(struct map_session_data *sd)
nullpo_ret(sd);
- if (sd->walktimer != -1)
+ if (sd->walktimer)
{
len = clif_set007b(sd, buf);
- clif_send(buf, len, &sd->bl, AREA);
+ clif_send(buf, len, &sd->bl, SendWho::AREA);
}
else
{
len = clif_set0078(sd, buf);
- clif_send(buf, len, &sd->bl, AREA);
+ clif_send(buf, len, &sd->bl, SendWho::AREA);
}
clif_changelook_accessories(&sd->bl, NULL);
@@ -2815,8 +2771,8 @@ int clif_fixpcpos(struct map_session_data *sd)
*------------------------------------------
*/
int clif_damage(struct block_list *src, struct block_list *dst,
- unsigned int tick, int sdelay, int ddelay, int damage,
- int div, DamageType type, int damage2)
+ tick_t tick, interval_t sdelay, interval_t ddelay, int damage,
+ int div, DamageType type, int damage2)
{
unsigned char buf[256];
eptr<struct status_change, StatusChange> sc_data;
@@ -2829,14 +2785,14 @@ int clif_damage(struct block_list *src, struct block_list *dst,
WBUFW(buf, 0) = 0x8a;
WBUFL(buf, 2) = src->id;
WBUFL(buf, 6) = dst->id;
- WBUFL(buf, 10) = tick;
- WBUFL(buf, 14) = sdelay;
- WBUFL(buf, 18) = ddelay;
+ WBUFL(buf, 10) = tick.time_since_epoch().count();
+ WBUFL(buf, 14) = sdelay.count();
+ WBUFL(buf, 18) = ddelay.count();
WBUFW(buf, 22) = (damage > 0x7fff) ? 0x7fff : damage;
WBUFW(buf, 24) = div;
WBUFB(buf, 26) = static_cast<uint8_t>(type);
WBUFW(buf, 27) = damage2;
- clif_send(buf, packet_len_table[0x8a], src, AREA);
+ clif_send(buf, clif_parse_func_table[0x8a].len, src, SendWho::AREA);
return 0;
}
@@ -2892,7 +2848,7 @@ void clif_getareachar_item(struct map_session_data *sd,
WFIFOB(fd, 15) = fitem->subx;
WFIFOB(fd, 16) = fitem->suby;
- WFIFOSET(fd, packet_len_table[0x9d]);
+ WFIFOSET(fd, clif_parse_func_table[0x9d].len);
}
/*==========================================
@@ -3065,7 +3021,7 @@ int clif_skillinfo(struct map_session_data *sd, SkillID skillid, int type,
memset(WFIFOP(fd, 14), 0, 24);
WFIFOB(fd, 38) =
(sd->status.skill[skillid].lv < skill_get_max_raise(id)) ? 1 : 0;
- WFIFOSET(fd, packet_len_table[0x147]);
+ WFIFOSET(fd, clif_parse_func_table[0x147].len);
return 0;
}
@@ -3134,7 +3090,7 @@ int clif_skillup(struct map_session_data *sd, SkillID skill_num)
WFIFOB(fd, 10) =
(sd->status.skill[skill_num].lv <
skill_get_max_raise(sd->status.skill[skill_num].id)) ? 1 : 0;
- WFIFOSET(fd, packet_len_table[0x10e]);
+ WFIFOSET(fd, clif_parse_func_table[0x10e].len);
return 0;
}
@@ -3151,7 +3107,7 @@ int clif_skillcastcancel(struct block_list *bl)
WBUFW(buf, 0) = 0x1b9;
WBUFL(buf, 2) = bl->id;
- clif_send(buf, packet_len_table[0x1b9], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x1b9].len, bl, SendWho::AREA);
return 0;
}
@@ -3180,7 +3136,7 @@ int clif_skill_fail(struct map_session_data *sd, SkillID skill_id, int type,
WFIFOW(fd, 6) = 0;
WFIFOB(fd, 8) = 0;
WFIFOB(fd, 9) = type;
- WFIFOSET(fd, packet_len_table[0x110]);
+ WFIFOSET(fd, clif_parse_func_table[0x110].len);
return 0;
}
@@ -3190,8 +3146,8 @@ int clif_skill_fail(struct map_session_data *sd, SkillID skill_id, int type,
*------------------------------------------
*/
int clif_skill_damage(struct block_list *src, struct block_list *dst,
- unsigned int tick, int sdelay, int ddelay, int damage,
- int div, SkillID skill_id, int skill_lv, int type)
+ tick_t tick, interval_t sdelay, interval_t ddelay, int damage,
+ int div, SkillID skill_id, int skill_lv, int type)
{
unsigned char buf[64];
eptr<struct status_change, StatusChange> sc_data;
@@ -3205,14 +3161,14 @@ int clif_skill_damage(struct block_list *src, struct block_list *dst,
WBUFW(buf, 2) = uint16_t(skill_id);
WBUFL(buf, 4) = src->id;
WBUFL(buf, 8) = dst->id;
- WBUFL(buf, 12) = tick;
- WBUFL(buf, 16) = sdelay;
- WBUFL(buf, 20) = ddelay;
+ WBUFL(buf, 12) = static_cast<uint32_t>(tick.time_since_epoch().count());
+ WBUFL(buf, 16) = static_cast<uint32_t>(sdelay.count());
+ WBUFL(buf, 20) = static_cast<uint32_t>(ddelay.count());
WBUFL(buf, 24) = damage;
WBUFW(buf, 28) = skill_lv;
WBUFW(buf, 30) = div;
WBUFB(buf, 32) = (type > 0) ? type : skill_get_hit(skill_id);
- clif_send(buf, packet_len_table[0x1de], src, AREA);
+ clif_send(buf, clif_parse_func_table[0x1de].len, src, SendWho::AREA);
return 0;
}
@@ -3231,7 +3187,7 @@ int clif_status_change(struct block_list *bl, StatusChange type, int flag)
WBUFW(buf, 2) = uint16_t(type);
WBUFL(buf, 4) = bl->id;
WBUFB(buf, 8) = flag;
- clif_send(buf, packet_len_table[0x196], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x196].len, bl, SendWho::AREA);
return 0;
}
@@ -3268,10 +3224,10 @@ void clif_GMmessage(struct block_list *bl, const_string mes, int flag)
WBUFB(buf, lp + mes.size()) = '\0';
flag &= 0x07;
clif_send(buf, WBUFW(buf, 2), bl,
- (flag == 1) ? ALL_SAMEMAP :
- (flag == 2) ? AREA :
- (flag == 3) ? SELF :
- ALL_CLIENT);
+ (flag == 1) ? SendWho::ALL_SAMEMAP :
+ (flag == 2) ? SendWho::AREA :
+ (flag == 3) ? SendWho::SELF :
+ SendWho::ALL_CLIENT);
}
/*==========================================
@@ -3288,7 +3244,7 @@ int clif_resurrection(struct block_list *bl, int type)
WBUFL(buf, 2) = bl->id;
WBUFW(buf, 6) = type;
- clif_send(buf, packet_len_table[0x148], bl, type == 1 ? AREA : AREA_WOS);
+ clif_send(buf, clif_parse_func_table[0x148].len, bl, type == 1 ? SendWho::AREA : SendWho::AREA_WOS);
return 0;
}
@@ -3315,7 +3271,7 @@ int clif_wis_end(int fd, int flag) // R 0098 <type>.B: 0: success to send wisper
{
WFIFOW(fd, 0) = 0x98;
WFIFOW(fd, 2) = flag;
- WFIFOSET(fd, packet_len_table[0x98]);
+ WFIFOSET(fd, clif_parse_func_table[0x98].len);
return 0;
}
@@ -3340,7 +3296,7 @@ int clif_party_created(struct map_session_data *sd, int flag)
fd = sd->fd;
WFIFOW(fd, 0) = 0xfa;
WFIFOB(fd, 2) = flag;
- WFIFOSET(fd, packet_len_table[0xfa]);
+ WFIFOSET(fd, clif_parse_func_table[0xfa].len);
return 0;
}
@@ -3381,7 +3337,7 @@ int clif_party_info(struct party *p, int fd)
return 9;
}
if (sd != NULL)
- clif_send(buf, WBUFW(buf, 2), &sd->bl, PARTY);
+ clif_send(buf, WBUFW(buf, 2), &sd->bl, SendWho::PARTY);
return 0;
}
@@ -3409,7 +3365,7 @@ int clif_party_invite(struct map_session_data *sd,
WFIFOW(fd, 0) = 0xfe;
WFIFOL(fd, 2) = sd->status.account_id;
memcpy(WFIFOP(fd, 6), p->name, 24);
- WFIFOSET(fd, packet_len_table[0xfe]);
+ WFIFOSET(fd, clif_parse_func_table[0xfe].len);
return 0;
}
@@ -3437,7 +3393,7 @@ int clif_party_inviteack(struct map_session_data *sd, const char *nick, int flag
WFIFOW(fd, 0) = 0xfd;
memcpy(WFIFOP(fd, 2), nick, 24);
WFIFOB(fd, 26) = flag;
- WFIFOSET(fd, packet_len_table[0xfd]);
+ WFIFOSET(fd, clif_parse_func_table[0xfd].len);
return 0;
}
@@ -3469,11 +3425,11 @@ int clif_party_option(struct party *p, struct map_session_data *sd, int flag)
WBUFW(buf, 2) = ((flag & 0x01) ? 2 : p->exp);
WBUFW(buf, 4) = ((flag & 0x10) ? 2 : p->item);
if (flag == 0)
- clif_send(buf, packet_len_table[0x101], &sd->bl, PARTY);
+ clif_send(buf, clif_parse_func_table[0x101].len, &sd->bl, SendWho::PARTY);
else
{
- memcpy(WFIFOP(sd->fd, 0), buf, packet_len_table[0x101]);
- WFIFOSET(sd->fd, packet_len_table[0x101]);
+ memcpy(WFIFOP(sd->fd, 0), buf, clif_parse_func_table[0x101].len);
+ WFIFOSET(sd->fd, clif_parse_func_table[0x101].len);
}
return 0;
}
@@ -3502,12 +3458,12 @@ int clif_party_leaved(struct party *p, struct map_session_data *sd,
if ((sd = p->member[i].sd) != NULL)
break;
if (sd != NULL)
- clif_send(buf, packet_len_table[0x105], &sd->bl, PARTY);
+ clif_send(buf, clif_parse_func_table[0x105].len, &sd->bl, SendWho::PARTY);
}
else if (sd != NULL)
{
- memcpy(WFIFOP(sd->fd, 0), buf, packet_len_table[0x105]);
- WFIFOSET(sd->fd, packet_len_table[0x105]);
+ memcpy(WFIFOP(sd->fd, 0), buf, clif_parse_func_table[0x105].len);
+ WFIFOSET(sd->fd, clif_parse_func_table[0x105].len);
}
return 0;
}
@@ -3536,7 +3492,7 @@ int clif_party_message(struct party *p, int account_id, const char *mes, int len
WBUFW(buf, 2) = len + 8;
WBUFL(buf, 4) = account_id;
memcpy(WBUFP(buf, 8), mes, len);
- clif_send(buf, len + 8, &sd->bl, PARTY);
+ clif_send(buf, len + 8, &sd->bl, SendWho::PARTY);
}
return 0;
}
@@ -3555,7 +3511,7 @@ int clif_party_xy(struct party *, struct map_session_data *sd)
WBUFL(buf, 2) = sd->status.account_id;
WBUFW(buf, 6) = sd->bl.x;
WBUFW(buf, 8) = sd->bl.y;
- clif_send(buf, packet_len_table[0x107], &sd->bl, PARTY_SAMEMAP_WOS);
+ clif_send(buf, clif_parse_func_table[0x107].len, &sd->bl, SendWho::PARTY_SAMEMAP_WOS);
// if(battle_config.etc_log)
// PRINTF("clif_party_xy %d\n",sd->status.account_id);
return 0;
@@ -3576,7 +3532,7 @@ int clif_party_hp(struct party *, struct map_session_data *sd)
WBUFW(buf, 6) = (sd->status.hp > 0x7fff) ? 0x7fff : sd->status.hp;
WBUFW(buf, 8) =
(sd->status.max_hp > 0x7fff) ? 0x7fff : sd->status.max_hp;
- clif_send(buf, packet_len_table[0x106], &sd->bl, PARTY_AREA_WOS);
+ clif_send(buf, clif_parse_func_table[0x106].len, &sd->bl, SendWho::PARTY_AREA_WOS);
// if(battle_config.etc_log)
// PRINTF("clif_party_hp %d\n",sd->status.account_id);
return 0;
@@ -3601,7 +3557,7 @@ int clif_movetoattack(struct map_session_data *sd, struct block_list *bl)
WFIFOW(fd, 10) = sd->bl.x;
WFIFOW(fd, 12) = sd->bl.y;
WFIFOW(fd, 14) = sd->attackrange;
- WFIFOSET(fd, packet_len_table[0x139]);
+ WFIFOSET(fd, clif_parse_func_table[0x139].len);
return 0;
}
@@ -3617,7 +3573,7 @@ int clif_mvp_effect(struct map_session_data *sd)
WBUFW(buf, 0) = 0x10c;
WBUFL(buf, 2) = sd->bl.id;
- clif_send(buf, packet_len_table[0x10c], &sd->bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x10c].len, &sd->bl, SendWho::AREA);
return 0;
}
@@ -3634,7 +3590,7 @@ void clif_emotion(struct block_list *bl, int type)
WBUFW(buf, 0) = 0xc0;
WBUFL(buf, 2) = bl->id;
WBUFB(buf, 6) = type;
- clif_send(buf, packet_len_table[0xc0], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0xc0].len, bl, SendWho::AREA);
}
static
@@ -3642,7 +3598,7 @@ void clif_emotion_towards(struct block_list *bl,
struct block_list *target, int type)
{
unsigned char buf[8];
- int len = packet_len_table[0xc0];
+ int len = clif_parse_func_table[0xc0].len;
struct map_session_data *sd = (struct map_session_data *) target;
nullpo_retv(bl);
@@ -3672,7 +3628,7 @@ void clif_sitting(int, struct map_session_data *sd)
WBUFW(buf, 0) = 0x8a;
WBUFL(buf, 2) = sd->bl.id;
WBUFB(buf, 26) = 2;
- clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x8a].len, &sd->bl, SendWho::AREA);
}
/*==========================================
@@ -3689,7 +3645,7 @@ int clif_GM_kickack(struct map_session_data *sd, int id)
fd = sd->fd;
WFIFOW(fd, 0) = 0xcd;
WFIFOL(fd, 2) = id;
- WFIFOSET(fd, packet_len_table[0xcd]);
+ WFIFOSET(fd, clif_parse_func_table[0xcd].len);
return 0;
}
@@ -3717,7 +3673,7 @@ int clif_specialeffect(struct block_list *bl, int type, int flag)
nullpo_ret(bl);
- memset(buf, 0, packet_len_table[0x19b]);
+ memset(buf, 0, clif_parse_func_table[0x19b].len);
WBUFW(buf, 0) = 0x19b;
WBUFL(buf, 2) = bl->id;
@@ -3736,9 +3692,9 @@ int clif_specialeffect(struct block_list *bl, int type, int flag)
}
else if (flag == 1)
- clif_send(buf, packet_len_table[0x19b], bl, SELF);
+ clif_send(buf, clif_parse_func_table[0x19b].len, bl, SendWho::SELF);
else if (!flag)
- clif_send(buf, packet_len_table[0x19b], bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x19b].len, bl, SendWho::AREA);
return 0;
@@ -3790,7 +3746,8 @@ void clif_parse_WantToConnection(int fd, struct map_session_data *sd)
sd->fd = fd;
pc_setnewpc(sd, account_id, RFIFOL(fd, 6), RFIFOL(fd, 10),
- RFIFOL(fd, 14), RFIFOB(fd, 18), fd);
+ tick_t(static_cast<interval_t>(RFIFOL(fd, 14))),
+ RFIFOB(fd, 18));
map_addiddb(&sd->bl);
@@ -3841,7 +3798,7 @@ void clif_parse_LoadEndAck(int, struct map_session_data *sd)
if (battle_config.pc_invincible_time > 0)
{
- pc_setinvincibletimer(sd, battle_config.pc_invincible_time);
+ pc_setinvincibletimer(sd, static_cast<interval_t>(battle_config.pc_invincible_time));
}
map_addblock(&sd->bl); // ブロック登録
@@ -3852,15 +3809,16 @@ void clif_parse_LoadEndAck(int, struct map_session_data *sd)
clif_updatestatus(sd, SP::WEIGHT);
// pvp
- if (sd->pvp_timer != -1 && !battle_config.pk_mode)
- delete_timer(sd->pvp_timer, pc_calc_pvprank_timer);
+ if (sd->pvp_timer && !battle_config.pk_mode)
+ delete_timer(sd->pvp_timer);
if (map[sd->bl.m].flag.pvp)
{
if (!battle_config.pk_mode)
- { // remove pvp stuff for pk_mode [Valaris]
- sd->pvp_timer =
- add_timer(gettick() + 200, pc_calc_pvprank_timer, sd->bl.id,
- 0);
+ {
+ // remove pvp stuff for pk_mode [Valaris]
+ sd->pvp_timer = add_timer(gettick() + std::chrono::milliseconds(200),
+ std::bind(pc_calc_pvprank_timer, ph::_1, ph::_2,
+ sd->bl.id));
sd->pvp_rank = 0;
sd->pvp_lastusers = 0;
sd->pvp_point = 5;
@@ -3868,7 +3826,7 @@ void clif_parse_LoadEndAck(int, struct map_session_data *sd)
}
else
{
- sd->pvp_timer = -1;
+ sd->pvp_timer = nullptr;
}
sd->state.connect_new = 0;
@@ -3879,9 +3837,6 @@ void clif_parse_LoadEndAck(int, struct map_session_data *sd)
clif_changelook(&sd->bl, LOOK::CLOTHES_COLOR,
sd->status.clothes_color);
- if (battle_config.muting_players && sd->status.manner < 0)
- skill_status_change_start(&sd->bl, StatusChange::SC_NOCHAT, 0, 0, 0, 0, 0, 0);
-
// option
clif_changeoption(&sd->bl);
for (i = 0; i < MAX_INVENTORY; i++)
@@ -3889,13 +3844,11 @@ void clif_parse_LoadEndAck(int, struct map_session_data *sd)
if (bool(sd->status.inventory[i].equip)
&& bool(sd->status.inventory[i].equip & EPOS::WEAPON)
&& sd->status.inventory[i].broken == 1)
- skill_status_change_start(&sd->bl, StatusChange::SC_BROKNWEAPON, 0, 0, 0, 0, 0,
- 0);
+ skill_status_change_start(&sd->bl, StatusChange::SC_BROKNWEAPON, 0, interval_t::zero());
if (bool(sd->status.inventory[i].equip)
&& bool(sd->status.inventory[i].equip & EPOS::MISC1)
&& sd->status.inventory[i].broken == 1)
- skill_status_change_start(&sd->bl, StatusChange::SC_BROKNARMOR, 0, 0, 0, 0, 0,
- 0);
+ skill_status_change_start(&sd->bl, StatusChange::SC_BROKNARMOR, 0, interval_t::zero());
}
// clif_changelook_accessories(sd, NULL);
@@ -3914,7 +3867,7 @@ void clif_parse_TickSend(int fd, struct map_session_data *sd)
{
nullpo_retv(sd);
- sd->client_tick = RFIFOL(fd, 2);
+ sd->client_tick = tick_t(static_cast<interval_t>(RFIFOL(fd, 2)));
sd->server_tick = gettick();
clif_servertick(sd);
}
@@ -3949,7 +3902,7 @@ void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
if (bool(sd->opt1) && sd->opt1 != (Opt1::_stone6))
return;
- if (sd->invincible_timer != -1)
+ if (sd->invincible_timer)
pc_delinvincibletimer(sd);
pc_stopattack(sd);
@@ -3966,27 +3919,22 @@ void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
*/
void clif_parse_QuitGame(int fd, struct map_session_data *sd)
{
- unsigned int tick = gettick();
+ tick_t tick = gettick();
nullpo_retv(sd);
WFIFOW(fd, 0) = 0x18b;
- if ((!pc_isdead(sd)
- && (sd->opt1 != Opt1::ZERO
- || (sd->opt2 != Opt2::ZERO
- && !(night_flag == 1 && sd->opt2 == Opt2::BLIND))))
- || (DIFF_TICK(tick, sd->canact_tick) < 0)
- )
+ if ((!pc_isdead(sd) && (sd->opt1 != Opt1::ZERO || sd->opt2 != Opt2::ZERO))
+ || (tick < sd->canact_tick))
{
WFIFOW(fd, 2) = 1;
- WFIFOSET(fd, packet_len_table[0x18b]);
+ WFIFOSET(fd, clif_parse_func_table[0x18b].len);
return;
}
/* Rovert's prevent logout option fixed [Valaris] */
- if ((battle_config.prevent_logout
- && (gettick() - sd->canlog_tick) >= 10000)
- || (!battle_config.prevent_logout))
+ if (!battle_config.prevent_logout
+ || tick >= sd->canlog_tick + std::chrono::seconds(10))
{
clif_setwaitclose(fd);
WFIFOW(fd, 2) = 0;
@@ -3995,7 +3943,7 @@ void clif_parse_QuitGame(int fd, struct map_session_data *sd)
{
WFIFOW(fd, 2) = 1;
}
- WFIFOSET(fd, packet_len_table[0x18b]);
+ WFIFOSET(fd, clif_parse_func_table[0x18b].len);
}
@@ -4029,7 +3977,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
memset(WFIFOP(fd, 6), 0, 24);
else
memcpy(WFIFOP(fd, 6), ssd->status.name, 24);
- WFIFOSET(fd, packet_len_table[0x95]);
+ WFIFOSET(fd, clif_parse_func_table[0x95].len);
struct party *p = NULL;
@@ -4051,7 +3999,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
memcpy(WFIFOP(fd, 30), "", 24);
memcpy(WFIFOP(fd, 54), "", 24);
memcpy(WFIFOP(fd, 78), "", 24); // We send this value twice because the client expects it
- WFIFOSET(fd, packet_len_table[0x195]);
+ WFIFOSET(fd, clif_parse_func_table[0x195].len);
}
@@ -4066,7 +4014,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
WFIFOL(fd, 2) = account_id;
WFIFOL(fd, 6) = ip.s_addr;
- WFIFOSET(fd, packet_len_table[0x20C]);
+ WFIFOSET(fd, clif_parse_func_table[0x20C].len);
}
}
@@ -4084,7 +4032,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
while (*start == '_')
*start++ = ' ';
}
- WFIFOSET(fd, packet_len_table[0x95]);
+ WFIFOSET(fd, clif_parse_func_table[0x95].len);
break;
case BL::MOB:
{
@@ -4093,7 +4041,7 @@ void clif_parse_GetCharNameRequest(int fd, struct map_session_data *sd)
nullpo_retv(md);
memcpy(WFIFOP(fd, 6), md->name, 24);
- WFIFOSET(fd, packet_len_table[0x95]);
+ WFIFOSET(fd, clif_parse_func_table[0x95].len);
}
break;
default:
@@ -4128,8 +4076,7 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd)
return;
}
- if (is_atcommand(fd, sd, message, 0)
- || (sd->sc_data[StatusChange::SC_NOCHAT].timer != -1)) //チャット禁止
+ if (is_atcommand(fd, sd, message, 0)) //チャット禁止
{
free(buf);
return;
@@ -4152,7 +4099,7 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data *sd)
// evil multiuse buffer!
clif_send((const uint8_t *)buf, msg_len + 8, &sd->bl,
- sd->chatID ? CHAT_WOS : AREA_CHAT_WOC);
+ sd->chatID ? SendWho::CHAT_WOS : SendWho::AREA_CHAT_WOC);
}
/* Send the message back to the speaker. */
@@ -4179,7 +4126,7 @@ int clif_message(struct block_list *bl, const char *msg)
WBUFL(buf, 4) = bl->id;
memcpy(WBUFP(buf, 8), msg, msg_len);
- clif_send(buf, WBUFW(buf, 2), bl, AREA);
+ clif_send(buf, WBUFW(buf, 2), bl, SendWho::AREA);
return 0;
}
@@ -4210,7 +4157,7 @@ void clif_parse_ChangeDir(int fd, struct map_session_data *sd)
WBUFW(buf, 6) = 0;
WBUFB(buf, 8) = static_cast<uint8_t>(dir);
- clif_send(buf, packet_len_table[0x9c], &sd->bl, AREA_WOS);
+ clif_send(buf, clif_parse_func_table[0x9c].len, &sd->bl, SendWho::AREA_WOS);
}
@@ -4231,7 +4178,7 @@ void clif_parse_Emotion(int fd, struct map_session_data *sd)
WBUFW(buf, 0) = 0xc0;
WBUFL(buf, 2) = sd->bl.id;
WBUFB(buf, 6) = RFIFOB(fd, 2);
- clif_send(buf, packet_len_table[0xc0], &sd->bl, AREA);
+ clif_send(buf, clif_parse_func_table[0xc0].len, &sd->bl, SendWho::AREA);
}
else
clif_skill_fail(sd, SkillID::ONE, 0, 1);
@@ -4246,7 +4193,7 @@ void clif_parse_HowManyConnections(int fd, struct map_session_data *)
{
WFIFOW(fd, 0) = 0xc2;
WFIFOL(fd, 2) = map_getusers();
- WFIFOSET(fd, packet_len_table[0xc2]);
+ WFIFOSET(fd, clif_parse_func_table[0xc2].len);
}
/*==========================================
@@ -4256,7 +4203,6 @@ void clif_parse_HowManyConnections(int fd, struct map_session_data *)
static
void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
{
- unsigned int tick;
unsigned char buf[64];
int action_type, target_id;
@@ -4272,7 +4218,7 @@ void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
|| sd->state.storage_open)
return;
- tick = gettick();
+ tick_t tick = gettick();
pc_stop_walking(sd, 0);
pc_stopattack(sd);
@@ -4288,13 +4234,13 @@ void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
return;
if (!battle_config.sdelay_attack_enable)
{
- if (DIFF_TICK(tick, sd->canact_tick) < 0)
+ if (tick < sd->canact_tick)
{
clif_skill_fail(sd, SkillID::ONE, 4, 0);
return;
}
}
- if (sd->invincible_timer != -1)
+ if (sd->invincible_timer)
pc_delinvincibletimer(sd);
if (sd->attacktarget > 0) // [Valaris]
sd->attacktarget = 0;
@@ -4312,7 +4258,7 @@ void clif_parse_ActionRequest(int fd, struct map_session_data *sd)
WBUFW(buf, 0) = 0x8a;
WBUFL(buf, 2) = sd->bl.id;
WBUFB(buf, 26) = 3;
- clif_send(buf, packet_len_table[0x8a], &sd->bl, AREA);
+ clif_send(buf, clif_parse_func_table[0x8a].len, &sd->bl, SendWho::AREA);
break;
}
}
@@ -4340,9 +4286,8 @@ void clif_parse_Restart(int fd, struct map_session_data *sd)
break;
case 0x01:
/* Rovert's Prevent logout option - Fixed [Valaris] */
- if ((battle_config.prevent_logout
- && (gettick() - sd->canlog_tick) >= 10000)
- || (!battle_config.prevent_logout))
+ if (!battle_config.prevent_logout
+ || gettick() >= sd->canlog_tick + std::chrono::seconds(10))
{
chrif_charselectreq(sd);
}
@@ -4351,7 +4296,7 @@ void clif_parse_Restart(int fd, struct map_session_data *sd)
WFIFOW(fd, 0) = 0x18b;
WFIFOW(fd, 2) = 1;
- WFIFOSET(fd, packet_len_table[0x018b]);
+ WFIFOSET(fd, clif_parse_func_table[0x018b].len);
}
break;
}
@@ -4383,8 +4328,7 @@ void clif_parse_Wis(int fd, struct map_session_data *sd)
return;
}
- if (is_atcommand(fd, sd, message, 0)
- || (sd->sc_data[StatusChange::SC_NOCHAT].timer != -1))
+ if (is_atcommand(fd, sd, message, 0))
{
free(buf);
return;
@@ -4472,8 +4416,7 @@ void clif_parse_TakeItem(int fd, struct map_session_data *sd)
}
if (sd->npc_id != 0
- || sd->opt1 != Opt1::ZERO
- || sd->sc_data[StatusChange::SC_NOCHAT].timer != -1) //会話禁止
+ || sd->opt1 != Opt1::ZERO) //会話禁止
return;
if (fitem == NULL || fitem->bl.m != sd->bl.m)
@@ -4538,11 +4481,10 @@ void clif_parse_UseItem(int fd, struct map_session_data *sd)
return;
}
if (sd->npc_id != 0
- || sd->opt1 != Opt1::ZERO
- || sd->sc_data[StatusChange::SC_NOCHAT].timer != -1) //会話禁止
+ || sd->opt1 != Opt1::ZERO) //会話禁止
return;
- if (sd->invincible_timer != -1)
+ if (sd->invincible_timer)
pc_delinvincibletimer(sd);
pc_useitem(sd, RFIFOW(fd, 2) - 2);
@@ -4606,10 +4548,10 @@ void clif_parse_UnequipItem(int fd, struct map_session_data *sd)
return;
}
index = RFIFOW(fd, 2) - 2;
- if (sd->status.inventory[index].broken == 1 && sd->sc_data[StatusChange::SC_BROKNWEAPON].timer != -1)
- skill_status_change_end(&sd->bl, StatusChange::SC_BROKNWEAPON, -1);
- if (sd->status.inventory[index].broken == 1 && sd->sc_data[StatusChange::SC_BROKNARMOR].timer != -1)
- skill_status_change_end(&sd->bl, StatusChange::SC_BROKNARMOR, -1);
+ if (sd->status.inventory[index].broken == 1 && sd->sc_data[StatusChange::SC_BROKNWEAPON].timer)
+ skill_status_change_end(&sd->bl, StatusChange::SC_BROKNWEAPON, nullptr);
+ if (sd->status.inventory[index].broken == 1 && sd->sc_data[StatusChange::SC_BROKNARMOR].timer)
+ skill_status_change_end(&sd->bl, StatusChange::SC_BROKNARMOR, nullptr);
if (sd->npc_id != 0
|| sd->opt1 != Opt1::ZERO)
@@ -4661,7 +4603,7 @@ void clif_parse_NpcBuyListSend(int fd, struct map_session_data *sd)
WFIFOW(fd, 0) = 0xca;
WFIFOB(fd, 2) = fail;
- WFIFOSET(fd, packet_len_table[0xca]);
+ WFIFOSET(fd, clif_parse_func_table[0xca].len);
}
/*==========================================
@@ -4679,7 +4621,7 @@ void clif_parse_NpcSellListSend(int fd, struct map_session_data *sd)
WFIFOW(fd, 0) = 0xcb;
WFIFOB(fd, 2) = fail;
- WFIFOSET(fd, packet_len_table[0xcb]);
+ WFIFOSET(fd, clif_parse_func_table[0xcb].len);
}
/*==========================================
@@ -5028,8 +4970,7 @@ void clif_parse_PartyMessage(int fd, struct map_session_data *sd)
return;
}
- if (is_atcommand(fd, sd, message, 0)
- || (sd->sc_data[StatusChange::SC_NOCHAT].timer != -1)) //チャット禁止
+ if (is_atcommand(fd, sd, message, 0)) //チャット禁止
{
free(buf);
return;
@@ -5060,12 +5001,12 @@ void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
{
sd->ignoreAll = 1;
WFIFOB(fd, 3) = 0; // success
- WFIFOSET(fd, packet_len_table[0x0d2]);
+ WFIFOSET(fd, clif_parse_func_table[0x0d2].len);
}
else
{
WFIFOB(fd, 3) = 1; // fail
- WFIFOSET(fd, packet_len_table[0x0d2]);
+ WFIFOSET(fd, clif_parse_func_table[0x0d2].len);
clif_wis_message(fd, wisp_server_name,
"You already block everyone.",
strlen("You already block everyone.") + 1);
@@ -5079,12 +5020,12 @@ void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
{
sd->ignoreAll = 0;
WFIFOB(fd, 3) = 0; // success
- WFIFOSET(fd, packet_len_table[0x0d2]);
+ WFIFOSET(fd, clif_parse_func_table[0x0d2].len);
}
else
{
WFIFOB(fd, 3) = 1; // fail
- WFIFOSET(fd, packet_len_table[0x0d2]);
+ WFIFOSET(fd, clif_parse_func_table[0x0d2].len);
clif_wis_message(fd, wisp_server_name,
"You already allow everyone.",
strlen("You already allow everyone.") + 1);
@@ -5094,580 +5035,566 @@ void clif_parse_PMIgnoreAll(int fd, struct map_session_data *sd)
return;
}
-// functions list. Rate is how many milliseconds are required between
-// calls. Packets exceeding this rate will be dropped. flood_rates in
-// map.h must be the same length as this table. rate 0 is default
-// rate -1 is unlimited
-
-// TODO: merge this with the packet length table, and put the pointer last
-typedef struct func_table
-{
- void(*func)(int fd, struct map_session_data *sd);
- int rate;
-} func_table;
-// *INDENT-OFF*
-static
-func_table clif_parse_func_table[0x220] =
-{
- { NULL, 0 }, // 0
- { NULL, 0 }, // 1
- { NULL, 0 }, // 2
- { NULL, 0 }, // 3
- { NULL, 0 }, // 4
- { NULL, 0 }, // 5
- { NULL, 0 }, // 6
- { NULL, 0 }, // 7
- { NULL, 0 }, // 8
- { NULL, 0 }, // 9
- { NULL, 0 }, // a
- { NULL, 0 }, // b
- { NULL, 0 }, // c
- { NULL, 0 }, // d
- { NULL, 0 }, // e
- { NULL, 0 }, // f
- { NULL, 0 }, // 10
- { NULL, 0 }, // 11
- { NULL, 0 }, // 12
- { NULL, 0 }, // 13
- { NULL, 0 }, // 14
- { NULL, 0 }, // 15
- { NULL, 0 }, // 16
- { NULL, 0 }, // 17
- { NULL, 0 }, // 18
- { NULL, 0 }, // 19
- { NULL, 0 }, // 1a
- { NULL, 0 }, // 1b
- { NULL, 0 }, // 1c
- { NULL, 0 }, // 1d
- { NULL, 0 }, // 1e
- { NULL, 0 }, // 1f
- { NULL, 0 }, // 20
- { NULL, 0 }, // 21
- { NULL, 0 }, // 22
- { NULL, 0 }, // 23
- { NULL, 0 }, // 24
- { NULL, 0 }, // 25
- { NULL, 0 }, // 26
- { NULL, 0 }, // 27
- { NULL, 0 }, // 28
- { NULL, 0 }, // 29
- { NULL, 0 }, // 2a
- { NULL, 0 }, // 2b
- { NULL, 0 }, // 2c
- { NULL, 0 }, // 2d
- { NULL, 0 }, // 2e
- { NULL, 0 }, // 2f
- { NULL, 0 }, // 30
- { NULL, 0 }, // 31
- { NULL, 0 }, // 32
- { NULL, 0 }, // 33
- { NULL, 0 }, // 34
- { NULL, 0 }, // 35
- { NULL, 0 }, // 36
- { NULL, 0 }, // 37
- { NULL, 0 }, // 38
- { NULL, 0 }, // 39
- { NULL, 0 }, // 3a
- { NULL, 0 }, // 3b
- { NULL, 0 }, // 3c
- { NULL, 0 }, // 3d
- { NULL, 0 }, // 3e
- { NULL, 0 }, // 3f
- { NULL, 0 }, // 40
- { NULL, 0 }, // 41
- { NULL, 0 }, // 42
- { NULL, 0 }, // 43
- { NULL, 0 }, // 44
- { NULL, 0 }, // 45
- { NULL, 0 }, // 46
- { NULL, 0 }, // 47
- { NULL, 0 }, // 48
- { NULL, 0 }, // 49
- { NULL, 0 }, // 4a
- { NULL, 0 }, // 4b
- { NULL, 0 }, // 4c
- { NULL, 0 }, // 4d
- { NULL, 0 }, // 4e
- { NULL, 0 }, // 4f
- { NULL, 0 }, // 50
- { NULL, 0 }, // 51
- { NULL, 0 }, // 52
- { NULL, 0 }, // 53
- { NULL, 0 }, // 54
- { NULL, 0 }, // 55
- { NULL, 0 }, // 56
- { NULL, 0 }, // 57
- { NULL, 0 }, // 58
- { NULL, 0 }, // 59
- { NULL, 0 }, // 5a
- { NULL, 0 }, // 5b
- { NULL, 0 }, // 5c
- { NULL, 0 }, // 5d
- { NULL, 0 }, // 5e
- { NULL, 0 }, // 5f
- { NULL, 0 }, // 60
- { NULL, 0 }, // 61
- { NULL, 0 }, // 62
- { NULL, 0 }, // 63
- { NULL, 0 }, // 64
- { NULL, 0 }, // 65
- { NULL, 0 }, // 66
- { NULL, 0 }, // 67
- { NULL, 0 }, // 68
- { NULL, 0 }, // 69
- { NULL, 0 }, // 6a
- { NULL, 0 }, // 6b
- { NULL, 0 }, // 6c
- { NULL, 0 }, // 6d
- { NULL, 0 }, // 6e
- { NULL, 0 }, // 6f
- { NULL, 0 }, // 70
- { NULL, 0 }, // 71
- { clif_parse_WantToConnection, 0 }, // 72
- { NULL, 0 }, // 73
- { NULL, 0 }, // 74
- { NULL, 0 }, // 75
- { NULL, 0 }, // 76
- { NULL, 0 }, // 77
- { NULL, 0 }, // 78
- { NULL, 0 }, // 79
- { NULL, 0 }, // 7a
- { NULL, 0 }, // 7b
- { NULL, 0 }, // 7c
- { clif_parse_LoadEndAck, -1 }, // 7d
- { clif_parse_TickSend, 0 }, // 7e
- { NULL, 0 }, // 7f
- { NULL, 0 }, // 80
- { NULL, 0 }, // 81
- { NULL, 0 }, // 82
- { NULL, 0 }, // 83
- { NULL, 0 }, // 84
- { clif_parse_WalkToXY, -1 }, // 85 Walk code limits this on it's own
- { NULL, 0 }, // 86
- { NULL, 0 }, // 87
- { NULL, 0 }, // 88
- { clif_parse_ActionRequest, 1000 }, // 89 Special case - see below
- { NULL, 0 }, // 8a
- { NULL, 0 }, // 8b
- { clif_parse_GlobalMessage, 300 }, // 8c
- { NULL, 0 }, // 8d
- { NULL, 0 }, // 8e
- { NULL, 0 }, // 8f
- { clif_parse_NpcClicked, 500 }, // 90
- { NULL, 0 }, // 91
- { NULL, 0 }, // 92
- { NULL, 0 }, // 93
- { clif_parse_GetCharNameRequest, -1 }, // 94
- { NULL, 0 }, // 95
- { clif_parse_Wis, 300 }, // 96
- { NULL, 0 }, // 97
- { NULL, 0 }, // 98
- { NULL, 300 }, // 99
- { NULL, 0 }, // 9a
- { clif_parse_ChangeDir, -1 }, // 9b
- { NULL, 0 }, // 9c
- { NULL, 0 }, // 9d
- { NULL, 0 }, // 9e
- { clif_parse_TakeItem, 400 }, // 9f
- { NULL, 0 }, // a0
- { NULL, 0 }, // a1
- { clif_parse_DropItem, 50 }, // a2
- { NULL, 0 }, // a3
- { NULL, 0 }, // a4
- { NULL, 0 }, // a5
- { NULL, 0 }, // a6
- { clif_parse_UseItem, 0 }, // a7
- { NULL, 0 }, // a8
- { clif_parse_EquipItem, -1 }, // a9 Special case - outfit window (not implemented yet - needs to allow bursts)
- { NULL, 0 }, // aa
- { clif_parse_UnequipItem, -1 }, // ab Special case - outfit window (not implemented yet - needs to allow bursts)
- { NULL, 0 }, // ac
- { NULL, 0 }, // ad
- { NULL, 0 }, // ae
- { NULL, 0 }, // af
- { NULL, 0 }, // b0
- { NULL, 0 }, // b1
- { clif_parse_Restart, 0 }, // b2
- { NULL, 0 }, // b3
- { NULL, 0 }, // b4
- { NULL, 0 }, // b5
- { NULL, 0 }, // b6
- { NULL, 0 }, // b7
- { clif_parse_NpcSelectMenu, 0 }, // b8
- { clif_parse_NpcNextClicked, -1 }, // b9
- { NULL, 0 }, // ba
- { clif_parse_StatusUp, -1 }, // bb People click this very quickly
- { NULL, 0 }, // bc
- { NULL, 0 }, // bd
- { NULL, 0 }, // be
- { clif_parse_Emotion, 1000 }, // bf
- { NULL, 0 }, // c0
- { clif_parse_HowManyConnections, 0 }, // c1
- { NULL, 0 }, // c2
- { NULL, 0 }, // c3
- { NULL, 0 }, // c4
- { clif_parse_NpcBuySellSelected, 0 }, // c5
- { NULL, 0 }, // c6
- { NULL, 0 }, // c7
- { clif_parse_NpcBuyListSend, -1 }, // c8
- { clif_parse_NpcSellListSend, -1 }, // c9 Selling multiple 1-slot items
- { NULL, 0 }, // ca
- { NULL, 0 }, // cb
- { NULL, 0 }, // cc
- { NULL, 0 }, // cd
- { NULL, 0 }, // ce
- { NULL, 0 }, // cf
- { clif_parse_PMIgnoreAll, 0 }, // d0
- { NULL, 0 }, // d1
- { NULL, 0 }, // d2
- { NULL, 0 }, // d3
- { NULL, 0 }, // d4
- { NULL, 0 }, // d5
- { NULL, 0 }, // d6
- { NULL, 0 }, // d7
- { NULL, 0 }, // d8
- { NULL, 0 }, // d9
- { NULL, 0 }, // da
- { NULL, 0 }, // db
- { NULL, 0 }, // dc
- { NULL, 0 }, // dd
- { NULL, 0 }, // de
- { NULL, 0 }, // df
- { NULL, 0 }, // e0
- { NULL, 0 }, // e1
- { NULL, 0 }, // e2
- { NULL, 0 }, // e3
- { clif_parse_TradeRequest, 2000 }, // e4
- { NULL, 0 }, // e5
- { clif_parse_TradeAck, 0 }, // e6
- { NULL, 0 }, // e7
- { clif_parse_TradeAddItem, 0 }, // e8
- { NULL, 0 }, // e9
- { NULL, 0 }, // ea
- { clif_parse_TradeOk, 0 }, // eb
- { NULL, 0 }, // ec
- { clif_parse_TradeCansel, 0 }, // ed
- { NULL, 0 }, // ee
- { clif_parse_TradeCommit, 0 }, // ef
- { NULL, 0 }, // f0
- { NULL, 0 }, // f1
- { NULL, 0 }, // f2
- { clif_parse_MoveToKafra, -1 }, // f3
- { NULL, 0 }, // f4
- { clif_parse_MoveFromKafra, -1 }, // f5
- { NULL, 0 }, // f6
- { clif_parse_CloseKafra, 0 }, // f7
- { NULL, 0 }, // f8
- { clif_parse_CreateParty, 2000 }, // f9
- { NULL, 0 }, // fa
- { NULL, 0 }, // fb
- { clif_parse_PartyInvite, 2000 }, // fc
- { NULL, 0 }, // fd
- { NULL, 0 }, // fe
- { clif_parse_ReplyPartyInvite, 0 }, // ff
- { clif_parse_LeaveParty, 0 }, // 100
- { NULL, 0 }, // 101
- { clif_parse_PartyChangeOption, 0 }, // 102
- { clif_parse_RemovePartyMember, 0 }, // 103
- { NULL, 0 }, // 104
- { NULL, 0 }, // 105
- { NULL, 0 }, // 106
- { NULL, 0 }, // 107
- { clif_parse_PartyMessage, 300 }, // 108
- { NULL, 0 }, // 109
- { NULL, 0 }, // 10a
- { NULL, 0 }, // 10b
- { NULL, 0 }, // 10c
- { NULL, 0 }, // 10d
- { NULL, 0 }, // 10e
- { NULL, 0 }, // 10f
- { NULL, 0 }, // 110
- { NULL, 0 }, // 111
- { clif_parse_SkillUp, -1 }, // 112
- { NULL, 0 }, // 113
- { NULL, 0 }, // 114
- { NULL, 0 }, // 115
- { NULL, 0 }, // 116
- { NULL, 0 }, // 117
- { clif_parse_StopAttack, 0 }, // 118
- { NULL, 0 }, // 119
- { NULL, 0 }, // 11a
- { NULL, 0 }, // 11b
- { NULL, 0 }, // 11c
- { NULL, 0 }, // 11d
- { NULL, 0 }, // 11e
- { NULL, 0 }, // 11f
- { NULL, 0 }, // 120
- { NULL, 0 }, // 121
- { NULL, 0 }, // 122
- { NULL, 0 }, // 123
- { NULL, 0 }, // 124
- { NULL, 0 }, // 125
- { NULL, 0 }, // 126
- { NULL, 0 }, // 127
- { NULL, 0 }, // 128
- { NULL, 0 }, // 129
- { NULL, 0 }, // 12a
- { NULL, 0 }, // 12b
- { NULL, 0 }, // 12c
- { NULL, 0 }, // 12d
- { NULL, 0 }, // 12e
- { NULL, 0 }, // 12f
- { NULL, 0 }, // 130
- { NULL, 0 }, // 131
- { NULL, 0 }, // 132
- { NULL, 0 }, // 133
- { NULL, 0 }, // 134
- { NULL, 0 }, // 135
- { NULL, 0 }, // 136
- { NULL, 0 }, // 137
- { NULL, 0 }, // 138
- { NULL, 0 }, // 139
- { NULL, 0 }, // 13a
- { NULL, 0 }, // 13b
- { NULL, 0 }, // 13c
- { NULL, 0 }, // 13d
- { NULL, 0 }, // 13e
- { NULL, 0 }, // 13f
- { NULL, 0 }, // 140
- { NULL, 0 }, // 141
- { NULL, 0 }, // 142
- { clif_parse_NpcAmountInput, 300 }, // 143
- { NULL, 0 }, // 144
- { NULL, 0 }, // 145
- { clif_parse_NpcCloseClicked, 300 }, // 146
- { NULL, 0 }, // 147
- { NULL, 0 }, // 148
- { NULL, 0 }, // 149
- { NULL, 0 }, // 14a
- { NULL, 0 }, // 14b
- { NULL, 0 }, // 14c
- { NULL, 0 }, // 14d
- { NULL, 0 }, // 14e
- { NULL, 0 }, // 14f
- { NULL, 0 }, // 150
- { NULL, 0 }, // 151
- { NULL, 0 }, // 152
- { NULL, 0 }, // 153
- { NULL, 0 }, // 154
- { NULL, 0 }, // 155
- { NULL, 0 }, // 156
- { NULL, 0 }, // 157
- { NULL, 0 }, // 158
- { NULL, 0 }, // 159
- { NULL, 0 }, // 15a
- { NULL, 0 }, // 15b
- { NULL, 0 }, // 15c
- { NULL, 0 }, // 15d
- { NULL, 0 }, // 15e
- { NULL, 0 }, // 15f
- { NULL, 0 }, // 160
- { NULL, 0 }, // 161
- { NULL, 0 }, // 162
- { NULL, 0 }, // 163
- { NULL, 0 }, // 164
- { NULL, 0 }, // 165
- { NULL, 0 }, // 166
- { NULL, 0 }, // 167
- { NULL, 0 }, // 168
- { NULL, 0 }, // 169
- { NULL, 0 }, // 16a
- { NULL, 0 }, // 16b
- { NULL, 0 }, // 16c
- { NULL, 0 }, // 16d
- { NULL, 0 }, // 16e
- { NULL, 0 }, // 16f
- { NULL, 0 }, // 170
- { NULL, 0 }, // 171
- { NULL, 0 }, // 172
- { NULL, 0 }, // 173
- { NULL, 0 }, // 174
- { NULL, 0 }, // 175
- { NULL, 0 }, // 176
- { NULL, 0 }, // 177
- { NULL, 0 }, // 178
- { NULL, 0 }, // 179
- { NULL, 0 }, // 17a
- { NULL, 0 }, // 17b
- { NULL, 0 }, // 17c
- { NULL, 0 }, // 17d
- { NULL, 0 }, // 17e
- { NULL, 0 }, // 17f
- { NULL, 0 }, // 180
- { NULL, 0 }, // 181
- { NULL, 0 }, // 182
- { NULL, 0 }, // 183
- { NULL, 0 }, // 184
- { NULL, 0 }, // 185
- { NULL, 0 }, // 186
- { NULL, 0 }, // 187
- { NULL, 0 }, // 188
- { NULL, 0 }, // 189
- { clif_parse_QuitGame, 0 }, // 18a
- { NULL, 0 }, // 18b
- { NULL, 0 }, // 18c
- { NULL, 0 }, // 18d
- { NULL, 0 }, // 18e
- { NULL, 0 }, // 18f
- { NULL, 0 }, // 190
- { NULL, 0 }, // 191
- { NULL, 0 }, // 192
- { NULL, 0 }, // 193
- { NULL, 0 }, // 194
- { NULL, 0 }, // 195
- { NULL, 0 }, // 196
- { NULL, 0 }, // 197
- { NULL, 0 }, // 198
- { NULL, 0 }, // 199
- { NULL, 0 }, // 19a
- { NULL, 0 }, // 19b
- { NULL, 0 }, // 19c
- { NULL, 300 }, // 19d
- { NULL, 0 }, // 19e
- { NULL, 0 }, // 19f
- { NULL, 0 }, // 1a0
- { NULL, 0 }, // 1a1
- { NULL, 0 }, // 1a2
- { NULL, 0 }, // 1a3
- { NULL, 0 }, // 1a4
- { NULL, 0 }, // 1a5
- { NULL, 0 }, // 1a6
- { NULL, 0 }, // 1a7
- { NULL, 0 }, // 1a8
- { NULL, 0 }, // 1a9
- { NULL, 0 }, // 1aa
- { NULL, 0 }, // 1ab
- { NULL, 0 }, // 1ac
- { NULL, 0 }, // 1ad
- { NULL, 0 }, // 1ae
- { NULL, 0 }, // 1af
- { NULL, 0 }, // 1b0
- { NULL, 0 }, // 1b1
- { NULL, 0 }, // 1b2
- { NULL, 0 }, // 1b3
- { NULL, 0 }, // 1b4
- { NULL, 0 }, // 1b5
- { NULL, 0 }, // 1b6
- { NULL, 0 }, // 1b7
- { NULL, 0 }, // 1b8
- { NULL, 0 }, // 1b9
- { NULL, 0 }, // 1ba
- { NULL, 0 }, // 1bb
- { NULL, 0 }, // 1bc
- { NULL, 0 }, // 1bd
- { NULL, 0 }, // 1be
- { NULL, 0 }, // 1bf
- { NULL, 0 }, // 1c0
- { NULL, 0 }, // 1c1
- { NULL, 0 }, // 1c2
- { NULL, 0 }, // 1c3
- { NULL, 0 }, // 1c4
- { NULL, 0 }, // 1c5
- { NULL, 0 }, // 1c6
- { NULL, 0 }, // 1c7
- { NULL, 0 }, // 1c8
- { NULL, 0 }, // 1c9
- { NULL, 0 }, // 1ca
- { NULL, 0 }, // 1cb
- { NULL, 0 }, // 1cc
- { NULL, 0 }, // 1cd
- { NULL, 0 }, // 1ce
- { NULL, 0 }, // 1cf
- { NULL, 0 }, // 1d0
- { NULL, 0 }, // 1d1
- { NULL, 0 }, // 1d2
- { NULL, 0 }, // 1d3
- { NULL, 0 }, // 1d4
- { clif_parse_NpcStringInput, 300 }, // 1d5
- { NULL, 0 }, // 1d6
- { NULL, 0 }, // 1d7
- { NULL, 0 }, // 1d8
- { NULL, 0 }, // 1d9
- { NULL, 0 }, // 1da
- { NULL, 0 }, // 1db
- { NULL, 0 }, // 1dc
- { NULL, 0 }, // 1dd
- { NULL, 0 }, // 1de
- { NULL, 0 }, // 1df
- { NULL, 0 }, // 1e0
- { NULL, 0 }, // 1e1
- { NULL, 0 }, // 1e2
- { NULL, 0 }, // 1e3
- { NULL, 0 }, // 1e4
- { NULL, 0 }, // 1e5
- { NULL, 0 }, // 1e6
- { NULL, 0 }, // 1e7
- { NULL, 0 }, // 1e8
- { NULL, 0 }, // 1e9
- { NULL, 0 }, // 1ea
- { NULL, 0 }, // 1eb
- { NULL, 0 }, // 1ec
- { NULL, 0 }, // 1ed
- { NULL, 0 }, // 1ee
- { NULL, 0 }, // 1ef
- { NULL, 0 }, // 1f0
- { NULL, 0 }, // 1f1
- { NULL, 0 }, // 1f2
- { NULL, 0 }, // 1f3
- { NULL, 0 }, // 1f4
- { NULL, 0 }, // 1f5
- { NULL, 0 }, // 1f6
- { NULL, 0 }, // 1f7
- { NULL, 0 }, // 1f8
- { NULL, 0 }, // 1f9
- { NULL, 0 }, // 1fa
- { NULL, 0 }, // 1fb
- { NULL, 0 }, // 1fc
- { NULL, 0 }, // 1fd
- { NULL, 0 }, // 1fe
- { NULL, 0 }, // 1ff
- { NULL, 0 }, // 200
- { NULL, 0 }, // 201
- { NULL, 0 }, // 202
- { NULL, 0 }, // 203
- { NULL, 0 }, // 204
- { NULL, 0 }, // 205
- { NULL, 0 }, // 206
- { NULL, 0 }, // 207
- { NULL, 0 }, // 208
- { NULL, 0 }, // 209
- { NULL, 0 }, // 20a
- { NULL, 0 }, // 20b
- { NULL, 0 }, // 20c
- { NULL, 0 }, // 20d
- { NULL, 0 }, // 20e
- { NULL, 0 }, // 20f
- { NULL, 0 }, // 210
- { NULL, 0 }, // 211
- { NULL, 0 }, // 212
- { NULL, 0 }, // 213
- { NULL, 0 }, // 214
- { NULL, 0 }, // 215
- { NULL, 0 }, // 216
- { NULL, 0 }, // 217
- { NULL, 0 }, // 218
- { NULL, 0 }, // 219
- { NULL, 0 }, // 21a
- { NULL, 0 }, // 21b
- { NULL, 0 }, // 21c
- { NULL, 0 }, // 21d
- { NULL, 0 }, // 21e
- { NULL, 0 }, // 21f
+func_table clif_parse_func_table[0x0220] =
+{
+ {0, 10, NULL, }, // 0x0000
+ {0, 0, NULL, }, // 0x0001
+ {0, 0, NULL, }, // 0x0002
+ {0, 0, NULL, }, // 0x0003
+ {0, 0, NULL, }, // 0x0004
+ {0, 0, NULL, }, // 0x0005
+ {0, 0, NULL, }, // 0x0006
+ {0, 0, NULL, }, // 0x0007
+ {0, 0, NULL, }, // 0x0008
+ {0, 0, NULL, }, // 0x0009
+ {0, 0, NULL, }, // 0x000a
+ {0, 0, NULL, }, // 0x000b
+ {0, 0, NULL, }, // 0x000c
+ {0, 0, NULL, }, // 0x000d
+ {0, 0, NULL, }, // 0x000e
+ {0, 0, NULL, }, // 0x000f
+ {0, 0, NULL, }, // 0x0010
+ {0, 0, NULL, }, // 0x0011
+ {0, 0, NULL, }, // 0x0012
+ {0, 0, NULL, }, // 0x0013
+ {0, 0, NULL, }, // 0x0014
+ {0, 0, NULL, }, // 0x0015
+ {0, 0, NULL, }, // 0x0016
+ {0, 0, NULL, }, // 0x0017
+ {0, 0, NULL, }, // 0x0018
+ {0, 0, NULL, }, // 0x0019
+ {0, 0, NULL, }, // 0x001a
+ {0, 0, NULL, }, // 0x001b
+ {0, 0, NULL, }, // 0x001c
+ {0, 0, NULL, }, // 0x001d
+ {0, 0, NULL, }, // 0x001e
+ {0, 0, NULL, }, // 0x001f
+ {0, 0, NULL, }, // 0x0020
+ {0, 0, NULL, }, // 0x0021
+ {0, 0, NULL, }, // 0x0022
+ {0, 0, NULL, }, // 0x0023
+ {0, 0, NULL, }, // 0x0024
+ {0, 0, NULL, }, // 0x0025
+ {0, 0, NULL, }, // 0x0026
+ {0, 0, NULL, }, // 0x0027
+ {0, 0, NULL, }, // 0x0028
+ {0, 0, NULL, }, // 0x0029
+ {0, 0, NULL, }, // 0x002a
+ {0, 0, NULL, }, // 0x002b
+ {0, 0, NULL, }, // 0x002c
+ {0, 0, NULL, }, // 0x002d
+ {0, 0, NULL, }, // 0x002e
+ {0, 0, NULL, }, // 0x002f
+ {0, 0, NULL, }, // 0x0030
+ {0, 0, NULL, }, // 0x0031
+ {0, 0, NULL, }, // 0x0032
+ {0, 0, NULL, }, // 0x0033
+ {0, 0, NULL, }, // 0x0034
+ {0, 0, NULL, }, // 0x0035
+ {0, 0, NULL, }, // 0x0036
+ {0, 0, NULL, }, // 0x0037
+ {0, 0, NULL, }, // 0x0038
+ {0, 0, NULL, }, // 0x0039
+ {0, 0, NULL, }, // 0x003a
+ {0, 0, NULL, }, // 0x003b
+ {0, 0, NULL, }, // 0x003c
+ {0, 0, NULL, }, // 0x003d
+ {0, 0, NULL, }, // 0x003e
+ {0, 0, NULL, }, // 0x003f
+ {0, 0, NULL, }, // 0x0040
+ {0, 0, NULL, }, // 0x0041
+ {0, 0, NULL, }, // 0x0042
+ {0, 0, NULL, }, // 0x0043
+ {0, 0, NULL, }, // 0x0044
+ {0, 0, NULL, }, // 0x0045
+ {0, 0, NULL, }, // 0x0046
+ {0, 0, NULL, }, // 0x0047
+ {0, 0, NULL, }, // 0x0048
+ {0, 0, NULL, }, // 0x0049
+ {0, 0, NULL, }, // 0x004a
+ {0, 0, NULL, }, // 0x004b
+ {0, 0, NULL, }, // 0x004c
+ {0, 0, NULL, }, // 0x004d
+ {0, 0, NULL, }, // 0x004e
+ {0, 0, NULL, }, // 0x004f
+ {0, 0, NULL, }, // 0x0050
+ {0, 0, NULL, }, // 0x0051
+ {0, 0, NULL, }, // 0x0052
+ {0, 0, NULL, }, // 0x0053
+ {0, 0, NULL, }, // 0x0054
+ {0, 0, NULL, }, // 0x0055
+ {0, 0, NULL, }, // 0x0056
+ {0, 0, NULL, }, // 0x0057
+ {0, 0, NULL, }, // 0x0058
+ {0, 0, NULL, }, // 0x0059
+ {0, 0, NULL, }, // 0x005a
+ {0, 0, NULL, }, // 0x005b
+ {0, 0, NULL, }, // 0x005c
+ {0, 0, NULL, }, // 0x005d
+ {0, 0, NULL, }, // 0x005e
+ {0, 0, NULL, }, // 0x005f
+ {0, 0, NULL, }, // 0x0060
+ {0, 0, NULL, }, // 0x0061
+ {0, 0, NULL, }, // 0x0062
+ {0, VAR,NULL, }, // 0x0063
+ {0, 55, NULL, }, // 0x0064
+ {0, 17, NULL, }, // 0x0065
+ {0, 3, NULL, }, // 0x0066
+ {0, 37, NULL, }, // 0x0067
+ {0, 46, NULL, }, // 0x0068
+ {0, VAR,NULL, }, // 0x0069
+ {0, 23, NULL, }, // 0x006a
+ {0, VAR,NULL, }, // 0x006b
+ {0, 3, NULL, }, // 0x006c
+ {0, 108,NULL, }, // 0x006d
+ {0, 3, NULL, }, // 0x006e
+ {0, 2, NULL, }, // 0x006f
+ {0, 3, NULL, }, // 0x0070
+ {0, 28, NULL, }, // 0x0071
+ {0, 19, clif_parse_WantToConnection, }, // 0x0072
+ {0, 11, NULL, }, // 0x0073
+ {0, 3, NULL, }, // 0x0074
+ {0, VAR,NULL, }, // 0x0075
+ {0, 9, NULL, }, // 0x0076
+ {0, 5, NULL, }, // 0x0077
+ {0, 54, NULL, }, // 0x0078
+ {0, 53, NULL, }, // 0x0079
+ {0, 58, NULL, }, // 0x007a
+ {0, 60, NULL, }, // 0x007b
+ {0, 41, NULL, }, // 0x007c
+ {-1, 2, clif_parse_LoadEndAck, }, // 0x007d
+ {0, 6, clif_parse_TickSend, }, // 0x007e
+ {0, 6, NULL, }, // 0x007f
+ {0, 7, NULL, }, // 0x0080
+ {0, 3, NULL, }, // 0x0081
+ {0, 2, NULL, }, // 0x0082
+ {0, 2, NULL, }, // 0x0083
+ {0, 2, NULL, }, // 0x0084
+ {-1, 5, clif_parse_WalkToXY, }, // 0x0085 Walk code limits this on it's own
+ {0, 16, NULL, }, // 0x0086
+ {0, 12, NULL, }, // 0x0087
+ {0, 10, NULL, }, // 0x0088
+ {1000, 7, clif_parse_ActionRequest, }, // 0x0089 Special case - see below
+ {0, 29, NULL, }, // 0x008a
+ {0, 23, NULL, }, // 0x008b unknown... size 2 or 23?
+ {300, VAR,clif_parse_GlobalMessage, }, // 0x008c
+ {0, VAR,NULL, }, // 0x008d
+ {0, VAR,NULL, }, // 0x008e
+ {0, 0, NULL, }, // 0x008f
+ {500, 7, clif_parse_NpcClicked, }, // 0x0090
+ {0, 22, NULL, }, // 0x0091
+ {0, 28, NULL, }, // 0x0092
+ {0, 2, NULL, }, // 0x0093
+ {-1, 6, clif_parse_GetCharNameRequest, }, // 0x0094
+ {0, 30, NULL, }, // 0x0095
+ {300, VAR,clif_parse_Wis, }, // 0x0096
+ {0, VAR,NULL, }, // 0x0097
+ {0, 3, NULL, }, // 0x0098
+ {300, VAR,NULL, }, // 0x0099
+ {0, VAR,NULL, }, // 0x009a
+ {-1, 5, clif_parse_ChangeDir, }, // 0x009b
+ {0, 9, NULL, }, // 0x009c
+ {0, 17, NULL, }, // 0x009d
+ {0, 17, NULL, }, // 0x009e
+ {400, 6, clif_parse_TakeItem, }, // 0x009f
+ {0, 23, NULL, }, // 0x00a0
+ {0, 6, NULL, }, // 0x00a1
+ {50, 6, clif_parse_DropItem, }, // 0x00a2
+ {0, VAR,NULL, }, // 0x00a3
+ {0, VAR,NULL, }, // 0x00a4
+ {0, VAR,NULL, }, // 0x00a5
+ {0, VAR,NULL, }, // 0x00a6
+ {0, 8, clif_parse_UseItem, }, // 0x00a7
+ {0, 7, NULL, }, // 0x00a8
+ {-1, 6, clif_parse_EquipItem, }, // 0x00a9 Special case - outfit window (not implemented yet - needs to allow bursts)
+ {0, 7, NULL, }, // 0x00aa
+ {-1, 4, clif_parse_UnequipItem, }, // 0x00ab Special case - outfit window (not implemented yet - needs to allow bursts)
+ {0, 7, NULL, }, // 0x00ac
+ {0, 0, NULL, }, // 0x00ad
+ {0, VAR,NULL, }, // 0x00ae
+ {0, 6, NULL, }, // 0x00af
+ {0, 8, NULL, }, // 0x00b0
+ {0, 8, NULL, }, // 0x00b1
+ {0, 3, clif_parse_Restart, }, // 0x00b2
+ {0, 3, NULL, }, // 0x00b3
+ {0, VAR,NULL, }, // 0x00b4
+ {0, 6, NULL, }, // 0x00b5
+ {0, 6, NULL, }, // 0x00b6
+ {0, VAR,NULL, }, // 0x00b7
+ {0, 7, clif_parse_NpcSelectMenu, }, // 0x00b8
+ {-1, 6, clif_parse_NpcNextClicked, }, // 0x00b9
+ {0, 2, NULL, }, // 0x00ba
+ {-1, 5, clif_parse_StatusUp, }, // 0x00bb People click this very quickly
+ {0, 6, NULL, }, // 0x00bc
+ {0, 44, NULL, }, // 0x00bd
+ {0, 5, NULL, }, // 0x00be
+ {1000, 3, clif_parse_Emotion, }, // 0x00bf
+ {0, 7, NULL, }, // 0x00c0
+ {0, 2, clif_parse_HowManyConnections, }, // 0x00c1
+ {0, 6, NULL, }, // 0x00c2
+ {0, 8, NULL, }, // 0x00c3
+ {0, 6, NULL, }, // 0x00c4
+ {0, 7, clif_parse_NpcBuySellSelected, }, // 0x00c5
+ {0, VAR,NULL, }, // 0x00c6
+ {0, VAR,NULL, }, // 0x00c7
+ {-1, VAR,clif_parse_NpcBuyListSend, }, // 0x00c8
+ {-1, VAR,clif_parse_NpcSellListSend, }, // 0x00c9 Selling multiple 1-slot items
+ {0, 3, NULL, }, // 0x00ca
+ {0, 3, NULL, }, // 0x00cb
+ {0, 6, NULL, }, // 0x00cc
+ {0, 6, NULL, }, // 0x00cd
+ {0, 2, NULL, }, // 0x00ce
+ {0, 27, NULL, }, // 0x00cf
+ {0, 3, clif_parse_PMIgnoreAll, }, // 0x00d0
+ {0, 4, NULL, }, // 0x00d1
+ {0, 4, NULL, }, // 0x00d2
+ {0, 2, NULL, }, // 0x00d3
+ {0, VAR,NULL, }, // 0x00d4
+ {0, VAR,NULL, }, // 0x00d5
+ {0, 3, NULL, }, // 0x00d6
+ {0, VAR,NULL, }, // 0x00d7
+ {0, 6, NULL, }, // 0x00d8
+ {0, 14, NULL, }, // 0x00d9
+ {0, 3, NULL, }, // 0x00da
+ {0, VAR,NULL, }, // 0x00db
+ {0, 28, NULL, }, // 0x00dc
+ {0, 29, NULL, }, // 0x00dd
+ {0, VAR,NULL, }, // 0x00de
+ {0, VAR,NULL, }, // 0x00df
+ {0, 30, NULL, }, // 0x00e0
+ {0, 30, NULL, }, // 0x00e1
+ {0, 26, NULL, }, // 0x00e2
+ {0, 2, NULL, }, // 0x00e3
+ {2000, 6, clif_parse_TradeRequest, }, // 0x00e4
+ {0, 26, NULL, }, // 0x00e5
+ {0, 3, clif_parse_TradeAck, }, // 0x00e6
+ {0, 3, NULL, }, // 0x00e7
+ {0, 8, clif_parse_TradeAddItem, }, // 0x00e8
+ {0, 19, NULL, }, // 0x00e9
+ {0, 5, NULL, }, // 0x00ea
+ {0, 2, clif_parse_TradeOk, }, // 0x00eb
+ {0, 3, NULL, }, // 0x00ec
+ {0, 2, clif_parse_TradeCansel, }, // 0x00ed
+ {0, 2, NULL, }, // 0x00ee
+ {0, 2, clif_parse_TradeCommit, }, // 0x00ef
+ {0, 3, NULL, }, // 0x00f0
+ {0, 2, NULL, }, // 0x00f1
+ {0, 6, NULL, }, // 0x00f2
+ {-1, 8, clif_parse_MoveToKafra, }, // 0x00f3
+ {0, 21, NULL, }, // 0x00f4
+ {-1, 8, clif_parse_MoveFromKafra, }, // 0x00f5
+ {0, 8, NULL, }, // 0x00f6
+ {0, 2, clif_parse_CloseKafra, }, // 0x00f7
+ {0, 2, NULL, }, // 0x00f8
+ {2000, 26, clif_parse_CreateParty, }, // 0x00f9
+ {0, 3, NULL, }, // 0x00fa
+ {0, VAR,NULL, }, // 0x00fb
+ {2000, 6, clif_parse_PartyInvite, }, // 0x00fc
+ {0, 27, NULL, }, // 0x00fd
+ {0, 30, NULL, }, // 0x00fe
+ {0, 10, clif_parse_ReplyPartyInvite, }, // 0x00ff
+ {0, 2, clif_parse_LeaveParty, }, // 0x0100
+ {0, 6, NULL, }, // 0x0101
+ {0, 6, clif_parse_PartyChangeOption, }, // 0x0102
+ {0, 30, clif_parse_RemovePartyMember, }, // 0x0103
+ {0, 79, NULL, }, // 0x0104
+ {0, 31, NULL, }, // 0x0105
+ {0, 10, NULL, }, // 0x0106
+ {0, 10, NULL, }, // 0x0107
+ {300, VAR,clif_parse_PartyMessage, }, // 0x0108
+ {0, VAR,NULL, }, // 0x0109
+ {0, 4, NULL, }, // 0x010a
+ {0, 6, NULL, }, // 0x010b
+ {0, 6, NULL, }, // 0x010c
+ {0, 2, NULL, }, // 0x010d
+ {0, 11, NULL, }, // 0x010e
+ {0, VAR,NULL, }, // 0x010f
+ {0, 10, NULL, }, // 0x0110
+ {0, 39, NULL, }, // 0x0111
+ {-1, 4, clif_parse_SkillUp, }, // 0x0112
+ {0, 10, NULL, }, // 0x0113
+ {0, 31, NULL, }, // 0x0114
+ {0, 35, NULL, }, // 0x0115
+ {0, 10, NULL, }, // 0x0116
+ {0, 18, NULL, }, // 0x0117
+ {0, 2, clif_parse_StopAttack, }, // 0x0118
+ {0, 13, NULL, }, // 0x0119
+ {0, 15, NULL, }, // 0x011a
+ {0, 20, NULL, }, // 0x011b
+ {0, 68, NULL, }, // 0x011c
+ {0, 2, NULL, }, // 0x011d
+ {0, 3, NULL, }, // 0x011e
+ {0, 16, NULL, }, // 0x011f
+ {0, 6, NULL, }, // 0x0120
+ {0, 14, NULL, }, // 0x0121
+ {0, VAR,NULL, }, // 0x0122
+ {0, VAR,NULL, }, // 0x0123
+ {0, 21, NULL, }, // 0x0124
+ {0, 8, NULL, }, // 0x0125
+ {0, 8, NULL, }, // 0x0126
+ {0, 8, NULL, }, // 0x0127
+ {0, 8, NULL, }, // 0x0128
+ {0, 8, NULL, }, // 0x0129
+ {0, 2, NULL, }, // 0x012a
+ {0, 2, NULL, }, // 0x012b
+ {0, 3, NULL, }, // 0x012c
+ {0, 4, NULL, }, // 0x012d
+ {0, 2, NULL, }, // 0x012e
+ {0, VAR,NULL, }, // 0x012f
+ {0, 6, NULL, }, // 0x0130
+ {0, 86, NULL, }, // 0x0131
+ {0, 6, NULL, }, // 0x0132
+ {0, VAR,NULL, }, // 0x0133
+ {0, VAR,NULL, }, // 0x0134
+ {0, 7, NULL, }, // 0x0135
+ {0, VAR,NULL, }, // 0x0136
+ {0, 6, NULL, }, // 0x0137
+ {0, 3, NULL, }, // 0x0138
+ {0, 16, NULL, }, // 0x0139
+ {0, 4, NULL, }, // 0x013a
+ {0, 4, NULL, }, // 0x013b
+ {0, 4, NULL, }, // 0x013c
+ {0, 6, NULL, }, // 0x013d
+ {0, 24, NULL, }, // 0x013e
+ {0, 26, NULL, }, // 0x013f
+ {0, 22, NULL, }, // 0x0140
+ {0, 14, NULL, }, // 0x0141
+ {0, 6, NULL, }, // 0x0142
+ {300, 10, clif_parse_NpcAmountInput, }, // 0x0143
+ {0, 23, NULL, }, // 0x0144
+ {0, 19, NULL, }, // 0x0145
+ {300, 6, clif_parse_NpcCloseClicked, }, // 0x0146
+ {0, 39, NULL, }, // 0x0147
+ {0, 8, NULL, }, // 0x0148
+ {0, 9, NULL, }, // 0x0149
+ {0, 6, NULL, }, // 0x014a
+ {0, 27, NULL, }, // 0x014b
+ {0, VAR,NULL, }, // 0x014c
+ {0, 2, NULL, }, // 0x014d
+ {0, 6, NULL, }, // 0x014e
+ {0, 6, NULL, }, // 0x014f
+ {0, 110,NULL, }, // 0x0150
+ {0, 6, NULL, }, // 0x0151
+ {0, VAR,NULL, }, // 0x0152
+ {0, VAR,NULL, }, // 0x0153
+ {0, VAR,NULL, }, // 0x0154
+ {0, VAR,NULL, }, // 0x0155
+ {0, VAR,NULL, }, // 0x0156
+ {0, 6, NULL, }, // 0x0157
+ {0, VAR,NULL, }, // 0x0158
+ {0, 54, NULL, }, // 0x0159
+ {0, 66, NULL, }, // 0x015a
+ {0, 54, NULL, }, // 0x015b
+ {0, 90, NULL, }, // 0x015c
+ {0, 42, NULL, }, // 0x015d
+ {0, 6, NULL, }, // 0x015e
+ {0, 42, NULL, }, // 0x015f
+ {0, VAR,NULL, }, // 0x0160
+ {0, VAR,NULL, }, // 0x0161
+ {0, VAR,NULL, }, // 0x0162
+ {0, VAR,NULL, }, // 0x0163
+ {0, VAR,NULL, }, // 0x0164
+ {0, 30, NULL, }, // 0x0165
+ {0, VAR,NULL, }, // 0x0166
+ {0, 3, NULL, }, // 0x0167
+ {0, 14, NULL, }, // 0x0168
+ {0, 3, NULL, }, // 0x0169
+ {0, 30, NULL, }, // 0x016a
+ {0, 10, NULL, }, // 0x016b
+ {0, 43, NULL, }, // 0x016c
+ {0, 14, NULL, }, // 0x016d
+ {0, 186,NULL, }, // 0x016e
+ {0, 182,NULL, }, // 0x016f
+ {0, 14, NULL, }, // 0x0170
+ {0, 30, NULL, }, // 0x0171
+ {0, 10, NULL, }, // 0x0172
+ {0, 3, NULL, }, // 0x0173
+ {0, VAR,NULL, }, // 0x0174
+ {0, 6, NULL, }, // 0x0175
+ {0, 106,NULL, }, // 0x0176
+ {0, VAR,NULL, }, // 0x0177
+ {0, 4, NULL, }, // 0x0178
+ {0, 5, NULL, }, // 0x0179
+ {0, 4, NULL, }, // 0x017a
+ {0, VAR,NULL, }, // 0x017b
+ {0, 6, NULL, }, // 0x017c
+ {0, 7, NULL, }, // 0x017d
+ {0, VAR,NULL, }, // 0x017e
+ {0, VAR,NULL, }, // 0x017f
+ {0, 6, NULL, }, // 0x0180
+ {0, 3, NULL, }, // 0x0181
+ {0, 106,NULL, }, // 0x0182
+ {0, 10, NULL, }, // 0x0183
+ {0, 10, NULL, }, // 0x0184
+ {0, 34, NULL, }, // 0x0185
+ {0, 0, NULL, }, // 0x0186
+ {0, 6, NULL, }, // 0x0187
+ {0, 8, NULL, }, // 0x0188
+ {0, 4, NULL, }, // 0x0189
+ {0, 4, clif_parse_QuitGame, }, // 0x018a
+ {0, 4, NULL, }, // 0x018b
+ {0, 29, NULL, }, // 0x018c
+ {0, VAR,NULL, }, // 0x018d
+ {0, 10, NULL, }, // 0x018e
+ {0, 6, NULL, }, // 0x018f
+ {0, 90, NULL, }, // 0x0190
+ {0, 86, NULL, }, // 0x0191
+ {0, 24, NULL, }, // 0x0192
+ {0, 6, NULL, }, // 0x0193
+ {0, 30, NULL, }, // 0x0194
+ {0, 102,NULL, }, // 0x0195
+ {0, 9, NULL, }, // 0x0196
+ {0, 4, NULL, }, // 0x0197
+ {0, 8, NULL, }, // 0x0198
+ {0, 4, NULL, }, // 0x0199
+ {0, 14, NULL, }, // 0x019a
+ {0, 10, NULL, }, // 0x019b
+ {0, VAR,NULL, }, // 0x019c
+ {300, 6, NULL, }, // 0x019d
+ {0, 2, NULL, }, // 0x019e
+ {0, 6, NULL, }, // 0x019f
+ {0, 3, NULL, }, // 0x01a0
+ {0, 3, NULL, }, // 0x01a1
+ {0, 35, NULL, }, // 0x01a2
+ {0, 5, NULL, }, // 0x01a3
+ {0, 11, NULL, }, // 0x01a4
+ {0, 26, NULL, }, // 0x01a5
+ {0, VAR,NULL, }, // 0x01a6
+ {0, 4, NULL, }, // 0x01a7
+ {0, 4, NULL, }, // 0x01a8
+ {0, 6, NULL, }, // 0x01a9
+ {0, 10, NULL, }, // 0x01aa
+ {0, 12, NULL, }, // 0x01ab
+ {0, 6, NULL, }, // 0x01ac
+ {0, VAR,NULL, }, // 0x01ad
+ {0, 4, NULL, }, // 0x01ae
+ {0, 4, NULL, }, // 0x01af
+ {0, 11, NULL, }, // 0x01b0
+ {0, 7, NULL, }, // 0x01b1
+ {0, VAR,NULL, }, // 0x01b2
+ {0, 67, NULL, }, // 0x01b3
+ {0, 12, NULL, }, // 0x01b4
+ {0, 18, NULL, }, // 0x01b5
+ {0, 114,NULL, }, // 0x01b6
+ {0, 6, NULL, }, // 0x01b7
+ {0, 3, NULL, }, // 0x01b8
+ {0, 6, NULL, }, // 0x01b9
+ {0, 26, NULL, }, // 0x01ba
+ {0, 26, NULL, }, // 0x01bb
+ {0, 26, NULL, }, // 0x01bc
+ {0, 26, NULL, }, // 0x01bd
+ {0, 2, NULL, }, // 0x01be
+ {0, 3, NULL, }, // 0x01bf
+ {0, 2, NULL, }, // 0x01c0
+ {0, 14, NULL, }, // 0x01c1
+ {0, 10, NULL, }, // 0x01c2
+ {0, VAR,NULL, }, // 0x01c3
+ {0, 22, NULL, }, // 0x01c4
+ {0, 22, NULL, }, // 0x01c5
+ {0, 4, NULL, }, // 0x01c6
+ {0, 2, NULL, }, // 0x01c7
+ {0, 13, NULL, }, // 0x01c8
+ {0, 97, NULL, }, // 0x01c9
+ {0, 0, NULL, }, // 0x01ca
+ {0, 9, NULL, }, // 0x01cb
+ {0, 9, NULL, }, // 0x01cc
+ {0, 30, NULL, }, // 0x01cd
+ {0, 6, NULL, }, // 0x01ce
+ {0, 28, NULL, }, // 0x01cf
+ {0, 8, NULL, }, // 0x01d0
+ {0, 14, NULL, }, // 0x01d1
+ {0, 10, NULL, }, // 0x01d2
+ {0, 35, NULL, }, // 0x01d3
+ {0, 6, NULL, }, // 0x01d4
+ {300, VAR,clif_parse_NpcStringInput, }, // 0x01d5 - set to -1
+ {0, 4, NULL, }, // 0x01d6
+ {0, 11, NULL, }, // 0x01d7
+ {0, 54, NULL, }, // 0x01d8
+ {0, 53, NULL, }, // 0x01d9
+ {0, 60, NULL, }, // 0x01da
+ {0, 2, NULL, }, // 0x01db
+ {0, VAR,NULL, }, // 0x01dc
+ {0, 47, NULL, }, // 0x01dd
+ {0, 33, NULL, }, // 0x01de
+ {0, 6, NULL, }, // 0x01df
+ {0, 30, NULL, }, // 0x01e0
+ {0, 8, NULL, }, // 0x01e1
+ {0, 34, NULL, }, // 0x01e2
+ {0, 14, NULL, }, // 0x01e3
+ {0, 2, NULL, }, // 0x01e4
+ {0, 6, NULL, }, // 0x01e5
+ {0, 26, NULL, }, // 0x01e6
+ {0, 2, NULL, }, // 0x01e7
+ {0, 28, NULL, }, // 0x01e8
+ {0, 81, NULL, }, // 0x01e9
+ {0, 6, NULL, }, // 0x01ea
+ {0, 10, NULL, }, // 0x01eb
+ {0, 26, NULL, }, // 0x01ec
+ {0, 2, NULL, }, // 0x01ed
+ {0, VAR,NULL, }, // 0x01ee
+ {0, VAR,NULL, }, // 0x01ef
+ {0, VAR,NULL, }, // 0x01f0
+ {0, VAR,NULL, }, // 0x01f1
+ {0, 20, NULL, }, // 0x01f2
+ {0, 10, NULL, }, // 0x01f3
+ {0, 32, NULL, }, // 0x01f4
+ {0, 9, NULL, }, // 0x01f5
+ {0, 34, NULL, }, // 0x01f6
+ {0, 14, NULL, }, // 0x01f7
+ {0, 2, NULL, }, // 0x01f8
+ {0, 6, NULL, }, // 0x01f9
+ {0, 48, NULL, }, // 0x01fa
+ {0, 56, NULL, }, // 0x01fb
+ {0, VAR,NULL, }, // 0x01fc
+ {0, 4, NULL, }, // 0x01fd
+ {0, 5, NULL, }, // 0x01fe
+ {0, 10, NULL, }, // 0x01ff
+ {0, 26, NULL, }, // 0x0200
+ {0, VAR,NULL, }, // 0x0201
+ {0, 26, NULL, }, // 0x0202
+ {0, 10, NULL, }, // 0x0203
+ {0, 18, NULL, }, // 0x0204
+ {0, 26, NULL, }, // 0x0205
+ {0, 11, NULL, }, // 0x0206
+ {0, 34, NULL, }, // 0x0207
+ {0, 14, NULL, }, // 0x0208
+ {0, 36, NULL, }, // 0x0209
+ {0, 10, NULL, }, // 0x020a
+ {0, 19, NULL, }, // 0x020b
+ {0, 10, NULL, }, // 0x020c
+ {0, VAR,NULL, }, // 0x020d
+ {0, 24, NULL, }, // 0x020e
+ {0, 0, NULL, }, // 0x020f
+ {0, 0, NULL, }, // 0x0210
+ {0, 0, NULL, }, // 0x0211
+ {0, 0, NULL, }, // 0x0212
+ {0, 0, NULL, }, // 0x0213
+ {0, 0, NULL, }, // 0x0214
+ {0, 0, NULL, }, // 0x0215
+ {0, 0, NULL, }, // 0x0216
+ {0, 0, NULL, }, // 0x0217
+ {0, 0, NULL, }, // 0x0218
+ {0, 0, NULL, }, // 0x0219
+ {0, 0, NULL, }, // 0x021a
+ {0, 0, NULL, }, // 0x021b
+ {0, 0, NULL, }, // 0x021c
+ {0, 0, NULL, }, // 0x021d
+ {0, 0, NULL, }, // 0x021e
+ {0, 0, NULL, }, // 0x021f
};
-// *INDENT-ON*
// Checks for packet flooding
static
int clif_check_packet_flood(int fd, int cmd)
{
struct map_session_data *sd = (struct map_session_data *)session[fd]->session_data;
- unsigned int rate, tick = gettick();
+ tick_t tick = gettick();
// sd will not be set if the client hasn't requested
// WantToConnection yet. Do not apply flood logic to GMs
// as approved bots (GMlvl1) should not have to work around
// flood logic.
- if (!sd || pc_isGM(sd) || clif_parse_func_table[cmd].rate == -1)
+ if (!sd || pc_isGM(sd) || clif_parse_func_table[cmd].rate == static_cast<interval_t>(-1))
return 0;
// Timer has wrapped
@@ -5678,17 +5605,18 @@ int clif_check_packet_flood(int fd, int cmd)
}
// Default rate is 100ms
- if ((rate = clif_parse_func_table[cmd].rate) == 0)
- rate = 100;
+ interval_t rate = clif_parse_func_table[cmd].rate;
+ if (rate == interval_t::zero())
+ rate = std::chrono::milliseconds(100);
// ActionRequest - attacks are allowed a faster rate than sit/stand
if (cmd == 0x89)
{
int action_type = RFIFOB(fd, 6);
if (action_type == 0x00 || action_type == 0x07)
- rate = 20;
+ rate = std::chrono::milliseconds(20);
else
- rate = 1000;
+ rate = std::chrono::seconds(1);
}
// Restore this code when mana1.0 is released
@@ -5944,8 +5872,8 @@ void clif_parse(int fd)
return;
// パケット長を計算
- packet_len = packet_len_table[cmd];
- if (packet_len == -1)
+ packet_len = clif_parse_func_table[cmd].len;
+ if (packet_len == VAR)
{
if (RFIFOREST(fd) < 4)
{
diff --git a/src/map/clif.hpp b/src/map/clif.hpp
index dd061ad..df0a48b 100644
--- a/src/map/clif.hpp
+++ b/src/map/clif.hpp
@@ -6,6 +6,7 @@
#include <functional>
#include "../common/const_array.hpp"
+#include "../common/timer.t.hpp"
#include "battle.t.hpp"
#include "map.t.hpp"
@@ -26,7 +27,7 @@ int clif_charselectok(int);
int clif_dropflooritem(struct flooritem_data *);
int clif_clearflooritem(struct flooritem_data *, int);
int clif_clearchar(struct block_list *, BeingRemoveWhy); // area or fd
-int clif_clearchar_delay(unsigned int, struct block_list *, BeingRemoveWhy);
+int clif_clearchar_delay(tick_t, struct block_list *, BeingRemoveWhy);
int clif_clearchar_id(int, BeingRemoveWhy, int);
int clif_spawnpc(struct map_session_data *); //area
int clif_spawnnpc(struct npc_data *); // area
@@ -55,11 +56,13 @@ int clif_viewpoint(struct map_session_data *, int, int, int, int, int, int); //
int clif_additem(struct map_session_data *, int, int, PickupFail); //self
int clif_delitem(struct map_session_data *, int, int); //self
int clif_updatestatus(struct map_session_data *, SP); //self
-int clif_damage(struct block_list *, struct block_list *, unsigned int, int, int, int, int, DamageType, int); // area
+int clif_damage(struct block_list *, struct block_list *,
+ tick_t, interval_t, interval_t,
+ int, int, DamageType, int); // area
inline
int clif_takeitem(struct block_list *src, struct block_list *dst)
{
- return clif_damage(src, dst, 0, 0, 0, 0, 0, DamageType::TAKEITEM, 0);
+ return clif_damage(src, dst, tick_t(), interval_t::zero(), interval_t::zero(), 0, 0, DamageType::TAKEITEM, 0);
}
int clif_changelook(struct block_list *, LOOK, int); // area
void clif_changelook_accessories(struct block_list *bl, struct map_session_data *dst); // area or target; list gloves, boots etc.
@@ -113,7 +116,7 @@ int clif_skillcastcancel(struct block_list *bl);
int clif_skill_fail(struct map_session_data *sd, SkillID skill_id, int type,
int btype);
int clif_skill_damage(struct block_list *src, struct block_list *dst,
- unsigned int tick, int sdelay, int ddelay, int damage,
+ tick_t tick, interval_t sdelay, interval_t ddelay, int damage,
int div, SkillID skill_id, int skill_lv, int type);
int clif_status_change(struct block_list *bl,
diff --git a/src/map/magic-expr.cpp b/src/map/magic-expr.cpp
index 2858064..65dafe4 100644
--- a/src/map/magic-expr.cpp
+++ b/src/map/magic-expr.cpp
@@ -1052,7 +1052,7 @@ int fun_running_status_update(env_t *, int, val_t *result,
return 1;
StatusChange sc = StatusChange(ARGINT(1));
- RESULTINT = battle_get_sc_data(ARGENTITY(0))[sc].timer != -1;
+ RESULTINT = battle_get_sc_data(ARGENTITY(0))[sc].timer != nullptr;
return 0;
}
diff --git a/src/map/magic-interpreter-base.cpp b/src/map/magic-interpreter-base.cpp
index ac885c2..5c68d26 100644
--- a/src/map/magic-interpreter-base.cpp
+++ b/src/map/magic-interpreter-base.cpp
@@ -2,6 +2,7 @@
#include "magic-interpreter.hpp"
#include "../common/cxxstdio.hpp"
+#include "../common/timer.hpp"
#include "magic-expr.hpp"
@@ -281,7 +282,8 @@ void copy_components(component_t ** component_holder, component_t *component)
typedef struct spellguard_check
{
component_t *catalysts, *components;
- int mana, casttime;
+ int mana;
+ interval_t casttime;
} spellguard_check_t;
static
@@ -313,20 +315,10 @@ static
int spellguard_can_satisfy(spellguard_check_t *check, character_t *caster,
env_t *env, int *near_miss)
{
- unsigned int tick = gettick();
+ tick_t tick = gettick();
int retval = check_prerequisites(caster, check->catalysts);
-/*
- FPRINTF(stderr, "MC(%d/%s)? %d%d%d%d (%u <= %u)\n",
- caster->bl.id, caster->status.name,
- retval,
- caster->cast_tick <= tick,
- check->mana <= caster->status.sp,
- check_prerequisites(caster, check->components),
- caster->cast_tick, tick);
-*/
-
if (retval && near_miss)
*near_miss = 1; // close enough!
@@ -336,10 +328,10 @@ int spellguard_can_satisfy(spellguard_check_t *check, character_t *caster,
if (retval)
{
- unsigned int casttime = (unsigned int) check->casttime;
+ interval_t casttime = check->casttime;
if (VAR(VAR_MIN_CASTTIME).ty == TYPE::INT)
- casttime = max(casttime, VAR(VAR_MIN_CASTTIME).v.v_int);
+ casttime = max(casttime, static_cast<interval_t>(VAR(VAR_MIN_CASTTIME).v.v_int));
caster->cast_tick = tick + casttime; /* Make sure not to cast too frequently */
@@ -402,7 +394,7 @@ effect_set_t *spellguard_check_sub(spellguard_check_t *check,
break;
case SPELLGUARD::CASTTIME:
- check->casttime += magic_eval_int(env, guard->s.s_mana);
+ check->casttime += static_cast<interval_t>(magic_eval_int(env, guard->s.s_mana));
break;
case SPELLGUARD::EFFECT:
@@ -429,7 +421,8 @@ effect_set_t *check_spellguard(spellguard_t *guard,
effect_set_t *retval;
check.catalysts = NULL;
check.components = NULL;
- check.mana = check.casttime = 0;
+ check.mana = 0;
+ check.casttime = interval_t::zero();
retval = spellguard_check_sub(&check, guard, caster, env, near_miss);
diff --git a/src/map/magic-interpreter.hpp b/src/map/magic-interpreter.hpp
index 35377bc..77197f0 100644
--- a/src/map/magic-interpreter.hpp
+++ b/src/map/magic-interpreter.hpp
@@ -320,7 +320,7 @@ typedef struct invocation
int caster; /* this is the person who originally invoked the spell */
int subject; /* when this person dies, the spell dies with it */
- int timer; /* spell timer, if any */
+ TimerData *timer; /* spell timer, if any */
int stack_size;
cont_activation_record_t stack[MAX_STACK_SIZE];
diff --git a/src/map/magic-stmt.cpp b/src/map/magic-stmt.cpp
index 2061e71..fdb95fc 100644
--- a/src/map/magic-stmt.cpp
+++ b/src/map/magic-stmt.cpp
@@ -1,4 +1,8 @@
+#include <cassert>
+
#include "../common/cxxstdio.hpp"
+#include "../common/mt_rand.hpp"
+#include "../common/timer.hpp"
#include "magic-expr.hpp"
#include "magic-expr-eval.hpp"
@@ -76,7 +80,7 @@ void clear_activation_record(cont_activation_record_t *ar)
}
static
-void invocation_timer_callback(timer_id, tick_t, custom_id_t id, custom_data_t)
+void invocation_timer_callback(TimerData *, tick_t, int id)
{
invocation_t *invocation = (invocation_t *) map_id2bl(id);
@@ -118,7 +122,7 @@ void spell_free_invocation(invocation_t *invocation)
clear_stack(invocation);
if (invocation->timer)
- delete_timer(invocation->timer, invocation_timer_callback);
+ delete_timer(invocation->timer);
magic_free_env(invocation->env);
@@ -154,12 +158,12 @@ void char_set_weapon_icon(character_t *subject, int count,
}
static
-void char_set_attack_info(character_t *subject, int speed, int range)
+void char_set_attack_info(character_t *subject, interval_t speed, int range)
{
subject->attack_spell_delay = speed;
subject->attack_spell_range = range;
- if (speed == 0)
+ if (speed == interval_t::zero())
{
pc_calcstatus(subject, 1);
clif_updatestatus(subject, SP::ASPD);
@@ -190,7 +194,7 @@ void magic_stop_completely(character_t *c)
spell_free_invocation(attack_spell);
c->attack_spell_override = 0;
char_set_weapon_icon(c, 0, StatusChange::ZERO, 0);
- char_set_attack_info(c, 0, 0);
+ char_set_attack_info(c, interval_t::zero(), 0);
}
}
@@ -241,7 +245,7 @@ void char_update(character_t *character)
}
static
-void timer_callback_effect(timer_id, tick_t, custom_id_t id, custom_data_t data)
+void timer_callback_effect(TimerData *, tick_t, int id, int data)
{
entity_t *target = map_id2bl(id);
if (target)
@@ -249,10 +253,11 @@ void timer_callback_effect(timer_id, tick_t, custom_id_t id, custom_data_t data)
}
static
-void entity_effect(entity_t *entity, int effect_nr, int delay)
+void entity_effect(entity_t *entity, int effect_nr, interval_t delay)
{
add_timer(gettick() + delay,
- &timer_callback_effect, entity->id, effect_nr);
+ std::bind(&timer_callback_effect, ph::_1, ph::_2,
+ entity->id, effect_nr));
}
void magic_unshroud(character_t *other_char)
@@ -265,8 +270,7 @@ void magic_unshroud(character_t *other_char)
}
static
-void timer_callback_effect_npc_delete(timer_id, tick_t,
- custom_id_t npc_id, custom_data_t)
+void timer_callback_effect_npc_delete(TimerData *, tick_t, int npc_id)
{
struct npc_data *effect_npc = (struct npc_data *) map_id2bl(npc_id);
npc_free(effect_npc);
@@ -274,16 +278,18 @@ void timer_callback_effect_npc_delete(timer_id, tick_t,
static
struct npc_data *local_spell_effect(int m, int x, int y, int effect,
- int tdelay)
+ interval_t tdelay)
{
- int delay = 30000; /* 1 minute should be enough for all interesting spell effects, I hope */
+ /* 1 minute should be enough for all interesting spell effects, I hope */
+ std::chrono::seconds delay = std::chrono::seconds(30);
struct npc_data *effect_npc = npc_spawn_text(m, x, y,
- INVISIBLE_NPC, "", "?");
+ INVISIBLE_NPC, "", "?");
int effect_npc_id = effect_npc->bl.id;
entity_effect(&effect_npc->bl, effect, tdelay);
add_timer(gettick() + delay,
- timer_callback_effect_npc_delete, effect_npc_id, 0);
+ std::bind(timer_callback_effect_npc_delete, ph::_1, ph::_2,
+ effect_npc_id));
return effect_npc;
}
@@ -291,7 +297,7 @@ struct npc_data *local_spell_effect(int m, int x, int y, int effect,
static
int op_sfx(env_t *, int, val_t *args)
{
- int delay = ARGINT(2);
+ interval_t delay = static_cast<interval_t>(ARGINT(2));
if (ARG_TYPE(0) == TYPE::ENTITY)
{
@@ -402,8 +408,7 @@ int op_message(env_t *, int, val_t *args)
}
static
-void timer_callback_kill_npc(timer_id, tick_t, custom_id_t npc_id,
- custom_data_t)
+void timer_callback_kill_npc(TimerData *, tick_t, int npc_id)
{
struct npc_data *npc = (struct npc_data *) map_id2bl(npc_id);
if (npc)
@@ -417,10 +422,11 @@ int op_messenger_npc(env_t *, int, val_t *args)
location_t *loc = &ARGLOCATION(0);
npc = npc_spawn_text(loc->m, loc->x, loc->y,
- ARGINT(1), ARGSTR(2), ARGSTR(3));
+ ARGINT(1), ARGSTR(2), ARGSTR(3));
- add_timer(gettick() + ARGINT(4),
- &timer_callback_kill_npc, npc->bl.id, 0);
+ add_timer(gettick() + static_cast<interval_t>(ARGINT(4)),
+ std::bind(timer_callback_kill_npc, ph::_1, ph::_2,
+ npc->bl.id));
return 0;
}
@@ -530,9 +536,12 @@ int op_status_change(env_t *env, int, val_t *args)
? VAR(VAR_INVOCATION).v.v_int : 0;
invocation_t *invocation = (invocation_t *) map_id2bl(invocation_id);
- skill_status_effect(subject, StatusChange(ARGINT(1)),
- ARGINT(2), ARGINT(3), ARGINT(4), ARGINT(5),
- ARGINT(6), 0, invocation_id);
+ assert (!ARGINT(3));
+ assert (!ARGINT(4));
+ assert (!ARGINT(5));
+ skill_status_effect(subject, static_cast<StatusChange>(ARGINT(1)),
+ ARGINT(2),
+ static_cast<interval_t>(ARGINT(6)), invocation_id);
if (invocation && subject->type == BL::PC)
record_status_change(invocation, subject->id, StatusChange(ARGINT(1)));
@@ -545,8 +554,8 @@ int op_stop_status_change(env_t *, int, val_t *args)
{
entity_t *subject = ARGENTITY(0);
- StatusChange sc = StatusChange(ARGINT(1));
- skill_status_change_end(subject, sc, -1);
+ StatusChange sc = static_cast<StatusChange>(ARGINT(1));
+ skill_status_change_end(subject, sc, nullptr);
return 0;
}
@@ -556,7 +565,7 @@ int op_override_attack(env_t *env, int, val_t *args)
{
entity_t *psubject = ARGENTITY(0);
int charges = ARGINT(1);
- int attack_delay = ARGINT(2);
+ interval_t attack_delay = static_cast<interval_t>(ARGINT(2));
int attack_range = ARGINT(3);
StatusChange icon = StatusChange(ARGINT(4));
int look = ARGINT(5);
@@ -675,7 +684,7 @@ int op_spawn(env_t *, int, val_t *args)
int monster_id = ARGINT(2);
MonsterAttitude monster_attitude = static_cast<MonsterAttitude>(ARGINT(3));
int monster_count = ARGINT(4);
- int monster_lifetime = ARGINT(5);
+ interval_t monster_lifetime = static_cast<interval_t>(ARGINT(5));
int i;
character_t *owner = NULL;
@@ -729,7 +738,8 @@ int op_spawn(env_t *, int, val_t *args)
MobMode::SUMMONED | MobMode::TURNS_AGAINST_BAD_MASTER;
mob->deletetimer = add_timer(gettick() + monster_lifetime,
- mob_timer_delete, mob_id, 0);
+ std::bind(mob_timer_delete, ph::_1, ph::_2,
+ mob_id));
if (owner)
{
@@ -783,7 +793,9 @@ int op_injure(env_t *env, int, val_t *args)
damage_caused = 0;
// display damage first, because dealing damage may deallocate the target.
- clif_damage(caster, target, gettick(), 0, 0, damage_caused, 0, DamageType::NORMAL, 0);
+ clif_damage(caster, target,
+ gettick(), interval_t::zero(), interval_t::zero(),
+ damage_caused, 0, DamageType::NORMAL, 0);
if (caster->type == BL::PC)
{
@@ -858,21 +870,21 @@ int op_drop_item_for (env_t *, int args_nr, val_t *args)
int stackable;
location_t *loc = &ARGLOCATION(0);
int count = ARGINT(2);
- int time = ARGINT(3);
+ interval_t time = static_cast<interval_t>(ARGINT(3));
character_t *c = ((args_nr > 4) && (ENTITY_TYPE(4) == BL::PC)) ? ARGPC(4) : NULL;
- int delay = (args_nr > 5) ? ARGINT(5) : 0;
- int delaytime[3] = { delay, delay, delay };
+ interval_t delay = (args_nr > 5) ? static_cast<interval_t>(ARGINT(5)) : interval_t::zero();
+ interval_t delaytime[3] = { delay, delay, delay };
character_t *owners[3] = { c, NULL, NULL };
GET_ARG_ITEM(1, item, stackable);
if (stackable)
map_addflooritem_any(&item, count, loc->m, loc->x, loc->y,
- owners, delaytime, time, 0);
+ owners, delaytime, time, 0);
else
while (count-- > 0)
map_addflooritem_any(&item, 1, loc->m, loc->x, loc->y,
- owners, delaytime, time, 0);
+ owners, delaytime, time, 0);
return 0;
}
@@ -1245,7 +1257,7 @@ effect_t *run_foreach(invocation_t *invocation, effect_t *foreach,
for (i = entities_nr - 1; i >= 0; i--)
{
- int random_index = rand() % (i + 1);
+ int random_index = MRAND(i + 1);
entities[i] = entities_collect[shuffle_board[random_index]];
shuffle_board[random_index] = shuffle_board[i]; // thus, we are guaranteed only to use unused indices
}
@@ -1407,10 +1419,10 @@ void print_cfg(int i, effect_t *e)
* -1 if we paused to wait for a user action (via script interaction)
*/
static
-int spell_run(invocation_t *invocation, int allow_delete)
+interval_t spell_run(invocation_t *invocation, int allow_delete)
{
const int invocation_id = invocation->bl.id;
-#define REFRESH_INVOCATION invocation = (invocation_t *) map_id2bl(invocation_id); if (!invocation) return 0;
+#define REFRESH_INVOCATION invocation = (invocation_t *) map_id2bl(invocation_id); if (!invocation) return interval_t::zero();
#ifdef DEBUG
FPRINTF(stderr, "Resuming execution: invocation of `%s'\n",
@@ -1465,10 +1477,10 @@ int spell_run(invocation_t *invocation, int allow_delete)
case EFFECT::SLEEP:
{
- int sleeptime =
- magic_eval_int(invocation->env, e->e.e_sleep);
+ interval_t sleeptime = static_cast<interval_t>(
+ magic_eval_int(invocation->env, e->e.e_sleep));
invocation->current_effect = next;
- if (sleeptime > 0)
+ if (sleeptime > interval_t::zero())
return sleeptime;
break;
}
@@ -1517,7 +1529,7 @@ int spell_run(invocation_t *invocation, int allow_delete)
/* Must set up for continuation */
recipient->npc_id = invocation->bl.id;
recipient->npc_pos = invocation->script_pos = newpos;
- return -1; /* Signal `wait for script' */
+ return static_cast<interval_t>(-1); /* Signal `wait for script' */
}
else
invocation->script_pos = 0;
@@ -1570,30 +1582,22 @@ int spell_run(invocation_t *invocation, int allow_delete)
if (allow_delete)
try_to_finish_invocation(invocation);
- return 0;
+ return interval_t::zero();
#undef REFRESH_INVOCATION
}
static
void spell_execute_d(invocation_t *invocation, int allow_deletion)
{
- int delta;
-
spell_update_location(invocation);
- delta = spell_run(invocation, allow_deletion);
+ interval_t delta = spell_run(invocation, allow_deletion);
- if (delta > 0)
+ if (delta > interval_t::zero())
{
- if (invocation->timer)
- {
- FPRINTF(stderr,
- "[magic] FATAL ERROR: Trying to add multiple timers to the same spell! Already had timer: %d\n",
- invocation->timer);
- /* *((int *)0x0) = 0; */
- }
+ assert (invocation->timer == nullptr);
invocation->timer = add_timer(gettick() + delta,
- &invocation_timer_callback,
- invocation->bl.id, 0);
+ std::bind(invocation_timer_callback, ph::_1, ph::_2,
+ invocation->bl.id));
}
/* If 0, the script cleaned itself. If -1(wait-for-script), we must wait for the user. */
@@ -1656,7 +1660,7 @@ int spell_attack(int caster_id, int target_id)
{
caster->attack_spell_override = 0;
char_set_weapon_icon(caster, 0, StatusChange::ZERO, 0);
- char_set_attack_info(caster, 0, 0);
+ char_set_attack_info(caster, interval_t::zero(), 0);
if (stop_attack)
pc_stopattack(caster);
diff --git a/src/map/map.cpp b/src/map/map.cpp
index aae2e44..7e2bf13 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -16,6 +16,7 @@
#include "../common/mt_rand.hpp"
#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
+#include "../common/timer.hpp"
#include "atcommand.hpp"
#include "battle.hpp"
@@ -70,9 +71,8 @@ int map_num = 0;
static
int map_port = 0;
-int autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
+interval_t autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
int save_settings = 0xFFFF;
-int night_flag = 0; // 0=day, 1=night [Yor]
struct charid2nick
{
@@ -176,14 +176,9 @@ int map_freeblock_unlock(void)
return block_free_lock;
}
-//
-// block化処理
-//
-/*==========================================
- * map[]のblock_listから繋がっている場合に
- * bl->prevにbl_headのアドレスを入れておく
- *------------------------------------------
- */
+/// This is a dummy entry that is shared by all the linked lists,
+/// so that any entry can unlink itself without worrying about
+/// whether it was the the head of the list.
static
struct block_list bl_head;
@@ -755,20 +750,20 @@ void map_foreachobject(std::function<void(struct block_list *)> func,
* map.h内で#defineしてある
*------------------------------------------
*/
-void map_clearflooritem_timer(timer_id tid, tick_t, custom_id_t id, custom_data_t data)
+void map_clearflooritem_timer(TimerData *tid, tick_t, int id)
{
struct flooritem_data *fitem = NULL;
fitem = (struct flooritem_data *) object[id];
if (fitem == NULL || fitem->bl.type != BL::ITEM
- || (!data && fitem->cleartimer != tid))
+ || (tid && fitem->cleartimer != tid))
{
if (battle_config.error_log)
PRINTF("map_clearflooritem_timer : error\n");
return;
}
- if (data)
- delete_timer(fitem->cleartimer, map_clearflooritem_timer);
+ if (!tid)
+ delete_timer(fitem->cleartimer);
clif_clearflooritem(fitem, 0);
map_delobject(fitem->bl.id, BL::ITEM);
}
@@ -831,12 +826,12 @@ int map_searchrandfreecell(int m, int x, int y, int range)
* item_dataはamount以外をcopyする
*------------------------------------------
*/
-int map_addflooritem_any(struct item *item_data, int amount, int m, int x,
- int y, struct map_session_data **owners,
- int *owner_protection, int lifetime, int dispersal)
+int map_addflooritem_any(struct item *item_data, int amount,
+ int m, int x, int y,
+ struct map_session_data **owners, interval_t *owner_protection,
+ interval_t lifetime, int dispersal)
{
int xy, r;
- unsigned int tick;
struct flooritem_data *fitem = NULL;
nullpo_ret(item_data);
@@ -852,11 +847,11 @@ int map_addflooritem_any(struct item *item_data, int amount, int m, int x,
fitem->bl.x = xy & 0xffff;
fitem->bl.y = (xy >> 16) & 0xffff;
fitem->first_get_id = 0;
- fitem->first_get_tick = 0;
+ fitem->first_get_tick = tick_t();
fitem->second_get_id = 0;
- fitem->second_get_tick = 0;
+ fitem->second_get_tick = tick_t();
fitem->third_get_id = 0;
- fitem->third_get_tick = 0;
+ fitem->third_get_tick = tick_t();
fitem->bl.id = map_addobject(&fitem->bl);
if (fitem->bl.id == 0)
@@ -865,7 +860,7 @@ int map_addflooritem_any(struct item *item_data, int amount, int m, int x,
return 0;
}
- tick = gettick();
+ tick_t tick = gettick();
if (owners[0])
fitem->first_get_id = owners[0]->bl.id;
@@ -883,9 +878,9 @@ int map_addflooritem_any(struct item *item_data, int amount, int m, int x,
fitem->item_data.amount = amount;
fitem->subx = (r & 3) * 3 + 3;
fitem->suby = ((r >> 2) & 3) * 3 + 3;
- fitem->cleartimer =
- add_timer(gettick() + lifetime, map_clearflooritem_timer,
- fitem->bl.id, 0);
+ fitem->cleartimer = add_timer(gettick() + lifetime,
+ std::bind(map_clearflooritem_timer, ph::_1, ph::_2,
+ fitem->bl.id));
map_addblock(&fitem->bl);
clif_dropflooritem(fitem);
@@ -893,100 +888,33 @@ int map_addflooritem_any(struct item *item_data, int amount, int m, int x,
return fitem->bl.id;
}
-int map_addflooritem(struct item *item_data, int amount, int m, int x, int y,
- struct map_session_data *first_sd,
- struct map_session_data *second_sd,
- struct map_session_data *third_sd, int type)
+int map_addflooritem(struct item *item_data, int amount,
+ int m, int x, int y,
+ struct map_session_data *first_sd,
+ struct map_session_data *second_sd,
+ struct map_session_data *third_sd, bool type)
{
struct map_session_data *owners[3] = { first_sd, second_sd, third_sd };
- int owner_protection[3];
+ interval_t owner_protection[3];
if (type)
{
- owner_protection[0] = battle_config.mvp_item_first_get_time;
- owner_protection[1] =
- owner_protection[0] + battle_config.mvp_item_second_get_time;
- owner_protection[2] =
- owner_protection[1] + battle_config.mvp_item_third_get_time;
+ owner_protection[0] = static_cast<interval_t>(battle_config.mvp_item_first_get_time);
+ owner_protection[1] = owner_protection[0] + static_cast<interval_t>(battle_config.mvp_item_second_get_time);
+ owner_protection[2] = owner_protection[1] + static_cast<interval_t>(battle_config.mvp_item_third_get_time);
}
else
{
- owner_protection[0] = battle_config.item_first_get_time;
- owner_protection[1] =
- owner_protection[0] + battle_config.item_second_get_time;
- owner_protection[2] =
- owner_protection[1] + battle_config.item_third_get_time;
+ owner_protection[0] = static_cast<interval_t>(battle_config.item_first_get_time);
+ owner_protection[1] = owner_protection[0] + static_cast<interval_t>(battle_config.item_second_get_time);
+ owner_protection[2] = owner_protection[1] + static_cast<interval_t>(battle_config.item_third_get_time);
}
return map_addflooritem_any(item_data, amount, m, x, y,
- owners, owner_protection,
- battle_config.flooritem_lifetime, 1);
+ owners, owner_protection,
+ static_cast<interval_t>(battle_config.flooritem_lifetime), 1);
}
-/* int xy,r; */
-/* unsigned int tick; */
-/* struct flooritem_data *fitem=NULL; */
-
-/* nullpo_ret(item_data); */
-
-/* if ((xy=map_searchrandfreecell(m,x,y,1))<0) */
-/* return 0; */
-/* r=rand(); */
-
-/* fitem = (struct flooritem_data *)aCalloc(1,sizeof(*fitem)); */
-/* fitem->bl.type=BL::ITEM; */
-/* fitem->bl.prev = fitem->bl.next = NULL; */
-/* fitem->bl.m=m; */
-/* fitem->bl.x=xy&0xffff; */
-/* fitem->bl.y= (xy>>16)&0xffff; */
-/* fitem->first_get_id = 0; */
-/* fitem->first_get_tick = 0; */
-/* fitem->second_get_id = 0; */
-/* fitem->second_get_tick = 0; */
-/* fitem->third_get_id = 0; */
-/* fitem->third_get_tick = 0; */
-
-/* fitem->bl.id = map_addobject(&fitem->bl); */
-/* if (fitem->bl.id==0){ */
-/* free(fitem); */
-/* return 0; */
-/* } */
-
-/* tick = gettick(); */
-/* if (first_sd) { */
-/* fitem->first_get_id = first_sd->bl.id; */
-/* if (type) */
-/* fitem->first_get_tick = tick + battle_config.mvp_item_first_get_time; */
-/* else */
-/* fitem->first_get_tick = tick + battle_config.item_first_get_time; */
-/* } */
-/* if (second_sd) { */
-/* fitem->second_get_id = second_sd->bl.id; */
-/* if (type) */
-/* fitem->second_get_tick = tick + battle_config.mvp_item_first_get_time + battle_config.mvp_item_second_get_time; */
-/* else */
-/* fitem->second_get_tick = tick + battle_config.item_first_get_time + battle_config.item_second_get_time; */
-/* } */
-/* if (third_sd) { */
-/* fitem->third_get_id = third_sd->bl.id; */
-/* if (type) */
-/* fitem->third_get_tick = tick + battle_config.mvp_item_first_get_time + battle_config.mvp_item_second_get_time + battle_config.mvp_item_third_get_time; */
-/* else */
-/* fitem->third_get_tick = tick + battle_config.item_first_get_time + battle_config.item_second_get_time + battle_config.item_third_get_time; */
-/* } */
-
-/* memcpy(&fitem->item_data,item_data,sizeof(*item_data)); */
-/* fitem->item_data.amount=amount; */
-/* fitem->subx= (r&3)*3+3; */
-/* fitem->suby= ((r>>2)&3)*3+3; */
-/* fitem->cleartimer=add_timer(gettick()+battle_config.flooritem_lifetime,map_clearflooritem_timer,fitem->bl.id,0); */
-
-/* map_addblock(&fitem->bl); */
-/* clif_dropflooritem(fitem); */
-
-/* return fitem->bl.id; */
-/* } */
-
/*==========================================
* charid_dbへ追加(返信待ちがあれば返信)
*------------------------------------------
@@ -1087,7 +1015,6 @@ int map_quit(struct map_session_data *sd)
pc_stop_walking(sd, 0);
pc_stopattack(sd);
pc_delinvincibletimer(sd);
- pc_delspiritball(sd, sd->spiritball, 1);
skill_gangsterparadise(sd, 0);
pc_calcstatus(sd, 4);
@@ -1866,8 +1793,8 @@ int map_config_read(const char *cfgName)
}
else if (w1 == "autosave_time")
{
- autosave_interval = atoi(w2.c_str()) * 1000;
- if (autosave_interval <= 0)
+ autosave_interval = std::chrono::seconds(atoi(w2.c_str()));
+ if (autosave_interval <= interval_t::zero())
autosave_interval = DEFAULT_AUTOSAVE_INTERVAL;
}
else if (w1 == "motd_txt")
@@ -2027,8 +1954,6 @@ int do_init(int argc, char *argv[])
map_readallmap();
-// add_timer_func_list (map_clearflooritem_timer, "map_clearflooritem_timer");
-
do_init_chrif ();
do_init_clif ();
do_init_itemdb();
diff --git a/src/map/map.hpp b/src/map/map.hpp
index 9d033f4..2af7ec8 100644
--- a/src/map/map.hpp
+++ b/src/map/map.hpp
@@ -8,7 +8,7 @@
#include <functional>
#include "../common/db.hpp"
-#include "../common/timer.hpp"
+#include "../common/timer.t.hpp"
#include "battle.t.hpp"
#include "magic-interpreter.t.hpp"
@@ -19,20 +19,20 @@
constexpr int MAX_NPC_PER_MAP = 512;
constexpr int BLOCK_SIZE = 8;
#define AREA_SIZE battle_config.area_size
-constexpr int LIFETIME_FLOORITEM = 60;
+constexpr std::chrono::seconds LIFETIME_FLOORITEM = std::chrono::minutes(1);
constexpr int DAMAGELOG_SIZE = 30;
constexpr int LOOTITEM_SIZE = 10;
constexpr int MAX_SKILL_LEVEL = 100;
constexpr int MAX_MOBSKILL = 32;
constexpr int MAX_EVENTQUEUE = 2;
constexpr int MAX_EVENTTIMER = 32;
-constexpr int NATURAL_HEAL_INTERVAL = 500;
+constexpr interval_t NATURAL_HEAL_INTERVAL = std::chrono::milliseconds(500);
constexpr int MAX_FLOORITEM = 500000;
constexpr int MAX_LEVEL = 255;
constexpr int MAX_WALKPATH = 48;
constexpr int MAX_DROP_PER_MAP = 48;
-constexpr int DEFAULT_AUTOSAVE_INTERVAL = 60 * 1000;
+constexpr interval_t DEFAULT_AUTOSAVE_INTERVAL = std::chrono::minutes(1);
struct block_list
{
@@ -60,10 +60,8 @@ struct script_regstr
};
struct status_change
{
- int timer;
- int val1, val2, val3, val4;
- SkillID val1_sk() { return SkillID(val1); }
- BCT& val1_bct() { return reinterpret_cast<BCT&>(val1); }
+ TimerData *timer;
+ int val1;
int spell_invocation; /* [Fate] If triggered by a spell, record here */
};
@@ -124,14 +122,14 @@ struct map_session_data
char mapname[24];
int fd, new_fd;
short to_x, to_y;
- short speed, prev_speed;
+ interval_t speed;
Opt1 opt1;
Opt2 opt2;
Opt3 opt3;
DIR dir, head_dir;
- unsigned int client_tick, server_tick;
+ tick_t client_tick, server_tick;
struct walkpath_data walkpath;
- int walktimer;
+ TimerData *walktimer;
int npc_id, areanpc_id, npc_shopid;
int npc_pos;
int npc_menu;
@@ -147,15 +145,15 @@ struct map_session_data
} npc_flags;
unsigned int chatID;
- int attacktimer;
+ TimerData *attacktimer;
int attacktarget;
ATK attacktarget_lv;
- unsigned int attackabletime;
+ tick_t attackabletime;
- int followtimer; // [MouseJstr]
+ // used by @hugo and @linus
int followtarget;
- unsigned int cast_tick; // [Fate] Next tick at which spellcasting is allowed
+ tick_t cast_tick; // [Fate] Next tick at which spellcasting is allowed
struct invocation *active_spells; // [Fate] Singly-linked list of active spells linked to this PC
int attack_spell_override; // [Fate] When an attack spell is active for this player, they trigger it
// like a weapon. Check pc_attack_timer() for details.
@@ -163,7 +161,7 @@ struct map_session_data
StatusChange attack_spell_icon_override;
short attack_spell_look_override; // Weapon `look' (attack animation) override
short attack_spell_charges; // [Fate] Remaining number of charges for the attack spell
- short attack_spell_delay; // [Fate] ms delay after spell attack
+ interval_t attack_spell_delay; // [Fate] ms delay after spell attack
short attack_spell_range; // [Fate] spell range
short spellpower_bonus_target, spellpower_bonus_current; // [Fate] Spellpower boni. _current is the active one.
//_current slowly approximates _target, and _target is determined by equipment.
@@ -175,19 +173,17 @@ struct map_session_data
// [Fate] XP that can be extracted from this player by healing
int heal_xp; // i.e., OTHER players (healers) can partake in this player's XP
- int invincible_timer;
- unsigned int canact_tick;
- unsigned int canmove_tick;
- unsigned int canlog_tick;
- int hp_sub, sp_sub;
- int inchealhptick, inchealsptick, inchealspirithptick,
- inchealspiritsptick;
-// -- moonsoul (new tick for berserk self-damage)
- int berserkdamagetick;
+ TimerData *invincible_timer;
+ tick_t canact_tick;
+ tick_t canmove_tick;
+ tick_t canlog_tick;
+ interval_t hp_sub, sp_sub;
+ interval_t inchealhptick, inchealsptick;
short weapontype1, weapontype2;
earray<int, ATTR, ATTR::COUNT> paramb, paramc, parame, paramcard;
- int hit, flee, flee2, aspd, amotion, dmotion;
+ int hit, flee, flee2;
+ interval_t aspd, amotion, dmotion;
int watk, watk2;
int def, def2, mdef, mdef2, critical, matk1, matk2;
int star, overrefine;
@@ -210,11 +206,7 @@ struct map_session_data
short break_weapon_rate, break_armor_rate;
short add_steal_rate;
- short spiritball, spiritball_old;
- int spirit_timer[MAX_SKILL_LEVEL];
-
int die_counter;
- short doridori_counter;
int reg_num;
struct script_reg *reg;
@@ -240,10 +232,12 @@ struct map_session_data
int catch_target_class;
- int pvp_point, pvp_rank, pvp_timer, pvp_lastusers;
+ int pvp_point, pvp_rank;
+ TimerData *pvp_timer;
+ int pvp_lastusers;
char eventqueue[MAX_EVENTQUEUE][50];
- int eventtimer[MAX_EVENTTIMER];
+ TimerData *eventtimer[MAX_EVENTTIMER];
struct
{
@@ -263,7 +257,7 @@ struct map_session_data
int chat_total_repeats;
char chat_lastmsg[513];
- unsigned int flood_rates[0x220];
+ tick_t flood_rates[0x220];
time_t packet_flood_reset_due;
int packet_flood_in;
@@ -272,7 +266,8 @@ struct map_session_data
struct npc_timerevent_list
{
- int timer, pos;
+ interval_t timer;
+ int pos;
};
struct npc_label_list
{
@@ -289,7 +284,7 @@ struct npc_data
short n;
short npc_class;
DIR dir;
- short speed;
+ interval_t speed;
char name[24];
char exname[24];
int chat_id;
@@ -304,8 +299,10 @@ struct npc_data
{
const ScriptCode *script;
short xs, ys;
- int timer, timerid, timeramount, nexttimer;
- unsigned int timertick;
+ interval_t timer;
+ TimerData *timerid;
+ int timeramount, nexttimer;
+ tick_t timertick;
struct npc_timerevent_list *timer_event;
int label_list_num;
struct npc_label_list *label_list;
@@ -323,7 +320,7 @@ struct npc_data
// ここにメンバを追加してはならない(shop_itemが可変長の為)
char eventqueue[MAX_EVENTQUEUE][50];
- int eventtimer[MAX_EVENTTIMER];
+ TimerData *eventtimer[MAX_EVENTTIMER];
short arenaflag;
};
@@ -339,7 +336,7 @@ struct mob_data
MobMode mode;
short m, x0, y0, xs, ys;
char name[24];
- int spawndelay1, spawndelay2;
+ interval_t spawndelay1, spawndelay2;
struct
{
MS state;
@@ -353,16 +350,16 @@ struct mob_data
unsigned walk_easy:1;
unsigned special_mob_ai:3;
} state;
- int timer;
+ TimerData *timer;
short to_x, to_y;
int hp;
int target_id, attacked_id;
ATK target_lv;
struct walkpath_data walkpath;
- unsigned int next_walktime;
- unsigned int attackabletime;
- unsigned int last_deadtime, last_spawntime, last_thinktime;
- unsigned int canmove_tick;
+ tick_t next_walktime;
+ tick_t attackabletime;
+ tick_t last_deadtime, last_spawntime, last_thinktime;
+ tick_t canmove_tick;
short move_fail_count;
struct
{
@@ -380,14 +377,14 @@ struct mob_data
Option option;
short min_chase;
short sg_count;
- int deletetimer;
+ TimerData *deletetimer;
- int skilltimer;
+ TimerData *skilltimer;
int skilltarget;
short skillx, skilly;
SkillID skillid;
short skilllv, skillidx;
- unsigned int skilldelay[MAX_MOBSKILL];
+ tick_t skilldelay[MAX_MOBSKILL];
LevelElement def_ele;
int master_id, master_dist;
int exclusion_src, exclusion_party;
@@ -473,9 +470,9 @@ struct flooritem_data
{
struct block_list bl;
short subx, suby;
- int cleartimer;
+ TimerData *cleartimer;
int first_get_id, second_get_id, third_get_id;
- unsigned int first_get_tick, second_get_tick, third_get_tick;
+ tick_t first_get_tick, second_get_tick, third_get_tick;
struct item item_data;
};
@@ -495,9 +492,8 @@ struct chat_data
char npc_event[50];
};
-extern int autosave_interval;
+extern interval_t autosave_interval;
extern int save_settings;
-extern int night_flag; // 0=day, 1=night [Yor]
extern char motd_txt[];
extern char help_txt[];
@@ -550,18 +546,18 @@ void map_log(const_string line);
sd->status.char_id, sd->bl.m, sd->bl.x, sd->bl.y, ## __VA_ARGS__)
// 床アイテム関連
-void map_clearflooritem_timer(timer_id, tick_t, custom_id_t, custom_data_t);
+void map_clearflooritem_timer(TimerData *, tick_t, int);
inline
-void map_clearflooritem(custom_id_t id)
+void map_clearflooritem(int id)
{
- map_clearflooritem_timer(0, 0, id, 1);
+ map_clearflooritem_timer(nullptr, tick_t(), id);
}
int map_addflooritem_any(struct item *, int amount, int m, int x, int y,
- struct map_session_data **owners, int *owner_protection,
- int lifetime, int dispersal);
+ struct map_session_data **owners, interval_t *owner_protection,
+ interval_t lifetime, int dispersal);
int map_addflooritem(struct item *, int, int, int, int,
struct map_session_data *, struct map_session_data *,
- struct map_session_data *, int);
+ struct map_session_data *, bool);
// キャラid=>キャラ名 変換関連
void map_addchariddb(int charid, const char *name);
diff --git a/src/map/map.t.hpp b/src/map/map.t.hpp
index 6b53015..e6417eb 100644
--- a/src/map/map.t.hpp
+++ b/src/map/map.t.hpp
@@ -114,7 +114,6 @@ enum class MS : uint8_t
WALK,
ATTACK,
DEAD,
- DELAY,
};
enum class ATK
diff --git a/src/map/mob.cpp b/src/map/mob.cpp
index b8339e4..20bf1ec 100644
--- a/src/map/mob.cpp
+++ b/src/map/mob.cpp
@@ -1,13 +1,17 @@
#include "mob.hpp"
+#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
+#include <algorithm>
+
#include "../common/cxxstdio.hpp"
#include "../common/mt_rand.hpp"
#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
+#include "../common/timer.hpp"
#include "battle.hpp"
#include "clif.hpp"
@@ -20,7 +24,7 @@
#include "../poison.hpp"
-constexpr int MIN_MOBTHINKTIME = 100;
+constexpr interval_t MIN_MOBTHINKTIME = std::chrono::milliseconds(100);
// Move probability in the negligent mode MOB (rate of 1000 minute)
constexpr int MOB_LAZYMOVEPERC = 50;
@@ -38,12 +42,10 @@ int distance(int, int, int, int);
static
int mob_makedummymobdb(int);
static
-void mob_timer(timer_id, tick_t, custom_id_t, custom_data_t);
+void mob_timer(TimerData *, tick_t, int, unsigned char);
static
int mobskill_use_id(struct mob_data *md, struct block_list *target,
- int skill_idx);
-static
-int mob_unlocktarget(struct mob_data *md, int tick);
+ int skill_idx);
/*==========================================
* Mob is searched with a name.
@@ -104,7 +106,7 @@ int mob_spawn_dataset(struct mob_data *md, const char *mobname, int mob_class)
md->bl.id = npc_get_new_npc_id();
memset(&md->state, 0, sizeof(md->state));
- md->timer = -1;
+ md->timer = nullptr;
md->target_id = 0;
md->attacked_id = 0;
@@ -429,8 +431,8 @@ int mob_once_spawn(struct map_session_data *sd, const char *mapname,
md->y0 = y;
md->xs = 0;
md->ys = 0;
- md->spawndelay1 = -1; // Only once is a flag.
- md->spawndelay2 = -1; // Only once is a flag.
+ md->spawndelay1 = static_cast<interval_t>(-1); // Only once is a flag.
+ md->spawndelay2 = static_cast<interval_t>(-1); // Only once is a flag.
memcpy(md->npc_event, event, sizeof(md->npc_event));
@@ -537,8 +539,8 @@ int mob_spawn_guardian(struct map_session_data *sd, const char *mapname,
md->y0 = y;
md->xs = 0;
md->ys = 0;
- md->spawndelay1 = -1; // Only once is a flag.
- md->spawndelay2 = -1; // Only once is a flag.
+ md->spawndelay1 = static_cast<interval_t>(-1); // Only once is a flag.
+ md->spawndelay2 = static_cast<interval_t>(-1); // Only once is a flag.
memcpy(md->npc_event, event, sizeof(md->npc_event));
@@ -622,12 +624,12 @@ int mob_can_move(struct mob_data *md)
*------------------------------------------
*/
static
-int calc_next_walk_step(struct mob_data *md)
+interval_t calc_next_walk_step(struct mob_data *md)
{
- nullpo_ret(md);
+ nullpo_retr(interval_t::zero(), md);
if (md->walkpath.path_pos >= md->walkpath.path_len)
- return -1;
+ return static_cast<interval_t>(-1);
if (dir_is_diagonal(md->walkpath.path[md->walkpath.path_pos]))
return battle_get_speed(&md->bl) * 14 / 10;
return battle_get_speed(&md->bl);
@@ -641,10 +643,10 @@ int mob_walktoxy_sub(struct mob_data *md);
*------------------------------------------
*/
static
-int mob_walk(struct mob_data *md, unsigned int tick, int data)
+int mob_walk(struct mob_data *md, tick_t tick, unsigned char data)
{
int moveblock;
- int i, ctype;
+ int ctype;
int x, y, dx, dy;
nullpo_ret(md);
@@ -715,13 +717,15 @@ int mob_walk(struct mob_data *md, unsigned int tick, int data)
-dx, -dy, BL::PC);
md->state.state = MS::IDLE;
}
- if ((i = calc_next_walk_step(md)) > 0)
+ interval_t i = calc_next_walk_step(md);
+ if (i > interval_t::zero())
{
- i = i >> 1;
- if (i < 1 && md->walkpath.path_half == 0)
- i = 1;
- md->timer =
- add_timer(tick + i, mob_timer, md->bl.id, md->walkpath.path_pos);
+ i = i / 2;
+ if (md->walkpath.path_half == 0)
+ i = std::max(i, std::chrono::milliseconds(1));
+ md->timer = add_timer(tick + i,
+ std::bind(mob_timer, ph::_1, ph::_2,
+ md->bl.id, md->walkpath.path_pos));
md->state.state = MS::WALK;
if (md->walkpath.path_pos >= md->walkpath.path_len)
@@ -750,7 +754,7 @@ int mob_check_attack(struct mob_data *md)
md->state.state = MS::IDLE;
md->state.skillstate = MobSkillState::MSS_IDLE;
- if (md->skilltimer != -1)
+ if (md->skilltimer)
return 0;
if (bool(md->opt1))
@@ -772,7 +776,7 @@ int mob_check_attack(struct mob_data *md)
if (tsd)
{
- if (pc_isdead(tsd) || tsd->invincible_timer != -1
+ if (pc_isdead(tsd) || tsd->invincible_timer
|| pc_isinvisible(tsd) || md->bl.m != tbl->m || tbl->prev == NULL
|| distance(md->bl.x, md->bl.y, tbl->x, tbl->y) >= 13)
{
@@ -826,10 +830,10 @@ int mob_check_attack(struct mob_data *md)
static
void mob_ancillary_attack(struct block_list *bl,
- struct block_list *mdbl, struct block_list *tbl, unsigned int tick)
+ struct block_list *mdbl, struct block_list *tbl, tick_t tick)
{
if (bl != tbl)
- battle_weapon_attack(mdbl, bl, tick, BCT_ZERO);
+ battle_weapon_attack(mdbl, bl, tick);
}
/*==========================================
@@ -837,7 +841,7 @@ void mob_ancillary_attack(struct block_list *bl,
*------------------------------------------
*/
static
-int mob_attack(struct mob_data *md, unsigned int tick, int)
+int mob_attack(struct mob_data *md, tick_t tick)
{
struct block_list *tbl = NULL;
@@ -858,7 +862,7 @@ int mob_attack(struct mob_data *md, unsigned int tick, int)
if (mobskill_use(md, tick, MobSkillCondition::NEVER_EQUAL))
return 0;
- md->target_lv = battle_weapon_attack(&md->bl, tbl, tick, BCT_ZERO);
+ md->target_lv = battle_weapon_attack(&md->bl, tbl, tick);
// If you are reading this, please note:
// it is highly platform-specific that this even works at all.
int radius = battle_config.mob_splash_radius;
@@ -869,7 +873,9 @@ int mob_attack(struct mob_data *md, unsigned int tick, int)
md->attackabletime = tick + battle_get_adelay(&md->bl);
- md->timer = add_timer(md->attackabletime, mob_timer, md->bl.id, 0);
+ md->timer = add_timer(md->attackabletime,
+ std::bind(mob_timer, ph::_1, ph::_2,
+ md->bl.id, 0));
md->state.state = MS::ATTACK;
return 0;
@@ -893,66 +899,70 @@ void mob_stopattacked(struct map_session_data *sd, int id)
* The timer in which the mob's states changes
*------------------------------------------
*/
-int mob_changestate(struct mob_data *md, MS state, int type)
+static
+int mob_changestate(struct mob_data *md, MS state, bool type)
{
- unsigned int tick;
- int i;
-
nullpo_ret(md);
- if (md->timer != -1)
- delete_timer(md->timer, mob_timer);
- md->timer = -1;
+ if (md->timer)
+ delete_timer(md->timer);
+ md->timer = nullptr;
md->state.state = state;
switch (state)
{
case MS::WALK:
- if ((i = calc_next_walk_step(md)) > 0)
+ {
+ interval_t i = calc_next_walk_step(md);
+ if (i > interval_t::zero())
{
- i = i >> 2;
- md->timer =
- add_timer(gettick() + i, mob_timer, md->bl.id, 0);
+ i = i / 4;
+ md->timer = add_timer(gettick() + i,
+ std::bind(mob_timer, ph::_1, ph::_2,
+ md->bl.id, 0));
}
else
md->state.state = MS::IDLE;
+ }
break;
case MS::ATTACK:
- tick = gettick();
- i = DIFF_TICK(md->attackabletime, tick);
- if (i > 0 && i < 2000)
- md->timer =
- add_timer(md->attackabletime, mob_timer, md->bl.id, 0);
+ {
+ tick_t tick = gettick();
+ interval_t i = md->attackabletime - tick;
+ if (i > interval_t::zero() && i < std::chrono::seconds(2))
+ md->timer = add_timer(md->attackabletime,
+ std::bind(mob_timer, ph::_1, ph::_2,
+ md->bl.id, 0));
else if (type)
{
md->attackabletime = tick + battle_get_amotion(&md->bl);
- md->timer =
- add_timer(md->attackabletime, mob_timer, md->bl.id, 0);
+ md->timer = add_timer(md->attackabletime,
+ std::bind(mob_timer, ph::_1, ph::_2,
+ md->bl.id, 0));
}
else
{
- md->attackabletime = tick + 1;
- md->timer =
- add_timer(md->attackabletime, mob_timer, md->bl.id, 0);
+ md->attackabletime = tick + std::chrono::milliseconds(1);
+ md->timer = add_timer(md->attackabletime,
+ std::bind(mob_timer, ph::_1, ph::_2,
+ md->bl.id, 0));
}
- break;
- case MS::DELAY:
- md->timer =
- add_timer(gettick() + type, mob_timer, md->bl.id, 0);
+ }
break;
case MS::DEAD:
+ {
skill_castcancel(&md->bl, 0);
-// mobskill_deltimer(md);
md->state.skillstate = MobSkillState::MSS_DEAD;
md->last_deadtime = gettick();
// Since it died, all aggressors' attack to this mob is stopped.
clif_foreachclient(std::bind(mob_stopattacked, ph::_1, md->bl.id));
skill_status_change_clear(&md->bl, 2); // The abnormalities in status are canceled.
- if (md->deletetimer != -1)
- delete_timer(md->deletetimer, mob_timer_delete);
- md->deletetimer = -1;
+ if (md->deletetimer)
+ delete_timer(md->deletetimer);
+ md->deletetimer = nullptr;
md->hp = md->target_id = md->attacked_id = 0;
md->state.attackable = false;
+ }
break;
}
@@ -965,7 +975,7 @@ int mob_changestate(struct mob_data *md, MS state, int type)
*------------------------------------------
*/
static
-void mob_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void mob_timer(TimerData *tid, tick_t tick, int id, unsigned char data)
{
struct mob_data *md;
struct block_list *bl;
@@ -980,13 +990,8 @@ void mob_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
md = (struct mob_data *) bl;
- if (md->timer != tid)
- {
- if (battle_config.error_log == 1)
- PRINTF("mob_timer %d != %d\n", md->timer, tid);
- return;
- }
- md->timer = -1;
+ assert (md->timer == tid);
+ md->timer = nullptr;
if (md->bl.prev == NULL || md->state.state == MS::DEAD)
return;
@@ -998,10 +1003,7 @@ void mob_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
mob_walk(md, tick, data);
break;
case MS::ATTACK:
- mob_attack(md, tick, data);
- break;
- case MS::DELAY:
- mob_changestate(md, MS::IDLE, 0);
+ mob_attack(md, tick);
break;
default:
if (battle_config.error_log == 1)
@@ -1071,7 +1073,7 @@ int mob_walktoxy(struct mob_data *md, int x, int y, int easy)
*------------------------------------------
*/
static
-void mob_delayspawn(timer_id, tick_t, custom_id_t m, custom_data_t)
+void mob_delayspawn(TimerData *, tick_t, int m)
{
mob_spawn(m);
}
@@ -1083,7 +1085,6 @@ void mob_delayspawn(timer_id, tick_t, custom_id_t m, custom_data_t)
static
int mob_setdelayspawn(int id)
{
- unsigned int spawntime, spawntime1, spawntime2, spawntime3;
struct mob_data *md;
struct block_list *bl;
@@ -1100,7 +1101,9 @@ int mob_setdelayspawn(int id)
return -1;
// Processing of MOB which is not revitalized
- if (md->spawndelay1 == -1 && md->spawndelay2 == -1 && md->n == 0)
+ if (md->spawndelay1 == static_cast<interval_t>(-1)
+ && md->spawndelay2 == static_cast<interval_t>(-1)
+ && md->n == 0)
{
map_deliddb(&md->bl);
if (md->lootitem)
@@ -1112,24 +1115,14 @@ int mob_setdelayspawn(int id)
return 0;
}
- spawntime1 = md->last_spawntime + md->spawndelay1;
- spawntime2 = md->last_deadtime + md->spawndelay2;
- spawntime3 = gettick() + 5000;
- // spawntime = max(spawntime1,spawntime2,spawntime3);
- if (DIFF_TICK(spawntime1, spawntime2) > 0)
- {
- spawntime = spawntime1;
- }
- else
- {
- spawntime = spawntime2;
- }
- if (DIFF_TICK(spawntime3, spawntime) > 0)
- {
- spawntime = spawntime3;
- }
+ tick_t spawntime1 = md->last_spawntime + md->spawndelay1;
+ tick_t spawntime2 = md->last_deadtime + md->spawndelay2;
+ tick_t spawntime3 = gettick() + std::chrono::seconds(5);
+ tick_t spawntime = std::max({spawntime1, spawntime2, spawntime3});
- add_timer(spawntime, mob_delayspawn, id, 0);
+ add_timer(spawntime,
+ std::bind(mob_delayspawn, ph::_1, ph::_2,
+ id));
return 0;
}
@@ -1140,7 +1133,7 @@ int mob_setdelayspawn(int id)
int mob_spawn(int id)
{
int x = 0, y = 0, c;
- unsigned int tick = gettick();
+ tick_t tick = gettick();
struct mob_data *md;
struct block_list *bl;
@@ -1185,7 +1178,9 @@ int mob_spawn(int id)
{
// if(battle_config.error_log==1)
// PRINTF("MOB spawn error %d @ %s\n",id,map[md->bl.m].name);
- add_timer(tick + 5000, mob_delayspawn, id, 0);
+ add_timer(tick + std::chrono::seconds(5),
+ std::bind(mob_delayspawn, ph::_1, ph::_2,
+ id));
return 1;
}
}
@@ -1210,18 +1205,18 @@ int mob_spawn(int id)
md->state.state = MS::IDLE;
md->state.skillstate = MobSkillState::MSS_IDLE;
- md->timer = -1;
+ md->timer = nullptr;
md->last_thinktime = tick;
- md->next_walktime = tick + MPRAND(5000, 50);
+ md->next_walktime = tick + std::chrono::seconds(5) + std::chrono::milliseconds(MRAND(50));
md->attackabletime = tick;
md->canmove_tick = tick;
md->sg_count = 0;
- md->deletetimer = -1;
+ md->deletetimer = nullptr;
- md->skilltimer = -1;
+ md->skilltimer = nullptr;
for (int i = 0; i < MAX_MOBSKILL; i++)
- md->skilldelay[i] = tick - 1000 * 3600 * 10;
+ md->skilldelay[i] = tick - std::chrono::hours(10);
md->skillid = SkillID();
md->skilllv = 0;
@@ -1232,9 +1227,8 @@ int mob_spawn(int id)
for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE))
{
- md->sc_data[i].timer = -1;
- md->sc_data[i].val1 = md->sc_data[i].val2 = md->sc_data[i].val3 =
- md->sc_data[i].val4 = 0;
+ md->sc_data[i].timer = nullptr;
+ md->sc_data[i].val1 = 0;
}
md->sc_count = 0;
md->opt1 = Opt1::ZERO;
@@ -1319,8 +1313,8 @@ int mob_stop_walking(struct mob_data *md, int type)
clif_fixmobpos(md);
if (type & 0x02)
{
- int delay = battle_get_dmotion(&md->bl);
- unsigned int tick = gettick();
+ interval_t delay = battle_get_dmotion(&md->bl);
+ tick_t tick = gettick();
if (md->canmove_tick < tick)
md->canmove_tick = tick + delay;
}
@@ -1431,7 +1425,7 @@ int mob_target(struct mob_data *md, struct block_list *bl, int dist)
{
sd = (struct map_session_data *) bl;
nullpo_ret(sd);
- if (sd->invincible_timer != -1 || pc_isinvisible(sd))
+ if (sd->invincible_timer || pc_isinvisible(sd))
return 0;
if (!bool(mode & MobMode::BOSS) && race != Race::_insect && race != Race::_demon
&& sd->state.gangsterparadise)
@@ -1491,7 +1485,7 @@ void mob_ai_sub_hard_activesearch(struct block_list *bl,
if (tsd &&
!pc_isdead(tsd) &&
tsd->bl.m == smd->bl.m &&
- tsd->invincible_timer == -1 &&
+ !tsd->invincible_timer &&
!pc_isinvisible(tsd) &&
(dist =
distance(smd->bl.x, smd->bl.y, tsd->bl.x, tsd->bl.y)) < 9)
@@ -1605,7 +1599,7 @@ void mob_ai_sub_hard_linksearch(struct block_list *bl, struct mob_data *md, stru
*------------------------------------------
*/
static
-int mob_ai_sub_hard_slavemob(struct mob_data *md, unsigned int tick)
+int mob_ai_sub_hard_slavemob(struct mob_data *md, tick_t tick)
{
struct mob_data *mmd = NULL;
struct block_list *bl;
@@ -1698,7 +1692,7 @@ int mob_ai_sub_hard_slavemob(struct mob_data *md, unsigned int tick)
while (ret && i < 10);
}
- md->next_walktime = tick + 500;
+ md->next_walktime = tick + std::chrono::milliseconds(500);
md->state.master_check = 1;
}
@@ -1707,7 +1701,7 @@ int mob_ai_sub_hard_slavemob(struct mob_data *md, unsigned int tick)
&& (!md->target_id || !md->state.attackable))
{
struct map_session_data *sd = map_id2sd(mmd->target_id);
- if (sd != NULL && !pc_isdead(sd) && sd->invincible_timer == -1
+ if (sd != NULL && !pc_isdead(sd) && !sd->invincible_timer
&& !pc_isinvisible(sd))
{
@@ -1735,14 +1729,14 @@ int mob_ai_sub_hard_slavemob(struct mob_data *md, unsigned int tick)
*------------------------------------------
*/
static
-int mob_unlocktarget(struct mob_data *md, int tick)
+int mob_unlocktarget(struct mob_data *md, tick_t tick)
{
nullpo_ret(md);
md->target_id = 0;
md->state.attackable = false;
md->state.skillstate = MobSkillState::MSS_IDLE;
- md->next_walktime = tick + MPRAND(3000, 3000);
+ md->next_walktime = tick + std::chrono::seconds(3) + std::chrono::milliseconds(MRAND(3000));
return 0;
}
@@ -1751,17 +1745,16 @@ int mob_unlocktarget(struct mob_data *md, int tick)
*------------------------------------------
*/
static
-int mob_randomwalk(struct mob_data *md, int tick)
+int mob_randomwalk(struct mob_data *md, tick_t tick)
{
const int retrycount = 20;
- int speed;
nullpo_ret(md);
- speed = battle_get_speed(&md->bl);
- if (DIFF_TICK(md->next_walktime, tick) < 0)
+ interval_t speed = battle_get_speed(&md->bl);
+ if (md->next_walktime < tick)
{
- int i, x, y, c, d = 12 - md->move_fail_count;
+ int i, x, y, d = 12 - md->move_fail_count;
if (d < 5)
d = 5;
for (i = 0; i < retrycount; i++)
@@ -1770,7 +1763,8 @@ int mob_randomwalk(struct mob_data *md, int tick)
int r = mt_random();
x = md->bl.x + r % (d * 2 + 1) - d;
y = md->bl.y + r / (d * 2 + 1) % (d * 2 + 1) - d;
- if ((c = map_getcell(md->bl.m, x, y)) != 1 && c != 5
+ uint8_t c = map_getcell(md->bl.m, x, y);
+ if (c != 1 && c != 5
&& mob_walktoxy(md, x, y, 1) == 0)
{
md->move_fail_count = 0;
@@ -1789,7 +1783,8 @@ int mob_randomwalk(struct mob_data *md, int tick)
}
}
}
- for (i = c = 0; i < md->walkpath.path_len; i++)
+ interval_t c = interval_t::zero();
+ for (i = 0; i < md->walkpath.path_len; i++)
{
// The next walk start time is calculated.
if (dir_is_diagonal(md->walkpath.path[i]))
@@ -1797,7 +1792,7 @@ int mob_randomwalk(struct mob_data *md, int tick)
else
c += speed;
}
- md->next_walktime = tick + MPRAND(3000, 3000) + c;
+ md->next_walktime = tick + std::chrono::seconds(3) + std::chrono::milliseconds(MRAND(3000)) + c;
md->state.skillstate = MobSkillState::MSS_WALK;
return 1;
}
@@ -1809,7 +1804,7 @@ int mob_randomwalk(struct mob_data *md, int tick)
*------------------------------------------
*/
static
-void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
+void mob_ai_sub_hard(struct block_list *bl, tick_t tick)
{
struct mob_data *md, *tmd = NULL;
struct map_session_data *tsd = NULL;
@@ -1822,13 +1817,14 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
nullpo_retv(bl);
md = (struct mob_data *) bl;
- if (DIFF_TICK(tick, md->last_thinktime) < MIN_MOBTHINKTIME)
+ if (tick < md->last_thinktime + MIN_MOBTHINKTIME)
return;
md->last_thinktime = tick;
- if (md->skilltimer != -1 || md->bl.prev == NULL)
- { // Under a skill aria and death
- if (DIFF_TICK(tick, md->next_walktime) > MIN_MOBTHINKTIME)
+ if (md->skilltimer || md->bl.prev == NULL)
+ {
+ // Under a skill aria and death
+ if (tick > md->next_walktime + MIN_MOBTHINKTIME)
md->next_walktime = tick;
return;
}
@@ -1841,8 +1837,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
Race race = mob_db[md->mob_class].race;
// Abnormalities
- if ((bool(md->opt1) && md->opt1 != Opt1::_stone6)
- || md->state.state == MS::DELAY)
+ if (bool(md->opt1) && md->opt1 != Opt1::_stone6)
return;
if (!bool(mode & MobMode::CAN_ATTACK) && md->target_id > 0)
@@ -1853,7 +1848,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
struct map_session_data *asd = map_id2sd(md->attacked_id);
if (asd)
{
- if (asd->invincible_timer == -1 && !pc_isinvisible(asd))
+ if (!asd->invincible_timer && !pc_isinvisible(asd))
{
map_foreachinarea(std::bind(mob_ai_sub_hard_linksearch, ph::_1, md, &asd->bl),
md->bl.m, md->bl.x - 13, md->bl.y - 13,
@@ -1874,7 +1869,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
if (abl->type == BL::PC)
asd = (struct map_session_data *) abl;
if (asd == NULL || md->bl.m != abl->m || abl->prev == NULL
- || asd->invincible_timer != -1 || pc_isinvisible(asd)
+ || asd->invincible_timer || pc_isinvisible(asd)
|| (dist =
distance(md->bl.x, md->bl.y, abl->x, abl->y)) >= 32
|| battle_check_target(bl, abl, BCT_ENEMY) == 0)
@@ -1962,18 +1957,16 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
return;
md->state.skillstate = MobSkillState::MSS_CHASE; // 突撃時スキル
mobskill_use(md, tick, MobSkillCondition::ANY);
-// if(md->timer != -1 && (DIFF_TICK(md->next_walktime,tick)<0 || distance(md->to_x,md->to_y,tsd->bl.x,tsd->bl.y)<2) )
- if (md->timer != -1 && md->state.state != MS::ATTACK
- && (DIFF_TICK(md->next_walktime, tick) < 0
- || distance(md->to_x, md->to_y, tbl->x,
- tbl->y) < 2))
+ if (md->timer && md->state.state != MS::ATTACK
+ && (md->next_walktime < tick
+ || distance(md->to_x, md->to_y, tbl->x, tbl->y) < 2))
return; // 既に移動中
if (!mob_can_reach(md, tbl, (md->min_chase > 13) ? md->min_chase : 13))
mob_unlocktarget(md, tick); // 移動できないのでタゲ解除(IWとか?)
else
{
// 追跡
- md->next_walktime = tick + 500;
+ md->next_walktime = tick + std::chrono::milliseconds(500);
i = 0;
do
{
@@ -1995,17 +1988,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
dx = tbl->x - md->bl.x + MRAND(3) - 1;
dy = tbl->y - md->bl.y + MRAND(3) - 1;
}
- /* if (path_search(&md->walkpath,md->bl.m,md->bl.x,md->bl.y,md->bl.x+dx,md->bl.y+dy,0)){
- * dx=tsd->bl.x - md->bl.x;
- * dy=tsd->bl.y - md->bl.y;
- * if (dx<0) dx--;
- * else if (dx>0) dx++;
- * if (dy<0) dy--;
- * else if (dy>0) dy++;
- * } */
- ret =
- mob_walktoxy(md, md->bl.x + dx,
- md->bl.y + dy, 0);
+ ret = mob_walktoxy(md, md->bl.x + dx, md->bl.y + dy, 0);
i++;
}
while (ret && i < 5);
@@ -2033,13 +2016,6 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
if (md->state.state == MS::ATTACK)
return; // 既に攻撃中
mob_changestate(md, MS::ATTACK, attack_type);
-
-/* if (mode&0x08){ // リンクモンスター
- map_foreachinarea(mob_ai_sub_hard_linksearch,md->bl.m,
- md->bl.x-13,md->bl.y-13,
- md->bl.x+13,md->bl.y+13,
- BL::MOB,md,&tsd->bl);
- }*/
}
return;
}
@@ -2066,19 +2042,13 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
return;
md->state.skillstate = MobSkillState::MSS_LOOT; // ルート時スキル使用
mobskill_use(md, tick, MobSkillCondition::ANY);
-// if(md->timer != -1 && (DIFF_TICK(md->next_walktime,tick)<0 || distance(md->to_x,md->to_y,tbl->x,tbl->y)<2) )
- if (md->timer != -1 && md->state.state != MS::ATTACK
- && (DIFF_TICK(md->next_walktime, tick) < 0
- || distance(md->to_x, md->to_y, tbl->x,
- tbl->y) <= 0))
+ if (md->timer && md->state.state != MS::ATTACK
+ && (md->next_walktime < tick
+ || distance(md->to_x, md->to_y, tbl->x, tbl->y) <= 0))
return; // 既に移動中
- md->next_walktime = tick + 500;
+ md->next_walktime = tick + std::chrono::milliseconds(500);
dx = tbl->x - md->bl.x;
dy = tbl->y - md->bl.y;
-/* if (path_search(&md->walkpath,md->bl.m,md->bl.x,md->bl.y,md->bl.x+dx,md->bl.y+dy,0)){
- dx=tbl->x - md->bl.x;
- dy=tbl->y - md->bl.y;
- }*/
ret = mob_walktoxy(md, md->bl.x + dx, md->bl.y + dy, 0);
if (ret)
mob_unlocktarget(md, tick); // 移動できないのでタゲ解除(IWとか?)
@@ -2131,13 +2101,20 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
&& mob_can_move(md)
&& (md->master_id == 0 || md->state.special_mob_ai
|| md->master_dist > 10))
- { //取り巻きMOBじゃない
-
- if (DIFF_TICK(md->next_walktime, tick) > +7000 &&
- (md->walkpath.path_len == 0
- || md->walkpath.path_pos >= md->walkpath.path_len))
+ {
+ //取り巻きMOBじゃない
+ if (md->next_walktime > tick + std::chrono::seconds(7)
+ && (md->walkpath.path_len == 0
+ || md->walkpath.path_pos >= md->walkpath.path_len))
{
- md->next_walktime = tick + 3000 * MRAND(2000);
+ // Original: (3000 * rand()) % 2000
+ // yields ({0 3000 6000 9000 12000 15000 ...} * 3000) % 2000
+ // = {0 1000 0 1000 0 1000 ...}
+ // Recent: 3000 * MRAND(2000)
+ // yields 3000 * {0 3000 6000 9000 ... 5991000 5994000 5997000}
+ // I have reverted to the original logic, but I don't understand.
+#warning "I don't understand this code! It is either wrong now or was wrong before."
+ md->next_walktime = tick + std::chrono::seconds(MRAND(2));
}
// Random movement
@@ -2156,7 +2133,7 @@ void mob_ai_sub_hard(struct block_list *bl, unsigned int tick)
*------------------------------------------
*/
static
-void mob_ai_sub_foreachclient(struct map_session_data *sd, unsigned int tick)
+void mob_ai_sub_foreachclient(struct map_session_data *sd, tick_t tick)
{
nullpo_retv(sd);
@@ -2170,7 +2147,7 @@ void mob_ai_sub_foreachclient(struct map_session_data *sd, unsigned int tick)
*------------------------------------------
*/
static
-void mob_ai_hard(timer_id, tick_t tick, custom_id_t, custom_data_t)
+void mob_ai_hard(TimerData *, tick_t tick)
{
clif_foreachclient(std::bind(mob_ai_sub_foreachclient, ph::_1, tick));
}
@@ -2180,7 +2157,7 @@ void mob_ai_hard(timer_id, tick_t tick, custom_id_t, custom_data_t)
*------------------------------------------
*/
static
-void mob_ai_sub_lazy(db_key_t, db_val_t data, unsigned int tick)
+void mob_ai_sub_lazy(db_key_t, db_val_t data, tick_t tick)
{
struct mob_data *md = (struct mob_data *)data;
@@ -2192,18 +2169,18 @@ void mob_ai_sub_lazy(db_key_t, db_val_t data, unsigned int tick)
if (md->bl.type == BL::NUL || md->bl.type != BL::MOB)
return;
- if (DIFF_TICK(tick, md->last_thinktime) < MIN_MOBTHINKTIME * 10)
+ if (tick < md->last_thinktime + MIN_MOBTHINKTIME * 10)
return;
md->last_thinktime = tick;
- if (md->bl.prev == NULL || md->skilltimer != -1)
+ if (md->bl.prev == NULL || md->skilltimer)
{
- if (DIFF_TICK(tick, md->next_walktime) > MIN_MOBTHINKTIME * 10)
+ if (tick > md->next_walktime + MIN_MOBTHINKTIME * 10)
md->next_walktime = tick;
return;
}
- if (DIFF_TICK(md->next_walktime, tick) < 0
+ if (md->next_walktime < tick
&& bool(mob_db[md->mob_class].mode & MobMode::CAN_MOVE)
&& mob_can_move(md))
{
@@ -2234,7 +2211,7 @@ void mob_ai_sub_lazy(db_key_t, db_val_t data, unsigned int tick)
mob_warp(md, -1, -1, -1, BeingRemoveWhy::NEGATIVE1);
}
- md->next_walktime = tick + MPRAND(5000, 10000);
+ md->next_walktime = tick + std::chrono::seconds(5) + std::chrono::milliseconds(MRAND(10 * 1000));
}
}
@@ -2243,7 +2220,7 @@ void mob_ai_sub_lazy(db_key_t, db_val_t data, unsigned int tick)
*------------------------------------------
*/
static
-void mob_ai_lazy(timer_id, tick_t tick, custom_id_t, custom_data_t)
+void mob_ai_lazy(TimerData *, tick_t tick)
{
map_foreachiddb(std::bind(mob_ai_sub_lazy, ph::_1, ph::_2, tick));
}
@@ -2273,13 +2250,11 @@ struct delay_item_drop2
*------------------------------------------
*/
static
-void mob_delay_item_drop(timer_id, tick_t, custom_id_t id, custom_data_t)
+void mob_delay_item_drop(TimerData *, tick_t, struct delay_item_drop *ditem)
{
- struct delay_item_drop *ditem;
struct item temp_item;
PickupFail flag;
- ditem = (struct delay_item_drop *) id;
nullpo_retv(ditem);
memset(&temp_item, 0, sizeof(temp_item));
@@ -2314,12 +2289,10 @@ void mob_delay_item_drop(timer_id, tick_t, custom_id_t id, custom_data_t)
*------------------------------------------
*/
static
-void mob_delay_item_drop2(timer_id, tick_t, custom_id_t id, custom_data_t)
+void mob_delay_item_drop2(TimerData *, tick_t, struct delay_item_drop2 *ditem)
{
- struct delay_item_drop2 *ditem;
PickupFail flag;
- ditem = (struct delay_item_drop2 *) id;
nullpo_retv(ditem);
if (battle_config.item_auto_get == 1)
@@ -2377,7 +2350,7 @@ int mob_catch_delete(struct mob_data *md, BeingRemoveWhy type)
return 0;
}
-void mob_timer_delete(timer_id, tick_t, custom_id_t id, custom_data_t)
+void mob_timer_delete(TimerData *, tick_t, int id)
{
struct block_list *bl = map_id2bl(id);
struct mob_data *md;
@@ -2442,7 +2415,7 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage,
} pt[DAMAGELOG_SIZE];
int pnum = 0;
int mvp_damage, max_hp;
- unsigned int tick = gettick();
+ tick_t tick = gettick();
struct map_session_data *mvp_sd = NULL, *second_sd = NULL, *third_sd =
NULL;
double tdmg, temp;
@@ -2756,7 +2729,9 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage,
ditem->first_sd = mvp_sd;
ditem->second_sd = second_sd;
ditem->third_sd = third_sd;
- add_timer(tick + 500 + i, mob_delay_item_drop, (int) ditem, 0);
+ add_timer(tick + std::chrono::milliseconds(500) + static_cast<interval_t>(i),
+ std::bind(mob_delay_item_drop, ph::_1, ph::_2,
+ ditem));
}
if (md->lootitem)
{
@@ -2774,8 +2749,10 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage,
ditem->first_sd = mvp_sd;
ditem->second_sd = second_sd;
ditem->third_sd = third_sd;
- add_timer(tick + 540 + i, mob_delay_item_drop2,
- (int) ditem, 0);
+ // ?
+ add_timer(tick + std::chrono::milliseconds(540) + static_cast<interval_t>(i),
+ std::bind(mob_delay_item_drop2, ph::_1, ph::_2,
+ ditem));
}
}
}
@@ -2872,8 +2849,8 @@ int mob_damage(struct block_list *src, struct mob_data *md, int damage,
*/
int mob_class_change(struct mob_data *md, int *value)
{
- unsigned int tick = gettick();
- int i, c, hp_rate, max_hp, mob_class, count = 0;
+ tick_t tick = gettick();
+ int i, hp_rate, max_hp, mob_class, count = 0;
nullpo_ret(md);
nullpo_ret(value);
@@ -2921,12 +2898,13 @@ int mob_class_change(struct mob_data *md, int *value)
skill_castcancel(&md->bl, 0);
md->state.skillstate = MobSkillState::MSS_IDLE;
md->last_thinktime = tick;
- md->next_walktime = tick + MPRAND(5000, 50);
+ md->next_walktime = tick + std::chrono::seconds(5) + std::chrono::milliseconds(MRAND(50));
md->attackabletime = tick;
md->canmove_tick = tick;
md->sg_count = 0;
- for (i = 0, c = tick - 1000 * 3600 * 10; i < MAX_MOBSKILL; i++)
+ tick_t c = tick - std::chrono::hours(10);
+ for (i = 0; i < MAX_MOBSKILL; i++)
md->skilldelay[i] = c;
md->skillid = SkillID();
md->skilllv = 0;
@@ -3165,8 +3143,8 @@ int mob_summonslave(struct mob_data *md2, int *value, int amount, int flag)
md->xs = 0;
md->ys = 0;
md->stats[mob_stat::SPEED] = md2->stats[mob_stat::SPEED];
- md->spawndelay1 = -1; // 一度のみフラグ
- md->spawndelay2 = -1; // 一度のみフラグ
+ md->spawndelay1 = static_cast<interval_t>(-1); // 一度のみフラグ
+ md->spawndelay2 = static_cast<interval_t>(-1); // 一度のみフラグ
memset(md->npc_event, 0, sizeof(md->npc_event));
md->bl.type = BL::MOB;
@@ -3196,14 +3174,14 @@ void mob_counttargeted_sub(struct block_list *bl,
if (bl->type == BL::PC)
{
struct map_session_data *sd = (struct map_session_data *) bl;
- if (sd && sd->attacktarget == id && sd->attacktimer != -1
+ if (sd && sd->attacktarget == id && sd->attacktimer
&& sd->attacktarget_lv >= target_lv)
(*c)++;
}
else if (bl->type == BL::MOB)
{
struct mob_data *md = (struct mob_data *) bl;
- if (md && md->target_id == id && md->timer != -1
+ if (md && md->target_id == id && md->timer
&& md->state.state == MS::ATTACK && md->target_lv >= target_lv)
(*c)++;
}
@@ -3235,7 +3213,7 @@ int mob_counttargeted(struct mob_data *md, struct block_list *src,
* スキル使用(詠唱完了、ID指定)
*------------------------------------------
*/
-void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
+void mobskill_castend_id(TimerData *tid, tick_t tick, int id)
{
struct mob_data *md = NULL;
struct block_list *bl;
@@ -3254,7 +3232,7 @@ void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_
if (md->skilltimer != tid) // タイマIDの確認
return;
- md->skilltimer = -1;
+ md->skilltimer = nullptr;
if (bool(md->opt1))
return;
@@ -3298,8 +3276,7 @@ void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_
break;
case 1: // 支援系
skill_castend_nodamage_id(&md->bl, bl,
- md->skillid, md->skilllv,
- tick, BCT_ZERO);
+ md->skillid, md->skilllv);
break;
}
}
@@ -3308,7 +3285,7 @@ void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_
* スキル使用(詠唱完了、場所指定)
*------------------------------------------
*/
-void mobskill_castend_pos(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
+void mobskill_castend_pos(TimerData *tid, tick_t tick, int id)
{
struct mob_data *md = NULL;
struct block_list *bl;
@@ -3327,7 +3304,7 @@ void mobskill_castend_pos(timer_id tid, tick_t tick, custom_id_t id, custom_data
if (md->skilltimer != tid) // タイマIDの確認
return;
- md->skilltimer = -1;
+ md->skilltimer = nullptr;
if (bool(md->opt1))
return;
@@ -3353,7 +3330,7 @@ void mobskill_castend_pos(timer_id tid, tick_t tick, custom_id_t id, custom_data
int mobskill_use_id(struct mob_data *md, struct block_list *target,
int skill_idx)
{
- int casttime, range;
+ int range;
struct mob_skill *ms;
SkillID skill_id;
int skill_lv;
@@ -3387,16 +3364,16 @@ int mobskill_use_id(struct mob_data *md, struct block_list *target,
// delay=skill_delayfix(&md->bl, skill_get_delay( skill_id,skill_lv) );
- casttime = skill_castfix(&md->bl, ms->casttime);
+ interval_t casttime = skill_castfix(&md->bl, ms->casttime);
md->state.skillcastcancel = ms->cancel;
md->skilldelay[skill_idx] = gettick();
if (battle_config.mob_skill_log == 1)
PRINTF("MOB skill use target_id=%d skill=%d lv=%d cast=%d, mob_class = %d\n",
- target->id, skill_id, skill_lv,
- casttime, md->mob_class);
+ target->id, skill_id, skill_lv,
+ static_cast<uint32_t>(casttime.count()), md->mob_class);
- if (casttime <= 0) // 詠唱の無いものはキャンセルされない
+ if (casttime <= interval_t::zero()) // 詠唱の無いものはキャンセルされない
md->state.skillcastcancel = 0;
md->skilltarget = target->id;
@@ -3406,16 +3383,16 @@ int mobskill_use_id(struct mob_data *md, struct block_list *target,
md->skilllv = skill_lv;
md->skillidx = skill_idx;
- if (casttime > 0)
+ if (casttime > interval_t::zero())
{
- md->skilltimer =
- add_timer(gettick() + casttime, mobskill_castend_id, md->bl.id,
- 0);
+ md->skilltimer = add_timer(gettick() + casttime,
+ std::bind(mobskill_castend_id, ph::_1, ph::_2,
+ md->bl.id));
}
else
{
- md->skilltimer = -1;
- mobskill_castend_id(md->skilltimer, gettick(), md->bl.id, 0);
+ md->skilltimer = nullptr;
+ mobskill_castend_id(md->skilltimer, gettick(), md->bl.id);
}
return 1;
@@ -3429,7 +3406,7 @@ static
int mobskill_use_pos(struct mob_data *md,
int skill_x, int skill_y, int skill_idx)
{
- int casttime = 0, range;
+ int range;
struct mob_skill *ms;
struct block_list bl;
int skill_lv;
@@ -3459,16 +3436,17 @@ int mobskill_use_pos(struct mob_data *md,
return 0;
// delay=skill_delayfix(&sd->bl, skill_get_delay( skill_id,skill_lv) );
- casttime = skill_castfix(&md->bl, ms->casttime);
+ interval_t casttime = skill_castfix(&md->bl, ms->casttime);
md->skilldelay[skill_idx] = gettick();
md->state.skillcastcancel = ms->cancel;
if (battle_config.mob_skill_log == 1)
PRINTF("MOB skill use target_pos= (%d,%d) skill=%d lv=%d cast=%d, mob_class = %d\n",
skill_x, skill_y, skill_id, skill_lv,
- casttime, md->mob_class);
+ static_cast<uint32_t>(casttime.count()), md->mob_class);
- if (casttime <= 0) // A skill without a cast time wont be cancelled.
+ if (casttime <= interval_t::zero())
+ // A skill without a cast time wont be cancelled.
md->state.skillcastcancel = 0;
md->skillx = skill_x;
@@ -3477,16 +3455,16 @@ int mobskill_use_pos(struct mob_data *md,
md->skillid = skill_id;
md->skilllv = skill_lv;
md->skillidx = skill_idx;
- if (casttime > 0)
+ if (casttime > interval_t::zero())
{
- md->skilltimer =
- add_timer(gettick() + casttime, mobskill_castend_pos, md->bl.id,
- 0);
+ md->skilltimer = add_timer(gettick() + casttime,
+ std::bind(mobskill_castend_pos, ph::_1, ph::_2,
+ md->bl.id));
}
else
{
- md->skilltimer = -1;
- mobskill_castend_pos(md->skilltimer, gettick(), md->bl.id, 0);
+ md->skilltimer = nullptr;
+ mobskill_castend_pos(md->skilltimer, gettick(), md->bl.id);
}
return 1;
@@ -3496,8 +3474,8 @@ int mobskill_use_pos(struct mob_data *md,
* Skill use judging
*------------------------------------------
*/
-int mobskill_use(struct mob_data *md, unsigned int tick,
- MobSkillCondition event, SkillID)
+int mobskill_use(struct mob_data *md, tick_t tick,
+ MobSkillCondition event)
{
struct mob_skill *ms;
// struct block_list *target=NULL;
@@ -3509,21 +3487,18 @@ int mobskill_use(struct mob_data *md, unsigned int tick,
max_hp = battle_get_max_hp(&md->bl);
- if (battle_config.mob_skill_use == 0 || md->skilltimer != -1)
+ if (battle_config.mob_skill_use == 0 || md->skilltimer)
return 0;
if (md->state.special_mob_ai)
return 0;
- if (md->sc_data[StatusChange::SC_SELFDESTRUCTION].timer != -1) //自爆中はスキルを使わない
- return 0;
-
for (int ii = 0; ii < mob_db[md->mob_class].maxskill; ii++)
{
int flag = 0;
// ディレイ中
- if (DIFF_TICK(tick, md->skilldelay[ii]) < ms[ii].delay)
+ if (tick < md->skilldelay[ii] + ms[ii].delay)
continue;
// 状態判定
@@ -4024,8 +3999,8 @@ int mob_readskilldb(void)
ms->skill_lv = atoi(sp[4]);
ms->permillage = atoi(sp[5]);
- ms->casttime = atoi(sp[6]);
- ms->delay = atoi(sp[7]);
+ ms->casttime = static_cast<interval_t>(atoi(sp[6]));
+ ms->delay = static_cast<interval_t>(atoi(sp[7]));
ms->cancel = atoi(sp[8]);
if (strcmp(sp[8], "yes") == 0)
ms->cancel = 1;
@@ -4082,10 +4057,12 @@ int do_init_mob(void)
mob_read_randommonster();
mob_readskilldb();
- add_timer_interval(gettick() + MIN_MOBTHINKTIME, mob_ai_hard, 0, 0,
- MIN_MOBTHINKTIME);
- add_timer_interval(gettick() + MIN_MOBTHINKTIME * 10, mob_ai_lazy, 0, 0,
- MIN_MOBTHINKTIME * 10);
+ add_timer_interval(gettick() + MIN_MOBTHINKTIME,
+ mob_ai_hard,
+ MIN_MOBTHINKTIME);
+ add_timer_interval(gettick() + MIN_MOBTHINKTIME * 10,
+ mob_ai_lazy,
+ MIN_MOBTHINKTIME * 10);
return 0;
}
diff --git a/src/map/mob.hpp b/src/map/mob.hpp
index 384c1b9..3a7ce3d 100644
--- a/src/map/mob.hpp
+++ b/src/map/mob.hpp
@@ -4,7 +4,7 @@
#include "mob.t.hpp"
#include "../common/mmo.hpp"
-#include "../common/timer.hpp"
+#include "../common/timer.t.hpp"
#include "clif.t.hpp"
#include "map.hpp"
@@ -18,7 +18,7 @@ struct mob_skill
SkillID skill_id;
short skill_lv;
short permillage;
- int casttime, delay;
+ interval_t casttime, delay;
short cancel;
MobSkillCondition cond1;
int cond2i;
@@ -82,7 +82,6 @@ int mob_stop_walking(struct mob_data *md, int type);
int mob_stopattack(struct mob_data *);
int mob_spawn(int);
int mob_damage(struct block_list *, struct mob_data *, int, int);
-int mob_changestate(struct mob_data *md, MS state, int type);
int mob_heal(struct mob_data *, int);
int mob_get_sex(int);
short mob_get_hair(int);
@@ -98,7 +97,7 @@ int do_init_mob(void);
int mob_delete(struct mob_data *md);
int mob_catch_delete(struct mob_data *md, BeingRemoveWhy type);
-void mob_timer_delete(timer_id, tick_t, custom_id_t, custom_data_t);
+void mob_timer_delete(TimerData *, tick_t, int);
int mob_deleteslave(struct mob_data *md);
@@ -108,11 +107,10 @@ int mob_counttargeted(struct mob_data *md, struct block_list *src,
int mob_class_change(struct mob_data *md, int *value);
int mob_warp(struct mob_data *md, int m, int x, int y, BeingRemoveWhy type);
-int mobskill_use(struct mob_data *md, unsigned int tick,
- MobSkillCondition event, SkillID skill=SkillID::ZERO);
+int mobskill_use(struct mob_data *md, tick_t tick, MobSkillCondition event);
int mobskill_event(struct mob_data *md, BF flag);
-void mobskill_castend_id(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data);
-void mobskill_castend_pos(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data);
+void mobskill_castend_id(TimerData *tid, tick_t tick, int id);
+void mobskill_castend_pos(TimerData *tid, tick_t tick, int id);
int mob_summonslave(struct mob_data *md2, int *value, int amount, int flag);
void mob_reload(void);
diff --git a/src/map/npc.cpp b/src/map/npc.cpp
index f77bac1..2aa9480 100644
--- a/src/map/npc.cpp
+++ b/src/map/npc.cpp
@@ -8,6 +8,7 @@
#include "../common/db.hpp"
#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
+#include "../common/timer.hpp"
#include "battle.hpp"
#include "clif.hpp"
@@ -126,7 +127,7 @@ int npc_event_dequeue(struct map_session_data *sd)
if (sd->eventqueue[0][0]) // キューのイベント処理
{
- if (!pc_addeventtimer(sd, 100, sd->eventqueue[0]))
+ if (!pc_addeventtimer(sd, std::chrono::milliseconds(100), sd->eventqueue[0]))
{
PRINTF("npc_event_dequeue(): Event timer is full.\n");
return 0;
@@ -154,21 +155,6 @@ int npc_delete(struct npc_data *nd)
return 0;
}
-/*==========================================
- * イベントの遅延実行
- *------------------------------------------
- */
-static
-void npc_event_timer(timer_id, tick_t, custom_id_t id, custom_data_t data)
-{
- struct map_session_data *sd = map_id2sd(id);
- if (sd == NULL)
- return;
-
- npc_event(sd, (const char *) data, 0);
- free((void *) data);
-}
-
int npc_timer_event(const char *eventname) // Added by RoVeRT
{
struct event_data *ev = (struct event_data *)strdb_search(ev_db, eventname);
@@ -255,7 +241,7 @@ int npc_event_do_l(const char *name, int rid, int argc, argrec_t *args)
*------------------------------------------
*/
static
-void npc_event_do_clock(timer_id, tick_t, custom_id_t, custom_data_t)
+void npc_event_do_clock(TimerData *, tick_t)
{
time_t timer = time(NULL);
struct tm *t = gmtime(&timer);
@@ -292,100 +278,20 @@ int npc_event_do_oninit(void)
int c = npc_event_doall("OnInit");
PRINTF("npc: OnInit Event done. (%d npc)\n", c);
- add_timer_interval(gettick() + 100, npc_event_do_clock, 0, 0, 1000);
-
- return 0;
-}
-
-/*==========================================
- * OnTimer NPC event - by RoVeRT
- *------------------------------------------
- */
-static
-int npc_addeventtimer(struct npc_data *nd, int tick, const char *name)
-{
- int i;
- for (i = 0; i < MAX_EVENTTIMER; i++)
- if (nd->eventtimer[i] == -1)
- break;
- if (i < MAX_EVENTTIMER)
- {
- char *evname;
- CREATE(evname, char, 24);
- memcpy(evname, name, 24);
- nd->eventtimer[i] = add_timer(gettick() + tick,
- npc_event_timer, nd->bl.id,
- (int) evname);
- }
- else
- PRINTF("npc_addtimer: event timer is full !\n");
-
- return 0;
-}
-
-static
-int npc_deleventtimer(struct npc_data *nd, const char *name)
-{
- int i;
- for (i = 0; i < MAX_EVENTTIMER; i++)
- if (nd->eventtimer[i] != -1 && strcmp((char
- *) (get_timer(nd->eventtimer
- [i])->data),
- name) == 0)
- {
- delete_timer(nd->eventtimer[i], npc_event_timer);
- nd->eventtimer[i] = -1;
- break;
- }
-
- return 0;
-}
+ add_timer_interval(gettick() + std::chrono::milliseconds(100),
+ npc_event_do_clock,
+ std::chrono::seconds(1));
-
-static
-void npc_do_ontimer_sub(db_key_t key, db_val_t data, int *c, int option)
-{
- const char *p = key.s;
- struct event_data *ev = (struct event_data *) data;
- int tick = 0;
- char temp[10];
- char event[50];
-
- if (ev->nd->bl.id == *c && (p = strchr(p, ':')) && p
- && strncasecmp("::OnTimer", p, 8) == 0)
- {
- sscanf(&p[9], "%s", temp);
- tick = atoi(temp);
-
- strcpy(event, ev->nd->name);
- strcat(event, p);
-
- if (option != 0)
- {
- npc_addeventtimer(ev->nd, tick, event);
- }
- else
- {
- npc_deleventtimer(ev->nd, event);
- }
- }
-}
-
-int npc_do_ontimer(int id, struct map_session_data *, int option)
-{
- strdb_foreach(ev_db, std::bind(npc_do_ontimer_sub, ph::_1, ph::_2, &id, option));
return 0;
}
-
/*==========================================
* タイマーイベント実行
*------------------------------------------
*/
static
-void npc_timerevent(timer_id, tick_t tick, custom_id_t id, custom_data_t data)
+void npc_timerevent(TimerData *, tick_t tick, int id, interval_t data)
{
- int next, t;
struct npc_data *nd = (struct npc_data *) map_id2bl(id);
struct npc_timerevent_list *te;
if (nd == NULL || nd->u.scr.nexttimer < 0)
@@ -395,14 +301,16 @@ void npc_timerevent(timer_id, tick_t tick, custom_id_t id, custom_data_t data)
}
nd->u.scr.timertick = tick;
te = nd->u.scr.timer_event + nd->u.scr.nexttimer;
- nd->u.scr.timerid = -1;
+ nd->u.scr.timerid = nullptr;
- t = nd->u.scr.timer += data;
+ interval_t t = nd->u.scr.timer += data;
nd->u.scr.nexttimer++;
if (nd->u.scr.timeramount > nd->u.scr.nexttimer)
{
- next = nd->u.scr.timer_event[nd->u.scr.nexttimer].timer - t;
- nd->u.scr.timerid = add_timer(tick + next, npc_timerevent, id, next);
+ interval_t next = nd->u.scr.timer_event[nd->u.scr.nexttimer].timer - t;
+ nd->u.scr.timerid = add_timer(tick + next,
+ std::bind(npc_timerevent, ph::_1, ph::_2,
+ id, next));
}
run_script(nd->u.scr.script, te->pos, 0, nd->bl.id);
@@ -414,7 +322,7 @@ void npc_timerevent(timer_id, tick_t tick, custom_id_t id, custom_data_t data)
*/
int npc_timerevent_start(struct npc_data *nd)
{
- int j, n, next;
+ int j, n;
nullpo_ret(nd);
@@ -433,9 +341,10 @@ int npc_timerevent_start(struct npc_data *nd)
if (j >= n)
return 0;
- next = nd->u.scr.timer_event[j].timer - nd->u.scr.timer;
- nd->u.scr.timerid =
- add_timer(gettick() + next, npc_timerevent, nd->bl.id, next);
+ interval_t next = nd->u.scr.timer_event[j].timer - nd->u.scr.timer;
+ nd->u.scr.timerid = add_timer(gettick() + next,
+ std::bind(npc_timerevent, ph::_1, ph::_2,
+ nd->bl.id, next));
return 0;
}
@@ -450,10 +359,10 @@ int npc_timerevent_stop(struct npc_data *nd)
if (nd->u.scr.nexttimer >= 0)
{
nd->u.scr.nexttimer = -1;
- nd->u.scr.timer += (int)(gettick() - nd->u.scr.timertick);
- if (nd->u.scr.timerid != -1)
- delete_timer(nd->u.scr.timerid, npc_timerevent);
- nd->u.scr.timerid = -1;
+ nd->u.scr.timer += gettick() - nd->u.scr.timertick;
+ if (nd->u.scr.timerid)
+ delete_timer(nd->u.scr.timerid);
+ nd->u.scr.timerid = nullptr;
}
return 0;
}
@@ -462,16 +371,14 @@ int npc_timerevent_stop(struct npc_data *nd)
* タイマー値の所得
*------------------------------------------
*/
-int npc_gettimerevent_tick(struct npc_data *nd)
+interval_t npc_gettimerevent_tick(struct npc_data *nd)
{
- int tick;
-
- nullpo_ret(nd);
+ nullpo_retr(interval_t::zero(), nd);
- tick = nd->u.scr.timer;
+ interval_t tick = nd->u.scr.timer;
if (nd->u.scr.nexttimer >= 0)
- tick += (int)(gettick() - nd->u.scr.timertick);
+ tick += gettick() - nd->u.scr.timertick;
return tick;
}
@@ -479,7 +386,7 @@ int npc_gettimerevent_tick(struct npc_data *nd)
* タイマー値の設定
*------------------------------------------
*/
-int npc_settimerevent_tick(struct npc_data *nd, int newtimer)
+int npc_settimerevent_tick(struct npc_data *nd, interval_t newtimer)
{
int flag;
@@ -1090,7 +997,7 @@ int npc_parse_warp(const char *w1, const char *, const char *w3, const char *w4)
nd->npc_class = WARP_CLASS;
else
nd->npc_class = WARP_DEBUG_CLASS;
- nd->speed = 200;
+ nd->speed = std::chrono::milliseconds(200);
nd->option = Option::ZERO;
nd->opt1 = Opt1::ZERO;
nd->opt2 = Opt2::ZERO;
@@ -1209,7 +1116,7 @@ int npc_parse_shop(char *w1, char *, char *w3, char *w4)
nd->flag = 0;
memcpy(nd->name, w3, 24);
nd->npc_class = atoi(w4);
- nd->speed = 200;
+ nd->speed = std::chrono::milliseconds(200);
nd->chat_id = 0;
nd->option = Option::ZERO;
nd->opt1 = Opt1::ZERO;
@@ -1459,7 +1366,7 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4,
nd->dir = dir;
nd->flag = 0;
nd->npc_class = npc_class;
- nd->speed = 200;
+ nd->speed = std::chrono::milliseconds(200);
nd->u.scr.script = script;
nd->u.scr.src_id = src_id;
nd->chat_id = 0;
@@ -1550,11 +1457,12 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4,
// ラベルデータからタイマーイベント取り込み
for (int i = 0; i < nd->u.scr.label_list_num; i++)
{
- int t = 0, n = 0;
+ int t_ = 0, n = 0;
char *lname = nd->u.scr.label_list[i].name;
int pos = nd->u.scr.label_list[i].pos;
- if (sscanf(lname, "OnTimer%d%n", &t, &n) == 1 && lname[n] == '\0')
+ if (sscanf(lname, "OnTimer%d%n", &t_, &n) == 1 && lname[n] == '\0')
{
+ interval_t t = static_cast<interval_t>(t_);
// タイマーイベント
struct npc_timerevent_list *te = nd->u.scr.timer_event;
int j, k = nd->u.scr.timeramount;
@@ -1583,7 +1491,7 @@ int npc_parse_script(char *w1, char *w2, char *w3, char *w4,
}
}
nd->u.scr.nexttimer = -1;
- nd->u.scr.timerid = -1;
+ nd->u.scr.timerid = nullptr;
return 0;
}
@@ -1673,22 +1581,24 @@ int npc_parse_function(char *, char *, char *w3, char *,
static
int npc_parse_mob(const char *w1, const char *, const char *w3, const char *w4)
{
- int m, x, y, xs, ys, mob_class, num, delay1, delay2;
+ int m, x, y, xs, ys, mob_class, num;
int i;
char mapname[24];
char eventname[24] = "";
struct mob_data *md;
xs = ys = 0;
- delay1 = delay2 = 0;
+ int delay1_ = 0, delay2_ = 0;
// 引数の個数チェック
if (sscanf(w1, "%[^,],%d,%d,%d,%d", mapname, &x, &y, &xs, &ys) < 3 ||
- sscanf(w4, "%d,%d,%d,%d,%s", &mob_class, &num, &delay1, &delay2,
+ sscanf(w4, "%d,%d,%d,%d,%s", &mob_class, &num, &delay1_, &delay2_,
eventname) < 2)
{
PRINTF("bad monster line : %s\n", w3);
return 1;
}
+ interval_t delay1 = std::chrono::milliseconds(delay1_);
+ interval_t delay2 = std::chrono::milliseconds(delay2_);
m = map_mapname2mapid(mapname);
@@ -1726,7 +1636,7 @@ int npc_parse_mob(const char *w1, const char *, const char *w3, const char *w4)
md->spawndelay2 = delay2;
memset(&md->state, 0, sizeof(md->state));
- md->timer = -1;
+ md->timer = nullptr;
md->target_id = 0;
md->attacked_id = 0;
@@ -1938,7 +1848,7 @@ struct npc_data *npc_spawn_text(int m, int x, int y,
retval->u.message = message ? strdup(message) : NULL;
retval->npc_class = npc_class;
- retval->speed = 200;
+ retval->speed = std::chrono::milliseconds(200);
clif_spawnnpc(retval);
map_addblock(&retval->bl);
diff --git a/src/map/npc.hpp b/src/map/npc.hpp
index 50cfaa5..bedca83 100644
--- a/src/map/npc.hpp
+++ b/src/map/npc.hpp
@@ -4,6 +4,8 @@
#include <cstddef>
#include <cstdint>
+#include "../common/timer.t.hpp"
+
constexpr int START_NPC_NUM = 110000000;
constexpr int WARP_CLASS = 45;
@@ -43,7 +45,6 @@ void npc_addsrcfile(const char *);
void npc_delsrcfile(const char *);
int do_init_npc(void);
int npc_event_do_oninit(void);
-int npc_do_ontimer(int, struct map_session_data *, int);
struct argrec;
int npc_event_doall_l(const char *name, int rid,
@@ -63,8 +64,8 @@ int npc_event_do(const char *name)
int npc_timerevent_start(struct npc_data *nd);
int npc_timerevent_stop(struct npc_data *nd);
-int npc_gettimerevent_tick(struct npc_data *nd);
-int npc_settimerevent_tick(struct npc_data *nd, int newtimer);
+interval_t npc_gettimerevent_tick(struct npc_data *nd);
+int npc_settimerevent_tick(struct npc_data *nd, interval_t newtimer);
int npc_delete(struct npc_data *nd);
#endif // NPC_HPP
diff --git a/src/map/party.cpp b/src/map/party.cpp
index b422e04..f6cb84b 100644
--- a/src/map/party.cpp
+++ b/src/map/party.cpp
@@ -18,7 +18,7 @@
#include "../poison.hpp"
// 座標やHP送信の間隔
-constexpr int PARTY_SEND_XYHP_INVERVAL = 1000;
+constexpr interval_t PARTY_SEND_XYHP_INVERVAL = std::chrono::seconds(1);
static
struct dbt *party_db;
@@ -26,15 +26,15 @@ struct dbt *party_db;
static
int party_check_conflict(struct map_session_data *sd);
static
-void party_send_xyhp_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data);
+void party_send_xyhp_timer(TimerData *tid, tick_t tick);
// 初期化
void do_init_party(void)
{
party_db = numdb_init();
add_timer_interval(gettick() + PARTY_SEND_XYHP_INVERVAL,
- party_send_xyhp_timer, 0, 0,
- PARTY_SEND_XYHP_INVERVAL);
+ party_send_xyhp_timer,
+ PARTY_SEND_XYHP_INVERVAL);
}
// 検索
@@ -664,7 +664,7 @@ void party_send_xyhp_timer_sub(db_key_t, db_val_t data)
}
// 位置やHP通知
-void party_send_xyhp_timer(timer_id, tick_t, custom_id_t, custom_data_t)
+void party_send_xyhp_timer(TimerData *, tick_t)
{
numdb_foreach(party_db, party_send_xyhp_timer_sub);
}
diff --git a/src/map/path.cpp b/src/map/path.cpp
index c2ab8ca..1a4385b 100644
--- a/src/map/path.cpp
+++ b/src/map/path.cpp
@@ -1,4 +1,5 @@
#include "../common/cxxstdio.hpp"
+#include "../common/mt_rand.hpp"
#include "../common/nullpo.hpp"
#include "battle.hpp"
@@ -255,7 +256,7 @@ int path_blownpos(int m, int x0, int y0, int dx, int dy, int count)
int fy = (dy != 0 && can_move(md, x0, y0, x0, y0 + dy, 0));
if (fx && fy)
{
- if (rand() & 1)
+ if (MRAND(2))
dx = 0;
else
dy = 0;
diff --git a/src/map/pc.cpp b/src/map/pc.cpp
index 3c55b08..bbd59aa 100644
--- a/src/map/pc.cpp
+++ b/src/map/pc.cpp
@@ -1,5 +1,6 @@
#include "pc.hpp"
+#include <cassert>
#include <cstdlib>
#include <cstring>
@@ -7,6 +8,7 @@
#include "../common/mt_rand.hpp"
#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
+#include "../common/timer.hpp"
#include "atcommand.hpp"
#include "battle.hpp"
@@ -28,7 +30,8 @@
#include "../poison.hpp"
// PVP順位計算の間隔
-constexpr int PVP_CALCRANK_INTERVAL = 1000;
+constexpr std::chrono::milliseconds PVP_CALCRANK_INTERVAL =
+ std::chrono::seconds(1);
//define it here, since the ifdef only occurs in this file
#define USE_ASTRAL_SOUL_SKILL
@@ -64,9 +67,6 @@ constexpr int MAGIC_SKILL_THRESHOLD = 200;
pc_readglobalreg(sd, "MAGIC_EXPERIENCE") & 0xffff, \
(pc_readglobalreg(sd, "MAGIC_EXPERIENCE") >> 24) & 0xff)
-timer_id day_timer_tid;
-timer_id night_timer_tid;
-
static //const
int max_weight_base_0 = 20000;
static //const
@@ -82,25 +82,25 @@ int sp_coefficient_0 = 100;
// coefficients for each weapon type
// (not all used)
static //const
-int aspd_base_0[17] =
-{
- 650,
- 700,
- 750,
- 600,
- 2000,
- 2000,
- 800,
- 2000,
- 700,
- 700,
- 650,
- 900,
- 2000,
- 2000,
- 2000,
- 2000,
- 2000,
+interval_t aspd_base_0[17] =
+{
+std::chrono::milliseconds(650),
+std::chrono::milliseconds(700),
+std::chrono::milliseconds(750),
+std::chrono::milliseconds(600),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(800),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(700),
+std::chrono::milliseconds(700),
+std::chrono::milliseconds(650),
+std::chrono::milliseconds(900),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(2000),
+std::chrono::milliseconds(2000),
};
static const
int exp_table_0[MAX_LEVEL] =
@@ -296,7 +296,7 @@ int distance(int x0, int y0, int x1, int y1)
}
static
-void pc_invincible_timer(timer_id tid, tick_t, custom_id_t id, custom_data_t)
+void pc_invincible_timer(TimerData *tid, tick_t, int id)
{
struct map_session_data *sd;
@@ -304,23 +304,19 @@ void pc_invincible_timer(timer_id tid, tick_t, custom_id_t id, custom_data_t)
|| sd->bl.type != BL::PC)
return;
- if (sd->invincible_timer != tid)
- {
- if (battle_config.error_log)
- PRINTF("invincible_timer %d != %d\n", sd->invincible_timer, tid);
- return;
- }
- sd->invincible_timer = -1;
+ assert (sd->invincible_timer == tid);
+ sd->invincible_timer = nullptr;
}
-int pc_setinvincibletimer(struct map_session_data *sd, int val)
+int pc_setinvincibletimer(struct map_session_data *sd, interval_t val)
{
nullpo_ret(sd);
- if (sd->invincible_timer != -1)
- delete_timer(sd->invincible_timer, pc_invincible_timer);
- sd->invincible_timer =
- add_timer(gettick() + val, pc_invincible_timer, sd->bl.id, 0);
+ if (sd->invincible_timer != nullptr)
+ delete_timer(sd->invincible_timer);
+ sd->invincible_timer = add_timer(gettick() + val,
+ std::bind(pc_invincible_timer, ph::_1, ph::_2,
+ sd->bl.id));
return 0;
}
@@ -328,106 +324,11 @@ int pc_delinvincibletimer(struct map_session_data *sd)
{
nullpo_ret(sd);
- if (sd->invincible_timer != -1)
- {
- delete_timer(sd->invincible_timer, pc_invincible_timer);
- sd->invincible_timer = -1;
- }
- return 0;
-}
-
-static
-void pc_spiritball_timer(timer_id tid, tick_t, custom_id_t id, custom_data_t)
-{
- struct map_session_data *sd;
- int i;
-
- if ((sd = map_id2sd(id)) == NULL
- || sd->bl.type != BL::PC)
- return;
-
- if (sd->spirit_timer[0] != tid)
- {
- if (battle_config.error_log)
- PRINTF("spirit_timer %d != %d\n", sd->spirit_timer[0], tid);
- return;
- }
- sd->spirit_timer[0] = -1;
- for (i = 1; i < sd->spiritball; i++)
- {
- sd->spirit_timer[i - 1] = sd->spirit_timer[i];
- sd->spirit_timer[i] = -1;
- }
- sd->spiritball--;
- if (sd->spiritball < 0)
- sd->spiritball = 0;
-}
-
-int pc_addspiritball(struct map_session_data *sd, int interval, int max)
-{
- int i;
-
- nullpo_ret(sd);
-
- if (max > MAX_SKILL_LEVEL)
- max = MAX_SKILL_LEVEL;
- if (sd->spiritball < 0)
- sd->spiritball = 0;
-
- if (sd->spiritball >= max)
- {
- if (sd->spirit_timer[0] != -1)
- {
- delete_timer(sd->spirit_timer[0], pc_spiritball_timer);
- sd->spirit_timer[0] = -1;
- }
- for (i = 1; i < max; i++)
- {
- sd->spirit_timer[i - 1] = sd->spirit_timer[i];
- sd->spirit_timer[i] = -1;
- }
- }
- else
- sd->spiritball++;
-
- sd->spirit_timer[sd->spiritball - 1] =
- add_timer(gettick() + interval, pc_spiritball_timer, sd->bl.id, 0);
-
- return 0;
-}
-
-int pc_delspiritball(struct map_session_data *sd, int count, int)
-{
- int i;
-
- nullpo_ret(sd);
-
- if (sd->spiritball <= 0)
+ if (sd->invincible_timer)
{
- sd->spiritball = 0;
- return 0;
+ delete_timer(sd->invincible_timer);
+ sd->invincible_timer = nullptr;
}
-
- if (count > sd->spiritball)
- count = sd->spiritball;
- sd->spiritball -= count;
- if (count > MAX_SKILL_LEVEL)
- count = MAX_SKILL_LEVEL;
-
- for (i = 0; i < count; i++)
- {
- if (sd->spirit_timer[i] != -1)
- {
- delete_timer(sd->spirit_timer[i], pc_spiritball_timer);
- sd->spirit_timer[i] = -1;
- }
- }
- for (i = count; i < MAX_SKILL_LEVEL; i++)
- {
- sd->spirit_timer[i - count] = sd->spirit_timer[i];
- sd->spirit_timer[i] = -1;
- }
-
return 0;
}
@@ -482,18 +383,17 @@ void pc_counttargeted_sub(struct block_list *bl,
if (bl->type == BL::PC)
{
struct map_session_data *sd = (struct map_session_data *) bl;
- if (sd && sd->attacktarget == id && sd->attacktimer != -1
+ if (sd->attacktarget == id && sd->attacktimer
&& sd->attacktarget_lv >= target_lv)
(*c)++;
}
else if (bl->type == BL::MOB)
{
struct mob_data *md = (struct mob_data *) bl;
- if (md && md->target_id == id && md->timer != -1
+ if (md->target_id == id && md->timer
&& md->state.state == MS::ATTACK && md->target_lv >= target_lv)
(*c)++;
- //PRINTF("md->target_lv:%d, target_lv:%d\n",((struct mob_data *)bl)->target_lv,target_lv);
}
}
@@ -552,9 +452,6 @@ int pc_makesavestatus(struct map_session_data *sd)
sizeof(sd->status.last_point));
}
- //マナーポイントがプラスだった場合0に
- if (battle_config.muting_players && sd->status.manner > 0)
- sd->status.manner = 0;
return 0;
}
@@ -563,7 +460,7 @@ int pc_makesavestatus(struct map_session_data *sd)
*------------------------------------------
*/
int pc_setnewpc(struct map_session_data *sd, int account_id, int char_id,
- int login_id1, int client_tick, int sex, int)
+ int login_id1, tick_t client_tick, int sex)
{
nullpo_ret(sd);
@@ -744,8 +641,7 @@ int pc_breakweapon(struct map_session_data *sd)
clif_emotion(&sd->bl, 23);
clif_displaymessage(sd->fd, output);
clif_equiplist(sd);
- skill_status_change_start(&sd->bl, StatusChange::SC_BROKNWEAPON, 0, 0, 0,
- 0, 0, 0);
+ skill_status_change_start(&sd->bl, StatusChange::SC_BROKNWEAPON, 0, interval_t::zero());
}
}
if (sd->status.inventory[i].broken == 1)
@@ -783,8 +679,7 @@ int pc_breakarmor(struct map_session_data *sd)
clif_emotion(&sd->bl, 23);
clif_displaymessage(sd->fd, output);
clif_equiplist(sd);
- skill_status_change_start(&sd->bl, StatusChange::SC_BROKNARMOR, 0, 0, 0, 0,
- 0, 0);
+ skill_status_change_start(&sd->bl, StatusChange::SC_BROKNARMOR, 0, interval_t::zero());
}
}
if (sd->status.inventory[i].broken == 1)
@@ -804,7 +699,7 @@ int pc_authok(int id, int login_id2, time_t connect_until_time,
struct map_session_data *sd = NULL;
struct party *p;
- unsigned long tick = gettick();
+ tick_t tick = gettick();
struct sockaddr_in sai;
socklen_t sa_len = sizeof(struct sockaddr);
@@ -838,24 +733,21 @@ int pc_authok(int id, int login_id2, time_t connect_until_time,
sd->dir = DIR::S;
sd->head_dir = DIR::S;
sd->state.auth = 1;
- sd->walktimer = -1;
- sd->attacktimer = -1;
- sd->followtimer = -1; // [MouseJstr]
- sd->invincible_timer = -1;
+ sd->walktimer = nullptr;
+ sd->attacktimer = nullptr;
+ sd->invincible_timer = nullptr;
sd->sg_count = 0;
sd->deal_locked = 0;
sd->trade_partner = 0;
- sd->inchealhptick = 0;
- sd->inchealsptick = 0;
- sd->hp_sub = 0;
- sd->sp_sub = 0;
+ sd->inchealhptick = interval_t::zero();
+ sd->inchealsptick = interval_t::zero();
+ sd->hp_sub = interval_t::zero();
+ sd->sp_sub = interval_t::zero();
sd->quick_regeneration_hp.amount = 0;
sd->quick_regeneration_sp.amount = 0;
sd->heal_xp = 0;
- sd->inchealspirithptick = 0;
- sd->inchealspiritsptick = 0;
sd->canact_tick = tick;
sd->canmove_tick = tick;
sd->attackabletime = tick;
@@ -863,14 +755,12 @@ int pc_authok(int id, int login_id2, time_t connect_until_time,
// Removed because it was buggy with the ~50 day wraparound,
// and there's already a limit on how fast you can log in and log out.
// -o11c
+ //
+ // The above is no longer accurate now that we use <chrono>, but
+ // I'm still not reverting this.
+ // -o11c
sd->cast_tick = tick; // + pc_readglobalreg (sd, "MAGIC_CAST_TICK");
- sd->doridori_counter = 0;
-
- sd->spiritball = 0;
- for (int i = 0; i < MAX_SKILL_LEVEL; i++)
- sd->spirit_timer[i] = -1;
-
memset(&sd->dev, 0, sizeof(struct square));
for (int i = 0; i < 5; i++)
{
@@ -888,9 +778,8 @@ int pc_authok(int id, int login_id2, time_t connect_until_time,
// ステータス異常の初期化
for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE))
{
- sd->sc_data[i].timer = -1;
- sd->sc_data[i].val1 = sd->sc_data[i].val2 = sd->sc_data[i].val3 =
- sd->sc_data[i].val4 = 0;
+ sd->sc_data[i].timer = nullptr;
+ sd->sc_data[i].val1 = 0;
}
sd->sc_count = 0;
if ((battle_config.atc_gmonly == 0 || pc_isGM(sd)) &&
@@ -912,7 +801,7 @@ int pc_authok(int id, int login_id2, time_t connect_until_time,
// イベント関係の初期化
memset(sd->eventqueue, 0, sizeof(sd->eventqueue));
for (int i = 0; i < MAX_EVENTTIMER; i++)
- sd->eventtimer[i] = -1;
+ sd->eventtimer[i] = nullptr;
// 位置の設定
pc_setpos(sd, sd->status.last_point.map, sd->status.last_point.x,
@@ -926,7 +815,7 @@ int pc_authok(int id, int login_id2, time_t connect_until_time,
// pvpの設定
sd->pvp_rank = 0;
sd->pvp_point = 0;
- sd->pvp_timer = -1;
+ sd->pvp_timer = nullptr;
// 通知
@@ -938,15 +827,6 @@ int pc_authok(int id, int login_id2, time_t connect_until_time,
//スパノビ用死にカウンターのスクリプト変数からの読み出しとsdへのセット
sd->die_counter = pc_readglobalreg(sd, "PC_DIE_COUNTER");
- if (night_flag == 1)
- {
- char tmpstr[1024];
- strcpy(tmpstr, "Actually, it's the night...");
- clif_wis_message(sd->fd, wisp_server_name, tmpstr,
- strlen(tmpstr) + 1);
- sd->opt2 |= Opt2::BLIND;
- }
-
// ステータス初期計算など
pc_calcstatus(sd, 1);
@@ -1068,30 +948,28 @@ int pc_checkweighticon(struct map_session_data *sd)
nullpo_ret(sd);
if (sd->weight * 2 >= sd->max_weight
- && sd->sc_data[StatusChange::SC_FLYING_BACKPACK].timer == -1)
+ && !sd->sc_data[StatusChange::SC_FLYING_BACKPACK].timer)
flag = 1;
if (sd->weight * 10 >= sd->max_weight * 9)
flag = 2;
if (flag == 1)
{
- if (sd->sc_data[StatusChange::SC_WEIGHT50].timer == -1)
- skill_status_change_start(&sd->bl, StatusChange::SC_WEIGHT50, 0, 0, 0, 0, 0,
- 0);
+ if (!sd->sc_data[StatusChange::SC_WEIGHT50].timer)
+ skill_status_change_start(&sd->bl, StatusChange::SC_WEIGHT50, 0, interval_t::zero());
}
else
{
- skill_status_change_end(&sd->bl, StatusChange::SC_WEIGHT50, -1);
+ skill_status_change_end(&sd->bl, StatusChange::SC_WEIGHT50, nullptr);
}
if (flag == 2)
{
- if (sd->sc_data[StatusChange::SC_WEIGHT90].timer == -1)
- skill_status_change_start(&sd->bl, StatusChange::SC_WEIGHT90, 0, 0, 0, 0, 0,
- 0);
+ if (!sd->sc_data[StatusChange::SC_WEIGHT90].timer)
+ skill_status_change_start(&sd->bl, StatusChange::SC_WEIGHT90, 0, interval_t::zero());
}
else
{
- skill_status_change_end(&sd->bl, StatusChange::SC_WEIGHT90, -1);
+ skill_status_change_end(&sd->bl, StatusChange::SC_WEIGHT90, nullptr);
}
return 0;
}
@@ -1115,9 +993,9 @@ void pc_set_weapon_look(struct map_session_data *sd)
*/
int pc_calcstatus(struct map_session_data *sd, int first)
{
- int b_speed, b_max_hp, b_max_sp, b_hp, b_sp, b_weight, b_max_weight,
+ int b_max_hp, b_max_sp, b_hp, b_sp, b_weight, b_max_weight,
b_hit, b_flee;
- int b_aspd, b_watk, b_def, b_watk2, b_def2, b_flee2, b_critical,
+ int b_watk, b_def, b_watk2, b_def2, b_flee2, b_critical,
b_attackrange, b_matk1, b_matk2, b_mdef, b_mdef2;
int b_base_atk;
earray<struct skill, SkillID, MAX_SKILL> b_skill;
@@ -1127,7 +1005,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
nullpo_ret(sd);
- b_speed = sd->speed;
+ interval_t b_speed = sd->speed;
b_max_hp = sd->status.max_hp;
b_max_sp = sd->status.max_sp;
b_hp = sd->status.hp;
@@ -1139,7 +1017,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
b_skill = sd->status.skill;
b_hit = sd->hit;
b_flee = sd->flee;
- b_aspd = sd->aspd;
+ interval_t b_aspd = sd->aspd;
b_watk = sd->watk;
b_def = sd->def;
b_watk2 = sd->watk2;
@@ -1193,7 +1071,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
sd->flee = 0;
sd->flee2 = 0;
sd->critical = 0;
- sd->aspd = 0;
+ sd->aspd = interval_t::zero();
sd->watk = 0;
sd->def = 0;
sd->mdef = 0;
@@ -1455,7 +1333,7 @@ int pc_calcstatus(struct map_session_data *sd, int first)
if (sd->aspd_add_rate != 100)
sd->aspd_rate += sd->aspd_add_rate - 100;
- sd->speed -= skill_power(sd, SkillID::TMW_SPEED) >> 3;
+ sd->speed -= std::chrono::milliseconds(skill_power(sd, SkillID::TMW_SPEED) / 8);
sd->aspd_rate -= skill_power(sd, SkillID::TMW_SPEED) / 10;
if (sd->aspd_rate < 20)
sd->aspd_rate = 20;
@@ -1631,57 +1509,42 @@ int pc_calcstatus(struct map_session_data *sd, int first)
if (sd->sc_count)
{
// ATK/DEF変化形
- if (sd->sc_data[StatusChange::SC_POISON].timer != -1) // 毒状態
+ if (sd->sc_data[StatusChange::SC_POISON].timer) // 毒状態
sd->def2 = sd->def2 * 75 / 100;
- if (sd->sc_data[StatusChange::SC_ATKPOT].timer != -1)
+ if (sd->sc_data[StatusChange::SC_ATKPOT].timer)
sd->watk += sd->sc_data[StatusChange::SC_ATKPOT].val1;
- if (sd->sc_data[StatusChange::SC_MATKPOT].timer != -1)
+ if (sd->sc_data[StatusChange::SC_MATKPOT].timer)
{
sd->matk1 += sd->sc_data[StatusChange::SC_MATKPOT].val1;
sd->matk2 += sd->sc_data[StatusChange::SC_MATKPOT].val1;
}
- {
- if (sd->sc_data[StatusChange::SC_SPEEDPOTION0].timer != -1)
- aspd_rate -= sd->sc_data[StatusChange::SC_SPEEDPOTION0].val1;
- }
+ if (sd->sc_data[StatusChange::SC_SPEEDPOTION0].timer)
+ aspd_rate -= sd->sc_data[StatusChange::SC_SPEEDPOTION0].val1;
- if (sd->sc_data[StatusChange::SC_HASTE].timer != -1)
+ if (sd->sc_data[StatusChange::SC_HASTE].timer)
aspd_rate -= sd->sc_data[StatusChange::SC_HASTE].val1;
/* Slow down if protected */
- if (sd->sc_data[StatusChange::SC_PHYS_SHIELD].timer != -1)
+ if (sd->sc_data[StatusChange::SC_PHYS_SHIELD].timer)
aspd_rate += sd->sc_data[StatusChange::SC_PHYS_SHIELD].val1;
-
- // HIT/FLEE変化系
- if (sd->sc_data[StatusChange::SC_BLIND].timer != -1)
- { // 暗黒
- sd->hit -= sd->hit * 25 / 100;
- sd->flee -= sd->flee * 25 / 100;
- }
-
- if (sd->sc_data[StatusChange::SC_CURSE].timer != -1)
- sd->speed += 450;
}
if (sd->speed_rate != 100)
sd->speed = sd->speed * sd->speed_rate / 100;
- if (sd->speed < 1)
- sd->speed = 1;
+ sd->speed = std::max(sd->speed, std::chrono::milliseconds(1));
if (aspd_rate != 100)
sd->aspd = sd->aspd * aspd_rate / 100;
if (sd->attack_spell_override)
sd->aspd = sd->attack_spell_delay;
- if (sd->aspd < battle_config.max_aspd)
- sd->aspd = battle_config.max_aspd;
+ sd->aspd = std::max(sd->aspd, static_cast<interval_t>(battle_config.max_aspd));
sd->amotion = sd->aspd;
- sd->dmotion = 800 - sd->paramc[ATTR::AGI] * 4;
- if (sd->dmotion < 400)
- sd->dmotion = 400;
+ sd->dmotion = std::chrono::milliseconds(800 - sd->paramc[ATTR::AGI] * 4);
+ sd->dmotion = std::max(sd->dmotion, std::chrono::milliseconds(400));
if (sd->status.hp > sd->status.max_hp)
sd->status.hp = sd->status.max_hp;
@@ -2428,7 +2291,7 @@ int can_pick_item_up_from(struct map_session_data *self, int other_id)
int pc_takeitem(struct map_session_data *sd, struct flooritem_data *fitem)
{
- unsigned int tick = gettick();
+ tick_t tick = gettick();
int can_take;
nullpo_ret(sd);
@@ -2469,7 +2332,7 @@ int pc_takeitem(struct map_session_data *sd, struct flooritem_data *fitem)
else
{
// 取得成功
- if (sd->attacktimer != -1)
+ if (sd->attacktimer)
pc_stopattack(sd);
clif_takeitem(&sd->bl, &fitem->bl);
map_clearflooritem(fitem->bl.id);
@@ -2615,9 +2478,7 @@ int pc_steal_item(struct map_session_data *sd, struct block_list *bl)
md = (struct mob_data *) bl;
if (!md->state.steal_flag
&& mob_db[md->mob_class].mexp <= 0
- && !bool(mob_db[md->mob_class].mode & MobMode::BOSS)
- && md->sc_data[StatusChange::SC_STONE].timer == -1
- && md->sc_data[StatusChange::SC_FREEZE].timer == -1)
+ && !bool(mob_db[md->mob_class].mode & MobMode::BOSS))
{
skill = sd->paramc[ATTR::DEX] - mob_db[md->mob_class].attrs[ATTR::DEX] + 10;
@@ -2625,7 +2486,7 @@ int pc_steal_item(struct map_session_data *sd, struct block_list *bl)
{
for (count = 8; count <= 8 && count != 0; count--)
{
- i = rand() % 8;
+ i = MRAND(8);
itemid = mob_db[md->mob_class].dropitem[i].nameid;
if (itemid > 0 && itemdb_type(itemid) != ItemType::_6)
@@ -2635,7 +2496,7 @@ int pc_steal_item(struct map_session_data *sd, struct block_list *bl)
battle_config.item_rate_common * 100 * skill) /
100;
- if (rand() % 10000 < rate)
+ if (MRAND(10000) < rate)
{
struct item tmp_item;
memset(&tmp_item, 0, sizeof(tmp_item));
@@ -2680,9 +2541,7 @@ int pc_steal_coin(struct map_session_data *sd, struct block_list *bl)
{
int rate;
struct mob_data *md = (struct mob_data *) bl;
- if (md && !md->state.steal_coin_flag
- && md->sc_data[StatusChange::SC_STONE].timer == -1
- && md->sc_data[StatusChange::SC_FREEZE].timer == -1)
+ if (md && !md->state.steal_coin_flag)
{
rate = (sd->status.base_level - mob_db[md->mob_class].lv) * 3
+ sd->paramc[ATTR::DEX] * 2 + sd->paramc[ATTR::LUK] * 2;
@@ -2875,12 +2734,12 @@ int pc_can_reach(struct map_session_data *sd, int x, int y)
*------------------------------------------
*/
static
-int calc_next_walk_step(struct map_session_data *sd)
+interval_t calc_next_walk_step(struct map_session_data *sd)
{
- nullpo_ret(sd);
+ nullpo_retr(interval_t::zero(), sd);
if (sd->walkpath.path_pos >= sd->walkpath.path_len)
- return -1;
+ return static_cast<interval_t>(-1);
if (dir_is_diagonal(sd->walkpath.path[sd->walkpath.path_pos]))
return sd->speed * 14 / 10;
@@ -2892,10 +2751,10 @@ int calc_next_walk_step(struct map_session_data *sd)
*------------------------------------------
*/
static
-void pc_walk(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void pc_walk(TimerData *tid, tick_t tick, int id, unsigned char data)
{
struct map_session_data *sd;
- int i, ctype;
+ int ctype;
int moveblock;
int x, y, dx, dy;
@@ -2903,21 +2762,12 @@ void pc_walk(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
if (sd == NULL)
return;
- if (sd->walktimer != tid)
- {
- if (battle_config.error_log)
- PRINTF("pc_walk %d != %d\n", sd->walktimer, tid);
- return;
- }
- sd->walktimer = -1;
+ assert (sd->walktimer == tid);
+ sd->walktimer = nullptr;
if (sd->walkpath.path_pos >= sd->walkpath.path_len
|| sd->walkpath.path_pos != data)
return;
- //歩いたので息吹のタイマーを初期化
- sd->inchealspirithptick = 0;
- sd->inchealspiritsptick = 0;
-
sd->walkpath.path_half ^= 1;
if (sd->walkpath.path_half == 0)
{ // マス目中心へ到着
@@ -2954,7 +2804,7 @@ void pc_walk(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
moveblock = (x / BLOCK_SIZE != (x + dx) / BLOCK_SIZE
|| y / BLOCK_SIZE != (y + dy) / BLOCK_SIZE);
- sd->walktimer = 1;
+ // sd->walktimer = dummy value that is not nullptr;
map_foreachinmovearea(std::bind(clif_pcoutsight, ph::_1, sd),
sd->bl.m, x - AREA_SIZE, y - AREA_SIZE,
x + AREA_SIZE, y + AREA_SIZE,
@@ -2976,7 +2826,7 @@ void pc_walk(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
x + AREA_SIZE, y + AREA_SIZE,
-dx, -dy,
BL::NUL);
- sd->walktimer = -1;
+ // sd->walktimer = nullptr;
if (sd->status.party_id > 0)
{ // パーティのHP情報通知検査
@@ -2995,7 +2845,7 @@ void pc_walk(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
}
// ディボーション検査
- for (i = 0; i < 5; i++)
+ for (int i = 0; i < 5; i++)
if (sd->dev.val1[i])
{
skill_devotion3(&sd->bl, sd->dev.val1[i]);
@@ -3007,13 +2857,15 @@ void pc_walk(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
else
sd->areanpc_id = 0;
}
- if ((i = calc_next_walk_step(sd)) > 0)
+ interval_t i = calc_next_walk_step(sd);
+ if (i > interval_t::zero())
{
- i = i >> 1;
- if (i < 1 && sd->walkpath.path_half == 0)
- i = 1;
- sd->walktimer =
- add_timer(tick + i, pc_walk, id, sd->walkpath.path_pos);
+ i = i / 2;
+ if (sd->walkpath.path_half == 0)
+ i = std::max(i, std::chrono::milliseconds(1));
+ sd->walktimer = add_timer(tick + i,
+ std::bind(pc_walk, ph::_1, ph::_2,
+ id, sd->walkpath.path_pos));
}
}
@@ -3025,7 +2877,6 @@ static
int pc_walktoxy_sub(struct map_session_data *sd)
{
struct walkpath_data wpd;
- int i;
nullpo_retr(1, sd);
@@ -3036,10 +2887,13 @@ int pc_walktoxy_sub(struct map_session_data *sd)
clif_walkok(sd);
sd->state.change_walk_target = 0;
- if ((i = calc_next_walk_step(sd)) > 0)
+ interval_t i = calc_next_walk_step(sd);
+ if (i > interval_t::zero())
{
- i = i >> 2;
- sd->walktimer = add_timer(gettick() + i, pc_walk, sd->bl.id, 0);
+ i = i / 4;
+ sd->walktimer = add_timer(gettick() + i,
+ std::bind(pc_walk, ph::_1, ph::_2,
+ sd->bl.id, 0));
}
clif_movechar(sd);
@@ -3061,7 +2915,7 @@ int pc_walktoxy(struct map_session_data *sd, int x, int y)
if (pc_issit(sd))
pc_setstand(sd);
- if (sd->walktimer != -1 && sd->state.change_walk_target == 0)
+ if (sd->walktimer && sd->state.change_walk_target == 0)
{
// 現在歩いている最中の目的地変更なのでマス目の中心に来た時に
// timer関数からpc_walktoxy_subを呼ぶようにする
@@ -3083,10 +2937,10 @@ int pc_stop_walking(struct map_session_data *sd, int type)
{
nullpo_ret(sd);
- if (sd->walktimer != -1)
+ if (sd->walktimer)
{
- delete_timer(sd->walktimer, pc_walk);
- sd->walktimer = -1;
+ delete_timer(sd->walktimer);
+ sd->walktimer = nullptr;
}
sd->walkpath.path_len = 0;
sd->to_x = sd->bl.x;
@@ -3095,8 +2949,8 @@ int pc_stop_walking(struct map_session_data *sd, int type)
clif_fixpos(&sd->bl);
if (type & 0x02 && battle_config.pc_damage_delay)
{
- unsigned int tick = gettick();
- int delay = battle_get_dmotion(&sd->bl);
+ tick_t tick = gettick();
+ interval_t delay = battle_get_dmotion(&sd->bl);
if (sd->canmove_tick < tick)
sd->canmove_tick = tick + delay;
}
@@ -3215,24 +3069,18 @@ int pc_checkequip(struct map_session_data *sd, EPOS pos)
*------------------------------------------
*/
static
-void pc_attack_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
+void pc_attack_timer(TimerData *tid, tick_t tick, int id)
{
struct map_session_data *sd;
struct block_list *bl;
eptr<struct status_change, StatusChange> sc_data;
int dist, range;
- int attack_spell_delay;
sd = map_id2sd(id);
if (sd == NULL)
return;
- if (sd->attacktimer != tid)
- {
- if (battle_config.error_log)
- PRINTF("pc_attack_timer %d != %d\n", sd->attacktimer, tid);
- return;
- }
- sd->attacktimer = -1;
+ assert (sd->attacktimer == tid);
+ sd->attacktimer = nullptr;
if (sd->bl.prev == NULL)
return;
@@ -3259,7 +3107,7 @@ void pc_attack_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
if (!battle_config.sdelay_attack_enable)
{
- if (DIFF_TICK(tick, sd->canact_tick) < 0)
+ if (tick < sd->canact_tick)
{
clif_skill_fail(sd, SkillID::ONE, 4, 0);
return;
@@ -3269,7 +3117,7 @@ void pc_attack_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
if (sd->attackabletime > tick)
return; // cannot attack yet
- attack_spell_delay = sd->attack_spell_delay;
+ interval_t attack_spell_delay = sd->attack_spell_delay;
if (sd->attack_spell_override // [Fate] If we have an active attack spell, use that
&& spell_attack(id, sd->attacktarget))
{
@@ -3296,33 +3144,34 @@ void pc_attack_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
// TMW client doesn't support this
//pc_walktoxy(sd,bl->x,bl->y);
clif_movetoattack(sd, bl);
- sd->attackabletime = tick + (sd->aspd << 1);
+ sd->attackabletime = tick + (sd->aspd * 2);
}
else
{
if (battle_config.pc_attack_direction_change)
sd->dir = sd->head_dir = map_calc_dir(&sd->bl, bl->x, bl->y); // 向き設定
- if (sd->walktimer != -1)
+ if (sd->walktimer)
pc_stop_walking(sd, 1);
{
map_freeblock_lock();
pc_stop_walking(sd, 0);
sd->attacktarget_lv =
- battle_weapon_attack(&sd->bl, bl, tick, BCT_ZERO);
+ battle_weapon_attack(&sd->bl, bl, tick);
map_freeblock_unlock();
- sd->attackabletime = tick + (sd->aspd << 1);
+ sd->attackabletime = tick + (sd->aspd * 2);
}
if (sd->attackabletime <= tick)
- sd->attackabletime = tick + (battle_config.max_aspd << 1);
+ sd->attackabletime = tick + static_cast<interval_t>(battle_config.max_aspd) * 2;
}
}
if (sd->state.attack_continue)
{
- sd->attacktimer =
- add_timer(sd->attackabletime, pc_attack_timer, sd->bl.id, 0);
+ sd->attacktimer = add_timer(sd->attackabletime,
+ std::bind(pc_attack_timer, ph::_1, ph::_2,
+ sd->bl.id));
}
}
@@ -3334,7 +3183,6 @@ void pc_attack_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t)
int pc_attack(struct map_session_data *sd, int target_id, int type)
{
struct block_list *bl;
- int d;
nullpo_ret(sd);
@@ -3350,21 +3198,22 @@ int pc_attack(struct map_session_data *sd, int target_id, int type)
if (!battle_check_target(&sd->bl, bl, BCT_ENEMY))
return 1;
- if (sd->attacktimer != -1)
+ if (sd->attacktimer)
pc_stopattack(sd);
sd->attacktarget = target_id;
sd->state.attack_continue = type;
- d = DIFF_TICK(sd->attackabletime, gettick());
- if (d > 0 && d < 2000)
+ interval_t d = sd->attackabletime - gettick();
+ if (d > interval_t::zero() && d < std::chrono::seconds(2))
{ // 攻撃delay中
- sd->attacktimer =
- add_timer(sd->attackabletime, pc_attack_timer, sd->bl.id, 0);
+ sd->attacktimer = add_timer(sd->attackabletime,
+ std::bind(pc_attack_timer, ph::_1, ph::_2,
+ sd->bl.id));
}
else
{
// 本来timer関数なので引数を合わせる
- pc_attack_timer(-1, gettick(), sd->bl.id, 0);
+ pc_attack_timer(nullptr, gettick(), sd->bl.id);
}
return 0;
@@ -3378,10 +3227,10 @@ int pc_stopattack(struct map_session_data *sd)
{
nullpo_ret(sd);
- if (sd->attacktimer != -1)
+ if (sd->attacktimer)
{
- delete_timer(sd->attacktimer, pc_attack_timer);
- sd->attacktimer = -1;
+ delete_timer(sd->attacktimer);
+ sd->attacktimer = nullptr;
}
sd->attacktarget = 0;
sd->state.attack_continue = 0;
@@ -4928,7 +4777,7 @@ int pc_setaccountreg2(struct map_session_data *sd, const char *reg, int val)
*------------------------------------------
*/
static
-void pc_eventtimer(timer_id tid, tick_t, custom_id_t id, custom_data_t data)
+void pc_eventtimer(TimerData *tid, tick_t, int id, const char *data)
{
struct map_session_data *sd = map_id2sd(id);
int i;
@@ -4939,12 +4788,12 @@ void pc_eventtimer(timer_id tid, tick_t, custom_id_t id, custom_data_t data)
{
if (sd->eventtimer[i] == tid)
{
- sd->eventtimer[i] = -1;
- npc_event(sd, (const char *) data, 0);
+ sd->eventtimer[i] = nullptr;
+ npc_event(sd, data, 0);
break;
}
}
- free((void *) data);
+ free(const_cast<char *>(data));
if (i == MAX_EVENTTIMER)
{
if (battle_config.error_log)
@@ -4956,14 +4805,14 @@ void pc_eventtimer(timer_id tid, tick_t, custom_id_t id, custom_data_t data)
* イベントタイマー追加
*------------------------------------------
*/
-int pc_addeventtimer(struct map_session_data *sd, int tick, const char *name)
+int pc_addeventtimer(struct map_session_data *sd, interval_t tick, const char *name)
{
int i;
nullpo_ret(sd);
for (i = 0; i < MAX_EVENTTIMER; i++)
- if (sd->eventtimer[i] == -1)
+ if (!sd->eventtimer[i])
break;
if (i < MAX_EVENTTIMER)
@@ -4972,8 +4821,8 @@ int pc_addeventtimer(struct map_session_data *sd, int tick, const char *name)
strncpy(evname, name, 24);
evname[23] = '\0';
sd->eventtimer[i] = add_timer(gettick() + tick,
- pc_eventtimer, sd->bl.id,
- (int) evname);
+ std::bind(pc_eventtimer, ph::_1, ph::_2,
+ sd->bl.id, evname));
return 1;
}
@@ -4981,54 +4830,6 @@ int pc_addeventtimer(struct map_session_data *sd, int tick, const char *name)
}
/*==========================================
- * イベントタイマー削除
- *------------------------------------------
- */
-int pc_deleventtimer(struct map_session_data *sd, const char *name)
-{
- int i;
-
- nullpo_ret(sd);
-
- for (i = 0; i < MAX_EVENTTIMER; i++)
- if (sd->eventtimer[i] != -1 && strcmp((char
- *) (get_timer(sd->eventtimer
- [i])->data),
- name) == 0)
- {
- delete_timer(sd->eventtimer[i], pc_eventtimer);
- sd->eventtimer[i] = -1;
- break;
- }
-
- return 0;
-}
-
-/*==========================================
- * イベントタイマーカウント値追加
- *------------------------------------------
- */
-int pc_addeventtimercount(struct map_session_data *sd, const char *name,
- int tick)
-{
- int i;
-
- nullpo_ret(sd);
-
- for (i = 0; i < MAX_EVENTTIMER; i++)
- if (sd->eventtimer[i] != -1 && strcmp((char
- *) (get_timer(sd->eventtimer
- [i])->data),
- name) == 0)
- {
- addtick_timer(sd->eventtimer[i], tick);
- break;
- }
-
- return 0;
-}
-
-/*==========================================
* イベントタイマー全削除
*------------------------------------------
*/
@@ -5039,10 +4840,10 @@ int pc_cleareventtimer(struct map_session_data *sd)
nullpo_ret(sd);
for (i = 0; i < MAX_EVENTTIMER; i++)
- if (sd->eventtimer[i] != -1)
+ if (sd->eventtimer[i])
{
- delete_timer(sd->eventtimer[i], pc_eventtimer);
- sd->eventtimer[i] = -1;
+ delete_timer(sd->eventtimer[i]);
+ sd->eventtimer[i] = nullptr;
}
return 0;
@@ -5261,10 +5062,10 @@ int pc_unequipitem(struct map_session_data *sd, int n, CalcStatus type)
}
pc_signal_advanced_equipment_change(sd, n);
- if (sd->sc_data[StatusChange::SC_BROKNWEAPON].timer != -1
+ if (sd->sc_data[StatusChange::SC_BROKNWEAPON].timer
&& bool(sd->status.inventory[n].equip & EPOS::WEAPON)
&& sd->status.inventory[n].broken == 1)
- skill_status_change_end(&sd->bl, StatusChange::SC_BROKNWEAPON, -1);
+ skill_status_change_end(&sd->bl, StatusChange::SC_BROKNWEAPON, nullptr);
clif_unequipitemack(sd, n, sd->status.inventory[n].equip, 1);
sd->status.inventory[n].equip = EPOS::ZERO;
@@ -5468,7 +5269,7 @@ int pc_calc_pvprank(struct map_session_data *sd)
* PVP順位計算(timer)
*------------------------------------------
*/
-void pc_calc_pvprank_timer(timer_id, tick_t, custom_id_t id, custom_data_t data)
+void pc_calc_pvprank_timer(TimerData *, tick_t, int id)
{
struct map_session_data *sd = NULL;
if (battle_config.pk_mode) // disable pvp ranking if pk_mode on [Valaris]
@@ -5477,10 +5278,11 @@ void pc_calc_pvprank_timer(timer_id, tick_t, custom_id_t id, custom_data_t data)
sd = map_id2sd(id);
if (sd == NULL)
return;
- sd->pvp_timer = -1;
+ sd->pvp_timer = nullptr;
if (pc_calc_pvprank(sd) > 0)
sd->pvp_timer = add_timer(gettick() + PVP_CALCRANK_INTERVAL,
- pc_calc_pvprank_timer, id, data);
+ std::bind(pc_calc_pvprank_timer, ph::_1, ph::_2,
+ id));
}
/*==========================================
@@ -5578,15 +5380,16 @@ struct map_session_data *pc_get_partner(struct map_session_data *sd)
*------------------------------------------
*/
static
-int natural_heal_tick, natural_heal_prev_tick, natural_heal_diff_tick;
+tick_t natural_heal_tick, natural_heal_prev_tick;
static
-int pc_spheal(struct map_session_data *sd)
-{
- int a;
+interval_t natural_heal_diff_tick;
- nullpo_ret(sd);
+static
+interval_t pc_spheal(struct map_session_data *sd)
+{
+ nullpo_retr(interval_t::zero(), sd);
- a = natural_heal_diff_tick;
+ interval_t a = natural_heal_diff_tick;
if (pc_issit(sd))
a += a;
@@ -5598,13 +5401,11 @@ int pc_spheal(struct map_session_data *sd)
*------------------------------------------
*/
static
-int pc_hpheal(struct map_session_data *sd)
+interval_t pc_hpheal(struct map_session_data *sd)
{
- int a;
-
- nullpo_ret(sd);
+ nullpo_retr(interval_t::zero(), sd);
- a = natural_heal_diff_tick;
+ interval_t a = natural_heal_diff_tick;
if (pc_issit(sd))
a += a;
@@ -5615,42 +5416,42 @@ static
int pc_natural_heal_hp(struct map_session_data *sd)
{
int bhp;
- int inc_num, bonus;
+ int bonus;
nullpo_ret(sd);
if (pc_checkoverhp(sd))
{
- sd->hp_sub = sd->inchealhptick = 0;
+ sd->hp_sub = sd->inchealhptick = interval_t::zero();
return 0;
}
bhp = sd->status.hp;
- if (sd->walktimer == -1)
+ if (!sd->walktimer)
{
- inc_num = pc_hpheal(sd);
+ interval_t inc_num = pc_hpheal(sd);
sd->hp_sub += inc_num;
sd->inchealhptick += natural_heal_diff_tick;
}
else
{
- sd->hp_sub = sd->inchealhptick = 0;
+ sd->hp_sub = sd->inchealhptick = interval_t::zero();
return 0;
}
- if (sd->hp_sub >= battle_config.natural_healhp_interval)
+ if (sd->hp_sub >= static_cast<interval_t>(battle_config.natural_healhp_interval))
{
bonus = sd->nhealhp;
- while (sd->hp_sub >= battle_config.natural_healhp_interval)
+ while (sd->hp_sub >= static_cast<interval_t>(battle_config.natural_healhp_interval))
{
- sd->hp_sub -= battle_config.natural_healhp_interval;
+ sd->hp_sub -= static_cast<interval_t>(battle_config.natural_healhp_interval);
if (sd->status.hp + bonus <= sd->status.max_hp)
sd->status.hp += bonus;
else
{
sd->status.hp = sd->status.max_hp;
- sd->hp_sub = sd->inchealhptick = 0;
+ sd->hp_sub = sd->inchealhptick = interval_t::zero();
}
}
}
@@ -5659,28 +5460,26 @@ int pc_natural_heal_hp(struct map_session_data *sd)
if (sd->nshealhp > 0)
{
- if (sd->inchealhptick >= battle_config.natural_heal_skill_interval
+ if (sd->inchealhptick >= static_cast<interval_t>(battle_config.natural_heal_skill_interval)
&& sd->status.hp < sd->status.max_hp)
{
bonus = sd->nshealhp;
- while (sd->inchealhptick >=
- battle_config.natural_heal_skill_interval)
+ while (sd->inchealhptick >= static_cast<interval_t>(battle_config.natural_heal_skill_interval))
{
- sd->inchealhptick -=
- battle_config.natural_heal_skill_interval;
+ sd->inchealhptick -= static_cast<interval_t>(battle_config.natural_heal_skill_interval);
if (sd->status.hp + bonus <= sd->status.max_hp)
sd->status.hp += bonus;
else
{
bonus = sd->status.max_hp - sd->status.hp;
sd->status.hp = sd->status.max_hp;
- sd->hp_sub = sd->inchealhptick = 0;
+ sd->hp_sub = sd->inchealhptick = interval_t::zero();
}
}
}
}
else
- sd->inchealhptick = 0;
+ sd->inchealhptick = interval_t::zero();
return 0;
}
@@ -5689,37 +5488,37 @@ static
int pc_natural_heal_sp(struct map_session_data *sd)
{
int bsp;
- int inc_num, bonus;
+ int bonus;
nullpo_ret(sd);
if (pc_checkoversp(sd))
{
- sd->sp_sub = sd->inchealsptick = 0;
+ sd->sp_sub = sd->inchealsptick = interval_t::zero();
return 0;
}
bsp = sd->status.sp;
- inc_num = pc_spheal(sd);
+ interval_t inc_num = pc_spheal(sd);
sd->sp_sub += inc_num;
- if (sd->walktimer == -1)
+ if (!sd->walktimer)
sd->inchealsptick += natural_heal_diff_tick;
else
- sd->inchealsptick = 0;
+ sd->inchealsptick = interval_t::zero();
- if (sd->sp_sub >= battle_config.natural_healsp_interval)
+ if (sd->sp_sub >= static_cast<interval_t>(battle_config.natural_healsp_interval))
{
- bonus = sd->nhealsp;;
- while (sd->sp_sub >= battle_config.natural_healsp_interval)
+ bonus = sd->nhealsp;
+ while (sd->sp_sub >= static_cast<interval_t>(battle_config.natural_healsp_interval))
{
- sd->sp_sub -= battle_config.natural_healsp_interval;
+ sd->sp_sub -= static_cast<interval_t>(battle_config.natural_healsp_interval);
if (sd->status.sp + bonus <= sd->status.max_sp)
sd->status.sp += bonus;
else
{
sd->status.sp = sd->status.max_sp;
- sd->sp_sub = sd->inchealsptick = 0;
+ sd->sp_sub = sd->inchealsptick = interval_t::zero();
}
}
}
@@ -5729,30 +5528,26 @@ int pc_natural_heal_sp(struct map_session_data *sd)
if (sd->nshealsp > 0)
{
- if (sd->inchealsptick >= battle_config.natural_heal_skill_interval
+ if (sd->inchealsptick >= static_cast<interval_t>(battle_config.natural_heal_skill_interval)
&& sd->status.sp < sd->status.max_sp)
{
bonus = sd->nshealsp;
- sd->doridori_counter = 0;
- while (sd->inchealsptick >=
- battle_config.natural_heal_skill_interval)
+ while (sd->inchealsptick >= static_cast<interval_t>(battle_config.natural_heal_skill_interval))
{
- sd->inchealsptick -=
- battle_config.natural_heal_skill_interval;
+ sd->inchealsptick -= static_cast<interval_t>(battle_config.natural_heal_skill_interval);
if (sd->status.sp + bonus <= sd->status.max_sp)
sd->status.sp += bonus;
else
{
bonus = sd->status.max_sp - sd->status.sp;
sd->status.sp = sd->status.max_sp;
- sd->sp_sub = sd->inchealsptick = 0;
+ sd->sp_sub = sd->inchealsptick = interval_t::zero();
}
}
}
}
else
- sd->inchealsptick = 0;
-
+ sd->inchealsptick = interval_t::zero();
return 0;
}
@@ -5809,13 +5604,16 @@ void pc_natural_heal_sub(struct map_session_data *sd)
pc_calcstatus(sd, 0);
}
- if (sd->sc_data[StatusChange::SC_HALT_REGENERATE].timer != -1)
+ if (sd->sc_data[StatusChange::SC_HALT_REGENERATE].timer)
return;
if (sd->quick_regeneration_hp.amount || sd->quick_regeneration_sp.amount)
{
int hp_bonus = pc_quickregenerate_effect(&sd->quick_regeneration_hp,
- (sd->sc_data[StatusChange::SC_POISON].timer == -1 || sd->sc_data[StatusChange::SC_SLOWPOISON].timer != -1) ? sd->nhealhp : 1); // [fate] slow down when poisoned
+ (!sd->sc_data[StatusChange::SC_POISON].timer == -1
+ || sd->sc_data[StatusChange::SC_SLOWPOISON].timer)
+ ? sd->nhealhp
+ : 1); // [fate] slow down when poisoned
int sp_bonus = pc_quickregenerate_effect(&sd->quick_regeneration_sp,
sd->nhealsp);
@@ -5823,23 +5621,20 @@ void pc_natural_heal_sub(struct map_session_data *sd)
}
skill_update_heal_animation(sd); // if needed.
-// -- moonsoul (if conditions below altered to disallow natural healing if under berserk status)
- if ((sd->sc_data[StatusChange::SC_FLYING_BACKPACK].timer != -1
- || battle_config.natural_heal_weight_rate > 100
- || sd->weight * 100 / sd->max_weight <
- battle_config.natural_heal_weight_rate) && !pc_isdead(sd)
- && sd->sc_data[StatusChange::SC_POISON].timer == -1)
+ if ((sd->sc_data[StatusChange::SC_FLYING_BACKPACK].timer
+ || battle_config.natural_heal_weight_rate > 100
+ || sd->weight * 100 / sd->max_weight < battle_config.natural_heal_weight_rate)
+ && !pc_isdead(sd)
+ && !sd->sc_data[StatusChange::SC_POISON].timer)
{
pc_natural_heal_hp(sd);
pc_natural_heal_sp(sd);
}
else
{
- sd->hp_sub = sd->inchealhptick = 0;
- sd->sp_sub = sd->inchealsptick = 0;
+ sd->hp_sub = sd->inchealhptick = interval_t::zero();
+ sd->sp_sub = sd->inchealsptick = interval_t::zero();
}
- sd->inchealspirithptick = 0;
- sd->inchealspiritsptick = 0;
}
/*==========================================
@@ -5847,11 +5642,10 @@ void pc_natural_heal_sub(struct map_session_data *sd)
*------------------------------------------
*/
static
-void pc_natural_heal(timer_id, tick_t tick, custom_id_t, custom_data_t)
+void pc_natural_heal(TimerData *, tick_t tick)
{
natural_heal_tick = tick;
- natural_heal_diff_tick =
- DIFF_TICK(natural_heal_tick, natural_heal_prev_tick);
+ natural_heal_diff_tick = natural_heal_tick - natural_heal_prev_tick;
clif_foreachclient(pc_natural_heal_sub);
natural_heal_prev_tick = tick;
@@ -5899,19 +5693,17 @@ void pc_autosave_sub(struct map_session_data *sd)
*------------------------------------------
*/
static
-void pc_autosave(timer_id, tick_t, custom_id_t, custom_data_t)
+void pc_autosave(TimerData *, tick_t)
{
- int interval;
-
save_flag = 0;
clif_foreachclient(pc_autosave_sub);
if (save_flag == 0)
last_save_fd = 0;
- interval = autosave_interval / (clif_countusers() + 1);
- if (interval <= 0)
- interval = 1;
- add_timer(gettick() + interval, pc_autosave, 0, 0);
+ interval_t interval = autosave_interval / (clif_countusers() + 1);
+ if (interval <= interval_t::zero())
+ interval = std::chrono::milliseconds(1);
+ add_timer(gettick() + interval, pc_autosave);
}
int pc_read_gm_account(int fd)
@@ -5932,72 +5724,6 @@ int pc_read_gm_account(int fd)
return GM_num;
}
-/*==========================================
- * timer to do the day
- *------------------------------------------
- */
-static
-void map_day_timer(timer_id, tick_t, custom_id_t, custom_data_t)
-{
- // by [yor]
- struct map_session_data *pl_sd = NULL;
- int i;
- char tmpstr[1024];
-
- if (battle_config.day_duration > 0)
- { // if we want a day
- if (night_flag != 0)
- {
- strcpy(tmpstr, "The day has arrived!");
- night_flag = 0; // 0=day, 1=night [Yor]
- for (i = 0; i < fd_max; i++)
- {
- if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
- && pl_sd->state.auth)
- {
- pl_sd->opt2 &= ~Opt2::BLIND;
- clif_changeoption(&pl_sd->bl);
- clif_wis_message(pl_sd->fd, wisp_server_name, tmpstr,
- strlen(tmpstr) + 1);
- }
- }
- }
- }
-}
-
-/*==========================================
- * timer to do the night
- *------------------------------------------
- */
-static
-void map_night_timer(timer_id, tick_t, custom_id_t, custom_data_t)
-{
- // by [yor]
- struct map_session_data *pl_sd = NULL;
- int i;
- char tmpstr[1024];
-
- if (battle_config.night_duration > 0)
- { // if we want a night
- if (night_flag == 0)
- {
- strcpy(tmpstr, "The night has fallen...");
- night_flag = 1; // 0=day, 1=night [Yor]
- for (i = 0; i < fd_max; i++)
- {
- if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
- && pl_sd->state.auth)
- {
- pl_sd->opt2 |= Opt2::BLIND;
- clif_changeoption(&pl_sd->bl);
- clif_wis_message(pl_sd->fd, wisp_server_name, tmpstr,
- strlen(tmpstr) + 1);
- }
- }
- }
- }
-}
-
void pc_setstand(struct map_session_data *sd)
{
nullpo_retv(sd);
@@ -6029,44 +5755,12 @@ int pc_calc_sigma(void)
int do_init_pc(void)
{
pc_calc_sigma();
-
- add_timer_interval((natural_heal_prev_tick =
- gettick() + NATURAL_HEAL_INTERVAL), pc_natural_heal,
- 0, 0, NATURAL_HEAL_INTERVAL);
- add_timer(gettick() + autosave_interval, pc_autosave, 0, 0);
-
- {
- int day_duration = battle_config.day_duration;
- int night_duration = battle_config.night_duration;
- if (day_duration < 60000)
- day_duration = 60000;
- if (night_duration < 60000)
- night_duration = 60000;
- if (battle_config.night_at_start == 0)
- {
- night_flag = 0; // 0=day, 1=night [Yor]
- day_timer_tid =
- add_timer_interval(gettick() + day_duration +
- night_duration, map_day_timer, 0, 0,
- day_duration + night_duration);
- night_timer_tid =
- add_timer_interval(gettick() + day_duration,
- map_night_timer, 0, 0,
- day_duration + night_duration);
- }
- else
- {
- night_flag = 1; // 0=day, 1=night [Yor]
- day_timer_tid =
- add_timer_interval(gettick() + night_duration,
- map_day_timer, 0, 0,
- day_duration + night_duration);
- night_timer_tid =
- add_timer_interval(gettick() + day_duration +
- night_duration, map_night_timer, 0, 0,
- day_duration + night_duration);
- }
- }
+ natural_heal_prev_tick = gettick() + NATURAL_HEAL_INTERVAL;
+ add_timer_interval(natural_heal_prev_tick,
+ pc_natural_heal,
+ NATURAL_HEAL_INTERVAL);
+ add_timer(gettick() + autosave_interval,
+ pc_autosave);
return 0;
}
@@ -6097,7 +5791,7 @@ int pc_logout(struct map_session_data *sd) // [fate] Player logs out
if (!sd)
return 0;
- if (sd->sc_data[StatusChange::SC_POISON].timer != -1)
+ if (sd->sc_data[StatusChange::SC_POISON].timer)
sd->status.hp = 1; // Logging out while poisoned -> bad
/*
diff --git a/src/map/pc.hpp b/src/map/pc.hpp
index bc565ab..18e72e9 100644
--- a/src/map/pc.hpp
+++ b/src/map/pc.hpp
@@ -55,7 +55,7 @@ int pc_counttargeted(struct map_session_data *sd, struct block_list *src,
ATK target_lv);
int pc_setrestartvalue(struct map_session_data *sd, int type);
int pc_makesavestatus(struct map_session_data *);
-int pc_setnewpc(struct map_session_data *, int, int, int, int, int, int);
+int pc_setnewpc(struct map_session_data *, int, int, int, tick_t, int);
int pc_authok(int, int, time_t, short tmw_version, const struct mmo_charstatus *);
int pc_authfail(int);
@@ -142,15 +142,12 @@ int pc_setaccountreg(struct map_session_data *, const char *, int);
int pc_readaccountreg2(struct map_session_data *, const char *);
int pc_setaccountreg2(struct map_session_data *, const char *, int);
-int pc_addeventtimer(struct map_session_data *sd, int tick,
+int pc_addeventtimer(struct map_session_data *sd, interval_t tick,
const char *name);
-int pc_deleventtimer(struct map_session_data *sd, const char *name);
int pc_cleareventtimer(struct map_session_data *sd);
-int pc_addeventtimercount(struct map_session_data *sd, const char *name,
- int tick);
int pc_calc_pvprank(struct map_session_data *sd);
-void pc_calc_pvprank_timer(timer_id, tick_t, custom_id_t, custom_data_t);
+void pc_calc_pvprank_timer(TimerData *, tick_t, int);
int pc_marriage(struct map_session_data *sd,
struct map_session_data *dstsd);
@@ -161,16 +158,10 @@ void pc_setstand(struct map_session_data *sd);
void pc_cleanup(struct map_session_data *sd); // [Fate] Clean up after a logged-out PC
int pc_read_gm_account(int fd);
-int pc_setinvincibletimer(struct map_session_data *sd, int);
+int pc_setinvincibletimer(struct map_session_data *sd, interval_t);
int pc_delinvincibletimer(struct map_session_data *sd);
-int pc_addspiritball(struct map_session_data *sd, int, int);
-int pc_delspiritball(struct map_session_data *sd, int, int);
int pc_logout(struct map_session_data *sd); // [fate] Player logs out
int do_init_pc(void);
-// timer for night.day
-extern timer_id day_timer_tid;
-extern timer_id night_timer_tid;
-
#endif // PC_HPP
diff --git a/src/map/script.cpp b/src/map/script.cpp
index 3228160..22e2f16 100644
--- a/src/map/script.cpp
+++ b/src/map/script.cpp
@@ -15,6 +15,7 @@
#include "../common/mt_rand.hpp"
#include "../common/socket.hpp"
#include "../common/utils.hpp"
+#include "../common/timer.hpp"
#include "atcommand.hpp"
#include "battle.hpp"
@@ -72,7 +73,7 @@ struct dbt *mapregstr_db = NULL;
static
int mapreg_dirty = -1;
char mapreg_txt[256] = "save/mapreg.txt";
-constexpr int MAPREG_AUTOSAVE_INTERVAL = 10 * 1000;
+constexpr std::chrono::milliseconds MAPREG_AUTOSAVE_INTERVAL = std::chrono::seconds(10);
static
struct dbt *scriptlabel_db = NULL;
@@ -2662,7 +2663,7 @@ void builtin_gettimetick(ScriptState *st) /* Asgard Version */
/* System tick(unsigned int, and yes, it will wrap). */
case 0:
default:
- push_val(st->stack, ScriptCode::INT, gettick());
+ push_val(st->stack, ScriptCode::INT, (int) gettick().time_since_epoch().count());
break;
}
}
@@ -2837,8 +2838,8 @@ void builtin_killmonster_sub(struct block_list *bl, const char *event, int allfl
}
else if (allflag)
{
- if (((struct mob_data *) bl)->spawndelay1 == -1
- && ((struct mob_data *) bl)->spawndelay2 == -1)
+ if (((struct mob_data *) bl)->spawndelay1 == static_cast<interval_t>(-1)
+ && ((struct mob_data *) bl)->spawndelay2 == static_cast<interval_t>(-1))
mob_delete((struct mob_data *) bl);
return;
}
@@ -2895,8 +2896,7 @@ void builtin_donpcevent(ScriptState *st)
static
void builtin_addtimer(ScriptState *st)
{
- int tick;
- tick = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ interval_t tick = static_cast<interval_t>(conv_num(st, &(st->stack->stack_data[st->start + 2])));
const char *event = conv_str(st, &(st->stack->stack_data[st->start + 3]));
pc_addeventtimer(script_rid2sd(st), tick, event);
}
@@ -2914,7 +2914,7 @@ void builtin_initnpctimer(ScriptState *st)
else
nd = (struct npc_data *) map_id2bl(st->oid);
- npc_settimerevent_tick(nd, 0);
+ npc_settimerevent_tick(nd, interval_t::zero());
npc_timerevent_start(nd);
}
@@ -2968,7 +2968,7 @@ void builtin_getnpctimer(ScriptState *st)
switch (type)
{
case 0:
- val = npc_gettimerevent_tick(nd);
+ val = (int) npc_gettimerevent_tick(nd).count();
break;
case 1:
val = (nd->u.scr.nexttimer >= 0);
@@ -2987,9 +2987,8 @@ void builtin_getnpctimer(ScriptState *st)
static
void builtin_setnpctimer(ScriptState *st)
{
- int tick;
struct npc_data *nd;
- tick = conv_num(st, &(st->stack->stack_data[st->start + 2]));
+ interval_t tick = static_cast<interval_t>(conv_num(st, &(st->stack->stack_data[st->start + 2])));
if (st->end > st->start + 3)
nd = npc_name2id(conv_str(st, &(st->stack->stack_data[st->start + 3])));
else
@@ -3224,15 +3223,24 @@ static
void builtin_sc_start(ScriptState *st)
{
struct block_list *bl;
- int tick, val1;
- StatusChange type = StatusChange(conv_num(st, &(st->stack->stack_data[st->start + 2])));
- tick = conv_num(st, &(st->stack->stack_data[st->start + 3]));
+ int val1;
+ StatusChange type = static_cast<StatusChange>(conv_num(st, &(st->stack->stack_data[st->start + 2])));
+ interval_t tick = static_cast<interval_t>(conv_num(st, &(st->stack->stack_data[st->start + 3])));
+ if (tick < std::chrono::seconds(1))
+ // work around old behaviour of:
+ // speed potion
+ // atk potion
+ // matk potion
+ //
+ // which used to use seconds
+ // all others used milliseconds
+ tick *= 1000;
val1 = conv_num(st, &(st->stack->stack_data[st->start + 4]));
if (st->end > st->start + 5) //指定したキャラを状態異常にする
bl = map_id2bl(conv_num(st, &(st->stack->stack_data[st->start + 5])));
else
bl = map_id2bl(st->rid);
- skill_status_change_start(bl, type, val1, 0, 0, 0, tick, 0);
+ skill_status_change_start(bl, type, val1, tick);
}
/*==========================================
@@ -3245,9 +3253,7 @@ void builtin_sc_end(ScriptState *st)
struct block_list *bl;
StatusChange type = StatusChange(conv_num(st, &(st->stack->stack_data[st->start + 2])));
bl = map_id2bl(st->rid);
- skill_status_change_end(bl, type, -1);
-// if(battle_config.etc_log)
-// PRINTF("sc_end : %d %d\n",st->rid,type);
+ skill_status_change_end(bl, type, nullptr);
}
static
@@ -3579,11 +3585,11 @@ void builtin_pvpon(ScriptState *st)
if (session[i] && (pl_sd = (struct map_session_data *)session[i]->session_data)
&& pl_sd->state.auth)
{
- if (m == pl_sd->bl.m && pl_sd->pvp_timer == -1)
+ if (m == pl_sd->bl.m && !pl_sd->pvp_timer)
{
- pl_sd->pvp_timer =
- add_timer(gettick() + 200, pc_calc_pvprank_timer,
- pl_sd->bl.id, 0);
+ pl_sd->pvp_timer = add_timer(gettick() + std::chrono::milliseconds(200),
+ std::bind(pc_calc_pvprank_timer, ph::_1, ph::_2,
+ pl_sd->bl.id));
pl_sd->pvp_rank = 0;
pl_sd->pvp_lastusers = 0;
pl_sd->pvp_point = 5;
@@ -3616,11 +3622,10 @@ void builtin_pvpoff(ScriptState *st)
{
if (m == pl_sd->bl.m)
{
- if (pl_sd->pvp_timer != -1)
+ if (pl_sd->pvp_timer)
{
- delete_timer(pl_sd->pvp_timer,
- pc_calc_pvprank_timer);
- pl_sd->pvp_timer = -1;
+ delete_timer(pl_sd->pvp_timer);
+ pl_sd->pvp_timer = nullptr;
}
}
}
@@ -4226,7 +4231,7 @@ void builtin_getsavepoint(ScriptState *st)
*------------------------------------------
*/
static
-void builtin_areatimer_sub(struct block_list *bl, int tick, const char *event)
+void builtin_areatimer_sub(struct block_list *bl, interval_t tick, const char *event)
{
pc_addeventtimer((struct map_session_data *) bl, tick, event);
}
@@ -4234,7 +4239,7 @@ void builtin_areatimer_sub(struct block_list *bl, int tick, const char *event)
static
void builtin_areatimer(ScriptState *st)
{
- int tick, m;
+ int m;
int x0, y0, x1, y1;
const char *mapname = conv_str(st, &(st->stack->stack_data[st->start + 2]));
@@ -4242,7 +4247,7 @@ void builtin_areatimer(ScriptState *st)
y0 = conv_num(st, &(st->stack->stack_data[st->start + 4]));
x1 = conv_num(st, &(st->stack->stack_data[st->start + 5]));
y1 = conv_num(st, &(st->stack->stack_data[st->start + 6]));
- tick = conv_num(st, &(st->stack->stack_data[st->start + 7]));
+ interval_t tick = static_cast<interval_t>(conv_num(st, &(st->stack->stack_data[st->start + 7])));
const char *event = conv_str(st, &(st->stack->stack_data[st->start + 8]));
if ((m = map_mapname2mapid(mapname)) < 0)
@@ -5037,7 +5042,7 @@ void script_save_mapreg(void)
}
static
-void script_autosave_mapreg(timer_id, tick_t, custom_id_t, custom_data_t)
+void script_autosave_mapreg(TimerData *, tick_t)
{
if (mapreg_dirty)
script_save_mapreg();
@@ -5110,8 +5115,8 @@ void do_init_script(void)
script_load_mapreg();
add_timer_interval(gettick() + MAPREG_AUTOSAVE_INTERVAL,
- script_autosave_mapreg, 0, 0,
- MAPREG_AUTOSAVE_INTERVAL);
+ script_autosave_mapreg,
+ MAPREG_AUTOSAVE_INTERVAL);
scriptlabel_db = strdb_init(50);
}
diff --git a/src/map/skill.cpp b/src/map/skill.cpp
index ed9e551..d1d5c38 100644
--- a/src/map/skill.cpp
+++ b/src/map/skill.cpp
@@ -1,5 +1,6 @@
#include "skill.hpp"
+#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
@@ -8,6 +9,7 @@
#include "../common/mt_rand.hpp"
#include "../common/nullpo.hpp"
#include "../common/socket.hpp"
+#include "../common/timer.hpp"
#include "battle.hpp"
#include "clif.hpp"
@@ -56,13 +58,13 @@ earray<struct skill_db, SkillID, SkillID::MAX_SKILL_DB> skill_db;
static
int skill_attack(BF attack_type, struct block_list *src,
struct block_list *dsrc, struct block_list *bl,
- SkillID skillid, int skilllv, unsigned int tick, BCT flag);
+ SkillID skillid, int skilllv, tick_t tick, BCT flag);
static
void skill_devotion_end(struct map_session_data *md,
struct map_session_data *sd, int target);
static
-void skill_status_change_timer(timer_id tid, tick_t tick,
- custom_id_t id, custom_data_t data);
+void skill_status_change_timer(TimerData *tid, tick_t tick,
+ int id, StatusChange type);
int skill_get_hit(SkillID id)
{
@@ -145,8 +147,7 @@ int distance(int x0, int y0, int x1, int y1)
*------------------------------------------
*/
int skill_additional_effect(struct block_list *src, struct block_list *bl,
- SkillID skillid, int skilllv, BF,
- unsigned int)
+ SkillID skillid, int skilllv)
{
struct map_session_data *sd = NULL;
struct mob_data *md = NULL;
@@ -174,7 +175,7 @@ int skill_additional_effect(struct block_list *src, struct block_list *bl,
}
sc_def_phys_shield_spell = 0;
- if (battle_get_sc_data(bl)[StatusChange::SC_PHYS_SHIELD].timer != -1)
+ if (battle_get_sc_data(bl)[StatusChange::SC_PHYS_SHIELD].timer)
sc_def_phys_shield_spell =
battle_get_sc_data(bl)[StatusChange::SC_PHYS_SHIELD].val1;
@@ -208,11 +209,9 @@ int skill_additional_effect(struct block_list *src, struct block_list *bl,
switch (skillid)
{
case SkillID::NPC_POISON:
- if (MRAND(100) <
- 50 - (sc_def_vit >> 2) - (sc_def_phys_shield_spell) +
- (skilllv >> 2))
- skill_status_change_start(bl, StatusChange::SC_POISON,
- skilllv, 0, 0, 0, skilllv, 0);
+ // blame Fate for this
+ if (MRAND(100) < 50 - (sc_def_vit >> 2) - (sc_def_phys_shield_spell) + (skilllv >> 2))
+ skill_status_change_start(bl, StatusChange::SC_POISON, skilllv, static_cast<interval_t>(skilllv));
break;
}
@@ -233,7 +232,7 @@ int skill_additional_effect(struct block_list *src, struct block_list *bl,
int skill_attack(BF attack_type, struct block_list *src,
struct block_list *dsrc, struct block_list *bl,
- SkillID skillid, int skilllv, unsigned int tick, BCT flag)
+ SkillID skillid, int skilllv, tick_t tick, BCT flag)
{
struct Damage dmg;
eptr<struct status_change, StatusChange> sc_data;
@@ -298,8 +297,7 @@ int skill_attack(BF attack_type, struct block_list *src,
if (bl->type != BL::PC || (sd && !pc_isdead(sd)))
{
if (damage > 0)
- skill_additional_effect(src, bl, skillid, skilllv,
- attack_type, tick);
+ skill_additional_effect(src, bl, skillid, skilllv);
if (bl->type == BL::MOB && src != bl) /* スキル使用条件のMOBスキル */
{
struct mob_data *md = (struct mob_data *) bl;
@@ -310,11 +308,11 @@ int skill_attack(BF attack_type, struct block_list *src,
target = md->target_id;
if (src->type == BL::PC)
md->target_id = src->id;
- mobskill_use(md, tick, MobSkillCondition::ANY, skillid);
+ mobskill_use(md, tick, MobSkillCondition::ANY);
md->target_id = target;
}
else
- mobskill_use(md, tick, MobSkillCondition::ANY, skillid);
+ mobskill_use(md, tick, MobSkillCondition::ANY);
}
}
}
@@ -359,12 +357,12 @@ int skill_attack(BF attack_type, struct block_list *src,
typedef int(*SkillFunc)(struct block_list *, struct block_list *,
SkillID, int,
- unsigned int, BCT);
+ tick_t, BCT);
static
void skill_area_sub(struct block_list *bl,
struct block_list *src, SkillID skill_id, int skill_lv,
- unsigned int tick, BCT flag, SkillFunc func)
+ tick_t tick, BCT flag, SkillFunc func)
{
nullpo_retv(bl);
@@ -375,6 +373,7 @@ void skill_area_sub(struct block_list *bl,
func(src, bl, skill_id, skill_lv, tick, flag);
}
+
/* 範囲スキル使用処理小分けここまで
* -------------------------------------------------------------------------
*/
@@ -391,7 +390,7 @@ static int skill_area_temp_id, skill_area_temp_hp;
*/
int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
SkillID skillid, int skilllv,
- unsigned int tick, BCT flag)
+ tick_t tick, BCT flag)
{
struct map_session_data *sd = NULL;
@@ -438,7 +437,8 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
{
skill_area_temp_id = bl->id;
skill_area_temp_hp = battle_get_hp(src);
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv,
+ tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
bl->m, bl->x - 5, bl->y - 5,
bl->x + 5, bl->y + 5, BL::NUL);
battle_damage(src, src, md->hp, 0);
@@ -460,7 +460,8 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
{
// TODO does this happen?
skill_area_temp_id = bl->id;
- map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv, tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
+ map_foreachinarea(std::bind(skill_area_sub, ph::_1, src, skillid, skilllv,
+ tick, flag | BCT_ENEMY | BCT_lo_x01, skill_castend_damage_id),
bl->m, bl->x - 0, bl->y - 0,
bl->x + 0, bl->y + 0, BL::NUL);
}
@@ -483,8 +484,7 @@ int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
// skillid.nk == 1
// so skillid in (SkillID::NPC_SUMMONSLAVE, SkillID::NPC_EMOTION)
int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
- SkillID skillid, int skilllv,
- unsigned int, BCT)
+ SkillID skillid, int skilllv)
{
struct map_session_data *sd = NULL;
struct map_session_data *dstsd = NULL;
@@ -561,7 +561,7 @@ int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
* 詠唱時間計算
*------------------------------------------
*/
-int skill_castfix(struct block_list *bl, int time)
+interval_t skill_castfix(struct block_list *bl, interval_t time)
{
struct mob_data *md; // [Valaris]
eptr<struct status_change, StatusChange> sc_data;
@@ -570,7 +570,7 @@ int skill_castfix(struct block_list *bl, int time)
SkillID skill;
int lv, castnodex;
- nullpo_ret(bl);
+ nullpo_retr(interval_t::zero(), bl);
if (bl->type == BL::MOB)
{ // Crash fix [Valaris]
@@ -588,12 +588,12 @@ int skill_castfix(struct block_list *bl, int time)
dex = battle_get_dex(bl);
if (skill > SkillID::MAX_SKILL_DB /*|| skill < SkillID()*/)
- return 0;
+ return interval_t::zero();
castnodex = skill_get_castnodex(skill, lv);
- if (time == 0)
- return 0;
+ if (time == interval_t::zero())
+ return interval_t::zero();
if (castnodex > 0 && bl->type == BL::PC)
castrate = 100;
else if (castnodex <= 0 && bl->type == BL::PC)
@@ -606,22 +606,22 @@ int skill_castfix(struct block_list *bl, int time)
time = time * battle_config.cast_rate / 100;
}
- return (time > 0) ? time : 0;
+ return std::max(time, interval_t::zero());
}
/*==========================================
* ディレイ計算
*------------------------------------------
*/
-int skill_delayfix(struct block_list *bl, int time)
+interval_t skill_delayfix(struct block_list *bl, interval_t time)
{
eptr<struct status_change, StatusChange> sc_data;
- nullpo_ret(bl);
+ nullpo_retr(interval_t::zero(), bl);
sc_data = battle_get_sc_data(bl);
- if (time <= 0)
- return 0;
+ if (time <= interval_t::zero())
+ return interval_t::zero();
if (bl->type == BL::PC)
{
@@ -633,7 +633,7 @@ int skill_delayfix(struct block_list *bl, int time)
time = time * battle_config.delay_rate / 100;
}
- return (time > 0) ? time : 0;
+ return std::max(time, interval_t::zero());
}
/*==========================================
@@ -642,15 +642,12 @@ int skill_delayfix(struct block_list *bl, int time)
*/
int skill_castcancel(struct block_list *bl, int)
{
- int inf;
-
nullpo_ret(bl);
if (bl->type == BL::PC)
{
struct map_session_data *sd = (struct map_session_data *) bl;
- unsigned long tick = gettick();
- nullpo_ret(sd);
+ tick_t tick = gettick();
sd->canact_tick = tick;
sd->canmove_tick = tick;
@@ -659,14 +656,10 @@ int skill_castcancel(struct block_list *bl, int)
else if (bl->type == BL::MOB)
{
struct mob_data *md = (struct mob_data *) bl;
- nullpo_ret(md);
- if (md->skilltimer != -1)
+ if (md->skilltimer)
{
- if ((inf = skill_get_inf(md->skillid)) == 2 || inf == 32)
- delete_timer(md->skilltimer, mobskill_castend_pos);
- else
- delete_timer(md->skilltimer, mobskill_castend_id);
- md->skilltimer = -1;
+ delete_timer(md->skilltimer);
+ md->skilltimer = nullptr;
clif_skillcastcancel(bl);
}
return 0;
@@ -765,10 +758,10 @@ int skill_status_change_active(struct block_list *bl, StatusChange type)
if (not sc_data)
return 0;
- return sc_data[type].timer != -1;
+ return sc_data[type].timer != nullptr;
}
-int skill_status_change_end(struct block_list *bl, StatusChange type, int tid)
+int skill_status_change_end(struct block_list *bl, StatusChange type, TimerData *tid)
{
eptr<struct status_change, StatusChange> sc_data;
int opt_flag = 0, calc_flag = 0;
@@ -799,15 +792,16 @@ int skill_status_change_end(struct block_list *bl, StatusChange type, int tid)
opt3 = battle_get_opt3(bl);
nullpo_ret(opt3);
- if ((*sc_count) > 0 && sc_data[type].timer != -1
- && (sc_data[type].timer == tid || tid == -1))
+ if ((*sc_count) > 0 && sc_data[type].timer
+ && (sc_data[type].timer == tid || !tid))
{
- if (tid == -1) // タイマから呼ばれていないならタイマ削除をする
- delete_timer(sc_data[type].timer, skill_status_change_timer);
+ if (!tid)
+ // タイマから呼ばれていないならタイマ削除をする
+ delete_timer(sc_data[type].timer);
/* 該当の異常を正常に戻す */
- sc_data[type].timer = -1;
+ sc_data[type].timer = nullptr;
(*sc_count)--;
switch (type)
@@ -819,27 +813,9 @@ int skill_status_change_end(struct block_list *bl, StatusChange type, int tid)
case StatusChange::SC_HASTE:
calc_flag = 1;
break;
- case StatusChange::SC_NOCHAT: //チャット禁止状態
- break;
- case StatusChange::SC_SELFDESTRUCTION: /* 自爆 */
- {
- //自分のダメージは0にして
- struct mob_data *md = NULL;
- if (bl->type == BL::MOB && (md = (struct mob_data *) bl))
- skill_castend_damage_id(bl, bl,
- static_cast<SkillID>(sc_data[type].val2), sc_data[type].val1,
- gettick(), BCT_ZERO);
- }
- break;
- /* option1 */
- case StatusChange::SC_FREEZE:
- sc_data[type].val3 = 0;
- break;
/* option2 */
case StatusChange::SC_POISON: /* 毒 */
- case StatusChange::SC_BLIND: /* 暗黒 */
- case StatusChange::SC_CURSE:
calc_flag = 1;
break;
}
@@ -848,37 +824,14 @@ int skill_status_change_end(struct block_list *bl, StatusChange type, int tid)
clif_status_change(bl, type, 0); /* アイコン消去 */
switch (type)
- { /* 正常に戻るときなにか処理が必要 */
- case StatusChange::SC_STONE:
- case StatusChange::SC_FREEZE:
- case StatusChange::SC_STAN:
- case StatusChange::SC_SLEEP:
- *opt1 = Opt1::ZERO;
- opt_flag = 1;
- break;
-
+ {
case StatusChange::SC_POISON:
*opt2 &= ~Opt2::_poison;
opt_flag = 1;
break;
- case StatusChange::SC_CURSE:
- *opt2 &= ~Opt2::_curse;
- opt_flag = 1;
- break;
-
- case StatusChange::SC_SILENCE:
- *opt2 &= ~Opt2::_silence;
- opt_flag = 1;
- break;
-
- case StatusChange::SC_BLIND:
- *opt2 &= ~Opt2::BLIND;
- opt_flag = 1;
- break;
-
case StatusChange::SC_SLOWPOISON:
- if (sc_data[StatusChange::SC_POISON].timer != -1)
+ if (sc_data[StatusChange::SC_POISON].timer)
*opt2 |= Opt2::_poison;
*opt2 &= ~Opt2::_slowpoison;
opt_flag = 1;
@@ -895,14 +848,6 @@ int skill_status_change_end(struct block_list *bl, StatusChange type, int tid)
break;
}
- if (night_flag == 1
- && !bool(*opt2 & Opt2::BLIND)
- && bl->type == BL::PC)
- { // by [Yor]
- *opt2 |= Opt2::BLIND;
- opt_flag = 1;
- }
-
if (opt_flag) /* optionの変更を伝える */
clif_changeoption(bl);
@@ -936,9 +881,8 @@ int skill_update_heal_animation(struct map_session_data *sd)
* ステータス異常終了タイマー
*------------------------------------------
*/
-void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom_data_t data)
+void skill_status_change_timer(TimerData *tid, tick_t tick, int id, StatusChange type)
{
- StatusChange type = static_cast<StatusChange>(data);
struct block_list *bl;
struct map_session_data *sd = NULL;
eptr<struct status_change, StatusChange> sc_data;
@@ -956,12 +900,7 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom
//sc_count=battle_get_sc_count(bl); //使ってない?
- if (sc_data[type].timer != tid)
- {
- if (battle_config.error_log)
- PRINTF("skill_status_change_timer %d != %d\n", tid,
- sc_data[type].timer);
- }
+ assert (sc_data[type].timer == tid);
if (sc_data[type].spell_invocation)
{ // Must report termination
@@ -971,51 +910,9 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom
}
switch (type)
- { /* 特殊な処理になる場合 */
- case StatusChange::SC_STONE:
- if (sc_data[type].val2 != 0)
- {
- Opt1 *opt1 = battle_get_opt1(bl);
- sc_data[type].val2 = 0;
- sc_data[type].val4 = 0;
- battle_stopwalking(bl, 1);
- if (opt1)
- {
- *opt1 = Opt1::_stone1;
- clif_changeoption(bl);
- }
- sc_data[type].timer =
- add_timer(1000 + tick, skill_status_change_timer, bl->id,
- data);
- return;
- }
- else if ((--sc_data[type].val3) > 0)
- {
- int hp = battle_get_max_hp(bl);
- if ((++sc_data[type].val4) % 5 == 0
- && battle_get_hp(bl) > hp >> 2)
- {
- hp = hp / 100;
- if (hp < 1)
- hp = 1;
- if (bl->type == BL::PC)
- pc_heal((struct map_session_data *) bl, -hp, 0);
- else if (bl->type == BL::MOB)
- {
- struct mob_data *md;
- if ((md = ((struct mob_data *) bl)) == NULL)
- break;
- md->hp -= hp;
- }
- }
- sc_data[type].timer =
- add_timer(1000 + tick, skill_status_change_timer, bl->id,
- data);
- return;
- }
- break;
+ {
case StatusChange::SC_POISON:
- if (sc_data[StatusChange::SC_SLOWPOISON].timer == -1)
+ if (!sc_data[StatusChange::SC_SLOWPOISON].timer)
{
const int resist_poison =
skill_power_bl(bl, SkillID::TMW_RESIST_POISON) >> 3;
@@ -1042,15 +939,15 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom
md->hp -= hp;
}
}
- sc_data[type].timer =
- add_timer(1000 + tick, skill_status_change_timer,
- bl->id, data);
+ sc_data[type].timer = add_timer(tick + std::chrono::seconds(1),
+ std::bind(skill_status_change_timer, ph::_1, ph::_2,
+ bl->id, type));
}
}
else
- sc_data[type].timer =
- add_timer(2000 + tick, skill_status_change_timer, bl->id,
- data);
+ sc_data[type].timer = add_timer(tick + std::chrono::seconds(2),
+ std::bind(skill_status_change_timer, ph::_1, ph::_2,
+ bl->id, type));
break;
/* 時間切れ無し?? */
@@ -1059,45 +956,11 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom
case StatusChange::SC_BROKNWEAPON:
case StatusChange::SC_BROKNARMOR:
if (sc_data[type].timer == tid)
- sc_data[type].timer =
- add_timer(1000 * 600 + tick, skill_status_change_timer,
- bl->id, data);
+ sc_data[type].timer = add_timer(tick + std::chrono::minutes(10),
+ std::bind(skill_status_change_timer, ph::_1, ph::_2,
+ bl->id, type));
return;
- case StatusChange::SC_NOCHAT: //チャット禁止状態
- if (sd && battle_config.muting_players)
- {
- time_t timer;
- if ((++sd->status.manner)
- && time(&timer) <
- ((sc_data[type].val2) + 60 * (0 - sd->status.manner)))
- { //開始からstatus.manner分経ってないので継続
- sc_data[type].timer = add_timer( /* タイマー再設定(60秒) */
- 60000 + tick,
- skill_status_change_timer,
- bl->id, data);
- return;
- }
- }
- break;
- case StatusChange::SC_SELFDESTRUCTION: /* 自爆 */
- if (--sc_data[type].val3 > 0)
- {
- struct mob_data *md;
- if (bl->type == BL::MOB && (md = (struct mob_data *) bl)
- && md->stats[mob_stat::SPEED] > 250)
- {
- md->stats[mob_stat::SPEED] -= 250;
- md->next_walktime = tick;
- }
- sc_data[type].timer = add_timer( /* タイマー再設定 */
- 1000 + tick,
- skill_status_change_timer,
- bl->id, data);
- return;
- }
- break;
-
case StatusChange::SC_FLYING_BACKPACK:
clif_updatestatus(sd, SP::WEIGHT);
break;
@@ -1112,16 +975,15 @@ void skill_status_change_timer(timer_id tid, tick_t tick, custom_id_t id, custom
*------------------------------------------
*/
int skill_status_change_start(struct block_list *bl, StatusChange type,
- int val1, int val2, int val3, int val4,
- int tick, int flag)
+ int val1,
+ interval_t tick)
{
- return skill_status_effect(bl, type, val1, val2, val3, val4, tick, flag,
- 0);
+ return skill_status_effect(bl, type, val1, tick, 0);
}
int skill_status_effect(struct block_list *bl, StatusChange type,
- int val1, int val2, int val3, int val4,
- int tick, int flag, int spell_invocation)
+ int val1,
+ interval_t tick, int spell_invocation)
{
struct map_session_data *sd = NULL;
eptr<struct status_change, StatusChange> sc_data;
@@ -1131,7 +993,6 @@ int skill_status_effect(struct block_list *bl, StatusChange type,
Opt2 *opt2;
Opt3 *opt3;
int opt_flag = 0, calc_flag = 0;
- int undead_flag;
SP updateflag = SP::ZERO;
int scdef = 0;
@@ -1150,33 +1011,11 @@ int skill_status_effect(struct block_list *bl, StatusChange type,
opt3 = battle_get_opt3(bl);
nullpo_ret(opt3);
- Race race = battle_get_race(bl);
- MobMode mode = battle_get_mode(bl);
- Element elem = battle_get_elem_type(bl);
- undead_flag = battle_check_undead(race, elem);
-
switch (type)
{
- case StatusChange::SC_STONE:
- case StatusChange::SC_FREEZE:
- scdef = 3 + battle_get_mdef(bl) + battle_get_luk(bl) / 3;
- break;
- case StatusChange::SC_STAN:
- case StatusChange::SC_SILENCE:
case StatusChange::SC_POISON:
scdef = 3 + battle_get_vit(bl) + battle_get_luk(bl) / 3;
break;
- case StatusChange::SC_SLEEP:
- case StatusChange::SC_BLIND:
- scdef = 3 + battle_get_int(bl) + battle_get_luk(bl) / 3;
- break;
- case StatusChange::SC_CURSE:
- scdef = 3 + battle_get_luk(bl);
- break;
-
-// case StatusChange::SC_CONFUSION:
- default:
- scdef = 0;
}
if (scdef >= 100)
return 0;
@@ -1194,51 +1033,35 @@ int skill_status_effect(struct block_list *bl, StatusChange type,
return 0;
}
- if (type == StatusChange::SC_FREEZE && undead_flag && !(flag & 1))
- return 0;
-
- if (bool(mode & MobMode::BOSS)
- && (type == StatusChange::SC_STONE
- || type == StatusChange::SC_FREEZE
- || type == StatusChange::SC_STAN
- || type == StatusChange::SC_SLEEP
- || type == StatusChange::SC_SILENCE
- )
- && !(flag & 1))
- {
- /* ボスには効かない(ただしカードによる効果は適用される) */
- return 0;
- }
- if (type == StatusChange::SC_FREEZE || type == StatusChange::SC_STAN || type == StatusChange::SC_SLEEP)
- battle_stopwalking(bl, 1);
-
- if (sc_data[type].timer != -1)
+ if (sc_data[type].timer)
{ /* すでに同じ異常になっている場合タイマ解除 */
if (sc_data[type].val1 > val1
&& type != StatusChange::SC_SPEEDPOTION0
&& type != StatusChange::SC_ATKPOT
&& type != StatusChange::SC_MATKPOT) // added atk and matk potions [Valaris]
return 0;
- if (type >= StatusChange::SC_STAN && type <= StatusChange::SC_BLIND)
- return 0; /* 継ぎ足しができない状態異常である時は状態異常を行わない */
+ if (type == StatusChange::SC_POISON)
+ return 0;
+
+ /* 継ぎ足しができない状態異常である時は状態異常を行わない */
{
(*sc_count)--;
- delete_timer(sc_data[type].timer, skill_status_change_timer);
- sc_data[type].timer = -1;
+ delete_timer(sc_data[type].timer);
+ sc_data[type].timer = nullptr;
}
}
switch (type)
- { /* 異常の種類ごとの処理 */
+ {
+ /* 異常の種類ごとの処理 */
case StatusChange::SC_SLOWPOISON:
- if (sc_data[StatusChange::SC_POISON].timer == -1)
+ if (!sc_data[StatusChange::SC_POISON].timer)
return 0;
break;
case StatusChange::SC_SPEEDPOTION0: /* 増速ポーション */
*opt2 |= Opt2::_speedpotion0;
calc_flag = 1;
- tick = 1000 * tick;
// val2 = 5*(2+type-StatusChange::SC_SPEEDPOTION0);
break;
@@ -1248,109 +1071,26 @@ int skill_status_effect(struct block_list *bl, StatusChange type,
FALLTHROUGH;
case StatusChange::SC_MATKPOT:
calc_flag = 1;
- tick = 1000 * tick;
- break;
-
- case StatusChange::SC_NOCHAT: //チャット禁止状態
- {
- time_t timer;
-
- if (!battle_config.muting_players)
- break;
-
- tick = 60000;
- if (!val2)
- val2 = time(&timer);
- // updateflag = SP_MANNER;
- }
- break;
- case StatusChange::SC_SELFDESTRUCTION: //自爆
- val3 = tick / 1000;
- tick = 1000;
- break;
-
- /* option1 */
- case StatusChange::SC_STONE: /* 石化 */
- if (!(flag & 2))
- {
- int sc_def = battle_get_mdef(bl) * 200;
- tick = tick - sc_def;
- }
- val3 = tick / 1000;
- if (val3 < 1)
- val3 = 1;
- tick = 5000;
- val2 = 1;
- break;
- case StatusChange::SC_SLEEP: /* 睡眠 */
- if (!(flag & 2))
- {
-// int sc_def = 100 - (battle_get_int(bl) + battle_get_luk(bl)/3);
-// tick = tick * sc_def / 100;
-// if(tick < 1000) tick = 1000;
- tick = 30000; //睡眠はステータス耐性に関わらず30秒
- }
- break;
- case StatusChange::SC_FREEZE: /* 凍結 */
- if (!(flag & 2))
- {
- int sc_def = 100 - battle_get_mdef(bl);
- tick = tick * sc_def / 100;
- }
- break;
- case StatusChange::SC_STAN: /* スタン(val2にミリ秒セット) */
- if (!(flag & 2))
- {
- int sc_def =
- 100 - (battle_get_vit(bl) + battle_get_luk(bl) / 3);
- tick = tick * sc_def / 100;
- }
break;
/* option2 */
case StatusChange::SC_POISON: /* 毒 */
calc_flag = 1;
- if (!(flag & 2))
{
int sc_def =
100 - (battle_get_vit(bl) + battle_get_luk(bl) / 5);
tick = tick * sc_def / 100;
}
- val3 = tick / 1000;
- if (val3 < 1)
- val3 = 1;
- tick = 1000;
- break;
- case StatusChange::SC_SILENCE: /* 沈黙(レックスデビーナ) */
- if (!(flag & 2))
- {
- int sc_def = 100 - battle_get_vit(bl);
- tick = tick * sc_def / 100;
- }
- break;
- case StatusChange::SC_BLIND: /* 暗黒 */
- calc_flag = 1;
- if (!(flag & 2))
- {
- int sc_def =
- battle_get_lv(bl) / 10 + battle_get_int(bl) / 15;
- tick = 30000 - sc_def;
- }
- break;
- case StatusChange::SC_CURSE:
- calc_flag = 1;
- if (!(flag & 2))
- {
- int sc_def = 100 - battle_get_vit(bl);
- tick = tick * sc_def / 100;
- }
+
+ // huh?
+ tick = std::chrono::seconds(1);
break;
case StatusChange::SC_WEIGHT50:
case StatusChange::SC_WEIGHT90:
case StatusChange::SC_BROKNWEAPON:
case StatusChange::SC_BROKNARMOR:
- tick = 600 * 1000;
+ tick = std::chrono::minutes(10);
break;
case StatusChange::SC_HASTE:
@@ -1376,53 +1116,14 @@ int skill_status_effect(struct block_list *bl, StatusChange type,
/* optionの変更 */
switch (type)
{
- case StatusChange::SC_STONE:
- case StatusChange::SC_FREEZE:
- case StatusChange::SC_STAN:
- case StatusChange::SC_SLEEP:
- battle_stopattack(bl); /* 攻撃停止 */
- skill_stop_dancing(bl, 0); /* 演奏/ダンスの中断 */
- /* 同時に掛からないステータス異常を解除 */
- for (StatusChange i : MAJOR_STATUS_EFFECTS_1)
- {
- if (sc_data[i].timer != -1)
- {
- (*sc_count)--;
- delete_timer(sc_data[i].timer,
- skill_status_change_timer);
- sc_data[i].timer = -1;
- }
- }
- switch (type)
- {
- case StatusChange::SC_STONE: *opt1 = Opt1::_stone6; break;
- case StatusChange::SC_FREEZE: *opt1 = Opt1::_freeze; break;
- case StatusChange::SC_STAN: *opt1 = Opt1::_stan; break;
- case StatusChange::SC_SLEEP: *opt1 = Opt1::_sleep; break;
- }
- opt_flag = 1;
- break;
case StatusChange::SC_POISON:
- if (sc_data[StatusChange::SC_SLOWPOISON].timer == -1)
+ if (!sc_data[StatusChange::SC_SLOWPOISON].timer)
{
*opt2 |= Opt2::_poison;
opt_flag = 1;
}
break;
- case StatusChange::SC_CURSE:
- *opt2 |= Opt2::_curse;
- opt_flag = 1;
- break;
- case StatusChange::SC_SILENCE:
- *opt2 |= Opt2::_silence;
- opt_flag = 1;
- break;
- case StatusChange::SC_BLIND:
- *opt2 |= Opt2::BLIND;
- opt_flag = 1;
- break;
-
case StatusChange::SC_SLOWPOISON:
*opt2 &= ~Opt2::_poison;
*opt2 |= Opt2::_slowpoison;
@@ -1436,9 +1137,6 @@ int skill_status_effect(struct block_list *bl, StatusChange type,
(*sc_count)++; /* ステータス異常の数 */
sc_data[type].val1 = val1;
- sc_data[type].val2 = val2;
- sc_data[type].val3 = val3;
- sc_data[type].val4 = val4;
if (sc_data[type].spell_invocation) // Supplant by newer spell
spell_effect_report_termination(sc_data[type].spell_invocation,
bl->id, type, 1);
@@ -1446,9 +1144,9 @@ int skill_status_effect(struct block_list *bl, StatusChange type,
sc_data[type].spell_invocation = spell_invocation;
/* タイマー設定 */
- sc_data[type].timer =
- add_timer(gettick() + tick, skill_status_change_timer, bl->id,
- custom_data_t(type));
+ sc_data[type].timer = add_timer(gettick() + tick,
+ std::bind(skill_status_change_timer, ph::_1, ph::_2,
+ bl->id, type));
if (bl->type == BL::PC && calc_flag)
pc_calcstatus(sd, 0); /* ステータス再計算 */
@@ -1491,10 +1189,8 @@ int skill_status_change_clear(struct block_list *bl, int type)
return 0;
for (StatusChange i : erange(StatusChange(), StatusChange::MAX_STATUSCHANGE))
{
- if (sc_data[i].timer != -1)
- {
- skill_status_change_end(bl, i, -1);
- }
+ if (sc_data[i].timer)
+ skill_status_change_end(bl, i, nullptr);
}
*sc_count = 0;
*opt1 = Opt1::ZERO;
@@ -1502,9 +1198,6 @@ int skill_status_change_clear(struct block_list *bl, int type)
*opt3 = Opt3::ZERO;
*option = Option::ZERO;
- if (night_flag == 1 && type == 1) // by [Yor]
- *opt2 |= Opt2::BLIND;
-
if (type == 0 || type & 2)
clif_changeoption(bl);
diff --git a/src/map/skill.hpp b/src/map/skill.hpp
index 9fb95a2..10b6d89 100644
--- a/src/map/skill.hpp
+++ b/src/map/skill.hpp
@@ -25,7 +25,6 @@ struct skill_db
hp_rate[MAX_SKILL_LEVEL], sp_rate[MAX_SKILL_LEVEL],
zeny[MAX_SKILL_LEVEL];
int weapon;
- int spiritball[MAX_SKILL_LEVEL];
int itemid[10], amount[10];
int castnodex[MAX_SKILL_LEVEL];
};
@@ -65,11 +64,10 @@ int skill_get_maxcount(SkillID id);
// 追加効果
int skill_additional_effect(struct block_list *src, struct block_list *bl,
- SkillID skillid, int skilllv, BF attack_type,
- unsigned int tick);
+ SkillID skillid, int skilllv);
-int skill_castfix(struct block_list *bl, int time);
-int skill_delayfix(struct block_list *bl, int time);
+interval_t skill_castfix(struct block_list *bl, interval_t time);
+interval_t skill_delayfix(struct block_list *bl, interval_t time);
void skill_stop_dancing(struct block_list *src, int flag);
@@ -82,20 +80,20 @@ int skill_devotion3(struct block_list *bl, int target);
// ステータス異常
int skill_status_effect(struct block_list *bl, StatusChange type,
- int val1, int val2, int val3, int val4,
- int tick, int flag, int spell_invocation);
+ int val1,
+ interval_t tick, int spell_invocation);
int skill_status_change_start(struct block_list *bl, StatusChange type,
- int val1, int val2, int val3, int val4, int tick, int flag);
+ int val1,
+ interval_t tick);
int skill_status_change_active(struct block_list *bl, StatusChange type); // [fate]
-int skill_status_change_end(struct block_list *bl, StatusChange type, int tid);
+int skill_status_change_end(struct block_list *bl, StatusChange type, TimerData *tid);
int skill_status_change_clear(struct block_list *bl, int type);
// mobスキルのため
int skill_castend_nodamage_id(struct block_list *src, struct block_list *bl,
- SkillID skillid, int skilllv, unsigned int tick,
- BCT flag);
+ SkillID skillid, int skilllv);
int skill_castend_damage_id(struct block_list *src, struct block_list *bl,
- SkillID skillid, int skilllv, unsigned int tick,
+ SkillID skillid, int skilllv, tick_t tick,
BCT flag);
int skill_update_heal_animation(struct map_session_data *sd); // [Fate] Check whether the healing flag must be updated, do so if needed
diff --git a/src/map/skill.t.hpp b/src/map/skill.t.hpp
index 9dcb119..3214062 100644
--- a/src/map/skill.t.hpp
+++ b/src/map/skill.t.hpp
@@ -13,7 +13,6 @@ enum class StatusChange : uint16_t
// sometimes means "none", sometimes not
NEGATIVE1 = 0xffff,
- ANY_BAD = NEGATIVE1,
// these ones are used by clif_status_change,
// e.g. by the magic system
@@ -36,23 +35,11 @@ enum class StatusChange : uint16_t
SC_HEALING = 70, // item script
- SC_STONE = 128, // ?bad
- SC_FREEZE = 129, // ?bad
- SC_STAN = 130, // ?bad
- SC_SLEEP = 131, // ?bad
SC_POISON = 132, // bad; actually used
- SC_CURSE = 133, // ?bad
- SC_SILENCE = 134, // ?bad
- SC_CONFUSION = 135, // ?bad
- SC_BLIND = 136, // ?bad
SC_ATKPOT = 185, // item script
SC_MATKPOT = 186, // unused, but kept for parallel
- SC_NOCHAT = 188, // ? something with manner
-
- SC_SELFDESTRUCTION = 190, // see table - maybe used, maybe not
-
// Added for Fate's spells
SC_HIDE = 194, // Hide from `detect' magic (PCs only)
SC_SHEARED = 194, // Has been sheared (mobs only)
@@ -64,60 +51,6 @@ enum class StatusChange : uint16_t
MAX_STATUSCHANGE = 200,
};
-constexpr
-StatusChange MAJOR_STATUS_EFFECTS[] =
-{
- StatusChange::SC_STONE,
- StatusChange::SC_FREEZE,
- StatusChange::SC_STAN,
- StatusChange::SC_SLEEP,
- StatusChange::SC_POISON,
- StatusChange::SC_CURSE,
- StatusChange::SC_SILENCE,
- StatusChange::SC_CONFUSION,
- StatusChange::SC_BLIND,
-};
-
-constexpr
-StatusChange MAJOR_STATUS_EFFECTS_1[] =
-{
- StatusChange::SC_STONE,
- StatusChange::SC_FREEZE,
- StatusChange::SC_STAN,
- StatusChange::SC_SLEEP,
-};
-
-// needed to work around some subtractative indexing
-// I think it *might* be able to be totally removed.
-enum class BadSC
-{
- STONE = 0,
- FREEZE = 1,
- STAN = 2,
- SLEEP = 3,
- POISON = 4,
- CURSE = 5,
- SILENCE = 6,
- CONFUSION = 7,
- BLIND = 8,
-
- COUNT = 9, // formerly 10,
- // there is apocryphal evidence of a "bleeding" effect
-};
-
-constexpr
-StatusChange BadSC_to_SC(BadSC bsc)
-{
- return StatusChange(uint16_t(StatusChange::SC_STONE) + int(bsc));
-}
-
-constexpr
-BadSC BadSC_from_SC(StatusChange sc)
-{
- return BadSC(uint16_t(sc) - uint16_t(StatusChange::SC_STONE));
-}
-
-// TODO remove most of these
enum class SkillID : uint16_t
{
// TODO: Remove these!